summaryrefslogtreecommitdiffstats
path: root/WebCore/dom/CharacterData.cpp
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
commit1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch)
tree4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /WebCore/dom/CharacterData.cpp
parent9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff)
downloadexternal_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'WebCore/dom/CharacterData.cpp')
-rw-r--r--WebCore/dom/CharacterData.cpp113
1 files changed, 39 insertions, 74 deletions
diff --git a/WebCore/dom/CharacterData.cpp b/WebCore/dom/CharacterData.cpp
index d525650..247a5b6 100644
--- a/WebCore/dom/CharacterData.cpp
+++ b/WebCore/dom/CharacterData.cpp
@@ -26,42 +26,36 @@
#include "Document.h"
#include "EventNames.h"
#include "ExceptionCode.h"
-#include "TextStream.h"
#include "MutationEvent.h"
#include "RenderText.h"
namespace WebCore {
-using namespace EventNames;
-
CharacterData::CharacterData(Document *doc)
: EventTargetNode(doc)
+ , m_data(StringImpl::empty())
{
}
-CharacterData::CharacterData(Document *doc, const String &_text)
- : EventTargetNode(doc)
+CharacterData::CharacterData(Document* document, const String& text)
+ : EventTargetNode(document)
{
- m_data = _text.impl() ? _text.impl() : StringImpl::empty();
+ m_data = text.impl() ? text.impl() : StringImpl::empty();
}
CharacterData::~CharacterData()
{
}
-void CharacterData::setData(const String& data, ExceptionCode& ec)
+void CharacterData::setData(const String& data, ExceptionCode&)
{
- // NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly
- if (isReadOnlyNode()) {
- ec = NO_MODIFICATION_ALLOWED_ERR;
- return;
- }
-
- if (equal(m_data.get(), data.impl()))
+ 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 = data.impl();
+ m_data = dataImpl;
if ((!renderer() || !rendererIsNeeded(renderer()->style())) && attached()) {
detach();
@@ -71,12 +65,11 @@ void CharacterData::setData(const String& data, ExceptionCode& ec)
dispatchModifiedEvent(oldStr.get());
- document()->removeMarkers(this);
+ document()->textRemoved(this, 0, oldLength);
}
-String CharacterData::substringData( const unsigned offset, const unsigned count, ExceptionCode& ec)
+String CharacterData::substringData(unsigned offset, unsigned count, ExceptionCode& ec)
{
- ec = 0;
checkCharDataOperation(offset, ec);
if (ec)
return String();
@@ -84,16 +77,8 @@ String CharacterData::substringData( const unsigned offset, const unsigned count
return m_data->substring(offset, count);
}
-void CharacterData::appendData( const String &arg, ExceptionCode& ec)
+void CharacterData::appendData(const String& arg, ExceptionCode&)
{
- ec = 0;
-
- // NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly
- if (isReadOnlyNode()) {
- ec = NO_MODIFICATION_ALLOWED_ERR;
- return;
- }
-
String newStr = m_data;
newStr.append(arg);
@@ -109,9 +94,8 @@ void CharacterData::appendData( const String &arg, ExceptionCode& ec)
dispatchModifiedEvent(oldStr.get());
}
-void CharacterData::insertData( const unsigned offset, const String &arg, ExceptionCode& ec)
+void CharacterData::insertData(unsigned offset, const String& arg, ExceptionCode& ec)
{
- ec = 0;
checkCharDataOperation(offset, ec);
if (ec)
return;
@@ -127,23 +111,26 @@ void CharacterData::insertData( const unsigned offset, const String &arg, Except
attach();
} else if (renderer())
static_cast<RenderText*>(renderer())->setTextWithOffset(m_data, offset, 0);
-
+
dispatchModifiedEvent(oldStr.get());
- // update the markers for spell checking and grammar checking
- unsigned length = arg.length();
- document()->shiftMarkers(this, offset, length);
+ document()->textInserted(this, offset, arg.length());
}
-void CharacterData::deleteData( const unsigned offset, const unsigned count, ExceptionCode& ec)
+void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionCode& ec)
{
- ec = 0;
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, count);
+ newStr.remove(offset, realCount);
RefPtr<StringImpl> oldStr = m_data;
m_data = newStr.impl();
@@ -156,21 +143,18 @@ void CharacterData::deleteData( const unsigned offset, const unsigned count, Exc
dispatchModifiedEvent(oldStr.get());
- // update the markers for spell checking and grammar checking
- document()->removeMarkers(this, offset, count);
- document()->shiftMarkers(this, offset + count, -static_cast<int>(count));
+ document()->textRemoved(this, offset, realCount);
}
-void CharacterData::replaceData( const unsigned offset, const unsigned count, const String &arg, ExceptionCode& ec)
+void CharacterData::replaceData(unsigned offset, unsigned count, const String& arg, ExceptionCode& ec)
{
- ec = 0;
checkCharDataOperation(offset, ec);
if (ec)
return;
unsigned realCount;
- if (offset + count > m_data->length())
- realCount = m_data->length()-offset;
+ if (offset + count > length())
+ realCount = length() - offset;
else
realCount = count;
@@ -190,9 +174,8 @@ void CharacterData::replaceData( const unsigned offset, const unsigned count, co
dispatchModifiedEvent(oldStr.get());
// update the markers for spell checking and grammar checking
- int diff = arg.length() - count;
- document()->removeMarkers(this, offset, count);
- document()->shiftMarkers(this, offset + count, diff);
+ document()->textRemoved(this, offset, realCount);
+ document()->textInserted(this, offset, arg.length());
}
String CharacterData::nodeValue() const
@@ -202,54 +185,45 @@ String CharacterData::nodeValue() const
bool CharacterData::containsOnlyWhitespace() const
{
- if (m_data)
- return m_data->containsOnlyWhitespace();
- return true;
+ return !m_data || m_data->containsOnlyWhitespace();
}
-void CharacterData::setNodeValue( const String &_nodeValue, ExceptionCode& ec)
+void CharacterData::setNodeValue(const String& nodeValue, ExceptionCode& ec)
{
- // NO_MODIFICATION_ALLOWED_ERR: taken care of by setData()
- setData(_nodeValue, ec);
+ setData(nodeValue, ec);
}
-void CharacterData::dispatchModifiedEvent(StringImpl *prevValue)
+void CharacterData::dispatchModifiedEvent(StringImpl* prevValue)
{
if (parentNode())
parentNode()->childrenChanged();
if (document()->hasListenerType(Document::DOMCHARACTERDATAMODIFIED_LISTENER)) {
ExceptionCode ec;
- dispatchEvent(new MutationEvent(DOMCharacterDataModifiedEvent, true, false, 0, prevValue, m_data, String(), 0), ec);
+ dispatchEvent(MutationEvent::create(eventNames().DOMCharacterDataModifiedEvent, true, false, 0, prevValue, m_data, String(), 0), ec);
}
dispatchSubtreeModifiedEvent();
}
-void CharacterData::checkCharDataOperation( const unsigned offset, ExceptionCode& ec)
+void CharacterData::checkCharDataOperation(unsigned offset, ExceptionCode& ec)
{
ec = 0;
// INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of 16-bit
// units in data.
- if (offset > m_data->length()) {
+ if (offset > length()) {
ec = INDEX_SIZE_ERR;
return;
}
-
- // NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly
- if (isReadOnlyNode()) {
- ec = NO_MODIFICATION_ALLOWED_ERR;
- return;
- }
}
-int CharacterData::maxCharacterOffset() const
+int CharacterData::maxCharacterOffset() const
{
- return (int)length();
+ return static_cast<int>(length());
}
bool CharacterData::rendererIsNeeded(RenderStyle *style)
{
- if (!m_data || m_data->length() == 0)
+ if (!m_data || !length())
return false;
return EventTargetNode::rendererIsNeeded(style);
}
@@ -259,13 +233,4 @@ bool CharacterData::offsetInCharacters() const
return true;
}
-#ifndef NDEBUG
-void CharacterData::dump(TextStream *stream, DeprecatedString ind) const
-{
- *stream << " m_data=\"" << String(m_data).utf8().data() << "\"";
-
- EventTargetNode::dump(stream, ind);
-}
-#endif
-
} // namespace WebCore