summaryrefslogtreecommitdiffstats
path: root/src/core/render_widget_host_view_qt.cpp
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2018-05-22 16:17:16 +0200
committerJüri Valdmann <juri.valdmann@qt.io>2018-06-05 14:09:29 +0000
commitedaef97bc20ae2aff35600110273dc46da0eee8b (patch)
treeace2d79fba7d3a73d7d69b56cc71e0999b0cc0b4 /src/core/render_widget_host_view_qt.cpp
parent94b2d1fd7525f1086276b3d093775b71e7f4aa21 (diff)
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 <michal.klocek@qt.io>
Diffstat (limited to 'src/core/render_widget_host_view_qt.cpp')
-rw-r--r--src/core/render_widget_host_view_qt.cpp29
1 files changed, 25 insertions, 4 deletions
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