PassRefPtr<Text> Text::splitText(unsigned offset, ExceptionCode& ec) { ec = 0; if (this->parent()) {if (!RO_check(this->parent())) return 0;} // INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than // the number of 16-bit units in data. if (offset > length()) { ec = INDEX_SIZE_ERR; return 0; } RefPtr<StringImpl> oldStr = dataImpl(); RefPtr<Text> newText = virtualCreate(oldStr->substring(offset)); setDataImpl(oldStr->substring(0, offset)); dispatchModifiedEvent(oldStr.get()); if (parentNode()) parentNode()->insertBefore(newText.get(), nextSibling(), ec); if (ec) return 0; if (parentNode()) document()->textNodeSplit(this); if (renderer()) toRenderText(renderer())->setTextWithOffset(dataImpl(), 0, oldStr->length()); return newText.release(); }
PassRefPtr<Text> Text::replaceWholeText(const String& newText, ExceptionCode&) { // Remove all adjacent text nodes, and replace the contents of this one. if (this->parent()) {if (!RO_check(this->parent())) return 0;} // Protect startText and endText against mutation event handlers removing the last ref RefPtr<Text> startText = const_cast<Text*>(earliestLogicallyAdjacentTextNode(this)); RefPtr<Text> endText = const_cast<Text*>(latestLogicallyAdjacentTextNode(this)); RefPtr<Text> protectedThis(this); // Mutation event handlers could cause our last ref to go away Node* parent = parentNode(); // Protect against mutation handlers moving this node during traversal ExceptionCode ignored = 0; for (RefPtr<Node> n = startText; n && n != this && n->isTextNode() && n->parentNode() == parent;) { RefPtr<Node> nodeToRemove(n.release()); n = nodeToRemove->nextSibling(); parent->removeChild(nodeToRemove.get(), ignored); } if (this != endText) { Node* onePastEndText = endText->nextSibling(); for (RefPtr<Node> n = nextSibling(); n && n != onePastEndText && n->isTextNode() && n->parentNode() == parent;) { RefPtr<Node> nodeToRemove(n.release()); n = nodeToRemove->nextSibling(); parent->removeChild(nodeToRemove.get(), ignored); } } if (newText.isEmpty()) { if (parent && parentNode() == parent) parent->removeChild(this, ignored); return 0; } setData(newText, ignored); return protectedThis.release(); }
void HTMLOptionElement::setSelected(bool selected) { if (!RO_check(this)) return; if (m_data.selected() == selected) return; OptionElement::setSelectedState(m_data, this, selected); if (HTMLSelectElement* select = ownerSelectElement()) select->setSelectedIndex(selected ? index() : -1, false); }
void HTMLOptionElement::setText(const String &text, ExceptionCode& ec) { if (!RO_check(this)) return; // Handle the common special case where there's exactly 1 child node, and it's a text node. Node* child = firstChild(); if (child && child->isTextNode() && !child->nextSibling()) { static_cast<Text *>(child)->setData(text, ec); return; } removeChildren(); appendChild(Text::create(document(), text), ec); }