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 "nsIURI.h"
15 #include "ProxyAccessible.h"
16 
17 using namespace mozilla;
18 using namespace mozilla::a11y;
19 
20 extern "C" {
21 const gchar* getDescriptionCB(AtkObject* aAtkObj);
22 
23 static void
getImagePositionCB(AtkImage * aImage,gint * aAccX,gint * aAccY,AtkCoordType aCoordType)24 getImagePositionCB(AtkImage* aImage, gint* aAccX, gint* aAccY,
25                    AtkCoordType aCoordType)
26 {
27   nsIntPoint pos;
28   uint32_t geckoCoordType = (aCoordType == ATK_XY_WINDOW) ?
29     nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE :
30     nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
31 
32   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aImage));
33   if (accWrap && accWrap->IsImage()) {
34     ImageAccessible* image = accWrap->AsImage();
35     pos = image->Position(geckoCoordType);
36   } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aImage))) {
37     pos = proxy->ImagePosition(geckoCoordType);
38   }
39 
40   *aAccX = pos.x;
41   *aAccY = pos.y;
42 }
43 
44 static const gchar*
getImageDescriptionCB(AtkImage * aImage)45 getImageDescriptionCB(AtkImage* aImage)
46 {
47   return getDescriptionCB(ATK_OBJECT(aImage));
48 }
49 
50 static void
getImageSizeCB(AtkImage * aImage,gint * aAccWidth,gint * aAccHeight)51 getImageSizeCB(AtkImage* aImage, gint* aAccWidth, gint* aAccHeight)
52 {
53   nsIntSize size;
54   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aImage));
55   if (accWrap && accWrap->IsImage()) {
56     size = accWrap->AsImage()->Size();
57   } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aImage))) {
58     size = proxy->ImageSize();
59   }
60 
61   *aAccWidth = size.width;
62   *aAccHeight = size.height;
63 }
64 
65 } // extern "C"
66 
67 void
imageInterfaceInitCB(AtkImageIface * aIface)68 imageInterfaceInitCB(AtkImageIface* aIface)
69 {
70   NS_ASSERTION(aIface, "no interface!");
71   if (MOZ_UNLIKELY(!aIface))
72     return;
73 
74   aIface->get_image_position = getImagePositionCB;
75   aIface->get_image_description = getImageDescriptionCB;
76   aIface->get_image_size = getImageSizeCB;
77 }
78