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

Unified Diff: third_party/WebKit/Source/core/html/TextControlElement.cpp

Issue 2735633006: INPUT/TEXTAREA elements: Dispatch 'select' event only if text selection is changed. (Closed)
Patch Set: . Created 3 years, 9 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
Index: third_party/WebKit/Source/core/html/TextControlElement.cpp
diff --git a/third_party/WebKit/Source/core/html/TextControlElement.cpp b/third_party/WebKit/Source/core/html/TextControlElement.cpp
index 71f9b7796e538155913811dbe66603e9239174dd..59ca8766c8e7d40b5c158e994ea7561f2ffd4948 100644
--- a/third_party/WebKit/Source/core/html/TextControlElement.cpp
+++ b/third_party/WebKit/Source/core/html/TextControlElement.cpp
@@ -291,7 +291,8 @@ void TextControlElement::setRangeText(const String& replacement,
else
text.insert(replacement, start);
- setValue(text, TextFieldEventBehavior::DispatchNoEvent);
+ setValue(text, TextFieldEventBehavior::DispatchNoEvent,
+ TextControlSetValueSelection::kDoNotSet);
if (selectionMode == "select") {
newSelectionStart = start;
@@ -410,14 +411,14 @@ bool TextControlElement::setSelectionRange(
if (direction == SelectionHasNoDirection && frame &&
frame->editor().behavior().shouldConsiderSelectionAsDirectional())
direction = SelectionHasForwardDirection;
- cacheSelection(start, end, direction);
+ bool didChange = cacheSelection(start, end, direction);
if (document().focusedElement() != this)
- return true;
+ return didChange;
HTMLElement* innerEditor = innerEditorElement();
if (!frame || !innerEditor)
- return true;
+ return didChange;
Position startPosition = positionForIndex(innerEditor, start);
Position endPosition =
@@ -444,7 +445,20 @@ bool TextControlElement::setSelectionRange(
.build(),
FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle |
FrameSelection::DoNotSetFocus);
- return true;
+ return didChange;
+}
+
+bool TextControlElement::cacheSelection(unsigned start,
+ unsigned end,
+ TextFieldSelectionDirection direction) {
+ DCHECK_LE(start, end);
+ bool didChange = m_cachedSelectionStart != start ||
+ m_cachedSelectionEnd != end ||
+ m_cachedSelectionDirection != direction;
+ m_cachedSelectionStart = start;
+ m_cachedSelectionEnd = end;
+ m_cachedSelectionDirection = direction;
+ return didChange;
}
VisiblePosition TextControlElement::visiblePositionForIndex(int index) const {

Powered by Google App Engine
This is Rietveld 408576698