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

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

Issue 1523843004: Add support for new CSS ::slotted() pseudo element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase / fix comments for tests (FYI) 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
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:
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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 return true; 1049 return true;
1025 } 1050 }
1026 return false; 1051 return false;
1027 } 1052 }
1028 case CSSSelector::PseudoWebKitCustomElement: 1053 case CSSSelector::PseudoWebKitCustomElement:
1029 { 1054 {
1030 if (ShadowRoot* root = element.containingShadowRoot()) 1055 if (ShadowRoot* root = element.containingShadowRoot())
1031 return root->type() == ShadowRootType::UserAgent && element.shad owPseudoId() == selector.value(); 1056 return root->type() == ShadowRootType::UserAgent && element.shad owPseudoId() == selector.value();
1032 return false; 1057 return false;
1033 } 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 }
1034 case CSSSelector::PseudoContent: 1072 case CSSSelector::PseudoContent:
1035 return element.isInShadowTree() && element.isInsertionPoint(); 1073 return element.isInShadowTree() && element.isInsertionPoint();
1036 case CSSSelector::PseudoShadow: 1074 case CSSSelector::PseudoShadow:
1037 return element.isInShadowTree() && context.previousElement; 1075 return element.isInShadowTree() && context.previousElement;
1038 default: 1076 default:
1039 break; 1077 break;
1040 } 1078 }
1041 1079
1042 if (!context.inRightmostCompound && m_mode == ResolvingStyle) 1080 if (!context.inRightmostCompound && m_mode == ResolvingStyle)
1043 return false; 1081 return false;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 } 1236 }
1199 1237
1200 bool SelectorChecker::matchesFocusPseudoClass(const Element& element) 1238 bool SelectorChecker::matchesFocusPseudoClass(const Element& element)
1201 { 1239 {
1202 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element ), CSSSelector::PseudoFocus)) 1240 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element ), CSSSelector::PseudoFocus))
1203 return true; 1241 return true;
1204 return element.focused() && isFrameFocused(element); 1242 return element.focused() && isFrameFocused(element);
1205 } 1243 }
1206 1244
1207 } 1245 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/RuleSet.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