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; |
} |