Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: ui/accessibility/platform/atk_util_auralinux.cc

Issue 1005293002: Re-land: Resurrect Aura Linux accessibility. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium 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 <atk/atk.h>
6 #include <gconf/gconf-client.h>
7 #include <glib-2.0/gmodule.h>
8
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "base/memory/singleton.h"
12 #include "ui/accessibility/platform/atk_util_auralinux.h"
13 #include "ui/accessibility/platform/ax_platform_node_auralinux.h"
14
15 namespace {
16
17 const char kGnomeAccessibilityEnabledKey[] =
18 "/desktop/gnome/interface/accessibility";
19
20 bool ShouldEnableAccessibility() {
21 GConfClient* client = gconf_client_get_default();
22 if (!client) {
23 LOG(ERROR) << "gconf_client_get_default failed";
24 return false;
25 }
26
27 GError* error = nullptr;
28 gboolean value = gconf_client_get_bool(client,
29 kGnomeAccessibilityEnabledKey,
30 &error);
31 if (error) {
32 VLOG(1) << "gconf_client_get_bool failed";
33 g_error_free(error);
34 g_object_unref(client);
35 return false;
36 }
37
38 g_object_unref(client);
39 return value;
40 }
41
42 } // namespace
43
44 G_BEGIN_DECLS
45
46 //
47 // atk_util_auralinux AtkObject definition and implementation.
48 //
49
50 #define ATK_UTIL_AURALINUX_TYPE (atk_util_auralinux_get_type())
51 #define ATK_UTIL_AURALINUX(obj) \
52 (G_TYPE_CHECK_INSTANCE_CAST((obj), \
53 ATK_UTIL_AURALINUX_TYPE, \
54 AtkUtilAuraLinux))
55 #define ATK_UTIL_AURALINUX_CLASS(klass) \
56 (G_TYPE_CHECK_CLASS_CAST((klass), \
57 ATK_UTIL_AURALINUX_TYPE, \
58 AtkUtilAuraLinuxClass))
59 #define IS_ATK_UTIL_AURALINUX(obj) \
60 (G_TYPE_CHECK_INSTANCE_TYPE((obj), ATK_UTIL_AURALINUX_TYPE))
61 #define IS_ATK_UTIL_AURALINUX_CLASS(klass) \
62 (G_TYPE_CHECK_CLASS_TYPE((klass), ATK_UTIL_AURALINUX_TYPE))
63 #define ATK_UTIL_AURALINUX_GET_CLASS(obj) \
64 (G_TYPE_INSTANCE_GET_CLASS((obj), \
65 ATK_UTIL_AURALINUX_TYPE, \
66 AtkUtilAuraLinuxClass))
67
68 typedef struct _AtkUtilAuraLinux AtkUtilAuraLinux;
69 typedef struct _AtkUtilAuraLinuxClass AtkUtilAuraLinuxClass;
70
71 struct _AtkUtilAuraLinux
72 {
73 AtkUtil parent;
74 };
75
76 struct _AtkUtilAuraLinuxClass
77 {
78 AtkUtilClass parent_class;
79 };
80
81 GType atk_util_auralinux_get_type();
82
83 G_DEFINE_TYPE(AtkUtilAuraLinux, atk_util_auralinux, ATK_TYPE_UTIL);
84
85 static void atk_util_auralinux_init(AtkUtilAuraLinux *ax_util) {
86 }
87
88 static AtkObject* atk_util_auralinux_get_root() {
89 ui::AXPlatformNode* application = ui::AXPlatformNodeAuraLinux::application();
90 if (application) {
91 return application->GetNativeViewAccessible();
92 }
93 return nullptr;
94 }
95
96 static G_CONST_RETURN gchar* atk_util_auralinux_get_toolkit_name(void) {
97 return "Chromium";
98 }
99
100 static G_CONST_RETURN gchar* atk_util_auralinux_get_toolkit_version(void) {
101 return "1.0";
102 }
103
104 static void atk_util_auralinux_class_init(AtkUtilAuraLinuxClass *klass) {
105 AtkUtilClass *atk_class;
106 gpointer data;
107
108 data = g_type_class_peek(ATK_TYPE_UTIL);
109 atk_class = ATK_UTIL_CLASS(data);
110
111 atk_class->get_root = atk_util_auralinux_get_root;
112 atk_class->get_toolkit_name = atk_util_auralinux_get_toolkit_name;
113 atk_class->get_toolkit_version = atk_util_auralinux_get_toolkit_version;
114 }
115
116 G_END_DECLS
117
118 //
119 // AtkUtilAuraLinuxClass implementation.
120 //
121
122 namespace ui {
123
124 // static
125 AtkUtilAuraLinux* AtkUtilAuraLinux::GetInstance() {
126 return Singleton<AtkUtilAuraLinux>::get();
127 }
128
129 AtkUtilAuraLinux::AtkUtilAuraLinux() {
130 // Register our util class.
131 g_type_class_unref(g_type_class_ref(ATK_UTIL_AURALINUX_TYPE));
132
133 if (!ShouldEnableAccessibility()) {
134 VLOG(1) << "Will not enable ATK accessibility support.";
135 return;
136 }
137
138 VLOG(1) << "Enabling ATK accessibility support.";
139
140 // Try to load libatk-bridge.so.
141 base::FilePath atk_bridge_path(ATK_LIB_DIR);
142 atk_bridge_path = atk_bridge_path.Append("gtk-2.0/modules/libatk-bridge.so");
143 GModule* bridge = g_module_open(atk_bridge_path.value().c_str(),
144 static_cast<GModuleFlags>(0));
145 if (!bridge) {
146 VLOG(1) << "Unable to open module " << atk_bridge_path.value();
147 return;
148 }
149
150 // Try to call gnome_accessibility_module_init from libatk-bridge.so.
151 void (*gnome_accessibility_module_init)();
152 if (g_module_symbol(bridge, "gnome_accessibility_module_init",
153 (gpointer *)&gnome_accessibility_module_init)) {
154 (*gnome_accessibility_module_init)();
155 }
156 }
157
158 AtkUtilAuraLinux::~AtkUtilAuraLinux() {
159 }
160
161 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698