OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_H_ |
6 #define CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_H_ | 6 #define CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
12 #include <oleacc.h> | 12 #include <oleacc.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/hash_tables.h" | |
18 #include "base/scoped_ptr.h" | |
19 #include "chrome/common/render_messages_params.h" | |
20 #include "gfx/native_widget_types.h" | 17 #include "gfx/native_widget_types.h" |
21 #include "webkit/glue/webaccessibility.h" | 18 #include "webkit/glue/webaccessibility.h" |
22 | 19 |
23 | 20 struct ViewHostMsg_AccessibilityNotification_Params; |
24 class BrowserAccessibility; | |
25 #if defined(OS_WIN) | |
26 class BrowserAccessibilityManagerWin; | |
27 #endif | |
28 | 21 |
29 using webkit_glue::WebAccessibility; | 22 using webkit_glue::WebAccessibility; |
30 | 23 |
31 // Class that can perform actions on behalf of the BrowserAccessibilityManager. | 24 // Class that can perform actions on behalf of the BrowserAccessibilityManager. |
32 class BrowserAccessibilityDelegate { | 25 class BrowserAccessibilityDelegate { |
33 public: | 26 public: |
34 virtual ~BrowserAccessibilityDelegate() {} | 27 virtual ~BrowserAccessibilityDelegate() {} |
35 virtual void SetAccessibilityFocus(int acc_obj_id) = 0; | 28 virtual void SetAccessibilityFocus(int acc_obj_id) = 0; |
36 virtual void AccessibilityDoDefaultAction(int acc_obj_id) = 0; | 29 virtual void AccessibilityDoDefaultAction(int acc_obj_id) = 0; |
37 virtual bool HasFocus() = 0; | 30 virtual bool HasFocus() = 0; |
38 }; | 31 }; |
39 | 32 |
40 class BrowserAccessibilityFactory { | |
41 public: | |
42 virtual ~BrowserAccessibilityFactory() {} | |
43 | |
44 // Create an instance of BrowserAccessibility and return a new | |
45 // reference to it. | |
46 virtual BrowserAccessibility* Create(); | |
47 }; | |
48 | |
49 // Manages a tree of BrowserAccessibility objects. | 33 // Manages a tree of BrowserAccessibility objects. |
50 class BrowserAccessibilityManager { | 34 class BrowserAccessibilityManager { |
51 public: | 35 public: |
52 // Creates the platform specific BrowserAccessibilityManager. Ownership passes | 36 // Creates the platform specific BrowserAccessibilityManager. Ownership passes |
53 // to the caller. | 37 // to the caller. |
54 static BrowserAccessibilityManager* Create( | 38 static BrowserAccessibilityManager* Create( |
55 gfx::NativeView parent_view, | 39 gfx::NativeWindow parent_window, |
56 const WebAccessibility& src, | 40 const webkit_glue::WebAccessibility& src, |
57 BrowserAccessibilityDelegate* delegate, | 41 BrowserAccessibilityDelegate* delegate); |
58 BrowserAccessibilityFactory* factory = new BrowserAccessibilityFactory()); | |
59 | 42 |
60 virtual ~BrowserAccessibilityManager(); | 43 virtual ~BrowserAccessibilityManager(); |
61 | 44 |
62 virtual void NotifyAccessibilityEvent( | |
63 ViewHostMsg_AccessibilityNotification_Params::NotificationType n, | |
64 BrowserAccessibility* node) = 0; | |
65 | |
66 // Returns the next unique child id. | |
67 static int32 GetNextChildID(); | |
68 | |
69 // Return a pointer to the root of the tree, does not make a new reference. | |
70 BrowserAccessibility* GetRoot(); | |
71 | |
72 // Removes the BrowserAccessibility child_id from the manager. | |
73 void Remove(int32 child_id); | |
74 | |
75 // Return a pointer to the object corresponding to the given child_id, | |
76 // does not make a new reference. | |
77 BrowserAccessibility* GetFromChildID(int32 child_id); | |
78 | |
79 // Called to notify the accessibility manager that its associated native | 45 // Called to notify the accessibility manager that its associated native |
80 // view got focused. | 46 // window got focused. |
81 void GotFocus(); | 47 virtual void GotFocus() = 0; |
82 | |
83 // Tell the renderer to set focus to this node. | |
84 void SetFocus(const BrowserAccessibility& node); | |
85 | |
86 // Tell the renderer to do the default action for this node. | |
87 void DoDefaultAction(const BrowserAccessibility& node); | |
88 | 48 |
89 // Called when the renderer process has notified us of about tree changes. | 49 // Called when the renderer process has notified us of about tree changes. |
90 // Send a notification to MSAA clients of the change. | 50 // Send a notification to MSAA clients of the change. |
91 void OnAccessibilityNotifications( | 51 void OnAccessibilityNotifications( |
92 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params); | 52 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params); |
93 | 53 |
94 gfx::NativeView GetParentView(); | 54 gfx::NativeWindow GetParentWindow(); |
95 | 55 |
96 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
97 BrowserAccessibilityManagerWin* toBrowserAccessibilityManagerWin(); | 57 virtual IAccessible* GetRootAccessible() = 0; |
98 #endif | 58 #endif |
99 | 59 |
100 // Return the object that has focus, if it's a descandant of the | 60 protected: |
101 // given root (inclusive). Does not make a new reference. | 61 explicit BrowserAccessibilityManager(gfx::NativeWindow parent_window); |
102 BrowserAccessibility* GetFocus(BrowserAccessibility* root); | |
103 | 62 |
104 protected: | 63 virtual void OnAccessibilityObjectStateChange( |
105 BrowserAccessibilityManager( | 64 const webkit_glue::WebAccessibility& acc_obj) = 0; |
106 gfx::NativeView parent_view, | 65 virtual void OnAccessibilityObjectChildrenChange( |
107 const WebAccessibility& src, | 66 const webkit_glue::WebAccessibility& acc_obj) = 0; |
108 BrowserAccessibilityDelegate* delegate, | 67 virtual void OnAccessibilityObjectFocusChange( |
109 BrowserAccessibilityFactory* factory); | 68 const webkit_glue::WebAccessibility& acc_obj) = 0; |
| 69 virtual void OnAccessibilityObjectLoadComplete( |
| 70 const webkit_glue::WebAccessibility& acc_obj) = 0; |
| 71 virtual void OnAccessibilityObjectValueChange( |
| 72 const webkit_glue::WebAccessibility& acc_obj) = 0; |
| 73 virtual void OnAccessibilityObjectTextChange( |
| 74 const webkit_glue::WebAccessibility& acc_obj) = 0; |
110 | 75 |
111 private: | 76 private: |
112 void OnAccessibilityObjectStateChange( | 77 // The parent window. |
113 const WebAccessibility& acc_obj); | 78 gfx::NativeWindow parent_window_; |
114 void OnAccessibilityObjectChildrenChange( | |
115 const WebAccessibility& acc_obj); | |
116 void OnAccessibilityObjectFocusChange( | |
117 const WebAccessibility& acc_obj); | |
118 void OnAccessibilityObjectLoadComplete( | |
119 const WebAccessibility& acc_obj); | |
120 void OnAccessibilityObjectValueChange( | |
121 const WebAccessibility& acc_obj); | |
122 void OnAccessibilityObjectTextChange( | |
123 const WebAccessibility& acc_obj); | |
124 | |
125 // Recursively compare the IDs of our subtree to a new subtree received | |
126 // from the renderer and return true if their IDs match exactly. | |
127 bool CanModifyTreeInPlace( | |
128 BrowserAccessibility* current_root, | |
129 const WebAccessibility& new_root); | |
130 | |
131 // Recursively modify a subtree (by reinitializing) to match a new | |
132 // subtree received from the renderer process. Should only be called | |
133 // if CanModifyTreeInPlace returned true. | |
134 void ModifyTreeInPlace( | |
135 BrowserAccessibility* current_root, | |
136 const WebAccessibility& new_root); | |
137 | |
138 // Update the accessibility tree with an updated WebAccessibility tree or | |
139 // subtree received from the renderer process. First attempts to modify | |
140 // the tree in place, and if that fails, replaces the entire subtree. | |
141 // Returns the updated node or NULL if no node was updated. | |
142 BrowserAccessibility* UpdateTree( | |
143 const WebAccessibility& acc_obj); | |
144 | |
145 // Recursively build a tree of BrowserAccessibility objects from | |
146 // the WebAccessibility tree received from the renderer process. | |
147 BrowserAccessibility* CreateAccessibilityTree( | |
148 BrowserAccessibility* parent, | |
149 int child_id, | |
150 const WebAccessibility& src, | |
151 int index_in_parent); | |
152 | |
153 protected: | |
154 // The next unique id for a BrowserAccessibility instance. | |
155 static int32 next_child_id_; | |
156 | |
157 // The parent view. | |
158 gfx::NativeView parent_view_; | |
159 | |
160 // The object that can perform actions on our behalf. | |
161 BrowserAccessibilityDelegate* delegate_; | |
162 | |
163 // Factory to create BrowserAccessibility objects (for dependency injection). | |
164 scoped_ptr<BrowserAccessibilityFactory> factory_; | |
165 | |
166 // The root of the tree of IAccessible objects and the element that | |
167 // currently has focus, if any. | |
168 BrowserAccessibility* root_; | |
169 BrowserAccessibility* focus_; | |
170 | |
171 // A mapping from the IDs of objects in the renderer, to the child IDs | |
172 // we use internally here. | |
173 base::hash_map<int, int32> renderer_id_to_child_id_map_; | |
174 | |
175 // A mapping from child IDs to BrowserAccessibility objects. | |
176 base::hash_map<int32, BrowserAccessibility*> child_id_map_; | |
177 | 79 |
178 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManager); | 80 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManager); |
179 }; | 81 }; |
180 | 82 |
181 #endif // CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_H_ | 83 #endif // CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_H_ |
OLD | NEW |