OLD | NEW |
(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 "ui/accessibility/platform/ax_platform_node_auralinux.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "ui/accessibility/ax_node_data.h" |
| 10 #include "ui/accessibility/platform/atk_util_auralinux.h" |
| 11 #include "ui/accessibility/platform/ax_platform_node_delegate.h" |
| 12 |
| 13 // |
| 14 // ax_platform_node_auralinux AtkObject definition and implementation. |
| 15 // |
| 16 |
| 17 G_BEGIN_DECLS |
| 18 |
| 19 #define AX_PLATFORM_NODE_AURALINUX_TYPE (ax_platform_node_auralinux_get_type()) |
| 20 #define AX_PLATFORM_NODE_AURALINUX(obj) \ |
| 21 (G_TYPE_CHECK_INSTANCE_CAST( \ |
| 22 (obj), AX_PLATFORM_NODE_AURALINUX_TYPE, AXPlatformNodeAuraLinuxObject)) |
| 23 #define AX_PLATFORM_NODE_AURALINUX_CLASS(klass) \ |
| 24 (G_TYPE_CHECK_CLASS_CAST( \ |
| 25 (klass), AX_PLATFORM_NODE_AURALINUX_TYPE, AXPlatformNodeAuraLinuxClass)) |
| 26 #define IS_AX_PLATFORM_NODE_AURALINUX(obj) \ |
| 27 (G_TYPE_CHECK_INSTANCE_TYPE((obj), AX_PLATFORM_NODE_AURALINUX_TYPE)) |
| 28 #define IS_AX_PLATFORM_NODE_AURALINUX_CLASS(klass) \ |
| 29 (G_TYPE_CHECK_CLASS_TYPE((klass), AX_PLATFORM_NODE_AURALINUX_TYPE)) |
| 30 #define AX_PLATFORM_NODE_AURALINUX_GET_CLASS(obj) \ |
| 31 (G_TYPE_INSTANCE_GET_CLASS( \ |
| 32 (obj), AX_PLATFORM_NODE_AURALINUX_TYPE, AXPlatformNodeAuraLinuxClass)) |
| 33 |
| 34 typedef struct _AXPlatformNodeAuraLinuxObject AXPlatformNodeAuraLinuxObject; |
| 35 typedef struct _AXPlatformNodeAuraLinuxClass AXPlatformNodeAuraLinuxClass; |
| 36 |
| 37 struct _AXPlatformNodeAuraLinuxObject { |
| 38 AtkObject parent; |
| 39 ui::AXPlatformNodeAuraLinux* m_object; |
| 40 }; |
| 41 |
| 42 struct _AXPlatformNodeAuraLinuxClass { |
| 43 AtkObjectClass parent_class; |
| 44 }; |
| 45 |
| 46 GType ax_platform_node_auralinux_get_type(); |
| 47 |
| 48 static ui::AXPlatformNodeAuraLinux* ToAXPlatformNodeAuraLinux( |
| 49 AXPlatformNodeAuraLinuxObject* atk_object) { |
| 50 if (!atk_object) |
| 51 return nullptr; |
| 52 |
| 53 return atk_object->m_object; |
| 54 } |
| 55 |
| 56 static ui::AXPlatformNodeAuraLinux* AtkObjectToAXPlatformNodeAuraLinux( |
| 57 AtkObject* atk_object) { |
| 58 if (!atk_object) |
| 59 return nullptr; |
| 60 |
| 61 if (IS_AX_PLATFORM_NODE_AURALINUX(atk_object)) |
| 62 return ToAXPlatformNodeAuraLinux(AX_PLATFORM_NODE_AURALINUX(atk_object)); |
| 63 |
| 64 return nullptr; |
| 65 } |
| 66 |
| 67 static const gchar* ax_platform_node_auralinux_get_name(AtkObject* atk_object) { |
| 68 ui::AXPlatformNodeAuraLinux* obj = |
| 69 AtkObjectToAXPlatformNodeAuraLinux(atk_object); |
| 70 if (!obj) |
| 71 return nullptr; |
| 72 |
| 73 return obj->GetStringAttribute(ui::AX_ATTR_NAME).c_str(); |
| 74 } |
| 75 |
| 76 static const gchar* ax_platform_node_auralinux_get_description( |
| 77 AtkObject* atk_object) { |
| 78 ui::AXPlatformNodeAuraLinux* obj = |
| 79 AtkObjectToAXPlatformNodeAuraLinux(atk_object); |
| 80 if (!obj) |
| 81 return nullptr; |
| 82 |
| 83 return obj->GetStringAttribute( |
| 84 ui::AX_ATTR_DESCRIPTION).c_str(); |
| 85 } |
| 86 |
| 87 static AtkObject* ax_platform_node_auralinux_get_parent(AtkObject* atk_object) { |
| 88 ui::AXPlatformNodeAuraLinux* obj = |
| 89 AtkObjectToAXPlatformNodeAuraLinux(atk_object); |
| 90 if (!obj) |
| 91 return nullptr; |
| 92 |
| 93 return obj->GetParent(); |
| 94 } |
| 95 |
| 96 static gint ax_platform_node_auralinux_get_n_children(AtkObject* atk_object) { |
| 97 ui::AXPlatformNodeAuraLinux* obj = |
| 98 AtkObjectToAXPlatformNodeAuraLinux(atk_object); |
| 99 if (!obj) |
| 100 return 0; |
| 101 |
| 102 return obj->GetChildCount(); |
| 103 } |
| 104 |
| 105 static AtkObject* ax_platform_node_auralinux_ref_child( |
| 106 AtkObject* atk_object, gint index) { |
| 107 ui::AXPlatformNodeAuraLinux* obj = |
| 108 AtkObjectToAXPlatformNodeAuraLinux(atk_object); |
| 109 if (!obj) |
| 110 return nullptr; |
| 111 |
| 112 AtkObject* result = obj->ChildAtIndex(index); |
| 113 if (result) |
| 114 g_object_ref(result); |
| 115 return result; |
| 116 } |
| 117 |
| 118 static AtkRole ax_platform_node_auralinux_get_role(AtkObject* atk_object) { |
| 119 ui::AXPlatformNodeAuraLinux* obj = |
| 120 AtkObjectToAXPlatformNodeAuraLinux(atk_object); |
| 121 if (!obj) |
| 122 return ATK_ROLE_INVALID; |
| 123 return obj->GetAtkRole(); |
| 124 } |
| 125 |
| 126 // |
| 127 // The rest of the AXPlatformNodeAuraLinux code, not specific to one |
| 128 // of the Atk* interfaces. |
| 129 // |
| 130 |
| 131 static gpointer ax_platform_node_auralinux_parent_class = nullptr; |
| 132 |
| 133 static void ax_platform_node_auralinux_init(AtkObject* atk_object, |
| 134 gpointer data) { |
| 135 if (ATK_OBJECT_CLASS(ax_platform_node_auralinux_parent_class)->initialize) { |
| 136 ATK_OBJECT_CLASS(ax_platform_node_auralinux_parent_class)->initialize( |
| 137 atk_object, data); |
| 138 } |
| 139 |
| 140 AX_PLATFORM_NODE_AURALINUX(atk_object)->m_object = |
| 141 reinterpret_cast<ui::AXPlatformNodeAuraLinux*>(data); |
| 142 } |
| 143 |
| 144 static void ax_platform_node_auralinux_finalize(GObject* atk_object) { |
| 145 G_OBJECT_CLASS(ax_platform_node_auralinux_parent_class)->finalize(atk_object); |
| 146 } |
| 147 |
| 148 static void ax_platform_node_auralinux_class_init(AtkObjectClass* klass) { |
| 149 GObjectClass* gobject_class = G_OBJECT_CLASS(klass); |
| 150 ax_platform_node_auralinux_parent_class = g_type_class_peek_parent(klass); |
| 151 |
| 152 gobject_class->finalize = ax_platform_node_auralinux_finalize; |
| 153 klass->initialize = ax_platform_node_auralinux_init; |
| 154 klass->get_name = ax_platform_node_auralinux_get_name; |
| 155 klass->get_description = ax_platform_node_auralinux_get_description; |
| 156 klass->get_parent = ax_platform_node_auralinux_get_parent; |
| 157 klass->get_n_children = ax_platform_node_auralinux_get_n_children; |
| 158 klass->ref_child = ax_platform_node_auralinux_ref_child; |
| 159 klass->get_role = ax_platform_node_auralinux_get_role; |
| 160 } |
| 161 |
| 162 GType ax_platform_node_auralinux_get_type() { |
| 163 static volatile gsize type_volatile = 0; |
| 164 |
| 165 if (g_once_init_enter(&type_volatile)) { |
| 166 static const GTypeInfo tinfo = { |
| 167 sizeof(AXPlatformNodeAuraLinuxClass), |
| 168 (GBaseInitFunc) 0, |
| 169 (GBaseFinalizeFunc) 0, |
| 170 (GClassInitFunc) ax_platform_node_auralinux_class_init, |
| 171 (GClassFinalizeFunc) 0, |
| 172 0, /* class data */ |
| 173 sizeof(AXPlatformNodeAuraLinuxObject), /* instance size */ |
| 174 0, /* nb preallocs */ |
| 175 (GInstanceInitFunc) 0, |
| 176 0 /* value table */ |
| 177 }; |
| 178 |
| 179 GType type = g_type_register_static( |
| 180 ATK_TYPE_OBJECT, "AXPlatformNodeAuraLinux", &tinfo, GTypeFlags(0)); |
| 181 g_once_init_leave(&type_volatile, type); |
| 182 } |
| 183 |
| 184 return type_volatile; |
| 185 } |
| 186 |
| 187 AXPlatformNodeAuraLinuxObject* ax_platform_node_auralinux_new( |
| 188 ui::AXPlatformNodeAuraLinux* obj) { |
| 189 #if !GLIB_CHECK_VERSION(2, 36, 0) |
| 190 static bool first_time = true; |
| 191 if (first_time) { |
| 192 g_type_init(); |
| 193 first_time = false; |
| 194 } |
| 195 #endif |
| 196 |
| 197 GType type = AX_PLATFORM_NODE_AURALINUX_TYPE; |
| 198 AtkObject* atk_object = static_cast<AtkObject*>(g_object_new(type, 0)); |
| 199 atk_object_initialize(atk_object, obj); |
| 200 return AX_PLATFORM_NODE_AURALINUX(atk_object); |
| 201 } |
| 202 |
| 203 void ax_platform_node_auralinux_detach( |
| 204 AXPlatformNodeAuraLinuxObject* atk_object) { |
| 205 atk_object->m_object = nullptr; |
| 206 } |
| 207 |
| 208 G_END_DECLS |
| 209 |
| 210 // |
| 211 // AXPlatformNodeAuraLinux implementation. |
| 212 // |
| 213 |
| 214 namespace ui { |
| 215 |
| 216 // static |
| 217 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { |
| 218 AXPlatformNodeAuraLinux* node = new AXPlatformNodeAuraLinux(); |
| 219 node->Init(delegate); |
| 220 return node; |
| 221 } |
| 222 |
| 223 // static |
| 224 AXPlatformNode* AXPlatformNodeAuraLinux::application_ = nullptr; |
| 225 |
| 226 // static |
| 227 void AXPlatformNodeAuraLinux::SetApplication(AXPlatformNode* application) { |
| 228 application_ = application; |
| 229 AtkUtilAuraLinux::GetInstance(); |
| 230 } |
| 231 |
| 232 AtkRole AXPlatformNodeAuraLinux::GetAtkRole() { |
| 233 switch (GetData().role) { |
| 234 case ui::AX_ROLE_APPLICATION: |
| 235 return ATK_ROLE_APPLICATION; |
| 236 case ui::AX_ROLE_BUTTON: |
| 237 return ATK_ROLE_PUSH_BUTTON; |
| 238 case ui::AX_ROLE_CHECK_BOX: |
| 239 return ATK_ROLE_CHECK_BOX; |
| 240 case ui::AX_ROLE_COMBO_BOX: |
| 241 return ATK_ROLE_COMBO_BOX; |
| 242 case ui::AX_ROLE_STATIC_TEXT: |
| 243 return ATK_ROLE_TEXT; |
| 244 case ui::AX_ROLE_TEXT_FIELD: |
| 245 return ATK_ROLE_ENTRY; |
| 246 case ui::AX_ROLE_WINDOW: |
| 247 return ATK_ROLE_WINDOW; |
| 248 default: |
| 249 return ATK_ROLE_UNKNOWN; |
| 250 } |
| 251 } |
| 252 |
| 253 AXPlatformNodeAuraLinux::AXPlatformNodeAuraLinux() |
| 254 : atk_object_(nullptr) { |
| 255 } |
| 256 |
| 257 AXPlatformNodeAuraLinux::~AXPlatformNodeAuraLinux() { |
| 258 g_object_unref(atk_object_); |
| 259 } |
| 260 |
| 261 void AXPlatformNodeAuraLinux::Init(AXPlatformNodeDelegate* delegate) { |
| 262 // Initialize ATK. |
| 263 AXPlatformNodeBase::Init(delegate); |
| 264 atk_object_ = ATK_OBJECT(ax_platform_node_auralinux_new(this)); |
| 265 } |
| 266 |
| 267 void AXPlatformNodeAuraLinux::Destroy() { |
| 268 delegate_ = nullptr; |
| 269 delete this; |
| 270 } |
| 271 |
| 272 gfx::NativeViewAccessible AXPlatformNodeAuraLinux::GetNativeViewAccessible() { |
| 273 return atk_object_; |
| 274 } |
| 275 |
| 276 void AXPlatformNodeAuraLinux::NotifyAccessibilityEvent(ui::AXEvent event_type) { |
| 277 } |
| 278 |
| 279 int AXPlatformNodeAuraLinux::GetIndexInParent() { |
| 280 return 0; |
| 281 } |
| 282 |
| 283 } // namespace ui |
OLD | NEW |