1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "InterfaceInitFuncs.h"
8 
9 #include "AccessibleWrap.h"
10 #include "ImageAccessible.h"
11 #include "mozilla/Likely.h"
12 #include "nsMai.h"
13 #include "nsIAccessibleTypes.h"
14 #include "ProxyAccessible.h"
15 
16 using namespace mozilla;
17 using namespace mozilla::a11y;
18 
19 extern "C" {
20 const gchar* getDescriptionCB(AtkObject* aAtkObj);
21 
getImagePositionCB(AtkImage * aImage,gint * aAccX,gint * aAccY,AtkCoordType aCoordType)22 static void getImagePositionCB(AtkImage* aImage, gint* aAccX, gint* aAccY,
23                                AtkCoordType aCoordType) {
24   nsIntPoint pos = nsIntPoint(-1, -1);
25   uint32_t geckoCoordType =
26       (aCoordType == ATK_XY_WINDOW)
27           ? nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE
28           : nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
29 
30   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aImage));
31   if (accWrap && accWrap->IsImage()) {
32     ImageAccessible* image = accWrap->AsImage();
33     pos = image->Position(geckoCoordType);
34   } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aImage))) {
35     pos = proxy->ImagePosition(geckoCoordType);
36   }
37 
38   *aAccX = pos.x;
39   *aAccY = pos.y;
40 }
41 
getImageDescriptionCB(AtkImage * aImage)42 static const gchar* getImageDescriptionCB(AtkImage* aImage) {
43   return getDescriptionCB(ATK_OBJECT(aImage));
44 }
45 
getImageSizeCB(AtkImage * aImage,gint * aAccWidth,gint * aAccHeight)46 static void getImageSizeCB(AtkImage* aImage, gint* aAccWidth,
47                            gint* aAccHeight) {
48   nsIntSize size = nsIntSize(-1, -1);
49   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aImage));
50   if (accWrap && accWrap->IsImage()) {
51     size = accWrap->AsImage()->Size();
52   } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aImage))) {
53     size = proxy->ImageSize();
54   }
55 
56   *aAccWidth = size.width;
57   *aAccHeight = size.height;
58 }
59 
60 }  // extern "C"
61 
imageInterfaceInitCB(AtkImageIface * aIface)62 void imageInterfaceInitCB(AtkImageIface* aIface) {
63   NS_ASSERTION(aIface, "no interface!");
64   if (MOZ_UNLIKELY(!aIface)) return;
65 
66   aIface->get_image_position = getImagePositionCB;
67   aIface->get_image_description = getImageDescriptionCB;
68   aIface->get_image_size = getImageSizeCB;
69 }
70