Merge lp:~osomon/oxide/thumbnails into lp:~oxide-developers/oxide/oxide.trunk

Proposed by Olivier Tilloy
Status: Work in progress
Proposed branch: lp:~osomon/oxide/thumbnails
Merge into: lp:~oxide-developers/oxide/oxide.trunk
Diff against target: 576 lines (+306/-8)
17 files modified
qt/core/browser/oxide_qt_web_view.cc (+27/-7)
qt/core/browser/oxide_qt_web_view.h (+3/-0)
qt/core/glue/oxide_qt_web_view_adapter.cc (+4/-0)
qt/core/glue/oxide_qt_web_view_adapter.h (+5/-0)
qt/quick/CMakeLists.txt (+1/-0)
qt/quick/api/oxideqquickwebthumbnail.cc (+54/-0)
qt/quick/api/oxideqquickwebthumbnail_p.h (+59/-0)
qt/quick/api/oxideqquickwebthumbnail_p_p.h (+41/-0)
qt/quick/api/oxideqquickwebview.cc (+14/-0)
qt/quick/api/oxideqquickwebview_p.h (+4/-0)
qt/quick/api/oxideqquickwebview_p_p.h (+2/-0)
qt/quick/oxide_qml_plugin.cc (+3/-0)
qt/tests/qmltests/api/tst_WebView_thumbnail.qml (+44/-0)
shared/browser/oxide_render_widget_host_view.cc (+1/-0)
shared/browser/oxide_render_widget_host_view.h (+2/-0)
shared/browser/oxide_web_view.cc (+36/-1)
shared/browser/oxide_web_view.h (+6/-0)
To merge this branch: bzr merge lp:~osomon/oxide/thumbnails
Reviewer Review Type Date Requested Status
Chris Coulson Pending
Review via email: mp+214984@code.launchpad.net

Commit message

Expose an asynchronous API on WebView to request a thumbnail.

To post a comment you must log in.
lp:~osomon/oxide/thumbnails updated
455. By Olivier Tilloy

Merge the latest changes from trunk.

456. By Olivier Tilloy

Use the physical size of the view in pixels instead of the DPI aware bounds.

457. By Olivier Tilloy

Scale down using bilinear filtering.

458. By Olivier Tilloy

Clip scrollbars only when overlay scrollbars are not enabled.

459. By Olivier Tilloy

Add some unit tests for thumbnailing.

460. By Olivier Tilloy

Merge the latest changes from trunk and resolve a conflict.

461. By Olivier Tilloy

Match API changes in trunk.

462. By Olivier Tilloy

Merge the latest changes from trunk and resolve a bunch of conflicts.

463. By Olivier Tilloy

Add warning to make it clear that RenderWidgetHostView::CopyFromCompositingSurface(…) is not implemented.

464. By Olivier Tilloy

Merge the latest changes from trunk and resolve a bunch of conflicts.

Unmerged revisions

464. By Olivier Tilloy

Merge the latest changes from trunk and resolve a bunch of conflicts.

463. By Olivier Tilloy

Add warning to make it clear that RenderWidgetHostView::CopyFromCompositingSurface(…) is not implemented.

462. By Olivier Tilloy

Merge the latest changes from trunk and resolve a bunch of conflicts.

461. By Olivier Tilloy

Match API changes in trunk.

460. By Olivier Tilloy

Merge the latest changes from trunk and resolve a conflict.

459. By Olivier Tilloy

Add some unit tests for thumbnailing.

458. By Olivier Tilloy

Clip scrollbars only when overlay scrollbars are not enabled.

457. By Olivier Tilloy

Scale down using bilinear filtering.

456. By Olivier Tilloy

Use the physical size of the view in pixels instead of the DPI aware bounds.

455. By Olivier Tilloy

Merge the latest changes from trunk.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'qt/core/browser/oxide_qt_web_view.cc'
--- qt/core/browser/oxide_qt_web_view.cc 2014-05-30 08:58:49 +0000
+++ qt/core/browser/oxide_qt_web_view.cc 2014-06-02 08:50:28 +0000
@@ -17,17 +17,19 @@
1717
18#include "oxide_qt_web_view.h"18#include "oxide_qt_web_view.h"
1919
20#include <QImage>
20#include <QKeyEvent>21#include <QKeyEvent>
21#include <QString>22#include <QString>
22#include <QtDebug>23#include <QtDebug>
23#include <QUrl>24#include <QUrl>
2425
25#include "base/strings/utf_string_conversions.h"26#include "base/strings/utf_string_conversions.h"
26#include "url/gurl.h"27#include "content/public/browser/native_web_keyboard_event.h"
27#include "content/public/browser/navigation_controller.h"28#include "content/public/browser/navigation_controller.h"
28#include "content/browser/web_contents/web_contents_impl.h"29#include "content/browser/web_contents/web_contents_impl.h"
29#include "net/base/net_errors.h"30#include "net/base/net_errors.h"
30#include "content/public/browser/native_web_keyboard_event.h"31#include "third_party/skia/include/core/SkBitmap.h"
32#include "url/gurl.h"
3133
32#include "qt/core/api/oxideqloadevent.h"34#include "qt/core/api/oxideqloadevent.h"
33#include "qt/core/api/oxideqnavigationrequest.h"35#include "qt/core/api/oxideqnavigationrequest.h"
@@ -342,11 +344,6 @@
342 return view;344 return view;
343}345}
344346
345// static
346WebView* WebView::Create(WebViewAdapter* adapter) {
347 return new WebView(adapter);
348}
349
350void WebView::HandleKeyboardEvent(content::WebContents* source,347void WebView::HandleKeyboardEvent(content::WebContents* source,
351 const content::NativeWebKeyboardEvent& event) {348 const content::NativeWebKeyboardEvent& event) {
352 if (event.skip_in_browser) {349 if (event.skip_in_browser) {
@@ -366,5 +363,28 @@
366 adapter_->HandleKeyboardEvent(qevent);363 adapter_->HandleKeyboardEvent(qevent);
367}364}
368365
366void WebView::GotThumbnail(const GURL& url, const gfx::Size& size,
367 bool result, const SkBitmap& bitmap) {
368 QUrl qurl(QString::fromStdString(url.spec()));
369 if (result) {
370 QImage thumbnail(static_cast<uchar*>(bitmap.getPixels()),
371 bitmap.width(), bitmap.height(), QImage::Format_ARGB32);
372 if ((bitmap.width() > size.width()) || (bitmap.height() > size.height())) {
373 // CopyFromBackingStore doesn’t guarantee it will honour the requested size
374 thumbnail = thumbnail.scaled(size.width(), size.height(),
375 Qt::IgnoreAspectRatio,
376 Qt::SmoothTransformation);
377 }
378 adapter_->GotThumbnail(qurl, thumbnail);
379 } else {
380 adapter_->GotThumbnail(qurl, QImage());
381 }
382}
383
384// static
385WebView* WebView::Create(WebViewAdapter* adapter) {
386 return new WebView(adapter);
387}
388
369} // namespace qt389} // namespace qt
370} // namespace oxide390} // namespace oxide
371391
=== modified file 'qt/core/browser/oxide_qt_web_view.h'
--- qt/core/browser/oxide_qt_web_view.h 2014-05-30 08:58:49 +0000
+++ qt/core/browser/oxide_qt_web_view.h 2014-06-02 08:50:28 +0000
@@ -110,6 +110,9 @@
110 void HandleKeyboardEvent(content::WebContents* source,110 void HandleKeyboardEvent(content::WebContents* source,
111 const content::NativeWebKeyboardEvent& event);111 const content::NativeWebKeyboardEvent& event);
112112
113 void GotThumbnail(const GURL& url, const gfx::Size& size,
114 bool result, const SkBitmap& bitmap) FINAL;
115
113 WebViewAdapter* adapter_;116 WebViewAdapter* adapter_;
114117
115 DISALLOW_IMPLICIT_CONSTRUCTORS(WebView);118 DISALLOW_IMPLICIT_CONSTRUCTORS(WebView);
116119
=== modified file 'qt/core/glue/oxide_qt_web_view_adapter.cc'
--- qt/core/glue/oxide_qt_web_view_adapter.cc 2014-05-30 08:53:36 +0000
+++ qt/core/glue/oxide_qt_web_view_adapter.cc 2014-06-02 08:50:28 +0000
@@ -273,5 +273,9 @@
273 priv->UpdateWebPreferences();273 priv->UpdateWebPreferences();
274}274}
275275
276void WebViewAdapter::requestThumbnail(const QSize& size) const {
277 priv->RequestThumbnail(gfx::Size(size.width(), size.height()));
278}
279
276} // namespace qt280} // namespace qt
277} // namespace oxide281} // namespace oxide
278282
=== modified file 'qt/core/glue/oxide_qt_web_view_adapter.h'
--- qt/core/glue/oxide_qt_web_view_adapter.h 2014-05-30 08:58:49 +0000
+++ qt/core/glue/oxide_qt_web_view_adapter.h 2014-06-02 08:50:28 +0000
@@ -30,6 +30,7 @@
30#include "qt/core/glue/oxide_qt_javascript_dialog_delegate.h"30#include "qt/core/glue/oxide_qt_javascript_dialog_delegate.h"
3131
32QT_BEGIN_NAMESPACE32QT_BEGIN_NAMESPACE
33class QImage;
33class QKeyEvent;34class QKeyEvent;
34class QSize;35class QSize;
35QT_END_NAMESPACE36QT_END_NAMESPACE
@@ -107,6 +108,8 @@
107108
108 void updateWebPreferences();109 void updateWebPreferences();
109110
111 void requestThumbnail(const QSize& size) const;
112
110 protected:113 protected:
111 WebViewAdapter(QObject* q);114 WebViewAdapter(QObject* q);
112115
@@ -175,6 +178,8 @@
175178
176 virtual void HandleKeyboardEvent(QKeyEvent* event) = 0;179 virtual void HandleKeyboardEvent(QKeyEvent* event) = 0;
177180
181 virtual void GotThumbnail(const QUrl& url, const QImage& thumbnail) = 0;
182
178 QScopedPointer<WebView> priv;183 QScopedPointer<WebView> priv;
179 QList<ScriptMessageHandlerAdapter *> message_handlers_;184 QList<ScriptMessageHandlerAdapter *> message_handlers_;
180 QScopedPointer<ConstructProperties> construct_props_;185 QScopedPointer<ConstructProperties> construct_props_;
181186
=== modified file 'qt/quick/CMakeLists.txt'
--- qt/quick/CMakeLists.txt 2014-04-23 21:36:15 +0000
+++ qt/quick/CMakeLists.txt 2014-06-02 08:50:28 +0000
@@ -56,6 +56,7 @@
56 api/oxideqquickwebcontext.cc56 api/oxideqquickwebcontext.cc
57 api/oxideqquickwebcontextdelegateworker.cc57 api/oxideqquickwebcontextdelegateworker.cc
58 api/oxideqquickwebframe.cc58 api/oxideqquickwebframe.cc
59 api/oxideqquickwebthumbnail.cc
59 api/oxideqquickwebview.cc60 api/oxideqquickwebview.cc
60 api/oxidequseragentoverriderequest.cc61 api/oxidequseragentoverriderequest.cc
61 oxide_qml_plugin.cc62 oxide_qml_plugin.cc
6263
=== added file 'qt/quick/api/oxideqquickwebthumbnail.cc'
--- qt/quick/api/oxideqquickwebthumbnail.cc 1970-01-01 00:00:00 +0000
+++ qt/quick/api/oxideqquickwebthumbnail.cc 2014-06-02 08:50:28 +0000
@@ -0,0 +1,54 @@
1// vim:expandtab:shiftwidth=2:tabstop=2:
2// Copyright (C) 2014 Canonical Ltd.
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18#include "oxideqquickwebthumbnail_p.h"
19#include "oxideqquickwebthumbnail_p_p.h"
20
21OxideQQuickWebThumbnailPrivate::OxideQQuickWebThumbnailPrivate(
22 const QUrl& url, const QImage& thumbnail) :
23 url_(url),
24 thumbnail_(thumbnail) {}
25
26OxideQQuickWebThumbnail::OxideQQuickWebThumbnail(
27 const QUrl& url, const QImage& thumbnail) :
28 d_ptr(new OxideQQuickWebThumbnailPrivate(url, thumbnail)) {}
29
30OxideQQuickWebThumbnail::~OxideQQuickWebThumbnail() {}
31
32const QUrl& OxideQQuickWebThumbnail::url() const {
33 Q_D(const OxideQQuickWebThumbnail);
34
35 return d->url_;
36}
37
38int OxideQQuickWebThumbnail::width() const {
39 Q_D(const OxideQQuickWebThumbnail);
40
41 return d->thumbnail_.width();
42}
43
44int OxideQQuickWebThumbnail::height() const {
45 Q_D(const OxideQQuickWebThumbnail);
46
47 return d->thumbnail_.height();
48}
49
50void OxideQQuickWebThumbnail::save(const QString& fileName) const {
51 Q_D(const OxideQQuickWebThumbnail);
52
53 d->thumbnail_.save(fileName);
54}
055
=== added file 'qt/quick/api/oxideqquickwebthumbnail_p.h'
--- qt/quick/api/oxideqquickwebthumbnail_p.h 1970-01-01 00:00:00 +0000
+++ qt/quick/api/oxideqquickwebthumbnail_p.h 2014-06-02 08:50:28 +0000
@@ -0,0 +1,59 @@
1// vim:expandtab:shiftwidth=2:tabstop=2:
2// Copyright (C) 2014 Canonical Ltd.
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18#ifndef _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_H_
19#define _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_H_
20
21#include <QObject>
22#include <QScopedPointer>
23#include <QtQml>
24#include <QUrl>
25
26QT_BEGIN_NAMESPACE
27class QImage;
28class QString;
29QT_END_NAMESPACE
30
31class OxideQQuickWebThumbnailPrivate;
32
33class OxideQQuickWebThumbnail Q_DECL_FINAL : public QObject {
34 Q_OBJECT
35 Q_PROPERTY(QUrl url READ url CONSTANT FINAL)
36 Q_PROPERTY(int width READ width CONSTANT FINAL)
37 Q_PROPERTY(int height READ height CONSTANT FINAL)
38
39 public:
40 OxideQQuickWebThumbnail(const QUrl& url, const QImage& thumbnail);
41 ~OxideQQuickWebThumbnail();
42
43 const QUrl& url() const;
44 int width() const;
45 int height() const;
46
47 public Q_SLOTS:
48 void save(const QString& fileName) const;
49
50 private:
51 QScopedPointer<OxideQQuickWebThumbnailPrivate> d_ptr;
52
53 Q_DECLARE_PRIVATE(OxideQQuickWebThumbnail)
54 Q_DISABLE_COPY(OxideQQuickWebThumbnail)
55};
56
57QML_DECLARE_TYPE(OxideQQuickWebThumbnail)
58
59#endif // _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_H_
060
=== added file 'qt/quick/api/oxideqquickwebthumbnail_p_p.h'
--- qt/quick/api/oxideqquickwebthumbnail_p_p.h 1970-01-01 00:00:00 +0000
+++ qt/quick/api/oxideqquickwebthumbnail_p_p.h 2014-06-02 08:50:28 +0000
@@ -0,0 +1,41 @@
1// vim:expandtab:shiftwidth=2:tabstop=2:
2// Copyright (C) 2014 Canonical Ltd.
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18#ifndef _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_P_H_
19#define _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_P_H_
20
21#include <QImage>
22#include <QtGlobal>
23#include <QUrl>
24
25class OxideQQuickWebThumbnail;
26
27class OxideQQuickWebThumbnailPrivate Q_DECL_FINAL {
28 Q_DECLARE_PUBLIC(OxideQQuickWebThumbnail)
29
30 private:
31 OxideQQuickWebThumbnailPrivate(const QUrl& url, const QImage& thumbnail);
32
33 OxideQQuickWebThumbnail* q_ptr;
34
35 QUrl url_;
36 QImage thumbnail_;
37
38 Q_DISABLE_COPY(OxideQQuickWebThumbnailPrivate);
39};
40
41#endif // _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_P_H_
042
=== modified file 'qt/quick/api/oxideqquickwebview.cc'
--- qt/quick/api/oxideqquickwebview.cc 2014-05-31 08:30:20 +0000
+++ qt/quick/api/oxideqquickwebview.cc 2014-06-02 08:50:28 +0000
@@ -44,6 +44,7 @@
44#include "oxideqquickwebcontext_p_p.h"44#include "oxideqquickwebcontext_p_p.h"
45#include "oxideqquickwebframe_p.h"45#include "oxideqquickwebframe_p.h"
46#include "oxideqquickwebframe_p_p.h"46#include "oxideqquickwebframe_p_p.h"
47#include "oxideqquickwebthumbnail_p.h"
4748
48QT_USE_NAMESPACE49QT_USE_NAMESPACE
4950
@@ -299,6 +300,13 @@
299 w->sendEvent(q, event);300 w->sendEvent(q, event);
300}301}
301302
303void OxideQQuickWebViewPrivate::GotThumbnail(const QUrl& url,
304 const QImage& thumbnail) {
305 Q_Q(OxideQQuickWebView);
306
307 emit q->gotThumbnail(new OxideQQuickWebThumbnail(url, thumbnail));
308}
309
302void OxideQQuickWebViewPrivate::completeConstruction() {310void OxideQQuickWebViewPrivate::completeConstruction() {
303 Q_Q(OxideQQuickWebView);311 Q_Q(OxideQQuickWebView);
304312
@@ -877,4 +885,10 @@
877 d->loadHtml(html, baseUrl);885 d->loadHtml(html, baseUrl);
878}886}
879887
888void OxideQQuickWebView::requestThumbnail(const QSize& size) {
889 Q_D(OxideQQuickWebView);
890
891 d->requestThumbnail(size);
892}
893
880#include "moc_oxideqquickwebview_p.cpp"894#include "moc_oxideqquickwebview_p.cpp"
881895
=== modified file 'qt/quick/api/oxideqquickwebview_p.h'
--- qt/quick/api/oxideqquickwebview_p.h 2014-05-30 08:58:49 +0000
+++ qt/quick/api/oxideqquickwebview_p.h 2014-06-02 08:50:28 +0000
@@ -28,6 +28,7 @@
2828
29QT_BEGIN_NAMESPACE29QT_BEGIN_NAMESPACE
30class QQmlComponent;30class QQmlComponent;
31class QSize;
31QT_END_NAMESPACE32QT_END_NAMESPACE
3233
33QT_USE_NAMESPACE34QT_USE_NAMESPACE
@@ -41,6 +42,7 @@
41class OxideQQuickScriptMessageHandler;42class OxideQQuickScriptMessageHandler;
42class OxideQQuickWebContext;43class OxideQQuickWebContext;
43class OxideQQuickWebFrame;44class OxideQQuickWebFrame;
45class OxideQQuickWebThumbnail;
44class OxideQQuickWebView;46class OxideQQuickWebView;
45class OxideQQuickWebViewPrivate;47class OxideQQuickWebViewPrivate;
4648
@@ -172,6 +174,7 @@
172 void stop();174 void stop();
173 void reload();175 void reload();
174 void loadHtml(const QString& html, const QUrl& baseUrl = QUrl());176 void loadHtml(const QString& html, const QUrl& baseUrl = QUrl());
177 void requestThumbnail(const QSize& size);
175178
176 Q_SIGNALS:179 Q_SIGNALS:
177 void urlChanged();180 void urlChanged();
@@ -203,6 +206,7 @@
203 const QString& message,206 const QString& message,
204 int lineNumber,207 int lineNumber,
205 const QString& sourceId);208 const QString& sourceId);
209 void gotThumbnail(OxideQQuickWebThumbnail* thumbnail);
206210
207 private:211 private:
208 Q_PRIVATE_SLOT(d_func(), void contextConstructed());212 Q_PRIVATE_SLOT(d_func(), void contextConstructed());
209213
=== modified file 'qt/quick/api/oxideqquickwebview_p_p.h'
--- qt/quick/api/oxideqquickwebview_p_p.h 2014-05-30 08:58:49 +0000
+++ qt/quick/api/oxideqquickwebview_p_p.h 2014-06-02 08:50:28 +0000
@@ -100,6 +100,8 @@
100100
101 void HandleKeyboardEvent(QKeyEvent *event) Q_DECL_FINAL;101 void HandleKeyboardEvent(QKeyEvent *event) Q_DECL_FINAL;
102102
103 void GotThumbnail(const QUrl& url, const QImage& thumbnail) Q_DECL_FINAL;
104
103 void completeConstruction();105 void completeConstruction();
104106
105 static void messageHandler_append(107 static void messageHandler_append(
106108
=== modified file 'qt/quick/oxide_qml_plugin.cc'
--- qt/quick/oxide_qml_plugin.cc 2014-05-07 14:06:05 +0000
+++ qt/quick/oxide_qml_plugin.cc 2014-06-02 08:50:28 +0000
@@ -35,6 +35,7 @@
35#include "qt/quick/api/oxideqquickwebcontext_p.h"35#include "qt/quick/api/oxideqquickwebcontext_p.h"
36#include "qt/quick/api/oxideqquickwebcontextdelegateworker_p.h"36#include "qt/quick/api/oxideqquickwebcontextdelegateworker_p.h"
37#include "qt/quick/api/oxideqquickwebframe_p.h"37#include "qt/quick/api/oxideqquickwebframe_p.h"
38#include "qt/quick/api/oxideqquickwebthumbnail_p.h"
38#include "qt/quick/api/oxideqquickwebview_p.h"39#include "qt/quick/api/oxideqquickwebview_p.h"
3940
40QT_USE_NAMESPACE41QT_USE_NAMESPACE
@@ -78,6 +79,8 @@
78 "OutgoingMessageRequests are created automatically by WebFrame.sendMessage");79 "OutgoingMessageRequests are created automatically by WebFrame.sendMessage");
79 qmlRegisterUncreatableType<OxideQQuickWebFrame>(uri, 1, 0, "WebFrame",80 qmlRegisterUncreatableType<OxideQQuickWebFrame>(uri, 1, 0, "WebFrame",
80 "Frames are created automatically by Oxide to represent frames in the renderer");81 "Frames are created automatically by Oxide to represent frames in the renderer");
82 qmlRegisterUncreatableType<OxideQQuickWebThumbnail>(uri, 1, 0, "WebThumbnail",
83 "WebThumbnails are created automatically by Oxide");
8184
82 qmlRegisterType<OxideQQuickScriptMessageHandler>(uri, 1, 0, "ScriptMessageHandler");85 qmlRegisterType<OxideQQuickScriptMessageHandler>(uri, 1, 0, "ScriptMessageHandler");
83 qmlRegisterType<OxideQQuickUserScript>(uri, 1, 0, "UserScript");86 qmlRegisterType<OxideQQuickUserScript>(uri, 1, 0, "UserScript");
8487
=== added file 'qt/tests/qmltests/api/tst_WebView_thumbnail.qml'
--- qt/tests/qmltests/api/tst_WebView_thumbnail.qml 1970-01-01 00:00:00 +0000
+++ qt/tests/qmltests/api/tst_WebView_thumbnail.qml 2014-06-02 08:50:28 +0000
@@ -0,0 +1,44 @@
1import QtQuick 2.0
2import QtTest 1.0
3import com.canonical.Oxide.Testing 1.0
4
5TestWebView {
6 id: webView
7 focus: true
8 width: 200
9 height: 200
10
11 SignalSpy {
12 id: spy
13 target: webView
14 signalName: "gotThumbnail"
15 }
16
17 TestCase {
18 name: "WebView_thumbnail"
19 when: windowShown
20
21 function test_requestThumbnail_data() {
22 return [
23 { requested: Qt.size(50, 50), expected: Qt.size(50, 50) },
24 { requested: Qt.size(50, 75), expected: Qt.size(50, 75) },
25 { requested: Qt.size(75, 50), expected: Qt.size(75, 50) },
26 // Account for the clipping of scrollbars (15px, assuming this test
27 // will be run on desktop where overlay scrollbars are not enabled).
28 { requested: Qt.size(300, 300), expected: Qt.size(185, 185) }
29 ];
30 }
31
32 function test_requestThumbnail(data) {
33 webView.url = "http://localhost:8080/empty.html";
34 verify(webView.waitForLoadSucceeded(),
35 "Timed out waiting for successful load");
36 webView.requestThumbnail(data.requested);
37 spy.wait();
38 var thumbnail = spy.signalArguments[spy.count - 1][0];
39 compare(thumbnail.url, webView.url);
40 compare(thumbnail.width, data.expected.width);
41 compare(thumbnail.height, data.expected.height);
42 }
43 }
44}
045
=== modified file 'shared/browser/oxide_render_widget_host_view.cc'
--- shared/browser/oxide_render_widget_host_view.cc 2014-05-19 10:10:11 +0000
+++ shared/browser/oxide_render_widget_host_view.cc 2014-06-02 08:50:28 +0000
@@ -270,6 +270,7 @@
270 const gfx::Size& dst_size,270 const gfx::Size& dst_size,
271 const base::Callback<void(bool, const SkBitmap&)>& callback,271 const base::Callback<void(bool, const SkBitmap&)>& callback,
272 const SkBitmap::Config config) {272 const SkBitmap::Config config) {
273 NOTIMPLEMENTED();
273 callback.Run(false, SkBitmap());274 callback.Run(false, SkBitmap());
274}275}
275276
276277
=== modified file 'shared/browser/oxide_render_widget_host_view.h'
--- shared/browser/oxide_render_widget_host_view.h 2014-05-19 09:32:11 +0000
+++ shared/browser/oxide_render_widget_host_view.h 2014-06-02 08:50:28 +0000
@@ -103,6 +103,8 @@
103 // content::RenderWidgetHostView103 // content::RenderWidgetHostView
104 content::RenderWidgetHost* GetRenderWidgetHost() const FINAL;104 content::RenderWidgetHost* GetRenderWidgetHost() const FINAL;
105105
106 virtual gfx::Size GetPhysicalBackingSize() const = 0;
107
106 void SetBounds(const gfx::Rect& rect) FINAL;108 void SetBounds(const gfx::Rect& rect) FINAL;
107109
108 protected:110 protected:
109111
=== modified file 'shared/browser/oxide_web_view.cc'
--- shared/browser/oxide_web_view.cc 2014-05-31 08:35:36 +0000
+++ shared/browser/oxide_web_view.cc 2014-06-02 08:50:28 +0000
@@ -43,14 +43,15 @@
43#include "content/public/common/url_constants.h"43#include "content/public/common/url_constants.h"
44#include "net/base/net_errors.h"44#include "net/base/net_errors.h"
45#include "ui/base/window_open_disposition.h"45#include "ui/base/window_open_disposition.h"
46#include "ui/gfx/scrollbar_size.h"
46#include "url/gurl.h"47#include "url/gurl.h"
47#include "webkit/common/webpreferences.h"48#include "webkit/common/webpreferences.h"
4849
49#include "shared/common/oxide_content_client.h"50#include "shared/common/oxide_content_client.h"
5051
51#include "oxide_browser_process_main.h"
52#include "oxide_content_browser_client.h"52#include "oxide_content_browser_client.h"
53#include "oxide_file_picker.h"53#include "oxide_file_picker.h"
54#include "oxide_form_factor.h"
54#include "oxide_render_widget_host_view.h"55#include "oxide_render_widget_host_view.h"
55#include "oxide_web_contents_view.h"56#include "oxide_web_contents_view.h"
56#include "oxide_web_frame.h"57#include "oxide_web_frame.h"
@@ -938,4 +939,38 @@
938 return false;939 return false;
939}940}
940941
942void WebView::RequestThumbnail(const gfx::Size& size) {
943 RenderWidgetHostView* rwhv = static_cast<RenderWidgetHostView *>(
944 web_contents_->GetRenderWidgetHostView());
945 if (!rwhv) {
946 return;
947 }
948 gfx::Rect copy_rect(rwhv->GetPhysicalBackingSize());
949
950 if (GetFormFactorHint() == FORM_FACTOR_DESKTOP) {
951 // Clip the pixels that will commonly hold a scrollbar,
952 // which looks bad in thumbnails.
953 int scrollbar_size = gfx::scrollbar_size();
954 copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size);
955 }
956
957 // Crop the target region to match the aspect ratio of the requested size.
958 int c1 = size.width() * copy_rect.height();
959 int c2 = copy_rect.width() * size.height();
960 if (c1 > c2) {
961 copy_rect.set_height(c2 / size.width());
962 } else if (c1 < c2) {
963 copy_rect.set_width(c1 / size.height());
964 }
965
966 if (!copy_rect.IsEmpty()) {
967 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
968 rvh->CopyFromBackingStore(
969 copy_rect, size,
970 base::Bind(
971 &WebView::GotThumbnail, base::Unretained(this), GetURL(), size),
972 SkBitmap::kARGB_8888_Config);
973 }
974}
975
941} // namespace oxide976} // namespace oxide
942977
=== modified file 'shared/browser/oxide_web_view.h'
--- shared/browser/oxide_web_view.h 2014-05-30 08:58:49 +0000
+++ shared/browser/oxide_web_view.h 2014-06-02 08:50:28 +0000
@@ -41,6 +41,7 @@
41#include "shared/common/oxide_message_enums.h"41#include "shared/common/oxide_message_enums.h"
4242
43class GURL;43class GURL;
44class SkBitmap;
4445
45namespace gfx {46namespace gfx {
46class Size;47class Size;
@@ -170,6 +171,8 @@
170171
171 virtual bool CanCreateWindows() const;172 virtual bool CanCreateWindows() const;
172173
174 void RequestThumbnail(const gfx::Size& size);
175
173 protected:176 protected:
174 WebView();177 WebView();
175178
@@ -307,6 +310,9 @@
307 virtual WebView* CreateNewWebView(const gfx::Rect& initial_pos,310 virtual WebView* CreateNewWebView(const gfx::Rect& initial_pos,
308 WindowOpenDisposition disposition);311 WindowOpenDisposition disposition);
309312
313 virtual void GotThumbnail(const GURL& url, const gfx::Size& size,
314 bool result, const SkBitmap& bitmap) = 0;
315
310 scoped_ptr<content::WebContentsImpl> web_contents_;316 scoped_ptr<content::WebContentsImpl> web_contents_;
311 WebViewContentsHelper* web_contents_helper_;317 WebViewContentsHelper* web_contents_helper_;
312318

Subscribers

People subscribed via source and target branches