Flutter Engine
The Flutter Engine
ax_platform_node.h
Go to the documentation of this file.
1// Copyright 2014 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 UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_H_
6#define UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_H_
7
8#include <functional>
9#include <ostream>
10#include <string>
11
12#include "ax/ax_enums.h"
13#include "ax/ax_export.h"
14#include "ax/ax_mode.h"
15#include "ax/ax_mode_observer.h"
17#include "base/macros.h"
19
20namespace ui {
21
22class AXPlatformNodeDelegate;
23
24// AXPlatformNode is the abstract base class for an implementation of
25// native accessibility APIs on supported platforms (e.g. Windows, Mac OS X).
26// An object that wants to be accessible can derive from AXPlatformNodeDelegate
27// and then call AXPlatformNode::Create. The delegate implementation should
28// own the AXPlatformNode instance (or otherwise manage its lifecycle).
30 public:
31 typedef AXPlatformNode* NativeWindowHandlerCallback(gfx::NativeWindow);
32
33 // Create an appropriate platform-specific instance. The delegate owns the
34 // AXPlatformNode instance (or manages its lifecycle in some other way).
36
37 // Cast a gfx::NativeViewAccessible to an AXPlatformNode if it is one,
38 // or return nullptr if it's not an instance of this class.
39 static AXPlatformNode* FromNativeViewAccessible(
40 gfx::NativeViewAccessible accessible);
41
42 // Return the AXPlatformNode at the root of the tree for a native window.
43 static AXPlatformNode* FromNativeWindow(gfx::NativeWindow native_window);
44
45 // Provide a function that returns the AXPlatformNode at the root of the
46 // tree for a native window.
47 static void RegisterNativeWindowHandler(
48 std::function<NativeWindowHandlerCallback> handler);
49
50 // Register and unregister to receive notifications about AXMode changes
51 // for this node.
52 static void AddAXModeObserver(AXModeObserver* observer);
53 static void RemoveAXModeObserver(AXModeObserver* observer);
54
55 // Convenience method to get the current accessibility mode.
56 static AXMode GetAccessibilityMode() { return ax_mode_; }
57
58 // Helper static function to notify all global observers about
59 // the addition of an AXMode flag.
60 static void NotifyAddAXModeFlags(AXMode mode_flags);
61
62 // Return the focused object in any UI popup overlaying content, or null.
63 static gfx::NativeViewAccessible GetPopupFocusOverride();
64
65 // Set the focused object withn any UI popup overlaying content, or null.
66 // The focus override is the perceived focus within the popup, and it changes
67 // each time a user navigates to a new item within the popup.
68 static void SetPopupFocusOverride(gfx::NativeViewAccessible focus_override);
69
70 // Call Destroy rather than deleting this, because the subclass may
71 // use reference counting.
72 virtual void Destroy();
73
74 // Get the platform-specific accessible object type for this instance.
75 // On some platforms this is just a type cast, on others it may be a
76 // wrapper object or handle.
78
79 // Fire a platform-specific notification that an event has occurred on
80 // this object.
82
83#if defined(OS_APPLE)
84 // Fire a platform-specific notification to announce |text|.
85 virtual void AnnounceText(const std::u16string& text) = 0;
86#endif
87
88 // Return this object's delegate.
89 virtual AXPlatformNodeDelegate* GetDelegate() const = 0;
90
91 // Return true if this object is equal to or a descendant of |ancestor|.
92 virtual bool IsDescendantOf(AXPlatformNode* ancestor) const = 0;
93
94 // Set |this| as the primary web contents for the window.
95 void SetIsPrimaryWebContentsForWindow(bool is_primary);
96 bool IsPrimaryWebContentsForWindow() const;
97
98 // Return the unique ID.
99 int32_t GetUniqueId() const;
100
101 // Creates a string representation of this node's data.
102 std::string ToString();
103
104 // Returns a string representation of the subtree of nodes rooted at this
105 // node.
106 std::string SubtreeToString();
107
108 friend std::ostream& operator<<(std::ostream& stream, AXPlatformNode& node);
109 virtual ~AXPlatformNode();
110
111 protected:
113
114 private:
115 static std::vector<AXModeObserver*> ax_mode_observers_;
116 static std::function<NativeWindowHandlerCallback> native_window_handler_;
117
118 static AXMode ax_mode_;
119
120 // This allows UI menu popups like to act as if they are focused in the
121 // exposed platform accessibility API, even though actual focus remains in
122 // underlying content.
123 static gfx::NativeViewAccessible popup_focus_override_;
124
125 bool is_primary_web_contents_for_window_ = false;
126
128};
129
130} // namespace ui
131
132#endif // UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_H_
static sk_sp< Effect > Create()
Definition: RefCntTest.cpp:117
ax::mojom::Event event_type
#define AX_EXPORT
Definition: ax_export.h:29
virtual void NotifyAccessibilityEvent(ax::mojom::Event event_type)=0
virtual gfx::NativeViewAccessible GetNativeViewAccessible()=0
AXPlatformNode * NativeWindowHandlerCallback(gfx::NativeWindow)
static AXMode GetAccessibilityMode()
virtual AXPlatformNodeDelegate * GetDelegate() const =0
virtual bool IsDescendantOf(AXPlatformNode *ancestor) const =0
std::u16string text
UnimplementedNativeViewAccessible * NativeViewAccessible
const char * ToString(ax::mojom::Event event)
Definition: ax_enum_util.cc:9
std::ostream & operator<<(std::ostream &os, AXEventGenerator::Event event)
#define BASE_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:8