Bug 1559077 - Implement Element.part. r=bzbarsky
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 13 Oct 2019 09:40:08 +0000
changeset 497362 a15487779ef4178edb66d3992df45bc3127fad41
parent 497361 119ad04b0efc030afcf10c153b4e86c863c8a96e
child 497363 25cadf00037220e19d6ea38a962d2970a7f66a1b
push id36686
push useraiakab@mozilla.com
push dateSun, 13 Oct 2019 21:36:50 +0000
treeherdermozilla-central@3bdfb7bc00a0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1559077
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1559077 - Implement Element.part. r=bzbarsky Differential Revision: https://phabricator.services.mozilla.com/D48707
dom/base/Element.cpp
dom/base/Element.h
dom/base/FragmentOrElement.cpp
dom/base/FragmentOrElement.h
dom/webidl/Element.webidl
testing/web-platform/meta/css/css-shadow-parts/invalidation-change-part-name-idl-domtokenlist.html.ini
testing/web-platform/meta/css/css-shadow-parts/invalidation-change-part-name-idl-setter.html.ini
testing/web-platform/meta/css/css-shadow-parts/part-name-idl.html.ini
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -534,16 +534,26 @@ nsDOMTokenList* Element::ClassList() {
 
   if (!slots->mClassList) {
     slots->mClassList = new nsDOMTokenList(this, nsGkAtoms::_class);
   }
 
   return slots->mClassList;
 }
 
+nsDOMTokenList* Element::Part() {
+  Element::nsDOMSlots* slots = DOMSlots();
+
+  if (!slots->mPart) {
+    slots->mPart = new nsDOMTokenList(this, nsGkAtoms::part);
+  }
+
+  return slots->mPart;
+}
+
 void Element::GetAttributeNames(nsTArray<nsString>& aResult) {
   uint32_t count = mAttrs.AttrCount();
   for (uint32_t i = 0; i < count; ++i) {
     const nsAttrName* name = mAttrs.AttrNameAt(i);
     name->GetQualifiedName(*aResult.AppendElement());
   }
 }
 
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -1025,16 +1025,18 @@ class Element : public FragmentOrElement
   void GetClassName(DOMString& aClassName) {
     GetAttr(kNameSpaceID_None, nsGkAtoms::_class, aClassName);
   }
   void SetClassName(const nsAString& aClassName) {
     SetAttr(kNameSpaceID_None, nsGkAtoms::_class, aClassName, true);
   }
 
   nsDOMTokenList* ClassList();
+  nsDOMTokenList* Part();
+
   nsDOMAttributeMap* Attributes() {
     nsDOMSlots* slots = DOMSlots();
     if (!slots->mAttributeMap) {
       slots->mAttributeMap = new nsDOMAttributeMap(this);
     }
 
     return slots->mAttributeMap;
   }
--- a/dom/base/FragmentOrElement.cpp
+++ b/dom/base/FragmentOrElement.cpp
@@ -592,27 +592,31 @@ void FragmentOrElement::nsDOMSlots::Trav
   NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mSlots->mAttributeMap");
   aCb.NoteXPCOMChild(mAttributeMap.get());
 
   NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mSlots->mChildrenList");
   aCb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsINodeList*, mChildrenList));
 
   NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mSlots->mClassList");
   aCb.NoteXPCOMChild(mClassList.get());
+
+  NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mSlots->mPart");
+  aCb.NoteXPCOMChild(mPart.get());
 }
 
 void FragmentOrElement::nsDOMSlots::Unlink() {
   nsIContent::nsContentSlots::Unlink();
   mStyle = nullptr;
   if (mAttributeMap) {
     mAttributeMap->DropReference();
     mAttributeMap = nullptr;
   }
   mChildrenList = nullptr;
   mClassList = nullptr;
+  mPart = nullptr;
 }
 
 size_t FragmentOrElement::nsDOMSlots::SizeOfIncludingThis(
     MallocSizeOf aMallocSizeOf) const {
   size_t n = aMallocSizeOf(this);
 
   nsExtendedContentSlots* extendedSlots = GetExtendedContentSlots();
   if (extendedSlots) {
--- a/dom/base/FragmentOrElement.h
+++ b/dom/base/FragmentOrElement.h
@@ -242,16 +242,21 @@ class FragmentOrElement : public nsICont
      * An object implementing the .children property for this element.
      */
     RefPtr<nsContentList> mChildrenList;
 
     /**
      * An object implementing the .classList property for this element.
      */
     RefPtr<nsDOMTokenList> mClassList;
+
+    /**
+     * An object implementing the .part property for this element.
+     */
+    RefPtr<nsDOMTokenList> mPart;
   };
 
   /**
    * In case ExtendedDOMSlots is needed before normal DOMSlots, an instance of
    * FatSlots class, which combines those two slot types, is created.
    * This way we can avoid extra allocation for ExtendedDOMSlots.
    * FatSlots is useful for example when creating Custom Elements.
    */
--- a/dom/webidl/Element.webidl
+++ b/dom/webidl/Element.webidl
@@ -28,16 +28,20 @@ interface Element : Node {
 
   [CEReactions, Pure]
            attribute DOMString id;
   [CEReactions, Pure]
            attribute DOMString className;
   [Constant, PutForwards=value]
   readonly attribute DOMTokenList classList;
 
+  // https://drafts.csswg.org/css-shadow-parts/#idl
+  [SameObject, PutForwards=value, Pref="layout.css.shadow-parts.enabled"]
+  readonly attribute DOMTokenList part;
+
   [SameObject]
   readonly attribute NamedNodeMap attributes;
   [Pure]
   sequence<DOMString> getAttributeNames();
   [Pure]
   DOMString? getAttribute(DOMString name);
   [Pure]
   DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
deleted file mode 100644
--- a/testing/web-platform/meta/css/css-shadow-parts/invalidation-change-part-name-idl-domtokenlist.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[invalidation-change-part-name-idl-domtokenlist.html]
-  [Part in selected host changed color via part IDL DOMTokenList attribute.]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/css/css-shadow-parts/invalidation-change-part-name-idl-setter.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[invalidation-change-part-name-idl-setter.html]
-  [Part in selected host changed color via part IDL attribute setter.]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/css/css-shadow-parts/part-name-idl.html.ini
+++ /dev/null
@@ -1,13 +0,0 @@
-[part-name-idl.html]
-  [Access to .part returns an empty DOMTokenList.]
-    expected: FAIL
-
-  [Changes in DOMTokenList are refected in attribute.]
-    expected: FAIL
-
-  [DOMTokenList created by access is persisted.]
-    expected: FAIL
-
-  [Multiple names give a DOMTokenList with multiple entries.]
-    expected: FAIL
-