| OLD | NEW |
| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 return false; | 81 return false; |
| 82 | 82 |
| 83 return Document::isValidName(name.string()); | 83 return Document::isValidName(name.string()); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool CustomElement::isCustomTagName(const AtomicString& localName) | 86 bool CustomElement::isCustomTagName(const AtomicString& localName) |
| 87 { | 87 { |
| 88 return isValidTypeName(localName); | 88 return isValidTypeName(localName); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void CustomElement::define(Element* element, PassRefPtr<CustomElementDefinition>
definition) | 91 void CustomElement::define(Element* element, PassRefPtr<CustomElementDefinition>
passDefinition) |
| 92 { | 92 { |
| 93 definitions().add(element, definition); | 93 RefPtr<CustomElementDefinition> definition(passDefinition); |
| 94 |
| 95 switch (element->customElementState()) { |
| 96 case Element::NotCustomElement: |
| 97 case Element::Upgraded: |
| 98 ASSERT_NOT_REACHED(); |
| 99 break; |
| 100 |
| 101 case Element::WaitingForParser: |
| 102 definitions().add(element, definition); |
| 103 break; |
| 104 |
| 105 case Element::WaitingForUpgrade: |
| 106 definitions().add(element, definition); |
| 107 CustomElementCallbackScheduler::scheduleCreatedCallback(definition->call
backs(), element); |
| 108 break; |
| 109 } |
| 94 } | 110 } |
| 95 | 111 |
| 96 CustomElementDefinition* CustomElement::definitionFor(Element* element) | 112 CustomElementDefinition* CustomElement::definitionFor(Element* element) |
| 97 { | 113 { |
| 98 return definitions().get(element); | 114 CustomElementDefinition* definition = definitions().get(element); |
| 115 ASSERT(definition); |
| 116 return definition; |
| 117 } |
| 118 |
| 119 void CustomElement::didFinishParsingChildren(Element* element) |
| 120 { |
| 121 ASSERT(element->customElementState() == Element::WaitingForParser); |
| 122 element->setCustomElementState(Element::WaitingForUpgrade); |
| 123 |
| 124 CustomElementObserver::notifyElementDidFinishParsingChildren(element); |
| 125 |
| 126 if (CustomElementDefinition* definition = definitions().get(element)) |
| 127 CustomElementCallbackScheduler::scheduleCreatedCallback(definition->call
backs(), element); |
| 99 } | 128 } |
| 100 | 129 |
| 101 void CustomElement::attributeDidChange(Element* element, const AtomicString& nam
e, const AtomicString& oldValue, const AtomicString& newValue) | 130 void CustomElement::attributeDidChange(Element* element, const AtomicString& nam
e, const AtomicString& oldValue, const AtomicString& newValue) |
| 102 { | 131 { |
| 103 ASSERT(element->customElementState() == Element::Upgraded); | 132 ASSERT(element->customElementState() == Element::Upgraded); |
| 104 CustomElementCallbackScheduler::scheduleAttributeChangedCallback(definitions
().get(element)->callbacks(), element, name, oldValue, newValue); | 133 CustomElementCallbackScheduler::scheduleAttributeChangedCallback(definitionF
or(element)->callbacks(), element, name, oldValue, newValue); |
| 105 } | 134 } |
| 106 | 135 |
| 107 void CustomElement::didEnterDocument(Element* element, Document* document) | 136 void CustomElement::didEnterDocument(Element* element, Document* document) |
| 108 { | 137 { |
| 109 ASSERT(element->customElementState() == Element::Upgraded); | 138 ASSERT(element->customElementState() == Element::Upgraded); |
| 110 if (!document->defaultView()) | 139 if (!document->defaultView()) |
| 111 return; | 140 return; |
| 112 CustomElementCallbackScheduler::scheduleEnteredDocumentCallback(definitions(
).get(element)->callbacks(), element); | 141 CustomElementCallbackScheduler::scheduleEnteredDocumentCallback(definitionFo
r(element)->callbacks(), element); |
| 113 } | 142 } |
| 114 | 143 |
| 115 void CustomElement::didLeaveDocument(Element* element, Document* document) | 144 void CustomElement::didLeaveDocument(Element* element, Document* document) |
| 116 { | 145 { |
| 117 ASSERT(element->customElementState() == Element::Upgraded); | 146 ASSERT(element->customElementState() == Element::Upgraded); |
| 118 if (!document->defaultView()) | 147 if (!document->defaultView()) |
| 119 return; | 148 return; |
| 120 CustomElementCallbackScheduler::scheduleLeftDocumentCallback(definitions().g
et(element)->callbacks(), element); | 149 CustomElementCallbackScheduler::scheduleLeftDocumentCallback(definitionFor(e
lement)->callbacks(), element); |
| 121 } | 150 } |
| 122 | 151 |
| 123 void CustomElement::wasDestroyed(Element* element) | 152 void CustomElement::wasDestroyed(Element* element) |
| 124 { | 153 { |
| 125 switch (element->customElementState()) { | 154 switch (element->customElementState()) { |
| 126 case Element::NotCustomElement: | 155 case Element::NotCustomElement: |
| 127 ASSERT_NOT_REACHED(); | 156 ASSERT_NOT_REACHED(); |
| 128 break; | 157 break; |
| 129 | 158 |
| 159 case Element::WaitingForParser: |
| 130 case Element::WaitingForUpgrade: | 160 case Element::WaitingForUpgrade: |
| 131 case Element::Upgraded: | 161 case Element::Upgraded: |
| 132 definitions().remove(element); | 162 definitions().remove(element); |
| 133 CustomElementObserver::notifyElementWasDestroyed(element); | 163 CustomElementObserver::notifyElementWasDestroyed(element); |
| 134 break; | 164 break; |
| 135 } | 165 } |
| 136 } | 166 } |
| 137 | 167 |
| 138 void CustomElement::DefinitionMap::add(Element* element, PassRefPtr<CustomElemen
tDefinition> definition) | 168 void CustomElement::DefinitionMap::add(Element* element, PassRefPtr<CustomElemen
tDefinition> definition) |
| 139 { | 169 { |
| 140 ASSERT(definition.get()); | 170 ASSERT(definition.get()); |
| 141 DefinitionMap::ElementDefinitionHashMap::AddResult result = m_definitions.ad
d(element, definition); | 171 DefinitionMap::ElementDefinitionHashMap::AddResult result = m_definitions.ad
d(element, definition); |
| 142 ASSERT(result.isNewEntry); | 172 ASSERT(result.isNewEntry); |
| 143 } | 173 } |
| 144 | 174 |
| 145 void CustomElement::DefinitionMap::remove(Element* element) | |
| 146 { | |
| 147 m_definitions.remove(element); | |
| 148 } | |
| 149 | |
| 150 CustomElementDefinition* CustomElement::DefinitionMap::get(Element* element) | |
| 151 { | |
| 152 DefinitionMap::ElementDefinitionHashMap::const_iterator it = m_definitions.f
ind(element); | |
| 153 ASSERT(it != m_definitions.end()); | |
| 154 return it->value.get(); | |
| 155 } | |
| 156 | |
| 157 CustomElement::DefinitionMap& CustomElement::definitions() | 175 CustomElement::DefinitionMap& CustomElement::definitions() |
| 158 { | 176 { |
| 159 DEFINE_STATIC_LOCAL(DefinitionMap, map, ()); | 177 DEFINE_STATIC_LOCAL(DefinitionMap, map, ()); |
| 160 return map; | 178 return map; |
| 161 } | 179 } |
| 162 | 180 |
| 163 } // namespace WebCore | 181 } // namespace WebCore |
| OLD | NEW |