Changeset 89913 in webkit
- Timestamp:
- Jun 28, 2011 2:30:58 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r89912 r89913 1 2011-06-28 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Hajime Morita. 4 5 Refactor RenderTextControl::text(). 6 https://bugs.webkit.org/show_bug.cgi?id=63519 7 8 No new tests because this is just a refactoring. 9 10 * rendering/RenderTextControl.cpp: 11 (WebCore::RenderTextControl::setInnerTextValue): 12 Resuce the number of text() calls. 13 (WebCore::finishText): 14 - Use StringBuilder. 15 - Make this a static function. 16 This function doesn't access anything of RenderTextControl. 17 (WebCore::RenderTextControl::text): 18 Use emptyString() and StringBuilder. 19 (WebCore::RenderTextControl::textWithHardLineBreaks): ditto. 20 * rendering/RenderTextControl.h: Remove finishText(). 21 1 22 2011-06-28 Yury Semikhatsky <yurys@chromium.org> 2 23 -
trunk/Source/WebCore/rendering/RenderTextControl.cpp
r89733 r89913 41 41 #include "TextControlInnerElements.h" 42 42 #include "TextIterator.h" 43 #include <wtf/text/StringBuilder.h> 43 44 #include <wtf/unicode/CharacterNames.h> 44 45 … … 144 145 } 145 146 146 void RenderTextControl::setInnerTextValue(const String& innerTextValue)147 { 148 String value = innerTextValue;149 if ( value != text()|| !innerTextElement()->hasChildNodes()) {150 if ( value != text()&& document() && AXObjectCache::accessibilityEnabled())147 void RenderTextControl::setInnerTextValue(const String& value) 148 { 149 bool textIsChanged = value != text(); 150 if (textIsChanged || !innerTextElement()->hasChildNodes()) { 151 if (textIsChanged && document() && AXObjectCache::accessibilityEnabled()) 151 152 document()->axObjectCache()->postNotification(this, AXObjectCache::AXValueChanged, false); 152 153 … … 334 335 } 335 336 336 String RenderTextControl::finishText(Vector<UChar>& result) const 337 static String finishText(StringBuilder& result) 337 338 { 338 339 // Remove one trailing newline; there's always one that's collapsed out by rendering. 339 size_t size = result. size();340 size_t size = result.length(); 340 341 if (size && result[size - 1] == '\n') 341 result.shrink(--size); 342 343 return String::adopt(result); 342 result.resize(--size); 343 return result.toString(); 344 344 } 345 345 … … 348 348 HTMLElement* innerText = innerTextElement(); 349 349 if (!innerText) 350 return "";350 return emptyString(); 351 351 352 Vector<UChar> result; 353 354 for (Node* n = innerText; n; n = n->traverseNextNode(innerText)) { 355 if (n->hasTagName(brTag)) 356 result.append(&newlineCharacter, 1); 357 else if (n->isTextNode()) { 358 String data = static_cast<Text*>(n)->data(); 359 result.append(data.characters(), data.length()); 360 } 361 } 362 352 StringBuilder result; 353 for (Node* node = innerText; node; node = node->traverseNextNode(innerText)) { 354 if (node->hasTagName(brTag)) 355 result.append(newlineCharacter); 356 else if (node->isTextNode()) 357 result.append(static_cast<Text*>(node)->data()); 358 } 363 359 return finishText(result); 364 360 } … … 385 381 HTMLElement* innerText = innerTextElement(); 386 382 if (!innerText) 387 return "";383 return emptyString(); 388 384 389 385 RenderBlock* renderer = toRenderBlock(innerText->renderer()); 390 386 if (!renderer) 391 return "";387 return emptyString(); 392 388 393 389 Node* breakNode; … … 395 391 RootInlineBox* line = renderer->firstRootBox(); 396 392 if (!line) 397 return "";393 return emptyString(); 398 394 399 395 getNextSoftBreak(line, breakNode, breakOffset); 400 396 401 Vector<UChar> result; 402 403 for (Node* n = innerText->firstChild(); n; n = n->traverseNextNode(innerText)) { 404 if (n->hasTagName(brTag)) 405 result.append(&newlineCharacter, 1); 406 else if (n->isTextNode()) { 407 Text* text = static_cast<Text*>(n); 408 String data = text->data(); 397 StringBuilder result; 398 for (Node* node = innerText->firstChild(); node; node = node->traverseNextNode(innerText)) { 399 if (node->hasTagName(brTag)) 400 result.append(newlineCharacter); 401 else if (node->isTextNode()) { 402 String data = static_cast<Text*>(node)->data(); 409 403 unsigned length = data.length(); 410 404 unsigned position = 0; 411 while (breakNode == n && breakOffset <= length) {405 while (breakNode == node && breakOffset <= length) { 412 406 if (breakOffset > position) { 413 407 result.append(data.characters() + position, breakOffset - position); 414 408 position = breakOffset; 415 result.append( &newlineCharacter, 1);409 result.append(newlineCharacter); 416 410 } 417 411 getNextSoftBreak(line, breakNode, breakOffset); … … 419 413 result.append(data.characters() + position, length - position); 420 414 } 421 while (breakNode == n )415 while (breakNode == node) 422 416 getNextSoftBreak(line, breakNode, breakOffset); 423 417 } 424 425 418 return finishText(result); 426 419 } -
trunk/Source/WebCore/rendering/RenderTextControl.h
r88456 r89913 99 99 virtual bool requiresForcedStyleRecalcPropagation() const { return true; } 100 100 101 String finishText(Vector<UChar>&) const;102 103 101 bool hasVisibleTextArea() const; 104 102 friend void setSelectionRange(Node*, int start, int end);
Note: See TracChangeset
for help on using the changeset viewer.