| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef MouseEventHitRegion_h | 5 #ifndef MouseEventHitRegion_h |
| 6 #define MouseEventHitRegion_h | 6 #define MouseEventHitRegion_h |
| 7 | 7 |
| 8 #include "core/events/MouseEvent.h" | 8 #include "core/events/MouseEvent.h" |
| 9 #include "core/html/HTMLCanvasElement.h" | 9 #include "core/html/HTMLCanvasElement.h" |
| 10 #include "core/html/canvas/CanvasRenderingContext.h" | 10 #include "core/html/canvas/CanvasRenderingContext.h" |
| 11 #include "core/html/canvas/CanvasRenderingContext2D.h" | 11 #include "core/html/canvas/CanvasRenderingContext2D.h" |
| 12 | 12 |
| 13 namespace WebCore { | 13 namespace WebCore { |
| 14 | 14 |
| 15 class MouseEventHitRegion { | 15 class MouseEventHitRegion { |
| 16 public: | 16 public: |
| 17 static String region(MouseEvent& event, bool& isNull) | 17 static String region(MouseEvent& event) |
| 18 { | 18 { |
| 19 if (!event.target() || !isHTMLCanvasElement(event.target()->toNode())) { | 19 if (!event.target() || !isHTMLCanvasElement(event.target()->toNode())) |
| 20 isNull = true; | |
| 21 return String(); | 20 return String(); |
| 22 } | |
| 23 | 21 |
| 24 HTMLCanvasElement* canvas = toHTMLCanvasElement(event.target()->toNode()
); | 22 HTMLCanvasElement* canvas = toHTMLCanvasElement(event.target()->toNode()
); |
| 25 CanvasRenderingContext* context = canvas->renderingContext(); | 23 CanvasRenderingContext* context = canvas->renderingContext(); |
| 26 if (!context || !context->is2d()) { | 24 if (!context || !context->is2d()) |
| 27 isNull = true; | |
| 28 return String(); | 25 return String(); |
| 29 } | |
| 30 | 26 |
| 31 HitRegion* hitRegion = toCanvasRenderingContext2D(context)-> | 27 HitRegion* hitRegion = toCanvasRenderingContext2D(context)-> |
| 32 hitRegionAtPoint(LayoutPoint(event.offsetX(), event.offsetY())); | 28 hitRegionAtPoint(LayoutPoint(event.offsetX(), event.offsetY())); |
| 33 | 29 |
| 34 String id; | 30 if (!hitRegion) |
| 35 if (hitRegion) | 31 return String(); |
| 36 id = hitRegion->id(); | |
| 37 | 32 |
| 38 isNull = id.isEmpty(); | 33 String id = hitRegion->id(); |
| 34 if (id.isEmpty()) |
| 35 return String(); |
| 39 | 36 |
| 40 return id; | 37 return id; |
| 41 } | 38 } |
| 42 }; | 39 }; |
| 43 | 40 |
| 44 } // namespace WebCore | 41 } // namespace WebCore |
| 45 | 42 |
| 46 #endif | 43 #endif |
| OLD | NEW |