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

Unified Diff: third_party/WebKit/Source/core/page/FocusController.cpp

Issue 2791753002: Revert of Reland: Do not send redundant selectionchange-events (Closed)
Patch Set: Add a NeedsRebaseline to manage conflict with http://crrev.com/460732 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/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;
}
« no previous file with comments | « third_party/WebKit/Source/core/editing/PendingSelection.cpp ('k') | third_party/WebKit/Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698