blob: 62b5966f960e0dd6b51c49cc7a64ba6075b9953b [file] [log] [blame]
[email protected]c5c2a672010-10-01 23:28:041// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_
6#define CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_
7#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]c5c2a672010-10-01 23:28:0425
26////////////////////////////////////////////////////////////////////////////////
27//
28// BrowserAccessibility
29//
30// Class implementing the cross platform interface for the Browser-Renderer
31// communication of accessibility information, providing accessibility
32// to be used by screen readers and other assistive technology (AT).
33//
34// An implementation for each platform handles platform specific accessibility
35// APIs.
36//
37////////////////////////////////////////////////////////////////////////////////
38class BrowserAccessibility {
39 public:
[email protected]f27e81c2010-10-07 05:20:2340 // Creates a platform specific BrowserAccessibility. Ownership passes to the
[email protected]c5c2a672010-10-01 23:28:0441 // caller.
[email protected]f27e81c2010-10-07 05:20:2342 static BrowserAccessibility* Create();
43
[email protected]c5c2a672010-10-01 23:28:0444 virtual ~BrowserAccessibility();
45
[email protected]f27e81c2010-10-07 05:20:2346 // Perform platform specific initialization. This can be called multiple times
47 // during the lifetime of this instance after the members of this base object
48 // have been reset with new values from the renderer process.
49 virtual void Initialize() = 0;
50
51 // Remove references to all children and delete them if possible.
52 virtual void ReleaseTree();
53
54 // Release a reference to this node. This may be a no-op on platforms other
55 // than windows.
56 virtual void ReleaseReference() = 0;
57
[email protected]405acd1cd2010-10-29 23:53:1758 // Replace a child object. Used when updating the accessibility tree.
59 virtual void ReplaceChild(
60 BrowserAccessibility* old_acc,
61 BrowserAccessibility* new_acc);
62
[email protected]f27e81c2010-10-07 05:20:2363 // Initialize this object
64 void Initialize(BrowserAccessibilityManager* manager,
65 BrowserAccessibility* parent,
66 int32 child_id,
67 int32 index_in_parent,
68 const WebAccessibility& src);
69
70 // Add a child of this object.
71 void AddChild(BrowserAccessibility* child);
72
73 // Return true if this object is equal to or a descendant of |ancestor|.
74 bool IsDescendantOf(BrowserAccessibility* ancestor);
75
76 // Returns the parent of this object, or NULL if it's the root.
77 BrowserAccessibility* GetParent();
78
79 // Returns the number of children of this object.
80 uint32 GetChildCount();
81
82 // Return a pointer to the child with the given index.
83 BrowserAccessibility* GetChild(uint32 child_index);
84
85 // Return the previous sibling of this object, or NULL if it's the first
86 // child of its parent.
87 BrowserAccessibility* GetPreviousSibling();
88
89 // Return the next sibling of this object, or NULL if it's the last child
90 // of its parent.
91 BrowserAccessibility* GetNextSibling();
92
[email protected]02747d4e2010-11-03 19:10:0093 // Returns the bounds of this object in screen coordinates.
94 gfx::Rect GetBoundsRect();
95
96 // Returns the deepest descendant that contains the specified point.
97 BrowserAccessibility* BrowserAccessibilityForPoint(const gfx::Point& point);
98
[email protected]f27e81c2010-10-07 05:20:2399 // Accessors
[email protected]0d7dad62010-10-19 21:18:50100 const std::map<int32, string16>& attributes() const { return attributes_; }
[email protected]f27e81c2010-10-07 05:20:23101 int32 child_id() const { return child_id_; }
102 const std::vector<BrowserAccessibility*>& children() const {
103 return children_;
104 }
[email protected]0d7dad62010-10-19 21:18:50105 const std::vector<std::pair<string16, string16> >& html_attributes() const {
106 return html_attributes_;
107 }
[email protected]f27e81c2010-10-07 05:20:23108 int32 index_in_parent() const { return index_in_parent_; }
109 WebKit::WebRect location() const { return location_; }
[email protected]0d7dad62010-10-19 21:18:50110 BrowserAccessibilityManager* manager() const { return manager_; }
111 const string16& name() const { return name_; }
112 int32 renderer_id() const { return renderer_id_; }
113 int32 role() const { return role_; }
114 const string16& role_name() const { return role_name_; }
115 int32 state() const { return state_; }
116 const string16& value() const { return value_; }
[email protected]f27e81c2010-10-07 05:20:23117
[email protected]0d7dad62010-10-19 21:18:50118#if defined(OS_MACOSX) && __OBJC__
119 BrowserAccessibilityCocoa* toBrowserAccessibilityCocoa();
[email protected]1dbadbd2010-10-13 18:50:10120#elif defined(OS_WIN)
[email protected]f27e81c2010-10-07 05:20:23121 BrowserAccessibilityWin* toBrowserAccessibilityWin();
122#endif
123
[email protected]aa50cea82010-11-05 23:02:38124 // BrowserAccessibilityCocoa needs access to these methods.
[email protected]02747d4e2010-11-03 19:10:00125 // Return true if this attribute is in the attributes map.
126 bool HasAttribute(WebAccessibility::Attribute attribute);
127
128 // Retrieve the string value of an attribute from the attribute map and
129 // returns true if found.
130 bool GetAttribute(WebAccessibility::Attribute attribute, string16* value);
131
132 // Retrieve the value of an attribute from the attribute map and
133 // if found and nonempty, try to convert it to an integer.
134 // Returns true only if both the attribute was found and it was successfully
135 // converted to an integer.
136 bool GetAttributeAsInt(
137 WebAccessibility::Attribute attribute, int* value_int);
138
[email protected]aa50cea82010-11-05 23:02:38139 protected:
140 BrowserAccessibility();
141
[email protected]f27e81c2010-10-07 05:20:23142 // The manager of this tree of accessibility objects; needed for
143 // global operations like focus tracking.
144 BrowserAccessibilityManager* manager_;
145
146 // The parent of this object, may be NULL if we're the root object.
147 BrowserAccessibility* parent_;
148
149 // The ID of this object; globally unique within the browser process.
150 int32 child_id_;
151
152 // The index of this within its parent object.
153 int32 index_in_parent_;
154
155 // The ID of this object in the renderer process.
156 int32 renderer_id_;
157
158 // The children of this object.
159 std::vector<BrowserAccessibility*> children_;
160
161 // Accessibility metadata from the renderer
162 string16 name_;
163 string16 value_;
164 std::map<int32, string16> attributes_;
165 std::vector<std::pair<string16, string16> > html_attributes_;
166 int32 role_;
167 int32 state_;
168 string16 role_name_;
169 WebKit::WebRect location_;
170
[email protected]c5c2a672010-10-01 23:28:04171 private:
172 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility);
173};
174
175#endif // CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_H_