Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
| 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. |
| 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
| 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 #include "core/dom/shadow/ComposedTreeTraversal.h" | 40 #include "core/dom/shadow/ComposedTreeTraversal.h" |
| 41 #include "core/dom/shadow/InsertionPoint.h" | 41 #include "core/dom/shadow/InsertionPoint.h" |
| 42 #include "core/dom/shadow/ShadowRoot.h" | 42 #include "core/dom/shadow/ShadowRoot.h" |
| 43 #include "core/editing/FrameSelection.h" | 43 #include "core/editing/FrameSelection.h" |
| 44 #include "core/frame/LocalFrame.h" | 44 #include "core/frame/LocalFrame.h" |
| 45 #include "core/html/HTMLDocument.h" | 45 #include "core/html/HTMLDocument.h" |
| 46 #include "core/html/HTMLFrameElementBase.h" | 46 #include "core/html/HTMLFrameElementBase.h" |
| 47 #include "core/html/HTMLInputElement.h" | 47 #include "core/html/HTMLInputElement.h" |
| 48 #include "core/html/HTMLOptionElement.h" | 48 #include "core/html/HTMLOptionElement.h" |
| 49 #include "core/html/HTMLSelectElement.h" | 49 #include "core/html/HTMLSelectElement.h" |
| 50 #include "core/html/HTMLSlotElement.h" | |
| 50 #include "core/html/parser/HTMLParserIdioms.h" | 51 #include "core/html/parser/HTMLParserIdioms.h" |
| 51 #include "core/html/track/vtt/VTTElement.h" | 52 #include "core/html/track/vtt/VTTElement.h" |
| 52 #include "core/inspector/InspectorInstrumentation.h" | 53 #include "core/inspector/InspectorInstrumentation.h" |
| 53 #include "core/layout/LayoutObject.h" | 54 #include "core/layout/LayoutObject.h" |
| 54 #include "core/layout/LayoutScrollbar.h" | 55 #include "core/layout/LayoutScrollbar.h" |
| 55 #include "core/page/FocusController.h" | 56 #include "core/page/FocusController.h" |
| 56 #include "core/page/Page.h" | 57 #include "core/page/Page.h" |
| 57 #include "core/style/ComputedStyle.h" | 58 #include "core/style/ComputedStyle.h" |
| 58 #include "platform/scroll/ScrollableArea.h" | 59 #include "platform/scroll/ScrollableArea.h" |
| 59 #include "platform/scroll/ScrollbarTheme.h" | 60 #include "platform/scroll/ScrollbarTheme.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 // - If context.scope is a shadow root, we should walk up to its shadow host . | 107 // - If context.scope is a shadow root, we should walk up to its shadow host . |
| 107 // - If context.scope is some element in some shadow tree and querySelector initialized the context, | 108 // - If context.scope is some element in some shadow tree and querySelector initialized the context, |
| 108 // e.g. shadowRoot.querySelector(':host *'), | 109 // e.g. shadowRoot.querySelector(':host *'), |
| 109 // (a) context.element has the same treescope as context.scope, need to wa lk up to its shadow host. | 110 // (a) context.element has the same treescope as context.scope, need to wa lk up to its shadow host. |
| 110 // (b) Otherwise, should not walk up from a shadow root to a shadow host. | 111 // (b) Otherwise, should not walk up from a shadow root to a shadow host. |
| 111 if (context.scope && (context.scope == context.element->containingShadowRoot () || context.scope->treeScope() == context.element->treeScope())) | 112 if (context.scope && (context.scope == context.element->containingShadowRoot () || context.scope->treeScope() == context.element->treeScope())) |
| 112 return context.element->parentOrShadowHostElement(); | 113 return context.element->parentOrShadowHostElement(); |
| 113 return context.element->parentElement(); | 114 return context.element->parentElement(); |
| 114 } | 115 } |
| 115 | 116 |
| 117 static const HTMLSlotElement* findSlotElementInScope(const SelectorChecker::Sele ctorCheckingContext& context) | |
| 118 { | |
| 119 if (!context.scope) | |
| 120 return nullptr; | |
| 121 | |
| 122 const HTMLSlotElement* slot = context.element->assignedSlot(); | |
| 123 while (slot) { | |
| 124 if (slot->treeScope() == context.scope->treeScope()) | |
| 125 return slot; | |
| 126 slot = slot->assignedSlot(); | |
| 127 } | |
| 128 return nullptr; | |
| 129 } | |
| 130 | |
| 116 static bool scopeContainsLastMatchedElement(const SelectorChecker::SelectorCheck ingContext& context) | 131 static bool scopeContainsLastMatchedElement(const SelectorChecker::SelectorCheck ingContext& context) |
| 117 { | 132 { |
| 118 // If this context isn't scoped, skip checking. | 133 // If this context isn't scoped, skip checking. |
| 119 if (!context.scope) | 134 if (!context.scope) |
| 120 return true; | 135 return true; |
| 121 | 136 |
| 122 if (context.scope->treeScope() == context.element->treeScope()) | 137 if (context.scope->treeScope() == context.element->treeScope()) |
| 123 return true; | 138 return true; |
| 124 | 139 |
| 125 // Because Blink treats a shadow host's TreeScope as a separate one from its descendent shadow roots, | 140 // Because Blink treats a shadow host's TreeScope as a separate one from its descendent shadow roots, |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 for (nextContext.element = parentOrV0ShadowHostElement(*context.elem ent); nextContext.element; nextContext.element = parentOrV0ShadowHostElement(*ne xtContext.element)) { | 460 for (nextContext.element = parentOrV0ShadowHostElement(*context.elem ent); nextContext.element; nextContext.element = parentOrV0ShadowHostElement(*ne xtContext.element)) { |
| 446 Match match = matchSelector(nextContext, result); | 461 Match match = matchSelector(nextContext, result); |
| 447 if (match == SelectorMatches || match == SelectorFailsCompletely ) | 462 if (match == SelectorMatches || match == SelectorFailsCompletely ) |
| 448 return match; | 463 return match; |
| 449 if (nextSelectorExceedsScope(nextContext)) | 464 if (nextSelectorExceedsScope(nextContext)) |
| 450 return SelectorFailsCompletely; | 465 return SelectorFailsCompletely; |
| 451 } | 466 } |
| 452 return SelectorFailsCompletely; | 467 return SelectorFailsCompletely; |
| 453 } | 468 } |
| 454 | 469 |
| 470 case CSSSelector::ShadowSlot: | |
|
rune
2016/01/11 10:07:23
It's possible to implement this without this combi
| |
| 471 { | |
| 472 const HTMLSlotElement* slot = findSlotElementInScope(context); | |
| 473 if (!slot) | |
| 474 return SelectorFailsCompletely; | |
| 475 | |
| 476 nextContext.element = const_cast<HTMLSlotElement*>(slot); | |
| 477 return matchSelector(nextContext, result); | |
| 478 } | |
| 479 | |
| 455 case CSSSelector::SubSelector: | 480 case CSSSelector::SubSelector: |
| 456 ASSERT_NOT_REACHED(); | 481 ASSERT_NOT_REACHED(); |
| 457 } | 482 } |
| 458 | 483 |
| 459 ASSERT_NOT_REACHED(); | 484 ASSERT_NOT_REACHED(); |
| 460 return SelectorFailsCompletely; | 485 return SelectorFailsCompletely; |
| 461 } | 486 } |
| 462 | 487 |
| 463 SelectorChecker::Match SelectorChecker::matchForShadowDistributed(const Selector CheckingContext& context, const Element& element, MatchResult& result) const | 488 SelectorChecker::Match SelectorChecker::matchForShadowDistributed(const Selector CheckingContext& context, const Element& element, MatchResult& result) const |
| 464 { | 489 { |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 return true; | 1041 return true; |
| 1017 } | 1042 } |
| 1018 return false; | 1043 return false; |
| 1019 } | 1044 } |
| 1020 case CSSSelector::PseudoWebKitCustomElement: | 1045 case CSSSelector::PseudoWebKitCustomElement: |
| 1021 { | 1046 { |
| 1022 if (ShadowRoot* root = element.containingShadowRoot()) | 1047 if (ShadowRoot* root = element.containingShadowRoot()) |
| 1023 return root->type() == ShadowRootType::UserAgent && element.shad owPseudoId() == selector.value(); | 1048 return root->type() == ShadowRootType::UserAgent && element.shad owPseudoId() == selector.value(); |
| 1024 return false; | 1049 return false; |
| 1025 } | 1050 } |
| 1051 case CSSSelector::PseudoSlotted: | |
| 1052 { | |
| 1053 SelectorCheckingContext subContext(context); | |
| 1054 subContext.isSubSelector = true; | |
| 1055 subContext.scope = nullptr; | |
| 1056 subContext.treatShadowHostAsNormalScope = false; | |
| 1057 | |
| 1058 // ::slotted() only allows one compound selector. | |
| 1059 ASSERT(selector.selectorList()->first()); | |
| 1060 ASSERT(!CSSSelectorList::next(*selector.selectorList()->first())); | |
| 1061 subContext.selector = selector.selectorList()->first(); | |
| 1062 return match(subContext); | |
| 1063 } | |
| 1026 case CSSSelector::PseudoContent: | 1064 case CSSSelector::PseudoContent: |
| 1027 return element.isInShadowTree() && element.isInsertionPoint(); | 1065 return element.isInShadowTree() && element.isInsertionPoint(); |
| 1028 case CSSSelector::PseudoShadow: | 1066 case CSSSelector::PseudoShadow: |
| 1029 return element.isInShadowTree() && context.previousElement; | 1067 return element.isInShadowTree() && context.previousElement; |
| 1030 default: | 1068 default: |
| 1031 break; | 1069 break; |
| 1032 } | 1070 } |
| 1033 | 1071 |
| 1034 if (!context.inRightmostCompound && m_mode == ResolvingStyle) | 1072 if (!context.inRightmostCompound && m_mode == ResolvingStyle) |
| 1035 return false; | 1073 return false; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1190 } | 1228 } |
| 1191 | 1229 |
| 1192 bool SelectorChecker::matchesFocusPseudoClass(const Element& element) | 1230 bool SelectorChecker::matchesFocusPseudoClass(const Element& element) |
| 1193 { | 1231 { |
| 1194 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element ), CSSSelector::PseudoFocus)) | 1232 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element ), CSSSelector::PseudoFocus)) |
| 1195 return true; | 1233 return true; |
| 1196 return element.focused() && isFrameFocused(element); | 1234 return element.focused() && isFrameFocused(element); |
| 1197 } | 1235 } |
| 1198 | 1236 |
| 1199 } | 1237 } |
| OLD | NEW |