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/. */
7 #include "InterfaceInitFuncs.h"
9 #include "AccessibleWrap.h"
10 #include "ImageAccessible.h"
11 #include "mozilla/Likely.h"
13 #include "nsIAccessibleTypes.h"
14 #include "RemoteAccessible.h"
16 using namespace mozilla
;
17 using namespace mozilla::a11y
;
20 const gchar
* getDescriptionCB(AtkObject
* aAtkObj
);
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
;
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 (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aImage
))) {
35 pos
= proxy
->ImagePosition(geckoCoordType
);
42 static const gchar
* getImageDescriptionCB(AtkImage
* aImage
) {
43 return getDescriptionCB(ATK_OBJECT(aImage
));
46 static void getImageSizeCB(AtkImage
* aImage
, gint
* aAccWidth
,
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 (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aImage
))) {
53 size
= proxy
->ImageSize();
56 *aAccWidth
= size
.width
;
57 *aAccHeight
= size
.height
;
62 void imageInterfaceInitCB(AtkImageIface
* aIface
) {
63 NS_ASSERTION(aIface
, "no interface!");
64 if (MOZ_UNLIKELY(!aIface
)) return;
66 aIface
->get_image_position
= getImagePositionCB
;
67 aIface
->get_image_description
= getImageDescriptionCB
;
68 aIface
->get_image_size
= getImageSizeCB
;