Skip to content

Commit

Permalink
Add initial accessibility support to the Linux shell
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-ancell committed Nov 20, 2020
1 parent c45e02a commit a483552
Show file tree
Hide file tree
Showing 12 changed files with 820 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,10 @@ FILE: ../../../flutter/shell/platform/glfw/text_input_plugin.h
FILE: ../../../flutter/shell/platform/linux/egl_utils.cc
FILE: ../../../flutter/shell/platform/linux/egl_utils.h
FILE: ../../../flutter/shell/platform/linux/egl_utils_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_accessibility_plugin.cc
FILE: ../../../flutter/shell/platform/linux/fl_accessibility_plugin.h
FILE: ../../../flutter/shell/platform/linux/fl_accessibile.cc
FILE: ../../../flutter/shell/platform/linux/fl_accessibile.h
FILE: ../../../flutter/shell/platform/linux/fl_basic_message_channel.cc
FILE: ../../../flutter/shell/platform/linux/fl_basic_message_channel_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_binary_codec.cc
Expand Down Expand Up @@ -1359,6 +1363,8 @@ FILE: ../../../flutter/shell/platform/linux/fl_text_input_plugin.h
FILE: ../../../flutter/shell/platform/linux/fl_value.cc
FILE: ../../../flutter/shell/platform/linux/fl_value_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_view.cc
FILE: ../../../flutter/shell/platform/linux/fl_view_accessible.cc
FILE: ../../../flutter/shell/platform/linux/fl_view_accessible.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_binary_codec.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ source_set("flutter_linux_sources") {

sources = [
"egl_utils.cc",
"fl_accessibility_plugin.cc",
"fl_accessible.cc",
"fl_basic_message_channel.cc",
"fl_binary_codec.cc",
"fl_binary_messenger.cc",
Expand Down Expand Up @@ -116,6 +118,7 @@ source_set("flutter_linux_sources") {
"fl_text_input_plugin.cc",
"fl_value.cc",
"fl_view.cc",
"fl_view_accessible.cc",
]

# Set flag to stop headers being directly included (library users should not do this)
Expand Down
58 changes: 58 additions & 0 deletions shell/platform/linux/fl_accessibility_plugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/shell/platform/linux/fl_accessibility_plugin.h"
#include "flutter/shell/platform/linux/fl_accessible.h"
#include "flutter/shell/platform/linux/fl_view_accessible.h"

struct _FlAccessibilityPlugin {
GObject parent_instance;

FlView* view;
};

G_DEFINE_TYPE(FlAccessibilityPlugin, fl_accessibility_plugin, G_TYPE_OBJECT)

static void view_weak_notify_cb(gpointer user_data, GObject* object) {
FlAccessibilityPlugin* self = FL_ACCESSIBILITY_PLUGIN(object);
self->view = nullptr;
}

static void fl_accessibility_plugin_dispose(GObject* object) {
FlAccessibilityPlugin* self = FL_ACCESSIBILITY_PLUGIN(object);

if (self->view != nullptr) {
g_object_weak_unref(G_OBJECT(self->view), view_weak_notify_cb, self);
self->view = nullptr;
}

G_OBJECT_CLASS(fl_accessibility_plugin_parent_class)->dispose(object);
}

static void fl_accessibility_plugin_class_init(
FlAccessibilityPluginClass* klass) {
G_OBJECT_CLASS(klass)->dispose = fl_accessibility_plugin_dispose;
}

static void fl_accessibility_plugin_init(FlAccessibilityPlugin* self) {}

FlAccessibilityPlugin* fl_accessibility_plugin_new(FlView* view) {
FlAccessibilityPlugin* self = FL_ACCESSIBILITY_PLUGIN(
g_object_new(fl_accessibility_plugin_get_type(), nullptr));

self->view = view;
g_object_weak_ref(G_OBJECT(view), view_weak_notify_cb, self);

return self;
}

void fl_accessibility_plugin_handle_update_semantics_node(
FlAccessibilityPlugin* self,
const FlutterSemanticsNode* node) {
if (self->view != nullptr) {
AtkObject* accessible = gtk_widget_get_accessible(GTK_WIDGET(self->view));
fl_view_accessible_handle_update_semantics_node(
FL_VIEW_ACCESSIBLE(accessible), node);
}
}
50 changes: 50 additions & 0 deletions shell/platform/linux/fl_accessibility_plugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_ACCESSIBILITY_PLUGIN_H_
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_ACCESSIBILITY_PLUGIN_H_

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

#include "flutter/shell/platform/embedder/embedder.h"

G_BEGIN_DECLS

G_DECLARE_FINAL_TYPE(FlAccessibilityPlugin,
fl_accessibility_plugin,
FL,
ACCESSIBILITY_PLUGIN,
GObject);

/**
* FlAccessibilityPlugin:
*
* #FlAccessibilityPlugin is a plugin that handles semantic node updates and
* converts them to ATK events.
*/

/**
* fl_accessibility_plugin_new:
* @view: an #FlView to export accessibility information to.
*
* Creates a new plugin handles semantic node updates.
*
* Returns: a new #FlAccessibilityPlugin.
*/
FlAccessibilityPlugin* fl_accessibility_plugin_new(FlView* view);

/**
* fl_accessibility_plugin_handle_update_semantics_node:
* @plugin: an #FlAccessibilityPlugin.
* @node: semantic node information.
*
* Handle a semantics node update.
*/
void fl_accessibility_plugin_handle_update_semantics_node(
FlAccessibilityPlugin* plugin,
const FlutterSemanticsNode* node);

G_END_DECLS

#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_ACCESSIBILITY_PLUGIN_H_
Loading

0 comments on commit a483552

Please sign in to comment.