Skip to content

Commit

Permalink
custom-elements: Implement customElements.upgrade().
Browse files Browse the repository at this point in the history
Intent-to-implement-and-ship: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/zCQe7UkR07w

Bug: 819482
Change-Id: I5645d5711d7fe1323992533e6c73593ba59d1bca
Reviewed-on: https://chromium-review.googlesource.com/1009450
Reviewed-by: Hayato Ito <hayato@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550513}
  • Loading branch information
tkent-google authored and Commit Bot committed Apr 13, 2018
1 parent 5cf8deb commit d9efd42
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 8 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5456,6 +5456,8 @@ PASS CustomElementRegistry interface: operation get(DOMString)
PASS Unscopable handled correctly for get(DOMString) on CustomElementRegistry
PASS CustomElementRegistry interface: operation whenDefined(DOMString)
PASS Unscopable handled correctly for whenDefined(DOMString) on CustomElementRegistry
PASS CustomElementRegistry interface: operation upgrade(Node)
PASS Unscopable handled correctly for upgrade(Node) on CustomElementRegistry
PASS DataTransfer interface: existence and properties of interface object
PASS DataTransfer interface object length
PASS DataTransfer interface object name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,7 @@ interface CustomElementRegistry {
[CEReactions] void define(DOMString name, Function constructor, optional ElementDefinitionOptions options);
any get(DOMString name);
Promise<void> whenDefined(DOMString name);
[CEReactions] void upgrade(Node root);
};

dictionary ElementDefinitionOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ interface CustomElementRegistry
method constructor
method define
method get
method upgrade
method whenDefined
interface CustomEvent : Event
attribute @@toStringTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,7 @@ interface CustomElementRegistry
method constructor
method define
method get
method upgrade
method whenDefined
interface CustomEvent : Event
attribute @@toStringTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/element_definition_options.h"
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/exception_code.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/html/custom/ce_reactions_scope.h"
#include "third_party/blink/renderer/core/html/custom/custom_element.h"
Expand All @@ -30,6 +32,25 @@

namespace blink {

namespace {

void CollectUpgradeCandidateInNode(Node& root,
HeapVector<Member<Element>>& candidates) {
if (root.IsElementNode()) {
Element& root_element = ToElement(root);
if (root_element.GetCustomElementState() == CustomElementState::kUndefined)
candidates.push_back(root_element);
if (auto* shadow_root = root_element.GetShadowRoot()) {
if (shadow_root->GetType() != ShadowRootType::kUserAgent)
CollectUpgradeCandidateInNode(*shadow_root, candidates);
}
}
for (auto& element : Traversal<HTMLElement>::ChildrenOf(root))
CollectUpgradeCandidateInNode(element, candidates);
}

} // anonymous namespace

// Returns true if |name| is invalid.
static bool ThrowIfInvalidName(const AtomicString& name,
ExceptionState& exception_state) {
Expand Down Expand Up @@ -337,4 +358,19 @@ void CustomElementRegistry::CollectCandidates(
sorter.Sorted(elements, document);
}

// https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-upgrade
void CustomElementRegistry::upgrade(Node* root) {
DCHECK(root);

// 1. Let candidates be a list of all of root's shadow-including
// inclusive descendant elements, in tree order.
HeapVector<Member<Element>> candidates;
CollectUpgradeCandidateInNode(*root, candidates);

// 2. For each candidate of candidates, try to upgrade candidate.
for (auto& candidate : candidates) {
CustomElement::TryToUpgrade(candidate);
}
}

} // namespace blink
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class CORE_EXPORT CustomElementRegistry final : public ScriptWrappable {
ScriptPromise whenDefined(ScriptState*,
const AtomicString& name,
ExceptionState&);
void upgrade(Node* root);

void Entangle(V0CustomElementRegistrationContext*);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ interface CustomElementRegistry {
[CallWith=ScriptState, CEReactions, CustomElementCallbacks, RaisesException, MeasureAs=CustomElementRegistryDefine] void define(DOMString name, Function constructor, optional ElementDefinitionOptions options);
any get(DOMString name);
[CallWith=ScriptState,RaisesException] Promise<void> whenDefined(DOMString name);
[CEReactions] void upgrade(Node root);
};

0 comments on commit d9efd42

Please sign in to comment.