tor-browser

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

HTMLListAccessible.cpp (3685B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "HTMLListAccessible.h"
      8 
      9 #include "AccAttributes.h"
     10 #include "nsAccessibilityService.h"
     11 #include "mozilla/a11y/Role.h"
     12 #include "States.h"
     13 
     14 #include "nsLayoutUtils.h"
     15 
     16 using namespace mozilla;
     17 using namespace mozilla::a11y;
     18 
     19 ////////////////////////////////////////////////////////////////////////////////
     20 // HTMLListAccessible
     21 ////////////////////////////////////////////////////////////////////////////////
     22 
     23 role HTMLListAccessible::NativeRole() const {
     24  a11y::role r = GetAccService()->MarkupRole(mContent);
     25  return r != roles::NOTHING ? r : roles::LIST;
     26 }
     27 
     28 uint64_t HTMLListAccessible::NativeState() const {
     29  return HyperTextAccessible::NativeState() | states::READONLY;
     30 }
     31 
     32 ////////////////////////////////////////////////////////////////////////////////
     33 // HTMLLIAccessible
     34 ////////////////////////////////////////////////////////////////////////////////
     35 
     36 HTMLLIAccessible::HTMLLIAccessible(nsIContent* aContent, DocAccessible* aDoc)
     37    : HyperTextAccessible(aContent, aDoc) {
     38  mType = eHTMLLiType;
     39 }
     40 
     41 role HTMLLIAccessible::NativeRole() const {
     42  a11y::role r = GetAccService()->MarkupRole(mContent);
     43  return r != roles::NOTHING ? r : roles::LISTITEM;
     44 }
     45 
     46 uint64_t HTMLLIAccessible::NativeState() const {
     47  return HyperTextAccessible::NativeState() | states::READONLY;
     48 }
     49 
     50 nsRect HTMLLIAccessible::BoundsInAppUnits() const {
     51  nsRect rect = AccessibleWrap::BoundsInAppUnits();
     52 
     53  LocalAccessible* bullet = Bullet();
     54  nsIFrame* frame = GetFrame();
     55  MOZ_ASSERT(!(bullet && !frame), "Cannot have a bullet if there is no frame");
     56 
     57  if (bullet && frame &&
     58      frame->StyleList()->mListStylePosition !=
     59          StyleListStylePosition::Inside) {
     60    nsRect bulletRect = bullet->BoundsInAppUnits();
     61    return rect.Union(bulletRect);
     62  }
     63 
     64  return rect;
     65 }
     66 
     67 LocalAccessible* HTMLLIAccessible::Bullet() const {
     68  LocalAccessible* firstChild = LocalFirstChild();
     69  if (firstChild && firstChild->NativeRole() == roles::LISTITEM_MARKER) {
     70    return firstChild;
     71  }
     72 
     73  return nullptr;
     74 }
     75 
     76 ////////////////////////////////////////////////////////////////////////////////
     77 // HTMLListBulletAccessible
     78 ////////////////////////////////////////////////////////////////////////////////
     79 HTMLListBulletAccessible::HTMLListBulletAccessible(nsIContent* aContent,
     80                                                   DocAccessible* aDoc)
     81    : LeafAccessible(aContent, aDoc) {
     82  mGenericTypes |= eText;
     83 }
     84 
     85 ////////////////////////////////////////////////////////////////////////////////
     86 // HTMLListBulletAccessible: LocalAccessible
     87 
     88 ENameValueFlag HTMLListBulletAccessible::DirectName(nsString& aName) const {
     89  nsLayoutUtils::GetMarkerSpokenText(mContent, aName);
     90  return eNameOK;
     91 }
     92 
     93 role HTMLListBulletAccessible::NativeRole() const {
     94  return roles::LISTITEM_MARKER;
     95 }
     96 
     97 uint64_t HTMLListBulletAccessible::NativeState() const {
     98  return LeafAccessible::NativeState() | states::READONLY;
     99 }
    100 
    101 already_AddRefed<AccAttributes> HTMLListBulletAccessible::NativeAttributes() {
    102  RefPtr<AccAttributes> attributes = new AccAttributes();
    103  return attributes.forget();
    104 }
    105 
    106 void HTMLListBulletAccessible::AppendTextTo(nsAString& aText,
    107                                            uint32_t aStartOffset,
    108                                            uint32_t aLength) {
    109  nsAutoString bulletText;
    110  Name(bulletText);
    111  aText.Append(Substring(bulletText, aStartOffset, aLength));
    112 }