This source file includes following definitions.
- create
- init
- detach
- elementRect
- computeAccessibilityIsIgnored
- textCharacterOffsets
- wordBoundaries
- stringValue
- parentObject
- textDirection
#include "config.h"
#include "core/accessibility/AXInlineTextBox.h"
#include "core/accessibility/AXObjectCache.h"
#include "core/dom/Range.h"
#include "core/rendering/RenderText.h"
#include "platform/LayoutUnit.h"
namespace WebCore {
using namespace HTMLNames;
AXInlineTextBox::AXInlineTextBox(PassRefPtr<AbstractInlineTextBox> inlineTextBox)
: m_inlineTextBox(inlineTextBox)
{
RenderText* renderText = m_inlineTextBox->renderText();
m_axObjectCache = renderText->document().axObjectCache();
}
AXInlineTextBox::~AXInlineTextBox()
{
if (m_axObjectCache && m_inlineTextBox)
m_axObjectCache->remove(m_inlineTextBox.get());
}
PassRefPtr<AXInlineTextBox> AXInlineTextBox::create(PassRefPtr<AbstractInlineTextBox> inlineTextBox)
{
return adoptRef(new AXInlineTextBox(inlineTextBox));
}
void AXInlineTextBox::init()
{
}
void AXInlineTextBox::detach()
{
m_inlineTextBox = nullptr;
m_axObjectCache = 0;
AXObject::detach();
}
LayoutRect AXInlineTextBox::elementRect() const
{
if (!m_inlineTextBox)
return LayoutRect();
return m_inlineTextBox->bounds();
}
bool AXInlineTextBox::computeAccessibilityIsIgnored() const
{
if (AXObject* parent = parentObject())
return parent->accessibilityIsIgnored();
return false;
}
void AXInlineTextBox::textCharacterOffsets(Vector<int>& offsets) const
{
if (!m_inlineTextBox)
return;
unsigned len = m_inlineTextBox->len();
Vector<float> widths;
m_inlineTextBox->characterWidths(widths);
ASSERT(widths.size() == len);
offsets.resize(len);
float widthSoFar = 0;
for (unsigned i = 0; i < len; i++) {
widthSoFar += widths[i];
offsets[i] = LayoutUnit::fromFloatRound(widthSoFar);
}
}
void AXInlineTextBox::wordBoundaries(Vector<PlainTextRange>& words) const
{
if (!m_inlineTextBox)
return;
Vector<AbstractInlineTextBox::WordBoundaries> wordBoundaries;
m_inlineTextBox->wordBoundaries(wordBoundaries);
words.resize(wordBoundaries.size());
for (unsigned i = 0; i < wordBoundaries.size(); i++)
words[i] = PlainTextRange(wordBoundaries[i].startIndex, wordBoundaries[i].endIndex - wordBoundaries[i].startIndex);
}
String AXInlineTextBox::stringValue() const
{
if (!m_inlineTextBox)
return String();
return m_inlineTextBox->text();
}
AXObject* AXInlineTextBox::parentObject() const
{
if (!m_inlineTextBox || !m_axObjectCache)
return 0;
RenderText* renderText = m_inlineTextBox->renderText();
return m_axObjectCache->getOrCreate(renderText);
}
AccessibilityTextDirection AXInlineTextBox::textDirection() const
{
if (!m_inlineTextBox)
return AccessibilityTextDirectionLeftToRight;
switch (m_inlineTextBox->direction()) {
case AbstractInlineTextBox::LeftToRight:
return AccessibilityTextDirectionLeftToRight;
case AbstractInlineTextBox::RightToLeft:
return AccessibilityTextDirectionRightToLeft;
case AbstractInlineTextBox::TopToBottom:
return AccessibilityTextDirectionTopToBottom;
case AbstractInlineTextBox::BottomToTop:
return AccessibilityTextDirectionBottomToTop;
}
return AccessibilityTextDirectionLeftToRight;
}
}