| OLD | NEW |
| 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 Loading... |
| 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 // Accessing accessibility attributes: |
| 193 // map and returns true if found. | 160 // |
| 194 bool GetBoolAttribute( | 161 // There are dozens of possible attributes for an accessibility node, |
| 195 AccessibilityNodeData::BoolAttribute attr, bool* value) const; | 162 // but only a few tend to apply to any one object, so we store them |
| 163 // in sparse arrays of <attribute id, attribute value> pairs, organized |
| 164 // by type (bool, int, float, string, int list). |
| 165 // |
| 166 // There are three accessors for each type of attribute: one that returns |
| 167 // true if the attribute is present and false if not, one that takes a |
| 168 // pointer argument and returns true if the attribute is present (if you |
| 169 // need to distinguish between the default value and a missing attribute), |
| 170 // and another that returns the default value for that type if the |
| 171 // attribute is not present. In addition, strings can be returned as |
| 172 // either std::string or string16, for convenience. |
| 196 | 173 |
| 197 // Retrieve the value of a float attribute from the float attribute | 174 bool HasBoolAttribute(AccessibilityNodeData::BoolAttribute attr) const; |
| 198 // map and returns true if found. | 175 bool GetBoolAttribute(AccessibilityNodeData::BoolAttribute attr) const; |
| 176 bool GetBoolAttribute(AccessibilityNodeData::BoolAttribute attr, |
| 177 bool* value) const; |
| 178 |
| 179 bool HasFloatAttribute(AccessibilityNodeData::FloatAttribute attr) const; |
| 180 float GetFloatAttribute(AccessibilityNodeData::FloatAttribute attr) const; |
| 199 bool GetFloatAttribute(AccessibilityNodeData::FloatAttribute attr, | 181 bool GetFloatAttribute(AccessibilityNodeData::FloatAttribute attr, |
| 200 float* value) const; | 182 float* value) const; |
| 201 | 183 |
| 202 // Retrieve the value of an integer attribute from the integer attribute | 184 bool HasIntAttribute(AccessibilityNodeData::IntAttribute attribute) const; |
| 203 // map and returns true if found. | 185 int GetIntAttribute(AccessibilityNodeData::IntAttribute attribute) const; |
| 204 bool GetIntAttribute(AccessibilityNodeData::IntAttribute attribute, | 186 bool GetIntAttribute(AccessibilityNodeData::IntAttribute attribute, |
| 205 int* value) const; | 187 int* value) const; |
| 206 | 188 |
| 207 // Retrieve the value of a string attribute from the attribute map and | 189 bool HasStringAttribute( |
| 208 // returns true if found. | 190 AccessibilityNodeData::StringAttribute attribute) const; |
| 209 bool GetStringAttribute( | 191 const std::string& GetStringAttribute( |
| 210 AccessibilityNodeData::StringAttribute attribute, string16* value) const; | 192 AccessibilityNodeData::StringAttribute attribute) const; |
| 193 bool GetStringAttribute(AccessibilityNodeData::StringAttribute attribute, |
| 194 std::string* value) const; |
| 195 |
| 196 bool GetString16Attribute(AccessibilityNodeData::StringAttribute attribute, |
| 197 string16* value) const; |
| 198 string16 GetString16Attribute( |
| 199 AccessibilityNodeData::StringAttribute attribute) const; |
| 200 |
| 201 bool HasIntListAttribute( |
| 202 AccessibilityNodeData::IntListAttribute attribute) const; |
| 203 const std::vector<int32>& GetIntListAttribute( |
| 204 AccessibilityNodeData::IntListAttribute attribute) const; |
| 205 bool GetIntListAttribute(AccessibilityNodeData::IntListAttribute attribute, |
| 206 std::vector<int32>* value) const; |
| 207 |
| 208 void SetStringAttribute( |
| 209 AccessibilityNodeData::StringAttribute attribute, |
| 210 const std::string& value); |
| 211 | 211 |
| 212 // Retrieve the value of a html attribute from the attribute map and | 212 // Retrieve the value of a html attribute from the attribute map and |
| 213 // returns true if found. | 213 // returns true if found. |
| 214 bool GetHtmlAttribute(const char* attr, string16* value) const; | 214 bool GetHtmlAttribute(const char* attr, string16* value) const; |
| 215 bool GetHtmlAttribute(const char* attr, std::string* value) const; |
| 215 | 216 |
| 216 // Utility method to handle special cases for ARIA booleans, tristates and | 217 // Utility method to handle special cases for ARIA booleans, tristates and |
| 217 // booleans which have a "mixed" state. | 218 // booleans which have a "mixed" state. |
| 218 // | 219 // |
| 219 // Warning: the term "Tristate" is used loosely by the spec and here, | 220 // Warning: the term "Tristate" is used loosely by the spec and here, |
| 220 // as some attributes support a 4th state. | 221 // as some attributes support a 4th state. |
| 221 // | 222 // |
| 222 // The following attributes are appropriate to use with this method: | 223 // The following attributes are appropriate to use with this method: |
| 223 // aria-selected (selectable) | 224 // aria-selected (selectable) |
| 224 // aria-grabbed (grabbable) | 225 // aria-grabbed (grabbable) |
| 225 // aria-expanded (expandable) | 226 // aria-expanded (expandable) |
| 226 // aria-pressed (toggleable/pressable) -- supports 4th "mixed" state | 227 // aria-pressed (toggleable/pressable) -- supports 4th "mixed" state |
| 227 // aria-checked (checkable) -- supports 4th "mixed state" | 228 // aria-checked (checkable) -- supports 4th "mixed state" |
| 228 bool GetAriaTristate(const char* attr_name, | 229 bool GetAriaTristate(const char* attr_name, |
| 229 bool* is_defined, | 230 bool* is_defined, |
| 230 bool* is_mixed) const; | 231 bool* is_mixed) const; |
| 231 | 232 |
| 232 // Returns true if the bit corresponding to the given state enum is 1. | 233 // Returns true if the bit corresponding to the given state enum is 1. |
| 233 bool HasState(AccessibilityNodeData::State state_enum) const; | 234 bool HasState(AccessibilityNodeData::State state_enum) const; |
| 234 | 235 |
| 235 // Returns true if this node is an editable text field of any kind. | 236 // Returns true if this node is an editable text field of any kind. |
| 236 bool IsEditableText() const; | 237 bool IsEditableText() const; |
| 237 | 238 |
| 238 // Append the text from this node and its children. | 239 // Append the text from this node and its children. |
| 239 string16 GetTextRecursive() const; | 240 std::string GetTextRecursive() const; |
| 240 | 241 |
| 241 protected: | 242 protected: |
| 242 // Perform platform specific initialization. This can be called multiple times | 243 // Perform platform specific initialization. This can be called multiple times |
| 243 // during the lifetime of this instance after the members of this base object | 244 // during the lifetime of this instance after the members of this base object |
| 244 // have been reset with new values from the renderer process. | 245 // have been reset with new values from the renderer process. |
| 245 // Perform child independent initialization in this method. | 246 // Perform child independent initialization in this method. |
| 246 virtual void PreInitialize() {} | 247 virtual void PreInitialize() {} |
| 247 | 248 |
| 248 BrowserAccessibility(); | 249 BrowserAccessibility(); |
| 249 | 250 |
| 250 // The manager of this tree of accessibility objects; needed for | 251 // The manager of this tree of accessibility objects; needed for |
| 251 // global operations like focus tracking. | 252 // global operations like focus tracking. |
| 252 BrowserAccessibilityManager* manager_; | 253 BrowserAccessibilityManager* manager_; |
| 253 | 254 |
| 254 // The parent of this object, may be NULL if we're the root object. | 255 // The parent of this object, may be NULL if we're the root object. |
| 255 BrowserAccessibility* parent_; | 256 BrowserAccessibility* parent_; |
| 256 | 257 |
| 257 // The index of this within its parent object. | 258 // The index of this within its parent object. |
| 258 int32 index_in_parent_; | 259 int32 index_in_parent_; |
| 259 | 260 |
| 260 // The ID of this object in the renderer process. | 261 // The ID of this object in the renderer process. |
| 261 int32 renderer_id_; | 262 int32 renderer_id_; |
| 262 | 263 |
| 263 // The children of this object. | 264 // The children of this object. |
| 264 std::vector<BrowserAccessibility*> children_; | 265 std::vector<BrowserAccessibility*> children_; |
| 265 | 266 |
| 266 // Accessibility metadata from the renderer | 267 // Accessibility metadata from the renderer |
| 267 string16 name_; | 268 std::string name_; |
| 268 string16 value_; | 269 std::string value_; |
| 269 BoolAttrMap bool_attributes_; | 270 std::vector<std::pair< |
| 270 IntAttrMap int_attributes_; | 271 AccessibilityNodeData::BoolAttribute, bool> > bool_attributes_; |
| 271 FloatAttrMap float_attributes_; | 272 std::vector<std::pair< |
| 272 StringAttrMap string_attributes_; | 273 AccessibilityNodeData::FloatAttribute, float> > float_attributes_; |
| 273 std::vector<std::pair<string16, string16> > html_attributes_; | 274 std::vector<std::pair< |
| 275 AccessibilityNodeData::IntAttribute, int> > int_attributes_; |
| 276 std::vector<std::pair< |
| 277 AccessibilityNodeData::StringAttribute, std::string> > string_attributes_; |
| 278 std::vector<std::pair< |
| 279 AccessibilityNodeData::IntListAttribute, std::vector<int32> > > |
| 280 intlist_attributes_; |
| 281 std::vector<std::pair<std::string, std::string> > html_attributes_; |
| 274 int32 role_; | 282 int32 role_; |
| 275 int32 state_; | 283 int32 state_; |
| 276 string16 role_name_; | |
| 277 gfx::Rect location_; | 284 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 | 285 |
| 283 // BrowserAccessibility objects are reference-counted on some platforms. | 286 // BrowserAccessibility objects are reference-counted on some platforms. |
| 284 // When we're done with this object and it's removed from our accessibility | 287 // 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 | 288 // 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 | 289 // we mark it as inactive so that calls to any of this object's methods |
| 287 // immediately return failure. | 290 // immediately return failure. |
| 288 bool instance_active_; | 291 bool instance_active_; |
| 289 | 292 |
| 290 private: | 293 private: |
| 291 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility); | 294 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility); |
| 292 }; | 295 }; |
| 293 | 296 |
| 294 } // namespace content | 297 } // namespace content |
| 295 | 298 |
| 296 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_ | 299 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_ |
| OLD | NEW |