diff --git a/spec/custom/index.html b/spec/custom/index.html index eeb1b77b..b5d48f88 100644 --- a/spec/custom/index.html +++ b/spec/custom/index.html @@ -185,6 +185,12 @@

Concepts

In general, only documents associated with a browsing context have non-null custom element registries. Trying to register or create custom elements in other documents, such as those created by createDocument method or a template contents owner document, will fail.

+

Element registration is a process of adding a custom element definition to a custom element registry.

+ +

Because element registration can occur at any time, a non-custom element could be created that might in the future become a custom element after an appropriate definition is registered. Such elements are called undefined potentially-custom elements. If such a definition is ever registered, the element will be upgraded, becoming a custom element.

+ +

Each custom element registry has an associated upgrade candidates map tracking undefined potentially-custom elements. Each entry has a key that is a valid custom element name and a value that is a sorted element queue. It is is initially empty.

+

To create an element, given a document, localName, prefix, namespace, typeExtension, and optional synchronous custom elements flag, run the following steps:

    @@ -198,28 +204,44 @@

    Concepts

  1. If namespace is not the HTML namespace, throw a TypeError exception and abort these steps.
  2. -
  3. Let definition be the entry in registry with name typeExtension.
  4. +
  5. Let interface be the element interface for localName and the HTML namespace.
  6. -
  7. If definition's local name is not localName, throw a TypeError exception and abort these steps.
  8. +
  9. +

    If there is an the entry in registry with name typeExtension, let definition be that entry, and perform the following subsubsteps:

    -
  10. Let interface be the element interface for localName and the HTML namespace.
  11. +
      +
    1. If definition's local name is not localName, throw a TypeError exception and abort these steps.
    2. -
    3. Let result be a new element that implements interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix, local name set to localName, and node document set to document.
    4. +
    5. Let result be a new element that implements interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix, local name set to localName, defined flag unset, and node document set to document.
    6. -
    7. Set an attribute value for result using "is" and type.
    8. +
    9. Set an attribute value for result using "is" and type.
    10. -
    11. Enqueue a custom element upgrade given result.
    12. +
    13. Enqueue a custom element upgrade given result and definition.
    14. -
    15. Return result.
    16. +
    17. Return result.
    18. +
    + + +
  12. +

    Otherwise:

    + +
      +
    1. Let result be a new element that implements interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix, local name set to localName, defined flag unset, and node document set to document.
    2. + +
    3. Set an attribute value for result using "is" and type.
    4. + +
    5. Let upgrade queue be the sorted element queue that is the value of the entry in registry's upgrade candidates map with key typeExtension, creating an empty sorted element queue if no such entry exists.
    6. + +
    7. Enqueue result in upgrade queue.
    8. +
    +
  • -

    Otherwise, if registry is not null, namespace is the HTML namespace, and registry contains an entry with local name localName:

    +

    Otherwise, if registry is not null, namespace is the HTML namespace, and registry contains an entry with local name localName, let definition be that entry, and perform the following substeps:

      -
    1. Let definition be the entry in registry with local name localName.
    2. -
    3. If synchronous custom elements flag is set:

      @@ -234,6 +256,8 @@

      Concepts

      This is meant to be a brand check to ensure that the object was allocated by the HTMLElement constructor. Eventually Web IDL may give us a more precise way to do brand checks.

    4. +
    5. Set result's defined flag.
    6. +
    7. Return result.
  • @@ -242,9 +266,9 @@

    Concepts

    Otherwise:

      -
    1. Let result be a new element that implements the HTMLElement interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix, local name set to localName, and node document set document.
    2. +
    3. Let result be a new element that implements the HTMLElement interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix, local name set to localName, defined flag unset, and node document set document.
    4. -
    5. Enqueue a custom element upgrade given result.
    6. +
    7. Enqueue a custom element upgrade given result and definition.
    8. Return result.
    @@ -258,7 +282,15 @@

    Concepts

    1. Let interface be the element interface for localName and namespace.
    2. -
    3. Return a new element that implements interface, with no attributes, namespace set to namespace, namespace prefix set to prefix, local name set to localName, and node document set to the context object.
    4. +
    5. Let result be a new element that implements interface, with no attributes, namespace set to namespace, namespace prefix set to prefix, local name set to localName, defined flag is set, and node document set to the context object.
    6. + +
    7. If namespace is the HTML namespace, and localName is a valid custom element name, unset result's defined flag.
    8. + +
    9. Let upgrade queue be the sorted element queue that is the value of the entry in registry's upgrade candidates map with key localName, creating an empty sorted element queue if no such entry exists.
    10. + +
    11. Enqueue result in upgrade queue.
    12. + +
    13. Return result.
    @@ -271,6 +303,38 @@

    Registry-Related Changes to the HTML Standard

    Inside the algorithm for the document.open() method, add a step (near step 18, replacing the Document's singleton objects) that sets the Document's custom element registry to a new empty set.

    +
    +

    Element Interface Addition to the HTML Standard

    + +

    HTML currently does not do a great job of defining DOM's element interface concept. There is a definition hidden inside the parser, but it isn't explicit that this also covers other element creation cases. We should create a section that is more explicit, and it should roughly contain the following (including the note afterward):

    + +

    The element interface for an element with name name in the HTML namespace is determined as follows:

    + +
      +
    1. If this specification defines an interface appropriate for the element type corresponding to the tag name name, return that interface.
    2. +
    3. If other applicable specifications define such an appropriate interface for name, return the interface they define.
    4. +
    5. If name is a valid custom element name, return HTMLElement.
    6. +
    7. Otherwise, return HTMLUnknownElement.
    8. +
    + +

    + The use of HTMLElement instead of HTMLUnknownElement in the case of valid custom element names is done to ensure that any potential future upgrades only cause a linear transition of the element's prototype chain, from HTMLElement to a subclass, instead of a lateral one, from HTMLUnknownElement to an unrelated subclass. +

    + +
    + +
    +

    Element Changes to the DOM Standard

    + +

    The Element interface section will need to be modified as follows. The paragraph listing the values associated with an element should be modified to read as follows, including the note afterward:

    + +

    Elements have an associated namespace, namespace prefix, local name, and defined flag. When an element is created, all of these values are set. An element whose defined flag is set is said to be defined.

    + +

    + As detailed elsewhere in this specification, all elements that are not custom elements are already defined upon their creation. Custom elements become defined once their constructor has been called, either synchronously or during the upgrade process. +

    +
    +

    Cloning Changes to the DOM Standard

    @@ -338,19 +402,9 @@

    Enqueuing and Invoking Callbacks

  • If element's element is being created flag is false, add element to the current element queue.
  • -

    To enqueue a custom element upgrade, given an element element, run the following steps:

    +

    To enqueue a custom element upgrade, given an element element and custom element definition definition, run the following steps:

      -
    1. Let registry be the custom element registry for element's node document.
    2. - -
    3. Assert: registry is not null.
    4. - -
    5. - Let definition be the the entry in registry with entry name equal to element's custom element name. - -

      This algorithm can only be called when such a definition exists.

      -
    6. -
    7. Add an upgrade action to element's custom element action queue, with custom element definition definition.
    8. If element's element is being created flag is false, add element to the current element queue.
    9. @@ -494,20 +548,6 @@

      Changes to DOM's Mutation Algorithms

      Registering Custom Elements

      -

      Element registration is a process of adding an custom element definition to a custom element registry.

      - -

      Because element registration can occur at any time, a custom element could be created before its definition is registered. Such custom element instances are called unresolved elements. When an unresolved element is created, and if its element interface was not defined by HTML or other applicable specifications, the unresolved element's element interface MUST be HTMLElement.

      - -
      -The effect of this statement is that any HTML element with a local name that is a valid custom element name will have HTMLElement as its element interface, rather than HTMLUnknownElement. -
      - -

      Each custom element registry has an associated upgrade candidates map of all instances of unresolved elements, mapping a valid custom element name to a sorted element queue. It is is initially empty.

      - -

      Whenever an unresolved element is created, it MUST be added to the respective sorted element queue in upgrade candidates map.

      - -

      Elements are upgraded from being unresolved by the upgrade a newly-defined element algorithm.

      -

      New Document Method

      @@ -611,15 +651,6 @@

      New Document -

      -
      -

      :unresolved Element Pseudo-class

      - -

      The :unresolved pseudo-class [[!CSS3-SELECTORS]] MUST match all custom elements whose custom element constructor has not yet been invoked.

      - -
      -

      The :unresolved pseudo-class could be used to mitigate the flash of unstyled content [[FOUC]] issues with custom elements. -

      @@ -749,7 +780,7 @@

      Upgrading

    10. Let candidates be the sorted element queue which is the value of the entry in map with key name.
    11. -
    12. For each element candidate in candidates, enqueue a custom element upgrade for candidate.
    13. +
    14. For each element candidate in candidates, enqueue a custom element upgrade given candidate and definition.
    15. Set the value of the entry in map whose key is name to an empty sorted element queue.
    @@ -772,6 +803,8 @@

    Upgrading

    This can occur if C constructs another instance of the same custom element before calling super(), or if C uses JavaScript's return-override feature to return an arbitrary object from the constructor.

    + +
  • Set element's defined flag.
  • @@ -786,6 +819,20 @@

    Changes to Cloning

    +
    +

    Additions to CSS

    + +
    +

    The Defined Element Pseudo-class: ':defined'

    + +

    The ':defined' pseudo-class applies to elements that are defined.

    + +

    +The ':defined' pseudo-class can be used to mitigate the flash of unstyled content [[FOUC]] issues with custom elements. +

    +
    +
    +

    Custom Element Semantics

    The default semantics of a custom element is dependent upon the form in which it is instantiated: