OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_BASE_H_ | 5 #ifndef UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_BASE_H_ |
6 #define UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_BASE_H_ | 6 #define UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_BASE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "ui/accessibility/ax_action_data.h" | 12 #include "ui/accessibility/ax_action_data.h" |
13 #include "ui/accessibility/ax_node_data.h" | 13 #include "ui/accessibility/ax_node_data.h" |
14 #include "ui/accessibility/platform/ax_platform_node.h" | 14 #include "ui/accessibility/platform/ax_platform_node.h" |
15 #include "ui/accessibility/platform/ax_platform_node_delegate.h" | 15 #include "ui/accessibility/platform/ax_platform_node_delegate.h" |
16 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
17 #include "ui/views/accessibility/native_view_accessibility.h" | 17 #include "ui/views/accessibility/native_view_accessibility.h" |
18 #include "ui/views/views_export.h" | 18 #include "ui/views/views_export.h" |
19 #include "ui/views/widget/widget_observer.h" | 19 #include "ui/views/widget/widget_observer.h" |
20 | 20 |
21 namespace views { | 21 namespace views { |
22 | 22 |
| 23 namespace test { |
| 24 class NativeViewAccessibilityBaseIgnoredElementsTest; |
| 25 } |
| 26 |
23 class View; | 27 class View; |
24 class Widget; | 28 class Widget; |
25 | 29 |
26 // Shared base class for platforms that require an implementation of | 30 // Shared base class for platforms that require an implementation of |
27 // NativeViewAccessibility to interface with the native accessibility toolkit. | 31 // NativeViewAccessibility to interface with the native accessibility toolkit. |
28 class VIEWS_EXPORT NativeViewAccessibilityBase | 32 class VIEWS_EXPORT NativeViewAccessibilityBase |
29 : public NativeViewAccessibility, | 33 : public NativeViewAccessibility, |
30 public ui::AXPlatformNodeDelegate, | 34 public ui::AXPlatformNodeDelegate, |
31 public WidgetObserver { | 35 public WidgetObserver { |
32 public: | 36 public: |
| 37 // Convenience method for checking if a View should be ignored by a11y. |
| 38 static bool IsIgnoredView(View* view); |
| 39 |
33 ~NativeViewAccessibilityBase() override; | 40 ~NativeViewAccessibilityBase() override; |
34 | 41 |
35 // NativeViewAccessibility: | 42 // NativeViewAccessibility: |
36 gfx::NativeViewAccessible GetNativeObject() override; | 43 gfx::NativeViewAccessible GetNativeObject() override; |
37 void NotifyAccessibilityEvent(ui::AXEvent event_type) override; | 44 void NotifyAccessibilityEvent(ui::AXEvent event_type) override; |
38 | 45 |
39 // Focuses or unfocuses a View. | 46 // Focuses or unfocuses a View. |
40 bool SetFocused(bool focused); | 47 bool SetFocused(bool focused); |
41 | 48 |
42 // ui::AXPlatformNodeDelegate | 49 // ui::AXPlatformNodeDelegate |
43 const ui::AXNodeData& GetData() const override; | 50 const ui::AXNodeData& GetData() const override; |
44 int GetChildCount() override; | 51 int GetChildCount() override; |
45 gfx::NativeViewAccessible ChildAtIndex(int index) override; | 52 gfx::NativeViewAccessible ChildAtIndex(int index) override; |
46 gfx::NativeWindow GetTopLevelWidget() override; | 53 gfx::NativeWindow GetTopLevelWidget() override; |
47 gfx::NativeViewAccessible GetParent() override; | 54 gfx::NativeViewAccessible GetParent() override; |
48 gfx::Vector2d GetGlobalCoordinateOffset() override; | 55 gfx::Vector2d GetGlobalCoordinateOffset() override; |
49 gfx::NativeViewAccessible HitTestSync(int x, int y) override; | 56 gfx::NativeViewAccessible HitTestSync(int x, int y) override; |
50 gfx::NativeViewAccessible GetFocus() override; | 57 gfx::NativeViewAccessible GetFocus() override; |
51 gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; | 58 gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; |
52 bool AccessibilityPerformAction(const ui::AXActionData& data) override; | 59 bool AccessibilityPerformAction(const ui::AXActionData& data) override; |
53 void DoDefaultAction() override; | 60 void DoDefaultAction() override; |
54 | 61 |
55 // WidgetObserver | 62 // WidgetObserver |
56 void OnWidgetDestroying(Widget* widget) override; | 63 void OnWidgetDestroying(Widget* widget) override; |
57 | 64 |
58 Widget* parent_widget() const { return parent_widget_; } | 65 Widget* parent_widget() const { return parent_widget_; } |
59 void SetParentWidget(Widget* parent_widget); | 66 void SetParentWidget(Widget* parent_widget); |
60 | 67 |
61 protected: | 68 protected: |
| 69 friend class test::NativeViewAccessibilityBaseIgnoredElementsTest; |
| 70 |
| 71 // Retrieves the NativeViewAccessibility instance for the given View. This |
| 72 // invokes View::GetNativeViewAccessible() to ensure it exists. |
| 73 static NativeViewAccessibilityBase* GetForView(View* view); |
| 74 |
62 explicit NativeViewAccessibilityBase(View* view); | 75 explicit NativeViewAccessibilityBase(View* view); |
63 | 76 |
| 77 // Retrieves the gfx::NativeViewAccessibility for |view_|'s Widget/Rootview. |
| 78 virtual gfx::NativeViewAccessible GetNativeViewAccessibleForWidget(); |
| 79 |
64 // Weak. Owns this. | 80 // Weak. Owns this. |
65 View* view_; | 81 View* view_; |
66 | 82 |
67 // Weak. Uses WidgetObserver to clear. This is set on the root view for | 83 // Weak. Uses WidgetObserver to clear. This is set on the root view for |
68 // a widget that's owned by another widget, so we can walk back up the | 84 // a widget that's owned by another widget, so we can walk back up the |
69 // tree. | 85 // tree. |
70 Widget* parent_widget_; | 86 Widget* parent_widget_; |
71 | 87 |
72 protected: | 88 protected: |
73 virtual gfx::RectF GetBoundsInScreen() const; | 89 virtual gfx::RectF GetBoundsInScreen() const; |
74 | 90 |
75 private: | 91 private: |
76 void PopulateChildWidgetVector(std::vector<Widget*>* result_child_widgets); | 92 void PopulateChildWidgetVector(std::vector<Widget*>* result_child_widgets); |
77 | 93 |
78 // We own this, but it is reference-counted on some platforms so we can't use | 94 // We own this, but it is reference-counted on some platforms so we can't use |
79 // a scoped_ptr. It is dereferenced in the destructor. | 95 // a scoped_ptr. It is dereferenced in the destructor. |
80 ui::AXPlatformNode* ax_node_; | 96 ui::AXPlatformNode* ax_node_; |
81 | 97 |
| 98 // Accessibility information associated to |view_|. |
82 mutable ui::AXNodeData data_; | 99 mutable ui::AXNodeData data_; |
83 | 100 |
84 DISALLOW_COPY_AND_ASSIGN(NativeViewAccessibilityBase); | 101 DISALLOW_COPY_AND_ASSIGN(NativeViewAccessibilityBase); |
85 }; | 102 }; |
86 | 103 |
87 } // namespace views | 104 } // namespace views |
88 | 105 |
89 #endif // UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_BASE_H_ | 106 #endif // UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_BASE_H_ |
OLD | NEW |