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

Side by Side Diff: Source/modules/canvas2d/EventHitRegion.cpp

Issue 1259973002: Canvas2d: Remove unnecessary conversion in EventHitRegion. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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
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 "config.h" 5 #include "config.h"
6 #include "modules/canvas2d/EventHitRegion.h" 6 #include "modules/canvas2d/EventHitRegion.h"
7 7
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/html/HTMLCanvasElement.h" 9 #include "core/html/HTMLCanvasElement.h"
10 #include "core/layout/LayoutObject.h" 10 #include "core/layout/LayoutObject.h"
11 #include "modules/canvas2d/CanvasRenderingContext2D.h" 11 #include "modules/canvas2d/CanvasRenderingContext2D.h"
12 #include "modules/canvas2d/HitRegion.h" 12 #include "modules/canvas2d/HitRegion.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 String EventHitRegion::regionIdFromAbsoluteLocation(HTMLCanvasElement& canvas, c onst LayoutPoint& location) 16 String EventHitRegion::regionIdFromAbsoluteLocation(HTMLCanvasElement& canvas, c onst LayoutPoint& location)
17 { 17 {
18 CanvasRenderingContext* context = canvas.renderingContext(); 18 CanvasRenderingContext* context = canvas.renderingContext();
19 if (!context || !context->is2d()) 19 if (!context || !context->is2d())
20 return String(); 20 return String();
21 21
22 Document& document = canvas.document(); 22 Document& document = canvas.document();
23 document.updateLayoutTreeForNodeIfNeeded(&canvas); 23 document.updateLayoutTreeForNodeIfNeeded(&canvas);
24 24
25 // Adjust offsetLocation to be relative to the canvas's position. 25 // Adjust offsetLocation to be relative to the canvas's position.
26 LayoutObject* layoutObject = canvas.layoutObject(); 26 LayoutObject* layoutObject = canvas.layoutObject();
27 FloatPoint localPos = layoutObject->absoluteToLocal(FloatPoint(location), Us eTransforms); 27 FloatPoint localPos = layoutObject->absoluteToLocal(FloatPoint(location), Us eTransforms);
28 LayoutPoint localLayoutPoint = roundedLayoutPoint(localPos);
29 28
30 LocalFrame* frame = document.frame(); 29 LocalFrame* frame = document.frame();
31 float zoomFactor = frame ? frame->pageZoomFactor() : 1; 30 float zoomFactor = frame ? frame->pageZoomFactor() : 1;
32 float scaleFactor = 1 / zoomFactor; 31 float scaleFactor = 1 / zoomFactor;
33 if (scaleFactor != 1.0f) 32 if (scaleFactor != 1.0f)
34 localLayoutPoint.scale(scaleFactor, scaleFactor); 33 localPos.scale(scaleFactor, scaleFactor);
35 34
36 HitRegion* hitRegion = toCanvasRenderingContext2D(context)->hitRegionAtPoint (localLayoutPoint); 35 HitRegion* hitRegion = toCanvasRenderingContext2D(context)->hitRegionAtPoint (localPos);
37 if (!hitRegion || hitRegion->id().isEmpty()) 36 if (!hitRegion || hitRegion->id().isEmpty())
38 return String(); 37 return String();
39 38
40 return hitRegion->id(); 39 return hitRegion->id();
41 } 40 }
42 41
43 } // namespace blink 42 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/canvas2d/CanvasRenderingContext2D.cpp ('k') | Source/modules/canvas2d/HitRegion.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698