static void clearSelectionIfNeeded(Frame* oldFocusedFrame, Frame* newFocusedFrame, Node* newFocusedNode) { if (!oldFocusedFrame || !newFocusedFrame) return; if (oldFocusedFrame->document() != newFocusedFrame->document()) return; SelectionController* s = oldFocusedFrame->selection(); if (s->isNone()) return; bool caretBrowsing = oldFocusedFrame->settings()->caretBrowsingEnabled(); if (caretBrowsing) return; Node* selectionStartNode = s->selection().start().node(); if (selectionStartNode == newFocusedNode || selectionStartNode->isDescendantOf(newFocusedNode) || selectionStartNode->shadowAncestorNode() == newFocusedNode) return; if (Node* mousePressNode = newFocusedFrame->eventHandler()->mousePressNode()) if (mousePressNode->renderer() && !mousePressNode->canStartSelection()) if (Node* root = s->rootEditableElement()) if (Node* shadowAncestorNode = root->shadowAncestorNode()) // Don't do this for textareas and text fields, when they lose focus their selections should be cleared // and then restored when they regain focus, to match other browsers. if (!shadowAncestorNode->hasTagName(inputTag) && !shadowAncestorNode->hasTagName(textareaTag)) return; s->clear(); }
static void clearSelectionIfNeeded(Frame* oldFocusedFrame, Frame* newFocusedFrame, Node* newFocusedNode) { if (!oldFocusedFrame || !newFocusedFrame) return; if (oldFocusedFrame->document() != newFocusedFrame->document()) return; SelectionController* s = oldFocusedFrame->selection(); if (s->isNone()) return; bool caretBrowsing = oldFocusedFrame->settings()->caretBrowsingEnabled(); if (caretBrowsing) return; Node* selectionStartNode = s->selection().start().deprecatedNode(); if (selectionStartNode == newFocusedNode || selectionStartNode->isDescendantOf(newFocusedNode) || selectionStartNode->shadowAncestorNode() == newFocusedNode) return; if (Node* mousePressNode = newFocusedFrame->eventHandler()->mousePressNode()) { if (mousePressNode->renderer() && !mousePressNode->canStartSelection()) { // Don't clear the selection for contentEditable elements, but do clear it for input and textarea. See bug 38696. Node * root = s->rootEditableElement(); if (!root) return; if (Node* shadowAncestorNode = root->shadowAncestorNode()) { if (!shadowAncestorNode->hasTagName(inputTag) && !shadowAncestorNode->hasTagName(textareaTag)) return; } } } s->clear(); }