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

Side by Side Diff: third_party/WebKit/Source/core/dom/ContainerNode.cpp

Issue 2821303005: [selectors4] Use common ancestor strategy for :focus-within (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights
6 * reserved. 6 * reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 SetNeedsStyleRecalc(change_type, 1037 SetNeedsStyleRecalc(change_type,
1038 StyleChangeReasonForTracing::CreateWithExtraData( 1038 StyleChangeReasonForTracing::CreateWithExtraData(
1039 StyleChangeReason::kPseudoClass, 1039 StyleChangeReason::kPseudoClass,
1040 StyleChangeExtraData::g_focus_within)); 1040 StyleChangeExtraData::g_focus_within));
1041 } 1041 }
1042 if (IsElementNode() && 1042 if (IsElementNode() &&
1043 ToElement(this)->ChildrenOrSiblingsAffectedByFocusWithin()) 1043 ToElement(this)->ChildrenOrSiblingsAffectedByFocusWithin())
1044 ToElement(this)->PseudoStateChanged(CSSSelector::kPseudoFocusWithin); 1044 ToElement(this)->PseudoStateChanged(CSSSelector::kPseudoFocusWithin);
1045 } 1045 }
1046 1046
1047 void ContainerNode::SetFocused(bool received, WebFocusType focus_type) { 1047 void ContainerNode::SetFocused(bool received,
1048 WebFocusType focus_type,
1049 Node* common_ancestor) {
1048 // Recurse up author shadow trees to mark shadow hosts if it matches :focus. 1050 // Recurse up author shadow trees to mark shadow hosts if it matches :focus.
1049 // TODO(kochi): Handle UA shadows which marks multiple nodes as focused such 1051 // TODO(kochi): Handle UA shadows which marks multiple nodes as focused such
1050 // as <input type="date"> the same way as author shadow. 1052 // as <input type="date"> the same way as author shadow.
1051 if (ShadowRoot* root = ContainingShadowRoot()) { 1053 if (ShadowRoot* root = ContainingShadowRoot()) {
1052 if (root->GetType() != ShadowRootType::kUserAgent) 1054 if (root->GetType() != ShadowRootType::kUserAgent)
1053 OwnerShadowHost()->SetFocused(received, focus_type); 1055 OwnerShadowHost()->SetFocused(received, focus_type);
rune 2017/04/20 09:22:17 Having a default argument for common_ancestor look
Manuel Rego 2017/04/20 15:20:37 Yeah, this is an oversight in this version of the
1054 } 1056 }
1055 1057
1056 // If this is an author shadow host and indirectly focused (has focused 1058 // If this is an author shadow host and indirectly focused (has focused
1057 // element within its shadow root), update focus. 1059 // element within its shadow root), update focus.
1058 if (IsElementNode() && GetDocument().FocusedElement() && 1060 if (IsElementNode() && GetDocument().FocusedElement() &&
1059 GetDocument().FocusedElement() != this) { 1061 GetDocument().FocusedElement() != this) {
1060 if (ToElement(this)->AuthorShadowRoot()) 1062 if (ToElement(this)->AuthorShadowRoot())
1061 received = 1063 received =
1062 received && ToElement(this)->AuthorShadowRoot()->delegatesFocus(); 1064 received && ToElement(this)->AuthorShadowRoot()->delegatesFocus();
1063 } 1065 }
1064 1066
1065 if (IsFocused() == received) 1067 if (IsFocused() == received)
1066 return; 1068 return;
1067 1069
1068 Node::SetFocused(received, focus_type); 1070 Node::SetFocused(received, focus_type);
1069 1071
1070 FocusStateChanged(); 1072 FocusStateChanged();
1071 1073
1072 UpdateDistribution(); 1074 UpdateDistribution();
1073 for (ContainerNode* node = this; node; 1075 for (ContainerNode* node = this; node && node != common_ancestor;
1074 node = FlatTreeTraversal::Parent(*node)) { 1076 node = FlatTreeTraversal::Parent(*node)) {
1075 node->SetHasFocusWithin(received); 1077 node->SetHasFocusWithin(received);
1076 node->FocusWithinStateChanged(); 1078 node->FocusWithinStateChanged();
1077 } 1079 }
1078 1080
1079 if (GetLayoutObject() || received) 1081 if (GetLayoutObject() || received)
1080 return; 1082 return;
1081 1083
1082 // If :focus sets display: none, we lose focus but still need to recalc our 1084 // If :focus sets display: none, we lose focus but still need to recalc our
1083 // style. 1085 // style.
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 return true; 1521 return true;
1520 1522
1521 if (node->IsElementNode() && ToElement(node)->Shadow()) 1523 if (node->IsElementNode() && ToElement(node)->Shadow())
1522 return true; 1524 return true;
1523 1525
1524 return false; 1526 return false;
1525 } 1527 }
1526 #endif 1528 #endif
1527 1529
1528 } // namespace blink 1530 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ContainerNode.h ('k') | third_party/WebKit/Source/core/dom/Document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698