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

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

Issue 300223009: Implement basic parts of hit regions on canvas2d. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: exclude clipping region part 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/HitRegion.h
diff --git a/Source/core/html/canvas/HitRegion.h b/Source/core/html/canvas/HitRegion.h
new file mode 100644
index 0000000000000000000000000000000000000000..c0d57be5a619042deaaee471462aac38870c3e9b
--- /dev/null
+++ b/Source/core/html/canvas/HitRegion.h
@@ -0,0 +1,95 @@
+// 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 HitRegion_h
+#define HitRegion_h
+
+#include "bindings/v8/Dictionary.h"
+#include "core/dom/Element.h"
+#include "platform/graphics/Path.h"
+#include "platform/heap/Handle.h"
+#include "wtf/Noncopyable.h"
+#include "wtf/OwnPtr.h"
+#include "wtf/PassOwnPtr.h"
+#include "wtf/PassRefPtr.h"
+#include "wtf/RefPtr.h"
+
+namespace WebCore {
+
+struct HitRegionOptions {
+ STACK_ALLOCATED();
+
+public:
+ String id;
+ RefPtrWillBeMember<Element> control;
+ Path path;
+};
+
+class HitRegion FINAL : public RefCountedWillBeGarbageCollected<HitRegion> {
+public:
+ static PassRefPtrWillBeRawPtr<HitRegion> create(const HitRegionOptions& options)
+ {
+ return adoptRefWillBeNoop(new HitRegion(options));
+ }
+
+ virtual ~HitRegion() { }
+
+ void removePixels(const Path&);
+ void updateAccessibility(Element* canvas);
+
+ bool contains(const LayoutPoint&) const;
+
+ const String& id() const { return m_id; }
+ const Path& path() const { return m_path; }
+ Element* control() const { return m_control.get(); }
+
+ void trace(Visitor*);
+
+private:
+ explicit HitRegion(const HitRegionOptions&);
+
+ String m_id;
+ RefPtrWillBeMember<Element> m_control;
+ Path m_path;
+};
+
+class HitRegionManager FINAL : public NoBaseWillBeGarbageCollected<HitRegionManager> {
+ WTF_MAKE_NONCOPYABLE(HitRegionManager);
+
+public:
+ static PassOwnPtrWillBeRawPtr<HitRegionManager> create() { return adoptPtrWillBeNoop(new HitRegionManager()); }
+ virtual ~HitRegionManager() { }
+
+ void addHitRegion(PassRefPtrWillBeRawPtr<HitRegion>);
+
+ void removeHitRegion(HitRegion*);
+ void removeHitRegionById(const String& id);
+ void removeHitRegionByControl(Element*);
+ void removeHitRegionsInRect(const FloatRect&, const AffineTransform&);
+ void removeAllHitRegions();
+
+ HitRegion* getHitRegionById(const String& id) const;
+ HitRegion* getHitRegionByControl(Element*) const;
+ HitRegion* getHitRegionAtPoint(const LayoutPoint&) const;
+
+ unsigned getHitRegionsCount() const;
+
+ void trace(Visitor*);
+
+private:
+ HitRegionManager() { }
+
+ typedef WillBeHeapListHashSet<RefPtrWillBeMember<HitRegion> > HitRegionList;
+ typedef HitRegionList::const_reverse_iterator HitRegionIterator;
+ typedef WillBeHeapHashMap<String, RefPtrWillBeMember<HitRegion> > HitRegionIdMap;
+ typedef WillBeHeapHashMap<RefPtrWillBeMember<Element>, RefPtrWillBeMember<HitRegion> > HitRegionControlMap;
+
+ HitRegionList m_hitRegionList;
+ HitRegionIdMap m_hitRegionIdMap;
+ HitRegionControlMap m_hitRegionControlMap;
+};
+
+} // namespace WebCore
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698