tor-browser

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

ARIAGridAccessible.cpp (2849B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #include "ARIAGridAccessible.h"
      7 
      8 #include <stdint.h>
      9 #include "LocalAccessible-inl.h"
     10 #include "AccAttributes.h"
     11 #include "mozilla/a11y/TableAccessible.h"
     12 #include "mozilla/a11y/TableCellAccessible.h"
     13 #include "nsAccessibilityService.h"
     14 #include "nsAccUtils.h"
     15 #include "nsGkAtoms.h"
     16 #include "mozilla/a11y/Role.h"
     17 #include "States.h"
     18 
     19 using namespace mozilla;
     20 using namespace mozilla::a11y;
     21 
     22 ////////////////////////////////////////////////////////////////////////////////
     23 // ARIAGridCellAccessible
     24 ////////////////////////////////////////////////////////////////////////////////
     25 
     26 ////////////////////////////////////////////////////////////////////////////////
     27 // Constructor
     28 
     29 ARIAGridCellAccessible::ARIAGridCellAccessible(nsIContent* aContent,
     30                                               DocAccessible* aDoc)
     31    : HyperTextAccessible(aContent, aDoc) {
     32  mGenericTypes |= eTableCell;
     33 }
     34 
     35 ////////////////////////////////////////////////////////////////////////////////
     36 // LocalAccessible
     37 
     38 void ARIAGridCellAccessible::ApplyARIAState(uint64_t* aState) const {
     39  HyperTextAccessible::ApplyARIAState(aState);
     40 
     41  // Return if the gridcell has aria-selected="true".
     42  if (*aState & states::SELECTED) return;
     43 
     44  // Check aria-selected="true" on the row.
     45  LocalAccessible* row = LocalParent();
     46  if (!row || row->Role() != roles::ROW) return;
     47 
     48  nsIContent* rowContent = row->GetContent();
     49  if (nsAccUtils::HasDefinedARIAToken(rowContent, nsGkAtoms::aria_selected) &&
     50      !nsAccUtils::ARIAAttrValueIs(rowContent->AsElement(),
     51                                   nsGkAtoms::aria_selected, nsGkAtoms::_false,
     52                                   eCaseMatters)) {
     53    *aState |= states::SELECTABLE | states::SELECTED;
     54  }
     55 }
     56 
     57 already_AddRefed<AccAttributes> ARIAGridCellAccessible::NativeAttributes() {
     58  RefPtr<AccAttributes> attributes = HyperTextAccessible::NativeAttributes();
     59 
     60  // We only need to expose table-cell-index to clients. If we're in the content
     61  // process, we don't need this, so building a CachedTableAccessible is very
     62  // wasteful. This will be exposed by RemoteAccessible in the parent process
     63  // instead.
     64  if (!IPCAccessibilityActive()) {
     65    if (const TableCellAccessible* cell = AsTableCell()) {
     66      TableAccessible* table = cell->Table();
     67      const uint32_t row = cell->RowIdx();
     68      const uint32_t col = cell->ColIdx();
     69      const int32_t cellIdx = table->CellIndexAt(row, col);
     70      if (cellIdx != -1) {
     71        attributes->SetAttribute(nsGkAtoms::tableCellIndex, cellIdx);
     72      }
     73    }
     74  }
     75 
     76  return attributes.forget();
     77 }