michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:expandtab:shiftwidth=2:tabstop=2: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "ia2AccessibleComponent.h" michael@0: michael@0: #include "AccessibleComponent_i.c" michael@0: michael@0: #include "AccessibleWrap.h" michael@0: #include "States.h" michael@0: #include "IUnknownImpl.h" michael@0: michael@0: #include "nsIFrame.h" michael@0: michael@0: using namespace mozilla::a11y; michael@0: michael@0: // IUnknown michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleComponent::QueryInterface(REFIID iid, void** ppv) michael@0: { michael@0: if (!ppv) michael@0: return E_INVALIDARG; michael@0: michael@0: *ppv = nullptr; michael@0: michael@0: if (IID_IAccessibleComponent == iid) { michael@0: *ppv = static_cast(this); michael@0: (reinterpret_cast(*ppv))->AddRef(); michael@0: return S_OK; michael@0: } michael@0: michael@0: return E_NOINTERFACE; michael@0: } michael@0: michael@0: // IAccessibleComponent michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleComponent::get_locationInParent(long* aX, long* aY) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aX || !aY) michael@0: return E_INVALIDARG; michael@0: michael@0: *aX = 0; michael@0: *aY = 0; michael@0: michael@0: AccessibleWrap* acc = static_cast(this); michael@0: if (acc->IsDefunct()) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: // If the object is not on any screen the returned position is (0,0). michael@0: uint64_t state = acc->State(); michael@0: if (state & states::INVISIBLE) michael@0: return S_OK; michael@0: michael@0: int32_t x = 0, y = 0, width = 0, height = 0; michael@0: nsresult rv = acc->GetBounds(&x, &y, &width, &height); michael@0: if (NS_FAILED(rv)) michael@0: return GetHRESULT(rv); michael@0: michael@0: Accessible* parentAcc = acc->Parent(); michael@0: michael@0: // The coordinates of the returned position are relative to this object's michael@0: // parent or relative to the screen on which this object is rendered if it michael@0: // has no parent. michael@0: if (!parentAcc) { michael@0: *aX = x; michael@0: *aY = y; michael@0: return S_OK; michael@0: } michael@0: michael@0: // The coordinates of the bounding box are given relative to the parent's michael@0: // coordinate system. michael@0: int32_t parentx = 0, parenty = 0; michael@0: rv = acc->GetBounds(&parentx, &parenty, &width, &height); michael@0: if (NS_FAILED(rv)) michael@0: return GetHRESULT(rv); michael@0: michael@0: *aX = x - parentx; michael@0: *aY = y - parenty; michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleComponent::get_foreground(IA2Color* aForeground) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aForeground) michael@0: return E_INVALIDARG; michael@0: michael@0: *aForeground = 0; michael@0: michael@0: AccessibleWrap* acc = static_cast(this); michael@0: if (acc->IsDefunct()) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: nsIFrame* frame = acc->GetFrame(); michael@0: if (frame) michael@0: *aForeground = frame->StyleColor()->mColor; michael@0: michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleComponent::get_background(IA2Color* aBackground) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aBackground) michael@0: return E_INVALIDARG; michael@0: michael@0: *aBackground = 0; michael@0: michael@0: AccessibleWrap* acc = static_cast(this); michael@0: if (acc->IsDefunct()) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: nsIFrame* frame = acc->GetFrame(); michael@0: if (frame) michael@0: *aBackground = frame->StyleBackground()->mBackgroundColor; michael@0: michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: