| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_BROWSER_ACCESSIBILITY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_BROWSER_ACCESSIBILITY_MANAGER_H_ |
| 6 #define CHROME_BROWSER_BROWSER_ACCESSIBILITY_MANAGER_H_ | 6 #define CHROME_BROWSER_BROWSER_ACCESSIBILITY_MANAGER_H_ |
| 7 | 7 |
| 8 #include <atlbase.h> | |
| 9 #include <atlcom.h> | |
| 10 #include <oleacc.h> | |
| 11 | |
| 12 #include <map> | 8 #include <map> |
| 13 | 9 |
| 14 #include "base/hash_tables.h" | 10 #include "base/singleton.h" |
| 15 #include "base/scoped_comptr_win.h" | 11 #include "chrome/common/notification_registrar.h" |
| 16 #include "base/scoped_ptr.h" | |
| 17 #include "webkit/glue/webaccessibility.h" | 12 #include "webkit/glue/webaccessibility.h" |
| 18 | 13 |
| 19 class BrowserAccessibility; | 14 class BrowserAccessibility; |
| 20 class RenderProcessHost; | 15 class RenderProcessHost; |
| 21 class RenderWidgetHost; | 16 class RenderWidgetHost; |
| 22 | 17 |
| 23 class BrowserAccessibilityFactory { | 18 using webkit_glue::WebAccessibility; |
| 19 |
| 20 //////////////////////////////////////////////////////////////////////////////// |
| 21 // |
| 22 // BrowserAccessibilityManager |
| 23 // |
| 24 // Used to manage instance creation and memory handling for browser side |
| 25 // accessibility. A singleton class. It implements NotificationObserver to |
| 26 // ensure that a termination of a renderer process gets propagated to the |
| 27 // active BrowserAccessibility instances calling into it. Each such instance |
| 28 // will upon such an event be set to an inactive state, failing calls from the |
| 29 // assistive technology gracefully. |
| 30 //////////////////////////////////////////////////////////////////////////////// |
| 31 class BrowserAccessibilityManager : public NotificationObserver { |
| 24 public: | 32 public: |
| 25 virtual ~BrowserAccessibilityFactory() {} | 33 // Gets the singleton BrowserAccessibilityManager object. The first time this |
| 34 // method is called, a CacheManagerHost object is constructed and returned. |
| 35 // Subsequent calls will return the same object. |
| 36 static BrowserAccessibilityManager* GetInstance(); |
| 26 | 37 |
| 27 // Create an instance of BrowserAccessibility and return a new | 38 // Creates an instance of BrowserAccessibility, initializes it and sets the |
| 28 // reference to it. | 39 // |acc_obj_id|, which is used for IPC communication, and |instance_id|, |
| 29 virtual BrowserAccessibility* Create(); | 40 // which is used to identify the mapping between accessibility instance and |
| 30 }; | 41 // RenderProcess. |
| 42 STDMETHODIMP CreateAccessibilityInstance(REFIID iid, |
| 43 int acc_obj_id, |
| 44 int routing_id, |
| 45 int process_id, |
| 46 HWND parent_hwnd, |
| 47 void** interface_ptr); |
| 31 | 48 |
| 32 // Manages a tree of BrowserAccessibility objects. | 49 // Composes and sends a message for requesting needed accessibility |
| 33 class BrowserAccessibilityManager { | 50 // information. |
| 34 public: | 51 bool RequestAccessibilityInfo(WebAccessibility::InParams* in, |
| 35 BrowserAccessibilityManager( | 52 int routing_id, |
| 36 HWND parent_hwnd, | 53 int process_id); |
| 37 const webkit_glue::WebAccessibility& src, | |
| 38 BrowserAccessibilityFactory* factory = new BrowserAccessibilityFactory()); | |
| 39 | 54 |
| 40 virtual ~BrowserAccessibilityManager(); | 55 // Notifies assistive technology that renderer focus changed, through the |
| 56 // platform-specific channels. |
| 57 bool ChangeAccessibilityFocus(int acc_obj_id, int process_id, int routing_id); |
| 41 | 58 |
| 42 // Return a pointer to the root of the tree, does not make a new reference. | 59 // Notifies assistive technology that an object's state changed, through the |
| 43 BrowserAccessibility* GetRoot(); | 60 // platform-specific channels. |
| 61 bool OnAccessibilityObjectStateChange(int acc_obj_id, |
| 62 int process_id, |
| 63 int routing_id); |
| 44 | 64 |
| 45 // Return a pointer to the object corresponding to the given child_id, | 65 // Wrapper function, for cleaner code. |
| 46 // does not make a new reference. | 66 const WebAccessibility::OutParams& response(); |
| 47 BrowserAccessibility* GetFromChildID(LONG child_id); | |
| 48 | 67 |
| 49 // Get a the default IAccessible for the parent window, does not make a | 68 // NotificationObserver implementation. |
| 50 // new reference. | 69 virtual void Observe(NotificationType type, |
| 51 IAccessible* GetParentWindowIAccessible(); | 70 const NotificationSource& source, |
| 71 const NotificationDetails& details); |
| 52 | 72 |
| 53 // Get the parent window. | 73 protected: |
| 54 HWND GetParentHWND(); | 74 // This class is a singleton. Do not instantiate directly. |
| 75 BrowserAccessibilityManager(); |
| 76 friend struct DefaultSingletonTraits<BrowserAccessibilityManager>; |
| 55 | 77 |
| 56 // Return the object that has focus, if it's a descandant of the | 78 ~BrowserAccessibilityManager(); |
| 57 // given root (inclusive). Does not make a new reference. | |
| 58 BrowserAccessibility* GetFocus(BrowserAccessibility* root); | |
| 59 | |
| 60 // Called when the renderer process has notified us of a focus or state | |
| 61 // change. Send a notification to MSAA clients of the change. | |
| 62 void OnAccessibilityFocusChange(int acc_obj_id); | |
| 63 void OnAccessibilityObjectStateChange(int acc_obj_id); | |
| 64 | 79 |
| 65 private: | 80 private: |
| 66 // Recursively build a tree of BrowserAccessibility objects from | 81 // Retrieves the BrowserAccessibility instance connected to the |
| 67 // the WebAccessibility tree received from the renderer process. | 82 // RenderProcessHost identified by the process/routing id pair. |
| 68 BrowserAccessibility* CreateAccessibilityTree( | 83 BrowserAccessibility* GetBrowserAccessibility(int process_id, int routing_id); |
| 69 BrowserAccessibility* parent, | |
| 70 const webkit_glue::WebAccessibility& src, | |
| 71 int index_in_parent); | |
| 72 | 84 |
| 73 // The parent window. | 85 // Multi-map from process id (key) to active BrowserAccessibility instances |
| 74 HWND parent_hwnd_; | 86 // for that RenderProcessHost. |
| 87 typedef std::multimap<int, BrowserAccessibility*> RenderProcessHostMap; |
| 88 typedef std::pair<int, BrowserAccessibility*> MapEntry; |
| 75 | 89 |
| 76 // Factory to create BrowserAccessibility objects (for dependency injection). | 90 NotificationRegistrar registrar_; |
| 77 scoped_ptr<BrowserAccessibilityFactory> factory_; | |
| 78 | 91 |
| 79 // A default IAccessible instance for the parent window. | 92 // Mapping to track which RenderProcessHosts ids are active. If a |
| 80 ScopedComPtr<IAccessible> window_iaccessible_; | 93 // RenderProcessHost is found to be terminated, its id (key) should be removed |
| 94 // from this mapping, and the connected BrowserAccessibility ids/instances |
| 95 // invalidated. |
| 96 RenderProcessHostMap render_process_host_map_; |
| 81 | 97 |
| 82 // The root of the tree of IAccessible objects and the element that | 98 // Structure passed by reference to hold response parameters from the |
| 83 // currently has focus, if any. | 99 // renderer. |
| 84 BrowserAccessibility* root_; | 100 WebAccessibility::OutParams out_params_; |
| 85 BrowserAccessibility* focus_; | |
| 86 | |
| 87 // A mapping from the IDs of objects in the renderer, to the child IDs | |
| 88 // we use internally here. | |
| 89 base::hash_map<int, LONG> renderer_id_to_child_id_map_; | |
| 90 | |
| 91 // A mapping from child IDs to BrowserAccessibility objects. | |
| 92 base::hash_map<LONG, BrowserAccessibility*> child_id_map_; | |
| 93 | |
| 94 // The next child ID to use; static so that they're global to the process. | |
| 95 // Screen readers cache these IDs to see if they've seen the same object | |
| 96 // before so we should avoid reusing them within the same project. | |
| 97 static LONG next_child_id_; | |
| 98 | 101 |
| 99 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManager); | 102 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManager); |
| 100 }; | 103 }; |
| 101 | |
| 102 #endif // CHROME_BROWSER_BROWSER_ACCESSIBILITY_MANAGER_H_ | 104 #endif // CHROME_BROWSER_BROWSER_ACCESSIBILITY_MANAGER_H_ |
| OLD | NEW |