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

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

Issue 287163007: WIP: <canvas> hit regions (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/html/canvas/CanvasHitRegion.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/canvas/CanvasHitRegion.h
diff --git a/Source/core/html/canvas/CanvasHitRegion.h b/Source/core/html/canvas/CanvasHitRegion.h
new file mode 100644
index 0000000000000000000000000000000000000000..1e3935224ca50a0aa28f581b83579501bce939c7
--- /dev/null
+++ b/Source/core/html/canvas/CanvasHitRegion.h
@@ -0,0 +1,135 @@
+// 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 CanvasHitRegion_h
+#define CanvasHitRegion_h
+
+#include "platform/graphics/Path.h"
+#include "platform/heap/Handle.h"
+#include "platform/transforms/AffineTransform.h"
+#include "wtf/HashMap.h"
+#include "wtf/HashSet.h"
+#include "wtf/Noncopyable.h"
+#include "wtf/OwnPtr.h"
+#include "wtf/PassOwnPtr.h"
+#include "wtf/PassRefPtr.h"
+#include "wtf/RefPtr.h"
+#include "wtf/Vector.h"
+#include "wtf/text/WTFString.h"
+
+namespace WebCore {
+
+class CanvasHitRegion;
+class CanvasHitRegionManager;
+class Dictionary;
+class Element;
+class ExceptionState;
+
+struct DecodedHitRegionOptions {
+ DecodedHitRegionOptions();
+ DecodedHitRegionOptions(const Dictionary& options);
+
+ void resolvePath(const Path&, const AffineTransform&);
+ void resolveIds(const CanvasHitRegionManager*);
+
+ bool validate(ExceptionState&) const;
+
+ Path path;
+ bool hasPath;
+ WindRule fillRule;
+ String id;
+ String parentId;
+ String cursor;
+ RefPtrWillBeRawPtr<Element> control;
+ String label;
+ String role;
+ RefPtrWillBeRawPtr<CanvasHitRegion> previousHitRegion;
+ RefPtrWillBeRawPtr<CanvasHitRegion> parentHitRegion;
+};
+
+class CanvasHitRegion : public RefCountedWillBeGarbageCollectedFinalized<CanvasHitRegion> {
+public:
+ static PassRefPtrWillBeRawPtr<CanvasHitRegion> create(const DecodedHitRegionOptions& options)
+ {
+ return adoptRef(new CanvasHitRegion(options));
+ }
+
+ virtual ~CanvasHitRegion();
+
+ class GeometryInfo : public RefCounted<GeometryInfo> {
+ public:
+ static PassRefPtr<GeometryInfo> create(const Path& path, WindRule fillRule, CanvasHitRegion* hitRegion)
+ {
+ return adoptRef(new GeometryInfo(path, fillRule, hitRegion));
+ }
+
+ bool contains(const LayoutPoint&) const;
+ bool isEnclosed(const FloatRect&, const AffineTransform&) const;
+
+ CanvasHitRegion* hitRegion() const { return m_hitRegion; }
+ void detachHitRegion() { m_hitRegion = 0; }
+
+ private:
+ GeometryInfo(const Path&, WindRule, CanvasHitRegion*);
+
+ Path m_path;
+ WindRule m_fillRule;
+ CanvasHitRegion* m_hitRegion;
+ };
+
+ bool isAncestorOf(const CanvasHitRegion*) const;
+
+ GeometryInfo* geometryInfo() const { return m_geometryInfo.get(); }
+ const String& id() const { return m_id; }
+ const CanvasHitRegion* parent() const { return m_parent.get(); }
+ const Element* control() const { return m_control.get(); }
+
+ virtual void trace(Visitor*) OVERRIDE;
+
+private:
+ CanvasHitRegion(const DecodedHitRegionOptions&);
+
+ RefPtr<GeometryInfo> m_geometryInfo;
+ RefPtrWillBeMember<CanvasHitRegion> m_parent;
+ RefPtrWillBeMember<Element> m_control;
+ String m_id;
+ String m_cursor;
+ String m_label;
+ String m_ariaRole;
+};
+
+class CanvasHitRegionManager : public NoBaseWillBeGarbageCollectedFinalized<CanvasHitRegionManager> {
+ WTF_MAKE_NONCOPYABLE(CanvasHitRegionManager);
+public:
+ static PassOwnPtrWillBeRawPtr<CanvasHitRegionManager> create() { return adoptPtr(new CanvasHitRegionManager()); }
+
+ virtual ~CanvasHitRegionManager() { }
+
+ void add(PassRefPtrWillBeRawPtr<CanvasHitRegion>);
+ void remove(CanvasHitRegion*);
+
+ void clear();
+
+ void removeEnclosed(const FloatRect&, const AffineTransform&);
+
+ CanvasHitRegion* getHitRegionById(const String& id) const;
+ CanvasHitRegion* getHitRegionAtPoint(const LayoutPoint&) const;
+
+ virtual void trace(Visitor*) OVERRIDE;
+
+private:
+ CanvasHitRegionManager() { }
+
+ typedef WillBeHeapHashSet<RefPtrWillBeMember<CanvasHitRegion> > HitRegionList;
+ typedef WillBeHeapHashMap<String, RefPtrWillBeMember<CanvasHitRegion> > HitRegionMap;
+ typedef Vector<RefPtr<CanvasHitRegion::GeometryInfo> > HitRegionGeometry;
+
+ HitRegionList m_hitRegions; // Storage for hit regions.
+ HitRegionMap m_hitRegionIdMap; // Map for id-based lookups.
+ HitRegionGeometry m_hitRegionGeometry; // The intersection/hit test query list.
+};
+
+} // namespace WebCore
+
+#endif
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/html/canvas/CanvasHitRegion.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698