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

Unified Diff: third_party/WebKit/Source/core/html/HTMLSlotElement.cpp

Issue 2789363002: Styling slot fallback content with ::slotted()
Patch Set: rebase Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSlotElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp b/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
index bf89d354ebb0401e3a1e7986bb1eb47a4c570fc8..6e6938883b290df59194b3a37710dd8167f0fb01 100644
--- a/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
@@ -51,6 +51,10 @@ inline HTMLSlotElement::HTMLSlotElement(Document& document)
: HTMLElement(slotTag, document) {
UseCounter::Count(document, UseCounter::kHTMLSlotElement);
SetHasCustomStyleCallbacks();
+ // TODO(kochi): This is required for slot fallback contents to be matched
+ // against ::slotted() pseudo element in a document tree. Remove this once
+ // Shadow DOM V0 code is removed.
+ document.SetShadowCascadeOrder(ShadowCascadeOrder::kShadowCascadeV1);
}
DEFINE_NODE_FACTORY(HTMLSlotElement);
@@ -60,6 +64,35 @@ AtomicString HTMLSlotElement::NormalizeSlotName(const AtomicString& name) {
return (name.IsNull() || name.IsEmpty()) ? g_empty_atom : name;
}
+// static
+HTMLSlotElement* HTMLSlotElement::FindFallbackSlotElementFor(
+ const Element& element) {
+ // Check if |element| is a fallback content.
+ Element* parent = element.parentElement();
+ if (!parent || !isHTMLSlotElement(parent) ||
+ !toHTMLSlotElement(parent)->AssignedNodes().IsEmpty())
+ return nullptr;
+
+ // At this point, |parent| is an immediate parent of element, which is
+ // a <slot> with empty assigned nodes. This slot is one of the following:
+ // (1) doesn't have any slot in ancestor.
+ // (2) have a slot in ancestor which is assigned to another slot.
+ // (3) have a slot in ancestor which has assigned nodes.
+ // In cases (1) and (2), this slot is a fallback content.
+ // In case (3), this slot is not a fallback content.
+ HTMLSlotElement* slot = toHTMLSlotElement(parent);
+ while ((parent = parent->parentElement())) {
+ if (!isHTMLSlotElement(parent))
+ continue;
+ if (!toHTMLSlotElement(parent)->AssignedNodes().IsEmpty())
+ return nullptr;
+ slot = toHTMLSlotElement(parent);
+ if (slot->AssignedSlot())
+ break;
+ }
+ return slot;
+}
+
const HeapVector<Member<Node>>& HTMLSlotElement::AssignedNodes() {
DCHECK(!NeedsDistributionRecalc());
DCHECK(IsInShadowTree() || assigned_nodes_.IsEmpty());
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSlotElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698