| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "modules/canvas2d/EventHitRegion.h" | |
| 6 | |
| 7 #include "core/dom/Document.h" | |
| 8 #include "core/html/HTMLCanvasElement.h" | |
| 9 #include "core/layout/LayoutBox.h" | |
| 10 #include "core/page/Page.h" | |
| 11 #include "modules/canvas2d/CanvasRenderingContext2D.h" | |
| 12 #include "modules/canvas2d/HitRegion.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 String EventHitRegion::regionIdFromAbsoluteLocation(HTMLCanvasElement& canvas, c
onst LayoutPoint& location) | |
| 17 { | |
| 18 CanvasRenderingContext* context = canvas.renderingContext(); | |
| 19 if (!context || !context->is2d()) | |
| 20 return String(); | |
| 21 | |
| 22 Document& document = canvas.document(); | |
| 23 document.updateLayoutTreeForNode(&canvas); | |
| 24 | |
| 25 // Adjust offsetLocation to be relative to the canvas's position. | |
| 26 LayoutBox* box = canvas.layoutBox(); | |
| 27 FloatPoint localPos = box->absoluteToLocal(FloatPoint(location), UseTransfor
ms); | |
| 28 if (box->hasBorderOrPadding()) | |
| 29 localPos.move(-box->contentBoxOffset()); | |
| 30 localPos.scale(canvas.width() / box->contentWidth(), canvas.height() / box->
contentHeight()); | |
| 31 | |
| 32 HitRegion* hitRegion = toCanvasRenderingContext2D(context)->hitRegionAtPoint
(localPos); | |
| 33 if (!hitRegion || hitRegion->id().isEmpty()) | |
| 34 return String(); | |
| 35 | |
| 36 return hitRegion->id(); | |
| 37 } | |
| 38 | |
| 39 } // namespace blink | |
| OLD | NEW |