Index: third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
diff --git a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
index 736d889bf286020e88b7afa6ef2f399bf276d8fd..9e57fe1c6d49c16bd2aa137e8e72712efd4e6f12 100644 |
--- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
+++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
@@ -374,6 +374,29 @@ Element* rootEditableElement(const Node& node) { |
return toElement(const_cast<Node*>(result)); |
} |
+bool selectionHasFocus(const SelectionInFlatTree& selection) { |
+ if (selection.isNone()) |
+ return false; |
+ |
+ const Document* document = selection.base().document(); |
+ if (!document) |
yosin_UTC9
2017/03/23 01:26:20
nit: Since selection.isNone() implies selection.ba
hugoh_UTC2
2017/03/23 01:38:06
Done. See PS27.
|
+ return false; |
+ |
+ const Element* focus = document->focusedElement(); |
+ if (!focus) { |
+ // No focused element means document root has focus. |
+ focus = document->documentElement(); |
+ } |
+ |
+ const Node* const nodeWhereSelectionStarts = |
+ selection.base().computeContainerNode(); |
+ const Node* const nodeWhereSelectionEnds = |
+ selection.extent().computeContainerNode(); |
+ |
+ return focus->containsIncludingHostElements(*nodeWhereSelectionStarts) || |
+ focus->containsIncludingHostElements(*nodeWhereSelectionEnds); |
+} |
+ |
ContainerNode* highestEditableRoot( |
const Position& position, |
Element* (*rootEditableElementOf)(const Position&), |