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