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