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

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

Issue 374883004: Revert of Blink does not respect input.selectionStart and input.selectionEnd for some cases (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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 | « LayoutTests/fast/forms/validationMessage.html ('k') | Source/core/html/forms/TextFieldInputType.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLTextFormControlElement.cpp
diff --git a/Source/core/html/HTMLTextFormControlElement.cpp b/Source/core/html/HTMLTextFormControlElement.cpp
index 3ce8c61419cf9ea69ab0bc1de60dc03180087b30..0434728f24a557dcb6aa4a94af75ce08ceaccc60 100644
--- a/Source/core/html/HTMLTextFormControlElement.cpp
+++ b/Source/core/html/HTMLTextFormControlElement.cpp
@@ -282,21 +282,13 @@
if (!renderer() || !renderer()->isTextControl())
return;
- int textLength = innerEditorValue().length();
- end = std::max(std::min(end, textLength), 0);
- start = std::max(std::min(start, end), 0);
- cacheSelection(start, end, direction);
- bool isCaretSelection = start == end;
- bool shouldSetSelection = document().focusedElement() == this || (!isCaretSelection && start < textLength);
-
- if (!hasVisibleTextArea(renderer(), innerEditorElement()))
- return;
-
- LocalFrame* frame = document().frame();
-
- if (!frame || !shouldSetSelection)
- return;
-
+ end = std::max(end, 0);
+ start = std::min(std::max(start, 0), end);
+
+ if (!hasVisibleTextArea(renderer(), innerEditorElement())) {
+ cacheSelection(start, end, direction);
+ return;
+ }
VisiblePosition startPosition = visiblePositionForIndex(start);
VisiblePosition endPosition;
if (start == end)
@@ -317,7 +309,8 @@
newSelection = VisibleSelection(startPosition, endPosition);
newSelection.setIsDirectional(direction != SelectionHasNoDirection);
- frame->selection().setSelection(newSelection);
+ if (LocalFrame* frame = document().frame())
+ frame->selection().setSelection(newSelection);
}
VisiblePosition HTMLTextFormControlElement::visiblePositionForIndex(int index) const
@@ -484,8 +477,8 @@
if (!renderer() || !isTextFormControl())
return;
- if (document().focusedElement() == this)
- cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelectionDirection());
+ // selectionStart() or selectionEnd() will return cached selection when this node doesn't have focus
+ cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelectionDirection());
if (LocalFrame* frame = document().frame()) {
if (frame->selection().isRange() && userTriggered)
« no previous file with comments | « LayoutTests/fast/forms/validationMessage.html ('k') | Source/core/html/forms/TextFieldInputType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698