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

Unified Diff: third_party/WebKit/Source/core/html/TextControlElement.cpp

Issue 2698793003: Get rid of redundant layout tree update related to selection (Closed)
Patch Set: 2017-02-17T00:37:54 FrameSelection::selectFrameElementInParentIfFullySelected() to use FS::isRange() Created 3 years, 10 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: 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..8669007430f601925ca7f2572051adad2a1e0d76 100644
--- a/third_party/WebKit/Source/core/html/TextControlElement.cpp
+++ b/third_party/WebKit/Source/core/html/TextControlElement.cpp
@@ -485,9 +485,16 @@ 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) {
yoichio 2017/02/17 04:35:16 Why do you split case on granularity?
yosin_UTC9 2017/02/17 05:14:49 I introduce SelectionTemplate::computeSelectionTyp
+ return indexForPosition(innerEditorElement(),
+ selection.computeStartPosition());
+ }
+ const VisibleSelection& visibleSelection = frame->selection().selection();
+ return indexForPosition(innerEditorElement(), visibleSelection.start());
}
unsigned TextControlElement::selectionEnd() const {
@@ -500,9 +507,16 @@ 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().selection();
+ return indexForPosition(innerEditorElement(), visibleSelection.end());
}
static const AtomicString& directionString(
@@ -539,10 +553,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;
}
@@ -685,10 +700,15 @@ void TextControlElement::selectionChanged(bool userTriggered) {
cacheSelection(computeSelectionStart(), computeSelectionEnd(),
computeSelectionDirection());
- if (LocalFrame* frame = document().frame()) {
- if (frame->selection().isRange() && userTriggered)
- dispatchEvent(Event::createBubble(EventTypeNames::select));
- }
+ LocalFrame* frame = document().frame();
+ if (!frame || !userTriggered)
+ return;
+ const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree();
+ if (selection.isNone())
+ return;
+ if (selection.isCaret() && selection.granularity() == CharacterGranularity)
+ return;
+ dispatchEvent(Event::createBubble(EventTypeNames::select));
}
void TextControlElement::scheduleSelectEvent() {

Powered by Google App Engine
This is Rietveld 408576698