blob: 80a0250340d5b653a040f38227a73be799b3a452 [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]02747d4e2010-11-03 19:10:00100 // Returns the bounds of this object in screen coordinates.
101 gfx::Rect GetBoundsRect();
102
103 // Returns the deepest descendant that contains the specified point.
104 BrowserAccessibility* BrowserAccessibilityForPoint(const gfx::Point& point);
105
[email protected]8368e3c2011-03-08 19:26:24106 //
107 // Reference counting
108 //
109 // Each object has an internal reference count and many platform
110 // implementations may also use native reference counting.
111 //
112 // The internal reference counting is used because sometimes
113 // multiple references to the same object exist temporarily during
114 // an update. When the internal reference count reaches zero,
115 // NativeReleaseReference is called.
116 //
117 // Native reference counting is used on some platforms because the
118 // operating system may hold onto a reference to a BrowserAccessibility
119 // object even after we're through with it. On these platforms, when
120 // the internal reference count reaches zero, instance_active is set
121 // to zero, and all queries on this object should return failure.
122 // The object isn't actually deleted until the operating system releases
123 // all of its references.
124 //
125
126 // Increment this node's internal reference count.
127 virtual void InternalAddReference();
128
129 // Decrement this node's internal reference count. If the reference count
130 // reaches zero, call NativeReleaseReference().
131 virtual void InternalReleaseReference(bool recursive);
132
133 // Subclasses should override this to support platform reference counting.
134 virtual void NativeAddReference() { }
135
136 // Subclasses should override this to support platform reference counting.
[email protected]402da9f2011-03-08 19:45:41137 virtual void NativeReleaseReference();
[email protected]8368e3c2011-03-08 19:26:24138
139 //
[email protected]f27e81c2010-10-07 05:20:23140 // Accessors
[email protected]8368e3c2011-03-08 19:26:24141 //
142
[email protected]ee845122011-09-01 08:44:16143 const BoolAttrMap& bool_attributes() const {
144 return bool_attributes_;
[email protected]1b12b232011-07-20 21:16:34145 }
146
[email protected]ee845122011-09-01 08:44:16147 const FloatAttrMap& float_attributes() const {
148 return float_attributes_;
149 }
150
151 const IntAttrMap& int_attributes() const {
[email protected]1b12b232011-07-20 21:16:34152 return int_attributes_;
153 }
154
[email protected]ee845122011-09-01 08:44:16155 const StringAttrMap& string_attributes() const {
156 return string_attributes_;
157 }
158
[email protected]f27e81c2010-10-07 05:20:23159 int32 child_id() const { return child_id_; }
160 const std::vector<BrowserAccessibility*>& children() const {
161 return children_;
162 }
[email protected]0d7dad62010-10-19 21:18:50163 const std::vector<std::pair<string16, string16> >& html_attributes() const {
164 return html_attributes_;
165 }
[email protected]f27e81c2010-10-07 05:20:23166 int32 index_in_parent() const { return index_in_parent_; }
[email protected]457af8d2011-05-14 01:02:47167 const std::vector<int32>& indirect_child_ids() const {
168 return indirect_child_ids_;
169 }
[email protected]80d647532011-06-17 22:53:49170 const std::vector<int32>& line_breaks() const {
171 return line_breaks_;
172 }
[email protected]1b12b232011-07-20 21:16:34173 const std::vector<int32>& cell_ids() const {
174 return cell_ids_;
175 }
[email protected]ee845122011-09-01 08:44:16176 const std::vector<int32>& unique_cell_ids() const {
177 return unique_cell_ids_;
178 }
[email protected]0aed2f52011-03-23 18:06:36179 gfx::Rect location() const { return location_; }
[email protected]0d7dad62010-10-19 21:18:50180 BrowserAccessibilityManager* manager() const { return manager_; }
181 const string16& name() const { return name_; }
182 int32 renderer_id() const { return renderer_id_; }
183 int32 role() const { return role_; }
184 const string16& role_name() const { return role_name_; }
185 int32 state() const { return state_; }
186 const string16& value() const { return value_; }
[email protected]8368e3c2011-03-08 19:26:24187 bool instance_active() const { return instance_active_; }
188 int32 ref_count() const { return ref_count_; }
[email protected]f27e81c2010-10-07 05:20:23189
[email protected]0d7dad62010-10-19 21:18:50190#if defined(OS_MACOSX) && __OBJC__
191 BrowserAccessibilityCocoa* toBrowserAccessibilityCocoa();
[email protected]1dbadbd2010-10-13 18:50:10192#elif defined(OS_WIN)
[email protected]f27e81c2010-10-07 05:20:23193 BrowserAccessibilityWin* toBrowserAccessibilityWin();
194#endif
195
[email protected]ee845122011-09-01 08:44:16196 // Retrieve the value of a bool attribute from the bool attribute
197 // map and returns true if found.
198 bool GetBoolAttribute(WebAccessibility::BoolAttribute attr, bool* value)
199 const;
200
201 // Retrieve the value of a float attribute from the float attribute
202 // map and returns true if found.
203 bool GetFloatAttribute(WebAccessibility::FloatAttribute attr, float* value)
204 const;
[email protected]02747d4e2010-11-03 19:10:00205
[email protected]1b12b232011-07-20 21:16:34206 // Retrieve the value of an integer attribute from the integer attribute
207 // map and returns true if found.
[email protected]ee845122011-09-01 08:44:16208 bool GetIntAttribute(WebAccessibility::IntAttribute attribute, int* value)
209 const;
210
211 // Retrieve the value of a string attribute from the attribute map and
212 // returns true if found.
213 bool GetStringAttribute(WebAccessibility::StringAttribute attribute,
214 string16* value) const;
215
216 // Retrieve the value of a html attribute from the attribute map and
217 // returns true if found.
218 bool GetHtmlAttribute(const char* attr, string16* value) const;
219
220 // Returns true if this node is an editable text field of any kind.
221 bool IsEditableText() const;
[email protected]02747d4e2010-11-03 19:10:00222
[email protected]aa50cea82010-11-05 23:02:38223 protected:
224 BrowserAccessibility();
225
[email protected]f27e81c2010-10-07 05:20:23226 // The manager of this tree of accessibility objects; needed for
227 // global operations like focus tracking.
228 BrowserAccessibilityManager* manager_;
229
230 // The parent of this object, may be NULL if we're the root object.
231 BrowserAccessibility* parent_;
232
233 // The ID of this object; globally unique within the browser process.
234 int32 child_id_;
235
236 // The index of this within its parent object.
237 int32 index_in_parent_;
238
239 // The ID of this object in the renderer process.
240 int32 renderer_id_;
241
242 // The children of this object.
243 std::vector<BrowserAccessibility*> children_;
244
[email protected]8368e3c2011-03-08 19:26:24245 // The number of internal references to this object.
246 int32 ref_count_;
247
[email protected]f27e81c2010-10-07 05:20:23248 // Accessibility metadata from the renderer
249 string16 name_;
250 string16 value_;
[email protected]ee845122011-09-01 08:44:16251 BoolAttrMap bool_attributes_;
252 IntAttrMap int_attributes_;
253 FloatAttrMap float_attributes_;
254 StringAttrMap string_attributes_;
[email protected]f27e81c2010-10-07 05:20:23255 std::vector<std::pair<string16, string16> > html_attributes_;
256 int32 role_;
257 int32 state_;
258 string16 role_name_;
[email protected]0aed2f52011-03-23 18:06:36259 gfx::Rect location_;
[email protected]8368e3c2011-03-08 19:26:24260 std::vector<int32> indirect_child_ids_;
[email protected]be4eeb0b2011-06-15 22:15:06261 std::vector<int32> line_breaks_;
[email protected]1b12b232011-07-20 21:16:34262 std::vector<int32> cell_ids_;
[email protected]ee845122011-09-01 08:44:16263 std::vector<int32> unique_cell_ids_;
[email protected]8368e3c2011-03-08 19:26:24264
265 // BrowserAccessibility objects are reference-counted on some platforms.
266 // When we're done with this object and it's removed from our accessibility
267 // tree, a client may still be holding onto a pointer to this object, so
268 // we mark it as inactive so that calls to any of this object's methods
269 // immediately return failure.
270 bool instance_active_;
[email protected]f27e81c2010-10-07 05:20:23271
[email protected]c5c2a672010-10-01 23:28:04272 private:
273 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility);
274};
275
[email protected]ba1fa652011-06-25 05:16:22276#endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_