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

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: WIP Created 4 years, 12 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 30 matching lines...) Expand all
41 #include "core/dom/shadow/ComposedTreeTraversal.h" 41 #include "core/dom/shadow/ComposedTreeTraversal.h"
42 #include "core/dom/shadow/InsertionPoint.h" 42 #include "core/dom/shadow/InsertionPoint.h"
43 #include "core/dom/shadow/ShadowRoot.h" 43 #include "core/dom/shadow/ShadowRoot.h"
44 #include "core/editing/FrameSelection.h" 44 #include "core/editing/FrameSelection.h"
45 #include "core/frame/LocalFrame.h" 45 #include "core/frame/LocalFrame.h"
46 #include "core/html/HTMLDocument.h" 46 #include "core/html/HTMLDocument.h"
47 #include "core/html/HTMLFrameElementBase.h" 47 #include "core/html/HTMLFrameElementBase.h"
48 #include "core/html/HTMLInputElement.h" 48 #include "core/html/HTMLInputElement.h"
49 #include "core/html/HTMLOptionElement.h" 49 #include "core/html/HTMLOptionElement.h"
50 #include "core/html/HTMLSelectElement.h" 50 #include "core/html/HTMLSelectElement.h"
51 #include "core/html/HTMLSlotElement.h"
51 #include "core/html/parser/HTMLParserIdioms.h" 52 #include "core/html/parser/HTMLParserIdioms.h"
52 #include "core/html/track/vtt/VTTElement.h" 53 #include "core/html/track/vtt/VTTElement.h"
53 #include "core/inspector/InspectorInstrumentation.h" 54 #include "core/inspector/InspectorInstrumentation.h"
54 #include "core/layout/LayoutObject.h" 55 #include "core/layout/LayoutObject.h"
55 #include "core/layout/LayoutScrollbar.h" 56 #include "core/layout/LayoutScrollbar.h"
56 #include "core/page/FocusController.h" 57 #include "core/page/FocusController.h"
57 #include "core/page/Page.h" 58 #include "core/page/Page.h"
58 #include "core/style/ComputedStyle.h" 59 #include "core/style/ComputedStyle.h"
59 #include "platform/scroll/ScrollableArea.h" 60 #include "platform/scroll/ScrollableArea.h"
60 #include "platform/scroll/ScrollbarTheme.h" 61 #include "platform/scroll/ScrollbarTheme.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // - If context.scope is a shadow root, we should walk up to its shadow host . 108 // - If context.scope is a shadow root, we should walk up to its shadow host .
108 // - If context.scope is some element in some shadow tree and querySelector initialized the context, 109 // - If context.scope is some element in some shadow tree and querySelector initialized the context,
109 // e.g. shadowRoot.querySelector(':host *'), 110 // e.g. shadowRoot.querySelector(':host *'),
110 // (a) context.element has the same treescope as context.scope, need to wa lk up to its shadow host. 111 // (a) context.element has the same treescope as context.scope, need to wa lk up to its shadow host.
111 // (b) Otherwise, should not walk up from a shadow root to a shadow host. 112 // (b) Otherwise, should not walk up from a shadow root to a shadow host.
112 if (context.scope && (context.scope == context.element->containingShadowRoot () || context.scope->treeScope() == context.element->treeScope())) 113 if (context.scope && (context.scope == context.element->containingShadowRoot () || context.scope->treeScope() == context.element->treeScope()))
113 return context.element->parentOrShadowHostElement(); 114 return context.element->parentOrShadowHostElement();
114 return context.element->parentElement(); 115 return context.element->parentElement();
115 } 116 }
116 117
118 static const HTMLSlotElement* findSlotElementInScope(const SelectorChecker::Sele ctorCheckingContext& context)
119 {
120 if (!context.scope)
121 return nullptr;
122
123 const HTMLSlotElement* slot = context.element->assignedSlot();
124 while (slot) {
125 if (slot->treeScope() == context.scope->treeScope())
126 return slot;
127 slot = slot->assignedSlot();
128 }
129 return nullptr;
130 }
131
117 static bool scopeContainsLastMatchedElement(const SelectorChecker::SelectorCheck ingContext& context) 132 static bool scopeContainsLastMatchedElement(const SelectorChecker::SelectorCheck ingContext& context)
118 { 133 {
119 // If this context isn't scoped, skip checking. 134 // If this context isn't scoped, skip checking.
120 if (!context.scope) 135 if (!context.scope)
121 return true; 136 return true;
122 137
123 if (context.scope->treeScope() == context.element->treeScope()) 138 if (context.scope->treeScope() == context.element->treeScope())
124 return true; 139 return true;
125 140
126 // Because Blink treats a shadow host's TreeScope as a separate one from its descendent shadow roots, 141 // 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
446 for (nextContext.element = parentOrV0ShadowHostElement(*context.elem ent); nextContext.element; nextContext.element = parentOrV0ShadowHostElement(*ne xtContext.element)) { 461 for (nextContext.element = parentOrV0ShadowHostElement(*context.elem ent); nextContext.element; nextContext.element = parentOrV0ShadowHostElement(*ne xtContext.element)) {
447 Match match = matchSelector(nextContext, result); 462 Match match = matchSelector(nextContext, result);
448 if (match == SelectorMatches || match == SelectorFailsCompletely ) 463 if (match == SelectorMatches || match == SelectorFailsCompletely )
449 return match; 464 return match;
450 if (nextSelectorExceedsScope(nextContext)) 465 if (nextSelectorExceedsScope(nextContext))
451 return SelectorFailsCompletely; 466 return SelectorFailsCompletely;
452 } 467 }
453 return SelectorFailsCompletely; 468 return SelectorFailsCompletely;
454 } 469 }
455 470
471 case CSSSelector::ShadowSlot:
472 {
473 const HTMLSlotElement* slot = findSlotElementInScope(context);
474 if (!slot)
475 return SelectorFailsCompletely;
476
477 nextContext.element = const_cast<HTMLSlotElement*>(slot);
478 return matchSelector(nextContext, result);
479 }
480
456 case CSSSelector::SubSelector: 481 case CSSSelector::SubSelector:
457 ASSERT_NOT_REACHED(); 482 ASSERT_NOT_REACHED();
458 } 483 }
459 484
460 ASSERT_NOT_REACHED(); 485 ASSERT_NOT_REACHED();
461 return SelectorFailsCompletely; 486 return SelectorFailsCompletely;
462 } 487 }
463 488
464 SelectorChecker::Match SelectorChecker::matchForShadowDistributed(const Selector CheckingContext& context, const Element& element, MatchResult& result) const 489 SelectorChecker::Match SelectorChecker::matchForShadowDistributed(const Selector CheckingContext& context, const Element& element, MatchResult& result) const
465 { 490 {
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 return true; 1042 return true;
1018 } 1043 }
1019 return false; 1044 return false;
1020 } 1045 }
1021 case CSSSelector::PseudoWebKitCustomElement: 1046 case CSSSelector::PseudoWebKitCustomElement:
1022 { 1047 {
1023 if (ShadowRoot* root = element.containingShadowRoot()) 1048 if (ShadowRoot* root = element.containingShadowRoot())
1024 return root->type() == ShadowRootType::UserAgent && element.shad owPseudoId() == selector.value(); 1049 return root->type() == ShadowRootType::UserAgent && element.shad owPseudoId() == selector.value();
1025 return false; 1050 return false;
1026 } 1051 }
1052 case CSSSelector::PseudoSlotted:
1053 {
1054 SelectorCheckingContext subContext(context);
1055 subContext.isSubSelector = true;
1056 subContext.scope = nullptr;
1057 subContext.treatShadowHostAsNormalScope = false;
1058
1059 // ::slotted() only allows one simple selector.
1060 ASSERT(selector.selectorList()->first());
1061 ASSERT(!CSSSelectorList::next(*selector.selectorList()->first()));
1062 subContext.selector = selector.selectorList()->first();
1063 return match(subContext);
1064 }
1027 case CSSSelector::PseudoContent: 1065 case CSSSelector::PseudoContent:
1028 return element.isInShadowTree() && element.isInsertionPoint(); 1066 return element.isInShadowTree() && element.isInsertionPoint();
1029 case CSSSelector::PseudoShadow: 1067 case CSSSelector::PseudoShadow:
1030 return element.isInShadowTree() && context.previousElement; 1068 return element.isInShadowTree() && context.previousElement;
1031 default: 1069 default:
1032 break; 1070 break;
1033 } 1071 }
1034 1072
1035 if (!context.inRightmostCompound && m_mode == ResolvingStyle) 1073 if (!context.inRightmostCompound && m_mode == ResolvingStyle)
1036 return false; 1074 return false;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 } 1229 }
1192 1230
1193 bool SelectorChecker::matchesFocusPseudoClass(const Element& element) 1231 bool SelectorChecker::matchesFocusPseudoClass(const Element& element)
1194 { 1232 {
1195 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element ), CSSSelector::PseudoFocus)) 1233 if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(&element ), CSSSelector::PseudoFocus))
1196 return true; 1234 return true;
1197 return element.focused() && isFrameFocused(element); 1235 return element.focused() && isFrameFocused(element);
1198 } 1236 }
1199 1237
1200 } 1238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698