blob: 1426e5c6c197c73c7b2639724546e96305bc886b [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"
15#include "webkit/glue/webaccessibility.h"
16
17class BrowserAccessibilityManager;
[email protected]0d7dad62010-10-19 21:18:5018#if defined(OS_MACOSX) && __OBJC__
19@class BrowserAccessibilityCocoa;
[email protected]1dbadbd2010-10-13 18:50:1020#elif defined(OS_WIN)
[email protected]f27e81c2010-10-07 05:20:2321class BrowserAccessibilityWin;
22#endif
23
24using webkit_glue::WebAccessibility;
[email protected]ee845122011-09-01 08:44:1625typedef std::map<WebAccessibility::BoolAttribute, bool> BoolAttrMap;
26typedef std::map<WebAccessibility::FloatAttribute, float> FloatAttrMap;
27typedef std::map<WebAccessibility::IntAttribute, int> IntAttrMap;
28typedef std::map<WebAccessibility::StringAttribute, string16> StringAttrMap;
[email protected]c5c2a672010-10-01 23:28:0429
30////////////////////////////////////////////////////////////////////////////////
31//
32// BrowserAccessibility
33//
34// Class implementing the cross platform interface for the Browser-Renderer
35// communication of accessibility information, providing accessibility
36// to be used by screen readers and other assistive technology (AT).
37//
38// An implementation for each platform handles platform specific accessibility
39// APIs.
40//
41////////////////////////////////////////////////////////////////////////////////
42class BrowserAccessibility {
43 public:
[email protected]f27e81c2010-10-07 05:20:2344 // Creates a platform specific BrowserAccessibility. Ownership passes to the
[email protected]c5c2a672010-10-01 23:28:0445 // caller.
[email protected]f27e81c2010-10-07 05:20:2346 static BrowserAccessibility* Create();
47
[email protected]c5c2a672010-10-01 23:28:0448 virtual ~BrowserAccessibility();
49
[email protected]b05cd542011-06-08 01:38:0250 // Detach all descendants of this subtree and push all of the node pointers,
51 // including this node, onto the end of |nodes|.
52 virtual void DetachTree(std::vector<BrowserAccessibility*>* nodes);
53
[email protected]f27e81c2010-10-07 05:20:2354 // Perform platform specific initialization. This can be called multiple times
55 // during the lifetime of this instance after the members of this base object
56 // have been reset with new values from the renderer process.
[email protected]8368e3c2011-03-08 19:26:2457 virtual void Initialize();
[email protected]f27e81c2010-10-07 05:20:2358
[email protected]ee845122011-09-01 08:44:1659 // Optionally send events triggered simply by the fact that this node
60 // has been created or modified (and has been attached to the tree).
61 // This can include "show" events, "text changed" events in live regions,
62 // or "alert" events.
63 virtual void SendNodeUpdateEvents() {}
64
[email protected]8368e3c2011-03-08 19:26:2465 // Initialize this object, reading attributes from |src|. Does not
66 // recurse into children of |src| and build the whole subtree.
[email protected]f27e81c2010-10-07 05:20:2367 void Initialize(BrowserAccessibilityManager* manager,
68 BrowserAccessibility* parent,
69 int32 child_id,
70 int32 index_in_parent,
71 const WebAccessibility& src);
72
73 // Add a child of this object.
74 void AddChild(BrowserAccessibility* child);
75
[email protected]8368e3c2011-03-08 19:26:2476 // Update the parent and index in parent if this node has been moved.
77 void UpdateParent(BrowserAccessibility* parent, int index_in_parent);
78
[email protected]f27e81c2010-10-07 05:20:2379 // Return true if this object is equal to or a descendant of |ancestor|.
80 bool IsDescendantOf(BrowserAccessibility* ancestor);
81
82 // Returns the parent of this object, or NULL if it's the root.
[email protected]9c1a75a2011-03-10 02:38:1283 BrowserAccessibility* parent() { return parent_; }
[email protected]f27e81c2010-10-07 05:20:2384
85 // Returns the number of children of this object.
[email protected]9c1a75a2011-03-10 02:38:1286 uint32 child_count() const { return children_.size(); }
[email protected]f27e81c2010-10-07 05:20:2387
88 // Return a pointer to the child with the given index.
89 BrowserAccessibility* GetChild(uint32 child_index);
90
91 // Return the previous sibling of this object, or NULL if it's the first
92 // child of its parent.
93 BrowserAccessibility* GetPreviousSibling();
94
95 // Return the next sibling of this object, or NULL if it's the last child
96 // of its parent.
97 BrowserAccessibility* GetNextSibling();
98
[email protected]02747d4e2010-11-03 19:10:0099 // Returns the bounds of this object in screen coordinates.
100 gfx::Rect GetBoundsRect();
101
102 // Returns the deepest descendant that contains the specified point.
103 BrowserAccessibility* BrowserAccessibilityForPoint(const gfx::Point& point);
104
[email protected]8368e3c2011-03-08 19:26:24105 //
106 // Reference counting
107 //
108 // Each object has an internal reference count and many platform
109 // implementations may also use native reference counting.
110 //
111 // The internal reference counting is used because sometimes
112 // multiple references to the same object exist temporarily during
113 // an update. When the internal reference count reaches zero,
114 // NativeReleaseReference is called.
115 //
116 // Native reference counting is used on some platforms because the
117 // operating system may hold onto a reference to a BrowserAccessibility
118 // object even after we're through with it. On these platforms, when
119 // the internal reference count reaches zero, instance_active is set
120 // to zero, and all queries on this object should return failure.
121 // The object isn't actually deleted until the operating system releases
122 // all of its references.
123 //
124
125 // Increment this node's internal reference count.
126 virtual void InternalAddReference();
127
128 // Decrement this node's internal reference count. If the reference count
129 // reaches zero, call NativeReleaseReference().
130 virtual void InternalReleaseReference(bool recursive);
131
132 // Subclasses should override this to support platform reference counting.
133 virtual void NativeAddReference() { }
134
135 // Subclasses should override this to support platform reference counting.
[email protected]402da9f2011-03-08 19:45:41136 virtual void NativeReleaseReference();
[email protected]8368e3c2011-03-08 19:26:24137
138 //
[email protected]f27e81c2010-10-07 05:20:23139 // Accessors
[email protected]8368e3c2011-03-08 19:26:24140 //
141
[email protected]ee845122011-09-01 08:44:16142 const BoolAttrMap& bool_attributes() const {
143 return bool_attributes_;
[email protected]1b12b232011-07-20 21:16:34144 }
145
[email protected]ee845122011-09-01 08:44:16146 const FloatAttrMap& float_attributes() const {
147 return float_attributes_;
148 }
149
150 const IntAttrMap& int_attributes() const {
[email protected]1b12b232011-07-20 21:16:34151 return int_attributes_;
152 }
153
[email protected]ee845122011-09-01 08:44:16154 const StringAttrMap& string_attributes() const {
155 return string_attributes_;
156 }
157
[email protected]f27e81c2010-10-07 05:20:23158 int32 child_id() const { return child_id_; }
159 const std::vector<BrowserAccessibility*>& children() const {
160 return children_;
161 }
[email protected]0d7dad62010-10-19 21:18:50162 const std::vector<std::pair<string16, string16> >& html_attributes() const {
163 return html_attributes_;
164 }
[email protected]f27e81c2010-10-07 05:20:23165 int32 index_in_parent() const { return index_in_parent_; }
[email protected]457af8d2011-05-14 01:02:47166 const std::vector<int32>& indirect_child_ids() const {
167 return indirect_child_ids_;
168 }
[email protected]80d647532011-06-17 22:53:49169 const std::vector<int32>& line_breaks() const {
170 return line_breaks_;
171 }
[email protected]1b12b232011-07-20 21:16:34172 const std::vector<int32>& cell_ids() const {
173 return cell_ids_;
174 }
[email protected]ee845122011-09-01 08:44:16175 const std::vector<int32>& unique_cell_ids() const {
176 return unique_cell_ids_;
177 }
[email protected]0aed2f52011-03-23 18:06:36178 gfx::Rect location() const { return location_; }
[email protected]0d7dad62010-10-19 21:18:50179 BrowserAccessibilityManager* manager() const { return manager_; }
180 const string16& name() const { return name_; }
181 int32 renderer_id() const { return renderer_id_; }
182 int32 role() const { return role_; }
183 const string16& role_name() const { return role_name_; }
184 int32 state() const { return state_; }
185 const string16& value() const { return value_; }
[email protected]8368e3c2011-03-08 19:26:24186 bool instance_active() const { return instance_active_; }
187 int32 ref_count() const { return ref_count_; }
[email protected]f27e81c2010-10-07 05:20:23188
[email protected]0d7dad62010-10-19 21:18:50189#if defined(OS_MACOSX) && __OBJC__
190 BrowserAccessibilityCocoa* toBrowserAccessibilityCocoa();
[email protected]1dbadbd2010-10-13 18:50:10191#elif defined(OS_WIN)
[email protected]f27e81c2010-10-07 05:20:23192 BrowserAccessibilityWin* toBrowserAccessibilityWin();
193#endif
194
[email protected]ee845122011-09-01 08:44:16195 // Retrieve the value of a bool attribute from the bool attribute
196 // map and returns true if found.
197 bool GetBoolAttribute(WebAccessibility::BoolAttribute attr, bool* value)
198 const;
199
200 // Retrieve the value of a float attribute from the float attribute
201 // map and returns true if found.
202 bool GetFloatAttribute(WebAccessibility::FloatAttribute attr, float* value)
203 const;
[email protected]02747d4e2010-11-03 19:10:00204
[email protected]1b12b232011-07-20 21:16:34205 // Retrieve the value of an integer attribute from the integer attribute
206 // map and returns true if found.
[email protected]ee845122011-09-01 08:44:16207 bool GetIntAttribute(WebAccessibility::IntAttribute attribute, int* value)
208 const;
209
210 // Retrieve the value of a string attribute from the attribute map and
211 // returns true if found.
212 bool GetStringAttribute(WebAccessibility::StringAttribute attribute,
213 string16* value) const;
214
215 // Retrieve the value of a html attribute from the attribute map and
216 // returns true if found.
217 bool GetHtmlAttribute(const char* attr, string16* value) const;
218
219 // Returns true if this node is an editable text field of any kind.
220 bool IsEditableText() const;
[email protected]02747d4e2010-11-03 19:10:00221
[email protected]aa50cea82010-11-05 23:02:38222 protected:
223 BrowserAccessibility();
224
[email protected]f27e81c2010-10-07 05:20:23225 // The manager of this tree of accessibility objects; needed for
226 // global operations like focus tracking.
227 BrowserAccessibilityManager* manager_;
228
229 // The parent of this object, may be NULL if we're the root object.
230 BrowserAccessibility* parent_;
231
232 // The ID of this object; globally unique within the browser process.
233 int32 child_id_;
234
235 // The index of this within its parent object.
236 int32 index_in_parent_;
237
238 // The ID of this object in the renderer process.
239 int32 renderer_id_;
240
241 // The children of this object.
242 std::vector<BrowserAccessibility*> children_;
243
[email protected]8368e3c2011-03-08 19:26:24244 // The number of internal references to this object.
245 int32 ref_count_;
246
[email protected]f27e81c2010-10-07 05:20:23247 // Accessibility metadata from the renderer
248 string16 name_;
249 string16 value_;
[email protected]ee845122011-09-01 08:44:16250 BoolAttrMap bool_attributes_;
251 IntAttrMap int_attributes_;
252 FloatAttrMap float_attributes_;
253 StringAttrMap string_attributes_;
[email protected]f27e81c2010-10-07 05:20:23254 std::vector<std::pair<string16, string16> > html_attributes_;
255 int32 role_;
256 int32 state_;
257 string16 role_name_;
[email protected]0aed2f52011-03-23 18:06:36258 gfx::Rect location_;
[email protected]8368e3c2011-03-08 19:26:24259 std::vector<int32> indirect_child_ids_;
[email protected]be4eeb0b2011-06-15 22:15:06260 std::vector<int32> line_breaks_;
[email protected]1b12b232011-07-20 21:16:34261 std::vector<int32> cell_ids_;
[email protected]ee845122011-09-01 08:44:16262 std::vector<int32> unique_cell_ids_;
[email protected]8368e3c2011-03-08 19:26:24263
264 // BrowserAccessibility objects are reference-counted on some platforms.
265 // When we're done with this object and it's removed from our accessibility
266 // tree, a client may still be holding onto a pointer to this object, so
267 // we mark it as inactive so that calls to any of this object's methods
268 // immediately return failure.
269 bool instance_active_;
[email protected]f27e81c2010-10-07 05:20:23270
[email protected]c5c2a672010-10-01 23:28:04271 private:
272 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility);
273};
274
[email protected]ba1fa652011-06-25 05:16:22275#endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_