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, 2008, 2010 Apple Inc. All rights reserv ed. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed. |
| 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
| 7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) | 7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 } | 406 } |
| 407 | 407 |
| 408 void HTMLTextAreaElement::setInnerEditorValue(const String& value) | 408 void HTMLTextAreaElement::setInnerEditorValue(const String& value) |
| 409 { | 409 { |
| 410 HTMLTextFormControlElement::setInnerEditorValue(value); | 410 HTMLTextFormControlElement::setInnerEditorValue(value); |
| 411 m_valueIsUpToDate = true; | 411 m_valueIsUpToDate = true; |
| 412 } | 412 } |
| 413 | 413 |
| 414 String HTMLTextAreaElement::defaultValue() const | 414 String HTMLTextAreaElement::defaultValue() const |
| 415 { | 415 { |
| 416 StringBuilder value; | 416 return textContent(); |
| 417 | |
| 418 // Since there may be comments, ignore nodes other than text nodes. | |
| 419 for (Node* n = firstChild(); n; n = n->nextSibling()) { | |
| 420 if (n->isTextNode()) | |
| 421 value.append(toText(n)->data()); | |
| 422 } | |
| 423 | |
| 424 return value.toString(); | |
| 425 } | 417 } |
| 426 | 418 |
| 427 void HTMLTextAreaElement::setDefaultValue(const String& defaultValue) | 419 void HTMLTextAreaElement::setDefaultValue(const String& defaultValue) |
| 428 { | 420 { |
| 429 RefPtrWillBeRawPtr<Node> protectFromMutationEvents(this); | 421 setTextContent(defaultValue); |
| 430 | |
| 431 // To preserve comments, remove only the text nodes, then add a single text node. | |
| 432 WillBeHeapVector<RefPtrWillBeMember<Node>> textNodes; | |
| 433 for (Node* n = firstChild(); n; n = n->nextSibling()) { | |
| 434 if (n->isTextNode()) | |
| 435 textNodes.append(n); | |
| 436 } | |
| 437 size_t size = textNodes.size(); | |
| 438 for (size_t i = 0; i < size; ++i) | |
| 439 removeChild(textNodes[i].get(), IGNORE_EXCEPTION); | |
| 440 | |
| 441 // Normalize line endings. | |
| 442 String value = defaultValue; | |
| 443 value.replace("\r\n", "\n"); | |
| 444 value.replace('\r', '\n'); | |
| 445 | |
| 446 insertBefore(document().createTextNode(value), firstChild(), IGNORE_EXCEPTIO N); | |
| 447 | |
| 448 if (!m_isDirty) | 422 if (!m_isDirty) |
|
Sunil Ratnu
2015/07/10 07:47:26
I tried using ImplementedAs=textContent in the idl
tkent
2015/07/10 07:59:40
Can you add test cases of ta.textContent = '...' t
| |
| 449 setNonDirtyValue(value); | 423 setNonDirtyValue(defaultValue); |
| 450 } | 424 } |
| 451 | 425 |
| 452 int HTMLTextAreaElement::maxLength() const | 426 int HTMLTextAreaElement::maxLength() const |
| 453 { | 427 { |
| 454 int value; | 428 int value; |
| 455 if (!parseHTMLInteger(getAttribute(maxlengthAttr), value)) | 429 if (!parseHTMLInteger(getAttribute(maxlengthAttr), value)) |
| 456 return -1; | 430 return -1; |
| 457 return value >= 0 ? value : -1; | 431 return value >= 0 ? value : -1; |
| 458 } | 432 } |
| 459 | 433 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 | 616 |
| 643 void HTMLTextAreaElement::copyNonAttributePropertiesFromElement(const Element& s ource) | 617 void HTMLTextAreaElement::copyNonAttributePropertiesFromElement(const Element& s ource) |
| 644 { | 618 { |
| 645 const HTMLTextAreaElement& sourceElement = static_cast<const HTMLTextAreaEle ment&>(source); | 619 const HTMLTextAreaElement& sourceElement = static_cast<const HTMLTextAreaEle ment&>(source); |
| 646 setValueCommon(sourceElement.value(), DispatchNoEvent, SetSeletion); | 620 setValueCommon(sourceElement.value(), DispatchNoEvent, SetSeletion); |
| 647 m_isDirty = sourceElement.m_isDirty; | 621 m_isDirty = sourceElement.m_isDirty; |
| 648 HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(source); | 622 HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(source); |
| 649 } | 623 } |
| 650 | 624 |
| 651 } // namespace blink | 625 } // namespace blink |
| OLD | NEW |