Chromium Code Reviews| Index: Source/core/html/HTMLTextFormControlElement.cpp |
| diff --git a/Source/core/html/HTMLTextFormControlElement.cpp b/Source/core/html/HTMLTextFormControlElement.cpp |
| index 0434728f24a557dcb6aa4a94af75ce08ceaccc60..b7af2c497189936fd728c10d8c1c9fd7b94bad4a 100644 |
| --- a/Source/core/html/HTMLTextFormControlElement.cpp |
| +++ b/Source/core/html/HTMLTextFormControlElement.cpp |
| @@ -282,13 +282,21 @@ void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField |
| if (!renderer() || !renderer()->isTextControl()) |
| return; |
| - end = std::max(end, 0); |
| - start = std::min(std::max(start, 0), end); |
| + 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 (!hasVisibleTextArea(renderer(), innerEditorElement())) { |
| - cacheSelection(start, end, direction); |
| + if (!frame || !shouldSetSelection) |
| return; |
| - } |
| + |
| VisiblePosition startPosition = visiblePositionForIndex(start); |
| VisiblePosition endPosition; |
| if (start == end) |
| @@ -309,8 +317,7 @@ void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextField |
| newSelection = VisibleSelection(startPosition, endPosition); |
| newSelection.setIsDirectional(direction != SelectionHasNoDirection); |
| - if (LocalFrame* frame = document().frame()) |
| - frame->selection().setSelection(newSelection); |
| + frame->selection().setSelection(newSelection); |
| } |
| VisiblePosition HTMLTextFormControlElement::visiblePositionForIndex(int index) const |
| @@ -342,7 +349,6 @@ int HTMLTextFormControlElement::selectionStart() const |
| return 0; |
| if (document().focusedElement() != this) |
| return m_cachedSelectionStart; |
| - |
|
tkent
2014/07/08 00:34:48
nit: This blank line change is unnecessary.
harpreet.sk
2014/07/08 06:07:59
Done.
|
| return computeSelectionStart(); |
| } |
| @@ -477,8 +483,8 @@ 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 (document().focusedElement() == this) |
| + cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelectionDirection()); |
| if (LocalFrame* frame = document().frame()) { |
| if (frame->selection().isRange() && userTriggered) |