blob: 8fda68fc07908b80322804ff4215a29a89f7a652 [file] [log] [blame]
[email protected]eaf8a3422012-01-24 23:35:311// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c5c2a672010-10-01 23:28:042// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]ba1fa652011-06-25 05:16:225#ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_
6#define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_
[email protected]c5c2a672010-10-01 23:28:047
[email protected]f27e81c2010-10-07 05:20:238#include <map>
9#include <utility>
10#include <vector>
11
[email protected]c5c2a672010-10-01 23:28:0412#include "base/basictypes.h"
[email protected]f27e81c2010-10-07 05:20:2313#include "build/build_config.h"
[email protected]0a935a02012-06-12 22:55:1514#include "content/common/accessibility_node_data.h"
[email protected]f3112a52011-09-30 23:47:4915#include "content/common/content_export.h"
[email protected]f27e81c2010-10-07 05:20:2316
[email protected]95b3f5442012-05-06 17:10:0717#if defined(OS_MACOSX) && __OBJC__
18@class BrowserAccessibilityCocoa;
[email protected]e6b34872012-10-24 20:51:3219#endif
20
21namespace content {
22class BrowserAccessibilityManager;
23#if defined(OS_WIN)
[email protected]f27e81c2010-10-07 05:20:2324class BrowserAccessibilityWin;
[email protected]cd3e2d902012-05-09 07:05:2025#elif defined(TOOLKIT_GTK)
26class BrowserAccessibilityGtk;
[email protected]f27e81c2010-10-07 05:20:2327#endif
28
[email protected]e6b34872012-10-24 20:51:3229typedef std::map<AccessibilityNodeData::BoolAttribute, bool> BoolAttrMap;
30typedef std::map<AccessibilityNodeData::FloatAttribute, float> FloatAttrMap;
31typedef std::map<AccessibilityNodeData::IntAttribute, int> IntAttrMap;
32typedef std::map<AccessibilityNodeData::StringAttribute, string16>
[email protected]0a935a02012-06-12 22:55:1533 StringAttrMap;
[email protected]c5c2a672010-10-01 23:28:0434
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]f3112a52011-09-30 23:47:4947class CONTENT_EXPORT BrowserAccessibility {
[email protected]c5c2a672010-10-01 23:28:0448 public:
[email protected]f27e81c2010-10-07 05:20:2349 // Creates a platform specific BrowserAccessibility. Ownership passes to the
[email protected]c5c2a672010-10-01 23:28:0450 // caller.
[email protected]f27e81c2010-10-07 05:20:2351 static BrowserAccessibility* Create();
52
[email protected]c5c2a672010-10-01 23:28:0453 virtual ~BrowserAccessibility();
54
[email protected]b05cd542011-06-08 01:38:0255 // 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]c477540962013-03-07 00:43:1059 // Perform platform-specific initialization. This can be called multiple times
[email protected]f27e81c2010-10-07 05:20:2360 // 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]a52aa412011-12-14 19:03:3062 // Child dependent initialization can be done here.
63 virtual void PostInitialize() {}
[email protected]ee845122011-09-01 08:44:1664
[email protected]cd3e2d902012-05-09 07:05:2065 // 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]c477540962013-03-07 00:43:1069 // Initialize the tree structure of this object.
70 void InitializeTreeStructure(
71 BrowserAccessibilityManager* manager,
[email protected]a52aa412011-12-14 19:03:3072 BrowserAccessibility* parent,
[email protected]c477540962013-03-07 00:43:1073 int32 renderer_id,
74 int32 index_in_parent);
75
76 // Initialize this object's data.
77 void InitializeData(const AccessibilityNodeData& src);
[email protected]f27e81c2010-10-07 05:20:2378
[email protected]26aef302013-03-14 22:43:5179 virtual void SwapChildren(std::vector<BrowserAccessibility*>& children);
[email protected]c477540962013-03-07 00:43:1080
[email protected]8368e3c2011-03-08 19:26:2481 // 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]a10a5f82013-05-06 05:24:5684 // Update this node's location, leaving everything else the same.
85 virtual void SetLocation(const gfx::Rect& new_location);
86
[email protected]f27e81c2010-10-07 05:20:2387 // 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]7f2d9f6b2013-06-13 22:57:0191 BrowserAccessibility* parent() const { return parent_; }
[email protected]f27e81c2010-10-07 05:20:2392
93 // Returns the number of children of this object.
[email protected]9c1a75a2011-03-10 02:38:1294 uint32 child_count() const { return children_.size(); }
[email protected]f27e81c2010-10-07 05:20:2395
96 // Return a pointer to the child with the given index.
[email protected]7f2d9f6b2013-06-13 22:57:0197 BrowserAccessibility* GetChild(uint32 child_index) const;
[email protected]f27e81c2010-10-07 05:20:2398
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]9052cca2011-11-30 23:59:31107 // Returns the bounds of this object in coordinates relative to the
108 // top-left corner of the overall web area.
[email protected]7f2d9f6b2013-06-13 22:57:01109 gfx::Rect GetLocalBoundsRect() const;
[email protected]02747d4e2010-11-03 19:10:00110
[email protected]9052cca2011-11-30 23:59:31111 // Returns the bounds of this object in screen coordinates.
[email protected]7f2d9f6b2013-06-13 22:57:01112 gfx::Rect GetGlobalBoundsRect() const;
[email protected]9052cca2011-11-30 23:59:31113
114 // Returns the deepest descendant that contains the specified point
115 // (in global screen coordinates).
[email protected]02747d4e2010-11-03 19:10:00116 BrowserAccessibility* BrowserAccessibilityForPoint(const gfx::Point& point);
117
[email protected]c477540962013-03-07 00:43:10118 // 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]8368e3c2011-03-08 19:26:24121 //
[email protected]c477540962013-03-07 00:43:10122 // Reference counting is used on some platforms because the
[email protected]8368e3c2011-03-08 19:26:24123 // operating system may hold onto a reference to a BrowserAccessibility
[email protected]c477540962013-03-07 00:43:10124 // 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]8368e3c2011-03-08 19:26:24128
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]402da9f2011-03-08 19:45:41133 virtual void NativeReleaseReference();
[email protected]8368e3c2011-03-08 19:26:24134
135 //
[email protected]f27e81c2010-10-07 05:20:23136 // Accessors
[email protected]8368e3c2011-03-08 19:26:24137 //
138
[email protected]ee845122011-09-01 08:44:16139 const BoolAttrMap& bool_attributes() const {
140 return bool_attributes_;
[email protected]1b12b232011-07-20 21:16:34141 }
142
[email protected]ee845122011-09-01 08:44:16143 const FloatAttrMap& float_attributes() const {
144 return float_attributes_;
145 }
146
147 const IntAttrMap& int_attributes() const {
[email protected]1b12b232011-07-20 21:16:34148 return int_attributes_;
149 }
150
[email protected]ee845122011-09-01 08:44:16151 const StringAttrMap& string_attributes() const {
152 return string_attributes_;
153 }
154
[email protected]f27e81c2010-10-07 05:20:23155 const std::vector<BrowserAccessibility*>& children() const {
156 return children_;
157 }
[email protected]0d7dad62010-10-19 21:18:50158 const std::vector<std::pair<string16, string16> >& html_attributes() const {
159 return html_attributes_;
160 }
[email protected]f27e81c2010-10-07 05:20:23161 int32 index_in_parent() const { return index_in_parent_; }
[email protected]457af8d2011-05-14 01:02:47162 const std::vector<int32>& indirect_child_ids() const {
163 return indirect_child_ids_;
164 }
[email protected]80d647532011-06-17 22:53:49165 const std::vector<int32>& line_breaks() const {
166 return line_breaks_;
167 }
[email protected]1b12b232011-07-20 21:16:34168 const std::vector<int32>& cell_ids() const {
169 return cell_ids_;
170 }
[email protected]ee845122011-09-01 08:44:16171 const std::vector<int32>& unique_cell_ids() const {
172 return unique_cell_ids_;
173 }
[email protected]0aed2f52011-03-23 18:06:36174 gfx::Rect location() const { return location_; }
[email protected]0d7dad62010-10-19 21:18:50175 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]8368e3c2011-03-08 19:26:24182 bool instance_active() const { return instance_active_; }
[email protected]f27e81c2010-10-07 05:20:23183
[email protected]95b3f5442012-05-06 17:10:07184#if defined(OS_MACOSX) && __OBJC__
[email protected]cd3e2d902012-05-09 07:05:20185 BrowserAccessibilityCocoa* ToBrowserAccessibilityCocoa();
[email protected]1dbadbd2010-10-13 18:50:10186#elif defined(OS_WIN)
[email protected]cd3e2d902012-05-09 07:05:20187 BrowserAccessibilityWin* ToBrowserAccessibilityWin();
188#elif defined(TOOLKIT_GTK)
189 BrowserAccessibilityGtk* ToBrowserAccessibilityGtk();
[email protected]f27e81c2010-10-07 05:20:23190#endif
191
[email protected]ee845122011-09-01 08:44:16192 // Retrieve the value of a bool attribute from the bool attribute
193 // map and returns true if found.
[email protected]0a935a02012-06-12 22:55:15194 bool GetBoolAttribute(
[email protected]e6b34872012-10-24 20:51:32195 AccessibilityNodeData::BoolAttribute attr, bool* value) const;
[email protected]ee845122011-09-01 08:44:16196
197 // Retrieve the value of a float attribute from the float attribute
198 // map and returns true if found.
[email protected]e6b34872012-10-24 20:51:32199 bool GetFloatAttribute(AccessibilityNodeData::FloatAttribute attr,
[email protected]0a935a02012-06-12 22:55:15200 float* value) const;
[email protected]02747d4e2010-11-03 19:10:00201
[email protected]1b12b232011-07-20 21:16:34202 // Retrieve the value of an integer attribute from the integer attribute
203 // map and returns true if found.
[email protected]e6b34872012-10-24 20:51:32204 bool GetIntAttribute(AccessibilityNodeData::IntAttribute attribute,
[email protected]0a935a02012-06-12 22:55:15205 int* value) const;
[email protected]ee845122011-09-01 08:44:16206
207 // Retrieve the value of a string attribute from the attribute map and
208 // returns true if found.
[email protected]0a935a02012-06-12 22:55:15209 bool GetStringAttribute(
[email protected]e6b34872012-10-24 20:51:32210 AccessibilityNodeData::StringAttribute attribute, string16* value) const;
[email protected]ee845122011-09-01 08:44:16211
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]38f1e3b052012-02-10 21:46:07216 // 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]c43b0dc2011-12-03 04:31:13232 // Returns true if the bit corresponding to the given state enum is 1.
[email protected]e6b34872012-10-24 20:51:32233 bool HasState(AccessibilityNodeData::State state_enum) const;
[email protected]c43b0dc2011-12-03 04:31:13234
[email protected]ee845122011-09-01 08:44:16235 // Returns true if this node is an editable text field of any kind.
236 bool IsEditableText() const;
[email protected]02747d4e2010-11-03 19:10:00237
[email protected]d1029c52011-10-21 21:59:51238 // Append the text from this node and its children.
239 string16 GetTextRecursive() const;
240
[email protected]aa50cea82010-11-05 23:02:38241 protected:
[email protected]a52aa412011-12-14 19:03:30242 // 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]c477540962013-03-07 00:43:10246 virtual void PreInitialize() {}
[email protected]a52aa412011-12-14 19:03:30247
[email protected]aa50cea82010-11-05 23:02:38248 BrowserAccessibility();
249
[email protected]f27e81c2010-10-07 05:20:23250 // 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]f27e81c2010-10-07 05:20:23257 // 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]ee845122011-09-01 08:44:16269 BoolAttrMap bool_attributes_;
270 IntAttrMap int_attributes_;
271 FloatAttrMap float_attributes_;
272 StringAttrMap string_attributes_;
[email protected]f27e81c2010-10-07 05:20:23273 std::vector<std::pair<string16, string16> > html_attributes_;
274 int32 role_;
275 int32 state_;
276 string16 role_name_;
[email protected]0aed2f52011-03-23 18:06:36277 gfx::Rect location_;
[email protected]8368e3c2011-03-08 19:26:24278 std::vector<int32> indirect_child_ids_;
[email protected]be4eeb0b2011-06-15 22:15:06279 std::vector<int32> line_breaks_;
[email protected]1b12b232011-07-20 21:16:34280 std::vector<int32> cell_ids_;
[email protected]ee845122011-09-01 08:44:16281 std::vector<int32> unique_cell_ids_;
[email protected]8368e3c2011-03-08 19:26:24282
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]f27e81c2010-10-07 05:20:23289
[email protected]c5c2a672010-10-01 23:28:04290 private:
291 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility);
292};
293
[email protected]e6b34872012-10-24 20:51:32294} // namespace content
295
[email protected]ba1fa652011-06-25 05:16:22296#endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_