Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(858)

Unified Diff: third_party/WebKit/Source/modules/canvas2d/EventHitRegion.cpp

Issue 1553373002: Canvas2d: Fix incorrect alignment of hit region when applied css/zoom. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/canvas2d/EventHitRegion.cpp
diff --git a/third_party/WebKit/Source/modules/canvas2d/EventHitRegion.cpp b/third_party/WebKit/Source/modules/canvas2d/EventHitRegion.cpp
index fe7393ff5208476568d58103af3c2c92aed56df5..647710e09626e89867ac61957967d185f41fe9c6 100644
--- a/third_party/WebKit/Source/modules/canvas2d/EventHitRegion.cpp
+++ b/third_party/WebKit/Source/modules/canvas2d/EventHitRegion.cpp
@@ -6,7 +6,8 @@
#include "core/dom/Document.h"
#include "core/html/HTMLCanvasElement.h"
-#include "core/layout/LayoutObject.h"
+#include "core/layout/LayoutBox.h"
+#include "core/page/Page.h"
#include "modules/canvas2d/CanvasRenderingContext2D.h"
#include "modules/canvas2d/HitRegion.h"
@@ -22,12 +23,22 @@ String EventHitRegion::regionIdFromAbsoluteLocation(HTMLCanvasElement& canvas, c
document.updateLayoutTreeForNodeIfNeeded(&canvas);
// Adjust offsetLocation to be relative to the canvas's position.
- LayoutObject* layoutObject = canvas.layoutObject();
- FloatPoint localPos = layoutObject->absoluteToLocal(FloatPoint(location), UseTransforms);
-
- LocalFrame* frame = document.frame();
- float zoomFactor = frame ? frame->pageZoomFactor() : 1;
- float scaleFactor = 1 / zoomFactor;
+ LayoutBoxModelObject* lbmo = canvas.layoutBoxModelObject();
+ FloatPoint localPos = lbmo->absoluteToLocal(FloatPoint(location), UseTransforms);
+
+ float width = lbmo->offsetWidth();
+ float height = lbmo->offsetHeight();
+ if (lbmo->hasBorderOrPadding()) {
+ float borderAndPaddingLeft = lbmo->borderLeft() + lbmo->paddingLeft();
+ float borderAndPaddingTop = lbmo->borderTop() + lbmo->paddingTop();
+ localPos.move(-borderAndPaddingLeft, -borderAndPaddingTop);
+ width -= lbmo->borderAndPaddingWidth();
+ height -= lbmo->borderAndPaddingHeight();
Justin Novosad 2016/01/05 16:48:39 Isn't there a method that already computes these w
zino 2016/01/06 17:22:31 Done.
+ }
+ localPos.scale((canvas.width() / width), (canvas.height() / height));
+
+ Page* page = document.page();
+ float scaleFactor = page->deviceScaleFactor();
if (scaleFactor != 1.0f)
localPos.scale(scaleFactor, scaleFactor);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698