| OLD | NEW |
| 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 |
| OLD | NEW |