1/*
2 * Copyright (C) 2008 Nuanti Ltd.
3 * Copyright (C) 2009 Jan Alonzo
4 * Copyright (C) 2009, 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 "WebKitAccessibleInterfaceImage.h"
34
35#if HAVE(ACCESSIBILITY)
36
37#include "AccessibilityObject.h"
38#include "IntRect.h"
39#include "WebKitAccessible.h"
40#include "WebKitAccessibleUtil.h"
41
42using namespace WebCore;
43
44static AccessibilityObject* core(AtkImage* image)
45{
46 if (!WEBKIT_IS_ACCESSIBLE(image))
47 return 0;
48
49 return &webkitAccessibleGetAccessibilityObject(WEBKIT_ACCESSIBLE(image));
50}
51
52static void webkitAccessibleImageGetImagePosition(AtkImage* image, gint* x, gint* y, AtkCoordType coordType)
53{
54 g_return_if_fail(ATK_IMAGE(image));
55 returnIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(image));
56
57 IntRect rect = snappedIntRect(core(image)->elementRect());
58 contentsRelativeToAtkCoordinateType(core(image), coordType, rect, x, y);
59}
60
61static const gchar* webkitAccessibleImageGetImageDescription(AtkImage* image)
62{
63 auto* accessible = WEBKIT_ACCESSIBLE(image);
64 returnValIfWebKitAccessibleIsInvalid(accessible, nullptr);
65
66 return webkitAccessibleCacheAndReturnAtkProperty(accessible, AtkCachedImageDescription, accessibilityDescription(core(image)).utf8());
67}
68
69static void webkitAccessibleImageGetImageSize(AtkImage* image, gint* width, gint* height)
70{
71 g_return_if_fail(ATK_IMAGE(image));
72 returnIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(image));
73
74 IntSize size = snappedIntRect(core(image)->elementRect()).size();
75
76 if (width)
77 *width = size.width();
78 if (height)
79 *height = size.height();
80}
81
82void webkitAccessibleImageInterfaceInit(AtkImageIface* iface)
83{
84 iface->get_image_position = webkitAccessibleImageGetImagePosition;
85 iface->get_image_description = webkitAccessibleImageGetImageDescription;
86 iface->get_image_size = webkitAccessibleImageGetImageSize;
87}
88
89#endif
90