|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:expandtab:shiftwidth=2:tabstop=2: |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #include "ia2AccessibleImage.h" |
|
9 |
|
10 #include "AccessibleImage_i.c" |
|
11 |
|
12 #include "ImageAccessibleWrap.h" |
|
13 #include "IUnknownImpl.h" |
|
14 #include "nsIAccessibleTypes.h" |
|
15 |
|
16 #include "nsString.h" |
|
17 #include "nsIURI.h" |
|
18 |
|
19 using namespace mozilla; |
|
20 using namespace mozilla::a11y; |
|
21 |
|
22 // IUnknown |
|
23 |
|
24 STDMETHODIMP |
|
25 ia2AccessibleImage::QueryInterface(REFIID iid, void** ppv) |
|
26 { |
|
27 if (!ppv) |
|
28 return E_INVALIDARG; |
|
29 |
|
30 *ppv = nullptr; |
|
31 |
|
32 if (IID_IAccessibleImage == iid) { |
|
33 *ppv = static_cast<IAccessibleImage*>(this); |
|
34 (static_cast<IUnknown*>(*ppv))->AddRef(); |
|
35 return S_OK; |
|
36 } |
|
37 |
|
38 return E_NOINTERFACE; |
|
39 } |
|
40 |
|
41 // IAccessibleImage |
|
42 |
|
43 STDMETHODIMP |
|
44 ia2AccessibleImage::get_description(BSTR* aDescription) |
|
45 { |
|
46 A11Y_TRYBLOCK_BEGIN |
|
47 |
|
48 if (!aDescription) |
|
49 return E_INVALIDARG; |
|
50 |
|
51 *aDescription = nullptr; |
|
52 |
|
53 ImageAccessibleWrap* acc = static_cast<ImageAccessibleWrap*>(this); |
|
54 if (acc->IsDefunct()) |
|
55 return CO_E_OBJNOTCONNECTED; |
|
56 |
|
57 nsAutoString description; |
|
58 nsresult rv = acc->GetName(description); |
|
59 if (NS_FAILED(rv)) |
|
60 return GetHRESULT(rv); |
|
61 |
|
62 if (description.IsEmpty()) |
|
63 return S_FALSE; |
|
64 |
|
65 *aDescription = ::SysAllocStringLen(description.get(), description.Length()); |
|
66 return *aDescription ? S_OK : E_OUTOFMEMORY; |
|
67 |
|
68 A11Y_TRYBLOCK_END |
|
69 } |
|
70 |
|
71 STDMETHODIMP |
|
72 ia2AccessibleImage::get_imagePosition(enum IA2CoordinateType aCoordType, |
|
73 long* aX, |
|
74 long* aY) |
|
75 { |
|
76 A11Y_TRYBLOCK_BEGIN |
|
77 |
|
78 if (!aX || !aY) |
|
79 return E_INVALIDARG; |
|
80 |
|
81 *aX = 0; |
|
82 *aY = 0; |
|
83 |
|
84 ImageAccessibleWrap* imageAcc = static_cast<ImageAccessibleWrap*>(this); |
|
85 if (imageAcc->IsDefunct()) |
|
86 return CO_E_OBJNOTCONNECTED; |
|
87 |
|
88 uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ? |
|
89 nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE : |
|
90 nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE; |
|
91 int32_t x = 0, y = 0; |
|
92 |
|
93 nsresult rv = imageAcc->GetImagePosition(geckoCoordType, &x, &y); |
|
94 if (NS_FAILED(rv)) |
|
95 return GetHRESULT(rv); |
|
96 |
|
97 *aX = x; |
|
98 *aY = y; |
|
99 return S_OK; |
|
100 |
|
101 A11Y_TRYBLOCK_END |
|
102 } |
|
103 |
|
104 STDMETHODIMP |
|
105 ia2AccessibleImage::get_imageSize(long* aHeight, long* aWidth) |
|
106 { |
|
107 A11Y_TRYBLOCK_BEGIN |
|
108 |
|
109 if (!aHeight || !aWidth) |
|
110 return E_INVALIDARG; |
|
111 |
|
112 *aHeight = 0; |
|
113 *aWidth = 0; |
|
114 |
|
115 ImageAccessibleWrap* imageAcc = static_cast<ImageAccessibleWrap*>(this); |
|
116 if (imageAcc->IsDefunct()) |
|
117 return CO_E_OBJNOTCONNECTED; |
|
118 |
|
119 int32_t width = 0, height = 0; |
|
120 nsresult rv = imageAcc->GetImageSize(&width, &height); |
|
121 if (NS_FAILED(rv)) |
|
122 return GetHRESULT(rv); |
|
123 |
|
124 *aHeight = width; |
|
125 *aWidth = height; |
|
126 return S_OK; |
|
127 |
|
128 A11Y_TRYBLOCK_END |
|
129 } |
|
130 |