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 "ia2AccessibleComponent.h"
9 
10 #include "AccessibleComponent_i.c"
11 
12 #include "AccessibleWrap.h"
13 #include "States.h"
14 #include "IUnknownImpl.h"
15 
16 #include "nsIFrame.h"
17 
18 using namespace mozilla::a11y;
19 
LocalAcc()20 AccessibleWrap* ia2AccessibleComponent::LocalAcc() {
21   return static_cast<MsaaAccessible*>(this)->LocalAcc();
22 }
23 
24 // IUnknown
25 
26 STDMETHODIMP
QueryInterface(REFIID iid,void ** ppv)27 ia2AccessibleComponent::QueryInterface(REFIID iid, void** ppv) {
28   if (!ppv) return E_INVALIDARG;
29 
30   *ppv = nullptr;
31 
32   if (IID_IAccessibleComponent == iid) {
33     *ppv = static_cast<IAccessibleComponent*>(this);
34     (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
35     return S_OK;
36   }
37 
38   return E_NOINTERFACE;
39 }
40 
41 // IAccessibleComponent
42 
43 STDMETHODIMP
get_locationInParent(long * aX,long * aY)44 ia2AccessibleComponent::get_locationInParent(long* aX, long* aY) {
45   if (!aX || !aY) return E_INVALIDARG;
46 
47   *aX = 0;
48   *aY = 0;
49 
50   AccessibleWrap* acc = LocalAcc();
51   if (!acc) return CO_E_OBJNOTCONNECTED;
52 
53   // If the object is not on any screen the returned position is (0,0).
54   uint64_t state = acc->State();
55   if (state & states::INVISIBLE) return S_OK;
56 
57   nsIntRect rect = acc->Bounds();
58 
59   // The coordinates of the returned position are relative to this object's
60   // parent or relative to the screen on which this object is rendered if it
61   // has no parent.
62   if (!acc->LocalParent()) {
63     *aX = rect.X();
64     *aY = rect.Y();
65     return S_OK;
66   }
67 
68   // The coordinates of the bounding box are given relative to the parent's
69   // coordinate system.
70   nsIntRect parentRect = acc->LocalParent()->Bounds();
71   *aX = rect.X() - parentRect.X();
72   *aY = rect.Y() - parentRect.Y();
73   return S_OK;
74 }
75 
76 STDMETHODIMP
get_foreground(IA2Color * aForeground)77 ia2AccessibleComponent::get_foreground(IA2Color* aForeground) {
78   if (!aForeground) return E_INVALIDARG;
79 
80   *aForeground = 0;
81 
82   AccessibleWrap* acc = LocalAcc();
83   if (!acc) return CO_E_OBJNOTCONNECTED;
84 
85   nsIFrame* frame = acc->GetFrame();
86   if (frame) *aForeground = frame->StyleText()->mColor.ToColor();
87 
88   return S_OK;
89 }
90 
91 STDMETHODIMP
get_background(IA2Color * aBackground)92 ia2AccessibleComponent::get_background(IA2Color* aBackground) {
93   if (!aBackground) return E_INVALIDARG;
94 
95   *aBackground = 0;
96 
97   AccessibleWrap* acc = LocalAcc();
98   if (!acc) return CO_E_OBJNOTCONNECTED;
99 
100   nsIFrame* frame = acc->GetFrame();
101   if (frame) {
102     *aBackground = frame->StyleBackground()->BackgroundColor(frame);
103   }
104 
105   return S_OK;
106 }
107