| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "core/dom/Document.h" | 26 #include "core/dom/Document.h" |
| 27 #include "core/dom/ExceptionCode.h" | 27 #include "core/dom/ExceptionCode.h" |
| 28 #include "core/dom/MutationObserverInterestGroup.h" | 28 #include "core/dom/MutationObserverInterestGroup.h" |
| 29 #include "core/dom/MutationRecord.h" | 29 #include "core/dom/MutationRecord.h" |
| 30 #include "core/dom/ProcessingInstruction.h" | 30 #include "core/dom/ProcessingInstruction.h" |
| 31 #include "core/dom/Text.h" | 31 #include "core/dom/Text.h" |
| 32 #include "core/editing/FrameSelection.h" | 32 #include "core/editing/FrameSelection.h" |
| 33 #include "core/events/MutationEvent.h" | 33 #include "core/events/MutationEvent.h" |
| 34 #include "core/events/ThreadLocalEventNames.h" | 34 #include "core/events/ThreadLocalEventNames.h" |
| 35 #include "core/inspector/InspectorInstrumentation.h" | 35 #include "core/inspector/InspectorInstrumentation.h" |
| 36 | 36 #include "wtf/CheckedArithmetic.h" |
| 37 using namespace std; | |
| 38 | 37 |
| 39 namespace WebCore { | 38 namespace WebCore { |
| 40 | 39 |
| 41 void CharacterData::atomize() | 40 void CharacterData::atomize() |
| 42 { | 41 { |
| 43 m_data = AtomicString(m_data); | 42 m_data = AtomicString(m_data); |
| 44 } | 43 } |
| 45 | 44 |
| 46 void CharacterData::setData(const String& data) | 45 void CharacterData::setData(const String& data) |
| 47 { | 46 { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } | 98 } |
| 100 | 99 |
| 101 String newStr = m_data; | 100 String newStr = m_data; |
| 102 newStr.insert(data, offset); | 101 newStr.insert(data, offset); |
| 103 | 102 |
| 104 setDataAndUpdate(newStr, offset, 0, data.length(), recalcStyleBehavior); | 103 setDataAndUpdate(newStr, offset, 0, data.length(), recalcStyleBehavior); |
| 105 | 104 |
| 106 document().didInsertText(this, offset, data.length()); | 105 document().didInsertText(this, offset, data.length()); |
| 107 } | 106 } |
| 108 | 107 |
| 108 static bool validateOffsetCount(unsigned offset, unsigned count, unsigned length
, unsigned& realCount, ExceptionState& exceptionState) |
| 109 { |
| 110 if (offset > length) { |
| 111 exceptionState.throwDOMException(IndexSizeError, "The offset " + String:
:number(offset) + " is greater than the node's length (" + String::number(length
) + ")."); |
| 112 return false; |
| 113 } |
| 114 |
| 115 Checked<unsigned, RecordOverflow> offsetCount = offset; |
| 116 offsetCount += count; |
| 117 |
| 118 if (offsetCount.hasOverflowed() || offset + count > length) |
| 119 realCount = length - offset; |
| 120 else |
| 121 realCount = count; |
| 122 |
| 123 return true; |
| 124 } |
| 125 |
| 109 void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionState&
exceptionState, RecalcStyleBehavior recalcStyleBehavior) | 126 void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionState&
exceptionState, RecalcStyleBehavior recalcStyleBehavior) |
| 110 { | 127 { |
| 111 if (offset > length()) { | 128 unsigned realCount; |
| 112 exceptionState.throwDOMException(IndexSizeError, "The offset " + String:
:number(offset) + " is greater than the node's length (" + String::number(length
()) + ")."); | 129 if (!validateOffsetCount(offset, count, length(), realCount, exceptionState)
) |
| 113 return; | 130 return; |
| 114 } | |
| 115 | |
| 116 unsigned realCount; | |
| 117 if (offset + count > length()) | |
| 118 realCount = length() - offset; | |
| 119 else | |
| 120 realCount = count; | |
| 121 | 131 |
| 122 String newStr = m_data; | 132 String newStr = m_data; |
| 123 newStr.remove(offset, realCount); | 133 newStr.remove(offset, realCount); |
| 124 | 134 |
| 125 setDataAndUpdate(newStr, offset, count, 0, recalcStyleBehavior); | 135 setDataAndUpdate(newStr, offset, realCount, 0, recalcStyleBehavior); |
| 126 | 136 |
| 127 document().didRemoveText(this, offset, realCount); | 137 document().didRemoveText(this, offset, realCount); |
| 128 } | 138 } |
| 129 | 139 |
| 130 void CharacterData::replaceData(unsigned offset, unsigned count, const String& d
ata, ExceptionState& exceptionState) | 140 void CharacterData::replaceData(unsigned offset, unsigned count, const String& d
ata, ExceptionState& exceptionState) |
| 131 { | 141 { |
| 132 if (offset > length()) { | 142 unsigned realCount; |
| 133 exceptionState.throwDOMException(IndexSizeError, "The offset " + String:
:number(offset) + " is greater than the node's length (" + String::number(length
()) + ")."); | 143 if (!validateOffsetCount(offset, count, length(), realCount, exceptionState)
) |
| 134 return; | 144 return; |
| 135 } | |
| 136 | |
| 137 unsigned realCount; | |
| 138 if (offset + count > length()) | |
| 139 realCount = length() - offset; | |
| 140 else | |
| 141 realCount = count; | |
| 142 | 145 |
| 143 String newStr = m_data; | 146 String newStr = m_data; |
| 144 newStr.remove(offset, realCount); | 147 newStr.remove(offset, realCount); |
| 145 newStr.insert(data, offset); | 148 newStr.insert(data, offset); |
| 146 | 149 |
| 147 setDataAndUpdate(newStr, offset, count, data.length()); | 150 setDataAndUpdate(newStr, offset, realCount, data.length()); |
| 148 | 151 |
| 149 // update the markers for spell checking and grammar checking | 152 // update the markers for spell checking and grammar checking |
| 150 document().didRemoveText(this, offset, realCount); | 153 document().didRemoveText(this, offset, realCount); |
| 151 document().didInsertText(this, offset, data.length()); | 154 document().didInsertText(this, offset, data.length()); |
| 152 } | 155 } |
| 153 | 156 |
| 154 String CharacterData::nodeValue() const | 157 String CharacterData::nodeValue() const |
| 155 { | 158 { |
| 156 return m_data; | 159 return m_data; |
| 157 } | 160 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 { | 208 { |
| 206 return static_cast<int>(length()); | 209 return static_cast<int>(length()); |
| 207 } | 210 } |
| 208 | 211 |
| 209 bool CharacterData::offsetInCharacters() const | 212 bool CharacterData::offsetInCharacters() const |
| 210 { | 213 { |
| 211 return true; | 214 return true; |
| 212 } | 215 } |
| 213 | 216 |
| 214 } // namespace WebCore | 217 } // namespace WebCore |
| OLD | NEW |