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* ToAXPlatformNodeAuraLinux( |
| 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 = ToAXPlatformNodeAuraLinux(atk_object); |
| 69 if (!obj) |
| 70 return nullptr; |
| 71 |
| 72 return obj->GetStringAttribute(ui::AX_ATTR_NAME).c_str(); |
| 73 } |
| 74 |
| 75 static const gchar* ax_platform_node_auralinux_get_description( |
| 76 AtkObject* atk_object) { |
| 77 ui::AXPlatformNodeAuraLinux* obj = ToAXPlatformNodeAuraLinux(atk_object); |
| 78 if (!obj) |
| 79 return nullptr; |
| 80 |
| 81 return obj->GetStringAttribute( |
| 82 ui::AX_ATTR_DESCRIPTION).c_str(); |
| 83 } |
| 84 |
| 85 static AtkObject* ax_platform_node_auralinux_get_parent(AtkObject* atk_object) { |
| 86 ui::AXPlatformNodeAuraLinux* obj = ToAXPlatformNodeAuraLinux(atk_object); |
| 87 if (!obj) |
| 88 return nullptr; |
| 89 |
| 90 return obj->GetParent(); |
| 91 } |
| 92 |
| 93 static gint ax_platform_node_auralinux_get_n_children(AtkObject* atk_object) { |
| 94 ui::AXPlatformNodeAuraLinux* obj = ToAXPlatformNodeAuraLinux(atk_object); |
| 95 if (!obj) |
| 96 return 0; |
| 97 |
| 98 return obj->GetChildCount(); |
| 99 } |
| 100 |
| 101 static AtkObject* ax_platform_node_auralinux_ref_child( |
| 102 AtkObject* atk_object, gint index) { |
| 103 ui::AXPlatformNodeAuraLinux* obj = ToAXPlatformNodeAuraLinux(atk_object); |
| 104 if (!obj) |
| 105 return nullptr; |
| 106 |
| 107 AtkObject* result = obj->ChildAtIndex(index); |
| 108 if (result) |
| 109 g_object_ref(result); |
| 110 return result; |
| 111 } |
| 112 |
| 113 static AtkRole ax_platform_node_auralinux_get_role(AtkObject* atk_object) { |
| 114 ui::AXPlatformNodeAuraLinux* obj = ToAXPlatformNodeAuraLinux(atk_object); |
| 115 if (!obj) |
| 116 return ATK_ROLE_INVALID; |
| 117 return obj->GetAtkRole(); |
| 118 } |
| 119 |
| 120 // |
| 121 // The rest of the AXPlatformNodeAuraLinux code, not specific to one |
| 122 // of the Atk* interfaces. |
| 123 // |
| 124 |
| 125 static gpointer ax_platform_node_auralinux_parent_class = nullptr; |
| 126 |
| 127 static void ax_platform_node_auralinux_init(AtkObject* atk_object, |
| 128 gpointer data) { |
| 129 if (ATK_OBJECT_CLASS(ax_platform_node_auralinux_parent_class)->initialize) { |
| 130 ATK_OBJECT_CLASS(ax_platform_node_auralinux_parent_class)->initialize( |
| 131 atk_object, data); |
| 132 } |
| 133 |
| 134 AX_PLATFORM_NODE_AURALINUX(atk_object)->m_object = |
| 135 reinterpret_cast<ui::AXPlatformNodeAuraLinux*>(data); |
| 136 } |
| 137 |
| 138 static void ax_platform_node_auralinux_finalize(GObject* atk_object) { |
| 139 G_OBJECT_CLASS(ax_platform_node_auralinux_parent_class)->finalize(atk_object); |
| 140 } |
| 141 |
| 142 static void ax_platform_node_auralinux_class_init(AtkObjectClass* klass) { |
| 143 GObjectClass* gobject_class = G_OBJECT_CLASS(klass); |
| 144 ax_platform_node_auralinux_parent_class = g_type_class_peek_parent(klass); |
| 145 |
| 146 gobject_class->finalize = ax_platform_node_auralinux_finalize; |
| 147 klass->initialize = ax_platform_node_auralinux_init; |
| 148 klass->get_name = ax_platform_node_auralinux_get_name; |
| 149 klass->get_description = ax_platform_node_auralinux_get_description; |
| 150 klass->get_parent = ax_platform_node_auralinux_get_parent; |
| 151 klass->get_n_children = ax_platform_node_auralinux_get_n_children; |
| 152 klass->ref_child = ax_platform_node_auralinux_ref_child; |
| 153 klass->get_role = ax_platform_node_auralinux_get_role; |
| 154 } |
| 155 |
| 156 GType ax_platform_node_auralinux_get_type() { |
| 157 static volatile gsize type_volatile = 0; |
| 158 |
| 159 if (g_once_init_enter(&type_volatile)) { |
| 160 static const GTypeInfo tinfo = { |
| 161 sizeof(AXPlatformNodeAuraLinuxClass), |
| 162 (GBaseInitFunc) 0, |
| 163 (GBaseFinalizeFunc) 0, |
| 164 (GClassInitFunc) ax_platform_node_auralinux_class_init, |
| 165 (GClassFinalizeFunc) 0, |
| 166 0, /* class data */ |
| 167 sizeof(AXPlatformNodeAuraLinuxObject), /* instance size */ |
| 168 0, /* nb preallocs */ |
| 169 (GInstanceInitFunc) 0, |
| 170 0 /* value table */ |
| 171 }; |
| 172 |
| 173 GType type = g_type_register_static( |
| 174 ATK_TYPE_OBJECT, "AXPlatformNodeAuraLinux", &tinfo, GTypeFlags(0)); |
| 175 g_once_init_leave(&type_volatile, type); |
| 176 } |
| 177 |
| 178 return type_volatile; |
| 179 } |
| 180 |
| 181 AXPlatformNodeAuraLinuxObject* ax_platform_node_auralinux_new( |
| 182 ui::AXPlatformNodeAuraLinux* obj) { |
| 183 GType type = AX_PLATFORM_NODE_AURALINUX_TYPE; |
| 184 AtkObject* atk_object = static_cast<AtkObject*>(g_object_new(type, 0)); |
| 185 atk_object_initialize(atk_object, obj); |
| 186 return AX_PLATFORM_NODE_AURALINUX(atk_object); |
| 187 } |
| 188 |
| 189 void ax_platform_node_auralinux_detach( |
| 190 AXPlatformNodeAuraLinuxObject* atk_object) { |
| 191 atk_object->m_object = nullptr; |
| 192 } |
| 193 |
| 194 G_END_DECLS |
| 195 |
| 196 // |
| 197 // AXPlatformNodeAuraLinux implementation. |
| 198 // |
| 199 |
| 200 namespace ui { |
| 201 |
| 202 // static |
| 203 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { |
| 204 AXPlatformNodeAuraLinux* node = new AXPlatformNodeAuraLinux(); |
| 205 node->Init(delegate); |
| 206 return node; |
| 207 } |
| 208 |
| 209 // static |
| 210 AXPlatformNode* AXPlatformNodeAuraLinux::application_ = nullptr; |
| 211 |
| 212 // static |
| 213 void AXPlatformNodeAuraLinux::SetApplication(AXPlatformNode* application) { |
| 214 application_ = application; |
| 215 AtkUtilAuraLinux::GetInstance(); |
| 216 } |
| 217 |
| 218 AtkRole AXPlatformNodeAuraLinux::GetAtkRole() { |
| 219 switch (GetData().role) { |
| 220 case ui::AX_ROLE_APPLICATION: |
| 221 return ATK_ROLE_APPLICATION; |
| 222 case ui::AX_ROLE_BUTTON: |
| 223 return ATK_ROLE_PUSH_BUTTON; |
| 224 case ui::AX_ROLE_CHECK_BOX: |
| 225 return ATK_ROLE_CHECK_BOX; |
| 226 case ui::AX_ROLE_COMBO_BOX: |
| 227 return ATK_ROLE_COMBO_BOX; |
| 228 case ui::AX_ROLE_STATIC_TEXT: |
| 229 return ATK_ROLE_TEXT; |
| 230 case ui::AX_ROLE_TEXT_FIELD: |
| 231 return ATK_ROLE_ENTRY; |
| 232 case ui::AX_ROLE_WINDOW: |
| 233 return ATK_ROLE_WINDOW; |
| 234 default: |
| 235 return ATK_ROLE_UNKNOWN; |
| 236 } |
| 237 } |
| 238 |
| 239 AXPlatformNodeAuraLinux::AXPlatformNodeAuraLinux() |
| 240 : atk_object_(nullptr) { |
| 241 } |
| 242 |
| 243 AXPlatformNodeAuraLinux::~AXPlatformNodeAuraLinux() { |
| 244 g_object_unref(atk_object_); |
| 245 } |
| 246 |
| 247 void AXPlatformNodeAuraLinux::Init(AXPlatformNodeDelegate* delegate) { |
| 248 // Initialize ATK. |
| 249 AXPlatformNodeBase::Init(delegate); |
| 250 atk_object_ = ATK_OBJECT(ax_platform_node_auralinux_new(this)); |
| 251 } |
| 252 |
| 253 void AXPlatformNodeAuraLinux::Destroy() { |
| 254 delegate_ = nullptr; |
| 255 delete this; |
| 256 } |
| 257 |
| 258 gfx::NativeViewAccessible AXPlatformNodeAuraLinux::GetNativeViewAccessible() { |
| 259 return atk_object_; |
| 260 } |
| 261 |
| 262 void AXPlatformNodeAuraLinux::NotifyAccessibilityEvent(ui::AXEvent event_type) { |
| 263 } |
| 264 |
| 265 int AXPlatformNodeAuraLinux::GetIndexInParent() { |
| 266 return 0; |
| 267 } |
| 268 |
| 269 } // namespace ui |
OLD | NEW |