tor-browser

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

FormControlAccessible.cpp (2684B)


      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 // NOTE: alphabetically ordered
      7 
      8 #include "FormControlAccessible.h"
      9 
     10 #include "mozilla/dom/HTMLInputElement.h"
     11 #include "mozilla/a11y/Role.h"
     12 
     13 using namespace mozilla::a11y;
     14 
     15 ////////////////////////////////////////////////////////////////////////////////
     16 // CheckboxAccessible
     17 ////////////////////////////////////////////////////////////////////////////////
     18 
     19 role CheckboxAccessible::NativeRole() const { return roles::CHECKBUTTON; }
     20 
     21 void CheckboxAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) {
     22  if (aIndex == eAction_Click) {
     23    uint64_t state = NativeState();
     24    if (state & states::CHECKED) {
     25      aName.AssignLiteral("uncheck");
     26    } else if (state & states::MIXED) {
     27      aName.AssignLiteral("cycle");
     28    } else {
     29      aName.AssignLiteral("check");
     30    }
     31  }
     32 }
     33 
     34 bool CheckboxAccessible::HasPrimaryAction() const { return true; }
     35 
     36 uint64_t CheckboxAccessible::NativeState() const {
     37  uint64_t state = LeafAccessible::NativeState();
     38 
     39  state |= states::CHECKABLE;
     40  dom::HTMLInputElement* input = dom::HTMLInputElement::FromNode(mContent);
     41  if (input) {  // HTML:input@type="checkbox"
     42    if (input->Indeterminate()) {
     43      return state | states::MIXED;
     44    }
     45 
     46    if (input->Checked()) {
     47      return state | states::CHECKED;
     48    }
     49 
     50  } else if (mContent->AsElement()->GetBoolAttr(nsGkAtoms::checked)) {
     51    return state | states::CHECKED;
     52  }
     53 
     54  return state;
     55 }
     56 
     57 ////////////////////////////////////////////////////////////////////////////////
     58 // CheckboxAccessible: Widgets
     59 
     60 bool CheckboxAccessible::IsWidget() const { return true; }
     61 
     62 ////////////////////////////////////////////////////////////////////////////////
     63 // RadioButtonAccessible
     64 ////////////////////////////////////////////////////////////////////////////////
     65 
     66 RadioButtonAccessible::RadioButtonAccessible(nsIContent* aContent,
     67                                             DocAccessible* aDoc)
     68    : LeafAccessible(aContent, aDoc) {}
     69 
     70 bool RadioButtonAccessible::HasPrimaryAction() const { return true; }
     71 
     72 void RadioButtonAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) {
     73  if (aIndex == eAction_Click) aName.AssignLiteral("select");
     74 }
     75 
     76 role RadioButtonAccessible::NativeRole() const { return roles::RADIOBUTTON; }
     77 
     78 ////////////////////////////////////////////////////////////////////////////////
     79 // RadioButtonAccessible: Widgets
     80 
     81 bool RadioButtonAccessible::IsWidget() const { return true; }