| Index: third_party/WebKit/Source/core/page/FocusController.cpp
|
| diff --git a/third_party/WebKit/Source/core/page/FocusController.cpp b/third_party/WebKit/Source/core/page/FocusController.cpp
|
| index e4cdd7edc64cfd225d5b7c4397867fada83a7576..383f1623b0b046285b32c9e0537673b3ddb79e4d 100644
|
| --- a/third_party/WebKit/Source/core/page/FocusController.cpp
|
| +++ b/third_party/WebKit/Source/core/page/FocusController.cpp
|
| @@ -1039,10 +1039,6 @@ bool FocusController::advanceFocusInDocumentOrder(
|
|
|
| setFocusedFrame(newDocument.frame());
|
|
|
| - if (!element->isTextControl() && !hasEditableStyle(*element->toNode())) {
|
| - // TODO(editing-dev): Remove this clear(), crbug.com/692898.
|
| - focusedFrame()->selection().clear();
|
| - }
|
| element->focus(
|
| FocusParams(SelectionBehaviorOnFocus::Reset, type, sourceCapabilities));
|
| return true;
|
| @@ -1069,6 +1065,35 @@ static bool relinquishesEditingFocus(const Element& element) {
|
| return element.document().frame() && rootEditableElement(element);
|
| }
|
|
|
| +static void clearSelectionIfNeeded(LocalFrame* oldFocusedFrame,
|
| + LocalFrame* newFocusedFrame,
|
| + Element* newFocusedElement) {
|
| + if (!oldFocusedFrame || !newFocusedFrame)
|
| + return;
|
| +
|
| + if (oldFocusedFrame->document() != newFocusedFrame->document())
|
| + return;
|
| +
|
| + FrameSelection& selection = oldFocusedFrame->selection();
|
| + const SelectionInDOMTree& selectionInDOMTree = selection.selectionInDOMTree();
|
| + if (selectionInDOMTree.isNone())
|
| + return;
|
| +
|
| + Node* selectionStartNode = selectionInDOMTree.base().anchorNode();
|
| + if (selectionStartNode == newFocusedElement ||
|
| + selectionStartNode->isDescendantOf(newFocusedElement))
|
| + return;
|
| +
|
| + if (!enclosingTextControl(selectionStartNode))
|
| + return;
|
| +
|
| + if (selectionStartNode->isInShadowTree() &&
|
| + selectionStartNode->ownerShadowHost() == newFocusedElement)
|
| + return;
|
| +
|
| + selection.clear();
|
| +}
|
| +
|
| bool FocusController::setFocusedElement(Element* element,
|
| Frame* newFocusedFrame) {
|
| return setFocusedElement(
|
| @@ -1105,6 +1130,10 @@ bool FocusController::setFocusedElement(Element* element,
|
| newDocument->focusedElement() == element)
|
| return true;
|
|
|
| + if (newFocusedFrame && newFocusedFrame->isLocalFrame())
|
| + clearSelectionIfNeeded(oldFocusedFrame, toLocalFrame(newFocusedFrame),
|
| + element);
|
| +
|
| if (oldDocument && oldDocument != newDocument)
|
| oldDocument->clearFocusedElement();
|
|
|
| @@ -1325,10 +1354,6 @@ bool FocusController::advanceFocusDirectionallyInContainer(
|
| Element* element = toElement(focusCandidate.focusableNode);
|
| DCHECK(element);
|
|
|
| - if (!element->isTextControl() && !hasEditableStyle(*element->toNode())) {
|
| - // TODO(editing-dev): Remove this clear(), crbug.com/692898.
|
| - focusedFrame()->selection().clear();
|
| - }
|
| element->focus(FocusParams(SelectionBehaviorOnFocus::Reset, type, nullptr));
|
| return true;
|
| }
|
|
|