blob: 5b860729d43f042f2021837049be1d82fd0e3b95 [file] [log] [blame]
[email protected]9c1a75a2011-03-10 02:38:121// Copyright (c) 2011 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#pragma once
8
[email protected]f27e81c2010-10-07 05:20:239#include <map>
10#include <utility>
11#include <vector>
12
[email protected]c5c2a672010-10-01 23:28:0413#include "base/basictypes.h"
[email protected]f27e81c2010-10-07 05:20:2314#include "build/build_config.h"
[email protected]f3112a52011-09-30 23:47:4915#include "content/common/content_export.h"
[email protected]f27e81c2010-10-07 05:20:2316#include "webkit/glue/webaccessibility.h"
17
18class BrowserAccessibilityManager;
[email protected]0d7dad62010-10-19 21:18:5019#if defined(OS_MACOSX) && __OBJC__
20@class BrowserAccessibilityCocoa;
[email protected]1dbadbd2010-10-13 18:50:1021#elif defined(OS_WIN)
[email protected]f27e81c2010-10-07 05:20:2322class BrowserAccessibilityWin;
23#endif
24
25using webkit_glue::WebAccessibility;
[email protected]ee845122011-09-01 08:44:1626typedef std::map<WebAccessibility::BoolAttribute, bool> BoolAttrMap;
27typedef std::map<WebAccessibility::FloatAttribute, float> FloatAttrMap;
28typedef std::map<WebAccessibility::IntAttribute, int> IntAttrMap;
29typedef std::map<WebAccessibility::StringAttribute, string16> StringAttrMap;
[email protected]c5c2a672010-10-01 23:28:0430
31////////////////////////////////////////////////////////////////////////////////
32//
33// BrowserAccessibility
34//
35// Class implementing the cross platform interface for the Browser-Renderer
36// communication of accessibility information, providing accessibility
37// to be used by screen readers and other assistive technology (AT).
38//
39// An implementation for each platform handles platform specific accessibility
40// APIs.
41//
42////////////////////////////////////////////////////////////////////////////////
[email protected]f3112a52011-09-30 23:47:4943class CONTENT_EXPORT BrowserAccessibility {
[email protected]c5c2a672010-10-01 23:28:0444 public:
[email protected]f27e81c2010-10-07 05:20:2345 // Creates a platform specific BrowserAccessibility. Ownership passes to the
[email protected]c5c2a672010-10-01 23:28:0446 // caller.
[email protected]f27e81c2010-10-07 05:20:2347 static BrowserAccessibility* Create();
48
[email protected]c5c2a672010-10-01 23:28:0449 virtual ~BrowserAccessibility();
50
[email protected]b05cd542011-06-08 01:38:0251 // Detach all descendants of this subtree and push all of the node pointers,
52 // including this node, onto the end of |nodes|.
53 virtual void DetachTree(std::vector<BrowserAccessibility*>* nodes);
54
[email protected]f27e81c2010-10-07 05:20:2355 // Perform platform specific initialization. This can be called multiple times
56 // during the lifetime of this instance after the members of this base object
57 // have been reset with new values from the renderer process.
[email protected]8368e3c2011-03-08 19:26:2458 virtual void Initialize();
[email protected]f27e81c2010-10-07 05:20:2359
[email protected]ee845122011-09-01 08:44:1660 // Optionally send events triggered simply by the fact that this node
61 // has been created or modified (and has been attached to the tree).
62 // This can include "show" events, "text changed" events in live regions,
63 // or "alert" events.
64 virtual void SendNodeUpdateEvents() {}
65
[email protected]8368e3c2011-03-08 19:26:2466 // Initialize this object, reading attributes from |src|. Does not
67 // recurse into children of |src| and build the whole subtree.
[email protected]f27e81c2010-10-07 05:20:2368 void Initialize(BrowserAccessibilityManager* manager,
69 BrowserAccessibility* parent,
70 int32 child_id,
71 int32 index_in_parent,
72 const WebAccessibility& src);
73
74 // Add a child of this object.
75 void AddChild(BrowserAccessibility* child);
76
[email protected]8368e3c2011-03-08 19:26:2477 // Update the parent and index in parent if this node has been moved.
78 void UpdateParent(BrowserAccessibility* parent, int index_in_parent);
79
[email protected]f27e81c2010-10-07 05:20:2380 // Return true if this object is equal to or a descendant of |ancestor|.
81 bool IsDescendantOf(BrowserAccessibility* ancestor);
82
83 // Returns the parent of this object, or NULL if it's the root.
[email protected]9c1a75a2011-03-10 02:38:1284 BrowserAccessibility* parent() { return parent_; }
[email protected]f27e81c2010-10-07 05:20:2385
86 // Returns the number of children of this object.
[email protected]9c1a75a2011-03-10 02:38:1287 uint32 child_count() const { return children_.size(); }
[email protected]f27e81c2010-10-07 05:20:2388
89 // Return a pointer to the child with the given index.
90 BrowserAccessibility* GetChild(uint32 child_index);
91
92 // Return the previous sibling of this object, or NULL if it's the first
93 // child of its parent.
94 BrowserAccessibility* GetPreviousSibling();
95
96 // Return the next sibling of this object, or NULL if it's the last child
97 // of its parent.
98 BrowserAccessibility* GetNextSibling();
99
[email protected]9052cca2011-11-30 23:59:31100 // Returns the bounds of this object in coordinates relative to the
101 // top-left corner of the overall web area.
102 gfx::Rect GetLocalBoundsRect();
[email protected]02747d4e2010-11-03 19:10:00103
[email protected]9052cca2011-11-30 23:59:31104 // Returns the bounds of this object in screen coordinates.
105 gfx::Rect GetGlobalBoundsRect();
106
107 // Returns the deepest descendant that contains the specified point
108 // (in global screen coordinates).
[email protected]02747d4e2010-11-03 19:10:00109 BrowserAccessibility* BrowserAccessibilityForPoint(const gfx::Point& point);
110
[email protected]8368e3c2011-03-08 19:26:24111 //
112 // Reference counting
113 //
114 // Each object has an internal reference count and many platform
115 // implementations may also use native reference counting.
116 //
117 // The internal reference counting is used because sometimes
118 // multiple references to the same object exist temporarily during
119 // an update. When the internal reference count reaches zero,
120 // NativeReleaseReference is called.
121 //
122 // Native reference counting is used on some platforms because the
123 // operating system may hold onto a reference to a BrowserAccessibility
124 // object even after we're through with it. On these platforms, when
125 // the internal reference count reaches zero, instance_active is set
126 // to zero, and all queries on this object should return failure.
127 // The object isn't actually deleted until the operating system releases
128 // all of its references.
129 //
130
131 // Increment this node's internal reference count.
132 virtual void InternalAddReference();
133
134 // Decrement this node's internal reference count. If the reference count
135 // reaches zero, call NativeReleaseReference().
136 virtual void InternalReleaseReference(bool recursive);
137
138 // Subclasses should override this to support platform reference counting.
139 virtual void NativeAddReference() { }
140
141 // Subclasses should override this to support platform reference counting.
[email protected]402da9f2011-03-08 19:45:41142 virtual void NativeReleaseReference();
[email protected]8368e3c2011-03-08 19:26:24143
144 //
[email protected]f27e81c2010-10-07 05:20:23145 // Accessors
[email protected]8368e3c2011-03-08 19:26:24146 //
147
[email protected]ee845122011-09-01 08:44:16148 const BoolAttrMap& bool_attributes() const {
149 return bool_attributes_;
[email protected]1b12b232011-07-20 21:16:34150 }
151
[email protected]ee845122011-09-01 08:44:16152 const FloatAttrMap& float_attributes() const {
153 return float_attributes_;
154 }
155
156 const IntAttrMap& int_attributes() const {
[email protected]1b12b232011-07-20 21:16:34157 return int_attributes_;
158 }
159
[email protected]ee845122011-09-01 08:44:16160 const StringAttrMap& string_attributes() const {
161 return string_attributes_;
162 }
163
[email protected]f27e81c2010-10-07 05:20:23164 int32 child_id() const { return child_id_; }
165 const std::vector<BrowserAccessibility*>& children() const {
166 return children_;
167 }
[email protected]0d7dad62010-10-19 21:18:50168 const std::vector<std::pair<string16, string16> >& html_attributes() const {
169 return html_attributes_;
170 }
[email protected]f27e81c2010-10-07 05:20:23171 int32 index_in_parent() const { return index_in_parent_; }
[email protected]457af8d2011-05-14 01:02:47172 const std::vector<int32>& indirect_child_ids() const {
173 return indirect_child_ids_;
174 }
[email protected]80d647532011-06-17 22:53:49175 const std::vector<int32>& line_breaks() const {
176 return line_breaks_;
177 }
[email protected]1b12b232011-07-20 21:16:34178 const std::vector<int32>& cell_ids() const {
179 return cell_ids_;
180 }
[email protected]ee845122011-09-01 08:44:16181 const std::vector<int32>& unique_cell_ids() const {
182 return unique_cell_ids_;
183 }
[email protected]0aed2f52011-03-23 18:06:36184 gfx::Rect location() const { return location_; }
[email protected]0d7dad62010-10-19 21:18:50185 BrowserAccessibilityManager* manager() const { return manager_; }
186 const string16& name() const { return name_; }
187 int32 renderer_id() const { return renderer_id_; }
188 int32 role() const { return role_; }
189 const string16& role_name() const { return role_name_; }
190 int32 state() const { return state_; }
191 const string16& value() const { return value_; }
[email protected]8368e3c2011-03-08 19:26:24192 bool instance_active() const { return instance_active_; }
193 int32 ref_count() const { return ref_count_; }
[email protected]f27e81c2010-10-07 05:20:23194
[email protected]0d7dad62010-10-19 21:18:50195#if defined(OS_MACOSX) && __OBJC__
196 BrowserAccessibilityCocoa* toBrowserAccessibilityCocoa();
[email protected]1dbadbd2010-10-13 18:50:10197#elif defined(OS_WIN)
[email protected]f27e81c2010-10-07 05:20:23198 BrowserAccessibilityWin* toBrowserAccessibilityWin();
199#endif
200
[email protected]ee845122011-09-01 08:44:16201 // Retrieve the value of a bool attribute from the bool attribute
202 // map and returns true if found.
203 bool GetBoolAttribute(WebAccessibility::BoolAttribute attr, bool* value)
204 const;
205
206 // Retrieve the value of a float attribute from the float attribute
207 // map and returns true if found.
208 bool GetFloatAttribute(WebAccessibility::FloatAttribute attr, float* value)
209 const;
[email protected]02747d4e2010-11-03 19:10:00210
[email protected]1b12b232011-07-20 21:16:34211 // Retrieve the value of an integer attribute from the integer attribute
212 // map and returns true if found.
[email protected]ee845122011-09-01 08:44:16213 bool GetIntAttribute(WebAccessibility::IntAttribute attribute, int* value)
214 const;
215
216 // Retrieve the value of a string attribute from the attribute map and
217 // returns true if found.
218 bool GetStringAttribute(WebAccessibility::StringAttribute attribute,
219 string16* value) const;
220
221 // Retrieve the value of a html attribute from the attribute map and
222 // returns true if found.
223 bool GetHtmlAttribute(const char* attr, string16* value) const;
224
[email protected]c43b0dc2011-12-03 04:31:13225 // Returns true if the bit corresponding to the given state enum is 1.
226 bool HasState(WebAccessibility::State state_enum) const;
227
[email protected]ee845122011-09-01 08:44:16228 // Returns true if this node is an editable text field of any kind.
229 bool IsEditableText() const;
[email protected]02747d4e2010-11-03 19:10:00230
[email protected]d1029c52011-10-21 21:59:51231 // Append the text from this node and its children.
232 string16 GetTextRecursive() const;
233
[email protected]aa50cea82010-11-05 23:02:38234 protected:
235 BrowserAccessibility();
236
[email protected]f27e81c2010-10-07 05:20:23237 // The manager of this tree of accessibility objects; needed for
238 // global operations like focus tracking.
239 BrowserAccessibilityManager* manager_;
240
241 // The parent of this object, may be NULL if we're the root object.
242 BrowserAccessibility* parent_;
243
244 // The ID of this object; globally unique within the browser process.
245 int32 child_id_;
246
247 // The index of this within its parent object.
248 int32 index_in_parent_;
249
250 // The ID of this object in the renderer process.
251 int32 renderer_id_;
252
253 // The children of this object.
254 std::vector<BrowserAccessibility*> children_;
255
[email protected]8368e3c2011-03-08 19:26:24256 // The number of internal references to this object.
257 int32 ref_count_;
258
[email protected]f27e81c2010-10-07 05:20:23259 // Accessibility metadata from the renderer
260 string16 name_;
261 string16 value_;
[email protected]ee845122011-09-01 08:44:16262 BoolAttrMap bool_attributes_;
263 IntAttrMap int_attributes_;
264 FloatAttrMap float_attributes_;
265 StringAttrMap string_attributes_;
[email protected]f27e81c2010-10-07 05:20:23266 std::vector<std::pair<string16, string16> > html_attributes_;
267 int32 role_;
268 int32 state_;
269 string16 role_name_;
[email protected]0aed2f52011-03-23 18:06:36270 gfx::Rect location_;
[email protected]8368e3c2011-03-08 19:26:24271 std::vector<int32> indirect_child_ids_;
[email protected]be4eeb0b2011-06-15 22:15:06272 std::vector<int32> line_breaks_;
[email protected]1b12b232011-07-20 21:16:34273 std::vector<int32> cell_ids_;
[email protected]ee845122011-09-01 08:44:16274 std::vector<int32> unique_cell_ids_;
[email protected]8368e3c2011-03-08 19:26:24275
276 // BrowserAccessibility objects are reference-counted on some platforms.
277 // When we're done with this object and it's removed from our accessibility
278 // tree, a client may still be holding onto a pointer to this object, so
279 // we mark it as inactive so that calls to any of this object's methods
280 // immediately return failure.
281 bool instance_active_;
[email protected]f27e81c2010-10-07 05:20:23282
[email protected]c5c2a672010-10-01 23:28:04283 private:
284 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility);
285};
286
[email protected]ba1fa652011-06-25 05:16:22287#endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_