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

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElement.cpp

Issue 2043153003: Implement "create an element" when async for Custom Element V1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/custom/CustomElement.h" 5 #include "core/dom/custom/CustomElement.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/QualifiedName.h" 8 #include "core/dom/QualifiedName.h"
9 #include "core/dom/custom/CEReactionsScope.h" 9 #include "core/dom/custom/CEReactionsScope.h"
10 #include "core/dom/custom/CustomElementDefinition.h"
10 #include "core/dom/custom/CustomElementUpgradeReaction.h" 11 #include "core/dom/custom/CustomElementUpgradeReaction.h"
12 #include "core/dom/custom/CustomElementsRegistry.h"
11 #include "core/dom/custom/V0CustomElement.h" 13 #include "core/dom/custom/V0CustomElement.h"
12 #include "core/dom/custom/V0CustomElementRegistrationContext.h" 14 #include "core/dom/custom/V0CustomElementRegistrationContext.h"
13 #include "core/frame/LocalDOMWindow.h" 15 #include "core/frame/LocalDOMWindow.h"
14 #include "core/html/HTMLElement.h" 16 #include "core/html/HTMLElement.h"
15 #include "platform/text/Character.h" 17 #include "platform/text/Character.h"
16 #include "wtf/text/AtomicStringHash.h" 18 #include "wtf/text/AtomicStringHash.h"
17 19
18 namespace blink { 20 namespace blink {
19 21
20 CustomElementsRegistry* CustomElement::registry(const Element& element) 22 CustomElementsRegistry* CustomElement::registry(const Element& element)
21 { 23 {
22 if (LocalDOMWindow* window = element.document().domWindow()) 24 return registry(element.document());
25 }
26
27 CustomElementsRegistry* CustomElement::registry(const Document& document)
28 {
29 if (LocalDOMWindow* window = document.domWindow())
23 return window->customElements(); 30 return window->customElements();
24 return nullptr; 31 return nullptr;
25 } 32 }
26 33
27 bool CustomElement::isValidName(const AtomicString& name) 34 bool CustomElement::isValidName(const AtomicString& name)
28 { 35 {
29 if (!name.length() || name[0] < 'a' || name[0] > 'z') 36 if (!name.length() || name[0] < 'a' || name[0] > 'z')
30 return false; 37 return false;
31 38
32 bool hasHyphens = false; 39 bool hasHyphens = false;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 75
69 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie dName& tagName) 76 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie dName& tagName)
70 { 77 {
71 return shouldCreateCustomElement(document, tagName.localName()) 78 return shouldCreateCustomElement(document, tagName.localName())
72 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; 79 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI;
73 } 80 }
74 81
75 HTMLElement* CustomElement::createCustomElement(Document& document, const Atomic String& localName, CreateElementFlags flags) 82 HTMLElement* CustomElement::createCustomElement(Document& document, const Atomic String& localName, CreateElementFlags flags)
76 { 83 {
77 return createCustomElement(document, 84 return createCustomElement(document,
78 QualifiedName(nullAtom, document.convertLocalName(localName), HTMLNames: :xhtmlNamespaceURI), 85 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI),
79 flags); 86 flags);
80 } 87 }
81 88
82 HTMLElement* CustomElement::createCustomElement(Document& document, const Qualif iedName& tagName, CreateElementFlags flags) 89 HTMLElement* CustomElement::createCustomElement(Document& document, const Qualif iedName& tagName, CreateElementFlags flags)
83 { 90 {
84 DCHECK(shouldCreateCustomElement(document, tagName)); 91 DCHECK(shouldCreateCustomElement(document, tagName));
85 92
86 // TODO(kojii): Look up already defined custom elements when custom element 93 // To create an element:
87 // queues and upgrade are implemented. 94 // https://dom.spec.whatwg.org/#concept-create-element
95 // 6. If definition is non-null, then:
96 HTMLElement* element;
97 if (CustomElementsRegistry* registry = CustomElement::registry(document)) {
98 if (CustomElementDefinition* definition = registry->definitionForName(ta gName.localName())) {
99 // 6.2. If the synchronous custom elements flag is not set:
100 if (flags & AsynchronousCustomElements)
101 return createCustomElementAsync(document, *definition, tagName);
88 102
89 HTMLElement* element; 103 // TODO(kojii): Synchronous mode implementation coming after async.
104 }
105 }
106
90 if (V0CustomElement::isValidName(tagName.localName()) && document.registrati onContext()) { 107 if (V0CustomElement::isValidName(tagName.localName()) && document.registrati onContext()) {
91 Element* v0element = document.registrationContext()->createCustomTagElem ent(document, tagName); 108 Element* v0element = document.registrationContext()->createCustomTagElem ent(document, tagName);
92 SECURITY_DCHECK(v0element->isHTMLElement()); 109 SECURITY_DCHECK(v0element->isHTMLElement());
93 element = toHTMLElement(v0element); 110 element = toHTMLElement(v0element);
94 } else { 111 } else {
95 element = HTMLElement::create(tagName, document); 112 element = HTMLElement::create(tagName, document);
96 } 113 }
97 114
98 element->setCustomElementState(CustomElementState::Undefined); 115 element->setCustomElementState(CustomElementState::Undefined);
99 116
100 return element; 117 return element;
101 } 118 }
102 119
120 HTMLElement* CustomElement::createCustomElementAsync(Document& document,
121 CustomElementDefinition& definition, const QualifiedName& tagName)
122 {
123 // https://dom.spec.whatwg.org/#concept-create-element
124 // 6. If definition is non-null, then:
125 // 6.2. If the synchronous custom elements flag is not set:
126 // 6.2.1. Set result to a new element that implements the HTMLElement
127 // interface, with no attributes, namespace set to the HTML namespace,
128 // namespace prefix set to prefix, local name set to localName, custom
129 // element state set to "undefined", and node document set to document.
130 HTMLElement* element = HTMLElement::create(tagName, document);
131 element->setCustomElementState(CustomElementState::Undefined);
132 // 6.2.2. Enqueue a custom element upgrade reaction given result and
133 // definition.
134 enqueueUpgradeReaction(element, &definition);
135 return element;
136 }
137
103 void CustomElement::enqueueUpgradeReaction(Element* element, CustomElementDefini tion* definition) 138 void CustomElement::enqueueUpgradeReaction(Element* element, CustomElementDefini tion* definition)
104 { 139 {
105 // CEReactionsScope must be created by [CEReactions] in IDL, 140 // CEReactionsScope must be created by [CEReactions] in IDL,
106 // or callers must setup explicitly if it does not go through bindings. 141 // or callers must setup explicitly if it does not go through bindings.
107 DCHECK(CEReactionsScope::current()); 142 DCHECK(CEReactionsScope::current());
108 CEReactionsScope::current()->enqueue(element, 143 CEReactionsScope::current()->enqueue(element,
109 new CustomElementUpgradeReaction(definition)); 144 new CustomElementUpgradeReaction(definition));
110 } 145 }
111 146
112 } // namespace blink 147 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698