| 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_WIN_H_ | 5 #ifndef CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_WIN_H_ |
| 6 #define CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_WIN_H_ | 6 #define CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_WIN_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <atlbase.h> | |
| 10 #include <atlcom.h> | |
| 11 #include <oleacc.h> | 9 #include <oleacc.h> |
| 12 | 10 |
| 13 #include <hash_map> | 11 #include "base/scoped_comptr_win.h" |
| 14 #include <vector> | |
| 15 | |
| 16 #include "chrome/browser/accessibility/browser_accessibility_manager.h" | 12 #include "chrome/browser/accessibility/browser_accessibility_manager.h" |
| 17 #include "base/hash_tables.h" | 13 #include "chrome/common/render_messages_params.h" |
| 18 #include "base/scoped_comptr_win.h" | |
| 19 #include "base/scoped_ptr.h" | |
| 20 #include "webkit/glue/webaccessibility.h" | 14 #include "webkit/glue/webaccessibility.h" |
| 21 | 15 |
| 22 class BrowserAccessibilityWin; | 16 class BrowserAccessibilityWin; |
| 23 struct ViewHostMsg_AccessibilityNotification_Params; | 17 struct ViewHostMsg_AccessibilityNotification_Params; |
| 24 | 18 |
| 25 class BrowserAccessibilityWinFactory { | 19 using webkit_glue::WebAccessibility; |
| 26 public: | |
| 27 virtual ~BrowserAccessibilityWinFactory() {} | |
| 28 | |
| 29 // Create an instance of BrowserAccessibilityWin and return a new | |
| 30 // reference to it. | |
| 31 virtual BrowserAccessibilityWin* Create(); | |
| 32 }; | |
| 33 | 20 |
| 34 // Manages a tree of BrowserAccessibilityWin objects. | 21 // Manages a tree of BrowserAccessibilityWin objects. |
| 35 class BrowserAccessibilityManagerWin : public BrowserAccessibilityManager { | 22 class BrowserAccessibilityManagerWin : public BrowserAccessibilityManager { |
| 36 public: | 23 public: |
| 37 BrowserAccessibilityManagerWin( | |
| 38 HWND parent_window, | |
| 39 const webkit_glue::WebAccessibility& src, | |
| 40 BrowserAccessibilityDelegate* delegate, | |
| 41 BrowserAccessibilityWinFactory* factory = | |
| 42 new BrowserAccessibilityWinFactory()); | |
| 43 | |
| 44 virtual ~BrowserAccessibilityManagerWin(); | 24 virtual ~BrowserAccessibilityManagerWin(); |
| 45 | 25 |
| 46 // Return a pointer to the root of the tree, does not make a new reference. | |
| 47 BrowserAccessibilityWin* GetRoot(); | |
| 48 | |
| 49 // Removes the BrowserAccessibilityWin child_id from the manager. | |
| 50 void Remove(LONG child_id); | |
| 51 | |
| 52 // Return a pointer to the object corresponding to the given child_id, | |
| 53 // does not make a new reference. | |
| 54 BrowserAccessibilityWin* GetFromChildID(LONG child_id); | |
| 55 | |
| 56 // Get a the default IAccessible for the parent window, does not make a | 26 // Get a the default IAccessible for the parent window, does not make a |
| 57 // new reference. | 27 // new reference. |
| 58 IAccessible* GetParentWindowIAccessible(); | 28 IAccessible* GetParentWindowIAccessible(); |
| 59 | 29 |
| 60 // Return the object that has focus, if it's a descandant of the | 30 // BrowserAccessibilityManager methods |
| 61 // given root (inclusive). Does not make a new reference. | 31 virtual void NotifyAccessibilityEvent( |
| 62 BrowserAccessibilityWin* GetFocus(BrowserAccessibilityWin* root); | 32 ViewHostMsg_AccessibilityNotification_Params::NotificationType n, |
| 63 | 33 BrowserAccessibility* node); |
| 64 // Tell the renderer to set focus to this node. | |
| 65 void SetFocus(const BrowserAccessibilityWin& node); | |
| 66 | |
| 67 // Tell the renderer to do the default action for this node. | |
| 68 void DoDefaultAction(const BrowserAccessibilityWin& node); | |
| 69 | |
| 70 // BrowserAccessibilityManager Methods | |
| 71 virtual void GotFocus(); | |
| 72 virtual IAccessible* GetRootAccessible(); | |
| 73 virtual void OnAccessibilityObjectStateChange( | |
| 74 const webkit_glue::WebAccessibility& acc_obj); | |
| 75 virtual void OnAccessibilityObjectChildrenChange( | |
| 76 const webkit_glue::WebAccessibility& acc_obj); | |
| 77 virtual void OnAccessibilityObjectFocusChange( | |
| 78 const webkit_glue::WebAccessibility& acc_obj); | |
| 79 virtual void OnAccessibilityObjectLoadComplete( | |
| 80 const webkit_glue::WebAccessibility& acc_obj); | |
| 81 virtual void OnAccessibilityObjectValueChange( | |
| 82 const webkit_glue::WebAccessibility& acc_obj); | |
| 83 virtual void OnAccessibilityObjectTextChange( | |
| 84 const webkit_glue::WebAccessibility& acc_obj); | |
| 85 | 34 |
| 86 private: | 35 private: |
| 87 // Recursively compare the IDs of our subtree to a new subtree received | 36 BrowserAccessibilityManagerWin( |
| 88 // from the renderer and return true if their IDs match exactly. | 37 HWND parent_window, |
| 89 bool CanModifyTreeInPlace( | 38 const WebAccessibility& src, |
| 90 BrowserAccessibilityWin* current_root, | 39 BrowserAccessibilityDelegate* delegate, |
| 91 const webkit_glue::WebAccessibility& new_root); | 40 BrowserAccessibilityFactory* factory); |
| 92 | |
| 93 // Recursively modify a subtree (by reinitializing) to match a new | |
| 94 // subtree received from the renderer process. Should only be called | |
| 95 // if CanModifyTreeInPlace returned true. | |
| 96 void ModifyTreeInPlace( | |
| 97 BrowserAccessibilityWin* current_root, | |
| 98 const webkit_glue::WebAccessibility& new_root); | |
| 99 | |
| 100 // Update the accessibility tree with an updated WebAccessibility tree or | |
| 101 // subtree received from the renderer process. First attempts to modify | |
| 102 // the tree in place, and if that fails, replaces the entire subtree. | |
| 103 // Returns the updated node or NULL if no node was updated. | |
| 104 BrowserAccessibilityWin* UpdateTree( | |
| 105 const webkit_glue::WebAccessibility& acc_obj); | |
| 106 | |
| 107 // Returns the next MSAA child id. | |
| 108 static LONG GetNextChildID(); | |
| 109 | |
| 110 // Recursively build a tree of BrowserAccessibilityWin objects from | |
| 111 // the WebAccessibility tree received from the renderer process. | |
| 112 BrowserAccessibilityWin* CreateAccessibilityTree( | |
| 113 BrowserAccessibilityWin* parent, | |
| 114 int child_id, | |
| 115 const webkit_glue::WebAccessibility& src, | |
| 116 int index_in_parent); | |
| 117 | |
| 118 // The object that can perform actions on our behalf. | |
| 119 BrowserAccessibilityDelegate* delegate_; | |
| 120 | |
| 121 // Factory to create BrowserAccessibility objects (for dependency injection). | |
| 122 scoped_ptr<BrowserAccessibilityWinFactory> factory_; | |
| 123 | 41 |
| 124 // A default IAccessible instance for the parent window. | 42 // A default IAccessible instance for the parent window. |
| 125 ScopedComPtr<IAccessible> window_iaccessible_; | 43 ScopedComPtr<IAccessible> window_iaccessible_; |
| 126 | 44 |
| 127 // The root of the tree of IAccessible objects and the element that | 45 // Give BrowserAccessibilityManager::Create access to our constructor. |
| 128 // currently has focus, if any. | 46 friend class BrowserAccessibilityManager; |
| 129 BrowserAccessibilityWin* root_; | |
| 130 BrowserAccessibilityWin* focus_; | |
| 131 | |
| 132 // A mapping from the IDs of objects in the renderer, to the child IDs | |
| 133 // we use internally here. | |
| 134 base::hash_map<int, LONG> renderer_id_to_child_id_map_; | |
| 135 | |
| 136 // A mapping from child IDs to BrowserAccessibilityWin objects. | |
| 137 base::hash_map<LONG, BrowserAccessibilityWin*> child_id_map_; | |
| 138 | |
| 139 // The next child ID to use; static so that they're global to the process. | |
| 140 // Screen readers cache these IDs to see if they've seen the same object | |
| 141 // before so we should avoid reusing them within the same project. | |
| 142 static LONG next_child_id_; | |
| 143 | 47 |
| 144 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManagerWin); | 48 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManagerWin); |
| 145 }; | 49 }; |
| 146 | 50 |
| 147 #endif // CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_WIN_H_ | 51 #endif // CHROME_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_MANAGER_WIN_H_ |
| OLD | NEW |