| 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 23 matching lines...) Expand all Loading... |
| 34 #include "core/events/ScopedEventQueue.h" | 34 #include "core/events/ScopedEventQueue.h" |
| 35 #include "core/layout/LayoutText.h" | 35 #include "core/layout/LayoutText.h" |
| 36 #include "core/layout/LayoutTextCombine.h" | 36 #include "core/layout/LayoutTextCombine.h" |
| 37 #include "core/layout/svg/LayoutSVGInlineText.h" | 37 #include "core/layout/svg/LayoutSVGInlineText.h" |
| 38 #include "core/svg/SVGForeignObjectElement.h" | 38 #include "core/svg/SVGForeignObjectElement.h" |
| 39 #include "wtf/text/CString.h" | 39 #include "wtf/text/CString.h" |
| 40 #include "wtf/text/StringBuilder.h" | 40 #include "wtf/text/StringBuilder.h" |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 PassRefPtrWillBeRawPtr<Text> Text::create(Document& document, const String& data
) | 44 RawPtr<Text> Text::create(Document& document, const String& data) |
| 45 { | 45 { |
| 46 return adoptRefWillBeNoop(new Text(document, data, CreateText)); | 46 return (new Text(document, data, CreateText)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 PassRefPtrWillBeRawPtr<Text> Text::createEditingText(Document& document, const S
tring& data) | 49 RawPtr<Text> Text::createEditingText(Document& document, const String& data) |
| 50 { | 50 { |
| 51 return adoptRefWillBeNoop(new Text(document, data, CreateEditingText)); | 51 return (new Text(document, data, CreateEditingText)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 PassRefPtrWillBeRawPtr<Node> Text::mergeNextSiblingNodesIfPossible() | 54 RawPtr<Node> Text::mergeNextSiblingNodesIfPossible() |
| 55 { | 55 { |
| 56 RefPtrWillBeRawPtr<Node> protect(this); | 56 RawPtr<Node> protect(this); |
| 57 | 57 |
| 58 // Remove empty text nodes. | 58 // Remove empty text nodes. |
| 59 if (!length()) { | 59 if (!length()) { |
| 60 // Care must be taken to get the next node before removing the current n
ode. | 60 // Care must be taken to get the next node before removing the current n
ode. |
| 61 RefPtrWillBeRawPtr<Node> nextNode(NodeTraversal::nextPostOrder(*this)); | 61 RawPtr<Node> nextNode(NodeTraversal::nextPostOrder(*this)); |
| 62 remove(IGNORE_EXCEPTION); | 62 remove(IGNORE_EXCEPTION); |
| 63 return nextNode.release(); | 63 return nextNode.release(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Merge text nodes. | 66 // Merge text nodes. |
| 67 while (Node* nextSibling = this->nextSibling()) { | 67 while (Node* nextSibling = this->nextSibling()) { |
| 68 if (nextSibling->nodeType() != TEXT_NODE) | 68 if (nextSibling->nodeType() != TEXT_NODE) |
| 69 break; | 69 break; |
| 70 | 70 |
| 71 RefPtrWillBeRawPtr<Text> nextText = toText(nextSibling); | 71 RawPtr<Text> nextText = toText(nextSibling); |
| 72 | 72 |
| 73 // Remove empty text nodes. | 73 // Remove empty text nodes. |
| 74 if (!nextText->length()) { | 74 if (!nextText->length()) { |
| 75 nextText->remove(IGNORE_EXCEPTION); | 75 nextText->remove(IGNORE_EXCEPTION); |
| 76 continue; | 76 continue; |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Both non-empty text nodes. Merge them. | 79 // Both non-empty text nodes. Merge them. |
| 80 unsigned offset = length(); | 80 unsigned offset = length(); |
| 81 String nextTextData = nextText->data(); | 81 String nextTextData = nextText->data(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 94 nextText->updateTextLayoutObject(0, 0); | 94 nextText->updateTextLayoutObject(0, 0); |
| 95 | 95 |
| 96 document().incDOMTreeVersion(); | 96 document().incDOMTreeVersion(); |
| 97 didModifyData(oldTextData, CharacterData::UpdateFromNonParser); | 97 didModifyData(oldTextData, CharacterData::UpdateFromNonParser); |
| 98 nextText->remove(IGNORE_EXCEPTION); | 98 nextText->remove(IGNORE_EXCEPTION); |
| 99 } | 99 } |
| 100 | 100 |
| 101 return NodeTraversal::nextPostOrder(*this); | 101 return NodeTraversal::nextPostOrder(*this); |
| 102 } | 102 } |
| 103 | 103 |
| 104 PassRefPtrWillBeRawPtr<Text> Text::splitText(unsigned offset, ExceptionState& ex
ceptionState) | 104 RawPtr<Text> Text::splitText(unsigned offset, ExceptionState& exceptionState) |
| 105 { | 105 { |
| 106 // IndexSizeError: Raised if the specified offset is negative or greater tha
n | 106 // IndexSizeError: Raised if the specified offset is negative or greater tha
n |
| 107 // the number of 16-bit units in data. | 107 // the number of 16-bit units in data. |
| 108 if (offset > length()) { | 108 if (offset > length()) { |
| 109 exceptionState.throwDOMException(IndexSizeError, "The offset " + String:
:number(offset) + " is larger than the Text node's length."); | 109 exceptionState.throwDOMException(IndexSizeError, "The offset " + String:
:number(offset) + " is larger than the Text node's length."); |
| 110 return nullptr; | 110 return nullptr; |
| 111 } | 111 } |
| 112 | 112 |
| 113 EventQueueScope scope; | 113 EventQueueScope scope; |
| 114 String oldStr = data(); | 114 String oldStr = data(); |
| 115 RefPtrWillBeRawPtr<Text> newText = cloneWithData(oldStr.substring(offset)); | 115 RawPtr<Text> newText = cloneWithData(oldStr.substring(offset)); |
| 116 setDataWithoutUpdate(oldStr.substring(0, offset)); | 116 setDataWithoutUpdate(oldStr.substring(0, offset)); |
| 117 | 117 |
| 118 didModifyData(oldStr, CharacterData::UpdateFromNonParser); | 118 didModifyData(oldStr, CharacterData::UpdateFromNonParser); |
| 119 | 119 |
| 120 if (parentNode()) | 120 if (parentNode()) |
| 121 parentNode()->insertBefore(newText.get(), nextSibling(), exceptionState)
; | 121 parentNode()->insertBefore(newText.get(), nextSibling(), exceptionState)
; |
| 122 if (exceptionState.hadException()) | 122 if (exceptionState.hadException()) |
| 123 return nullptr; | 123 return nullptr; |
| 124 | 124 |
| 125 if (layoutObject()) | 125 if (layoutObject()) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 for (const Node* n = startText; n != onePastEndText; n = n->nextSibling()) { | 179 for (const Node* n = startText; n != onePastEndText; n = n->nextSibling()) { |
| 180 if (!n->isTextNode()) | 180 if (!n->isTextNode()) |
| 181 continue; | 181 continue; |
| 182 result.append(toText(n)->data()); | 182 result.append(toText(n)->data()); |
| 183 } | 183 } |
| 184 ASSERT(result.length() == resultLength); | 184 ASSERT(result.length() == resultLength); |
| 185 | 185 |
| 186 return result.toString(); | 186 return result.toString(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 PassRefPtrWillBeRawPtr<Text> Text::replaceWholeText(const String& newText) | 189 RawPtr<Text> Text::replaceWholeText(const String& newText) |
| 190 { | 190 { |
| 191 // Remove all adjacent text nodes, and replace the contents of this one. | 191 // Remove all adjacent text nodes, and replace the contents of this one. |
| 192 | 192 |
| 193 // Protect startText and endText against mutation event handlers removing th
e last ref | 193 // Protect startText and endText against mutation event handlers removing th
e last ref |
| 194 RefPtrWillBeRawPtr<Text> startText = const_cast<Text*>(earliestLogicallyAdja
centTextNode(this)); | 194 RawPtr<Text> startText = const_cast<Text*>(earliestLogicallyAdjacentTextNode
(this)); |
| 195 RefPtrWillBeRawPtr<Text> endText = const_cast<Text*>(latestLogicallyAdjacent
TextNode(this)); | 195 RawPtr<Text> endText = const_cast<Text*>(latestLogicallyAdjacentTextNode(thi
s)); |
| 196 | 196 |
| 197 RefPtrWillBeRawPtr<Text> protectedThis(this); // Mutation event handlers cou
ld cause our last ref to go away | 197 RawPtr<Text> protectedThis(this); // Mutation event handlers could cause our
last ref to go away |
| 198 RefPtrWillBeRawPtr<ContainerNode> parent = parentNode(); // Protect against
mutation handlers moving this node during traversal | 198 RawPtr<ContainerNode> parent = parentNode(); // Protect against mutation han
dlers moving this node during traversal |
| 199 for (RefPtrWillBeRawPtr<Node> n = startText; n && n != this && n->isTextNode
() && n->parentNode() == parent;) { | 199 for (RawPtr<Node> n = startText; n && n != this && n->isTextNode() && n->par
entNode() == parent;) { |
| 200 RefPtrWillBeRawPtr<Node> nodeToRemove(n.release()); | 200 RawPtr<Node> nodeToRemove(n.release()); |
| 201 n = nodeToRemove->nextSibling(); | 201 n = nodeToRemove->nextSibling(); |
| 202 parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION); | 202 parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION); |
| 203 } | 203 } |
| 204 | 204 |
| 205 if (this != endText) { | 205 if (this != endText) { |
| 206 Node* onePastEndText = endText->nextSibling(); | 206 Node* onePastEndText = endText->nextSibling(); |
| 207 for (RefPtrWillBeRawPtr<Node> n = nextSibling(); n && n != onePastEndTex
t && n->isTextNode() && n->parentNode() == parent;) { | 207 for (RawPtr<Node> n = nextSibling(); n && n != onePastEndText && n->isTe
xtNode() && n->parentNode() == parent;) { |
| 208 RefPtrWillBeRawPtr<Node> nodeToRemove(n.release()); | 208 RawPtr<Node> nodeToRemove(n.release()); |
| 209 n = nodeToRemove->nextSibling(); | 209 n = nodeToRemove->nextSibling(); |
| 210 parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION); | 210 parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | 213 |
| 214 if (newText.isEmpty()) { | 214 if (newText.isEmpty()) { |
| 215 if (parent && parentNode() == parent) | 215 if (parent && parentNode() == parent) |
| 216 parent->removeChild(this, IGNORE_EXCEPTION); | 216 parent->removeChild(this, IGNORE_EXCEPTION); |
| 217 return nullptr; | 217 return nullptr; |
| 218 } | 218 } |
| 219 | 219 |
| 220 setData(newText); | 220 setData(newText); |
| 221 return protectedThis.release(); | 221 return protectedThis.release(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 String Text::nodeName() const | 224 String Text::nodeName() const |
| 225 { | 225 { |
| 226 return "#text"; | 226 return "#text"; |
| 227 } | 227 } |
| 228 | 228 |
| 229 Node::NodeType Text::nodeType() const | 229 Node::NodeType Text::nodeType() const |
| 230 { | 230 { |
| 231 return TEXT_NODE; | 231 return TEXT_NODE; |
| 232 } | 232 } |
| 233 | 233 |
| 234 PassRefPtrWillBeRawPtr<Node> Text::cloneNode(bool /*deep*/) | 234 RawPtr<Node> Text::cloneNode(bool /*deep*/) |
| 235 { | 235 { |
| 236 return cloneWithData(data()); | 236 return cloneWithData(data()); |
| 237 } | 237 } |
| 238 | 238 |
| 239 static inline bool canHaveWhitespaceChildren(const LayoutObject& parent, Text* t
ext) | 239 static inline bool canHaveWhitespaceChildren(const LayoutObject& parent, Text* t
ext) |
| 240 { | 240 { |
| 241 // <button> should allow whitespace even though LayoutFlexibleBox doesn't. | 241 // <button> should allow whitespace even though LayoutFlexibleBox doesn't. |
| 242 if (parent.isLayoutButton()) | 242 if (parent.isLayoutButton()) |
| 243 return true; | 243 return true; |
| 244 | 244 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 if (!textLayoutObject || !textLayoutObjectIsNeeded(*textLayoutObject->style(
), *textLayoutObject->parent())) { | 408 if (!textLayoutObject || !textLayoutObjectIsNeeded(*textLayoutObject->style(
), *textLayoutObject->parent())) { |
| 409 lazyReattachIfAttached(); | 409 lazyReattachIfAttached(); |
| 410 // FIXME: Editing should be updated so this is not neccesary. | 410 // FIXME: Editing should be updated so this is not neccesary. |
| 411 if (recalcStyleBehavior == DeprecatedRecalcStyleImmediatlelyForEditing) | 411 if (recalcStyleBehavior == DeprecatedRecalcStyleImmediatlelyForEditing) |
| 412 document().updateLayoutTreeIfNeeded(); | 412 document().updateLayoutTreeIfNeeded(); |
| 413 return; | 413 return; |
| 414 } | 414 } |
| 415 textLayoutObject->setTextWithOffset(dataImpl(), offsetOfReplacedData, length
OfReplacedData); | 415 textLayoutObject->setTextWithOffset(dataImpl(), offsetOfReplacedData, length
OfReplacedData); |
| 416 } | 416 } |
| 417 | 417 |
| 418 PassRefPtrWillBeRawPtr<Text> Text::cloneWithData(const String& data) | 418 RawPtr<Text> Text::cloneWithData(const String& data) |
| 419 { | 419 { |
| 420 return create(document(), data); | 420 return create(document(), data); |
| 421 } | 421 } |
| 422 | 422 |
| 423 DEFINE_TRACE(Text) | 423 DEFINE_TRACE(Text) |
| 424 { | 424 { |
| 425 CharacterData::trace(visitor); | 425 CharacterData::trace(visitor); |
| 426 } | 426 } |
| 427 | 427 |
| 428 #ifndef NDEBUG | 428 #ifndef NDEBUG |
| (...skipping 10 matching lines...) Expand all Loading... |
| 439 result.appendLiteral("; "); | 439 result.appendLiteral("; "); |
| 440 result.appendLiteral("value="); | 440 result.appendLiteral("value="); |
| 441 result.append(s); | 441 result.append(s); |
| 442 } | 442 } |
| 443 | 443 |
| 444 strncpy(buffer, result.toString().utf8().data(), length - 1); | 444 strncpy(buffer, result.toString().utf8().data(), length - 1); |
| 445 } | 445 } |
| 446 #endif | 446 #endif |
| 447 | 447 |
| 448 } // namespace blink | 448 } // namespace blink |
| OLD | NEW |