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
1=== modified file 'qt/core/browser/oxide_qt_web_view.cc'
2--- qt/core/browser/oxide_qt_web_view.cc 2014-05-30 08:58:49 +0000
3+++ qt/core/browser/oxide_qt_web_view.cc 2014-06-02 08:50:28 +0000
4@@ -17,17 +17,19 @@
5
6 #include "oxide_qt_web_view.h"
7
8+#include <QImage>
9 #include <QKeyEvent>
10 #include <QString>
11 #include <QtDebug>
12 #include <QUrl>
13
14 #include "base/strings/utf_string_conversions.h"
15-#include "url/gurl.h"
16+#include "content/public/browser/native_web_keyboard_event.h"
17 #include "content/public/browser/navigation_controller.h"
18 #include "content/browser/web_contents/web_contents_impl.h"
19 #include "net/base/net_errors.h"
20-#include "content/public/browser/native_web_keyboard_event.h"
21+#include "third_party/skia/include/core/SkBitmap.h"
22+#include "url/gurl.h"
23
24 #include "qt/core/api/oxideqloadevent.h"
25 #include "qt/core/api/oxideqnavigationrequest.h"
26@@ -342,11 +344,6 @@
27 return view;
28 }
29
30-// static
31-WebView* WebView::Create(WebViewAdapter* adapter) {
32- return new WebView(adapter);
33-}
34-
35 void WebView::HandleKeyboardEvent(content::WebContents* source,
36 const content::NativeWebKeyboardEvent& event) {
37 if (event.skip_in_browser) {
38@@ -366,5 +363,28 @@
39 adapter_->HandleKeyboardEvent(qevent);
40 }
41
42+void WebView::GotThumbnail(const GURL& url, const gfx::Size& size,
43+ bool result, const SkBitmap& bitmap) {
44+ QUrl qurl(QString::fromStdString(url.spec()));
45+ if (result) {
46+ QImage thumbnail(static_cast<uchar*>(bitmap.getPixels()),
47+ bitmap.width(), bitmap.height(), QImage::Format_ARGB32);
48+ if ((bitmap.width() > size.width()) || (bitmap.height() > size.height())) {
49+ // CopyFromBackingStore doesn’t guarantee it will honour the requested size
50+ thumbnail = thumbnail.scaled(size.width(), size.height(),
51+ Qt::IgnoreAspectRatio,
52+ Qt::SmoothTransformation);
53+ }
54+ adapter_->GotThumbnail(qurl, thumbnail);
55+ } else {
56+ adapter_->GotThumbnail(qurl, QImage());
57+ }
58+}
59+
60+// static
61+WebView* WebView::Create(WebViewAdapter* adapter) {
62+ return new WebView(adapter);
63+}
64+
65 } // namespace qt
66 } // namespace oxide
67
68=== modified file 'qt/core/browser/oxide_qt_web_view.h'
69--- qt/core/browser/oxide_qt_web_view.h 2014-05-30 08:58:49 +0000
70+++ qt/core/browser/oxide_qt_web_view.h 2014-06-02 08:50:28 +0000
71@@ -110,6 +110,9 @@
72 void HandleKeyboardEvent(content::WebContents* source,
73 const content::NativeWebKeyboardEvent& event);
74
75+ void GotThumbnail(const GURL& url, const gfx::Size& size,
76+ bool result, const SkBitmap& bitmap) FINAL;
77+
78 WebViewAdapter* adapter_;
79
80 DISALLOW_IMPLICIT_CONSTRUCTORS(WebView);
81
82=== modified file 'qt/core/glue/oxide_qt_web_view_adapter.cc'
83--- qt/core/glue/oxide_qt_web_view_adapter.cc 2014-05-30 08:53:36 +0000
84+++ qt/core/glue/oxide_qt_web_view_adapter.cc 2014-06-02 08:50:28 +0000
85@@ -273,5 +273,9 @@
86 priv->UpdateWebPreferences();
87 }
88
89+void WebViewAdapter::requestThumbnail(const QSize& size) const {
90+ priv->RequestThumbnail(gfx::Size(size.width(), size.height()));
91+}
92+
93 } // namespace qt
94 } // namespace oxide
95
96=== modified file 'qt/core/glue/oxide_qt_web_view_adapter.h'
97--- qt/core/glue/oxide_qt_web_view_adapter.h 2014-05-30 08:58:49 +0000
98+++ qt/core/glue/oxide_qt_web_view_adapter.h 2014-06-02 08:50:28 +0000
99@@ -30,6 +30,7 @@
100 #include "qt/core/glue/oxide_qt_javascript_dialog_delegate.h"
101
102 QT_BEGIN_NAMESPACE
103+class QImage;
104 class QKeyEvent;
105 class QSize;
106 QT_END_NAMESPACE
107@@ -107,6 +108,8 @@
108
109 void updateWebPreferences();
110
111+ void requestThumbnail(const QSize& size) const;
112+
113 protected:
114 WebViewAdapter(QObject* q);
115
116@@ -175,6 +178,8 @@
117
118 virtual void HandleKeyboardEvent(QKeyEvent* event) = 0;
119
120+ virtual void GotThumbnail(const QUrl& url, const QImage& thumbnail) = 0;
121+
122 QScopedPointer<WebView> priv;
123 QList<ScriptMessageHandlerAdapter *> message_handlers_;
124 QScopedPointer<ConstructProperties> construct_props_;
125
126=== modified file 'qt/quick/CMakeLists.txt'
127--- qt/quick/CMakeLists.txt 2014-04-23 21:36:15 +0000
128+++ qt/quick/CMakeLists.txt 2014-06-02 08:50:28 +0000
129@@ -56,6 +56,7 @@
130 api/oxideqquickwebcontext.cc
131 api/oxideqquickwebcontextdelegateworker.cc
132 api/oxideqquickwebframe.cc
133+ api/oxideqquickwebthumbnail.cc
134 api/oxideqquickwebview.cc
135 api/oxidequseragentoverriderequest.cc
136 oxide_qml_plugin.cc
137
138=== added file 'qt/quick/api/oxideqquickwebthumbnail.cc'
139--- qt/quick/api/oxideqquickwebthumbnail.cc 1970-01-01 00:00:00 +0000
140+++ qt/quick/api/oxideqquickwebthumbnail.cc 2014-06-02 08:50:28 +0000
141@@ -0,0 +1,54 @@
142+// vim:expandtab:shiftwidth=2:tabstop=2:
143+// Copyright (C) 2014 Canonical Ltd.
144+
145+// This library is free software; you can redistribute it and/or
146+// modify it under the terms of the GNU Lesser General Public
147+// License as published by the Free Software Foundation; either
148+// version 2.1 of the License, or (at your option) any later version.
149+
150+// This library is distributed in the hope that it will be useful,
151+// but WITHOUT ANY WARRANTY; without even the implied warranty of
152+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
153+// Lesser General Public License for more details.
154+
155+// You should have received a copy of the GNU Lesser General Public
156+// License along with this library; if not, write to the Free Software
157+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
158+
159+#include "oxideqquickwebthumbnail_p.h"
160+#include "oxideqquickwebthumbnail_p_p.h"
161+
162+OxideQQuickWebThumbnailPrivate::OxideQQuickWebThumbnailPrivate(
163+ const QUrl& url, const QImage& thumbnail) :
164+ url_(url),
165+ thumbnail_(thumbnail) {}
166+
167+OxideQQuickWebThumbnail::OxideQQuickWebThumbnail(
168+ const QUrl& url, const QImage& thumbnail) :
169+ d_ptr(new OxideQQuickWebThumbnailPrivate(url, thumbnail)) {}
170+
171+OxideQQuickWebThumbnail::~OxideQQuickWebThumbnail() {}
172+
173+const QUrl& OxideQQuickWebThumbnail::url() const {
174+ Q_D(const OxideQQuickWebThumbnail);
175+
176+ return d->url_;
177+}
178+
179+int OxideQQuickWebThumbnail::width() const {
180+ Q_D(const OxideQQuickWebThumbnail);
181+
182+ return d->thumbnail_.width();
183+}
184+
185+int OxideQQuickWebThumbnail::height() const {
186+ Q_D(const OxideQQuickWebThumbnail);
187+
188+ return d->thumbnail_.height();
189+}
190+
191+void OxideQQuickWebThumbnail::save(const QString& fileName) const {
192+ Q_D(const OxideQQuickWebThumbnail);
193+
194+ d->thumbnail_.save(fileName);
195+}
196
197=== added file 'qt/quick/api/oxideqquickwebthumbnail_p.h'
198--- qt/quick/api/oxideqquickwebthumbnail_p.h 1970-01-01 00:00:00 +0000
199+++ qt/quick/api/oxideqquickwebthumbnail_p.h 2014-06-02 08:50:28 +0000
200@@ -0,0 +1,59 @@
201+// vim:expandtab:shiftwidth=2:tabstop=2:
202+// Copyright (C) 2014 Canonical Ltd.
203+
204+// This library is free software; you can redistribute it and/or
205+// modify it under the terms of the GNU Lesser General Public
206+// License as published by the Free Software Foundation; either
207+// version 2.1 of the License, or (at your option) any later version.
208+
209+// This library is distributed in the hope that it will be useful,
210+// but WITHOUT ANY WARRANTY; without even the implied warranty of
211+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
212+// Lesser General Public License for more details.
213+
214+// You should have received a copy of the GNU Lesser General Public
215+// License along with this library; if not, write to the Free Software
216+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
217+
218+#ifndef _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_H_
219+#define _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_H_
220+
221+#include <QObject>
222+#include <QScopedPointer>
223+#include <QtQml>
224+#include <QUrl>
225+
226+QT_BEGIN_NAMESPACE
227+class QImage;
228+class QString;
229+QT_END_NAMESPACE
230+
231+class OxideQQuickWebThumbnailPrivate;
232+
233+class OxideQQuickWebThumbnail Q_DECL_FINAL : public QObject {
234+ Q_OBJECT
235+ Q_PROPERTY(QUrl url READ url CONSTANT FINAL)
236+ Q_PROPERTY(int width READ width CONSTANT FINAL)
237+ Q_PROPERTY(int height READ height CONSTANT FINAL)
238+
239+ public:
240+ OxideQQuickWebThumbnail(const QUrl& url, const QImage& thumbnail);
241+ ~OxideQQuickWebThumbnail();
242+
243+ const QUrl& url() const;
244+ int width() const;
245+ int height() const;
246+
247+ public Q_SLOTS:
248+ void save(const QString& fileName) const;
249+
250+ private:
251+ QScopedPointer<OxideQQuickWebThumbnailPrivate> d_ptr;
252+
253+ Q_DECLARE_PRIVATE(OxideQQuickWebThumbnail)
254+ Q_DISABLE_COPY(OxideQQuickWebThumbnail)
255+};
256+
257+QML_DECLARE_TYPE(OxideQQuickWebThumbnail)
258+
259+#endif // _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_H_
260
261=== added file 'qt/quick/api/oxideqquickwebthumbnail_p_p.h'
262--- qt/quick/api/oxideqquickwebthumbnail_p_p.h 1970-01-01 00:00:00 +0000
263+++ qt/quick/api/oxideqquickwebthumbnail_p_p.h 2014-06-02 08:50:28 +0000
264@@ -0,0 +1,41 @@
265+// vim:expandtab:shiftwidth=2:tabstop=2:
266+// Copyright (C) 2014 Canonical Ltd.
267+
268+// This library is free software; you can redistribute it and/or
269+// modify it under the terms of the GNU Lesser General Public
270+// License as published by the Free Software Foundation; either
271+// version 2.1 of the License, or (at your option) any later version.
272+
273+// This library is distributed in the hope that it will be useful,
274+// but WITHOUT ANY WARRANTY; without even the implied warranty of
275+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
276+// Lesser General Public License for more details.
277+
278+// You should have received a copy of the GNU Lesser General Public
279+// License along with this library; if not, write to the Free Software
280+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
281+
282+#ifndef _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_P_H_
283+#define _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_P_H_
284+
285+#include <QImage>
286+#include <QtGlobal>
287+#include <QUrl>
288+
289+class OxideQQuickWebThumbnail;
290+
291+class OxideQQuickWebThumbnailPrivate Q_DECL_FINAL {
292+ Q_DECLARE_PUBLIC(OxideQQuickWebThumbnail)
293+
294+ private:
295+ OxideQQuickWebThumbnailPrivate(const QUrl& url, const QImage& thumbnail);
296+
297+ OxideQQuickWebThumbnail* q_ptr;
298+
299+ QUrl url_;
300+ QImage thumbnail_;
301+
302+ Q_DISABLE_COPY(OxideQQuickWebThumbnailPrivate);
303+};
304+
305+#endif // _OXIDE_QT_QUICK_API_WEB_THUMBNAIL_P_P_H_
306
307=== modified file 'qt/quick/api/oxideqquickwebview.cc'
308--- qt/quick/api/oxideqquickwebview.cc 2014-05-31 08:30:20 +0000
309+++ qt/quick/api/oxideqquickwebview.cc 2014-06-02 08:50:28 +0000
310@@ -44,6 +44,7 @@
311 #include "oxideqquickwebcontext_p_p.h"
312 #include "oxideqquickwebframe_p.h"
313 #include "oxideqquickwebframe_p_p.h"
314+#include "oxideqquickwebthumbnail_p.h"
315
316 QT_USE_NAMESPACE
317
318@@ -299,6 +300,13 @@
319 w->sendEvent(q, event);
320 }
321
322+void OxideQQuickWebViewPrivate::GotThumbnail(const QUrl& url,
323+ const QImage& thumbnail) {
324+ Q_Q(OxideQQuickWebView);
325+
326+ emit q->gotThumbnail(new OxideQQuickWebThumbnail(url, thumbnail));
327+}
328+
329 void OxideQQuickWebViewPrivate::completeConstruction() {
330 Q_Q(OxideQQuickWebView);
331
332@@ -877,4 +885,10 @@
333 d->loadHtml(html, baseUrl);
334 }
335
336+void OxideQQuickWebView::requestThumbnail(const QSize& size) {
337+ Q_D(OxideQQuickWebView);
338+
339+ d->requestThumbnail(size);
340+}
341+
342 #include "moc_oxideqquickwebview_p.cpp"
343
344=== modified file 'qt/quick/api/oxideqquickwebview_p.h'
345--- qt/quick/api/oxideqquickwebview_p.h 2014-05-30 08:58:49 +0000
346+++ qt/quick/api/oxideqquickwebview_p.h 2014-06-02 08:50:28 +0000
347@@ -28,6 +28,7 @@
348
349 QT_BEGIN_NAMESPACE
350 class QQmlComponent;
351+class QSize;
352 QT_END_NAMESPACE
353
354 QT_USE_NAMESPACE
355@@ -41,6 +42,7 @@
356 class OxideQQuickScriptMessageHandler;
357 class OxideQQuickWebContext;
358 class OxideQQuickWebFrame;
359+class OxideQQuickWebThumbnail;
360 class OxideQQuickWebView;
361 class OxideQQuickWebViewPrivate;
362
363@@ -172,6 +174,7 @@
364 void stop();
365 void reload();
366 void loadHtml(const QString& html, const QUrl& baseUrl = QUrl());
367+ void requestThumbnail(const QSize& size);
368
369 Q_SIGNALS:
370 void urlChanged();
371@@ -203,6 +206,7 @@
372 const QString& message,
373 int lineNumber,
374 const QString& sourceId);
375+ void gotThumbnail(OxideQQuickWebThumbnail* thumbnail);
376
377 private:
378 Q_PRIVATE_SLOT(d_func(), void contextConstructed());
379
380=== modified file 'qt/quick/api/oxideqquickwebview_p_p.h'
381--- qt/quick/api/oxideqquickwebview_p_p.h 2014-05-30 08:58:49 +0000
382+++ qt/quick/api/oxideqquickwebview_p_p.h 2014-06-02 08:50:28 +0000
383@@ -100,6 +100,8 @@
384
385 void HandleKeyboardEvent(QKeyEvent *event) Q_DECL_FINAL;
386
387+ void GotThumbnail(const QUrl& url, const QImage& thumbnail) Q_DECL_FINAL;
388+
389 void completeConstruction();
390
391 static void messageHandler_append(
392
393=== modified file 'qt/quick/oxide_qml_plugin.cc'
394--- qt/quick/oxide_qml_plugin.cc 2014-05-07 14:06:05 +0000
395+++ qt/quick/oxide_qml_plugin.cc 2014-06-02 08:50:28 +0000
396@@ -35,6 +35,7 @@
397 #include "qt/quick/api/oxideqquickwebcontext_p.h"
398 #include "qt/quick/api/oxideqquickwebcontextdelegateworker_p.h"
399 #include "qt/quick/api/oxideqquickwebframe_p.h"
400+#include "qt/quick/api/oxideqquickwebthumbnail_p.h"
401 #include "qt/quick/api/oxideqquickwebview_p.h"
402
403 QT_USE_NAMESPACE
404@@ -78,6 +79,8 @@
405 "OutgoingMessageRequests are created automatically by WebFrame.sendMessage");
406 qmlRegisterUncreatableType<OxideQQuickWebFrame>(uri, 1, 0, "WebFrame",
407 "Frames are created automatically by Oxide to represent frames in the renderer");
408+ qmlRegisterUncreatableType<OxideQQuickWebThumbnail>(uri, 1, 0, "WebThumbnail",
409+ "WebThumbnails are created automatically by Oxide");
410
411 qmlRegisterType<OxideQQuickScriptMessageHandler>(uri, 1, 0, "ScriptMessageHandler");
412 qmlRegisterType<OxideQQuickUserScript>(uri, 1, 0, "UserScript");
413
414=== added file 'qt/tests/qmltests/api/tst_WebView_thumbnail.qml'
415--- qt/tests/qmltests/api/tst_WebView_thumbnail.qml 1970-01-01 00:00:00 +0000
416+++ qt/tests/qmltests/api/tst_WebView_thumbnail.qml 2014-06-02 08:50:28 +0000
417@@ -0,0 +1,44 @@
418+import QtQuick 2.0
419+import QtTest 1.0
420+import com.canonical.Oxide.Testing 1.0
421+
422+TestWebView {
423+ id: webView
424+ focus: true
425+ width: 200
426+ height: 200
427+
428+ SignalSpy {
429+ id: spy
430+ target: webView
431+ signalName: "gotThumbnail"
432+ }
433+
434+ TestCase {
435+ name: "WebView_thumbnail"
436+ when: windowShown
437+
438+ function test_requestThumbnail_data() {
439+ return [
440+ { requested: Qt.size(50, 50), expected: Qt.size(50, 50) },
441+ { requested: Qt.size(50, 75), expected: Qt.size(50, 75) },
442+ { requested: Qt.size(75, 50), expected: Qt.size(75, 50) },
443+ // Account for the clipping of scrollbars (15px, assuming this test
444+ // will be run on desktop where overlay scrollbars are not enabled).
445+ { requested: Qt.size(300, 300), expected: Qt.size(185, 185) }
446+ ];
447+ }
448+
449+ function test_requestThumbnail(data) {
450+ webView.url = "http://localhost:8080/empty.html";
451+ verify(webView.waitForLoadSucceeded(),
452+ "Timed out waiting for successful load");
453+ webView.requestThumbnail(data.requested);
454+ spy.wait();
455+ var thumbnail = spy.signalArguments[spy.count - 1][0];
456+ compare(thumbnail.url, webView.url);
457+ compare(thumbnail.width, data.expected.width);
458+ compare(thumbnail.height, data.expected.height);
459+ }
460+ }
461+}
462
463=== modified file 'shared/browser/oxide_render_widget_host_view.cc'
464--- shared/browser/oxide_render_widget_host_view.cc 2014-05-19 10:10:11 +0000
465+++ shared/browser/oxide_render_widget_host_view.cc 2014-06-02 08:50:28 +0000
466@@ -270,6 +270,7 @@
467 const gfx::Size& dst_size,
468 const base::Callback<void(bool, const SkBitmap&)>& callback,
469 const SkBitmap::Config config) {
470+ NOTIMPLEMENTED();
471 callback.Run(false, SkBitmap());
472 }
473
474
475=== modified file 'shared/browser/oxide_render_widget_host_view.h'
476--- shared/browser/oxide_render_widget_host_view.h 2014-05-19 09:32:11 +0000
477+++ shared/browser/oxide_render_widget_host_view.h 2014-06-02 08:50:28 +0000
478@@ -103,6 +103,8 @@
479 // content::RenderWidgetHostView
480 content::RenderWidgetHost* GetRenderWidgetHost() const FINAL;
481
482+ virtual gfx::Size GetPhysicalBackingSize() const = 0;
483+
484 void SetBounds(const gfx::Rect& rect) FINAL;
485
486 protected:
487
488=== modified file 'shared/browser/oxide_web_view.cc'
489--- shared/browser/oxide_web_view.cc 2014-05-31 08:35:36 +0000
490+++ shared/browser/oxide_web_view.cc 2014-06-02 08:50:28 +0000
491@@ -43,14 +43,15 @@
492 #include "content/public/common/url_constants.h"
493 #include "net/base/net_errors.h"
494 #include "ui/base/window_open_disposition.h"
495+#include "ui/gfx/scrollbar_size.h"
496 #include "url/gurl.h"
497 #include "webkit/common/webpreferences.h"
498
499 #include "shared/common/oxide_content_client.h"
500
501-#include "oxide_browser_process_main.h"
502 #include "oxide_content_browser_client.h"
503 #include "oxide_file_picker.h"
504+#include "oxide_form_factor.h"
505 #include "oxide_render_widget_host_view.h"
506 #include "oxide_web_contents_view.h"
507 #include "oxide_web_frame.h"
508@@ -938,4 +939,38 @@
509 return false;
510 }
511
512+void WebView::RequestThumbnail(const gfx::Size& size) {
513+ RenderWidgetHostView* rwhv = static_cast<RenderWidgetHostView *>(
514+ web_contents_->GetRenderWidgetHostView());
515+ if (!rwhv) {
516+ return;
517+ }
518+ gfx::Rect copy_rect(rwhv->GetPhysicalBackingSize());
519+
520+ if (GetFormFactorHint() == FORM_FACTOR_DESKTOP) {
521+ // Clip the pixels that will commonly hold a scrollbar,
522+ // which looks bad in thumbnails.
523+ int scrollbar_size = gfx::scrollbar_size();
524+ copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size);
525+ }
526+
527+ // Crop the target region to match the aspect ratio of the requested size.
528+ int c1 = size.width() * copy_rect.height();
529+ int c2 = copy_rect.width() * size.height();
530+ if (c1 > c2) {
531+ copy_rect.set_height(c2 / size.width());
532+ } else if (c1 < c2) {
533+ copy_rect.set_width(c1 / size.height());
534+ }
535+
536+ if (!copy_rect.IsEmpty()) {
537+ content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
538+ rvh->CopyFromBackingStore(
539+ copy_rect, size,
540+ base::Bind(
541+ &WebView::GotThumbnail, base::Unretained(this), GetURL(), size),
542+ SkBitmap::kARGB_8888_Config);
543+ }
544+}
545+
546 } // namespace oxide
547
548=== modified file 'shared/browser/oxide_web_view.h'
549--- shared/browser/oxide_web_view.h 2014-05-30 08:58:49 +0000
550+++ shared/browser/oxide_web_view.h 2014-06-02 08:50:28 +0000
551@@ -41,6 +41,7 @@
552 #include "shared/common/oxide_message_enums.h"
553
554 class GURL;
555+class SkBitmap;
556
557 namespace gfx {
558 class Size;
559@@ -170,6 +171,8 @@
560
561 virtual bool CanCreateWindows() const;
562
563+ void RequestThumbnail(const gfx::Size& size);
564+
565 protected:
566 WebView();
567
568@@ -307,6 +310,9 @@
569 virtual WebView* CreateNewWebView(const gfx::Rect& initial_pos,
570 WindowOpenDisposition disposition);
571
572+ virtual void GotThumbnail(const GURL& url, const gfx::Size& size,
573+ bool result, const SkBitmap& bitmap) = 0;
574+
575 scoped_ptr<content::WebContentsImpl> web_contents_;
576 WebViewContentsHelper* web_contents_helper_;
577

Subscribers

People subscribed via source and target branches