| 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> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 virtual ~BrowserAccessibility(); | 50 virtual ~BrowserAccessibility(); |
| 51 | 51 |
| 52 // Called only once, immediately after construction. The constructor doesn't | 52 // Called only once, immediately after construction. The constructor doesn't |
| 53 // take any arguments because in the Windows subclass we use a special | 53 // take any arguments because in the Windows subclass we use a special |
| 54 // function to construct a COM object. | 54 // function to construct a COM object. |
| 55 virtual void Init(BrowserAccessibilityManager* manager, ui::AXNode* node); | 55 virtual void Init(BrowserAccessibilityManager* manager, ui::AXNode* node); |
| 56 | 56 |
| 57 // Called after the object is first initialized and again every time | 57 // Called after the object is first initialized and again every time |
| 58 // its data changes. | 58 // its data changes. |
| 59 virtual void OnDataChanged(); | 59 virtual void OnDataChanged() {} |
| 60 | 60 |
| 61 // Called after an atomic update to the tree finished and this object | 61 // Called after an atomic update to the tree finished and this object |
| 62 // was created or changed in this update. | 62 // was created or changed in this update. |
| 63 virtual void OnUpdateFinished() {} | 63 virtual void OnUpdateFinished() {} |
| 64 | 64 |
| 65 // Returns true if this is a native platform-specific object, vs a | 65 virtual void OnSubtreeWillBeDeleted() {} |
| 66 // cross-platform generic object. | 66 |
| 67 virtual bool IsNative() const; | 67 virtual void OnSubtreeCreationFinished() {} |
| 68 | 68 |
| 69 // Called when the location changed. | 69 // Called when the location changed. |
| 70 virtual void OnLocationChanged() {} | 70 virtual void OnLocationChanged() {} |
| 71 | 71 |
| 72 // Return true if this object is equal to or a descendant of |ancestor|. | 72 // Return true if this object is equal to or a descendant of |ancestor|. |
| 73 bool IsDescendantOf(BrowserAccessibility* ancestor); | 73 bool IsDescendantOf(BrowserAccessibility* ancestor); |
| 74 | 74 |
| 75 // Returns true if this is a leaf node on this platform, meaning any | 75 // Returns true if this is a leaf node on this platform, meaning any |
| 76 // children should not be exposed to this platform's native accessibility | 76 // children should not be exposed to this platform's native accessibility |
| 77 // layer. Each platform subclass should implement this itself. | 77 // layer. Each platform subclass should implement this itself. |
| 78 // The definition of a leaf may vary depending on the platform, | 78 // The definition of a leaf may vary depending on the platform, |
| 79 // but a leaf node should never have children that are focusable or | 79 // but a leaf node should never have children that are focusable or |
| 80 // that might send notifications. | 80 // that might send notifications. |
| 81 virtual bool PlatformIsLeaf() const; | 81 virtual bool PlatformIsLeaf() const; |
| 82 | 82 |
| 83 // Returns the number of children of this object, or 0 if PlatformIsLeaf() | 83 // Returns the number of children of this object, or 0 if PlatformIsLeaf() |
| 84 // returns true. | 84 // returns true. |
| 85 uint32 PlatformChildCount() const; | 85 uint32 PlatformChildCount() const; |
| 86 | 86 |
| 87 // Return a pointer to the child at the given index, or NULL for an | 87 // Return a pointer to the child at the given index, or NULL for an |
| 88 // invalid index. Returns NULL if PlatformIsLeaf() returns true. | 88 // invalid index. Returns NULL if PlatformIsLeaf() returns true. |
| 89 BrowserAccessibility* PlatformGetChild(uint32 child_index) const; | 89 BrowserAccessibility* PlatformGetChild(uint32 child_index) const; |
| 90 | 90 |
| 91 // Returns true if an ancestor of this node (not including itself) is a |
| 92 // leaf node, meaning that this node is not actually exposed to the |
| 93 // platform. |
| 94 bool PlatformIsChildOfLeaf() const; |
| 95 |
| 91 // Return the previous sibling of this object, or NULL if it's the first | 96 // Return the previous sibling of this object, or NULL if it's the first |
| 92 // child of its parent. | 97 // child of its parent. |
| 93 BrowserAccessibility* GetPreviousSibling(); | 98 BrowserAccessibility* GetPreviousSibling(); |
| 94 | 99 |
| 95 // Return the next sibling of this object, or NULL if it's the last child | 100 // Return the next sibling of this object, or NULL if it's the last child |
| 96 // of its parent. | 101 // of its parent. |
| 97 BrowserAccessibility* GetNextSibling(); | 102 BrowserAccessibility* GetNextSibling(); |
| 98 | 103 |
| 99 // Returns the bounds of this object in coordinates relative to the | 104 // Returns the bounds of this object in coordinates relative to the |
| 100 // top-left corner of the overall web area. | 105 // top-left corner of the overall web area. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // Subclasses should override this to support platform reference counting. | 138 // Subclasses should override this to support platform reference counting. |
| 134 virtual void NativeReleaseReference(); | 139 virtual void NativeReleaseReference(); |
| 135 | 140 |
| 136 // | 141 // |
| 137 // Accessors | 142 // Accessors |
| 138 // | 143 // |
| 139 | 144 |
| 140 BrowserAccessibilityManager* manager() const { return manager_; } | 145 BrowserAccessibilityManager* manager() const { return manager_; } |
| 141 bool instance_active() const { return node_ != NULL; } | 146 bool instance_active() const { return node_ != NULL; } |
| 142 ui::AXNode* node() const { return node_; } | 147 ui::AXNode* node() const { return node_; } |
| 143 const std::string& name() const { return name_; } | |
| 144 const std::string& value() const { return value_; } | |
| 145 void set_name(const std::string& name) { name_ = name; } | |
| 146 void set_value(const std::string& value) { value_ = value; } | |
| 147 | 148 |
| 148 // These access the internal accessibility tree, which doesn't necessarily | 149 // These access the internal accessibility tree, which doesn't necessarily |
| 149 // reflect the accessibility tree that should be exposed on each platform. | 150 // reflect the accessibility tree that should be exposed on each platform. |
| 150 // Use PlatformChildCount and PlatformGetChild to implement platform | 151 // Use PlatformChildCount and PlatformGetChild to implement platform |
| 151 // accessibility APIs. | 152 // accessibility APIs. |
| 152 uint32 InternalChildCount() const; | 153 uint32 InternalChildCount() const; |
| 153 BrowserAccessibility* InternalGetChild(uint32 child_index) const; | 154 BrowserAccessibility* InternalGetChild(uint32 child_index) const; |
| 154 | 155 |
| 155 BrowserAccessibility* GetParent() const; | 156 BrowserAccessibility* GetParent() const; |
| 156 int32 GetIndexInParent() const; | 157 int32 GetIndexInParent() const; |
| 157 | 158 |
| 158 int32 GetId() const; | 159 int32 GetId() const; |
| 159 const ui::AXNodeData& GetData() const; | 160 const ui::AXNodeData& GetData() const; |
| 160 gfx::Rect GetLocation() const; | 161 gfx::Rect GetLocation() const; |
| 161 int32 GetRole() const; | 162 int32 GetRole() const; |
| 162 int32 GetState() const; | 163 int32 GetState() const; |
| 163 | 164 |
| 164 typedef base::StringPairs HtmlAttributes; | 165 typedef base::StringPairs HtmlAttributes; |
| 165 const HtmlAttributes& GetHtmlAttributes() const; | 166 const HtmlAttributes& GetHtmlAttributes() const; |
| 166 | 167 |
| 168 |
| 169 // Returns true if this is a native platform-specific object, vs a |
| 170 // cross-platform generic object. Don't call ToBrowserAccessibilityXXX if |
| 171 // IsNative returns false. |
| 172 virtual bool IsNative() const; |
| 173 |
| 167 #if defined(OS_MACOSX) && __OBJC__ | 174 #if defined(OS_MACOSX) && __OBJC__ |
| 168 BrowserAccessibilityCocoa* ToBrowserAccessibilityCocoa(); | 175 BrowserAccessibilityCocoa* ToBrowserAccessibilityCocoa(); |
| 169 #elif defined(OS_WIN) | 176 #elif defined(OS_WIN) |
| 170 BrowserAccessibilityWin* ToBrowserAccessibilityWin(); | 177 BrowserAccessibilityWin* ToBrowserAccessibilityWin(); |
| 171 #endif | 178 #endif |
| 172 | 179 |
| 173 // Accessing accessibility attributes: | 180 // Accessing accessibility attributes: |
| 174 // | 181 // |
| 175 // There are dozens of possible attributes for an accessibility node, | 182 // There are dozens of possible attributes for an accessibility node, |
| 176 // but only a few tend to apply to any one object, so we store them | 183 // but only a few tend to apply to any one object, so we store them |
| (...skipping 30 matching lines...) Expand all Loading... |
| 207 base::string16* value) const; | 214 base::string16* value) const; |
| 208 base::string16 GetString16Attribute( | 215 base::string16 GetString16Attribute( |
| 209 ui::AXStringAttribute attribute) const; | 216 ui::AXStringAttribute attribute) const; |
| 210 | 217 |
| 211 bool HasIntListAttribute(ui::AXIntListAttribute attribute) const; | 218 bool HasIntListAttribute(ui::AXIntListAttribute attribute) const; |
| 212 const std::vector<int32>& GetIntListAttribute( | 219 const std::vector<int32>& GetIntListAttribute( |
| 213 ui::AXIntListAttribute attribute) const; | 220 ui::AXIntListAttribute attribute) const; |
| 214 bool GetIntListAttribute(ui::AXIntListAttribute attribute, | 221 bool GetIntListAttribute(ui::AXIntListAttribute attribute, |
| 215 std::vector<int32>* value) const; | 222 std::vector<int32>* value) const; |
| 216 | 223 |
| 217 void SetStringAttribute(ui::AXStringAttribute attribute, | |
| 218 const std::string& value); | |
| 219 | |
| 220 // Retrieve the value of a html attribute from the attribute map and | 224 // Retrieve the value of a html attribute from the attribute map and |
| 221 // returns true if found. | 225 // returns true if found. |
| 222 bool GetHtmlAttribute(const char* attr, base::string16* value) const; | 226 bool GetHtmlAttribute(const char* attr, base::string16* value) const; |
| 223 bool GetHtmlAttribute(const char* attr, std::string* value) const; | 227 bool GetHtmlAttribute(const char* attr, std::string* value) const; |
| 224 | 228 |
| 225 // Utility method to handle special cases for ARIA booleans, tristates and | 229 // Utility method to handle special cases for ARIA booleans, tristates and |
| 226 // booleans which have a "mixed" state. | 230 // booleans which have a "mixed" state. |
| 227 // | 231 // |
| 228 // Warning: the term "Tristate" is used loosely by the spec and here, | 232 // Warning: the term "Tristate" is used loosely by the spec and here, |
| 229 // as some attributes support a 4th state. | 233 // as some attributes support a 4th state. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 243 | 247 |
| 244 // Returns true if this node is an cell or an table header. | 248 // Returns true if this node is an cell or an table header. |
| 245 bool IsCellOrTableHeaderRole() const; | 249 bool IsCellOrTableHeaderRole() const; |
| 246 | 250 |
| 247 // Returns true if this node is an editable text field of any kind. | 251 // Returns true if this node is an editable text field of any kind. |
| 248 bool IsEditableText() const; | 252 bool IsEditableText() const; |
| 249 | 253 |
| 250 // True if this is a web area, and its grandparent is a presentational iframe. | 254 // True if this is a web area, and its grandparent is a presentational iframe. |
| 251 bool IsWebAreaForPresentationalIframe() const; | 255 bool IsWebAreaForPresentationalIframe() const; |
| 252 | 256 |
| 253 // Append the text from this node and its children. | |
| 254 std::string GetTextRecursive() const; | |
| 255 | |
| 256 protected: | 257 protected: |
| 257 BrowserAccessibility(); | 258 BrowserAccessibility(); |
| 258 | 259 |
| 259 // The manager of this tree of accessibility objects. | 260 // The manager of this tree of accessibility objects. |
| 260 BrowserAccessibilityManager* manager_; | 261 BrowserAccessibilityManager* manager_; |
| 261 | 262 |
| 262 // The underlying node. | 263 // The underlying node. |
| 263 ui::AXNode* node_; | 264 ui::AXNode* node_; |
| 264 | 265 |
| 265 private: | 266 private: |
| 266 // Return the sum of the lengths of all static text descendants, | 267 // Return the sum of the lengths of all static text descendants, |
| 267 // including this object if it's static text. | 268 // including this object if it's static text. |
| 268 int GetStaticTextLenRecursive() const; | 269 int GetStaticTextLenRecursive() const; |
| 269 | 270 |
| 270 // Similar to GetParent(), but includes nodes that are the host of a | 271 // Similar to GetParent(), but includes nodes that are the host of a |
| 271 // subtree rather than skipping over them - because they contain important | 272 // subtree rather than skipping over them - because they contain important |
| 272 // bounds offsets. | 273 // bounds offsets. |
| 273 BrowserAccessibility* GetParentForBoundsCalculation() const; | 274 BrowserAccessibility* GetParentForBoundsCalculation() const; |
| 274 | 275 |
| 275 std::string name_; | |
| 276 std::string value_; | |
| 277 | |
| 278 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility); | 276 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility); |
| 279 }; | 277 }; |
| 280 | 278 |
| 281 } // namespace content | 279 } // namespace content |
| 282 | 280 |
| 283 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_ | 281 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_ |
| OLD | NEW |