Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1128)

Unified Diff: Source/core/html/HTMLTextAreaElement.cpp

Issue 392573002: HTMLTextAreaElement.setSelectionRange should not change focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix tests Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLTextAreaElement.h ('k') | Source/core/html/HTMLTextFormControlElement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLTextAreaElement.cpp
diff --git a/Source/core/html/HTMLTextAreaElement.cpp b/Source/core/html/HTMLTextAreaElement.cpp
index fd7ad6434bc60392e35ebe11871ee0c35cb2c472..7ca0838c5313cde3fb9694071bf6070a5c014000 100644
--- a/Source/core/html/HTMLTextAreaElement.cpp
+++ b/Source/core/html/HTMLTextAreaElement.cpp
@@ -338,19 +338,17 @@ void HTMLTextAreaElement::setValue(const String& value, TextFieldEventBehavior e
RefPtrWillBeRawPtr<HTMLTextAreaElement> protector(this);
setValueCommon(value, eventBehavior);
m_isDirty = true;
- setNeedsValidityCheck();
if (document().focusedElement() == this)
document().frameHost()->chrome().client().didUpdateTextOfFocusedElementByNonUserInput();
}
void HTMLTextAreaElement::setNonDirtyValue(const String& value)
{
- setValueCommon(value, DispatchNoEvent);
+ setValueCommon(value, DispatchNoEvent, ChangeSelection);
m_isDirty = false;
- setNeedsValidityCheck();
}
-void HTMLTextAreaElement::setValueCommon(const String& newValue, TextFieldEventBehavior eventBehavior)
+void HTMLTextAreaElement::setValueCommon(const String& newValue, TextFieldEventBehavior eventBehavior, SelectionOption selectionOption)
{
// Code elsewhere normalizes line endings added by the user via the keyboard or pasting.
// We normalize line endings coming from JavaScript here.
@@ -358,10 +356,21 @@ void HTMLTextAreaElement::setValueCommon(const String& newValue, TextFieldEventB
normalizedValue.replace("\r\n", "\n");
normalizedValue.replace('\r', '\n');
- // Return early because we don't want to move the caret or trigger other side effects
- // when the value isn't changing. This matches Firefox behavior, at least.
- if (normalizedValue == value())
+ // Return early because we don't want to trigger other side effects
+ // when the value isn't changing.
+ // FIXME: Simple early return doesn't match the Firefox ever.
+ // Remove these lines.
+ if (normalizedValue == value()) {
+ if (selectionOption == ChangeSelection) {
+ setNeedsValidityCheck();
+ if (isFinishedParsingChildren()) {
+ // Set the caret to the end of the text value except for initialize.
+ unsigned endOfString = m_value.length();
+ setSelectionRange(endOfString, endOfString, SelectionHasNoDirection, NotChangeSelection);
+ }
+ }
return;
+ }
m_value = normalizedValue;
setInnerEditorValue(m_value);
@@ -370,11 +379,11 @@ void HTMLTextAreaElement::setValueCommon(const String& newValue, TextFieldEventB
updatePlaceholderVisibility(false);
setNeedsStyleRecalc(SubtreeStyleChange);
m_suggestedValue = String();
-
- // Set the caret to the end of the text value.
- if (document().focusedElement() == this) {
+ setNeedsValidityCheck();
+ if (isFinishedParsingChildren()) {
+ // Set the caret to the end of the text value except for initialize.
unsigned endOfString = m_value.length();
- setSelectionRange(endOfString, endOfString);
+ setSelectionRange(endOfString, endOfString, SelectionHasNoDirection, NotChangeSelection);
}
notifyFormStateChanged();
« no previous file with comments | « Source/core/html/HTMLTextAreaElement.h ('k') | Source/core/html/HTMLTextFormControlElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698