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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/SelectorChecker.cpp
diff --git a/third_party/WebKit/Source/core/css/SelectorChecker.cpp b/third_party/WebKit/Source/core/css/SelectorChecker.cpp
index 497e1722f3105f2352964ee1340c0149557e1bb2..8fde38869a74ba53acf808314d203501da1e7d5e 100644
--- a/third_party/WebKit/Source/core/css/SelectorChecker.cpp
+++ b/third_party/WebKit/Source/core/css/SelectorChecker.cpp
@@ -47,6 +47,7 @@
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLOptionElement.h"
#include "core/html/HTMLSelectElement.h"
+#include "core/html/HTMLSlotElement.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/html/track/vtt/VTTElement.h"
#include "core/inspector/InspectorInstrumentation.h"
@@ -113,6 +114,20 @@ static Element* parentElement(const SelectorChecker::SelectorCheckingContext& co
return context.element->parentElement();
}
+static const HTMLSlotElement* findSlotElementInScope(const SelectorChecker::SelectorCheckingContext& context)
+{
+ if (!context.scope)
+ return nullptr;
+
+ const HTMLSlotElement* slot = context.element->assignedSlot();
+ while (slot) {
+ if (slot->treeScope() == context.scope->treeScope())
+ return slot;
+ slot = slot->assignedSlot();
+ }
+ return nullptr;
+}
+
static bool scopeContainsLastMatchedElement(const SelectorChecker::SelectorCheckingContext& context)
{
// If this context isn't scoped, skip checking.
@@ -451,9 +466,16 @@ SelectorChecker::Match SelectorChecker::matchForRelation(const SelectorCheckingC
}
return SelectorFailsCompletely;
}
+
case CSSSelector::ShadowSlot:
- // TODO(kochi): Add this in later CL.
- return SelectorFailsCompletely;
+ {
+ const HTMLSlotElement* slot = findSlotElementInScope(context);
+ if (!slot)
+ return SelectorFailsCompletely;
+
+ nextContext.element = const_cast<HTMLSlotElement*>(slot);
+ return matchSelector(nextContext, result);
+ }
case CSSSelector::SubSelector:
ASSERT_NOT_REACHED();
@@ -1034,6 +1056,19 @@ bool SelectorChecker::checkPseudoElement(const SelectorCheckingContext& context,
return root->type() == ShadowRootType::UserAgent && element.shadowPseudoId() == selector.value();
return false;
}
+ case CSSSelector::PseudoSlotted:
+ {
+ SelectorCheckingContext subContext(context);
+ subContext.isSubSelector = true;
+ subContext.scope = nullptr;
+ subContext.treatShadowHostAsNormalScope = false;
+
+ // ::slotted() only allows one compound selector.
+ ASSERT(selector.selectorList()->first());
+ ASSERT(!CSSSelectorList::next(*selector.selectorList()->first()));
+ subContext.selector = selector.selectorList()->first();
+ return match(subContext);
+ }
case CSSSelector::PseudoContent:
return element.isInShadowTree() && element.isInsertionPoint();
case CSSSelector::PseudoShadow:
« 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