| Flutter Linux Embedder |

fl_accessibility_handler.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
5 #include "flutter/shell/platform/linux/fl_accessibility_handler.h"
6
7 #include "flutter/shell/platform/linux/fl_accessibility_channel.h"
8 #include "flutter/shell/platform/linux/fl_engine_private.h"
9 #include "flutter/shell/platform/linux/fl_view_private.h"
10
11 typedef struct {
12 GWeakRef engine;
13 FlAccessibilityChannel* channel;
14 } FlAccessibilityHandlerPrivate;
15
16 G_DEFINE_TYPE_WITH_PRIVATE(FlAccessibilityHandler,
17 fl_accessibility_handler,
18 G_TYPE_OBJECT)
19
20 static void send_announcement(int64_t view_id,
21 const char* message,
22 FlTextDirection text_direction,
23 FlAssertiveness assertiveness,
24 gpointer user_data) {
25 FlAccessibilityHandler* self = FL_ACCESSIBILITY_HANDLER(user_data);
26 FlAccessibilityHandlerPrivate* priv =
27 reinterpret_cast<FlAccessibilityHandlerPrivate*>(
28 fl_accessibility_handler_get_instance_private(self));
29
30 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&priv->engine));
31 if (engine == nullptr) {
32 return;
33 }
34
35 FlRenderable* renderable = fl_engine_get_renderable(engine, view_id);
36 if (renderable == nullptr || !FL_IS_VIEW(renderable)) {
37 return;
38 }
39
40 FlView* view = FL_VIEW(renderable);
41 FlViewAccessible* accessible = fl_view_get_accessible(view);
42 fl_view_accessible_send_announcement(
43 accessible, message, assertiveness == FL_ASSERTIVENESS_ASSERTIVE);
44 }
45
46 static void fl_accessibility_handler_dispose(GObject* object) {
47 FlAccessibilityHandler* self = FL_ACCESSIBILITY_HANDLER(object);
48 FlAccessibilityHandlerPrivate* priv =
49 reinterpret_cast<FlAccessibilityHandlerPrivate*>(
50 fl_accessibility_handler_get_instance_private(self));
51
52 g_weak_ref_clear(&priv->engine);
53 g_clear_object(&priv->channel);
54
55 G_OBJECT_CLASS(fl_accessibility_handler_parent_class)->dispose(object);
56 }
57
58 static void fl_accessibility_handler_class_init(
59 FlAccessibilityHandlerClass* klass) {
60 G_OBJECT_CLASS(klass)->dispose = fl_accessibility_handler_dispose;
61 }
62
63 static void fl_accessibility_handler_init(FlAccessibilityHandler* self) {}
64
65 static FlAccessibilityChannelVTable accessibility_channel_vtable = {
66 .send_announcement = send_announcement,
67 };
68
69 FlAccessibilityHandler* fl_accessibility_handler_new(FlEngine* engine) {
70 g_return_val_if_fail(FL_IS_ENGINE(engine), nullptr);
71
72 FlAccessibilityHandler* self = FL_ACCESSIBILITY_HANDLER(
73 g_object_new(fl_accessibility_handler_get_type(), nullptr));
74 FlAccessibilityHandlerPrivate* priv =
75 reinterpret_cast<FlAccessibilityHandlerPrivate*>(
76 fl_accessibility_handler_get_instance_private(self));
77
78 g_weak_ref_init(&priv->engine, engine);
79 priv->channel =
80 fl_accessibility_channel_new(fl_engine_get_binary_messenger(engine),
81 &accessibility_channel_vtable, self);
82
83 return self;
84 }
fl_accessibility_channel_new
FlAccessibilityChannel * fl_accessibility_channel_new(FlBinaryMessenger *messenger, FlAccessibilityChannelVTable *vtable, gpointer user_data)
Definition: fl_accessibility_channel.cc:177
fl_accessibility_channel.h
FlTextDirection
FlTextDirection
Definition: fl_accessibility_channel.h:19
FlAssertiveness
FlAssertiveness
Definition: fl_accessibility_channel.h:25
FL_ASSERTIVENESS_ASSERTIVE
@ FL_ASSERTIVENESS_ASSERTIVE
Definition: fl_accessibility_channel.h:27
accessible
FlViewAccessible * accessible
Definition: fl_accessibility_handler.cc:41
view
FlView * view
Definition: fl_accessibility_handler.cc:40
fl_accessibility_handler_dispose
static void fl_accessibility_handler_dispose(GObject *object)
Definition: fl_accessibility_handler.cc:46
fl_accessibility_handler_new
FlAccessibilityHandler * fl_accessibility_handler_new(FlEngine *engine)
Definition: fl_accessibility_handler.cc:69
message
const char * message
Definition: fl_accessibility_handler.cc:21
G_DEFINE_TYPE_WITH_PRIVATE
G_DEFINE_TYPE_WITH_PRIVATE(FlAccessibilityHandler, fl_accessibility_handler, G_TYPE_OBJECT) static void send_announcement(int64_t view_id
text_direction
const char FlTextDirection text_direction
Definition: fl_accessibility_handler.cc:22
accessibility_channel_vtable
static FlAccessibilityChannelVTable accessibility_channel_vtable
Definition: fl_accessibility_handler.cc:65
fl_view_accessible_send_announcement
fl_view_accessible_send_announcement(accessible, message, assertiveness==FL_ASSERTIVENESS_ASSERTIVE)
assertiveness
const char FlTextDirection FlAssertiveness assertiveness
Definition: fl_accessibility_handler.cc:23
fl_accessibility_handler_class_init
static void fl_accessibility_handler_class_init(FlAccessibilityHandlerClass *klass)
Definition: fl_accessibility_handler.cc:58
g_autoptr
g_autoptr(FlEngine) engine
fl_accessibility_handler_init
static void fl_accessibility_handler_init(FlAccessibilityHandler *self)
Definition: fl_accessibility_handler.cc:63
renderable
FlRenderable * renderable
Definition: fl_accessibility_handler.cc:35
user_data
const char FlTextDirection FlAssertiveness gpointer user_data
Definition: fl_accessibility_handler.cc:24
priv
FlAccessibilityHandlerPrivate * priv
Definition: fl_accessibility_handler.cc:26
fl_accessibility_handler.h
fl_engine_get_renderable
FlRenderable * fl_engine_get_renderable(FlEngine *self, FlutterViewId view_id)
Definition: fl_engine.cc:948
fl_engine_get_binary_messenger
G_MODULE_EXPORT FlBinaryMessenger * fl_engine_get_binary_messenger(FlEngine *self)
Definition: fl_engine.cc:1451
fl_engine_private.h
fl_view_get_accessible
FlViewAccessible * fl_view_get_accessible(FlView *self)
Definition: fl_view.cc:808
view_id
G_BEGIN_DECLS FlutterViewId view_id
Definition: fl_view_accessible.h:49
fl_view_private.h
FlAccessibilityChannelVTable
Definition: fl_accessibility_channel.h:37
FlAccessibilityChannelVTable::send_announcement
void(* send_announcement)(int64_t view_id, const char *message, FlTextDirection text_direction, FlAssertiveness assertiveness, gpointer user_data)
Definition: fl_accessibility_channel.h:38
FlAccessibilityHandlerPrivate
Definition: fl_accessibility_handler.cc:11
FlAccessibilityHandlerPrivate::channel
FlAccessibilityChannel * channel
Definition: fl_accessibility_handler.cc:13
FlAccessibilityHandlerPrivate::engine
GWeakRef engine
Definition: fl_accessibility_handler.cc:12