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

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

Issue 258063005: 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: Addressing the expected behavior and changes asked for LayoutTests Created 6 years, 7 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: Source/core/html/HTMLTextFormControlElement.cpp
diff --git a/Source/core/html/HTMLTextFormControlElement.cpp b/Source/core/html/HTMLTextFormControlElement.cpp
index bf3597a17159f2e0cad756e6e8be0ffc25b2bc4c..cda62387ff36d31657fbb0608b074667030b8a56 100644
--- a/Source/core/html/HTMLTextFormControlElement.cpp
+++ b/Source/core/html/HTMLTextFormControlElement.cpp
@@ -164,12 +164,12 @@ void HTMLTextFormControlElement::updatePlaceholderVisibility(bool placeholderVal
void HTMLTextFormControlElement::setSelectionStart(int start)
{
- setSelectionRange(start, max(start, selectionEnd()), selectionDirection());
+ setSelectionRange(start, max(start, selectionEndForJavascriptBindings()), selectionDirection());
}
void HTMLTextFormControlElement::setSelectionEnd(int end)
{
- setSelectionRange(min(end, selectionStart()), end, selectionDirection());
+ setSelectionRange(min(end, selectionStartForJavascriptBindings()), end, selectionDirection());
}
void HTMLTextFormControlElement::setSelectionDirection(const String& direction)
@@ -285,11 +285,10 @@ void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField
end = max(end, 0);
start = min(max(start, 0), end);
+ cacheSelection(start, end, direction);
- if (!hasVisibleTextArea(renderer(), innerTextElement())) {
- cacheSelection(start, end, direction);
+ if (!hasVisibleTextArea(renderer(), innerTextElement()))
return;
- }
VisiblePosition startPosition = visiblePositionForIndex(start);
VisiblePosition endPosition;
if (start == end)
@@ -341,6 +340,19 @@ int HTMLTextFormControlElement::selectionStart() const
{
if (!isTextFormControl())
return 0;
+ if (document().focusedElement() != this) {
tkent 2014/05/19 00:00:34 We should not need to adjust the value on getting.
harpreet.sk 2014/05/19 11:16:52 Only for given case we need to adjust value while
+ if (!innerTextValue().length())
+ return 0;
+ return m_cachedSelectionStart;
+ }
+
+ return computeSelectionStart();
+}
+
+int HTMLTextFormControlElement::selectionStartForJavascriptBindings() const
+{
+ if (!isTextFormControl())
+ return 0;
if (document().focusedElement() != this)
return m_cachedSelectionStart;
@@ -361,8 +373,21 @@ int HTMLTextFormControlElement::selectionEnd() const
{
if (!isTextFormControl())
return 0;
+ if (document().focusedElement() != this) {
+ if (!innerTextValue().length())
+ return 0;
+ return m_cachedSelectionEnd;
+ }
+ return computeSelectionEnd();
+}
+
+int HTMLTextFormControlElement::selectionEndForJavascriptBindings() const
+{
+ if (!isTextFormControl())
+ return 0;
if (document().focusedElement() != this)
return m_cachedSelectionEnd;
+
return computeSelectionEnd();
}
@@ -478,9 +503,6 @@ void HTMLTextFormControlElement::selectionChanged(bool userTriggered)
if (!renderer() || !isTextFormControl())
return;
- // 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)
dispatchEvent(Event::createBubble(EventTypeNames::select));

Powered by Google App Engine
This is Rietveld 408576698