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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 { | 331 { |
| 332 updateValue(); | 332 updateValue(); |
| 333 return m_value; | 333 return m_value; |
| 334 } | 334 } |
| 335 | 335 |
| 336 void HTMLTextAreaElement::setValue(const String& value, TextFieldEventBehavior e ventBehavior) | 336 void HTMLTextAreaElement::setValue(const String& value, TextFieldEventBehavior e ventBehavior) |
| 337 { | 337 { |
| 338 RefPtrWillBeRawPtr<HTMLTextAreaElement> protector(this); | 338 RefPtrWillBeRawPtr<HTMLTextAreaElement> protector(this); |
| 339 setValueCommon(value, eventBehavior); | 339 setValueCommon(value, eventBehavior); |
| 340 m_isDirty = true; | 340 m_isDirty = true; |
| 341 setNeedsValidityCheck(); | |
| 342 if (document().focusedElement() == this) | 341 if (document().focusedElement() == this) |
| 343 document().frameHost()->chrome().client().didUpdateTextOfFocusedElementB yNonUserInput(); | 342 document().frameHost()->chrome().client().didUpdateTextOfFocusedElementB yNonUserInput(); |
| 344 } | 343 } |
| 345 | 344 |
| 346 void HTMLTextAreaElement::setNonDirtyValue(const String& value) | 345 void HTMLTextAreaElement::setNonDirtyValue(const String& value) |
| 347 { | 346 { |
| 348 setValueCommon(value, DispatchNoEvent); | 347 setValueCommon(value, DispatchNoEvent, ChangeSelection); |
| 349 m_isDirty = false; | 348 m_isDirty = false; |
| 350 setNeedsValidityCheck(); | |
| 351 } | 349 } |
| 352 | 350 |
| 353 void HTMLTextAreaElement::setValueCommon(const String& newValue, TextFieldEventB ehavior eventBehavior) | 351 void HTMLTextAreaElement::setValueCommon(const String& newValue, TextFieldEventB ehavior eventBehavior, SelectionOption selectionOption) |
| 354 { | 352 { |
| 355 // Code elsewhere normalizes line endings added by the user via the keyboard or pasting. | 353 // Code elsewhere normalizes line endings added by the user via the keyboard or pasting. |
| 356 // We normalize line endings coming from JavaScript here. | 354 // We normalize line endings coming from JavaScript here. |
| 357 String normalizedValue = newValue.isNull() ? "" : newValue; | 355 String normalizedValue = newValue.isNull() ? "" : newValue; |
| 358 normalizedValue.replace("\r\n", "\n"); | 356 normalizedValue.replace("\r\n", "\n"); |
| 359 normalizedValue.replace('\r', '\n'); | 357 normalizedValue.replace('\r', '\n'); |
| 360 | 358 |
| 361 // Return early because we don't want to move the caret or trigger other sid e effects | 359 // Return early because we don't want to trigger other side effects |
| 362 // when the value isn't changing. This matches Firefox behavior, at least. | 360 // when the value isn't changing. |
| 363 if (normalizedValue == value()) | 361 // FIXME: Simple early return doesn't match the Firefox ever. |
| 362 // Remove these lines. | |
| 363 if (normalizedValue == value()) { | |
| 364 if (selectionOption == ChangeSelection) { | |
| 365 setNeedsValidityCheck(); | |
| 366 if (isFinishedParsingChildren()) { | |
| 367 // Set the caret to the end of the text value except for initial ize. | |
| 368 unsigned endOfString = m_value.length(); | |
| 369 setSelectionRange(endOfString, endOfString, SelectionHasNoDirect ion, NotChangeSelection); | |
| 370 } | |
| 371 } | |
| 364 return; | 372 return; |
| 373 } | |
| 365 | 374 |
| 366 m_value = normalizedValue; | 375 m_value = normalizedValue; |
| 367 setInnerEditorValue(m_value); | 376 setInnerEditorValue(m_value); |
| 368 if (eventBehavior == DispatchNoEvent) | 377 if (eventBehavior == DispatchNoEvent) |
| 369 setLastChangeWasNotUserEdit(); | 378 setLastChangeWasNotUserEdit(); |
| 370 updatePlaceholderVisibility(false); | 379 updatePlaceholderVisibility(false); |
| 371 setNeedsStyleRecalc(SubtreeStyleChange); | 380 setNeedsStyleRecalc(SubtreeStyleChange); |
| 372 m_suggestedValue = String(); | 381 m_suggestedValue = String(); |
| 373 | 382 setNeedsValidityCheck(); |
|
yoichio
2014/07/24 03:06:07
Moved from setSelectionRange, setValue and setNonD
| |
| 374 // Set the caret to the end of the text value. | 383 if (isFinishedParsingChildren()) { |
| 375 if (document().focusedElement() == this) { | 384 // Set the caret to the end of the text value except for initialize. |
| 376 unsigned endOfString = m_value.length(); | 385 unsigned endOfString = m_value.length(); |
| 377 setSelectionRange(endOfString, endOfString); | 386 setSelectionRange(endOfString, endOfString, SelectionHasNoDirection, Not ChangeSelection); |
| 378 } | 387 } |
| 379 | 388 |
| 380 notifyFormStateChanged(); | 389 notifyFormStateChanged(); |
| 381 if (eventBehavior == DispatchNoEvent) { | 390 if (eventBehavior == DispatchNoEvent) { |
| 382 setTextAsOfLastFormControlChangeEvent(normalizedValue); | 391 setTextAsOfLastFormControlChangeEvent(normalizedValue); |
| 383 } else { | 392 } else { |
| 384 if (eventBehavior == DispatchInputAndChangeEvent) | 393 if (eventBehavior == DispatchInputAndChangeEvent) |
| 385 dispatchFormControlInputEvent(); | 394 dispatchFormControlInputEvent(); |
| 386 dispatchFormControlChangeEvent(); | 395 dispatchFormControlChangeEvent(); |
| 387 } | 396 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 { | 565 { |
| 557 return true; | 566 return true; |
| 558 } | 567 } |
| 559 | 568 |
| 560 bool HTMLTextAreaElement::supportsAutofocus() const | 569 bool HTMLTextAreaElement::supportsAutofocus() const |
| 561 { | 570 { |
| 562 return true; | 571 return true; |
| 563 } | 572 } |
| 564 | 573 |
| 565 } | 574 } |
| OLD | NEW |