tor-browser

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

EnumVariant.cpp (2396B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "EnumVariant.h"
      8 
      9 using namespace mozilla;
     10 using namespace mozilla::a11y;
     11 
     12 ////////////////////////////////////////////////////////////////////////////////
     13 // ChildrenEnumVariant
     14 ////////////////////////////////////////////////////////////////////////////////
     15 
     16 IMPL_IUNKNOWN_QUERY_HEAD(ChildrenEnumVariant)
     17 IMPL_IUNKNOWN_QUERY_IFACE(IEnumVARIANT)
     18 IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mAnchorMsaa)
     19 
     20 STDMETHODIMP
     21 ChildrenEnumVariant::Next(ULONG aCount, VARIANT FAR* aItems,
     22                          ULONG FAR* aCountFetched) {
     23  if (!aItems || !aCountFetched) return E_INVALIDARG;
     24 
     25  *aCountFetched = 0;
     26 
     27  Accessible* anchor = mAnchorMsaa->Acc();
     28  if (!anchor || anchor->ChildAt(mCurIndex) != mCurAcc) {
     29    return CO_E_OBJNOTCONNECTED;
     30  }
     31 
     32  ULONG countFetched = 0;
     33  while (mCurAcc && countFetched < aCount) {
     34    VariantInit(aItems + countFetched);
     35 
     36    IDispatch* accNative = MsaaAccessible::NativeAccessible(mCurAcc);
     37 
     38    ++mCurIndex;
     39    mCurAcc = anchor->ChildAt(mCurIndex);
     40 
     41    // Don't output the accessible and count it as having been fetched unless
     42    // it is non-null
     43    MOZ_ASSERT(accNative);
     44    if (!accNative) {
     45      continue;
     46    }
     47 
     48    aItems[countFetched].pdispVal = accNative;
     49    aItems[countFetched].vt = VT_DISPATCH;
     50    ++countFetched;
     51  }
     52 
     53  (*aCountFetched) = countFetched;
     54 
     55  return countFetched < aCount ? S_FALSE : S_OK;
     56 }
     57 
     58 STDMETHODIMP
     59 ChildrenEnumVariant::Skip(ULONG aCount) {
     60  Accessible* anchor = mAnchorMsaa->Acc();
     61  if (!anchor || anchor->ChildAt(mCurIndex) != mCurAcc) {
     62    return CO_E_OBJNOTCONNECTED;
     63  }
     64 
     65  mCurIndex += aCount;
     66  mCurAcc = anchor->ChildAt(mCurIndex);
     67 
     68  return mCurAcc ? S_OK : S_FALSE;
     69 }
     70 
     71 STDMETHODIMP
     72 ChildrenEnumVariant::Reset() {
     73  Accessible* anchor = mAnchorMsaa->Acc();
     74  if (!anchor) return CO_E_OBJNOTCONNECTED;
     75 
     76  mCurIndex = 0;
     77  mCurAcc = anchor->ChildAt(0);
     78 
     79  return S_OK;
     80 }
     81 
     82 STDMETHODIMP
     83 ChildrenEnumVariant::Clone(IEnumVARIANT** aEnumVariant) {
     84  if (!aEnumVariant) return E_INVALIDARG;
     85 
     86  *aEnumVariant = new ChildrenEnumVariant(*this);
     87  (*aEnumVariant)->AddRef();
     88 
     89  return S_OK;
     90 }