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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 { | 76 { |
| 77 return text.length() + numberOfLineBreaks(text); | 77 return text.length() + numberOfLineBreaks(text); |
| 78 } | 78 } |
| 79 | 79 |
| 80 HTMLTextAreaElement::HTMLTextAreaElement(Document& document, HTMLFormElement* fo rm) | 80 HTMLTextAreaElement::HTMLTextAreaElement(Document& document, HTMLFormElement* fo rm) |
| 81 : HTMLTextFormControlElement(textareaTag, document, form) | 81 : HTMLTextFormControlElement(textareaTag, document, form) |
| 82 , m_rows(defaultRows) | 82 , m_rows(defaultRows) |
| 83 , m_cols(defaultCols) | 83 , m_cols(defaultCols) |
| 84 , m_wrap(SoftWrap) | 84 , m_wrap(SoftWrap) |
| 85 , m_isDirty(false) | 85 , m_isDirty(false) |
| 86 , m_valueIsUpToDate(true) | |
| 87 { | 86 { |
| 88 ScriptWrappable::init(this); | 87 ScriptWrappable::init(this); |
| 89 } | 88 } |
| 90 | 89 |
| 91 PassRefPtrWillBeRawPtr<HTMLTextAreaElement> HTMLTextAreaElement::create(Document & document, HTMLFormElement* form) | 90 PassRefPtrWillBeRawPtr<HTMLTextAreaElement> HTMLTextAreaElement::create(Document & document, HTMLFormElement* form) |
| 92 { | 91 { |
| 93 RefPtrWillBeRawPtr<HTMLTextAreaElement> textArea = adoptRefWillBeNoop(new HT MLTextAreaElement(document, form)); | 92 RefPtrWillBeRawPtr<HTMLTextAreaElement> textArea = adoptRefWillBeNoop(new HT MLTextAreaElement(document, form)); |
| 94 textArea->ensureUserAgentShadowRoot(); | 93 textArea->ensureUserAgentShadowRoot(); |
| 95 return textArea.release(); | 94 return textArea.release(); |
| 96 } | 95 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 | 260 |
| 262 void HTMLTextAreaElement::handleFocusEvent(Element*, FocusType) | 261 void HTMLTextAreaElement::handleFocusEvent(Element*, FocusType) |
| 263 { | 262 { |
| 264 if (LocalFrame* frame = document().frame()) | 263 if (LocalFrame* frame = document().frame()) |
| 265 frame->spellChecker().didBeginEditing(this); | 264 frame->spellChecker().didBeginEditing(this); |
| 266 } | 265 } |
| 267 | 266 |
| 268 void HTMLTextAreaElement::subtreeHasChanged() | 267 void HTMLTextAreaElement::subtreeHasChanged() |
| 269 { | 268 { |
| 270 setChangedSinceLastFormControlChangeEvent(true); | 269 setChangedSinceLastFormControlChangeEvent(true); |
| 271 m_valueIsUpToDate = false; | 270 // Update Value to match the renderer |
| 271 updateValue(); | |
| 272 setNeedsValidityCheck(); | 272 setNeedsValidityCheck(); |
| 273 setAutofilled(false); | 273 setAutofilled(false); |
| 274 | 274 |
| 275 if (!focused()) | 275 if (!focused()) |
| 276 return; | 276 return; |
| 277 | 277 |
| 278 // When typing in a textarea, childrenChanged is not called, so we need to f orce the directionality check. | 278 // When typing in a textarea, childrenChanged is not called, so we need to f orce the directionality check. |
| 279 calculateAndAdjustDirectionality(); | 279 calculateAndAdjustDirectionality(); |
| 280 | 280 |
| 281 ASSERT(document().isActive()); | 281 ASSERT(document().isActive()); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 310 | 310 |
| 311 String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue, unsigned maxLength) | 311 String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue, unsigned maxLength) |
| 312 { | 312 { |
| 313 if (maxLength > 0 && U16_IS_LEAD(proposedValue[maxLength - 1])) | 313 if (maxLength > 0 && U16_IS_LEAD(proposedValue[maxLength - 1])) |
| 314 --maxLength; | 314 --maxLength; |
| 315 return proposedValue.left(maxLength); | 315 return proposedValue.left(maxLength); |
| 316 } | 316 } |
| 317 | 317 |
| 318 void HTMLTextAreaElement::updateValue() const | 318 void HTMLTextAreaElement::updateValue() const |
| 319 { | 319 { |
| 320 if (m_valueIsUpToDate) | |
| 321 return; | |
| 322 | |
| 323 ASSERT(renderer()); | 320 ASSERT(renderer()); |
| 324 m_value = innerEditorValue(); | 321 m_value = innerEditorValue(); |
| 325 const_cast<HTMLTextAreaElement*>(this)->m_valueIsUpToDate = true; | |
| 326 const_cast<HTMLTextAreaElement*>(this)->notifyFormStateChanged(); | 322 const_cast<HTMLTextAreaElement*>(this)->notifyFormStateChanged(); |
| 327 m_isDirty = true; | 323 m_isDirty = true; |
| 328 const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility(false); | 324 const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility(false); |
| 329 } | 325 } |
| 330 | 326 |
| 331 String HTMLTextAreaElement::value() const | 327 String HTMLTextAreaElement::value() const |
| 332 { | 328 { |
| 333 updateValue(); | |
|
spartha
2014/09/02 14:09:55
Replaced by a call from subTreeChanged()
| |
| 334 return m_value; | 329 return m_value; |
| 335 } | 330 } |
| 336 | 331 |
| 337 void HTMLTextAreaElement::setValue(const String& value, TextFieldEventBehavior e ventBehavior) | 332 void HTMLTextAreaElement::setValue(const String& value, TextFieldEventBehavior e ventBehavior) |
| 338 { | 333 { |
| 339 RefPtrWillBeRawPtr<HTMLTextAreaElement> protector(this); | 334 RefPtrWillBeRawPtr<HTMLTextAreaElement> protector(this); |
| 340 setValueCommon(value, eventBehavior); | 335 setValueCommon(value, eventBehavior); |
| 341 m_isDirty = true; | 336 m_isDirty = true; |
| 342 if (document().focusedElement() == this) | 337 if (document().focusedElement() == this) |
| 343 document().frameHost()->chrome().client().didUpdateTextOfFocusedElementB yNonUserInput(); | 338 document().frameHost()->chrome().client().didUpdateTextOfFocusedElementB yNonUserInput(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 notifyFormStateChanged(); | 385 notifyFormStateChanged(); |
| 391 if (eventBehavior == DispatchNoEvent) { | 386 if (eventBehavior == DispatchNoEvent) { |
| 392 setTextAsOfLastFormControlChangeEvent(normalizedValue); | 387 setTextAsOfLastFormControlChangeEvent(normalizedValue); |
| 393 } else { | 388 } else { |
| 394 if (eventBehavior == DispatchInputAndChangeEvent) | 389 if (eventBehavior == DispatchInputAndChangeEvent) |
| 395 dispatchFormControlInputEvent(); | 390 dispatchFormControlInputEvent(); |
| 396 dispatchFormControlChangeEvent(); | 391 dispatchFormControlChangeEvent(); |
| 397 } | 392 } |
| 398 } | 393 } |
| 399 | 394 |
| 400 void HTMLTextAreaElement::setInnerEditorValue(const String& value) | |
| 401 { | |
| 402 HTMLTextFormControlElement::setInnerEditorValue(value); | |
| 403 m_valueIsUpToDate = true; | |
| 404 } | |
| 405 | |
| 406 String HTMLTextAreaElement::defaultValue() const | 395 String HTMLTextAreaElement::defaultValue() const |
| 407 { | 396 { |
| 408 StringBuilder value; | 397 StringBuilder value; |
| 409 | 398 |
| 410 // Since there may be comments, ignore nodes other than text nodes. | 399 // Since there may be comments, ignore nodes other than text nodes. |
| 411 for (Node* n = firstChild(); n; n = n->nextSibling()) { | 400 for (Node* n = firstChild(); n; n = n->nextSibling()) { |
| 412 if (n->isTextNode()) | 401 if (n->isTextNode()) |
| 413 value.append(toText(n)->data()); | 402 value.append(toText(n)->data()); |
| 414 } | 403 } |
| 415 | 404 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 { | 555 { |
| 567 return true; | 556 return true; |
| 568 } | 557 } |
| 569 | 558 |
| 570 bool HTMLTextAreaElement::supportsAutofocus() const | 559 bool HTMLTextAreaElement::supportsAutofocus() const |
| 571 { | 560 { |
| 572 return true; | 561 return true; |
| 573 } | 562 } |
| 574 | 563 |
| 575 } | 564 } |
| OLD | NEW |