Index: third_party/WebKit/Source/core/dom/Document.cpp |
diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp |
index a289edaa1ac1bf3457005f872c137db1c0c054f4..c79f3775d511140651a4298a109dcac17ca298c4 100644 |
--- a/third_party/WebKit/Source/core/dom/Document.cpp |
+++ b/third_party/WebKit/Source/core/dom/Document.cpp |
@@ -4054,9 +4054,17 @@ bool Document::SetFocusedElement(Element* prp_new_focused_element, |
Element* old_focused_element = focused_element_; |
focused_element_ = nullptr; |
+ UpdateDistribution(); |
+ Node* ancestor = (old_focused_element && old_focused_element->isConnected() && |
+ new_focused_element) |
+ ? FlatTreeTraversal::CommonAncestor(*old_focused_element, |
+ *new_focused_element) |
+ : nullptr; |
+ |
// Remove focus from the existing focus node (if any) |
if (old_focused_element) { |
old_focused_element->SetFocused(false, params.type); |
+ old_focused_element->SetHasFocusWithinUpToAncestor(false, ancestor); |
// Dispatch the blur event and let the node do any other blur related |
// activities (important for text fields) |
@@ -4104,6 +4112,8 @@ bool Document::SetFocusedElement(Element* prp_new_focused_element, |
SetSequentialFocusNavigationStartingPoint(focused_element_.Get()); |
focused_element_->SetFocused(true, params.type); |
+ focused_element_->SetHasFocusWithinUpToAncestor(true, ancestor); |
+ |
// Element::setFocused for frames can dispatch events. |
if (focused_element_ != new_focused_element) { |
focus_change_blocked = true; |