void CharacterData::replaceData(unsigned offset, unsigned count, const String& arg, ExceptionCode& ec) { checkCharDataOperation(offset, ec); if (ec) return; unsigned realCount; if (offset + count > length()) realCount = length() - offset; else realCount = count; String newStr = m_data; newStr.remove(offset, realCount); newStr.insert(arg, offset); RefPtr<StringImpl> oldStr = m_data; m_data = newStr.impl(); if ((!renderer() || !rendererIsNeeded(renderer()->style())) && attached()) { detach(); attach(); } else if (renderer()) static_cast<RenderText*>(renderer())->setTextWithOffset(m_data, offset, count); dispatchModifiedEvent(oldStr.get()); // update the markers for spell checking and grammar checking document()->textRemoved(this, offset, realCount); document()->textInserted(this, offset, arg.length()); }
void CharacterData::updateRenderer(unsigned offsetOfReplacedData, unsigned lengthOfReplacedData) { if ((!renderer() || !rendererIsNeeded(NodeRenderingContext(this, renderer()->style()))) && attached()) reattach(); else if (renderer()) toRenderText(renderer())->setTextWithOffset(m_data.impl(), offsetOfReplacedData, lengthOfReplacedData); }
void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionCode& ec) { checkCharDataOperation(offset, ec); if (ec) return; unsigned realCount; if (offset + count > length()) realCount = length() - offset; else realCount = count; String newStr = m_data; newStr.remove(offset, realCount); RefPtr<StringImpl> oldStr = m_data; m_data = newStr.impl(); if ((!renderer() || !rendererIsNeeded(renderer()->style())) && attached()) { detach(); attach(); } else if (renderer()) static_cast<RenderText*>(renderer())->setTextWithOffset(m_data, offset, count); dispatchModifiedEvent(oldStr.get()); document()->textRemoved(this, offset, realCount); }
void CharacterData::updateRenderer(unsigned offsetOfReplacedData, unsigned lengthOfReplacedData) { if ((!renderer() || !rendererIsNeeded(renderer()->style())) && attached()) { detach(); attach(); } else if (renderer()) toRenderText(renderer())->setTextWithOffset(m_data, offsetOfReplacedData, lengthOfReplacedData); }
void CharacterData::appendData(const String& arg, ExceptionCode&) { String newStr = m_data; newStr.append(arg); RefPtr<StringImpl> oldStr = m_data; m_data = newStr.impl(); if ((!renderer() || !rendererIsNeeded(renderer()->style())) && attached()) { detach(); attach(); } else if (renderer()) static_cast<RenderText*>(renderer())->setTextWithOffset(m_data, oldStr->length(), 0); dispatchModifiedEvent(oldStr.get()); }
void CharacterData::setData(const String& data, ExceptionCode&) { StringImpl* dataImpl = data.impl() ? data.impl() : StringImpl::empty(); if (equal(m_data.get(), dataImpl)) return; int oldLength = length(); RefPtr<StringImpl> oldStr = m_data; m_data = dataImpl; if ((!renderer() || !rendererIsNeeded(renderer()->style())) && attached()) { detach(); attach(); } else if (renderer()) static_cast<RenderText*>(renderer())->setText(m_data); dispatchModifiedEvent(oldStr.get()); document()->textRemoved(this, 0, oldLength); }
void CharacterData::insertData(unsigned offset, const String& arg, ExceptionCode& ec) { checkCharDataOperation(offset, ec); if (ec) return; String newStr = m_data; newStr.insert(arg, offset); RefPtr<StringImpl> oldStr = m_data; m_data = newStr.impl(); if ((!renderer() || !rendererIsNeeded(renderer()->style())) && attached()) { detach(); attach(); } else if (renderer()) static_cast<RenderText*>(renderer())->setTextWithOffset(m_data, offset, 0); dispatchModifiedEvent(oldStr.get()); document()->textInserted(this, offset, arg.length()); }