[email protected] | eaf8a342 | 2012-01-24 23:35:31 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c5c2a67 | 2010-10-01 23:28:04 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | ba1fa65 | 2011-06-25 05:16:22 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_ |
| 6 | #define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_ |
[email protected] | c5c2a67 | 2010-10-01 23:28:04 | [diff] [blame] | 7 | |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 8 | #include <map> |
| 9 | #include <utility> |
| 10 | #include <vector> |
| 11 | |
[email protected] | c5c2a67 | 2010-10-01 23:28:04 | [diff] [blame] | 12 | #include "base/basictypes.h" |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 0a935a0 | 2012-06-12 22:55:15 | [diff] [blame] | 14 | #include "content/common/accessibility_node_data.h" |
[email protected] | f3112a5 | 2011-09-30 23:47:49 | [diff] [blame] | 15 | #include "content/common/content_export.h" |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 16 | |
[email protected] | 95b3f544 | 2012-05-06 17:10:07 | [diff] [blame] | 17 | #if defined(OS_MACOSX) && __OBJC__ |
| 18 | @class BrowserAccessibilityCocoa; |
[email protected] | e6b3487 | 2012-10-24 20:51:32 | [diff] [blame] | 19 | #endif |
| 20 | |
| 21 | namespace content { |
| 22 | class BrowserAccessibilityManager; |
| 23 | #if defined(OS_WIN) |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 24 | class BrowserAccessibilityWin; |
[email protected] | cd3e2d90 | 2012-05-09 07:05:20 | [diff] [blame] | 25 | #elif defined(TOOLKIT_GTK) |
| 26 | class BrowserAccessibilityGtk; |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 27 | #endif |
| 28 | |
[email protected] | e6b3487 | 2012-10-24 20:51:32 | [diff] [blame] | 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> |
[email protected] | 0a935a0 | 2012-06-12 22:55:15 | [diff] [blame] | 33 | StringAttrMap; |
[email protected] | c5c2a67 | 2010-10-01 23:28:04 | [diff] [blame] | 34 | |
| 35 | //////////////////////////////////////////////////////////////////////////////// |
| 36 | // |
| 37 | // BrowserAccessibility |
| 38 | // |
| 39 | // Class implementing the cross platform interface for the Browser-Renderer |
| 40 | // communication of accessibility information, providing accessibility |
| 41 | // to be used by screen readers and other assistive technology (AT). |
| 42 | // |
| 43 | // An implementation for each platform handles platform specific accessibility |
| 44 | // APIs. |
| 45 | // |
| 46 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | f3112a5 | 2011-09-30 23:47:49 | [diff] [blame] | 47 | class CONTENT_EXPORT BrowserAccessibility { |
[email protected] | c5c2a67 | 2010-10-01 23:28:04 | [diff] [blame] | 48 | public: |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 49 | // Creates a platform specific BrowserAccessibility. Ownership passes to the |
[email protected] | c5c2a67 | 2010-10-01 23:28:04 | [diff] [blame] | 50 | // caller. |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 51 | static BrowserAccessibility* Create(); |
| 52 | |
[email protected] | c5c2a67 | 2010-10-01 23:28:04 | [diff] [blame] | 53 | virtual ~BrowserAccessibility(); |
| 54 | |
[email protected] | b05cd54 | 2011-06-08 01:38:02 | [diff] [blame] | 55 | // Detach all descendants of this subtree and push all of the node pointers, |
| 56 | // including this node, onto the end of |nodes|. |
| 57 | virtual void DetachTree(std::vector<BrowserAccessibility*>* nodes); |
| 58 | |
[email protected] | c47754096 | 2013-03-07 00:43:10 | [diff] [blame] | 59 | // Perform platform-specific initialization. This can be called multiple times |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 60 | // during the lifetime of this instance after the members of this base object |
| 61 | // have been reset with new values from the renderer process. |
[email protected] | a52aa41 | 2011-12-14 19:03:30 | [diff] [blame] | 62 | // Child dependent initialization can be done here. |
| 63 | virtual void PostInitialize() {} |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 64 | |
[email protected] | cd3e2d90 | 2012-05-09 07:05:20 | [diff] [blame] | 65 | // Returns true if this is a native platform-specific object, vs a |
| 66 | // cross-platform generic object. |
| 67 | virtual bool IsNative() const; |
| 68 | |
[email protected] | c47754096 | 2013-03-07 00:43:10 | [diff] [blame] | 69 | // Initialize the tree structure of this object. |
| 70 | void InitializeTreeStructure( |
| 71 | BrowserAccessibilityManager* manager, |
[email protected] | a52aa41 | 2011-12-14 19:03:30 | [diff] [blame] | 72 | BrowserAccessibility* parent, |
[email protected] | c47754096 | 2013-03-07 00:43:10 | [diff] [blame] | 73 | int32 renderer_id, |
| 74 | int32 index_in_parent); |
| 75 | |
| 76 | // Initialize this object's data. |
| 77 | void InitializeData(const AccessibilityNodeData& src); |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 78 | |
[email protected] | 26aef30 | 2013-03-14 22:43:51 | [diff] [blame] | 79 | virtual void SwapChildren(std::vector<BrowserAccessibility*>& children); |
[email protected] | c47754096 | 2013-03-07 00:43:10 | [diff] [blame] | 80 | |
[email protected] | 8368e3c | 2011-03-08 19:26:24 | [diff] [blame] | 81 | // Update the parent and index in parent if this node has been moved. |
| 82 | void UpdateParent(BrowserAccessibility* parent, int index_in_parent); |
| 83 | |
[email protected] | a10a5f8 | 2013-05-06 05:24:56 | [diff] [blame] | 84 | // Update this node's location, leaving everything else the same. |
| 85 | virtual void SetLocation(const gfx::Rect& new_location); |
| 86 | |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 87 | // Return true if this object is equal to or a descendant of |ancestor|. |
| 88 | bool IsDescendantOf(BrowserAccessibility* ancestor); |
| 89 | |
| 90 | // Returns the parent of this object, or NULL if it's the root. |
[email protected] | 7f2d9f6b | 2013-06-13 22:57:01 | [diff] [blame] | 91 | BrowserAccessibility* parent() const { return parent_; } |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 92 | |
| 93 | // Returns the number of children of this object. |
[email protected] | 9c1a75a | 2011-03-10 02:38:12 | [diff] [blame] | 94 | uint32 child_count() const { return children_.size(); } |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 95 | |
| 96 | // Return a pointer to the child with the given index. |
[email protected] | 7f2d9f6b | 2013-06-13 22:57:01 | [diff] [blame] | 97 | BrowserAccessibility* GetChild(uint32 child_index) const; |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 98 | |
| 99 | // Return the previous sibling of this object, or NULL if it's the first |
| 100 | // child of its parent. |
| 101 | BrowserAccessibility* GetPreviousSibling(); |
| 102 | |
| 103 | // Return the next sibling of this object, or NULL if it's the last child |
| 104 | // of its parent. |
| 105 | BrowserAccessibility* GetNextSibling(); |
| 106 | |
[email protected] | 9052cca | 2011-11-30 23:59:31 | [diff] [blame] | 107 | // Returns the bounds of this object in coordinates relative to the |
| 108 | // top-left corner of the overall web area. |
[email protected] | 7f2d9f6b | 2013-06-13 22:57:01 | [diff] [blame] | 109 | gfx::Rect GetLocalBoundsRect() const; |
[email protected] | 02747d4e | 2010-11-03 19:10:00 | [diff] [blame] | 110 | |
[email protected] | 9052cca | 2011-11-30 23:59:31 | [diff] [blame] | 111 | // Returns the bounds of this object in screen coordinates. |
[email protected] | 7f2d9f6b | 2013-06-13 22:57:01 | [diff] [blame] | 112 | gfx::Rect GetGlobalBoundsRect() const; |
[email protected] | 9052cca | 2011-11-30 23:59:31 | [diff] [blame] | 113 | |
| 114 | // Returns the deepest descendant that contains the specified point |
| 115 | // (in global screen coordinates). |
[email protected] | 02747d4e | 2010-11-03 19:10:00 | [diff] [blame] | 116 | BrowserAccessibility* BrowserAccessibilityForPoint(const gfx::Point& point); |
| 117 | |
[email protected] | c47754096 | 2013-03-07 00:43:10 | [diff] [blame] | 118 | // Marks this object for deletion, releases our reference to it, and |
| 119 | // recursively calls Destroy() on its children. May not delete |
| 120 | // immediately due to reference counting. |
[email protected] | 8368e3c | 2011-03-08 19:26:24 | [diff] [blame] | 121 | // |
[email protected] | c47754096 | 2013-03-07 00:43:10 | [diff] [blame] | 122 | // Reference counting is used on some platforms because the |
[email protected] | 8368e3c | 2011-03-08 19:26:24 | [diff] [blame] | 123 | // operating system may hold onto a reference to a BrowserAccessibility |
[email protected] | c47754096 | 2013-03-07 00:43:10 | [diff] [blame] | 124 | // object even after we're through with it. When a BrowserAccessibility |
| 125 | // has had Destroy() called but its reference count is not yet zero, |
| 126 | // queries on this object return failure |
| 127 | virtual void Destroy(); |
[email protected] | 8368e3c | 2011-03-08 19:26:24 | [diff] [blame] | 128 | |
| 129 | // Subclasses should override this to support platform reference counting. |
| 130 | virtual void NativeAddReference() { } |
| 131 | |
| 132 | // Subclasses should override this to support platform reference counting. |
[email protected] | 402da9f | 2011-03-08 19:45:41 | [diff] [blame] | 133 | virtual void NativeReleaseReference(); |
[email protected] | 8368e3c | 2011-03-08 19:26:24 | [diff] [blame] | 134 | |
| 135 | // |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 136 | // Accessors |
[email protected] | 8368e3c | 2011-03-08 19:26:24 | [diff] [blame] | 137 | // |
| 138 | |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 139 | const BoolAttrMap& bool_attributes() const { |
| 140 | return bool_attributes_; |
[email protected] | 1b12b23 | 2011-07-20 21:16:34 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 143 | const FloatAttrMap& float_attributes() const { |
| 144 | return float_attributes_; |
| 145 | } |
| 146 | |
| 147 | const IntAttrMap& int_attributes() const { |
[email protected] | 1b12b23 | 2011-07-20 21:16:34 | [diff] [blame] | 148 | return int_attributes_; |
| 149 | } |
| 150 | |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 151 | const StringAttrMap& string_attributes() const { |
| 152 | return string_attributes_; |
| 153 | } |
| 154 | |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 155 | const std::vector<BrowserAccessibility*>& children() const { |
| 156 | return children_; |
| 157 | } |
[email protected] | 0d7dad6 | 2010-10-19 21:18:50 | [diff] [blame] | 158 | const std::vector<std::pair<string16, string16> >& html_attributes() const { |
| 159 | return html_attributes_; |
| 160 | } |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 161 | int32 index_in_parent() const { return index_in_parent_; } |
[email protected] | 457af8d | 2011-05-14 01:02:47 | [diff] [blame] | 162 | const std::vector<int32>& indirect_child_ids() const { |
| 163 | return indirect_child_ids_; |
| 164 | } |
[email protected] | 80d64753 | 2011-06-17 22:53:49 | [diff] [blame] | 165 | const std::vector<int32>& line_breaks() const { |
| 166 | return line_breaks_; |
| 167 | } |
[email protected] | 1b12b23 | 2011-07-20 21:16:34 | [diff] [blame] | 168 | const std::vector<int32>& cell_ids() const { |
| 169 | return cell_ids_; |
| 170 | } |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 171 | const std::vector<int32>& unique_cell_ids() const { |
| 172 | return unique_cell_ids_; |
| 173 | } |
[email protected] | 0aed2f5 | 2011-03-23 18:06:36 | [diff] [blame] | 174 | gfx::Rect location() const { return location_; } |
[email protected] | 0d7dad6 | 2010-10-19 21:18:50 | [diff] [blame] | 175 | BrowserAccessibilityManager* manager() const { return manager_; } |
| 176 | const string16& name() const { return name_; } |
| 177 | int32 renderer_id() const { return renderer_id_; } |
| 178 | int32 role() const { return role_; } |
| 179 | const string16& role_name() const { return role_name_; } |
| 180 | int32 state() const { return state_; } |
| 181 | const string16& value() const { return value_; } |
[email protected] | 8368e3c | 2011-03-08 19:26:24 | [diff] [blame] | 182 | bool instance_active() const { return instance_active_; } |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 183 | |
[email protected] | 95b3f544 | 2012-05-06 17:10:07 | [diff] [blame] | 184 | #if defined(OS_MACOSX) && __OBJC__ |
[email protected] | cd3e2d90 | 2012-05-09 07:05:20 | [diff] [blame] | 185 | BrowserAccessibilityCocoa* ToBrowserAccessibilityCocoa(); |
[email protected] | 1dbadbd | 2010-10-13 18:50:10 | [diff] [blame] | 186 | #elif defined(OS_WIN) |
[email protected] | cd3e2d90 | 2012-05-09 07:05:20 | [diff] [blame] | 187 | BrowserAccessibilityWin* ToBrowserAccessibilityWin(); |
| 188 | #elif defined(TOOLKIT_GTK) |
| 189 | BrowserAccessibilityGtk* ToBrowserAccessibilityGtk(); |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 190 | #endif |
| 191 | |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 192 | // Retrieve the value of a bool attribute from the bool attribute |
| 193 | // map and returns true if found. |
[email protected] | 0a935a0 | 2012-06-12 22:55:15 | [diff] [blame] | 194 | bool GetBoolAttribute( |
[email protected] | e6b3487 | 2012-10-24 20:51:32 | [diff] [blame] | 195 | AccessibilityNodeData::BoolAttribute attr, bool* value) const; |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 196 | |
| 197 | // Retrieve the value of a float attribute from the float attribute |
| 198 | // map and returns true if found. |
[email protected] | e6b3487 | 2012-10-24 20:51:32 | [diff] [blame] | 199 | bool GetFloatAttribute(AccessibilityNodeData::FloatAttribute attr, |
[email protected] | 0a935a0 | 2012-06-12 22:55:15 | [diff] [blame] | 200 | float* value) const; |
[email protected] | 02747d4e | 2010-11-03 19:10:00 | [diff] [blame] | 201 | |
[email protected] | 1b12b23 | 2011-07-20 21:16:34 | [diff] [blame] | 202 | // Retrieve the value of an integer attribute from the integer attribute |
| 203 | // map and returns true if found. |
[email protected] | e6b3487 | 2012-10-24 20:51:32 | [diff] [blame] | 204 | bool GetIntAttribute(AccessibilityNodeData::IntAttribute attribute, |
[email protected] | 0a935a0 | 2012-06-12 22:55:15 | [diff] [blame] | 205 | int* value) const; |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 206 | |
| 207 | // Retrieve the value of a string attribute from the attribute map and |
| 208 | // returns true if found. |
[email protected] | 0a935a0 | 2012-06-12 22:55:15 | [diff] [blame] | 209 | bool GetStringAttribute( |
[email protected] | e6b3487 | 2012-10-24 20:51:32 | [diff] [blame] | 210 | AccessibilityNodeData::StringAttribute attribute, string16* value) const; |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 211 | |
| 212 | // Retrieve the value of a html attribute from the attribute map and |
| 213 | // returns true if found. |
| 214 | bool GetHtmlAttribute(const char* attr, string16* value) const; |
| 215 | |
[email protected] | 38f1e3b05 | 2012-02-10 21:46:07 | [diff] [blame] | 216 | // Utility method to handle special cases for ARIA booleans, tristates and |
| 217 | // booleans which have a "mixed" state. |
| 218 | // |
| 219 | // Warning: the term "Tristate" is used loosely by the spec and here, |
| 220 | // as some attributes support a 4th state. |
| 221 | // |
| 222 | // The following attributes are appropriate to use with this method: |
| 223 | // aria-selected (selectable) |
| 224 | // aria-grabbed (grabbable) |
| 225 | // aria-expanded (expandable) |
| 226 | // aria-pressed (toggleable/pressable) -- supports 4th "mixed" state |
| 227 | // aria-checked (checkable) -- supports 4th "mixed state" |
| 228 | bool GetAriaTristate(const char* attr_name, |
| 229 | bool* is_defined, |
| 230 | bool* is_mixed) const; |
| 231 | |
[email protected] | c43b0dc | 2011-12-03 04:31:13 | [diff] [blame] | 232 | // Returns true if the bit corresponding to the given state enum is 1. |
[email protected] | e6b3487 | 2012-10-24 20:51:32 | [diff] [blame] | 233 | bool HasState(AccessibilityNodeData::State state_enum) const; |
[email protected] | c43b0dc | 2011-12-03 04:31:13 | [diff] [blame] | 234 | |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 235 | // Returns true if this node is an editable text field of any kind. |
| 236 | bool IsEditableText() const; |
[email protected] | 02747d4e | 2010-11-03 19:10:00 | [diff] [blame] | 237 | |
[email protected] | d1029c5 | 2011-10-21 21:59:51 | [diff] [blame] | 238 | // Append the text from this node and its children. |
| 239 | string16 GetTextRecursive() const; |
| 240 | |
[email protected] | aa50cea8 | 2010-11-05 23:02:38 | [diff] [blame] | 241 | protected: |
[email protected] | a52aa41 | 2011-12-14 19:03:30 | [diff] [blame] | 242 | // 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 | // have been reset with new values from the renderer process. |
| 245 | // Perform child independent initialization in this method. |
[email protected] | c47754096 | 2013-03-07 00:43:10 | [diff] [blame] | 246 | virtual void PreInitialize() {} |
[email protected] | a52aa41 | 2011-12-14 19:03:30 | [diff] [blame] | 247 | |
[email protected] | aa50cea8 | 2010-11-05 23:02:38 | [diff] [blame] | 248 | BrowserAccessibility(); |
| 249 | |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 250 | // The manager of this tree of accessibility objects; needed for |
| 251 | // global operations like focus tracking. |
| 252 | BrowserAccessibilityManager* manager_; |
| 253 | |
| 254 | // The parent of this object, may be NULL if we're the root object. |
| 255 | BrowserAccessibility* parent_; |
| 256 | |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 257 | // The index of this within its parent object. |
| 258 | int32 index_in_parent_; |
| 259 | |
| 260 | // The ID of this object in the renderer process. |
| 261 | int32 renderer_id_; |
| 262 | |
| 263 | // The children of this object. |
| 264 | std::vector<BrowserAccessibility*> children_; |
| 265 | |
| 266 | // Accessibility metadata from the renderer |
| 267 | string16 name_; |
| 268 | string16 value_; |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 269 | BoolAttrMap bool_attributes_; |
| 270 | IntAttrMap int_attributes_; |
| 271 | FloatAttrMap float_attributes_; |
| 272 | StringAttrMap string_attributes_; |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 273 | std::vector<std::pair<string16, string16> > html_attributes_; |
| 274 | int32 role_; |
| 275 | int32 state_; |
| 276 | string16 role_name_; |
[email protected] | 0aed2f5 | 2011-03-23 18:06:36 | [diff] [blame] | 277 | gfx::Rect location_; |
[email protected] | 8368e3c | 2011-03-08 19:26:24 | [diff] [blame] | 278 | std::vector<int32> indirect_child_ids_; |
[email protected] | be4eeb0b | 2011-06-15 22:15:06 | [diff] [blame] | 279 | std::vector<int32> line_breaks_; |
[email protected] | 1b12b23 | 2011-07-20 21:16:34 | [diff] [blame] | 280 | std::vector<int32> cell_ids_; |
[email protected] | ee84512 | 2011-09-01 08:44:16 | [diff] [blame] | 281 | std::vector<int32> unique_cell_ids_; |
[email protected] | 8368e3c | 2011-03-08 19:26:24 | [diff] [blame] | 282 | |
| 283 | // BrowserAccessibility objects are reference-counted on some platforms. |
| 284 | // 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 |
| 286 | // we mark it as inactive so that calls to any of this object's methods |
| 287 | // immediately return failure. |
| 288 | bool instance_active_; |
[email protected] | f27e81c | 2010-10-07 05:20:23 | [diff] [blame] | 289 | |
[email protected] | c5c2a67 | 2010-10-01 23:28:04 | [diff] [blame] | 290 | private: |
| 291 | DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility); |
| 292 | }; |
| 293 | |
[email protected] | e6b3487 | 2012-10-24 20:51:32 | [diff] [blame] | 294 | } // namespace content |
| 295 | |
[email protected] | ba1fa65 | 2011-06-25 05:16:22 | [diff] [blame] | 296 | #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_ |