| 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 26 matching lines...) Expand all Loading... |
| 37 #include "sky/engine/core/dom/Element.h" | 37 #include "sky/engine/core/dom/Element.h" |
| 38 #include "sky/engine/core/dom/custom/CustomElement.h" | 38 #include "sky/engine/core/dom/custom/CustomElement.h" |
| 39 #include "sky/engine/core/dom/custom/CustomElementDefinition.h" | 39 #include "sky/engine/core/dom/custom/CustomElementDefinition.h" |
| 40 #include "sky/engine/core/dom/custom/CustomElementScheduler.h" | 40 #include "sky/engine/core/dom/custom/CustomElementScheduler.h" |
| 41 #include "sky/engine/core/html/HTMLElement.h" | 41 #include "sky/engine/core/html/HTMLElement.h" |
| 42 #include "sky/engine/wtf/RefPtr.h" | 42 #include "sky/engine/wtf/RefPtr.h" |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 CustomElementRegistrationContext::CustomElementRegistrationContext() | 46 CustomElementRegistrationContext::CustomElementRegistrationContext() |
| 47 : m_candidates(CustomElementUpgradeCandidateMap::create()) | |
| 48 { | 47 { |
| 49 } | 48 } |
| 50 | 49 |
| 51 void CustomElementRegistrationContext::registerElement(Document* document, Custo
mElementConstructorBuilder* constructorBuilder, const AtomicString& type, Custom
Element::NameSet validNames, ExceptionState& exceptionState) | 50 void CustomElementRegistrationContext::registerElement(Document* document, Custo
mElementConstructorBuilder* constructorBuilder, const AtomicString& type, Custom
Element::NameSet validNames, ExceptionState& exceptionState) |
| 52 { | 51 { |
| 53 CustomElementDefinition* definition = m_registry.registerElement(document, c
onstructorBuilder, type, validNames, exceptionState); | 52 m_registry.registerElement(document, constructorBuilder, type, validNames, e
xceptionState); |
| 54 | |
| 55 if (!definition) | |
| 56 return; | |
| 57 | |
| 58 // Upgrade elements that were waiting for this definition. | |
| 59 OwnPtr<CustomElementUpgradeCandidateMap::ElementSet> upgradeCandidates = m_c
andidates->takeUpgradeCandidatesFor(definition->descriptor()); | |
| 60 | |
| 61 if (!upgradeCandidates) | |
| 62 return; | |
| 63 | |
| 64 for (CustomElementUpgradeCandidateMap::ElementSet::const_iterator it = upgra
deCandidates->begin(); it != upgradeCandidates->end(); ++it) | |
| 65 CustomElement::define(*it, definition); | |
| 66 } | 53 } |
| 67 | 54 |
| 68 PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Doc
ument& document, const QualifiedName& tagName) | 55 PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Doc
ument& document, const QualifiedName& tagName) |
| 69 { | 56 { |
| 70 ASSERT(CustomElement::isValidName(tagName.localName())); | 57 ASSERT(CustomElement::isValidName(tagName.localName())); |
| 71 | 58 |
| 72 RefPtr<Element> element = HTMLElement::create(tagName, document); | 59 RefPtr<Element> element = HTMLElement::create(tagName, document); |
| 73 element->setCustomElementState(Element::WaitingForUpgrade); | 60 element->setCustomElementState(Element::WaitingForUpgrade); |
| 74 resolveOrScheduleResolution(element.get()); | 61 resolveOrScheduleResolution(element.get()); |
| 75 return element.release(); | 62 return element.release(); |
| 76 } | 63 } |
| 77 | 64 |
| 78 void CustomElementRegistrationContext::resolveOrScheduleResolution(Element* elem
ent) | 65 void CustomElementRegistrationContext::resolveOrScheduleResolution(Element* elem
ent) |
| 79 { | 66 { |
| 80 CustomElementDescriptor descriptor(element->localName()); | 67 CustomElementDescriptor descriptor(element->localName()); |
| 81 ASSERT(element->customElementState() == Element::WaitingForUpgrade); | 68 ASSERT(element->customElementState() == Element::WaitingForUpgrade); |
| 82 | 69 |
| 83 CustomElementScheduler::resolveOrScheduleResolution(this, element, descripto
r); | 70 CustomElementScheduler::resolveOrScheduleResolution(this, element, descripto
r); |
| 84 } | 71 } |
| 85 | 72 |
| 86 void CustomElementRegistrationContext::resolve(Element* element, const CustomEle
mentDescriptor& descriptor) | 73 void CustomElementRegistrationContext::resolve(Element* element, const CustomEle
mentDescriptor& descriptor) |
| 87 { | 74 { |
| 88 CustomElementDefinition* definition = m_registry.find(descriptor); | 75 if (CustomElementDefinition* definition = m_registry.find(descriptor)) |
| 89 if (definition) { | |
| 90 CustomElement::define(element, definition); | 76 CustomElement::define(element, definition); |
| 91 } else { | |
| 92 ASSERT(element->customElementState() == Element::WaitingForUpgrade); | |
| 93 m_candidates->add(descriptor, element); | |
| 94 } | |
| 95 } | 77 } |
| 96 | 78 |
| 97 } // namespace blink | 79 } // namespace blink |
| OLD | NEW |