This source file includes following definitions.
- getOrCreate
- willDestroy
- detach
- nextInlineTextBox
- bounds
- start
- len
- direction
- characterWidths
- wordBoundaries
- text
#include "config.h"
#include "core/rendering/AbstractInlineTextBox.h"
#include "core/editing/TextIterator.h"
#include "platform/text/TextBreakIterator.h"
namespace WebCore {
AbstractInlineTextBox::InlineToAbstractInlineTextBoxHashMap* AbstractInlineTextBox::gAbstractInlineTextBoxMap = 0;
PassRefPtr<AbstractInlineTextBox> AbstractInlineTextBox::getOrCreate(RenderText* renderText, InlineTextBox* inlineTextBox)
{
if (!inlineTextBox)
return nullptr;
if (!gAbstractInlineTextBoxMap)
gAbstractInlineTextBoxMap = new InlineToAbstractInlineTextBoxHashMap();
InlineToAbstractInlineTextBoxHashMap::const_iterator it = gAbstractInlineTextBoxMap->find(inlineTextBox);
if (it != gAbstractInlineTextBoxMap->end())
return it->value;
RefPtr<AbstractInlineTextBox> obj = adoptRef(new AbstractInlineTextBox(renderText, inlineTextBox));
gAbstractInlineTextBoxMap->set(inlineTextBox, obj);
return obj;
}
void AbstractInlineTextBox::willDestroy(InlineTextBox* inlineTextBox)
{
if (!gAbstractInlineTextBoxMap)
return;
InlineToAbstractInlineTextBoxHashMap::const_iterator it = gAbstractInlineTextBoxMap->find(inlineTextBox);
if (it != gAbstractInlineTextBoxMap->end()) {
it->value->detach();
gAbstractInlineTextBoxMap->remove(inlineTextBox);
}
}
void AbstractInlineTextBox::detach()
{
m_renderText = 0;
m_inlineTextBox = 0;
}
PassRefPtr<AbstractInlineTextBox> AbstractInlineTextBox::nextInlineTextBox() const
{
if (!m_inlineTextBox)
return nullptr;
return getOrCreate(m_renderText, m_inlineTextBox->nextTextBox());
}
LayoutRect AbstractInlineTextBox::bounds() const
{
if (!m_inlineTextBox || !m_renderText)
return LayoutRect();
FloatRect boundaries = m_inlineTextBox->calculateBoundaries();
return m_renderText->localToAbsoluteQuad(boundaries).enclosingBoundingBox();
}
unsigned AbstractInlineTextBox::start() const
{
if (!m_inlineTextBox)
return 0;
return m_inlineTextBox->start();
}
unsigned AbstractInlineTextBox::len() const
{
if (!m_inlineTextBox)
return 0;
return m_inlineTextBox->len();
}
AbstractInlineTextBox::Direction AbstractInlineTextBox::direction() const
{
if (!m_inlineTextBox || !m_renderText)
return LeftToRight;
if (m_renderText->style()->isHorizontalWritingMode())
return (m_inlineTextBox->direction() == RTL ? RightToLeft : LeftToRight);
return (m_inlineTextBox->direction() == RTL ? BottomToTop : TopToBottom);
}
void AbstractInlineTextBox::characterWidths(Vector<float>& widths) const
{
if (!m_inlineTextBox)
return;
m_inlineTextBox->characterWidths(widths);
}
void AbstractInlineTextBox::wordBoundaries(Vector<WordBoundaries>& words) const
{
if (!m_inlineTextBox)
return;
String text = this->text();
int len = text.length();
TextBreakIterator* iterator = wordBreakIterator(text, 0, len);
int pos = iterator->first();
while (pos >= 0 && pos < len) {
int next = iterator->next();
if (isWordTextBreak(iterator))
words.append(WordBoundaries(pos, next));
pos = next;
}
}
String AbstractInlineTextBox::text() const
{
if (!m_inlineTextBox || !m_renderText)
return String();
unsigned start = m_inlineTextBox->start();
unsigned len = m_inlineTextBox->len();
if (Node* node = m_renderText->node()) {
RefPtrWillBeRawPtr<Range> range = Range::create(node->document());
range->setStart(node, start, IGNORE_EXCEPTION);
range->setEnd(node, start + len, IGNORE_EXCEPTION);
return plainText(range.get(), TextIteratorIgnoresStyleVisibility);
}
String result = m_renderText->text().substring(start, len).simplifyWhiteSpace(WTF::DoNotStripWhiteSpace);
if (m_inlineTextBox->nextTextBox() && m_inlineTextBox->nextTextBox()->start() > m_inlineTextBox->end() && result.length() && !result.right(1).containsOnlyWhitespace())
return result + " ";
return result;
}
}