tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ia2AccessibleComponent.cpp (2674B)


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