| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 for (CustomElementUpgradeCandidateMap::ElementSet::const_iterator it = upgra
deCandidates->begin(); it != upgradeCandidates->end(); ++it) | 64 for (CustomElementUpgradeCandidateMap::ElementSet::const_iterator it = upgra
deCandidates->begin(); it != upgradeCandidates->end(); ++it) |
| 65 CustomElement::define(*it, definition); | 65 CustomElement::define(*it, definition); |
| 66 } | 66 } |
| 67 | 67 |
| 68 PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Doc
ument& document, const QualifiedName& tagName) | 68 PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Doc
ument& document, const QualifiedName& tagName) |
| 69 { | 69 { |
| 70 ASSERT(CustomElement::isValidName(tagName.localName())); | 70 ASSERT(CustomElement::isValidName(tagName.localName())); |
| 71 | 71 |
| 72 RefPtr<Element> element = HTMLElement::create(tagName, document); | 72 RefPtr<Element> element = HTMLElement::create(tagName, document); |
| 73 element->setCustomElementState(Element::WaitingForUpgrade); | 73 element->setCustomElementState(Element::WaitingForUpgrade); |
| 74 resolveOrScheduleResolution(element.get(), nullAtom); | 74 resolveOrScheduleResolution(element.get()); |
| 75 return element.release(); | 75 return element.release(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void CustomElementRegistrationContext::didGiveTypeExtension(Element* element, co
nst AtomicString& type) | 78 void CustomElementRegistrationContext::resolveOrScheduleResolution(Element* elem
ent) |
| 79 { | 79 { |
| 80 resolveOrScheduleResolution(element, type); | 80 CustomElementDescriptor descriptor(element->localName()); |
| 81 } | |
| 82 | |
| 83 void CustomElementRegistrationContext::resolveOrScheduleResolution(Element* elem
ent, const AtomicString& typeExtension) | |
| 84 { | |
| 85 // If an element has a custom tag name it takes precedence over | |
| 86 // the "is" attribute (if any). | |
| 87 const AtomicString& type = CustomElement::isValidName(element->localName()) | |
| 88 ? element->localName() | |
| 89 : typeExtension; | |
| 90 ASSERT(!type.isNull()); | |
| 91 | |
| 92 CustomElementDescriptor descriptor(type, element->localName()); | |
| 93 ASSERT(element->customElementState() == Element::WaitingForUpgrade); | 81 ASSERT(element->customElementState() == Element::WaitingForUpgrade); |
| 94 | 82 |
| 95 CustomElementScheduler::resolveOrScheduleResolution(this, element, descripto
r); | 83 CustomElementScheduler::resolveOrScheduleResolution(this, element, descripto
r); |
| 96 } | 84 } |
| 97 | 85 |
| 98 void CustomElementRegistrationContext::resolve(Element* element, const CustomEle
mentDescriptor& descriptor) | 86 void CustomElementRegistrationContext::resolve(Element* element, const CustomEle
mentDescriptor& descriptor) |
| 99 { | 87 { |
| 100 CustomElementDefinition* definition = m_registry.find(descriptor); | 88 CustomElementDefinition* definition = m_registry.find(descriptor); |
| 101 if (definition) { | 89 if (definition) { |
| 102 CustomElement::define(element, definition); | 90 CustomElement::define(element, definition); |
| 103 } else { | 91 } else { |
| 104 ASSERT(element->customElementState() == Element::WaitingForUpgrade); | 92 ASSERT(element->customElementState() == Element::WaitingForUpgrade); |
| 105 m_candidates->add(descriptor, element); | 93 m_candidates->add(descriptor, element); |
| 106 } | 94 } |
| 107 } | 95 } |
| 108 | 96 |
| 109 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* e
lement, const AtomicString& type) | |
| 110 { | |
| 111 ASSERT(element); | |
| 112 ASSERT(!type.isEmpty()); | |
| 113 element->setAttribute(HTMLNames::isAttr, type); | |
| 114 setTypeExtension(element, type); | |
| 115 } | |
| 116 | |
| 117 void CustomElementRegistrationContext::setTypeExtension(Element* element, const
AtomicString& type) | |
| 118 { | |
| 119 if (!element->isHTMLElement()) | |
| 120 return; | |
| 121 | |
| 122 CustomElementRegistrationContext* context = element->document().registration
Context(); | |
| 123 if (!context) | |
| 124 return; | |
| 125 | |
| 126 if (element->isCustomElement()) { | |
| 127 // This can happen if: | |
| 128 // 1. The element has a custom tag, which takes precedence over | |
| 129 // type extensions. | |
| 130 // 2. Undoing a command (eg ReplaceNodeWithSpan) recycles an | |
| 131 // element but tries to overwrite its attribute list. | |
| 132 return; | |
| 133 } | |
| 134 | |
| 135 // Custom tags take precedence over type extensions | |
| 136 ASSERT(!CustomElement::isValidName(element->localName())); | |
| 137 | |
| 138 if (!CustomElement::isValidName(type)) | |
| 139 return; | |
| 140 | |
| 141 element->setCustomElementState(Element::WaitingForUpgrade); | |
| 142 // FIXME(sky) this used to call Document::convertLocalName(type) which | |
| 143 // would lowercase if Document was HTML, that made no sense. | |
| 144 context->didGiveTypeExtension(element, type); | |
| 145 } | |
| 146 | |
| 147 } // namespace blink | 97 } // namespace blink |
| OLD | NEW |