| Index: Source/core/html/HTMLTextFormControlElement.cpp
|
| diff --git a/Source/core/html/HTMLTextFormControlElement.cpp b/Source/core/html/HTMLTextFormControlElement.cpp
|
| index c3f751a63f54d4eb643bdb97275b0ecbe1ae555c..816371b5a1c49296f951c303d8cb7eba837d3125 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)
|
| @@ -279,11 +279,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)
|
| @@ -335,6 +334,20 @@ int HTMLTextFormControlElement::selectionStart() const
|
| {
|
| if (!isTextFormControl())
|
| return 0;
|
| + if (document().focusedElement() != this) {
|
| + int innerTextLength = innerTextValue().length();
|
| + if (innerTextLength < m_cachedSelectionStart)
|
| + return innerTextLength;
|
| + return m_cachedSelectionStart;
|
| + }
|
| +
|
| + return computeSelectionStart();
|
| +}
|
| +
|
| +int HTMLTextFormControlElement::selectionStartForJavascriptBindings() const
|
| +{
|
| + if (!isTextFormControl())
|
| + return 0;
|
| if (document().focusedElement() != this)
|
| return m_cachedSelectionStart;
|
|
|
| @@ -355,8 +368,22 @@ int HTMLTextFormControlElement::selectionEnd() const
|
| {
|
| if (!isTextFormControl())
|
| return 0;
|
| + if (document().focusedElement() != this) {
|
| + int innerTextLength = innerTextValue().length();
|
| + if (innerTextLength < m_cachedSelectionEnd)
|
| + return innerTextLength;
|
| + return m_cachedSelectionEnd;
|
| + }
|
| + return computeSelectionEnd();
|
| +}
|
| +
|
| +int HTMLTextFormControlElement::selectionEndForJavascriptBindings() const
|
| +{
|
| + if (!isTextFormControl())
|
| + return 0;
|
| if (document().focusedElement() != this)
|
| return m_cachedSelectionEnd;
|
| +
|
| return computeSelectionEnd();
|
| }
|
|
|
| @@ -472,9 +499,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));
|
|
|