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

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

Issue 1914923002: Rename all existing custom element classes as V0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CustomElementV0 -> V0CustomElement Created 4 years, 7 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
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * 3. Neither the name of Google Inc. nor the names of its contributors
15 * may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "core/dom/custom/CustomElementRegistrationContext.h"
32
33 #include "bindings/core/v8/ExceptionState.h"
34 #include "core/HTMLNames.h"
35 #include "core/SVGNames.h"
36 #include "core/dom/Document.h"
37 #include "core/dom/Element.h"
38 #include "core/dom/custom/CustomElement.h"
39 #include "core/dom/custom/CustomElementDefinition.h"
40 #include "core/dom/custom/CustomElementScheduler.h"
41 #include "core/html/HTMLElement.h"
42 #include "core/html/HTMLUnknownElement.h"
43 #include "core/svg/SVGUnknownElement.h"
44
45 namespace blink {
46
47 CustomElementRegistrationContext::CustomElementRegistrationContext()
48 : m_candidates(CustomElementUpgradeCandidateMap::create())
49 {
50 }
51
52 void CustomElementRegistrationContext::registerElement(Document* document, Custo mElementConstructorBuilder* constructorBuilder, const AtomicString& type, Custom Element::NameSet validNames, ExceptionState& exceptionState)
53 {
54 CustomElementDefinition* definition = m_registry.registerElement(document, c onstructorBuilder, type, validNames, exceptionState);
55
56 if (!definition)
57 return;
58
59 // Upgrade elements that were waiting for this definition.
60 CustomElementUpgradeCandidateMap::ElementSet* upgradeCandidates = m_candidat es->takeUpgradeCandidatesFor(definition->descriptor());
61
62 if (!upgradeCandidates)
63 return;
64
65 for (const auto& candidate : *upgradeCandidates)
66 CustomElement::define(candidate, definition);
67 }
68
69 Element* CustomElementRegistrationContext::createCustomTagElement(Document& docu ment, const QualifiedName& tagName)
70 {
71 DCHECK(CustomElement::isValidName(tagName.localName()));
72
73 Element* element;
74
75 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) {
76 element = HTMLElement::create(tagName, document);
77 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) {
78 element = SVGUnknownElement::create(tagName, document);
79 } else {
80 // XML elements are not custom elements, so return early.
81 return Element::create(tagName, &document);
82 }
83
84 element->setCustomElementState(Element::WaitingForUpgrade);
85 resolveOrScheduleResolution(element, nullAtom);
86 return element;
87 }
88
89 void CustomElementRegistrationContext::didGiveTypeExtension(Element* element, co nst AtomicString& type)
90 {
91 resolveOrScheduleResolution(element, type);
92 }
93
94 void CustomElementRegistrationContext::resolveOrScheduleResolution(Element* elem ent, const AtomicString& typeExtension)
95 {
96 // If an element has a custom tag name it takes precedence over
97 // the "is" attribute (if any).
98 const AtomicString& type = CustomElement::isValidName(element->localName())
99 ? element->localName()
100 : typeExtension;
101 DCHECK(!type.isNull());
102
103 CustomElementDescriptor descriptor(type, element->namespaceURI(), element->l ocalName());
104 DCHECK_EQ(element->getCustomElementState(), Element::WaitingForUpgrade);
105
106 CustomElementScheduler::resolveOrScheduleResolution(this, element, descripto r);
107 }
108
109 void CustomElementRegistrationContext::resolve(Element* element, const CustomEle mentDescriptor& descriptor)
110 {
111 CustomElementDefinition* definition = m_registry.find(descriptor);
112 if (definition) {
113 CustomElement::define(element, definition);
114 } else {
115 DCHECK_EQ(element->getCustomElementState(), Element::WaitingForUpgrade);
116 m_candidates->add(descriptor, element);
117 }
118 }
119
120 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* e lement, const AtomicString& type)
121 {
122 DCHECK(element);
123 DCHECK(!type.isEmpty());
124 element->setAttribute(HTMLNames::isAttr, type);
125 setTypeExtension(element, type);
126 }
127
128 void CustomElementRegistrationContext::setTypeExtension(Element* element, const AtomicString& type)
129 {
130 if (!element->isHTMLElement() && !element->isSVGElement())
131 return;
132
133 CustomElementRegistrationContext* context = element->document().registration Context();
134 if (!context)
135 return;
136
137 if (element->isCustomElement()) {
138 // This can happen if:
139 // 1. The element has a custom tag, which takes precedence over
140 // type extensions.
141 // 2. Undoing a command (eg ReplaceNodeWithSpan) recycles an
142 // element but tries to overwrite its attribute list.
143 return;
144 }
145
146 // Custom tags take precedence over type extensions
147 DCHECK(!CustomElement::isValidName(element->localName()));
148
149 if (!CustomElement::isValidName(type))
150 return;
151
152 element->setCustomElementState(Element::WaitingForUpgrade);
153 context->didGiveTypeExtension(element, element->document().convertLocalName( type));
154 }
155
156 DEFINE_TRACE(CustomElementRegistrationContext)
157 {
158 visitor->trace(m_candidates);
159 visitor->trace(m_registry);
160 }
161
162 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698