static inline void appendContextSubtargetsForNode(Node* node, SubtargetGeometryList& subtargets) { // This is a variant of appendBasicSubtargetsForNode that adds special subtargets for // selected or auto-selectable parts of text nodes. ASSERT(node->renderer()); if (!node->isTextNode()) return appendBasicSubtargetsForNode(node, subtargets); Text* textNode = static_cast<WebCore::Text*>(node); RenderText* textRenderer = static_cast<RenderText*>(textNode->renderer()); if (textRenderer->frame()->editor()->behavior().shouldSelectOnContextualMenuClick()) { // Make subtargets out of every word. String textValue = textNode->data(); TextBreakIterator* wordIterator = wordBreakIterator(textValue.characters(), textValue.length()); int lastOffset = textBreakFirst(wordIterator); if (lastOffset == -1) return; int offset; while ((offset = textBreakNext(wordIterator)) != -1) { if (isWordTextBreak(wordIterator)) { Vector<FloatQuad> quads; textRenderer->absoluteQuadsForRange(quads, lastOffset, offset); appendQuadsToSubtargetList(quads, textNode, subtargets); } lastOffset = offset; } } else { if (textRenderer->selectionState() == RenderObject::SelectionNone) return appendBasicSubtargetsForNode(node, subtargets); // If selected, make subtargets out of only the selected part of the text. int startPos, endPos; switch (textRenderer->selectionState()) { case RenderObject::SelectionInside: startPos = 0; endPos = textRenderer->textLength(); break; case RenderObject::SelectionStart: textRenderer->selectionStartEnd(startPos, endPos); endPos = textRenderer->textLength(); break; case RenderObject::SelectionEnd: textRenderer->selectionStartEnd(startPos, endPos); startPos = 0; break; case RenderObject::SelectionBoth: textRenderer->selectionStartEnd(startPos, endPos); break; default: ASSERT_NOT_REACHED(); return; } Vector<FloatQuad> quads; textRenderer->absoluteQuadsForRange(quads, startPos, endPos); appendQuadsToSubtargetList(quads, textNode, subtargets); } }
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); // FIXME: When http://crbug.com/411764 is fixed, replace this with an ASSERT. if (!iterator) return; int pos = iterator->first(); while (pos >= 0 && pos < len) { int next = iterator->next(); if (isWordTextBreak(iterator)) words.append(WordBoundaries(pos, next)); pos = next; } }