Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: third_party/WebKit/Source/core/dom/Text.cpp

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 26 matching lines...) Expand all
37 #include "core/layout/LayoutTextCombine.h" 37 #include "core/layout/LayoutTextCombine.h"
38 #include "core/layout/LayoutTextFragment.h" 38 #include "core/layout/LayoutTextFragment.h"
39 #include "core/layout/api/LayoutTextItem.h" 39 #include "core/layout/api/LayoutTextItem.h"
40 #include "core/layout/svg/LayoutSVGInlineText.h" 40 #include "core/layout/svg/LayoutSVGInlineText.h"
41 #include "core/svg/SVGForeignObjectElement.h" 41 #include "core/svg/SVGForeignObjectElement.h"
42 #include "wtf/text/CString.h" 42 #include "wtf/text/CString.h"
43 #include "wtf/text/StringBuilder.h" 43 #include "wtf/text/StringBuilder.h"
44 44
45 namespace blink { 45 namespace blink {
46 46
47 PassRefPtrWillBeRawPtr<Text> Text::create(Document& document, const String& data ) 47 RawPtr<Text> Text::create(Document& document, const String& data)
48 { 48 {
49 return adoptRefWillBeNoop(new Text(document, data, CreateText)); 49 return new Text(document, data, CreateText);
50 } 50 }
51 51
52 PassRefPtrWillBeRawPtr<Text> Text::createEditingText(Document& document, const S tring& data) 52 RawPtr<Text> Text::createEditingText(Document& document, const String& data)
53 { 53 {
54 return adoptRefWillBeNoop(new Text(document, data, CreateEditingText)); 54 return new Text(document, data, CreateEditingText);
55 } 55 }
56 56
57 PassRefPtrWillBeRawPtr<Node> Text::mergeNextSiblingNodesIfPossible() 57 RawPtr<Node> Text::mergeNextSiblingNodesIfPossible()
58 { 58 {
59 RefPtrWillBeRawPtr<Node> protect(this); 59 RawPtr<Node> protect(this);
60 60
61 // Remove empty text nodes. 61 // Remove empty text nodes.
62 if (!length()) { 62 if (!length()) {
63 // Care must be taken to get the next node before removing the current n ode. 63 // Care must be taken to get the next node before removing the current n ode.
64 RefPtrWillBeRawPtr<Node> nextNode(NodeTraversal::nextPostOrder(*this)); 64 RawPtr<Node> nextNode(NodeTraversal::nextPostOrder(*this));
65 remove(IGNORE_EXCEPTION); 65 remove(IGNORE_EXCEPTION);
66 return nextNode.release(); 66 return nextNode.release();
67 } 67 }
68 68
69 // Merge text nodes. 69 // Merge text nodes.
70 while (Node* nextSibling = this->nextSibling()) { 70 while (Node* nextSibling = this->nextSibling()) {
71 if (nextSibling->getNodeType() != TEXT_NODE) 71 if (nextSibling->getNodeType() != TEXT_NODE)
72 break; 72 break;
73 73
74 RefPtrWillBeRawPtr<Text> nextText = toText(nextSibling); 74 RawPtr<Text> nextText = toText(nextSibling);
75 75
76 // Remove empty text nodes. 76 // Remove empty text nodes.
77 if (!nextText->length()) { 77 if (!nextText->length()) {
78 nextText->remove(IGNORE_EXCEPTION); 78 nextText->remove(IGNORE_EXCEPTION);
79 continue; 79 continue;
80 } 80 }
81 81
82 // Both non-empty text nodes. Merge them. 82 // Both non-empty text nodes. Merge them.
83 unsigned offset = length(); 83 unsigned offset = length();
84 String nextTextData = nextText->data(); 84 String nextTextData = nextText->data();
(...skipping 12 matching lines...) Expand all
97 nextText->updateTextLayoutObject(0, 0); 97 nextText->updateTextLayoutObject(0, 0);
98 98
99 document().incDOMTreeVersion(); 99 document().incDOMTreeVersion();
100 didModifyData(oldTextData, CharacterData::UpdateFromNonParser); 100 didModifyData(oldTextData, CharacterData::UpdateFromNonParser);
101 nextText->remove(IGNORE_EXCEPTION); 101 nextText->remove(IGNORE_EXCEPTION);
102 } 102 }
103 103
104 return NodeTraversal::nextPostOrder(*this); 104 return NodeTraversal::nextPostOrder(*this);
105 } 105 }
106 106
107 PassRefPtrWillBeRawPtr<Text> Text::splitText(unsigned offset, ExceptionState& ex ceptionState) 107 RawPtr<Text> Text::splitText(unsigned offset, ExceptionState& exceptionState)
108 { 108 {
109 // IndexSizeError: Raised if the specified offset is negative or greater tha n 109 // IndexSizeError: Raised if the specified offset is negative or greater tha n
110 // the number of 16-bit units in data. 110 // the number of 16-bit units in data.
111 if (offset > length()) { 111 if (offset > length()) {
112 exceptionState.throwDOMException(IndexSizeError, "The offset " + String: :number(offset) + " is larger than the Text node's length."); 112 exceptionState.throwDOMException(IndexSizeError, "The offset " + String: :number(offset) + " is larger than the Text node's length.");
113 return nullptr; 113 return nullptr;
114 } 114 }
115 115
116 EventQueueScope scope; 116 EventQueueScope scope;
117 String oldStr = data(); 117 String oldStr = data();
118 RefPtrWillBeRawPtr<Text> newText = cloneWithData(oldStr.substring(offset)); 118 RawPtr<Text> newText = cloneWithData(oldStr.substring(offset));
119 setDataWithoutUpdate(oldStr.substring(0, offset)); 119 setDataWithoutUpdate(oldStr.substring(0, offset));
120 120
121 didModifyData(oldStr, CharacterData::UpdateFromNonParser); 121 didModifyData(oldStr, CharacterData::UpdateFromNonParser);
122 122
123 if (parentNode()) 123 if (parentNode())
124 parentNode()->insertBefore(newText.get(), nextSibling(), exceptionState) ; 124 parentNode()->insertBefore(newText.get(), nextSibling(), exceptionState) ;
125 if (exceptionState.hadException()) 125 if (exceptionState.hadException())
126 return nullptr; 126 return nullptr;
127 127
128 if (layoutObject()) 128 if (layoutObject())
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 for (const Node* n = startText; n != onePastEndText; n = n->nextSibling()) { 182 for (const Node* n = startText; n != onePastEndText; n = n->nextSibling()) {
183 if (!n->isTextNode()) 183 if (!n->isTextNode())
184 continue; 184 continue;
185 result.append(toText(n)->data()); 185 result.append(toText(n)->data());
186 } 186 }
187 ASSERT(result.length() == resultLength); 187 ASSERT(result.length() == resultLength);
188 188
189 return result.toString(); 189 return result.toString();
190 } 190 }
191 191
192 PassRefPtrWillBeRawPtr<Text> Text::replaceWholeText(const String& newText) 192 RawPtr<Text> Text::replaceWholeText(const String& newText)
193 { 193 {
194 // Remove all adjacent text nodes, and replace the contents of this one. 194 // Remove all adjacent text nodes, and replace the contents of this one.
195 195
196 // Protect startText and endText against mutation event handlers removing th e last ref 196 // Protect startText and endText against mutation event handlers removing th e last ref
197 RefPtrWillBeRawPtr<Text> startText = const_cast<Text*>(earliestLogicallyAdja centTextNode(this)); 197 RawPtr<Text> startText = const_cast<Text*>(earliestLogicallyAdjacentTextNode (this));
198 RefPtrWillBeRawPtr<Text> endText = const_cast<Text*>(latestLogicallyAdjacent TextNode(this)); 198 RawPtr<Text> endText = const_cast<Text*>(latestLogicallyAdjacentTextNode(thi s));
199 199
200 RefPtrWillBeRawPtr<Text> protectedThis(this); // Mutation event handlers cou ld cause our last ref to go away 200 RawPtr<Text> protectedThis(this); // Mutation event handlers could cause our last ref to go away
201 RefPtrWillBeRawPtr<ContainerNode> parent = parentNode(); // Protect against mutation handlers moving this node during traversal 201 RawPtr<ContainerNode> parent = parentNode(); // Protect against mutation han dlers moving this node during traversal
202 for (RefPtrWillBeRawPtr<Node> n = startText; n && n != this && n->isTextNode () && n->parentNode() == parent;) { 202 for (RawPtr<Node> n = startText; n && n != this && n->isTextNode() && n->par entNode() == parent;) {
203 RefPtrWillBeRawPtr<Node> nodeToRemove(n.release()); 203 RawPtr<Node> nodeToRemove(n.release());
204 n = nodeToRemove->nextSibling(); 204 n = nodeToRemove->nextSibling();
205 parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION); 205 parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION);
206 } 206 }
207 207
208 if (this != endText) { 208 if (this != endText) {
209 Node* onePastEndText = endText->nextSibling(); 209 Node* onePastEndText = endText->nextSibling();
210 for (RefPtrWillBeRawPtr<Node> n = nextSibling(); n && n != onePastEndTex t && n->isTextNode() && n->parentNode() == parent;) { 210 for (RawPtr<Node> n = nextSibling(); n && n != onePastEndText && n->isTe xtNode() && n->parentNode() == parent;) {
211 RefPtrWillBeRawPtr<Node> nodeToRemove(n.release()); 211 RawPtr<Node> nodeToRemove(n.release());
212 n = nodeToRemove->nextSibling(); 212 n = nodeToRemove->nextSibling();
213 parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION); 213 parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION);
214 } 214 }
215 } 215 }
216 216
217 if (newText.isEmpty()) { 217 if (newText.isEmpty()) {
218 if (parent && parentNode() == parent) 218 if (parent && parentNode() == parent)
219 parent->removeChild(this, IGNORE_EXCEPTION); 219 parent->removeChild(this, IGNORE_EXCEPTION);
220 return nullptr; 220 return nullptr;
221 } 221 }
222 222
223 setData(newText); 223 setData(newText);
224 return protectedThis.release(); 224 return protectedThis.release();
225 } 225 }
226 226
227 String Text::nodeName() const 227 String Text::nodeName() const
228 { 228 {
229 return "#text"; 229 return "#text";
230 } 230 }
231 231
232 Node::NodeType Text::getNodeType() const 232 Node::NodeType Text::getNodeType() const
233 { 233 {
234 return TEXT_NODE; 234 return TEXT_NODE;
235 } 235 }
236 236
237 PassRefPtrWillBeRawPtr<Node> Text::cloneNode(bool /*deep*/) 237 RawPtr<Node> Text::cloneNode(bool /*deep*/)
238 { 238 {
239 return cloneWithData(data()); 239 return cloneWithData(data());
240 } 240 }
241 241
242 static inline bool canHaveWhitespaceChildren(const LayoutObject& parent) 242 static inline bool canHaveWhitespaceChildren(const LayoutObject& parent)
243 { 243 {
244 // <button> should allow whitespace even though LayoutFlexibleBox doesn't. 244 // <button> should allow whitespace even though LayoutFlexibleBox doesn't.
245 if (parent.isLayoutButton()) 245 if (parent.isLayoutButton())
246 return true; 246 return true;
247 247
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 if (shouldUpdateLayoutByReattaching(*this, textLayoutObject)) { 428 if (shouldUpdateLayoutByReattaching(*this, textLayoutObject)) {
429 lazyReattachIfAttached(); 429 lazyReattachIfAttached();
430 // FIXME: Editing should be updated so this is not neccesary. 430 // FIXME: Editing should be updated so this is not neccesary.
431 if (recalcStyleBehavior == DeprecatedRecalcStyleImmediatlelyForEditing) 431 if (recalcStyleBehavior == DeprecatedRecalcStyleImmediatlelyForEditing)
432 document().updateLayoutTree(); 432 document().updateLayoutTree();
433 return; 433 return;
434 } 434 }
435 textLayoutObject->setTextWithOffset(dataImpl(), offsetOfReplacedData, length OfReplacedData); 435 textLayoutObject->setTextWithOffset(dataImpl(), offsetOfReplacedData, length OfReplacedData);
436 } 436 }
437 437
438 PassRefPtrWillBeRawPtr<Text> Text::cloneWithData(const String& data) 438 RawPtr<Text> Text::cloneWithData(const String& data)
439 { 439 {
440 return create(document(), data); 440 return create(document(), data);
441 } 441 }
442 442
443 DEFINE_TRACE(Text) 443 DEFINE_TRACE(Text)
444 { 444 {
445 CharacterData::trace(visitor); 445 CharacterData::trace(visitor);
446 } 446 }
447 447
448 #ifndef NDEBUG 448 #ifndef NDEBUG
(...skipping 10 matching lines...) Expand all
459 result.appendLiteral("; "); 459 result.appendLiteral("; ");
460 result.appendLiteral("value="); 460 result.appendLiteral("value=");
461 result.append(s); 461 result.append(s);
462 } 462 }
463 463
464 strncpy(buffer, result.toString().utf8().data(), length - 1); 464 strncpy(buffer, result.toString().utf8().data(), length - 1);
465 } 465 }
466 #endif 466 #endif
467 467
468 } // namespace blink 468 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Text.h ('k') | third_party/WebKit/Source/core/dom/TextTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698