accessible/android/RootAccessibleWrap.cpp
author Karl Tomlinson <karlt+@karlt.net>
Mon, 07 Jan 2019 08:51:31 +0000
changeset 506591 39fe709c6cf8de41c2a739ad456877eb5fa1e7c3
parent 505471 66eb1f485c1a3ea81372758bc92292c9428b17cd
child 509549 f0a91d36587266d7454a450c6044d573664fbed5
permissions -rw-r--r--
Bug 1512737 - Assign HRTF to panningModel attribute instead of adding type property. r=padenot, a=test-only Differential Revision: https://phabricator.services.mozilla.com/D14494

/* -*- Mode: c++; c-basic-offset: 2; tab-width: 20; indent-tabs-mode: nil; -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "RootAccessibleWrap.h"

#include "Accessible-inl.h"
#include "AccessibleOrProxy.h"
#include "DocAccessibleParent.h"
#include "ProxyAccessibleWrap.h"
#include "SessionAccessibility.h"

using namespace mozilla::a11y;

RootAccessibleWrap::RootAccessibleWrap(nsIDocument* aDoc,
                                       nsIPresShell* aPresShell)
    : RootAccessible(aDoc, aPresShell) {}

RootAccessibleWrap::~RootAccessibleWrap() {}

AccessibleWrap* RootAccessibleWrap::GetContentAccessible() {
  if (ProxyAccessible* proxy = GetPrimaryRemoteTopLevelContentDoc()) {
    return WrapperFor(proxy);
  }

  // Find first document that is not defunct or hidden.
  // This is exclusively for Fennec which has a deck of browser elements.
  // Otherwise, standard GeckoView will only have one browser element.
  for (size_t i = 0; i < ChildDocumentCount(); i++) {
    DocAccessible* childDoc = GetChildDocumentAt(i);
    if (childDoc && !childDoc->IsDefunct() && !childDoc->IsHidden()) {
      return childDoc;
    }
  }

  return nullptr;
}

AccessibleWrap* RootAccessibleWrap::FindAccessibleById(int32_t aID) {
  AccessibleWrap* contentAcc = GetContentAccessible();

  if (!contentAcc) {
    return nullptr;
  }

  if (aID == AccessibleWrap::kNoID) {
    return contentAcc;
  }

  if (contentAcc->IsProxy()) {
    return FindAccessibleById(static_cast<DocProxyAccessibleWrap*>(contentAcc),
                              aID);
  }

  return FindAccessibleById(
      static_cast<DocAccessibleWrap*>(contentAcc->AsDoc()), aID);
}

AccessibleWrap* RootAccessibleWrap::FindAccessibleById(
    DocProxyAccessibleWrap* aDoc, int32_t aID) {
  AccessibleWrap* acc = aDoc->GetAccessibleByID(aID);
  uint32_t index = 0;
  while (!acc) {
    auto child =
        static_cast<DocProxyAccessibleWrap*>(aDoc->GetChildDocumentAt(index++));
    if (!child) {
      break;
    }
    acc = FindAccessibleById(child, aID);
  }

  return acc;
}

AccessibleWrap* RootAccessibleWrap::FindAccessibleById(DocAccessibleWrap* aDoc,
                                                       int32_t aID) {
  AccessibleWrap* acc = aDoc->GetAccessibleByID(aID);
  uint32_t index = 0;
  while (!acc) {
    auto child =
        static_cast<DocAccessibleWrap*>(aDoc->GetChildDocumentAt(index++));
    if (!child) {
      break;
    }
    acc = FindAccessibleById(child, aID);
  }

  return acc;
}