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