OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CanvasHitRegion_h |
| 6 #define CanvasHitRegion_h |
| 7 |
| 8 #include "platform/graphics/Path.h" |
| 9 #include "platform/heap/Handle.h" |
| 10 #include "platform/transforms/AffineTransform.h" |
| 11 #include "wtf/HashMap.h" |
| 12 #include "wtf/HashSet.h" |
| 13 #include "wtf/Noncopyable.h" |
| 14 #include "wtf/OwnPtr.h" |
| 15 #include "wtf/PassOwnPtr.h" |
| 16 #include "wtf/PassRefPtr.h" |
| 17 #include "wtf/RefPtr.h" |
| 18 #include "wtf/Vector.h" |
| 19 #include "wtf/text/WTFString.h" |
| 20 |
| 21 namespace WebCore { |
| 22 |
| 23 class CanvasHitRegion; |
| 24 class CanvasHitRegionManager; |
| 25 class Dictionary; |
| 26 class Element; |
| 27 class ExceptionState; |
| 28 |
| 29 struct DecodedHitRegionOptions { |
| 30 DecodedHitRegionOptions(); |
| 31 DecodedHitRegionOptions(const Dictionary& options); |
| 32 |
| 33 void resolvePath(const Path&, const AffineTransform&); |
| 34 void resolveIds(const CanvasHitRegionManager*); |
| 35 |
| 36 bool validate(ExceptionState&) const; |
| 37 |
| 38 Path path; |
| 39 bool hasPath; |
| 40 WindRule fillRule; |
| 41 String id; |
| 42 String parentId; |
| 43 String cursor; |
| 44 RefPtrWillBeRawPtr<Element> control; |
| 45 String label; |
| 46 String role; |
| 47 RefPtrWillBeRawPtr<CanvasHitRegion> previousHitRegion; |
| 48 RefPtrWillBeRawPtr<CanvasHitRegion> parentHitRegion; |
| 49 }; |
| 50 |
| 51 class CanvasHitRegion : public RefCountedWillBeGarbageCollectedFinalized<CanvasH
itRegion> { |
| 52 public: |
| 53 static PassRefPtrWillBeRawPtr<CanvasHitRegion> create(const DecodedHitRegion
Options& options) |
| 54 { |
| 55 return adoptRef(new CanvasHitRegion(options)); |
| 56 } |
| 57 |
| 58 virtual ~CanvasHitRegion(); |
| 59 |
| 60 class GeometryInfo : public RefCounted<GeometryInfo> { |
| 61 public: |
| 62 static PassRefPtr<GeometryInfo> create(const Path& path, WindRule fillRu
le, CanvasHitRegion* hitRegion) |
| 63 { |
| 64 return adoptRef(new GeometryInfo(path, fillRule, hitRegion)); |
| 65 } |
| 66 |
| 67 bool contains(const LayoutPoint&) const; |
| 68 bool isEnclosed(const FloatRect&, const AffineTransform&) const; |
| 69 |
| 70 CanvasHitRegion* hitRegion() const { return m_hitRegion; } |
| 71 void detachHitRegion() { m_hitRegion = 0; } |
| 72 |
| 73 private: |
| 74 GeometryInfo(const Path&, WindRule, CanvasHitRegion*); |
| 75 |
| 76 Path m_path; |
| 77 WindRule m_fillRule; |
| 78 CanvasHitRegion* m_hitRegion; |
| 79 }; |
| 80 |
| 81 bool isAncestorOf(const CanvasHitRegion*) const; |
| 82 |
| 83 GeometryInfo* geometryInfo() const { return m_geometryInfo.get(); } |
| 84 const String& id() const { return m_id; } |
| 85 const CanvasHitRegion* parent() const { return m_parent.get(); } |
| 86 const Element* control() const { return m_control.get(); } |
| 87 |
| 88 virtual void trace(Visitor*) OVERRIDE; |
| 89 |
| 90 private: |
| 91 CanvasHitRegion(const DecodedHitRegionOptions&); |
| 92 |
| 93 RefPtr<GeometryInfo> m_geometryInfo; |
| 94 RefPtrWillBeMember<CanvasHitRegion> m_parent; |
| 95 RefPtrWillBeMember<Element> m_control; |
| 96 String m_id; |
| 97 String m_cursor; |
| 98 String m_label; |
| 99 String m_ariaRole; |
| 100 }; |
| 101 |
| 102 class CanvasHitRegionManager : public NoBaseWillBeGarbageCollectedFinalized<Canv
asHitRegionManager> { |
| 103 WTF_MAKE_NONCOPYABLE(CanvasHitRegionManager); |
| 104 public: |
| 105 static PassOwnPtrWillBeRawPtr<CanvasHitRegionManager> create() { return adop
tPtr(new CanvasHitRegionManager()); } |
| 106 |
| 107 virtual ~CanvasHitRegionManager() { } |
| 108 |
| 109 void add(PassRefPtrWillBeRawPtr<CanvasHitRegion>); |
| 110 void remove(CanvasHitRegion*); |
| 111 |
| 112 void clear(); |
| 113 |
| 114 void removeEnclosed(const FloatRect&, const AffineTransform&); |
| 115 |
| 116 CanvasHitRegion* getHitRegionById(const String& id) const; |
| 117 CanvasHitRegion* getHitRegionAtPoint(const LayoutPoint&) const; |
| 118 |
| 119 virtual void trace(Visitor*) OVERRIDE; |
| 120 |
| 121 private: |
| 122 CanvasHitRegionManager() { } |
| 123 |
| 124 typedef WillBeHeapHashSet<RefPtrWillBeMember<CanvasHitRegion> > HitRegionLis
t; |
| 125 typedef WillBeHeapHashMap<String, RefPtrWillBeMember<CanvasHitRegion> > HitR
egionMap; |
| 126 typedef Vector<RefPtr<CanvasHitRegion::GeometryInfo> > HitRegionGeometry; |
| 127 |
| 128 HitRegionList m_hitRegions; // Storage for hit regions. |
| 129 HitRegionMap m_hitRegionIdMap; // Map for id-based lookups. |
| 130 HitRegionGeometry m_hitRegionGeometry; // The intersection/hit test query li
st. |
| 131 }; |
| 132 |
| 133 } // namespace WebCore |
| 134 |
| 135 #endif |
OLD | NEW |