Chromium Code Reviews| 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 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
| 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 return m_lastChangeWasUserEdit; | 625 return m_lastChangeWasUserEdit; |
| 626 } | 626 } |
| 627 | 627 |
| 628 void HTMLTextFormControlElement::setInnerEditorValue(const String& value) | 628 void HTMLTextFormControlElement::setInnerEditorValue(const String& value) |
| 629 { | 629 { |
| 630 ASSERT(!openShadowRoot()); | 630 ASSERT(!openShadowRoot()); |
| 631 if (!isTextFormControl() || openShadowRoot()) | 631 if (!isTextFormControl() || openShadowRoot()) |
| 632 return; | 632 return; |
| 633 | 633 |
| 634 bool textIsChanged = value != innerEditorValue(); | 634 bool textIsChanged = value != innerEditorValue(); |
| 635 if (textIsChanged || !innerEditorElement()->hasChildren()) { | 635 HTMLElement* innerEditor = innerEditorElement(); |
| 636 if (textIsChanged && layoutObject()) { | 636 if (!textIsChanged && innerEditor->hasChildren()) |
| 637 if (AXObjectCache* cache = document().existingAXObjectCache()) | 637 return; |
| 638 cache->handleTextFormControlChanged(this); | |
| 639 } | |
| 640 innerEditorElement()->setInnerText(value, ASSERT_NO_EXCEPTION); | |
| 641 | 638 |
| 642 if (value.endsWith('\n') || value.endsWith('\r')) | 639 // If the last child is a trailing <br> that's appended below, remove it |
| 643 innerEditorElement()->appendChild(HTMLBRElement::create(document())) ; | 640 // first so as to enable setInnerText() fast path of updating a text node, |
| 641 // requiring less allocations. Generally helpful, but avoids dead object | |
|
esprehn
2015/09/25 18:34:37
I would remove the comment about less allocations
sof
2015/09/26 06:20:23
Done.
| |
| 642 // buildup with Oilpan on benchmarks pounding this update operation. | |
| 643 if (isHTMLBRElement(innerEditor->lastChild())) | |
| 644 innerEditor->removeChild(innerEditor->lastChild(), ASSERT_NO_EXCEPTION); | |
| 645 | |
| 646 innerEditor->setInnerText(value, ASSERT_NO_EXCEPTION); | |
| 647 | |
| 648 if (value.endsWith('\n') || value.endsWith('\r')) | |
| 649 innerEditor->appendChild(HTMLBRElement::create(document())); | |
| 650 | |
| 651 if (textIsChanged && layoutObject()) { | |
| 652 if (AXObjectCache* cache = document().existingAXObjectCache()) | |
| 653 cache->handleTextFormControlChanged(this); | |
| 644 } | 654 } |
| 645 } | 655 } |
| 646 | 656 |
| 647 static String finishText(StringBuilder& result) | 657 static String finishText(StringBuilder& result) |
| 648 { | 658 { |
| 649 // Remove one trailing newline; there's always one that's collapsed out by l ayoutObject. | 659 // Remove one trailing newline; there's always one that's collapsed out by l ayoutObject. |
| 650 size_t size = result.length(); | 660 size_t size = result.length(); |
| 651 if (size && result[size - 1] == '\n') | 661 if (size && result[size - 1] == '\n') |
| 652 result.resize(--size); | 662 result.resize(--size); |
| 653 return result.toString(); | 663 return result.toString(); |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 } | 1017 } |
| 1008 | 1018 |
| 1009 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele ment& source) | 1019 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele ment& source) |
| 1010 { | 1020 { |
| 1011 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText FormControlElement&>(source); | 1021 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText FormControlElement&>(source); |
| 1012 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; | 1022 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; |
| 1013 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); | 1023 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); |
| 1014 } | 1024 } |
| 1015 | 1025 |
| 1016 } // namespace blink | 1026 } // namespace blink |
| OLD | NEW |