| 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 | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights |
| 6 * reserved. | 6 * reserved. |
| 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
| 8 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) | 8 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 return text.length() - crlfCount; | 70 return text.length() - crlfCount; |
| 71 } | 71 } |
| 72 | 72 |
| 73 HTMLTextAreaElement::HTMLTextAreaElement(Document& document) | 73 HTMLTextAreaElement::HTMLTextAreaElement(Document& document) |
| 74 : TextControlElement(textareaTag, document), | 74 : TextControlElement(textareaTag, document), |
| 75 m_rows(defaultRows), | 75 m_rows(defaultRows), |
| 76 m_cols(defaultCols), | 76 m_cols(defaultCols), |
| 77 m_wrap(SoftWrap), | 77 m_wrap(SoftWrap), |
| 78 m_isDirty(false), | 78 m_isDirty(false), |
| 79 m_valueIsUpToDate(true), | |
| 80 m_isPlaceholderVisible(false) {} | 79 m_isPlaceholderVisible(false) {} |
| 81 | 80 |
| 82 HTMLTextAreaElement* HTMLTextAreaElement::create(Document& document) { | 81 HTMLTextAreaElement* HTMLTextAreaElement::create(Document& document) { |
| 83 HTMLTextAreaElement* textArea = new HTMLTextAreaElement(document); | 82 HTMLTextAreaElement* textArea = new HTMLTextAreaElement(document); |
| 84 textArea->ensureUserAgentShadowRoot(); | 83 textArea->ensureUserAgentShadowRoot(); |
| 85 return textArea; | 84 return textArea; |
| 86 } | 85 } |
| 87 | 86 |
| 88 void HTMLTextAreaElement::didAddUserAgentShadowRoot(ShadowRoot& root) { | 87 void HTMLTextAreaElement::didAddUserAgentShadowRoot(ShadowRoot& root) { |
| 89 root.appendChild(TextControlInnerEditorElement::create(document())); | 88 root.appendChild(TextControlInnerEditorElement::create(document())); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 Element* innerEditor = innerEditorElement(); | 279 Element* innerEditor = innerEditorElement(); |
| 281 for (Node& node : NodeTraversal::descendantsOf(*innerEditor)) { | 280 for (Node& node : NodeTraversal::descendantsOf(*innerEditor)) { |
| 282 if (node.isTextNode()) | 281 if (node.isTextNode()) |
| 283 continue; | 282 continue; |
| 284 DCHECK(isHTMLBRElement(node)); | 283 DCHECK(isHTMLBRElement(node)); |
| 285 DCHECK_EQ(&node, innerEditor->lastChild()); | 284 DCHECK_EQ(&node, innerEditor->lastChild()); |
| 286 } | 285 } |
| 287 #endif | 286 #endif |
| 288 addPlaceholderBreakElementIfNecessary(); | 287 addPlaceholderBreakElementIfNecessary(); |
| 289 setChangedSinceLastFormControlChangeEvent(true); | 288 setChangedSinceLastFormControlChangeEvent(true); |
| 290 m_valueIsUpToDate = false; | 289 updateValue(); |
| 291 setNeedsValidityCheck(); | 290 setNeedsValidityCheck(); |
| 292 setAutofilled(false); | 291 setAutofilled(false); |
| 293 updatePlaceholderVisibility(); | 292 updatePlaceholderVisibility(); |
| 294 | 293 |
| 295 if (!isFocused()) | 294 if (!isFocused()) |
| 296 return; | 295 return; |
| 297 | 296 |
| 298 // When typing in a textarea, childrenChanged is not called, so we need to | 297 // When typing in a textarea, childrenChanged is not called, so we need to |
| 299 // force the directionality check. | 298 // force the directionality check. |
| 300 calculateAndAdjustDirectionality(); | 299 calculateAndAdjustDirectionality(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 break; | 352 break; |
| 354 } | 353 } |
| 355 if (submissionLength > maxLength) | 354 if (submissionLength > maxLength) |
| 356 break; | 355 break; |
| 357 } | 356 } |
| 358 if (i > 0 && U16_IS_LEAD(proposedValue[i - 1])) | 357 if (i > 0 && U16_IS_LEAD(proposedValue[i - 1])) |
| 359 --i; | 358 --i; |
| 360 return proposedValue.left(i); | 359 return proposedValue.left(i); |
| 361 } | 360 } |
| 362 | 361 |
| 363 void HTMLTextAreaElement::updateValue() const { | 362 void HTMLTextAreaElement::updateValue() { |
| 364 if (m_valueIsUpToDate) | |
| 365 return; | |
| 366 | |
| 367 m_value = innerEditorValue(); | 363 m_value = innerEditorValue(); |
| 368 const_cast<HTMLTextAreaElement*>(this)->m_valueIsUpToDate = true; | 364 notifyFormStateChanged(); |
| 369 const_cast<HTMLTextAreaElement*>(this)->notifyFormStateChanged(); | |
| 370 m_isDirty = true; | 365 m_isDirty = true; |
| 371 const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility(); | 366 updatePlaceholderVisibility(); |
| 372 } | 367 } |
| 373 | 368 |
| 374 String HTMLTextAreaElement::value() const { | 369 String HTMLTextAreaElement::value() const { |
| 375 updateValue(); | |
| 376 return m_value; | 370 return m_value; |
| 377 } | 371 } |
| 378 | 372 |
| 379 void HTMLTextAreaElement::setValue(const String& value, | 373 void HTMLTextAreaElement::setValue(const String& value, |
| 380 TextFieldEventBehavior eventBehavior, | 374 TextFieldEventBehavior eventBehavior, |
| 381 TextControlSetValueSelection selection) { | 375 TextControlSetValueSelection selection) { |
| 382 setValueCommon(value, eventBehavior, selection); | 376 setValueCommon(value, eventBehavior, selection); |
| 383 m_isDirty = true; | 377 m_isDirty = true; |
| 384 } | 378 } |
| 385 | 379 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 case DispatchNoEvent: | 430 case DispatchNoEvent: |
| 437 // We need to update textAsOfLastFormControlChangeEvent for |value| IDL | 431 // We need to update textAsOfLastFormControlChangeEvent for |value| IDL |
| 438 // setter without focus because input-assist features use setValue("...", | 432 // setter without focus because input-assist features use setValue("...", |
| 439 // DispatchChangeEvent) without setting focus. | 433 // DispatchChangeEvent) without setting focus. |
| 440 if (!isFocused()) | 434 if (!isFocused()) |
| 441 setTextAsOfLastFormControlChangeEvent(normalizedValue); | 435 setTextAsOfLastFormControlChangeEvent(normalizedValue); |
| 442 break; | 436 break; |
| 443 } | 437 } |
| 444 } | 438 } |
| 445 | 439 |
| 446 void HTMLTextAreaElement::setInnerEditorValue(const String& value) { | |
| 447 TextControlElement::setInnerEditorValue(value); | |
| 448 m_valueIsUpToDate = true; | |
| 449 } | |
| 450 | |
| 451 String HTMLTextAreaElement::defaultValue() const { | 440 String HTMLTextAreaElement::defaultValue() const { |
| 452 StringBuilder value; | 441 StringBuilder value; |
| 453 | 442 |
| 454 // Since there may be comments, ignore nodes other than text nodes. | 443 // Since there may be comments, ignore nodes other than text nodes. |
| 455 for (Node* n = firstChild(); n; n = n->nextSibling()) { | 444 for (Node* n = firstChild(); n; n = n->nextSibling()) { |
| 456 if (n->isTextNode()) | 445 if (n->isTextNode()) |
| 457 value.append(toText(n)->data()); | 446 value.append(toText(n)->data()); |
| 458 } | 447 } |
| 459 | 448 |
| 460 return value.toString(); | 449 return value.toString(); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 const Element& source) { | 626 const Element& source) { |
| 638 const HTMLTextAreaElement& sourceElement = | 627 const HTMLTextAreaElement& sourceElement = |
| 639 static_cast<const HTMLTextAreaElement&>(source); | 628 static_cast<const HTMLTextAreaElement&>(source); |
| 640 setValueCommon(sourceElement.value(), DispatchNoEvent, | 629 setValueCommon(sourceElement.value(), DispatchNoEvent, |
| 641 TextControlSetValueSelection::kSetSelectionToEnd); | 630 TextControlSetValueSelection::kSetSelectionToEnd); |
| 642 m_isDirty = sourceElement.m_isDirty; | 631 m_isDirty = sourceElement.m_isDirty; |
| 643 TextControlElement::copyNonAttributePropertiesFromElement(source); | 632 TextControlElement::copyNonAttributePropertiesFromElement(source); |
| 644 } | 633 } |
| 645 | 634 |
| 646 } // namespace blink | 635 } // namespace blink |
| OLD | NEW |