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

Side by Side Diff: third_party/WebKit/Source/core/css/SelectorChecker.cpp

Issue 1575363006: Implement matching part of ::slotted() pseudo element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blink_slotted_parser
Patch Set: rebase Created 4 years, 11 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) 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
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
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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 459
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 }
469
454 case CSSSelector::ShadowSlot: 470 case CSSSelector::ShadowSlot:
455 // TODO(kochi): Add this in later CL. 471 {
456 return SelectorFailsCompletely; 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 }
457 479
458 case CSSSelector::SubSelector: 480 case CSSSelector::SubSelector:
459 ASSERT_NOT_REACHED(); 481 ASSERT_NOT_REACHED();
460 } 482 }
461 483
462 ASSERT_NOT_REACHED(); 484 ASSERT_NOT_REACHED();
463 return SelectorFailsCompletely; 485 return SelectorFailsCompletely;
464 } 486 }
465 487
466 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
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 return true; 1049 return true;
1028 } 1050 }
1029 return false; 1051 return false;
1030 } 1052 }
1031 case CSSSelector::PseudoWebKitCustomElement: 1053 case CSSSelector::PseudoWebKitCustomElement:
1032 { 1054 {
1033 if (ShadowRoot* root = element.containingShadowRoot()) 1055 if (ShadowRoot* root = element.containingShadowRoot())
1034 return root->type() == ShadowRootType::UserAgent && element.shad owPseudoId() == selector.value(); 1056 return root->type() == ShadowRootType::UserAgent && element.shad owPseudoId() == selector.value();
1035 return false; 1057 return false;
1036 } 1058 }
1059 case CSSSelector::PseudoSlotted:
1060 {
1061 SelectorCheckingContext subContext(context);
1062 subContext.isSubSelector = true;
1063 subContext.scope = nullptr;
1064 subContext.treatShadowHostAsNormalScope = false;
1065
1066 // ::slotted() only allows one compound selector.
1067 ASSERT(selector.selectorList()->first());
1068 ASSERT(!CSSSelectorList::next(*selector.selectorList()->first()));
1069 subContext.selector = selector.selectorList()->first();
1070 return match(subContext);
1071 }
1037 case CSSSelector::PseudoContent: 1072 case CSSSelector::PseudoContent:
1038 return element.isInShadowTree() && element.isInsertionPoint(); 1073 return element.isInShadowTree() && element.isInsertionPoint();
1039 case CSSSelector::PseudoShadow: 1074 case CSSSelector::PseudoShadow:
1040 return element.isInShadowTree() && context.previousElement; 1075 return element.isInShadowTree() && context.previousElement;
1041 default: 1076 default:
1042 break; 1077 break;
1043 } 1078 }
1044 1079
1045 if (m_mode == QueryingRules) 1080 if (m_mode == QueryingRules)
1046 return false; 1081 return false;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 } 1232 }
1198 1233
1199 bool SelectorChecker::matchesFocusPseudoClass(const Element& element) 1234 bool SelectorChecker::matchesFocusPseudoClass(const Element& element)
1200 { 1235 {
1201 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element ), CSSSelector::PseudoFocus)) 1236 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element ), CSSSelector::PseudoFocus))
1202 return true; 1237 return true;
1203 return element.focused() && isFrameFocused(element); 1238 return element.focused() && isFrameFocused(element);
1204 } 1239 }
1205 1240
1206 } 1241 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/RuleFeature.cpp ('k') | third_party/WebKit/Source/core/css/SelectorFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698