1 | /* |
2 | * Copyright (C) 2008 Nuanti Ltd. |
3 | * Copyright (C) 2009 Jan Alonzo |
4 | * Copyright (C) 2012 Igalia S.L. |
5 | * Copyright (C) 2013 Samsung Electronics |
6 | * |
7 | * Portions from Mozilla a11y, copyright as follows: |
8 | * |
9 | * The Original Code is mozilla.org code. |
10 | * |
11 | * The Initial Developer of the Original Code is |
12 | * Sun Microsystems, Inc. |
13 | * Portions created by the Initial Developer are Copyright (C) 2002 |
14 | * the Initial Developer. All Rights Reserved. |
15 | * |
16 | * This library is free software; you can redistribute it and/or |
17 | * modify it under the terms of the GNU Library General Public |
18 | * License as published by the Free Software Foundation; either |
19 | * version 2 of the License, or (at your option) any later version. |
20 | * |
21 | * This library is distributed in the hope that it will be useful, |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
24 | * Library General Public License for more details. |
25 | * |
26 | * You should have received a copy of the GNU Library General Public License |
27 | * along with this library; see the file COPYING.LIB. If not, write to |
28 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
29 | * Boston, MA 02110-1301, USA. |
30 | */ |
31 | |
32 | #include "config.h" |
33 | #include "WebKitAccessibleInterfaceAction.h" |
34 | |
35 | #if HAVE(ACCESSIBILITY) |
36 | |
37 | #include "AccessibilityObject.h" |
38 | #include "NotImplemented.h" |
39 | #include "WebKitAccessible.h" |
40 | #include "WebKitAccessibleUtil.h" |
41 | |
42 | using namespace WebCore; |
43 | |
44 | static AccessibilityObject* core(AtkAction* action) |
45 | { |
46 | if (!WEBKIT_IS_ACCESSIBLE(action)) |
47 | return 0; |
48 | |
49 | return &webkitAccessibleGetAccessibilityObject(WEBKIT_ACCESSIBLE(action)); |
50 | } |
51 | |
52 | static gboolean webkitAccessibleActionDoAction(AtkAction* action, gint index) |
53 | { |
54 | g_return_val_if_fail(ATK_IS_ACTION(action), FALSE); |
55 | g_return_val_if_fail(!index, FALSE); |
56 | |
57 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(action), FALSE); |
58 | |
59 | return core(action)->performDefaultAction(); |
60 | } |
61 | |
62 | static gint webkitAccessibleActionGetNActions(AtkAction* action) |
63 | { |
64 | g_return_val_if_fail(ATK_IS_ACTION(action), 0); |
65 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(action), 0); |
66 | |
67 | return 1; |
68 | } |
69 | |
70 | static const gchar* webkitAccessibleActionGetDescription(AtkAction* action, gint) |
71 | { |
72 | g_return_val_if_fail(ATK_IS_ACTION(action), 0); |
73 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(action), 0); |
74 | |
75 | // TODO: Need a way to provide/localize action descriptions. |
76 | notImplemented(); |
77 | return "" ; |
78 | } |
79 | |
80 | static const gchar* webkitAccessibleActionGetKeybinding(AtkAction* action, gint) |
81 | { |
82 | auto* accessible = WEBKIT_ACCESSIBLE(action); |
83 | returnValIfWebKitAccessibleIsInvalid(accessible, nullptr); |
84 | |
85 | // FIXME: Construct a proper keybinding string. |
86 | return webkitAccessibleCacheAndReturnAtkProperty(accessible, AtkCachedActionKeyBinding, core(action)->accessKey().string().utf8()); |
87 | } |
88 | |
89 | static const gchar* webkitAccessibleActionGetName(AtkAction* action, gint) |
90 | { |
91 | auto* accessible = WEBKIT_ACCESSIBLE(action); |
92 | returnValIfWebKitAccessibleIsInvalid(accessible, nullptr); |
93 | |
94 | return webkitAccessibleCacheAndReturnAtkProperty(accessible, AtkCachedActionName, core(action)->actionVerb().utf8()); |
95 | } |
96 | |
97 | void webkitAccessibleActionInterfaceInit(AtkActionIface* iface) |
98 | { |
99 | iface->do_action = webkitAccessibleActionDoAction; |
100 | iface->get_n_actions = webkitAccessibleActionGetNActions; |
101 | iface->get_description = webkitAccessibleActionGetDescription; |
102 | iface->get_keybinding = webkitAccessibleActionGetKeybinding; |
103 | iface->get_name = webkitAccessibleActionGetName; |
104 | } |
105 | |
106 | #endif |
107 | |