Flutter Linux Embedder
fl_accessible_node.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 
7 
8 // Maps Flutter semantics actions to ATK actions.
9 typedef struct {
10  FlutterSemanticsAction action;
11  const gchar* name;
12 } ActionData;
14  {kFlutterSemanticsActionTap, "Tap"},
15  {kFlutterSemanticsActionLongPress, "LongPress"},
16  {kFlutterSemanticsActionScrollLeft, "ScrollLeft"},
17  {kFlutterSemanticsActionScrollRight, "ScrollRight"},
18  {kFlutterSemanticsActionScrollUp, "ScrollUp"},
19  {kFlutterSemanticsActionScrollDown, "ScrollDown"},
20  {kFlutterSemanticsActionIncrease, "Increase"},
21  {kFlutterSemanticsActionDecrease, "Decrease"},
22  {kFlutterSemanticsActionShowOnScreen, "ShowOnScreen"},
23  {kFlutterSemanticsActionMoveCursorForwardByCharacter,
24  "MoveCursorForwardByCharacter"},
25  {kFlutterSemanticsActionMoveCursorBackwardByCharacter,
26  "MoveCursorBackwardByCharacter"},
27  {kFlutterSemanticsActionCopy, "Copy"},
28  {kFlutterSemanticsActionCut, "Cut"},
29  {kFlutterSemanticsActionPaste, "Paste"},
30  {kFlutterSemanticsActionDidGainAccessibilityFocus,
31  "DidGainAccessibilityFocus"},
32  {kFlutterSemanticsActionDidLoseAccessibilityFocus,
33  "DidLoseAccessibilityFocus"},
34  {kFlutterSemanticsActionCustomAction, "CustomAction"},
35  {kFlutterSemanticsActionDismiss, "Dismiss"},
36  {kFlutterSemanticsActionMoveCursorForwardByWord, "MoveCursorForwardByWord"},
37  {kFlutterSemanticsActionMoveCursorBackwardByWord,
38  "MoveCursorBackwardByWord"},
39  {kFlutterSemanticsActionFocus, "Focus"},
40  {kFlutterSemanticsActionExpand, "Expand"},
41  {kFlutterSemanticsActionCollapse, "Collapse"},
42  {static_cast<FlutterSemanticsAction>(0), nullptr}};
43 
45  AtkObject parent_instance;
46 
47  // Weak reference to the engine this node is created for.
48  GWeakRef engine;
49 
50  /// The unique identifier of the view to which this node belongs.
51  FlutterViewId view_id;
52 
53  // Weak reference to the parent node of this one or %NULL.
54  GWeakRef parent;
55 
56  int32_t node_id;
57  gchar* name;
58  gint index;
59  gint x, y, width, height;
60  GPtrArray* actions;
62  GPtrArray* children;
63  FlutterSemanticsFlags flags;
64 };
65 
67 
68 #define FL_ACCESSIBLE_NODE_GET_PRIVATE(node) \
69  ((FlAccessibleNodePrivate*)fl_accessible_node_get_instance_private( \
70  FL_ACCESSIBLE_NODE(node)))
71 
73  AtkComponentIface* iface);
74 static void fl_accessible_node_action_interface_init(AtkActionIface* iface);
75 static void fl_accessible_node_text_interface_init(AtkTextIface* iface);
76 
78  FlAccessibleNode,
79  fl_accessible_node,
80  ATK_TYPE_OBJECT,
81  G_ADD_PRIVATE(FlAccessibleNode)
82  G_IMPLEMENT_INTERFACE(ATK_TYPE_COMPONENT,
84  G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION,
86  G_IMPLEMENT_INTERFACE(ATK_TYPE_TEXT,
88 
89 // Returns TRUE if [flags] indicate this element is checkable.
90 static gboolean is_checkable(FlutterSemanticsFlags flags) {
91  return flags.is_checked != kFlutterCheckStateNone ||
92  flags.is_toggled != kFlutterTristateNone;
93 }
94 
95 // Returns TRUE if [flags] indicate this element is checked.
96 static gboolean is_checked(FlutterSemanticsFlags flags) {
97  return flags.is_checked == kFlutterCheckStateTrue ||
98  flags.is_toggled == kFlutterTristateTrue;
99 }
100 
101 // Returns TRUE if [flags] indicate this element is focusable.
102 static gboolean is_focusable(FlutterSemanticsFlags flags) {
103  return flags.is_focused != kFlutterTristateNone;
104 }
105 
106 // Returns TRUE if [flags] indicate this element is focused.
107 static gboolean is_focused(FlutterSemanticsFlags flags) {
108  return flags.is_focused == kFlutterTristateTrue;
109 }
110 
111 // Returns TRUE if [flags] indicate this element is selected.
112 static gboolean is_selected(FlutterSemanticsFlags flags) {
113  return flags.is_selected == kFlutterTristateTrue;
114 }
115 
116 // Returns TRUE if [flags] indicate this element is sensitive.
117 static gboolean is_sensitive(FlutterSemanticsFlags flags) {
118  return flags.is_enabled != kFlutterTristateNone;
119 }
120 
121 // Returns TRUE if [flags] indicate this element is enabled.
122 static gboolean is_enabled(FlutterSemanticsFlags flags) {
123  return flags.is_enabled == kFlutterTristateTrue;
124 }
125 
126 // Returns TRUE if [action] is set in [actions].
127 static gboolean has_action(FlutterSemanticsAction actions,
128  FlutterSemanticsAction action) {
129  return (actions & action) != 0;
130 }
131 
132 // Gets the nth action.
134  if (index < 0 || static_cast<guint>(index) >= priv->actions->len) {
135  return nullptr;
136  }
137  return static_cast<ActionData*>(g_ptr_array_index(priv->actions, index));
138 }
139 
140 // Checks if [object] is in [children].
141 static gboolean has_child(GPtrArray* children, AtkObject* object) {
142  for (guint i = 0; i < children->len; i++) {
143  if (g_ptr_array_index(children, i) == object) {
144  return TRUE;
145  }
146  }
147 
148  return FALSE;
149 }
150 
151 static void fl_accessible_node_set_property(GObject* object,
152  guint prop_id,
153  const GValue* value,
154  GParamSpec* pspec) {
156  switch (prop_id) {
157  case PROP_ENGINE:
158  g_weak_ref_set(&priv->engine, g_value_get_object(value));
159  break;
160  case PROP_VIEW_ID:
161  priv->view_id = g_value_get_int64(value);
162  break;
163  case PROP_ID:
164  priv->node_id = g_value_get_int(value);
165  break;
166  default:
167  G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
168  break;
169  }
170 }
171 
172 static void fl_accessible_node_dispose(GObject* object) {
174 
175  g_weak_ref_clear(&priv->engine);
176  g_weak_ref_clear(&priv->parent);
177  g_clear_pointer(&priv->name, g_free);
178  g_clear_pointer(&priv->actions, g_ptr_array_unref);
179  g_clear_pointer(&priv->children, g_ptr_array_unref);
180 
181  G_OBJECT_CLASS(fl_accessible_node_parent_class)->dispose(object);
182 }
183 
184 // Implements AtkObject::get_name.
185 static const gchar* fl_accessible_node_get_name(AtkObject* accessible) {
187  return priv->name;
188 }
189 
190 // Implements AtkObject::get_parent.
191 static AtkObject* fl_accessible_node_get_parent(AtkObject* accessible) {
193  g_autoptr(AtkObject) parent = ATK_OBJECT(g_weak_ref_get(&priv->parent));
194  return parent;
195 }
196 
197 // Implements AtkObject::get_index_in_parent.
200  return priv->index;
201 }
202 
203 // Implements AtkObject::get_n_children.
206  return priv->children->len;
207 }
208 
209 // Implements AtkObject::ref_child.
210 static AtkObject* fl_accessible_node_ref_child(AtkObject* accessible, gint i) {
212 
213  if (i < 0 || static_cast<guint>(i) >= priv->children->len) {
214  return nullptr;
215  }
216 
217  return ATK_OBJECT(g_object_ref(g_ptr_array_index(priv->children, i)));
218 }
219 
220 // Implements AtkObject::get_role.
221 static AtkRole fl_accessible_node_get_role(AtkObject* accessible) {
223  if (priv->flags.is_button) {
224  return ATK_ROLE_PUSH_BUTTON;
225  }
226  if (priv->flags.is_in_mutually_exclusive_group &&
227  priv->flags.is_checked != kFlutterCheckStateNone) {
228  return ATK_ROLE_RADIO_BUTTON;
229  }
230  if (priv->flags.is_checked != kFlutterCheckStateNone) {
231  return ATK_ROLE_CHECK_BOX;
232  }
233  if (priv->flags.is_toggled != kFlutterTristateNone) {
234  return ATK_ROLE_TOGGLE_BUTTON;
235  }
236  if (priv->flags.is_slider) {
237  return ATK_ROLE_SLIDER;
238  }
239  if (priv->flags.is_text_field && priv->flags.is_obscured) {
240  return ATK_ROLE_PASSWORD_TEXT;
241  }
242  if (priv->flags.is_text_field) {
243  return ATK_ROLE_TEXT;
244  }
245  if (priv->flags.is_header) {
246  return ATK_ROLE_HEADING;
247  }
248  if (priv->flags.is_link) {
249  return ATK_ROLE_LINK;
250  }
251  if (priv->flags.is_image) {
252  return ATK_ROLE_IMAGE;
253  }
254 
255  return ATK_ROLE_PANEL;
256 }
257 
258 // Implements AtkObject::ref_state_set.
259 static AtkStateSet* fl_accessible_node_ref_state_set(AtkObject* accessible) {
261 
262  AtkStateSet* state_set = atk_state_set_new();
263 
264  if (!priv->flags.is_obscured) {
265  atk_state_set_add_state(state_set, ATK_STATE_SHOWING);
266  }
267  if (!priv->flags.is_hidden) {
268  atk_state_set_add_state(state_set, ATK_STATE_VISIBLE);
269  }
270  if (is_checkable(priv->flags)) {
271  atk_state_set_add_state(state_set, ATK_STATE_CHECKABLE);
272  }
273  if (is_checked(priv->flags)) {
274  atk_state_set_add_state(state_set, ATK_STATE_CHECKED);
275  }
276  if (is_focusable(priv->flags)) {
277  atk_state_set_add_state(state_set, ATK_STATE_FOCUSABLE);
278  }
279  if (is_focused(priv->flags)) {
280  atk_state_set_add_state(state_set, ATK_STATE_FOCUSED);
281  }
282  if (is_selected(priv->flags)) {
283  atk_state_set_add_state(state_set, ATK_STATE_SELECTED);
284  }
285  if (is_enabled(priv->flags)) {
286  atk_state_set_add_state(state_set, ATK_STATE_ENABLED);
287  }
288  if (is_sensitive(priv->flags)) {
289  atk_state_set_add_state(state_set, ATK_STATE_SENSITIVE);
290  }
291  if (priv->flags.is_read_only) {
292  atk_state_set_add_state(state_set, ATK_STATE_READ_ONLY);
293  }
294  if (priv->flags.is_text_field) {
295  atk_state_set_add_state(state_set, ATK_STATE_EDITABLE);
296  }
297 
298  return state_set;
299 }
300 
301 // Implements AtkComponent::get_extents.
302 static void fl_accessible_node_get_extents(AtkComponent* component,
303  gint* x,
304  gint* y,
305  gint* width,
306  gint* height,
307  AtkCoordType coord_type) {
309 
310  *x = 0;
311  *y = 0;
312  g_autoptr(AtkObject) parent = ATK_OBJECT(g_weak_ref_get(&priv->parent));
313  if (parent != nullptr) {
314  atk_component_get_extents(ATK_COMPONENT(parent), x, y, nullptr, nullptr,
315  coord_type);
316  }
317 
318  *x += priv->x;
319  *y += priv->y;
320  *width = priv->width;
321  *height = priv->height;
322 }
323 
324 // Implements AtkComponent::get_layer.
325 static AtkLayer fl_accessible_node_get_layer(AtkComponent* component) {
326  return ATK_LAYER_WIDGET;
327 }
328 
329 // Implements AtkAction::do_action.
330 static gboolean fl_accessible_node_do_action(AtkAction* action, gint i) {
332 
333  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&priv->engine));
334  if (engine == nullptr) {
335  return FALSE;
336  }
337 
338  ActionData* data = get_action(priv, i);
339  if (data == nullptr) {
340  return FALSE;
341  }
342 
343  fl_accessible_node_perform_action(FL_ACCESSIBLE_NODE(action), data->action,
344  nullptr);
345  return TRUE;
346 }
347 
348 // Implements AtkAction::get_n_actions.
349 static gint fl_accessible_node_get_n_actions(AtkAction* action) {
351  return priv->actions->len;
352 }
353 
354 // Implements AtkAction::get_name.
355 static const gchar* fl_accessible_node_get_name(AtkAction* action, gint i) {
357 
358  ActionData* data = get_action(priv, i);
359  if (data == nullptr) {
360  return nullptr;
361  }
362 
363  return data->name;
364 }
365 
366 // Implements FlAccessibleNode::set_name.
367 static void fl_accessible_node_set_name_impl(FlAccessibleNode* self,
368  const gchar* name) {
370  g_free(priv->name);
371  priv->name = g_strdup(name);
372 }
373 
374 // Implements FlAccessibleNode::set_extents.
375 static void fl_accessible_node_set_extents_impl(FlAccessibleNode* self,
376  gint x,
377  gint y,
378  gint width,
379  gint height) {
381  priv->x = x;
382  priv->y = y;
383  priv->width = width;
384  priv->height = height;
385 }
386 
387 // Check two boolean flags are different, in a way that handles true values
388 // being different (e.g. 1 and 2).
389 static bool flag_changed(bool old_flag, bool new_flag) {
390  return !old_flag != !new_flag;
391 }
392 
393 // Implements FlAccessibleNode::set_flags.
394 static void fl_accessible_node_set_flags_impl(FlAccessibleNode* self,
395  FlutterSemanticsFlags* flags) {
397 
398  FlutterSemanticsFlags old_flags = priv->flags;
399  priv->flags = *flags;
400 
401  if (flag_changed(old_flags.is_obscured, flags->is_obscured)) {
402  atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_SHOWING,
403  !flags->is_obscured);
404  }
405  if (flag_changed(old_flags.is_hidden, flags->is_hidden)) {
406  atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_VISIBLE,
407  !flags->is_hidden);
408  }
409  if (flag_changed(is_checkable(old_flags), is_checkable(priv->flags))) {
410  atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_CHECKABLE,
411  is_checkable(priv->flags));
412  }
413  if (flag_changed(is_checked(old_flags), is_checked(priv->flags))) {
414  atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_CHECKED,
415  is_checked(priv->flags));
416  }
417  if (flag_changed(is_focusable(old_flags), is_focusable(priv->flags))) {
418  atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_FOCUSABLE,
419  is_focusable(priv->flags));
420  }
421  if (flag_changed(is_focused(old_flags), is_focused(priv->flags))) {
422  atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_FOCUSED,
423  is_focused(priv->flags));
424  }
425  if (flag_changed(is_selected(old_flags), is_selected(priv->flags))) {
426  atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_SELECTED,
427  is_selected(priv->flags));
428  }
429  if (flag_changed(is_sensitive(old_flags), is_sensitive(priv->flags))) {
430  atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_SENSITIVE,
431  is_sensitive(priv->flags));
432  }
433  if (flag_changed(is_enabled(old_flags), is_enabled(priv->flags))) {
434  atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_ENABLED,
435  is_enabled(priv->flags));
436  }
437  if (flag_changed(old_flags.is_read_only, flags->is_read_only)) {
438  atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_READ_ONLY,
439  flags->is_read_only);
440  }
441  if (flag_changed(old_flags.is_text_field, flags->is_text_field)) {
442  atk_object_notify_state_change(ATK_OBJECT(self), ATK_STATE_EDITABLE,
443  flags->is_text_field);
444  }
445 }
446 
447 // Implements FlAccessibleNode::set_actions.
449  FlAccessibleNode* self,
450  FlutterSemanticsAction actions) {
452 
453  // NOTE(robert-ancell): It appears that AtkAction doesn't have a method of
454  // notifying that actions have changed, and even if it did an ATK client
455  // might access the old IDs before checking for new ones. Keep an eye
456  // out for a case where Flutter changes the actions on an item and see
457  // if we can resolve this in another way.
458  g_ptr_array_remove_range(priv->actions, 0, priv->actions->len);
459  for (int i = 0; action_mapping[i].name != nullptr; i++) {
460  if (has_action(actions, action_mapping[i].action)) {
461  g_ptr_array_add(priv->actions, &action_mapping[i]);
462  }
463  }
464 }
465 
466 // Implements FlAccessibleNode::set_value.
467 static void fl_accessible_node_set_value_impl(FlAccessibleNode* self,
468  const gchar* value) {}
469 
470 // Implements FlAccessibleNode::set_text_selection.
471 static void fl_accessible_node_set_text_selection_impl(FlAccessibleNode* self,
472  gint base,
473  gint extent) {}
474 
475 // Implements FlAccessibleNode::set_text_direction.
477  FlAccessibleNode* self,
478  FlutterTextDirection direction) {}
479 
480 // Implements FlAccessibleNode::perform_action.
482  FlAccessibleNode* self,
483  FlutterSemanticsAction action,
484  GBytes* data) {
486  g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&priv->engine));
487  if (engine == nullptr) {
488  return;
489  }
490  fl_engine_dispatch_semantics_action(engine, priv->view_id, priv->node_id,
491  action, data);
492 }
493 
494 static void fl_accessible_node_class_init(FlAccessibleNodeClass* klass) {
495  G_OBJECT_CLASS(klass)->set_property = fl_accessible_node_set_property;
496  G_OBJECT_CLASS(klass)->dispose = fl_accessible_node_dispose;
497  ATK_OBJECT_CLASS(klass)->get_name = fl_accessible_node_get_name;
498  ATK_OBJECT_CLASS(klass)->get_parent = fl_accessible_node_get_parent;
499  ATK_OBJECT_CLASS(klass)->get_index_in_parent =
501  ATK_OBJECT_CLASS(klass)->get_n_children = fl_accessible_node_get_n_children;
502  ATK_OBJECT_CLASS(klass)->ref_child = fl_accessible_node_ref_child;
503  ATK_OBJECT_CLASS(klass)->get_role = fl_accessible_node_get_role;
504  ATK_OBJECT_CLASS(klass)->ref_state_set = fl_accessible_node_ref_state_set;
505  FL_ACCESSIBLE_NODE_CLASS(klass)->set_name = fl_accessible_node_set_name_impl;
506  FL_ACCESSIBLE_NODE_CLASS(klass)->set_extents =
508  FL_ACCESSIBLE_NODE_CLASS(klass)->set_flags =
510  FL_ACCESSIBLE_NODE_CLASS(klass)->set_actions =
512  FL_ACCESSIBLE_NODE_CLASS(klass)->set_value =
514  FL_ACCESSIBLE_NODE_CLASS(klass)->set_text_selection =
516  FL_ACCESSIBLE_NODE_CLASS(klass)->set_text_direction =
518  FL_ACCESSIBLE_NODE_CLASS(klass)->perform_action =
520 
521  g_object_class_install_property(
522  G_OBJECT_CLASS(klass), PROP_ENGINE,
523  g_param_spec_object(
524  "engine", "engine", "Flutter engine", fl_engine_get_type(),
525  static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
526  G_PARAM_STATIC_STRINGS)));
527  g_object_class_install_property(
528  G_OBJECT_CLASS(klass), PROP_VIEW_ID,
529  g_param_spec_int64(
530  "view-id", "view-id", "View ID that this node belongs to", 0,
531  G_MAXINT64, 0,
532  static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)));
533  g_object_class_install_property(
534  G_OBJECT_CLASS(klass), PROP_ID,
535  g_param_spec_int(
536  "node-id", "node-id", "Accessibility node ID", 0, G_MAXINT, 0,
537  static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
538  G_PARAM_STATIC_STRINGS)));
539 }
540 
542  AtkComponentIface* iface) {
543  iface->get_extents = fl_accessible_node_get_extents;
544  iface->get_layer = fl_accessible_node_get_layer;
545 }
546 
547 static void fl_accessible_node_action_interface_init(AtkActionIface* iface) {
548  iface->do_action = fl_accessible_node_do_action;
549  iface->get_n_actions = fl_accessible_node_get_n_actions;
550  iface->get_name = fl_accessible_node_get_name;
551 }
552 
553 // Returns the number of UTF-8 characters in this node's text content. A
554 // Flutter semantics node's text content is its accessibility name.
556  return priv->name != nullptr
557  ? static_cast<gint>(g_utf8_strlen(priv->name, -1))
558  : 0;
559 }
560 
561 // Implements AtkText::get_character_count.
562 static gint fl_accessible_node_get_character_count(AtkText* text) {
565 }
566 
567 // Implements AtkText::get_text.
568 static gchar* fl_accessible_node_get_text(AtkText* text,
569  gint start_offset,
570  gint end_offset) {
572  if (priv->name == nullptr) {
573  return g_strdup("");
574  }
575 
577  start_offset = CLAMP(start_offset, 0, count);
578  if (end_offset < 0) {
579  end_offset = count;
580  }
581  end_offset = CLAMP(end_offset, start_offset, count);
582 
583  return g_utf8_substring(priv->name, start_offset, end_offset);
584 }
585 
586 // Implements AtkText::get_character_at_offset.
587 static gunichar fl_accessible_node_get_character_at_offset(AtkText* text,
588  gint offset) {
590  if (priv->name == nullptr || offset < 0 ||
592  return 0;
593  }
594 
595  return g_utf8_get_char(g_utf8_offset_to_pointer(priv->name, offset));
596 }
597 
598 // Implements AtkText::get_caret_offset.
599 // Static text such as a heading has no caret.
600 static gint fl_accessible_node_get_caret_offset(AtkText* text) {
601  (void)text;
602  return -1;
603 }
604 
605 // Implements AtkText::get_n_selections.
606 // Static text such as a heading cannot be selected, so report no selections.
607 static gint fl_accessible_node_get_n_selections(AtkText* text) {
608  (void)text;
609  return 0;
610 }
611 
612 // Implements AtkText::get_selection.
613 static gchar* fl_accessible_node_get_selection(AtkText* text,
614  gint selection_num,
615  gint* start_offset,
616  gint* end_offset) {
617  (void)text;
618  (void)selection_num;
619  if (start_offset != nullptr) {
620  *start_offset = 0;
621  }
622  if (end_offset != nullptr) {
623  *end_offset = 0;
624  }
625  return nullptr;
626 }
627 
628 // Implements AtkText::get_string_at_offset.
630  AtkText* text,
631  gint offset,
632  AtkTextGranularity granularity,
633  gint* start_offset,
634  gint* end_offset) {
637  if (offset < 0 || offset >= count) {
638  if (start_offset != nullptr) {
639  *start_offset = 0;
640  }
641  if (end_offset != nullptr) {
642  *end_offset = 0;
643  }
644  return nullptr;
645  }
646 
647  switch (granularity) {
648  case ATK_TEXT_GRANULARITY_CHAR:
649  if (start_offset != nullptr) {
650  *start_offset = offset;
651  }
652  if (end_offset != nullptr) {
653  *end_offset = offset + 1;
654  }
655  return g_utf8_substring(priv->name, offset, offset + 1);
656  case ATK_TEXT_GRANULARITY_WORD:
657  case ATK_TEXT_GRANULARITY_SENTENCE:
658  case ATK_TEXT_GRANULARITY_LINE:
659  case ATK_TEXT_GRANULARITY_PARAGRAPH:
660  if (start_offset != nullptr) {
661  *start_offset = 0;
662  }
663  if (end_offset != nullptr) {
664  *end_offset = count;
665  }
666  return g_strdup(priv->name != nullptr ? priv->name : "");
667  default:
668  return nullptr;
669  }
670 }
671 
672 // Implements AtkText::get_text_at_offset (deprecated, but still used by some
673 // ATK clients to read the text content of non-editable objects such as
674 // headings).
676  AtkText* text,
677  gint offset,
678  AtkTextBoundary boundary_type,
679  gint* start_offset,
680  gint* end_offset) {
681  switch (boundary_type) {
682  case ATK_TEXT_BOUNDARY_CHAR:
684  text, offset, ATK_TEXT_GRANULARITY_CHAR, start_offset, end_offset);
685  case ATK_TEXT_BOUNDARY_WORD_START:
686  case ATK_TEXT_BOUNDARY_WORD_END:
688  text, offset, ATK_TEXT_GRANULARITY_WORD, start_offset, end_offset);
689  case ATK_TEXT_BOUNDARY_SENTENCE_START:
690  case ATK_TEXT_BOUNDARY_SENTENCE_END:
692  text, offset, ATK_TEXT_GRANULARITY_SENTENCE, start_offset,
693  end_offset);
694  case ATK_TEXT_BOUNDARY_LINE_START:
695  case ATK_TEXT_BOUNDARY_LINE_END:
697  text, offset, ATK_TEXT_GRANULARITY_LINE, start_offset, end_offset);
698  default:
699  return nullptr;
700  }
701 }
702 
703 static void fl_accessible_node_text_interface_init(AtkTextIface* iface) {
704  iface->get_character_count = fl_accessible_node_get_character_count;
705  iface->get_text = fl_accessible_node_get_text;
706  iface->get_character_at_offset = fl_accessible_node_get_character_at_offset;
707  iface->get_caret_offset = fl_accessible_node_get_caret_offset;
708  iface->get_n_selections = fl_accessible_node_get_n_selections;
709  iface->get_selection = fl_accessible_node_get_selection;
710  iface->get_text_at_offset = fl_accessible_node_get_text_at_offset;
711  iface->get_string_at_offset = fl_accessible_node_get_string_at_offset;
712 }
713 
714 static void fl_accessible_node_init(FlAccessibleNode* self) {
716  g_weak_ref_init(&priv->engine, nullptr);
717  g_weak_ref_init(&priv->parent, nullptr);
718  priv->actions = g_ptr_array_new();
719  priv->children = g_ptr_array_new_with_free_func(g_object_unref);
720 }
721 
722 FlAccessibleNode* fl_accessible_node_new(FlEngine* engine,
723  FlutterViewId view_id,
724  int32_t node_id) {
725  FlAccessibleNode* self = FL_ACCESSIBLE_NODE(
726  g_object_new(fl_accessible_node_get_type(), "engine", engine, "view-id",
727  view_id, "node-id", node_id, nullptr));
728  return self;
729 }
730 
731 void fl_accessible_node_set_parent(FlAccessibleNode* self,
732  AtkObject* parent,
733  gint index) {
734  g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
736  g_weak_ref_set(&priv->parent, parent);
737  priv->index = index;
738 }
739 
740 void fl_accessible_node_set_children(FlAccessibleNode* self,
741  GPtrArray* children) {
742  g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
744 
745  // Remove nodes that are no longer required.
746  for (guint i = 0; i < priv->children->len;) {
747  AtkObject* object = ATK_OBJECT(g_ptr_array_index(priv->children, i));
748  if (has_child(children, object)) {
749  i++;
750  } else {
751  g_signal_emit_by_name(self, "children-changed::remove", i, object,
752  nullptr);
753  g_ptr_array_remove_index(priv->children, i);
754  }
755  }
756 
757  // Add new nodes.
758  for (guint i = 0; i < children->len; i++) {
759  AtkObject* object = ATK_OBJECT(g_ptr_array_index(children, i));
760  if (!has_child(priv->children, object)) {
761  g_ptr_array_add(priv->children, g_object_ref(object));
762  g_signal_emit_by_name(self, "children-changed::add", i, object, nullptr);
763  }
764  }
765 }
766 
767 void fl_accessible_node_set_name(FlAccessibleNode* self, const gchar* name) {
768  g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
769 
770  return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_name(self, name);
771 }
772 
773 void fl_accessible_node_set_extents(FlAccessibleNode* self,
774  gint x,
775  gint y,
776  gint width,
777  gint height) {
778  g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
779 
780  return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_extents(self, x, y, width,
781  height);
782 }
783 
784 void fl_accessible_node_set_flags(FlAccessibleNode* self,
785  FlutterSemanticsFlags* flags) {
786  g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
787 
788  return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_flags(self, flags);
789 }
790 
791 void fl_accessible_node_set_actions(FlAccessibleNode* self,
792  FlutterSemanticsAction actions) {
793  g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
794 
795  return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_actions(self, actions);
796 }
797 
798 void fl_accessible_node_set_value(FlAccessibleNode* self, const gchar* value) {
799  g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
800 
801  return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_value(self, value);
802 }
803 
804 void fl_accessible_node_set_text_selection(FlAccessibleNode* self,
805  gint base,
806  gint extent) {
807  g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
808 
809  return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_text_selection(self, base,
810  extent);
811 }
812 
813 void fl_accessible_node_set_text_direction(FlAccessibleNode* self,
814  FlutterTextDirection direction) {
815  g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
816 
817  return FL_ACCESSIBLE_NODE_GET_CLASS(self)->set_text_direction(self,
818  direction);
819 }
820 
821 void fl_accessible_node_perform_action(FlAccessibleNode* self,
822  FlutterSemanticsAction action,
823  GBytes* data) {
824  g_return_if_fail(FL_IS_ACCESSIBLE_NODE(self));
825 
826  return FL_ACCESSIBLE_NODE_GET_CLASS(self)->perform_action(self, action, data);
827 }
FlViewAccessible * accessible
g_autoptr(FlEngine) engine
FlAccessibilityHandlerPrivate * priv
static gboolean has_child(GPtrArray *children, AtkObject *object)
static void fl_accessible_node_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
void fl_accessible_node_set_name(FlAccessibleNode *self, const gchar *name)
static gboolean fl_accessible_node_do_action(AtkAction *action, gint i)
static void fl_accessible_node_action_interface_init(AtkActionIface *iface)
static void fl_accessible_node_set_text_direction_impl(FlAccessibleNode *self, FlutterTextDirection direction)
@ PROP_ENGINE
@ PROP_VIEW_ID
@ PROP_LAST
@ PROP_0
@ PROP_ID
void fl_accessible_node_set_text_direction(FlAccessibleNode *self, FlutterTextDirection direction)
void fl_accessible_node_perform_action(FlAccessibleNode *self, FlutterSemanticsAction action, GBytes *data)
static gboolean is_sensitive(FlutterSemanticsFlags flags)
static AtkRole fl_accessible_node_get_role(AtkObject *accessible)
static bool flag_changed(bool old_flag, bool new_flag)
static gchar * fl_accessible_node_get_text_at_offset(AtkText *text, gint offset, AtkTextBoundary boundary_type, gint *start_offset, gint *end_offset)
static void fl_accessible_node_set_value_impl(FlAccessibleNode *self, const gchar *value)
void fl_accessible_node_set_text_selection(FlAccessibleNode *self, gint base, gint extent)
static gchar * fl_accessible_node_get_selection(AtkText *text, gint selection_num, gint *start_offset, gint *end_offset)
static void fl_accessible_node_class_init(FlAccessibleNodeClass *klass)
static void fl_accessible_node_set_actions_impl(FlAccessibleNode *self, FlutterSemanticsAction actions)
static void fl_accessible_node_component_interface_init(AtkComponentIface *iface)
void fl_accessible_node_set_actions(FlAccessibleNode *self, FlutterSemanticsAction actions)
static void fl_accessible_node_text_interface_init(AtkTextIface *iface)
static void fl_accessible_node_dispose(GObject *object)
void fl_accessible_node_set_children(FlAccessibleNode *self, GPtrArray *children)
static const gchar * fl_accessible_node_get_name(AtkObject *accessible)
void fl_accessible_node_set_extents(FlAccessibleNode *self, gint x, gint y, gint width, gint height)
static gchar * fl_accessible_node_get_string_at_offset(AtkText *text, gint offset, AtkTextGranularity granularity, gint *start_offset, gint *end_offset)
static AtkLayer fl_accessible_node_get_layer(AtkComponent *component)
void fl_accessible_node_set_value(FlAccessibleNode *self, const gchar *value)
static gboolean is_enabled(FlutterSemanticsFlags flags)
static void fl_accessible_node_get_extents(AtkComponent *component, gint *x, gint *y, gint *width, gint *height, AtkCoordType coord_type)
static gint fl_accessible_node_get_n_actions(AtkAction *action)
static gint fl_accessible_node_get_character_count(AtkText *text)
static gint fl_accessible_node_get_caret_offset(AtkText *text)
static gint fl_accessible_node_get_n_selections(AtkText *text)
static AtkObject * fl_accessible_node_ref_child(AtkObject *accessible, gint i)
static gboolean is_selected(FlutterSemanticsFlags flags)
static gboolean has_action(FlutterSemanticsAction actions, FlutterSemanticsAction action)
static gint fl_accessible_node_get_index_in_parent(AtkObject *accessible)
static AtkObject * fl_accessible_node_get_parent(AtkObject *accessible)
static gboolean is_focusable(FlutterSemanticsFlags flags)
static void fl_accessible_node_init(FlAccessibleNode *self)
static gunichar fl_accessible_node_get_character_at_offset(AtkText *text, gint offset)
void fl_accessible_node_set_parent(FlAccessibleNode *self, AtkObject *parent, gint index)
static AtkStateSet * fl_accessible_node_ref_state_set(AtkObject *accessible)
static void fl_accessible_node_perform_action_impl(FlAccessibleNode *self, FlutterSemanticsAction action, GBytes *data)
static ActionData action_mapping[]
static void fl_accessible_node_set_text_selection_impl(FlAccessibleNode *self, gint base, gint extent)
void fl_accessible_node_set_flags(FlAccessibleNode *self, FlutterSemanticsFlags *flags)
static gint fl_accessible_node_get_n_children(AtkObject *accessible)
static gchar * fl_accessible_node_get_text(AtkText *text, gint start_offset, gint end_offset)
static gint fl_accessible_node_get_text_length(FlAccessibleNodePrivate *priv)
static gboolean is_checked(FlutterSemanticsFlags flags)
static void fl_accessible_node_set_extents_impl(FlAccessibleNode *self, gint x, gint y, gint width, gint height)
G_DEFINE_TYPE_WITH_CODE(FlAccessibleNode, fl_accessible_node, ATK_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(ATK_TYPE_COMPONENT, fl_accessible_node_component_interface_init) G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION, fl_accessible_node_action_interface_init) G_IMPLEMENT_INTERFACE(ATK_TYPE_TEXT, fl_accessible_node_text_interface_init)) static gboolean is_checkable(FlutterSemanticsFlags flags)
static ActionData * get_action(FlAccessibleNodePrivate *priv, gint index)
#define FL_ACCESSIBLE_NODE_GET_PRIVATE(node)
FlAccessibleNode * fl_accessible_node_new(FlEngine *engine, FlutterViewId view_id, int32_t node_id)
static void fl_accessible_node_set_name_impl(FlAccessibleNode *self, const gchar *name)
static gboolean is_focused(FlutterSemanticsFlags flags)
static void fl_accessible_node_set_flags_impl(FlAccessibleNode *self, FlutterSemanticsFlags *flags)
return g_utf8_substring(value, start, end)
FlFramebuffer double double int int height
FlFramebuffer double x
FlFramebuffer double double int width
FlFramebuffer double double y
return TRUE
void fl_engine_dispatch_semantics_action(FlEngine *self, FlutterViewId view_id, uint64_t node_id, FlutterSemanticsAction action, GBytes *data)
Definition: fl_engine.cc:1491
uint8_t value
guint prop_id
guint const GValue GParamSpec * pspec
G_BEGIN_DECLS FlutterViewId view_id
const gchar * name
FlutterSemanticsAction action
FlutterSemanticsFlags flags
FlutterViewId view_id
The unique identifier of the view to which this node belongs.