diff options
author | Arvid Nilsson <anilsson@blackberry.com> | 2013-11-28 15:29:40 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-04 14:23:33 +0100 |
commit | 5d66b66df1bc205a9ce3d25cfaaa84c961fa7a29 (patch) | |
tree | b99b54d09ba93dbe66a65313c50ac6d831e5a8d0 /src/core | |
parent | 5d92938e5bb830b8ca5a711fd4c1999dd09fd0e3 (diff) |
Quick: Add experimental.viewport.devicePixelRatio
This specifies a devicePixelRatio to be used by web content instead of
the QScreen::devicePixelRatio(). This is necessary on non-iOS mobile
devices to remain compatible with the mobile web which assumes
devicePixelRatio is computed as the ratio of actual dpi to 160 dpi.
Non-iOS mobile platforms may use different criteria to determine the
QScreen::devicePixelRatio(), depending on the history of the platform,
or simply leave it at 1.0.
For QNX, this setting gets a reasonable default value so developers
don't have to regularly use this experimental API.
These changes were inspired by the Android Chromium port which uses a
GetDpiScale() to accomplish the same in
content/browser/android/content_view_core_impl.cc.
Change-Id: I1bc8878a47dabcdb6986c4fe5c8c4ac230ae2514
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/render_widget_host_view_qt.cpp | 23 | ||||
-rw-r--r-- | src/core/render_widget_host_view_qt.h | 1 | ||||
-rw-r--r-- | src/core/type_conversion.h | 5 | ||||
-rw-r--r-- | src/core/web_contents_adapter.cpp | 11 | ||||
-rw-r--r-- | src/core/web_contents_adapter.h | 2 | ||||
-rw-r--r-- | src/core/web_contents_adapter_client.h | 1 | ||||
-rw-r--r-- | src/core/web_event_factory.cpp | 18 | ||||
-rw-r--r-- | src/core/web_event_factory.h | 6 |
8 files changed, 49 insertions, 18 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index e2df54afe..20c1dc4fe 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -46,6 +46,7 @@ #include "delegated_frame_node.h" #include "render_widget_host_view_qt_delegate.h" #include "type_conversion.h" +#include "web_contents_adapter_client.h" #include "web_event_factory.h" #include "cc/output/compositor_frame_ack.h" @@ -225,7 +226,8 @@ gfx::Size RenderWidgetHostViewQt::GetPhysicalBackingSize() const return gfx::Size(); const QScreen* screen = m_delegate->window()->screen(); - return gfx::ToCeiledSize(gfx::ScaleSize(GetViewBounds().size(), screen->devicePixelRatio())); + gfx::SizeF size = toGfx(m_delegate->screenRect().size()); + return gfx::ToCeiledSize(gfx::ScaleSize(size, screen->devicePixelRatio())); } gfx::NativeView RenderWidgetHostViewQt::GetNativeView() const @@ -290,7 +292,10 @@ bool RenderWidgetHostViewQt::IsShowing() gfx::Rect RenderWidgetHostViewQt::GetViewBounds() const { QRectF p = m_delegate->screenRect(); - return gfx::Rect(p.x(), p.y(), p.width(), p.height()); + float s = dpiScale(); + gfx::Point p1(floor(p.x() / s), floor(p.y() / s)); + gfx::Point p2(ceil(p.right() /s), ceil(p.bottom() / s)); + return gfx::BoundingRect(p1, p2); } // Subclasses should override this method to do what is appropriate to set @@ -592,6 +597,7 @@ void RenderWidgetHostViewQt::GetScreenInfo(WebKit::WebScreenInfo* results) if (!window) return; GetScreenInfoFromNativeWindow(window, results); + results->deviceScaleFactor *= dpiScale(); } gfx::Rect RenderWidgetHostViewQt::GetBoundsInRootWindow() @@ -814,6 +820,11 @@ void RenderWidgetHostViewQt::RemoveExpiredMappings(QTouchEvent *ev) m_touchIdMapping.swap(newMap); } +float RenderWidgetHostViewQt::dpiScale() const +{ + return m_adapterClient->dpiScale(); +} + bool RenderWidgetHostViewQt::IsPopup() const { return popup_type_ != WebKit::WebPopupTypeNone; @@ -825,7 +836,7 @@ void RenderWidgetHostViewQt::handleMouseEvent(QMouseEvent* event) if (eventType == QEvent::MouseButtonDblClick) return; - WebKit::WebMouseEvent webEvent = WebEventFactory::toWebMouseEvent(event); + WebKit::WebMouseEvent webEvent = WebEventFactory::toWebMouseEvent(event, dpiScale()); if (eventType == QMouseEvent::MouseButtonPress) { if (event->button() != m_clickHelper.lastPressButton || (event->timestamp() - m_clickHelper.lastPressTimestamp > static_cast<ulong>(qGuiApp->styleHints()->mouseDoubleClickInterval())) @@ -848,7 +859,7 @@ void RenderWidgetHostViewQt::handleKeyEvent(QKeyEvent *ev) void RenderWidgetHostViewQt::handleWheelEvent(QWheelEvent *ev) { - m_host->ForwardWheelEvent(WebEventFactory::toWebWheelEvent(ev)); + m_host->ForwardWheelEvent(WebEventFactory::toWebWheelEvent(ev, dpiScale())); } void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) @@ -866,7 +877,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) ui::TouchEvent uiEvent( toUIEventType(touchPoint.state()), - toGfxPoint(touchPoint.pos().toPoint()), + toGfxPoint((touchPoint.pos() / dpiScale()).toPoint()), 0, // flags GetMappedTouch(touchPoint.id()), timestamp, @@ -892,7 +903,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) void RenderWidgetHostViewQt::handleHoverEvent(QHoverEvent *ev) { - m_host->ForwardMouseEvent(WebEventFactory::toWebMouseEvent(ev)); + m_host->ForwardMouseEvent(WebEventFactory::toWebMouseEvent(ev, dpiScale())); } void RenderWidgetHostViewQt::handleFocusEvent(QFocusEvent *ev) diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h index c0905ffeb..e7fab3ff5 100644 --- a/src/core/render_widget_host_view_qt.h +++ b/src/core/render_widget_host_view_qt.h @@ -205,6 +205,7 @@ private: void ProcessGestures(ui::GestureRecognizer::Gestures *gestures); int GetMappedTouch(int qtTouchId); void RemoveExpiredMappings(QTouchEvent *ev); + float dpiScale() const; bool IsPopup() const; diff --git a/src/core/type_conversion.h b/src/core/type_conversion.h index 0f0a8ab60..94e30d72b 100644 --- a/src/core/type_conversion.h +++ b/src/core/type_conversion.h @@ -93,6 +93,11 @@ inline QSize toQt(const gfx::Size &size) return QSize(size.width(), size.height()); } +inline gfx::SizeF toGfx(const QSizeF& size) +{ + return gfx::SizeF(size.width(), size.height()); +} + inline QSizeF toQt(const gfx::SizeF &size) { return QSizeF(size.width(), size.height()); diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index c09fc362a..f3caa7478 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -49,6 +49,7 @@ #include "web_engine_context.h" #include "base/values.h" +#include "content/browser/renderer_host/render_view_host_impl.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" @@ -344,3 +345,13 @@ void WebContentsAdapter::runJavaScript(const QString &javaScript, const QString rvh->ExecuteJavascriptInWebFrameCallbackResult(toString16(xPath), toString16(javaScript), callback); } } + +void WebContentsAdapter::dpiScaleChanged() +{ + Q_D(WebContentsAdapter); + content::RenderWidgetHostImpl* impl = NULL; + if (d->webContents->GetRenderViewHost()) + impl = content::RenderWidgetHostImpl::From(d->webContents->GetRenderViewHost()); + if (impl) + impl->NotifyScreenInfoChanged(); +} diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h index f631b6d69..4bad8aa9b 100644 --- a/src/core/web_contents_adapter.h +++ b/src/core/web_contents_adapter.h @@ -89,6 +89,8 @@ public: void enableInspector(bool); void runJavaScript(const QString &javaScript, const QString &xPath = QString(), JSCallbackBase * = 0); + void dpiScaleChanged(); + private: Q_DISABLE_COPY(WebContentsAdapter); Q_DECLARE_PRIVATE(WebContentsAdapter); diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index c7746ffb1..dad77cf57 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -108,6 +108,7 @@ public: virtual void loadingStateChanged() = 0; virtual void loadProgressChanged(int progress) = 0; virtual QRectF viewportRect() const = 0; + virtual qreal dpiScale() const = 0; virtual void loadFinished(bool success) = 0; virtual void focusContainer() = 0; virtual void adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, const QRect & initialGeometry) = 0; diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp index d750aa3e0..febad0a3a 100644 --- a/src/core/web_event_factory.cpp +++ b/src/core/web_event_factory.cpp @@ -527,15 +527,15 @@ static WebInputEvent::Type webEventTypeForEvent(const QEvent* event) } } -WebMouseEvent WebEventFactory::toWebMouseEvent(QMouseEvent *ev) +WebMouseEvent WebEventFactory::toWebMouseEvent(QMouseEvent *ev, double dpiScale) { WebMouseEvent webKitEvent; webKitEvent.timeStampSeconds = currentTimeForEvent(ev); webKitEvent.button = mouseButtonForEvent(ev); webKitEvent.modifiers = modifiersForEvent(ev); - webKitEvent.x = webKitEvent.windowX = ev->x(); - webKitEvent.y = webKitEvent.windowY = ev->y(); + webKitEvent.x = webKitEvent.windowX = ev->x() / dpiScale; + webKitEvent.y = webKitEvent.windowY = ev->y() / dpiScale; webKitEvent.globalX = ev->globalX(); webKitEvent.globalY = ev->globalY(); @@ -545,20 +545,20 @@ WebMouseEvent WebEventFactory::toWebMouseEvent(QMouseEvent *ev) return webKitEvent; } -WebMouseEvent WebEventFactory::toWebMouseEvent(QHoverEvent *ev) +WebMouseEvent WebEventFactory::toWebMouseEvent(QHoverEvent *ev, double dpiScale) { WebMouseEvent webKitEvent; webKitEvent.timeStampSeconds = currentTimeForEvent(ev); webKitEvent.modifiers = modifiersForEvent(ev); - webKitEvent.x = webKitEvent.windowX = ev->pos().x(); - webKitEvent.y = webKitEvent.windowY = ev->pos().y(); + webKitEvent.x = webKitEvent.windowX = ev->pos().x() / dpiScale; + webKitEvent.y = webKitEvent.windowY = ev->pos().y() / dpiScale; webKitEvent.type = webEventTypeForEvent(ev); return webKitEvent; } -WebKit::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev) +WebKit::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev, double dpiScale) { WebMouseWheelEvent webEvent; webEvent.type = webEventTypeForEvent(ev); @@ -582,8 +582,8 @@ WebKit::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev) webEvent.deltaX = webEvent.wheelTicksX * wheelScrollLines * cDefaultQtScrollStep; webEvent.deltaY = webEvent.wheelTicksY * wheelScrollLines * cDefaultQtScrollStep; - webEvent.x = webEvent.windowX = ev->x(); - webEvent.y = webEvent.windowY = ev->y(); + webEvent.x = webEvent.windowX = ev->x() / dpiScale; + webEvent.y = webEvent.windowY = ev->y() / dpiScale; webEvent.globalX = ev->globalX(); webEvent.globalY = ev->globalY(); return webEvent; diff --git a/src/core/web_event_factory.h b/src/core/web_event_factory.h index e5ee91510..29a75a285 100644 --- a/src/core/web_event_factory.h +++ b/src/core/web_event_factory.h @@ -57,9 +57,9 @@ QT_END_NAMESPACE class WebEventFactory { public: - static WebKit::WebMouseEvent toWebMouseEvent(QMouseEvent*); - static WebKit::WebMouseEvent toWebMouseEvent(QHoverEvent*); - static WebKit::WebMouseWheelEvent toWebWheelEvent(QWheelEvent*); + static WebKit::WebMouseEvent toWebMouseEvent(QMouseEvent*, double dpiScale); + static WebKit::WebMouseEvent toWebMouseEvent(QHoverEvent*, double dpiScale); + static WebKit::WebMouseWheelEvent toWebWheelEvent(QWheelEvent*, double dpiScale); static content::NativeWebKeyboardEvent toWebKeyboardEvent(QKeyEvent*); }; |