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)); |