Flutter macOS Embedder
flutter::FlutterPlatformNodeDelegateMac Class Reference

#include <FlutterPlatformNodeDelegateMac.h>

Inheritance diagram for flutter::FlutterPlatformNodeDelegateMac:
flutter::FlutterPlatformNodeDelegate

Public Member Functions

 FlutterPlatformNodeDelegateMac (std::weak_ptr< AccessibilityBridge > bridge, __weak FlutterViewController *view_controller)
 
virtual ~FlutterPlatformNodeDelegateMac ()
 
void Init (std::weak_ptr< OwnerBridge > bridge, ui::AXNode *node) override
 Called only once, immediately after construction. The constructor doesn't take any arguments because in the Windows subclass we use a special function to construct a COM object. Subclasses must call super. More...
 
void NodeDataChanged (const ui::AXNodeData &old_node_data, const ui::AXNodeData &new_node_data) override
 
const ui::AXNodeData & GetData () const override
 
std::string GetLiveRegionText () const
 Gets the live region text of this node in UTF-8 format. This is useful to determine the changes in between semantics updates when generating accessibility events. More...
 
gfx::NativeViewAccessible GetNativeViewAccessible () override
 
gfx::NativeViewAccessible GetNSWindow () override
 
gfx::NativeViewAccessible GetParent () override
 
gfx::Rect GetBoundsRect (const ui::AXCoordinateSystem coordinate_system, const ui::AXClippingBehavior clipping_behavior, ui::AXOffscreenResult *offscreen_result) const override
 
- Public Member Functions inherited from flutter::FlutterPlatformNodeDelegate
 FlutterPlatformNodeDelegate ()
 
virtual ~FlutterPlatformNodeDelegate () override
 
const ui::AXUniqueId & GetUniqueId () const override
 
const ui::AXNodeData & GetData () const override
 
bool AccessibilityPerformAction (const ui::AXActionData &data) override
 
gfx::NativeViewAccessible GetParent () override
 
gfx::NativeViewAccessible GetFocus () override
 
int GetChildCount () const override
 
gfx::NativeViewAccessible ChildAtIndex (int index) override
 
gfx::Rect GetBoundsRect (const ui::AXCoordinateSystem coordinate_system, const ui::AXClippingBehavior clipping_behavior, ui::AXOffscreenResult *offscreen_result) const override
 
gfx::NativeViewAccessible GetLowestPlatformAncestor () const override
 
ui::AXNodePosition::AXPositionInstance CreateTextPositionAt (int offset) const override
 
ui::AXNode * GetAXNode () const
 Gets the underlying ax node for this platform node delegate. More...
 
std::weak_ptr< OwnerBridge > GetOwnerBridge () const
 Gets the owner of this platform node delegate. This is useful when you want to get the information about surrounding nodes of this platform node delegate, e.g. the global rect of this platform node delegate. This pointer is only safe in the platform thread. More...
 
virtual ui::AXPlatformNode * GetPlatformNode () const
 
virtual ui::AXPlatformNode * GetFromNodeID (int32_t id) override
 
virtual ui::AXPlatformNode * GetFromTreeIDAndNodeID (const ui::AXTreeID &tree_id, int32_t node_id) override
 
virtual const ui::AXTree::Selection GetUnignoredSelection () const override
 

Detailed Description

The macOS implementation of FlutterPlatformNodeDelegate. This class uses AXPlatformNodeMac to manage the macOS-specific accessibility objects.

Definition at line 22 of file FlutterPlatformNodeDelegateMac.h.

Constructor & Destructor Documentation

◆ FlutterPlatformNodeDelegateMac()

flutter::FlutterPlatformNodeDelegateMac::FlutterPlatformNodeDelegateMac ( std::weak_ptr< AccessibilityBridge >  bridge,
__weak FlutterViewController *  view_controller 
)

Definition at line 23 of file FlutterPlatformNodeDelegateMac.mm.

26  : bridge_(std::move(bridge)), view_controller_(view_controller) {}

◆ ~FlutterPlatformNodeDelegateMac()

flutter::FlutterPlatformNodeDelegateMac::~FlutterPlatformNodeDelegateMac ( )
virtual

Definition at line 63 of file FlutterPlatformNodeDelegateMac.mm.

63  {
64  // Destroy() also calls delete on itself.
65  ax_platform_node_->Destroy();
66 }

Member Function Documentation

◆ GetBoundsRect()

gfx::Rect flutter::FlutterPlatformNodeDelegateMac::GetBoundsRect ( const ui::AXCoordinateSystem  coordinate_system,
const ui::AXClippingBehavior  clipping_behavior,
ui::AXOffscreenResult *  offscreen_result 
) const
override

Definition at line 82 of file FlutterPlatformNodeDelegateMac.mm.

85  {
86  gfx::Rect local_bounds = FlutterPlatformNodeDelegate::GetBoundsRect(
87  coordinate_system, clipping_behavior, offscreen_result);
88  gfx::RectF local_bounds_f(local_bounds);
89  gfx::RectF screen_bounds = ConvertBoundsFromLocalToScreen(local_bounds_f);
90  return gfx::ToEnclosingRect(ConvertBoundsFromScreenToGlobal(screen_bounds));
91 }
gfx::Rect GetBoundsRect(const ui::AXCoordinateSystem coordinate_system, const ui::AXClippingBehavior clipping_behavior, ui::AXOffscreenResult *offscreen_result) const override

References flutter::FlutterPlatformNodeDelegate::GetBoundsRect().

◆ GetData()

const ui::AXNodeData & flutter::FlutterPlatformNodeDelegateMac::GetData ( ) const
override

Definition at line 53 of file FlutterPlatformNodeDelegateMac.mm.

53  {
54  const ui::AXNodeData& data = FlutterPlatformNodeDelegate::GetData();
55  if (data.IsTextField() && data.IsReadOnlyOrDisabled()) {
56  cached_data_ = data;
57  cached_data_.role = ax::mojom::Role::kStaticText;
58  return cached_data_;
59  }
60  return data;
61 }
const ui::AXNodeData & GetData() const override

References flutter::FlutterPlatformNodeDelegate::GetData().

Referenced by GetLiveRegionText(), and Init().

◆ GetLiveRegionText()

std::string flutter::FlutterPlatformNodeDelegateMac::GetLiveRegionText ( ) const

Gets the live region text of this node in UTF-8 format. This is useful to determine the changes in between semantics updates when generating accessibility events.

Definition at line 98 of file FlutterPlatformNodeDelegateMac.mm.

98  {
99  if (GetAXNode()->IsIgnored()) {
100  return "";
101  }
102 
103  std::string text = GetData().GetStringAttribute(ax::mojom::StringAttribute::kName);
104  if (!text.empty()) {
105  return text;
106  };
107  auto bridge_ptr = bridge_.lock();
108  NSCAssert(bridge_ptr, @"Accessibility bridge in flutter engine must not be null.");
109  for (int32_t child : GetData().child_ids) {
110  auto delegate_child = bridge_ptr->GetFlutterPlatformNodeDelegateFromID(child).lock();
111  if (!delegate_child) {
112  continue;
113  }
114  text += std::static_pointer_cast<FlutterPlatformNodeDelegateMac>(delegate_child)
115  ->GetLiveRegionText();
116  }
117  return text;
118 }
ui::AXNode * GetAXNode() const
Gets the underlying ax node for this platform node delegate.
const ui::AXNodeData & GetData() const override

References flutter::FlutterPlatformNodeDelegate::GetAXNode(), and GetData().

◆ GetNativeViewAccessible()

gfx::NativeViewAccessible flutter::FlutterPlatformNodeDelegateMac::GetNativeViewAccessible ( )
override

Definition at line 68 of file FlutterPlatformNodeDelegateMac.mm.

68  {
69  NSCAssert(ax_platform_node_, @"Platform node does not exist.");
70  return ax_platform_node_->GetNativeViewAccessible();
71 }

◆ GetNSWindow()

gfx::NativeViewAccessible flutter::FlutterPlatformNodeDelegateMac::GetNSWindow ( )
override

Definition at line 93 of file FlutterPlatformNodeDelegateMac.mm.

93  {
94  FlutterAppDelegate* appDelegate = (FlutterAppDelegate*)[NSApp delegate];
95  return appDelegate.mainFlutterWindow;
96 }
IBOutlet NSWindow * mainFlutterWindow

References FlutterAppDelegate::mainFlutterWindow.

◆ GetParent()

gfx::NativeViewAccessible flutter::FlutterPlatformNodeDelegateMac::GetParent ( )
override

Definition at line 73 of file FlutterPlatformNodeDelegateMac.mm.

73  {
74  gfx::NativeViewAccessible parent = FlutterPlatformNodeDelegate::GetParent();
75  if (!parent) {
76  NSCAssert(view_controller_.viewLoaded, @"Flutter view must be loaded");
77  return view_controller_.flutterView;
78  }
79  return parent;
80 }
gfx::NativeViewAccessible GetParent() override

References flutter::FlutterPlatformNodeDelegate::GetParent().

◆ Init()

void flutter::FlutterPlatformNodeDelegateMac::Init ( std::weak_ptr< OwnerBridge >  bridge,
ui::AXNode *  node 
)
overridevirtual

Called only once, immediately after construction. The constructor doesn't take any arguments because in the Windows subclass we use a special function to construct a COM object. Subclasses must call super.

Reimplemented from flutter::FlutterPlatformNodeDelegate.

Definition at line 28 of file FlutterPlatformNodeDelegateMac.mm.

28  {
30  if (GetData().IsTextField() && !GetData().IsReadOnlyOrDisabled()) {
31  ax_platform_node_ = new FlutterTextPlatformNode(this, view_controller_);
32  } else {
33  ax_platform_node_ = ui::AXPlatformNode::Create(this);
34  }
35  NSCAssert(ax_platform_node_, @"Failed to create platform node.");
36 }
virtual void Init(std::weak_ptr< OwnerBridge > bridge, ui::AXNode *node)
Called only once, immediately after construction. The constructor doesn't take any arguments because ...

References GetData(), and flutter::FlutterPlatformNodeDelegate::Init().

Referenced by flutter::testing::TEST().

◆ NodeDataChanged()

void flutter::FlutterPlatformNodeDelegateMac::NodeDataChanged ( const ui::AXNodeData &  old_node_data,
const ui::AXNodeData &  new_node_data 
)
overridevirtual

Reimplemented from flutter::FlutterPlatformNodeDelegate.

Definition at line 38 of file FlutterPlatformNodeDelegateMac.mm.

39  {
40  bool old_is_editable_textfield =
41  old_node_data.IsTextField() && !old_node_data.IsReadOnlyOrDisabled();
42  bool new_is_editable_textfield =
43  new_node_data.IsTextField() && !new_node_data.IsReadOnlyOrDisabled();
44  if (old_is_editable_textfield && !new_is_editable_textfield) {
45  ax_platform_node_->Destroy();
46  ax_platform_node_ = ui::AXPlatformNode::Create(this);
47  } else if (!old_is_editable_textfield && new_is_editable_textfield) {
48  ax_platform_node_->Destroy();
49  ax_platform_node_ = new FlutterTextPlatformNode(this, view_controller_);
50  }
51 }

The documentation for this class was generated from the following files: