1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/windows/ia2/ia2AccessibleComponent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,136 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:expandtab:shiftwidth=2:tabstop=2: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "ia2AccessibleComponent.h" 1.12 + 1.13 +#include "AccessibleComponent_i.c" 1.14 + 1.15 +#include "AccessibleWrap.h" 1.16 +#include "States.h" 1.17 +#include "IUnknownImpl.h" 1.18 + 1.19 +#include "nsIFrame.h" 1.20 + 1.21 +using namespace mozilla::a11y; 1.22 + 1.23 +// IUnknown 1.24 + 1.25 +STDMETHODIMP 1.26 +ia2AccessibleComponent::QueryInterface(REFIID iid, void** ppv) 1.27 +{ 1.28 + if (!ppv) 1.29 + return E_INVALIDARG; 1.30 + 1.31 + *ppv = nullptr; 1.32 + 1.33 + if (IID_IAccessibleComponent == iid) { 1.34 + *ppv = static_cast<IAccessibleComponent*>(this); 1.35 + (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); 1.36 + return S_OK; 1.37 + } 1.38 + 1.39 + return E_NOINTERFACE; 1.40 +} 1.41 + 1.42 +// IAccessibleComponent 1.43 + 1.44 +STDMETHODIMP 1.45 +ia2AccessibleComponent::get_locationInParent(long* aX, long* aY) 1.46 +{ 1.47 + A11Y_TRYBLOCK_BEGIN 1.48 + 1.49 + if (!aX || !aY) 1.50 + return E_INVALIDARG; 1.51 + 1.52 + *aX = 0; 1.53 + *aY = 0; 1.54 + 1.55 + AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); 1.56 + if (acc->IsDefunct()) 1.57 + return CO_E_OBJNOTCONNECTED; 1.58 + 1.59 + // If the object is not on any screen the returned position is (0,0). 1.60 + uint64_t state = acc->State(); 1.61 + if (state & states::INVISIBLE) 1.62 + return S_OK; 1.63 + 1.64 + int32_t x = 0, y = 0, width = 0, height = 0; 1.65 + nsresult rv = acc->GetBounds(&x, &y, &width, &height); 1.66 + if (NS_FAILED(rv)) 1.67 + return GetHRESULT(rv); 1.68 + 1.69 + Accessible* parentAcc = acc->Parent(); 1.70 + 1.71 + // The coordinates of the returned position are relative to this object's 1.72 + // parent or relative to the screen on which this object is rendered if it 1.73 + // has no parent. 1.74 + if (!parentAcc) { 1.75 + *aX = x; 1.76 + *aY = y; 1.77 + return S_OK; 1.78 + } 1.79 + 1.80 + // The coordinates of the bounding box are given relative to the parent's 1.81 + // coordinate system. 1.82 + int32_t parentx = 0, parenty = 0; 1.83 + rv = acc->GetBounds(&parentx, &parenty, &width, &height); 1.84 + if (NS_FAILED(rv)) 1.85 + return GetHRESULT(rv); 1.86 + 1.87 + *aX = x - parentx; 1.88 + *aY = y - parenty; 1.89 + return S_OK; 1.90 + 1.91 + A11Y_TRYBLOCK_END 1.92 +} 1.93 + 1.94 +STDMETHODIMP 1.95 +ia2AccessibleComponent::get_foreground(IA2Color* aForeground) 1.96 +{ 1.97 + A11Y_TRYBLOCK_BEGIN 1.98 + 1.99 + if (!aForeground) 1.100 + return E_INVALIDARG; 1.101 + 1.102 + *aForeground = 0; 1.103 + 1.104 + AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); 1.105 + if (acc->IsDefunct()) 1.106 + return CO_E_OBJNOTCONNECTED; 1.107 + 1.108 + nsIFrame* frame = acc->GetFrame(); 1.109 + if (frame) 1.110 + *aForeground = frame->StyleColor()->mColor; 1.111 + 1.112 + return S_OK; 1.113 + 1.114 + A11Y_TRYBLOCK_END 1.115 +} 1.116 + 1.117 +STDMETHODIMP 1.118 +ia2AccessibleComponent::get_background(IA2Color* aBackground) 1.119 +{ 1.120 + A11Y_TRYBLOCK_BEGIN 1.121 + 1.122 + if (!aBackground) 1.123 + return E_INVALIDARG; 1.124 + 1.125 + *aBackground = 0; 1.126 + 1.127 + AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); 1.128 + if (acc->IsDefunct()) 1.129 + return CO_E_OBJNOTCONNECTED; 1.130 + 1.131 + nsIFrame* frame = acc->GetFrame(); 1.132 + if (frame) 1.133 + *aBackground = frame->StyleBackground()->mBackgroundColor; 1.134 + 1.135 + return S_OK; 1.136 + 1.137 + A11Y_TRYBLOCK_END 1.138 +} 1.139 +