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

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

Issue 1654653002: Canvas2d: Implement rerouting event by hit region's control. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix bot errors Created 4 years, 9 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
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698