From edaef97bc20ae2aff35600110273dc46da0eee8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Tue, 22 May 2018 16:17:16 +0200 Subject: Fix WebCursor scaling and hotspot Old behavior: - Hotspot always chosen according to 2x devicePixelRatio. - Image always chosen according to 1x devicePixelRatio. New behavior: - Use actual devicePixelRatio. Task-number: QTBUG-68376 Change-Id: I6eef12a7dcf7fde7f8f488d9f2cba99f21e73cc2 Reviewed-by: Michal Klocek --- src/core/render_widget_host_view_qt.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/core/render_widget_host_view_qt.cpp') diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index ec3add2f6..443a299ac 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -68,12 +68,14 @@ #include "third_party/WebKit/public/platform/WebColor.h" #include "third_party/WebKit/public/platform/WebCursorInfo.h" #include "ui/base/clipboard/scoped_clipboard_writer.h" +#include "ui/base/resource/resource_bundle.h" #include "ui/events/blink/blink_event_util.h" #include "ui/events/event.h" #include "ui/events/gesture_detection/gesture_provider_config_helper.h" #include "ui/events/gesture_detection/motion_event.h" #include "ui/events/keycodes/keyboard_codes.h" #include "ui/gfx/geometry/size_conversions.h" +#include "ui/gfx/image/image_skia.h" #if defined(USE_AURA) #include "ui/base/cursor/cursor.h" @@ -674,11 +676,30 @@ void RenderWidgetHostViewQt::UpdateCursor(const content::WebCursor &webCursor) } #if defined(USE_AURA) if (auraType != ui::CursorType::kNull) { - SkBitmap bitmap; + QWindow *window = m_delegate->window(); + qreal windowDpr = window ? window->devicePixelRatio() : 1.0f; + int resourceId; gfx::Point hotspot; - if (ui::GetCursorBitmap(auraType, &bitmap, &hotspot)) { - m_delegate->updateCursor(QCursor(QPixmap::fromImage(toQImage(bitmap)), hotspot.x(), hotspot.y())); - return; + // GetCursorDataFor only knows hotspots for 1x and 2x cursor images, in physical pixels. + qreal hotspotDpr = windowDpr <= 1.0f ? 1.0f : 2.0f; + if (ui::GetCursorDataFor(ui::CursorSize::kNormal, auraType, hotspotDpr, &resourceId, &hotspot)) { + if (const gfx::ImageSkia *imageSkia = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resourceId)) { + QImage imageQt = toQImage(imageSkia->GetRepresentation(windowDpr)); + + // Convert hotspot coordinates into device-independent pixels. + qreal hotX = hotspot.x() / hotspotDpr; + qreal hotY = hotspot.y() / hotspotDpr; + +#if defined(Q_OS_LINUX) + // QTBUG-68571: On Linux (xcb, wayland, eglfs), hotspot coordinates must be in physical pixels. + qreal imageDpr = imageQt.devicePixelRatio(); + hotX *= imageDpr; + hotY *= imageDpr; +#endif + + m_delegate->updateCursor(QCursor(QPixmap::fromImage(std::move(imageQt)), qRound(hotX), qRound(hotY))); + return; + } } } #endif -- cgit v1.2.3