| OLD | NEW |
| 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 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 SetNeedsStyleRecalc( | 1018 SetNeedsStyleRecalc( |
| 1019 change_type, | 1019 change_type, |
| 1020 StyleChangeReasonForTracing::CreateWithExtraData( | 1020 StyleChangeReasonForTracing::CreateWithExtraData( |
| 1021 StyleChangeReason::kPseudoClass, StyleChangeExtraData::g_focus)); | 1021 StyleChangeReason::kPseudoClass, StyleChangeExtraData::g_focus)); |
| 1022 } | 1022 } |
| 1023 if (IsElementNode() && ToElement(this)->ChildrenOrSiblingsAffectedByFocus()) | 1023 if (IsElementNode() && ToElement(this)->ChildrenOrSiblingsAffectedByFocus()) |
| 1024 ToElement(this)->PseudoStateChanged(CSSSelector::kPseudoFocus); | 1024 ToElement(this)->PseudoStateChanged(CSSSelector::kPseudoFocus); |
| 1025 | 1025 |
| 1026 LayoutTheme::GetTheme().ControlStateChanged(*GetLayoutObject(), | 1026 LayoutTheme::GetTheme().ControlStateChanged(*GetLayoutObject(), |
| 1027 kFocusControlState); | 1027 kFocusControlState); |
| 1028 FocusWithinStateChanged(); |
| 1029 } |
| 1030 |
| 1031 void ContainerNode::FocusWithinStateChanged() { |
| 1032 if (GetComputedStyle() && GetComputedStyle()->AffectedByFocusWithin()) { |
| 1033 StyleChangeType change_type = |
| 1034 GetComputedStyle()->HasPseudoStyle(kPseudoIdFirstLetter) |
| 1035 ? kSubtreeStyleChange |
| 1036 : kLocalStyleChange; |
| 1037 SetNeedsStyleRecalc(change_type, |
| 1038 StyleChangeReasonForTracing::CreateWithExtraData( |
| 1039 StyleChangeReason::kPseudoClass, |
| 1040 StyleChangeExtraData::g_focus_within)); |
| 1041 } |
| 1042 if (IsElementNode() && |
| 1043 ToElement(this)->ChildrenOrSiblingsAffectedByFocusWithin()) |
| 1044 ToElement(this)->PseudoStateChanged(CSSSelector::kPseudoFocusWithin); |
| 1028 } | 1045 } |
| 1029 | 1046 |
| 1030 void ContainerNode::SetFocused(bool received) { | 1047 void ContainerNode::SetFocused(bool received) { |
| 1031 // Recurse up author shadow trees to mark shadow hosts if it matches :focus. | 1048 // Recurse up author shadow trees to mark shadow hosts if it matches :focus. |
| 1032 // TODO(kochi): Handle UA shadows which marks multiple nodes as focused such | 1049 // TODO(kochi): Handle UA shadows which marks multiple nodes as focused such |
| 1033 // as <input type="date"> the same way as author shadow. | 1050 // as <input type="date"> the same way as author shadow. |
| 1034 if (ShadowRoot* root = ContainingShadowRoot()) { | 1051 if (ShadowRoot* root = ContainingShadowRoot()) { |
| 1035 if (root->GetType() != ShadowRootType::kUserAgent) | 1052 if (root->GetType() != ShadowRootType::kUserAgent) |
| 1036 OwnerShadowHost()->SetFocused(received); | 1053 OwnerShadowHost()->SetFocused(received); |
| 1037 } | 1054 } |
| 1038 | 1055 |
| 1039 // If this is an author shadow host and indirectly focused (has focused | 1056 // If this is an author shadow host and indirectly focused (has focused |
| 1040 // element within its shadow root), update focus. | 1057 // element within its shadow root), update focus. |
| 1041 if (IsElementNode() && GetDocument().FocusedElement() && | 1058 if (IsElementNode() && GetDocument().FocusedElement() && |
| 1042 GetDocument().FocusedElement() != this) { | 1059 GetDocument().FocusedElement() != this) { |
| 1043 if (ToElement(this)->AuthorShadowRoot()) | 1060 if (ToElement(this)->AuthorShadowRoot()) |
| 1044 received = | 1061 received = |
| 1045 received && ToElement(this)->AuthorShadowRoot()->delegatesFocus(); | 1062 received && ToElement(this)->AuthorShadowRoot()->delegatesFocus(); |
| 1046 } | 1063 } |
| 1047 | 1064 |
| 1048 if (IsFocused() == received) | 1065 if (IsFocused() == received) |
| 1049 return; | 1066 return; |
| 1050 | 1067 |
| 1051 Node::SetFocused(received); | 1068 Node::SetFocused(received); |
| 1052 | 1069 |
| 1053 FocusStateChanged(); | 1070 FocusStateChanged(); |
| 1054 | 1071 |
| 1072 UpdateDistribution(); |
| 1073 for (ContainerNode* node = this; node; |
| 1074 node = FlatTreeTraversal::Parent(*node)) { |
| 1075 node->SetHasFocusWithin(received); |
| 1076 node->FocusWithinStateChanged(); |
| 1077 } |
| 1078 |
| 1055 if (GetLayoutObject() || received) | 1079 if (GetLayoutObject() || received) |
| 1056 return; | 1080 return; |
| 1057 | 1081 |
| 1058 // If :focus sets display: none, we lose focus but still need to recalc our | 1082 // If :focus sets display: none, we lose focus but still need to recalc our |
| 1059 // style. | 1083 // style. |
| 1060 if (IsElementNode() && ToElement(this)->ChildrenOrSiblingsAffectedByFocus()) | 1084 if (IsElementNode() && ToElement(this)->ChildrenOrSiblingsAffectedByFocus()) |
| 1061 ToElement(this)->PseudoStateChanged(CSSSelector::kPseudoFocus); | 1085 ToElement(this)->PseudoStateChanged(CSSSelector::kPseudoFocus); |
| 1062 else | 1086 else |
| 1063 SetNeedsStyleRecalc( | 1087 SetNeedsStyleRecalc( |
| 1064 kLocalStyleChange, | 1088 kLocalStyleChange, |
| 1065 StyleChangeReasonForTracing::CreateWithExtraData( | 1089 StyleChangeReasonForTracing::CreateWithExtraData( |
| 1066 StyleChangeReason::kPseudoClass, StyleChangeExtraData::g_focus)); | 1090 StyleChangeReason::kPseudoClass, StyleChangeExtraData::g_focus)); |
| 1091 |
| 1092 if (IsElementNode() && |
| 1093 ToElement(this)->ChildrenOrSiblingsAffectedByFocusWithin()) { |
| 1094 ToElement(this)->PseudoStateChanged(CSSSelector::kPseudoFocusWithin); |
| 1095 } else { |
| 1096 SetNeedsStyleRecalc(kLocalStyleChange, |
| 1097 StyleChangeReasonForTracing::CreateWithExtraData( |
| 1098 StyleChangeReason::kPseudoClass, |
| 1099 StyleChangeExtraData::g_focus_within)); |
| 1100 } |
| 1067 } | 1101 } |
| 1068 | 1102 |
| 1069 void ContainerNode::SetActive(bool down) { | 1103 void ContainerNode::SetActive(bool down) { |
| 1070 if (down == IsActive()) | 1104 if (down == IsActive()) |
| 1071 return; | 1105 return; |
| 1072 | 1106 |
| 1073 Node::SetActive(down); | 1107 Node::SetActive(down); |
| 1074 | 1108 |
| 1075 if (!GetLayoutObject()) { | 1109 if (!GetLayoutObject()) { |
| 1076 if (IsElementNode() && | 1110 if (IsElementNode() && |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1485 return true; | 1519 return true; |
| 1486 | 1520 |
| 1487 if (node->IsElementNode() && ToElement(node)->Shadow()) | 1521 if (node->IsElementNode() && ToElement(node)->Shadow()) |
| 1488 return true; | 1522 return true; |
| 1489 | 1523 |
| 1490 return false; | 1524 return false; |
| 1491 } | 1525 } |
| 1492 #endif | 1526 #endif |
| 1493 | 1527 |
| 1494 } // namespace blink | 1528 } // namespace blink |
| OLD | NEW |