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

Side by Side Diff: Source/core/html/canvas/HitRegion.cpp

Issue 300223009: Implement basic parts of hit regions on canvas2d. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add clip tests 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 unified diff | Download patch
OLDNEW
(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 #include "config.h"
6 #include "core/html/canvas/HitRegion.h"
7
8 #include "core/accessibility/AXObjectCache.h"
9 #include "core/rendering/RenderBoxModelObject.h"
10
11 namespace WebCore {
12
13 HitRegion::HitRegion(const HitRegionOptions& options)
14 : m_id(options.id)
15 , m_control(options.control)
16 , m_path(options.path)
17 {
18 }
19
20 void HitRegion::updateAccessibility(Element* canvas)
21 {
22 if (!m_control || !canvas || !canvas->renderer() || !m_control->isDescendant Of(canvas))
23 return;
24
25 FloatRect boundingRect = m_path.boundingRect();
26
27 // Offset by the canvas rect (We should take border and padding into account ).
dmazzoni 2014/06/09 07:27:26 What do you mean by "we should take border and pad
zino 2014/06/10 10:09:34 Done.
28 RenderBoxModelObject* rbmo = canvas->renderBoxModelObject();
29 IntRect canvasRect = canvas->renderer()->absoluteBoundingBoxRect();
30 canvasRect.move(rbmo->borderLeft() + rbmo->paddingLeft(),
31 rbmo->borderTop() + rbmo->paddingTop());
32 LayoutRect elementRect = enclosingLayoutRect(boundingRect);
33 elementRect.moveBy(canvasRect.location());
34
35 AXObjectCache* axObjectCache = m_control->document().existingAXObjectCache() ;
36 if (!axObjectCache)
dmazzoni 2014/06/09 07:27:26 Move this test up to the top; there's no reason to
zino 2014/06/10 10:09:34 Done.
37 return;
38
39 axObjectCache->setCanvasObjectBounds(m_control.get(), elementRect);
40 }
41
42 bool HitRegion::contains(const LayoutPoint& point) const
43 {
44 if (!m_path.boundingRect().contains(point))
45 return false;
46
47 return m_path.contains(point, RULE_NONZERO);
48 }
49
50 void HitRegion::removePixels(const Path& clearArea)
51 {
52 m_path.subtractPath(clearArea);
53 }
54
55 void HitRegion::trace(Visitor* visitor)
56 {
57 #if ENABLE(OILPAN)
58 visitor->trace(m_control);
59 #endif
60 }
61
62 void HitRegionManager::addHitRegion(PassRefPtrWillBeRawPtr<HitRegion> passHitReg ion)
63 {
64 RefPtrWillBeRawPtr<HitRegion> hitRegion = passHitRegion;
65
66 m_hitRegionList.add(hitRegion);
67
68 if (!hitRegion->id().isEmpty())
69 m_hitRegionIdMap.set(hitRegion->id(), hitRegion);
70
71 if (hitRegion->control())
72 m_hitRegionControlMap.set(hitRegion->control(), hitRegion);
73 }
74
75 void HitRegionManager::removeHitRegion(HitRegion* hitRegion)
76 {
77 if (!hitRegion)
78 return;
79
80 if (!hitRegion->id().isEmpty())
81 m_hitRegionIdMap.remove(hitRegion->id());
82
83 if (hitRegion->control())
84 m_hitRegionControlMap.remove(hitRegion->control());
85
86 m_hitRegionList.remove(hitRegion);
87 }
88
89 void HitRegionManager::removeHitRegionById(const String& id)
90 {
91 if (!id.isEmpty())
92 removeHitRegion(getHitRegionById(id));
93 }
94
95 void HitRegionManager::removeHitRegionByControl(Element* control)
96 {
97 removeHitRegion(getHitRegionByControl(control));
98 }
99
100 void HitRegionManager::removeHitRegionsInRect(const FloatRect& rect, const Affin eTransform& ctm)
101 {
102 Path clearArea;
103 clearArea.addRect(rect);
104 clearArea.transform(ctm);
105
106 HitRegionIterator itEnd = m_hitRegionList.rend();
107
108 for (HitRegionIterator it = m_hitRegionList.rbegin(); it != itEnd; ++it) {
109 RefPtrWillBeRawPtr<HitRegion> hitRegion = *it;
110 hitRegion->removePixels(clearArea);
111 if (hitRegion->path().isEmpty())
112 removeHitRegion(hitRegion.get());
113 }
114 }
115
116 void HitRegionManager::removeAllHitRegions()
117 {
118 m_hitRegionList.clear();
119 m_hitRegionIdMap.clear();
120 }
121
122 HitRegion* HitRegionManager::getHitRegionById(const String& id) const
123 {
124 return m_hitRegionIdMap.get(id);
125 }
126
127 HitRegion* HitRegionManager::getHitRegionByControl(Element* control) const
128 {
129 if (control)
130 return m_hitRegionControlMap.get(control);
131
132 return 0;
133 }
134
135 HitRegion* HitRegionManager::getHitRegionAtPoint(const LayoutPoint& point) const
136 {
137 HitRegionIterator itEnd = m_hitRegionList.rend();
138
139 for (HitRegionIterator it = m_hitRegionList.rbegin(); it != itEnd; ++it) {
140 RefPtrWillBeRawPtr<HitRegion> hitRegion = *it;
141 if (hitRegion->contains(point))
142 return hitRegion.get();
143 }
144
145 return 0;
146 }
147
148 unsigned HitRegionManager::getHitRegionsCount() const
149 {
150 return m_hitRegionList.size();
151 }
152
153 void HitRegionManager::trace(Visitor* visitor)
154 {
155 #if ENABLE(OILPAN)
156 visitor->trace(m_hitRegionList);
157 visitor->trace(m_hitRegionIdMap);
158 visitor->trace(m_hitRegionControlMap);
159 #endif
160 }
161
162 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698