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

Unified Diff: Source/core/html/canvas/MouseEventHitRegion.h

Issue 300223009: Implement basic parts of hit regions on canvas2d. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressed comments Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/html/canvas/MouseEventHitRegion.h
diff --git a/Source/core/html/canvas/MouseEventHitRegion.h b/Source/core/html/canvas/MouseEventHitRegion.h
new file mode 100644
index 0000000000000000000000000000000000000000..19215daad8757b12d3b8540034c5a73c5746f2cc
--- /dev/null
+++ b/Source/core/html/canvas/MouseEventHitRegion.h
@@ -0,0 +1,46 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MouseEventHitRegion_h
+#define MouseEventHitRegion_h
+
+#include "core/events/MouseEvent.h"
+#include "core/html/HTMLCanvasElement.h"
+#include "core/html/canvas/CanvasRenderingContext.h"
+#include "core/html/canvas/CanvasRenderingContext2D.h"
+
+namespace WebCore {
+
+class MouseEventHitRegion {
+public:
+ static String region(MouseEvent& event, bool& isNull)
+ {
+ if (!isHTMLCanvasElement(event.target()->toNode())) {
+ isNull = true;
+ return String();
+ }
+
+ HTMLCanvasElement* canvas = toHTMLCanvasElement(event.target()->toNode());
+ CanvasRenderingContext* context = canvas->renderingContext();
+ if (!context || !context->is2d()) {
+ isNull = true;
+ return String();
+ }
+
+ HitRegion* hitRegion = toCanvasRenderingContext2D(context)->
+ hitRegionAtPoint(LayoutPoint(event.offsetX(), event.offsetY()));
+
+ String id;
+ if (hitRegion)
+ id = hitRegion->id();
+
+ isNull = id.isEmpty();
+
+ return id;
+ }
+};
+
+} // namespace WebCore
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698