Chromium Code Reviews| 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 334c6e74659019cc3cbbd7852cc4ecd23cadc981..844e7060a4e17e95e3b029a875e22194cc653e52 100644 |
| --- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| +++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| @@ -372,6 +372,43 @@ Element* rootEditableElement(const Node& node) { |
| return toElement(const_cast<Node*>(result)); |
| } |
| +bool isSelectionInDocument(const VisibleSelectionInFlatTree& visibleSelection, |
| + const Document& document) { |
| + const PositionInFlatTree& start = visibleSelection.start(); |
| + if (start.isNotNull() && |
| + (!start.isConnected() || start.document() != document)) |
| + return false; |
| + const PositionInFlatTree& end = visibleSelection.end(); |
| + if (end.isNotNull() && (!end.isConnected() || end.document() != document)) |
| + return false; |
| + const PositionInFlatTree extent = visibleSelection.extent(); |
| + if (extent.isNotNull() && |
| + (!extent.isConnected() || extent.document() != document)) |
| + return false; |
| + return true; |
| +} |
| + |
| +bool selectionHasFocus(const LocalFrame& frame) { |
| + const VisibleSelectionInFlatTree& selection = |
| + frame.selection().computeVisibleSelectionInFlatTree(); |
| + if (!isSelectionInDocument(selection, *frame.document())) |
|
yosin_UTC9
2017/03/21 06:49:59
We can assume SelectionInFlatTree in FrameSelecito
hugoh_UTC2
2017/03/22 02:54:47
Done.
|
| + return false; |
| + |
| + const Element* focus = frame.document()->focusedElement(); |
| + if (!focus) { |
| + // No focused element means document root has focus. |
| + focus = frame.document()->documentElement(); |
| + } |
| + |
| + const Node* const nodeWhereSelectionStarts = |
|
yosin_UTC9
2017/03/21 06:49:59
To check base/extent in focus element, we don't ne
hugoh_UTC2
2017/03/22 02:54:47
FrameSelection has no public getter that returns t
|
| + 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&), |