Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:expandtab:shiftwidth=2:tabstop=2: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "ia2AccessibleComponent.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "AccessibleComponent_i.c" |
michael@0 | 11 | |
michael@0 | 12 | #include "AccessibleWrap.h" |
michael@0 | 13 | #include "States.h" |
michael@0 | 14 | #include "IUnknownImpl.h" |
michael@0 | 15 | |
michael@0 | 16 | #include "nsIFrame.h" |
michael@0 | 17 | |
michael@0 | 18 | using namespace mozilla::a11y; |
michael@0 | 19 | |
michael@0 | 20 | // IUnknown |
michael@0 | 21 | |
michael@0 | 22 | STDMETHODIMP |
michael@0 | 23 | ia2AccessibleComponent::QueryInterface(REFIID iid, void** ppv) |
michael@0 | 24 | { |
michael@0 | 25 | if (!ppv) |
michael@0 | 26 | return E_INVALIDARG; |
michael@0 | 27 | |
michael@0 | 28 | *ppv = nullptr; |
michael@0 | 29 | |
michael@0 | 30 | if (IID_IAccessibleComponent == iid) { |
michael@0 | 31 | *ppv = static_cast<IAccessibleComponent*>(this); |
michael@0 | 32 | (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); |
michael@0 | 33 | return S_OK; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | return E_NOINTERFACE; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | // IAccessibleComponent |
michael@0 | 40 | |
michael@0 | 41 | STDMETHODIMP |
michael@0 | 42 | ia2AccessibleComponent::get_locationInParent(long* aX, long* aY) |
michael@0 | 43 | { |
michael@0 | 44 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 45 | |
michael@0 | 46 | if (!aX || !aY) |
michael@0 | 47 | return E_INVALIDARG; |
michael@0 | 48 | |
michael@0 | 49 | *aX = 0; |
michael@0 | 50 | *aY = 0; |
michael@0 | 51 | |
michael@0 | 52 | AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); |
michael@0 | 53 | if (acc->IsDefunct()) |
michael@0 | 54 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 55 | |
michael@0 | 56 | // If the object is not on any screen the returned position is (0,0). |
michael@0 | 57 | uint64_t state = acc->State(); |
michael@0 | 58 | if (state & states::INVISIBLE) |
michael@0 | 59 | return S_OK; |
michael@0 | 60 | |
michael@0 | 61 | int32_t x = 0, y = 0, width = 0, height = 0; |
michael@0 | 62 | nsresult rv = acc->GetBounds(&x, &y, &width, &height); |
michael@0 | 63 | if (NS_FAILED(rv)) |
michael@0 | 64 | return GetHRESULT(rv); |
michael@0 | 65 | |
michael@0 | 66 | Accessible* parentAcc = acc->Parent(); |
michael@0 | 67 | |
michael@0 | 68 | // The coordinates of the returned position are relative to this object's |
michael@0 | 69 | // parent or relative to the screen on which this object is rendered if it |
michael@0 | 70 | // has no parent. |
michael@0 | 71 | if (!parentAcc) { |
michael@0 | 72 | *aX = x; |
michael@0 | 73 | *aY = y; |
michael@0 | 74 | return S_OK; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | // The coordinates of the bounding box are given relative to the parent's |
michael@0 | 78 | // coordinate system. |
michael@0 | 79 | int32_t parentx = 0, parenty = 0; |
michael@0 | 80 | rv = acc->GetBounds(&parentx, &parenty, &width, &height); |
michael@0 | 81 | if (NS_FAILED(rv)) |
michael@0 | 82 | return GetHRESULT(rv); |
michael@0 | 83 | |
michael@0 | 84 | *aX = x - parentx; |
michael@0 | 85 | *aY = y - parenty; |
michael@0 | 86 | return S_OK; |
michael@0 | 87 | |
michael@0 | 88 | A11Y_TRYBLOCK_END |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | STDMETHODIMP |
michael@0 | 92 | ia2AccessibleComponent::get_foreground(IA2Color* aForeground) |
michael@0 | 93 | { |
michael@0 | 94 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 95 | |
michael@0 | 96 | if (!aForeground) |
michael@0 | 97 | return E_INVALIDARG; |
michael@0 | 98 | |
michael@0 | 99 | *aForeground = 0; |
michael@0 | 100 | |
michael@0 | 101 | AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); |
michael@0 | 102 | if (acc->IsDefunct()) |
michael@0 | 103 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 104 | |
michael@0 | 105 | nsIFrame* frame = acc->GetFrame(); |
michael@0 | 106 | if (frame) |
michael@0 | 107 | *aForeground = frame->StyleColor()->mColor; |
michael@0 | 108 | |
michael@0 | 109 | return S_OK; |
michael@0 | 110 | |
michael@0 | 111 | A11Y_TRYBLOCK_END |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | STDMETHODIMP |
michael@0 | 115 | ia2AccessibleComponent::get_background(IA2Color* aBackground) |
michael@0 | 116 | { |
michael@0 | 117 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 118 | |
michael@0 | 119 | if (!aBackground) |
michael@0 | 120 | return E_INVALIDARG; |
michael@0 | 121 | |
michael@0 | 122 | *aBackground = 0; |
michael@0 | 123 | |
michael@0 | 124 | AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); |
michael@0 | 125 | if (acc->IsDefunct()) |
michael@0 | 126 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 127 | |
michael@0 | 128 | nsIFrame* frame = acc->GetFrame(); |
michael@0 | 129 | if (frame) |
michael@0 | 130 | *aBackground = frame->StyleBackground()->mBackgroundColor; |
michael@0 | 131 | |
michael@0 | 132 | return S_OK; |
michael@0 | 133 | |
michael@0 | 134 | A11Y_TRYBLOCK_END |
michael@0 | 135 | } |
michael@0 | 136 |