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

Side by Side Diff: content/browser/accessibility/browser_accessibility.h

Issue 21269002: Make AccessibilityNodeData more compact. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_ 5 #ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_
6 #define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_ 6 #define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_
7 7
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/strings/string16.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "content/common/accessibility_node_data.h" 15 #include "content/common/accessibility_node_data.h"
15 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
16 17
17 #if defined(OS_MACOSX) && __OBJC__ 18 #if defined(OS_MACOSX) && __OBJC__
18 @class BrowserAccessibilityCocoa; 19 @class BrowserAccessibilityCocoa;
19 #endif 20 #endif
20 21
21 namespace content { 22 namespace content {
22 class BrowserAccessibilityManager; 23 class BrowserAccessibilityManager;
23 #if defined(OS_WIN) 24 #if defined(OS_WIN)
24 class BrowserAccessibilityWin; 25 class BrowserAccessibilityWin;
25 #elif defined(TOOLKIT_GTK) 26 #elif defined(TOOLKIT_GTK)
26 class BrowserAccessibilityGtk; 27 class BrowserAccessibilityGtk;
27 #endif 28 #endif
28 29
29 typedef std::map<AccessibilityNodeData::BoolAttribute, bool> BoolAttrMap;
30 typedef std::map<AccessibilityNodeData::FloatAttribute, float> FloatAttrMap;
31 typedef std::map<AccessibilityNodeData::IntAttribute, int> IntAttrMap;
32 typedef std::map<AccessibilityNodeData::StringAttribute, string16>
33 StringAttrMap;
34
35 //////////////////////////////////////////////////////////////////////////////// 30 ////////////////////////////////////////////////////////////////////////////////
36 // 31 //
37 // BrowserAccessibility 32 // BrowserAccessibility
38 // 33 //
39 // Class implementing the cross platform interface for the Browser-Renderer 34 // Class implementing the cross platform interface for the Browser-Renderer
40 // communication of accessibility information, providing accessibility 35 // communication of accessibility information, providing accessibility
41 // to be used by screen readers and other assistive technology (AT). 36 // to be used by screen readers and other assistive technology (AT).
42 // 37 //
43 // An implementation for each platform handles platform specific accessibility 38 // An implementation for each platform handles platform specific accessibility
44 // APIs. 39 // APIs.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // Subclasses should override this to support platform reference counting. 124 // Subclasses should override this to support platform reference counting.
130 virtual void NativeAddReference() { } 125 virtual void NativeAddReference() { }
131 126
132 // Subclasses should override this to support platform reference counting. 127 // Subclasses should override this to support platform reference counting.
133 virtual void NativeReleaseReference(); 128 virtual void NativeReleaseReference();
134 129
135 // 130 //
136 // Accessors 131 // Accessors
137 // 132 //
138 133
139 const BoolAttrMap& bool_attributes() const {
140 return bool_attributes_;
141 }
142
143 const FloatAttrMap& float_attributes() const {
144 return float_attributes_;
145 }
146
147 const IntAttrMap& int_attributes() const {
148 return int_attributes_;
149 }
150
151 const StringAttrMap& string_attributes() const {
152 return string_attributes_;
153 }
154
155 const std::vector<BrowserAccessibility*>& children() const { 134 const std::vector<BrowserAccessibility*>& children() const {
156 return children_; 135 return children_;
157 } 136 }
158 const std::vector<std::pair<string16, string16> >& html_attributes() const { 137 const std::vector<std::pair<std::string, std::string> >&
138 html_attributes() const {
159 return html_attributes_; 139 return html_attributes_;
160 } 140 }
161 int32 index_in_parent() const { return index_in_parent_; } 141 int32 index_in_parent() const { return index_in_parent_; }
162 const std::vector<int32>& indirect_child_ids() const {
163 return indirect_child_ids_;
164 }
165 const std::vector<int32>& line_breaks() const {
166 return line_breaks_;
167 }
168 const std::vector<int32>& cell_ids() const {
169 return cell_ids_;
170 }
171 const std::vector<int32>& unique_cell_ids() const {
172 return unique_cell_ids_;
173 }
174 gfx::Rect location() const { return location_; } 142 gfx::Rect location() const { return location_; }
175 BrowserAccessibilityManager* manager() const { return manager_; } 143 BrowserAccessibilityManager* manager() const { return manager_; }
176 const string16& name() const { return name_; } 144 const std::string& name() const { return name_; }
177 int32 renderer_id() const { return renderer_id_; } 145 int32 renderer_id() const { return renderer_id_; }
178 int32 role() const { return role_; } 146 int32 role() const { return role_; }
179 const string16& role_name() const { return role_name_; }
180 int32 state() const { return state_; } 147 int32 state() const { return state_; }
181 const string16& value() const { return value_; } 148 const std::string& value() const { return value_; }
182 bool instance_active() const { return instance_active_; } 149 bool instance_active() const { return instance_active_; }
183 150
184 #if defined(OS_MACOSX) && __OBJC__ 151 #if defined(OS_MACOSX) && __OBJC__
185 BrowserAccessibilityCocoa* ToBrowserAccessibilityCocoa(); 152 BrowserAccessibilityCocoa* ToBrowserAccessibilityCocoa();
186 #elif defined(OS_WIN) 153 #elif defined(OS_WIN)
187 BrowserAccessibilityWin* ToBrowserAccessibilityWin(); 154 BrowserAccessibilityWin* ToBrowserAccessibilityWin();
188 #elif defined(TOOLKIT_GTK) 155 #elif defined(TOOLKIT_GTK)
189 BrowserAccessibilityGtk* ToBrowserAccessibilityGtk(); 156 BrowserAccessibilityGtk* ToBrowserAccessibilityGtk();
190 #endif 157 #endif
191 158
192 // Retrieve the value of a bool attribute from the bool attribute 159 // Retrieve the value of a bool attribute from the bool attribute
193 // map and returns true if found. 160 // map and returns true if found.
194 bool GetBoolAttribute( 161 bool GetBoolAttribute(
195 AccessibilityNodeData::BoolAttribute attr, bool* value) const; 162 AccessibilityNodeData::BoolAttribute attr, bool* value) const;
196 163
197 // Retrieve the value of a float attribute from the float attribute 164 // Retrieve the value of a float attribute from the float attribute
198 // map and returns true if found. 165 // map and returns true if found.
199 bool GetFloatAttribute(AccessibilityNodeData::FloatAttribute attr, 166 bool GetFloatAttribute(AccessibilityNodeData::FloatAttribute attr,
200 float* value) const; 167 float* value) const;
201 168
202 // Retrieve the value of an integer attribute from the integer attribute 169 // Retrieve the value of an integer attribute from the integer attribute
203 // map and returns true if found. 170 // map and returns true if found.
204 bool GetIntAttribute(AccessibilityNodeData::IntAttribute attribute, 171 bool GetIntAttribute(AccessibilityNodeData::IntAttribute attribute,
205 int* value) const; 172 int* value) const;
206 173
207 // Retrieve the value of a string attribute from the attribute map and 174 // Retrieve the value of a string attribute from the attribute map and
208 // returns true if found. 175 // returns true if found.
209 bool GetStringAttribute( 176 bool GetStringAttribute(
210 AccessibilityNodeData::StringAttribute attribute, string16* value) const; 177 AccessibilityNodeData::StringAttribute attribute, string16* value) const;
178 bool GetStringAttribute(
179 AccessibilityNodeData::StringAttribute attribute, std::string* value)
180 const;
181
182 void SetStringAttribute(
183 AccessibilityNodeData::StringAttribute attribute,
184 const std::string& value);
185
186 // Retrieve a reference an integer list attribute from the integer list
187 // attribute map, or a reference to an empty vector if not found.
188 const std::vector<int32>& GetIntListAttribute(
aboxhall 2013/07/31 18:34:47 Why does this accessor return the value when other
dmazzoni 2013/08/06 17:36:34 The distinction is whether you need to know whethe
189 AccessibilityNodeData::IntListAttribute attribute) const;
211 190
212 // Retrieve the value of a html attribute from the attribute map and 191 // Retrieve the value of a html attribute from the attribute map and
213 // returns true if found. 192 // returns true if found.
214 bool GetHtmlAttribute(const char* attr, string16* value) const; 193 bool GetHtmlAttribute(const char* attr, string16* value) const;
194 bool GetHtmlAttribute(const char* attr, std::string* value) const;
215 195
216 // Utility method to handle special cases for ARIA booleans, tristates and 196 // Utility method to handle special cases for ARIA booleans, tristates and
217 // booleans which have a "mixed" state. 197 // booleans which have a "mixed" state.
218 // 198 //
219 // Warning: the term "Tristate" is used loosely by the spec and here, 199 // Warning: the term "Tristate" is used loosely by the spec and here,
220 // as some attributes support a 4th state. 200 // as some attributes support a 4th state.
221 // 201 //
222 // The following attributes are appropriate to use with this method: 202 // The following attributes are appropriate to use with this method:
223 // aria-selected (selectable) 203 // aria-selected (selectable)
224 // aria-grabbed (grabbable) 204 // aria-grabbed (grabbable)
225 // aria-expanded (expandable) 205 // aria-expanded (expandable)
226 // aria-pressed (toggleable/pressable) -- supports 4th "mixed" state 206 // aria-pressed (toggleable/pressable) -- supports 4th "mixed" state
227 // aria-checked (checkable) -- supports 4th "mixed state" 207 // aria-checked (checkable) -- supports 4th "mixed state"
228 bool GetAriaTristate(const char* attr_name, 208 bool GetAriaTristate(const char* attr_name,
229 bool* is_defined, 209 bool* is_defined,
230 bool* is_mixed) const; 210 bool* is_mixed) const;
231 211
232 // Returns true if the bit corresponding to the given state enum is 1. 212 // Returns true if the bit corresponding to the given state enum is 1.
233 bool HasState(AccessibilityNodeData::State state_enum) const; 213 bool HasState(AccessibilityNodeData::State state_enum) const;
234 214
235 // Returns true if this node is an editable text field of any kind. 215 // Returns true if this node is an editable text field of any kind.
236 bool IsEditableText() const; 216 bool IsEditableText() const;
237 217
238 // Append the text from this node and its children. 218 // Append the text from this node and its children.
239 string16 GetTextRecursive() const; 219 std::string GetTextRecursive() const;
240 220
241 protected: 221 protected:
242 // Perform platform specific initialization. This can be called multiple times 222 // Perform platform specific initialization. This can be called multiple times
243 // during the lifetime of this instance after the members of this base object 223 // during the lifetime of this instance after the members of this base object
244 // have been reset with new values from the renderer process. 224 // have been reset with new values from the renderer process.
245 // Perform child independent initialization in this method. 225 // Perform child independent initialization in this method.
246 virtual void PreInitialize() {} 226 virtual void PreInitialize() {}
247 227
248 BrowserAccessibility(); 228 BrowserAccessibility();
249 229
250 // The manager of this tree of accessibility objects; needed for 230 // The manager of this tree of accessibility objects; needed for
251 // global operations like focus tracking. 231 // global operations like focus tracking.
252 BrowserAccessibilityManager* manager_; 232 BrowserAccessibilityManager* manager_;
253 233
254 // The parent of this object, may be NULL if we're the root object. 234 // The parent of this object, may be NULL if we're the root object.
255 BrowserAccessibility* parent_; 235 BrowserAccessibility* parent_;
256 236
257 // The index of this within its parent object. 237 // The index of this within its parent object.
258 int32 index_in_parent_; 238 int32 index_in_parent_;
259 239
260 // The ID of this object in the renderer process. 240 // The ID of this object in the renderer process.
261 int32 renderer_id_; 241 int32 renderer_id_;
262 242
263 // The children of this object. 243 // The children of this object.
264 std::vector<BrowserAccessibility*> children_; 244 std::vector<BrowserAccessibility*> children_;
265 245
266 // Accessibility metadata from the renderer 246 // Accessibility metadata from the renderer
267 string16 name_; 247 std::string name_;
268 string16 value_; 248 std::string value_;
269 BoolAttrMap bool_attributes_; 249 std::vector<std::pair<
aboxhall 2013/07/31 18:34:47 Could we add using statements for each attribute t
dmazzoni 2013/08/06 17:36:34 That's generally frowned-upon in header files.
270 IntAttrMap int_attributes_; 250 AccessibilityNodeData::BoolAttribute, bool> > bool_attributes_;
aboxhall 2013/07/31 18:34:47 Could we add using statements for AccessibilityNod
dmazzoni 2013/08/06 17:36:34 Same. However, a longer-term plan is to move thes
271 FloatAttrMap float_attributes_; 251 std::vector<std::pair<
272 StringAttrMap string_attributes_; 252 AccessibilityNodeData::FloatAttribute, float> > float_attributes_;
273 std::vector<std::pair<string16, string16> > html_attributes_; 253 std::vector<std::pair<
254 AccessibilityNodeData::IntAttribute, int> > int_attributes_;
255 std::vector<std::pair<
256 AccessibilityNodeData::StringAttribute, std::string> > string_attributes_;
257 std::vector<std::pair<
258 AccessibilityNodeData::IntListAttribute, std::vector<int32> > >
259 intlist_attributes_;
260 std::vector<std::pair<std::string, std::string> > html_attributes_;
274 int32 role_; 261 int32 role_;
275 int32 state_; 262 int32 state_;
276 string16 role_name_;
277 gfx::Rect location_; 263 gfx::Rect location_;
278 std::vector<int32> indirect_child_ids_;
279 std::vector<int32> line_breaks_;
280 std::vector<int32> cell_ids_;
281 std::vector<int32> unique_cell_ids_;
282 264
283 // BrowserAccessibility objects are reference-counted on some platforms. 265 // BrowserAccessibility objects are reference-counted on some platforms.
284 // When we're done with this object and it's removed from our accessibility 266 // When we're done with this object and it's removed from our accessibility
285 // tree, a client may still be holding onto a pointer to this object, so 267 // tree, a client may still be holding onto a pointer to this object, so
286 // we mark it as inactive so that calls to any of this object's methods 268 // we mark it as inactive so that calls to any of this object's methods
287 // immediately return failure. 269 // immediately return failure.
288 bool instance_active_; 270 bool instance_active_;
289 271
290 private: 272 private:
291 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility); 273 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility);
292 }; 274 };
293 275
294 } // namespace content 276 } // namespace content
295 277
296 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_ 278 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698