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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/canvas/resources/test-helpers.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/canvas2d/EventHitRegion.h" 5 #include "modules/canvas2d/EventHitRegion.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/html/HTMLCanvasElement.h" 8 #include "core/html/HTMLCanvasElement.h"
9 #include "core/layout/LayoutObject.h" 9 #include "core/layout/LayoutBox.h"
10 #include "core/page/Page.h"
10 #include "modules/canvas2d/CanvasRenderingContext2D.h" 11 #include "modules/canvas2d/CanvasRenderingContext2D.h"
11 #include "modules/canvas2d/HitRegion.h" 12 #include "modules/canvas2d/HitRegion.h"
12 13
13 namespace blink { 14 namespace blink {
14 15
15 String EventHitRegion::regionIdFromAbsoluteLocation(HTMLCanvasElement& canvas, c onst LayoutPoint& location) 16 String EventHitRegion::regionIdFromAbsoluteLocation(HTMLCanvasElement& canvas, c onst LayoutPoint& location)
16 { 17 {
17 CanvasRenderingContext* context = canvas.renderingContext(); 18 CanvasRenderingContext* context = canvas.renderingContext();
18 if (!context || !context->is2d()) 19 if (!context || !context->is2d())
19 return String(); 20 return String();
20 21
21 Document& document = canvas.document(); 22 Document& document = canvas.document();
22 document.updateLayoutTreeForNodeIfNeeded(&canvas); 23 document.updateLayoutTreeForNodeIfNeeded(&canvas);
23 24
24 // Adjust offsetLocation to be relative to the canvas's position. 25 // Adjust offsetLocation to be relative to the canvas's position.
25 LayoutObject* layoutObject = canvas.layoutObject(); 26 LayoutBox* box = canvas.layoutBox();
26 FloatPoint localPos = layoutObject->absoluteToLocal(FloatPoint(location), Us eTransforms); 27 FloatPoint localPos = box->absoluteToLocal(FloatPoint(location), UseTransfor ms);
27 28 if (box->hasBorderOrPadding())
28 LocalFrame* frame = document.frame(); 29 localPos.move(-box->contentBoxOffset());
29 float zoomFactor = frame ? frame->pageZoomFactor() : 1; 30 localPos.scale(canvas.width() / box->contentWidth(), canvas.height() / box-> contentHeight());
30 float scaleFactor = 1 / zoomFactor;
31 if (scaleFactor != 1.0f)
32 localPos.scale(scaleFactor, scaleFactor);
33 31
34 HitRegion* hitRegion = toCanvasRenderingContext2D(context)->hitRegionAtPoint (localPos); 32 HitRegion* hitRegion = toCanvasRenderingContext2D(context)->hitRegionAtPoint (localPos);
35 if (!hitRegion || hitRegion->id().isEmpty()) 33 if (!hitRegion || hitRegion->id().isEmpty())
36 return String(); 34 return String();
37 35
38 return hitRegion->id(); 36 return hitRegion->id();
39 } 37 }
40 38
41 } // namespace blink 39 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/canvas/resources/test-helpers.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698