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 "WebKitAccessibleUtil.h"
40#include "WebKitAccessibleWrapperAtk.h"
41
42using namespace WebCore;
43
44static AccessibilityObject* core(AtkAction* action)
45{
46    if (!WEBKIT_IS_ACCESSIBLE(action))
47        return 0;
48
49    return webkitAccessibleGetAccessibilityObject(WEBKIT_ACCESSIBLE(action));
50}
51
52static 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
62static 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
70static 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
80static const gchar* webkitAccessibleActionGetKeybinding(AtkAction* action, gint index)
81{
82    g_return_val_if_fail(ATK_IS_ACTION(action), 0);
83    g_return_val_if_fail(!index, 0);
84    returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(action), 0);
85
86    // FIXME: Construct a proper keybinding string.
87    return cacheAndReturnAtkProperty(ATK_OBJECT(action), AtkCachedActionKeyBinding, core(action)->accessKey().string());
88}
89
90static const gchar* webkitAccessibleActionGetName(AtkAction* action, gint index)
91{
92    g_return_val_if_fail(ATK_IS_ACTION(action), 0);
93    g_return_val_if_fail(!index, 0);
94    returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(action), 0);
95
96    return cacheAndReturnAtkProperty(ATK_OBJECT(action), AtkCachedActionName, core(action)->actionVerb());
97}
98
99void webkitAccessibleActionInterfaceInit(AtkActionIface* iface)
100{
101    iface->do_action = webkitAccessibleActionDoAction;
102    iface->get_n_actions = webkitAccessibleActionGetNActions;
103    iface->get_description = webkitAccessibleActionGetDescription;
104    iface->get_keybinding = webkitAccessibleActionGetKeybinding;
105    iface->get_name = webkitAccessibleActionGetName;
106}
107
108#endif
109