tor-browser

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

TextLeafAccessible.cpp (1479B)


      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 "TextLeafAccessible.h"
      7 
      8 #include "mozilla/a11y/Role.h"
      9 #include "nsCoreUtils.h"
     10 
     11 using namespace mozilla::a11y;
     12 
     13 ////////////////////////////////////////////////////////////////////////////////
     14 // TextLeafAccessible
     15 ////////////////////////////////////////////////////////////////////////////////
     16 
     17 TextLeafAccessible::TextLeafAccessible(nsIContent* aContent,
     18                                       DocAccessible* aDoc)
     19    : LinkableAccessible(aContent, aDoc) {
     20  mType = eTextLeafType;
     21  mGenericTypes |= eText;
     22  mStateFlags |= eNoKidsFromDOM;
     23 }
     24 
     25 TextLeafAccessible::~TextLeafAccessible() {}
     26 
     27 role TextLeafAccessible::NativeRole() const {
     28  nsIFrame* frame = GetFrame();
     29  if ((frame && frame->IsGeneratedContentFrame()) ||
     30      nsCoreUtils::IsPseudoElement(GetContent())) {
     31    return roles::STATICTEXT;
     32  }
     33 
     34  return roles::TEXT_LEAF;
     35 }
     36 
     37 void TextLeafAccessible::AppendTextTo(nsAString& aText, uint32_t aStartOffset,
     38                                      uint32_t aLength) {
     39  aText.Append(Substring(mText, aStartOffset, aLength));
     40 }
     41 
     42 ENameValueFlag TextLeafAccessible::DirectName(nsString& aName) const {
     43  // Text node, ARIA can't be used.
     44  aName = mText;
     45  return eNameOK;
     46 }