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

Unified Diff: third_party/WebKit/Source/core/editing/PendingSelection.cpp

Issue 2616623002: Do not send redundant selectionchange-events (decouple focus) (Closed)
Patch Set: Fix LayoutTests that create selections within SVG documents Created 3 years, 9 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/editing/PendingSelection.cpp
diff --git a/third_party/WebKit/Source/core/editing/PendingSelection.cpp b/third_party/WebKit/Source/core/editing/PendingSelection.cpp
index 1b106656d49673990d8f12016ed2f04fad889264..1a52dcc68f36be1a3e7046923a281e6477df1a97 100644
--- a/third_party/WebKit/Source/core/editing/PendingSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/PendingSelection.cpp
@@ -106,6 +106,27 @@ SelectionInFlatTree PendingSelection::calcVisibleSelection(
return builder.build();
}
+static bool selectionHasFocus(const LayoutView& layoutView,
+ const VisibleSelectionInFlatTree& selection) {
+ if (!isSelectionInDocument(selection, layoutView.document()))
+ return false;
+
+ const LocalFrame* const frame = layoutView.document().frame();
+ const Element* focus = frame->document()->focusedElement();
+ if (!focus) {
+ // No focused element means document has focus.
+ focus = layoutView.document().documentElement();
hugoh_UTC2 2017/03/10 10:10:37 I use document().documentElement(), not document.b
+ }
+
+ const Node* const nodeWhereSelectionStarts =
+ selection.base().computeContainerNode();
+ const Node* const nodeWhereSelectionEnds =
+ selection.extent().computeContainerNode();
+
+ return focus->containsIncludingHostElements(*nodeWhereSelectionStarts) ||
+ focus->containsIncludingHostElements(*nodeWhereSelectionEnds);
+}
+
void PendingSelection::commit(LayoutView& layoutView) {
if (!hasPendingSelection())
return;
@@ -126,7 +147,7 @@ void PendingSelection::commit(LayoutView& layoutView) {
const VisibleSelectionInFlatTree& selection =
createVisibleSelection(calcVisibleSelection(originalSelection));
- if (!selection.isRange()) {
+ if (!selection.isRange() || !selectionHasFocus(layoutView, selection)) {
layoutView.clearSelection();
return;
}

Powered by Google App Engine
This is Rietveld 408576698