| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEWS_H
_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEWS_H
_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEWS_H
_ | 6 #define CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEWS_H
_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "chrome/browser/accessibility/accessibility_events.h" | 13 #include "chrome/browser/accessibility/accessibility_events.h" |
| 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" |
| 14 #include "ui/base/accessibility/accessibility_types.h" | 16 #include "ui/base/accessibility/accessibility_types.h" |
| 15 | 17 |
| 16 class Profile; | 18 class Profile; |
| 17 | 19 |
| 18 template <typename T> struct DefaultSingletonTraits; | 20 template <typename T> struct DefaultSingletonTraits; |
| 19 | 21 |
| 20 namespace views { | 22 namespace views { |
| 21 class View; | 23 class View; |
| 22 } | 24 } |
| 23 | 25 |
| 24 // NOTE: This class is part of the Accessibility Extension API, which lets | 26 // NOTE: This class is part of the Accessibility Extension API, which lets |
| 25 // extensions receive accessibility events. It's distinct from code that | 27 // extensions receive accessibility events. It's distinct from code that |
| 26 // implements platform accessibility APIs like MSAA or ATK. | 28 // implements platform accessibility APIs like MSAA or ATK. |
| 27 // | 29 // |
| 28 // Singleton class that adds listeners to many views, then sends an | 30 // Singleton class that adds listeners to many views, then sends an |
| 29 // accessibility notification whenever a relevant event occurs in an | 31 // accessibility notification whenever a relevant event occurs in an |
| 30 // accessible view. | 32 // accessible view. |
| 31 // | 33 // |
| 32 // Views are not accessible by default. When you register a root widget, | 34 // Views are not accessible by default. When you register a root widget, |
| 33 // that widget and all of its descendants will start sending accessibility | 35 // that widget and all of its descendants will start sending accessibility |
| 34 // event notifications. You can then override the default behavior for | 36 // event notifications. You can then override the default behavior for |
| 35 // specific descendants using other methods. | 37 // specific descendants using other methods. |
| 36 // | 38 // |
| 37 // You can use Profile::PauseAccessibilityEvents to prevent a flurry | 39 // You can use Profile::PauseAccessibilityEvents to prevent a flurry |
| 38 // of accessibility events when a window is being created or initialized. | 40 // of accessibility events when a window is being created or initialized. |
| 39 class AccessibilityEventRouterViews { | 41 class AccessibilityEventRouterViews : public content::NotificationObserver { |
| 40 public: | 42 public: |
| 41 // Internal information about a particular view to override the | 43 // Internal information about a particular view to override the |
| 42 // information we get directly from the view. | 44 // information we get directly from the view. |
| 43 struct ViewInfo { | 45 struct ViewInfo { |
| 44 ViewInfo() : ignore(false) {} | 46 ViewInfo() : ignore(false) {} |
| 45 | 47 |
| 46 // If nonempty, will use this name instead of the view's label. | 48 // If nonempty, will use this name instead of the view's label. |
| 47 std::string name; | 49 std::string name; |
| 48 | 50 |
| 49 // If true, will ignore this widget and not send accessibility events. | 51 // If true, will ignore this widget and not send accessibility events. |
| 50 bool ignore; | 52 bool ignore; |
| 51 }; | 53 }; |
| 52 | 54 |
| 53 // Get the single instance of this class. | 55 // Get the single instance of this class. |
| 54 static AccessibilityEventRouterViews* GetInstance(); | 56 static AccessibilityEventRouterViews* GetInstance(); |
| 55 | 57 |
| 56 // Handle an accessibility event generated by a view. | 58 // Handle an accessibility event generated by a view. |
| 57 void HandleAccessibilityEvent( | 59 void HandleAccessibilityEvent( |
| 58 views::View* view, ui::AccessibilityTypes::Event event_type); | 60 views::View* view, ui::AccessibilityTypes::Event event_type); |
| 59 | 61 |
| 60 // Handle a menu item being focused (separate because a menu item is | 62 // Handle a menu item being focused (separate because a menu item is |
| 61 // not necessarily its own view). | 63 // not necessarily its own view). |
| 62 void HandleMenuItemFocused(const string16& menu_name, | 64 void HandleMenuItemFocused(const string16& menu_name, |
| 63 const string16& menu_item_name, | 65 const string16& menu_item_name, |
| 64 int item_index, | 66 int item_index, |
| 65 int item_count, | 67 int item_count, |
| 66 bool has_submenu); | 68 bool has_submenu); |
| 67 | 69 |
| 70 // NotificationObserver implementation. |
| 71 virtual void Observe(int type, |
| 72 const content::NotificationSource& source, |
| 73 const content::NotificationDetails& details) OVERRIDE; |
| 74 |
| 68 private: | 75 private: |
| 69 friend struct DefaultSingletonTraits<AccessibilityEventRouterViews>; | 76 friend struct DefaultSingletonTraits<AccessibilityEventRouterViews>; |
| 70 | 77 |
| 71 FRIEND_TEST_ALL_PREFIXES(AccessibilityEventRouterViewsTest, | 78 FRIEND_TEST_ALL_PREFIXES(AccessibilityEventRouterViewsTest, |
| 72 TestFocusNotification); | 79 TestFocusNotification); |
| 73 | 80 |
| 74 AccessibilityEventRouterViews(); | 81 AccessibilityEventRouterViews(); |
| 75 virtual ~AccessibilityEventRouterViews(); | 82 virtual ~AccessibilityEventRouterViews(); |
| 76 | 83 |
| 77 // Checks the type of the view and calls one of the more specific | 84 // Checks the type of the view and calls one of the more specific |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 int* count); | 152 int* count); |
| 146 | 153 |
| 147 // Recursively explore the subviews and return the text from the first | 154 // Recursively explore the subviews and return the text from the first |
| 148 // subview with a role of STATIC_TEXT. | 155 // subview with a role of STATIC_TEXT. |
| 149 static std::string RecursiveGetStaticText(views::View* view); | 156 static std::string RecursiveGetStaticText(views::View* view); |
| 150 | 157 |
| 151 // The profile associated with the most recent window event - used to | 158 // The profile associated with the most recent window event - used to |
| 152 // figure out where to route a few events that can't be directly traced | 159 // figure out where to route a few events that can't be directly traced |
| 153 // to a window with a profile (like menu events). | 160 // to a window with a profile (like menu events). |
| 154 Profile* most_recent_profile_; | 161 Profile* most_recent_profile_; |
| 162 |
| 163 // Notification registrar so we can clear most_recent_profile_ when a |
| 164 // profile is destroyed. |
| 165 content::NotificationRegistrar registrar_; |
| 155 }; | 166 }; |
| 156 | 167 |
| 157 #endif // CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEW
S_H_ | 168 #endif // CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEW
S_H_ |
| OLD | NEW |