tor-browser

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

DocAccessibleWrap.cpp (2729B)


      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
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "LocalAccessible-inl.h"
      8 #include "AccAttributes.h"
      9 #include "DocAccessibleChild.h"
     10 #include "DocAccessibleWrap.h"
     11 #include "nsIDocShell.h"
     12 #include "nsLayoutUtils.h"
     13 #include "nsAccessibilityService.h"
     14 #include "nsAccUtils.h"
     15 #include "Pivot.h"
     16 #include "SessionAccessibility.h"
     17 #include "TraversalRule.h"
     18 #include "mozilla/PresShell.h"
     19 
     20 using namespace mozilla;
     21 using namespace mozilla::a11y;
     22 
     23 #define UNIQUE_ID(acc)                             \
     24  !acc || (acc->IsDoc() && acc->AsDoc()->IPCDoc()) \
     25      ? 0                                          \
     26      : reinterpret_cast<uint64_t>(acc->UniqueID())
     27 
     28 ////////////////////////////////////////////////////////////////////////////////
     29 // DocAccessibleWrap
     30 ////////////////////////////////////////////////////////////////////////////////
     31 
     32 DocAccessibleWrap::DocAccessibleWrap(Document* aDocument, PresShell* aPresShell)
     33    : DocAccessible(aDocument, aPresShell) {
     34  // We need an nsINode associated with this accessible to register it with the
     35  // right SessionAccessibility instance. When the base AccessibleWrap
     36  // constructor is called we don't have one yet because null is passed as the
     37  // content node. So we do it here after a Document is associated with the
     38  // accessible.
     39  if (!IPCAccessibilityActive()) {
     40    MonitorAutoLock mal(nsAccessibilityService::GetAndroidMonitor());
     41    SessionAccessibility::RegisterAccessible(this);
     42  }
     43 }
     44 
     45 DocAccessibleWrap::~DocAccessibleWrap() {}
     46 
     47 void DocAccessibleWrap::Shutdown() {
     48  // Unregister here before disconnecting from PresShell.
     49  if (!IPCAccessibilityActive()) {
     50    MonitorAutoLock mal(nsAccessibilityService::GetAndroidMonitor());
     51    if (IsRoot()) {
     52      SessionAccessibility::UnregisterAll(PresShellPtr());
     53    } else {
     54      SessionAccessibility::UnregisterAccessible(this);
     55    }
     56  }
     57  DocAccessible::Shutdown();
     58 }
     59 
     60 DocAccessibleWrap* DocAccessibleWrap::GetTopLevelContentDoc(
     61    AccessibleWrap* aAccessible) {
     62  DocAccessibleWrap* doc =
     63      static_cast<DocAccessibleWrap*>(aAccessible->Document());
     64  while (doc && !doc->IsTopLevelContentDoc()) {
     65    doc = static_cast<DocAccessibleWrap*>(doc->ParentDocument());
     66  }
     67 
     68  return doc;
     69 }
     70 
     71 bool DocAccessibleWrap::IsTopLevelContentDoc() {
     72  DocAccessible* parentDoc = ParentDocument();
     73  return DocumentNode()->IsContentDocument() &&
     74         (!parentDoc || !parentDoc->DocumentNode()->IsContentDocument());
     75 }
     76 
     77 #undef UNIQUE_ID