Index: third_party/WebKit/Source/core/html/TextControlElement.cpp |
diff --git a/third_party/WebKit/Source/core/html/TextControlElement.cpp b/third_party/WebKit/Source/core/html/TextControlElement.cpp |
index f214cb1c8bbad618e27afd92b3b4c8f2a899c06d..6b7b6f34bc7767a3c9737040319b3bb6a8633525 100644 |
--- a/third_party/WebKit/Source/core/html/TextControlElement.cpp |
+++ b/third_party/WebKit/Source/core/html/TextControlElement.cpp |
@@ -485,9 +485,17 @@ unsigned TextControlElement::selectionStart() const { |
unsigned TextControlElement::computeSelectionStart() const { |
DCHECK(isTextControl()); |
- if (LocalFrame* frame = document().frame()) |
- return indexForPosition(innerEditorElement(), frame->selection().start()); |
- return 0; |
+ LocalFrame* frame = document().frame(); |
+ if (!frame) |
+ return 0; |
+ const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree(); |
+ if (selection.granularity() == CharacterGranularity) { |
+ return indexForPosition(innerEditorElement(), |
+ selection.computeStartPosition()); |
+ } |
+ const VisibleSelection& visibleSelection = |
+ frame->selection().computeVisibleSelectionInDOMTree(); |
+ return indexForPosition(innerEditorElement(), visibleSelection.start()); |
} |
unsigned TextControlElement::selectionEnd() const { |
@@ -500,9 +508,17 @@ unsigned TextControlElement::selectionEnd() const { |
unsigned TextControlElement::computeSelectionEnd() const { |
DCHECK(isTextControl()); |
- if (LocalFrame* frame = document().frame()) |
- return indexForPosition(innerEditorElement(), frame->selection().end()); |
- return 0; |
+ LocalFrame* frame = document().frame(); |
+ if (!frame) |
+ return 0; |
+ const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree(); |
+ if (selection.granularity() == CharacterGranularity) { |
+ return indexForPosition(innerEditorElement(), |
+ selection.computeEndPosition()); |
+ } |
+ const VisibleSelection& visibleSelection = |
+ frame->selection().computeVisibleSelectionInDOMTree(); |
+ return indexForPosition(innerEditorElement(), visibleSelection.end()); |
} |
static const AtomicString& directionString( |
@@ -539,10 +555,11 @@ TextFieldSelectionDirection TextControlElement::computeSelectionDirection() |
if (!frame) |
return SelectionHasNoDirection; |
- const VisibleSelection& selection = frame->selection().selection(); |
+ const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree(); |
+ const Position& start = selection.computeStartPosition(); |
return selection.isDirectional() |
- ? (selection.isBaseFirst() ? SelectionHasForwardDirection |
- : SelectionHasBackwardDirection) |
+ ? (selection.base() == start ? SelectionHasForwardDirection |
+ : SelectionHasBackwardDirection) |
: SelectionHasNoDirection; |
} |
@@ -686,7 +703,7 @@ void TextControlElement::selectionChanged(bool userTriggered) { |
computeSelectionDirection()); |
if (LocalFrame* frame = document().frame()) { |
- if (frame->selection().isRange() && userTriggered) |
+ if (frame->selection().selectionInDOMTree().isRange() && userTriggered) |
dispatchEvent(Event::createBubble(EventTypeNames::select)); |
} |
} |