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

Side by Side Diff: Source/core/dom/CustomElement.cpp

Issue 25777002: Move custom element code to core/dom/custom/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/CustomElement.h ('k') | Source/core/dom/CustomElementCallbackDispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "config.h"
32 #include "core/dom/CustomElement.h"
33
34 #include "HTMLNames.h"
35 #include "MathMLNames.h"
36 #include "RuntimeEnabledFeatures.h"
37 #include "SVGNames.h"
38 #include "core/dom/CustomElementCallbackScheduler.h"
39 #include "core/dom/CustomElementObserver.h"
40 #include "core/dom/Element.h"
41
42 namespace WebCore {
43
44 Vector<AtomicString>& CustomElement::embedderCustomElementNames()
45 {
46 DEFINE_STATIC_LOCAL(Vector<AtomicString>, names, ());
47 return names;
48 }
49
50 void CustomElement::addEmbedderCustomElementName(const AtomicString& name)
51 {
52 AtomicString lower = name.lower();
53 if (isValidName(lower, EmbedderNames))
54 return;
55 embedderCustomElementNames().append(lower);
56 }
57
58 static CustomElement::NameSet enabledNameSet()
59 {
60 return CustomElement::NameSet((RuntimeEnabledFeatures::customElementsEnabled () ? CustomElement::StandardNames : 0) | (RuntimeEnabledFeatures::embedderCustom ElementsEnabled() ? CustomElement::EmbedderNames : 0));
61 }
62
63 bool CustomElement::isValidName(const AtomicString& name, NameSet validNames)
64 {
65 validNames = NameSet(validNames & enabledNameSet());
66
67 if ((validNames & EmbedderNames) && kNotFound != embedderCustomElementNames( ).find(name))
68 return Document::isValidName(name);
69
70 if ((validNames & StandardNames) && kNotFound != name.find('-')) {
71 DEFINE_STATIC_LOCAL(Vector<AtomicString>, reservedNames, ());
72 if (reservedNames.isEmpty()) {
73 reservedNames.append(MathMLNames::annotation_xmlTag.localName());
74 reservedNames.append(SVGNames::color_profileTag.localName());
75 reservedNames.append(SVGNames::font_faceTag.localName());
76 reservedNames.append(SVGNames::font_face_srcTag.localName());
77 reservedNames.append(SVGNames::font_face_uriTag.localName());
78 reservedNames.append(SVGNames::font_face_formatTag.localName());
79 reservedNames.append(SVGNames::font_face_nameTag.localName());
80 reservedNames.append(SVGNames::missing_glyphTag.localName());
81 }
82
83 if (kNotFound == reservedNames.find(name))
84 return Document::isValidName(name.string());
85 }
86
87 return false;
88 }
89
90 void CustomElement::define(Element* element, PassRefPtr<CustomElementDefinition> passDefinition)
91 {
92 RefPtr<CustomElementDefinition> definition(passDefinition);
93
94 switch (element->customElementState()) {
95 case Element::NotCustomElement:
96 case Element::Upgraded:
97 ASSERT_NOT_REACHED();
98 break;
99
100 case Element::WaitingForParser:
101 definitions().add(element, definition);
102 break;
103
104 case Element::WaitingForUpgrade:
105 definitions().add(element, definition);
106 CustomElementCallbackScheduler::scheduleCreatedCallback(definition->call backs(), element);
107 break;
108 }
109 }
110
111 CustomElementDefinition* CustomElement::definitionFor(Element* element)
112 {
113 CustomElementDefinition* definition = definitions().get(element);
114 ASSERT(definition);
115 return definition;
116 }
117
118 void CustomElement::didFinishParsingChildren(Element* element)
119 {
120 ASSERT(element->customElementState() == Element::WaitingForParser);
121 element->setCustomElementState(Element::WaitingForUpgrade);
122
123 CustomElementObserver::notifyElementDidFinishParsingChildren(element);
124
125 if (CustomElementDefinition* definition = definitions().get(element))
126 CustomElementCallbackScheduler::scheduleCreatedCallback(definition->call backs(), element);
127 }
128
129 void CustomElement::attributeDidChange(Element* element, const AtomicString& nam e, const AtomicString& oldValue, const AtomicString& newValue)
130 {
131 ASSERT(element->customElementState() == Element::Upgraded);
132 CustomElementCallbackScheduler::scheduleAttributeChangedCallback(definitionF or(element)->callbacks(), element, name, oldValue, newValue);
133 }
134
135 void CustomElement::didEnterDocument(Element* element, const Document& document)
136 {
137 ASSERT(element->customElementState() == Element::Upgraded);
138 if (!document.defaultView())
139 return;
140 CustomElementCallbackScheduler::scheduleEnteredViewCallback(definitionFor(el ement)->callbacks(), element);
141 }
142
143 void CustomElement::didLeaveDocument(Element* element, const Document& document)
144 {
145 ASSERT(element->customElementState() == Element::Upgraded);
146 if (!document.defaultView())
147 return;
148 CustomElementCallbackScheduler::scheduleLeftViewCallback(definitionFor(eleme nt)->callbacks(), element);
149 }
150
151 void CustomElement::wasDestroyed(Element* element)
152 {
153 switch (element->customElementState()) {
154 case Element::NotCustomElement:
155 ASSERT_NOT_REACHED();
156 break;
157
158 case Element::WaitingForParser:
159 case Element::WaitingForUpgrade:
160 case Element::Upgraded:
161 definitions().remove(element);
162 CustomElementObserver::notifyElementWasDestroyed(element);
163 break;
164 }
165 }
166
167 void CustomElement::DefinitionMap::add(Element* element, PassRefPtr<CustomElemen tDefinition> definition)
168 {
169 ASSERT(definition.get());
170 DefinitionMap::ElementDefinitionHashMap::AddResult result = m_definitions.ad d(element, definition);
171 ASSERT(result.isNewEntry);
172 }
173
174 CustomElement::DefinitionMap& CustomElement::definitions()
175 {
176 DEFINE_STATIC_LOCAL(DefinitionMap, map, ());
177 return map;
178 }
179
180 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/CustomElement.h ('k') | Source/core/dom/CustomElementCallbackDispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698