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

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

Issue 177063004: Move custom element definitions into ElementRareData (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 { 90 {
91 RefPtr<CustomElementDefinition> definition(passDefinition); 91 RefPtr<CustomElementDefinition> definition(passDefinition);
92 92
93 switch (element->customElementState()) { 93 switch (element->customElementState()) {
94 case Element::NotCustomElement: 94 case Element::NotCustomElement:
95 case Element::Upgraded: 95 case Element::Upgraded:
96 ASSERT_NOT_REACHED(); 96 ASSERT_NOT_REACHED();
97 break; 97 break;
98 98
99 case Element::WaitingForUpgrade: 99 case Element::WaitingForUpgrade:
100 definitions().add(element, definition); 100 element->setCustomElementDefinition(definition);
101 CustomElementScheduler::scheduleCreatedCallback(definition->callbacks(), element); 101 CustomElementScheduler::scheduleCreatedCallback(definition->callbacks(), element);
102 break; 102 break;
103 } 103 }
104 } 104 }
105 105
106 CustomElementDefinition* CustomElement::definitionFor(Element* element)
107 {
108 CustomElementDefinition* definition = definitions().get(element);
109 ASSERT(definition);
110 return definition;
111 }
112
113 void CustomElement::attributeDidChange(Element* element, const AtomicString& nam e, const AtomicString& oldValue, const AtomicString& newValue) 106 void CustomElement::attributeDidChange(Element* element, const AtomicString& nam e, const AtomicString& oldValue, const AtomicString& newValue)
114 { 107 {
115 ASSERT(element->customElementState() == Element::Upgraded); 108 ASSERT(element->customElementState() == Element::Upgraded);
116 CustomElementScheduler::scheduleAttributeChangedCallback(definitionFor(eleme nt)->callbacks(), element, name, oldValue, newValue); 109 CustomElementScheduler::scheduleAttributeChangedCallback(element->customElem entDefinition()->callbacks(), element, name, oldValue, newValue);
117 } 110 }
118 111
119 void CustomElement::didEnterDocument(Element* element, const Document& document) 112 void CustomElement::didEnterDocument(Element* element, const Document& document)
120 { 113 {
121 ASSERT(element->customElementState() == Element::Upgraded); 114 ASSERT(element->customElementState() == Element::Upgraded);
122 if (!document.domWindow()) 115 if (!document.domWindow())
123 return; 116 return;
124 CustomElementScheduler::scheduleAttachedCallback(definitionFor(element)->cal lbacks(), element); 117 CustomElementScheduler::scheduleAttachedCallback(element->customElementDefin ition()->callbacks(), element);
125 } 118 }
126 119
127 void CustomElement::didLeaveDocument(Element* element, const Document& document) 120 void CustomElement::didLeaveDocument(Element* element, const Document& document)
128 { 121 {
129 ASSERT(element->customElementState() == Element::Upgraded); 122 ASSERT(element->customElementState() == Element::Upgraded);
130 if (!document.domWindow()) 123 if (!document.domWindow())
131 return; 124 return;
132 CustomElementScheduler::scheduleDetachedCallback(definitionFor(element)->cal lbacks(), element); 125 CustomElementScheduler::scheduleDetachedCallback(element->customElementDefin ition()->callbacks(), element);
133 } 126 }
134 127
135 void CustomElement::wasDestroyed(Element* element) 128 void CustomElement::wasDestroyed(Element* element)
136 { 129 {
137 switch (element->customElementState()) { 130 switch (element->customElementState()) {
138 case Element::NotCustomElement: 131 case Element::NotCustomElement:
139 ASSERT_NOT_REACHED(); 132 ASSERT_NOT_REACHED();
140 break; 133 break;
141 134
142 case Element::WaitingForUpgrade: 135 case Element::WaitingForUpgrade:
143 case Element::Upgraded: 136 case Element::Upgraded:
144 definitions().remove(element);
145 CustomElementObserver::notifyElementWasDestroyed(element); 137 CustomElementObserver::notifyElementWasDestroyed(element);
146 break; 138 break;
147 } 139 }
148 } 140 }
149 141
150 void CustomElement::DefinitionMap::add(Element* element, PassRefPtr<CustomElemen tDefinition> definition)
151 {
152 ASSERT(definition.get());
153 DefinitionMap::ElementDefinitionHashMap::AddResult result = m_definitions.ad d(element, definition);
154 ASSERT_UNUSED(result, result.isNewEntry);
155 }
156
157 CustomElement::DefinitionMap& CustomElement::definitions()
158 {
159 DEFINE_STATIC_LOCAL(DefinitionMap, map, ());
160 return map;
161 }
162
163 } // namespace WebCore 142 } // namespace WebCore
OLDNEW
« Source/core/dom/custom/CustomElement.h ('K') | « Source/core/dom/custom/CustomElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698