Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit aaa02ad

Browse files
committed
Add FlAccessibilityChannel
1 parent 63ed5b1 commit aaa02ad

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,8 @@ FILE: ../../../flutter/shell/platform/glfw/platform_handler.h
11891189
FILE: ../../../flutter/shell/platform/glfw/public/flutter_glfw.h
11901190
FILE: ../../../flutter/shell/platform/glfw/text_input_plugin.cc
11911191
FILE: ../../../flutter/shell/platform/glfw/text_input_plugin.h
1192+
FILE: ../../../flutter/shell/platform/linux/fl_accessibility_channel.cc
1193+
FILE: ../../../flutter/shell/platform/linux/fl_accessibility_channel.h
11921194
FILE: ../../../flutter/shell/platform/linux/fl_basic_message_channel.cc
11931195
FILE: ../../../flutter/shell/platform/linux/fl_binary_codec.cc
11941196
FILE: ../../../flutter/shell/platform/linux/fl_binary_codec_test.cc

shell/platform/linux/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ source_set("flutter_linux") {
7474
public = _public_headers
7575

7676
sources = [
77+
"fl_accessibility_channel.cc",
7778
"fl_basic_message_channel.cc",
7879
"fl_binary_codec.cc",
7980
"fl_binary_messenger.cc",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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_channel.h"
6+
#include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h"
7+
#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h"
8+
9+
struct _FlAccessibilityChannel {
10+
GObject parent_instance;
11+
12+
FlBasicMessageChannel* channel;
13+
};
14+
15+
G_DEFINE_TYPE(FlAccessibilityChannel, fl_accessibility_channel, G_TYPE_OBJECT)
16+
17+
// Called when a message is received on this channel
18+
static void message_cb(FlBasicMessageChannel* channel,
19+
FlValue* message,
20+
FlBasicMessageChannelResponseHandle* response_handle,
21+
gpointer user_data) {
22+
if (fl_value_get_type(message) != FL_VALUE_TYPE_MAP) {
23+
g_warning("Ignoring unknown flutter/accessibility message type");
24+
fl_basic_message_channel_respond(channel, response_handle, nullptr,
25+
nullptr);
26+
return;
27+
}
28+
29+
FlValue* type_value = fl_value_lookup_string(message, "type");
30+
if (type_value == nullptr ||
31+
fl_value_get_type(type_value) != FL_VALUE_TYPE_STRING) {
32+
g_warning(
33+
"Ignoring unknown flutter/accessibility message with unknown type");
34+
fl_basic_message_channel_respond(channel, response_handle, nullptr,
35+
nullptr);
36+
return;
37+
}
38+
const gchar* type = fl_value_get_string(type_value);
39+
40+
if (strcmp(type, "tooltip") == 0) {
41+
g_debug("Got tooltip");
42+
// FIXME: Make a callback
43+
fl_basic_message_channel_respond(channel, response_handle, nullptr,
44+
nullptr);
45+
} else {
46+
g_debug("Got unknown accessibility message: %s", type);
47+
fl_basic_message_channel_respond(channel, response_handle, nullptr,
48+
nullptr);
49+
}
50+
}
51+
52+
static void fl_accessibility_channel_dispose(GObject* object) {
53+
FlAccessibilityChannel* self = FL_ACCESSIBILITY_CHANNEL(object);
54+
55+
g_clear_object(&self->channel);
56+
57+
G_OBJECT_CLASS(fl_accessibility_channel_parent_class)->dispose(object);
58+
}
59+
60+
static void fl_accessibility_channel_class_init(
61+
FlAccessibilityChannelClass* klass) {
62+
G_OBJECT_CLASS(klass)->dispose = fl_accessibility_channel_dispose;
63+
}
64+
65+
static void fl_accessibility_channel_init(FlAccessibilityChannel* self) {}
66+
67+
FlAccessibilityChannel* fl_accessibility_channel_new(
68+
FlBinaryMessenger* messenger) {
69+
g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
70+
71+
FlAccessibilityChannel* self = FL_ACCESSIBILITY_CHANNEL(
72+
g_object_new(fl_accessibility_channel_get_type(), nullptr));
73+
74+
g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new();
75+
self->channel = fl_basic_message_channel_new(
76+
messenger, "flutter/accessibility", FL_MESSAGE_CODEC(codec));
77+
fl_basic_message_channel_set_message_handler(self->channel, message_cb, self,
78+
nullptr);
79+
80+
return self;
81+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
#ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_ACCESSIBILITY_CHANNEL_H_
6+
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_ACCESSIBILITY_CHANNEL_H_
7+
8+
#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"
9+
10+
G_BEGIN_DECLS
11+
12+
G_DECLARE_FINAL_TYPE(FlAccessibilityChannel,
13+
fl_accessibility_channel,
14+
FL,
15+
ACCESSIBILITY_CHANNEL,
16+
GObject);
17+
18+
/**
19+
* FlAccessibilityChannel:
20+
*
21+
* #FlAccessibilityChannel is a platform channel that implements the shell side
22+
* of SystemChannels.accessibility from the Flutter services library.
23+
*/
24+
25+
/**
26+
* fl_accessibility_channel_new:
27+
* @messenger: an #FlBinaryMessenger
28+
*
29+
* Creates a new accessibility channel.
30+
*
31+
* Returns: a new #FlAccessibilityChannel
32+
*/
33+
FlAccessibilityChannel* fl_accessibility_channel_new(
34+
FlBinaryMessenger* messenger);
35+
36+
G_END_DECLS
37+
38+
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_ACCESSIBILITY_CHANNEL_H_

shell/platform/linux/fl_view.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "flutter/shell/platform/linux/public/flutter_linux/fl_view.h"
66

7+
#include "flutter/shell/platform/linux/fl_accessibility_channel.h"
78
#include "flutter/shell/platform/linux/fl_engine_private.h"
89
#include "flutter/shell/platform/linux/fl_key_event_plugin.h"
910
#include "flutter/shell/platform/linux/fl_plugin_registrar_private.h"
@@ -31,6 +32,7 @@ struct _FlView {
3132
int64_t button_state;
3233

3334
// Flutter system channel handlers.
35+
FlAccessibilityChannel* accessibility_channel;
3436
FlKeyEventPlugin* key_event_plugin;
3537
};
3638

@@ -113,6 +115,7 @@ static void fl_view_constructed(GObject* object) {
113115

114116
// Create system channel handlers
115117
FlBinaryMessenger* messenger = fl_engine_get_binary_messenger(self->engine);
118+
self->accessibility_channel = fl_accessibility_channel_new(messenger);
116119
self->key_event_plugin = fl_key_event_plugin_new(messenger);
117120
}
118121

@@ -155,6 +158,7 @@ static void fl_view_dispose(GObject* object) {
155158
g_clear_object(&self->project);
156159
g_clear_object(&self->renderer);
157160
g_clear_object(&self->engine);
161+
g_clear_object(&self->accessibility_channel);
158162
g_clear_object(&self->key_event_plugin);
159163

160164
G_OBJECT_CLASS(fl_view_parent_class)->dispose(object);

0 commit comments

Comments
 (0)