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/render_widget_host_view_qt.cpp | |
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/render_widget_host_view_qt.cpp')
-rw-r--r-- | src/core/render_widget_host_view_qt.cpp | 23 |
1 files changed, 17 insertions, 6 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) |