| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) { | 75 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) { |
| 76 element = HTMLElement::create(tagName, document); | 76 element = HTMLElement::create(tagName, document); |
| 77 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) { | 77 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) { |
| 78 element = SVGUnknownElement::create(tagName, document); | 78 element = SVGUnknownElement::create(tagName, document); |
| 79 } else { | 79 } else { |
| 80 // XML elements are not custom elements, so return early. | 80 // XML elements are not custom elements, so return early. |
| 81 return Element::create(tagName, &document); | 81 return Element::create(tagName, &document); |
| 82 } | 82 } |
| 83 | 83 |
| 84 element->setCustomElementState(Element::WaitingForUpgrade); | 84 element->setV0CustomElementState(Element::V0WaitingForUpgrade); |
| 85 resolveOrScheduleResolution(element, nullAtom); | 85 resolveOrScheduleResolution(element, nullAtom); |
| 86 return element; | 86 return element; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void V0CustomElementRegistrationContext::didGiveTypeExtension(Element* element,
const AtomicString& type) | 89 void V0CustomElementRegistrationContext::didGiveTypeExtension(Element* element,
const AtomicString& type) |
| 90 { | 90 { |
| 91 resolveOrScheduleResolution(element, type); | 91 resolveOrScheduleResolution(element, type); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void V0CustomElementRegistrationContext::resolveOrScheduleResolution(Element* el
ement, const AtomicString& typeExtension) | 94 void V0CustomElementRegistrationContext::resolveOrScheduleResolution(Element* el
ement, const AtomicString& typeExtension) |
| 95 { | 95 { |
| 96 // If an element has a custom tag name it takes precedence over | 96 // If an element has a custom tag name it takes precedence over |
| 97 // the "is" attribute (if any). | 97 // the "is" attribute (if any). |
| 98 const AtomicString& type = V0CustomElement::isValidName(element->localName()
) | 98 const AtomicString& type = V0CustomElement::isValidName(element->localName()
) |
| 99 ? element->localName() | 99 ? element->localName() |
| 100 : typeExtension; | 100 : typeExtension; |
| 101 DCHECK(!type.isNull()); | 101 DCHECK(!type.isNull()); |
| 102 | 102 |
| 103 V0CustomElementDescriptor descriptor(type, element->namespaceURI(), element-
>localName()); | 103 V0CustomElementDescriptor descriptor(type, element->namespaceURI(), element-
>localName()); |
| 104 DCHECK_EQ(element->getCustomElementState(), Element::WaitingForUpgrade); | 104 DCHECK_EQ(element->getV0CustomElementState(), Element::V0WaitingForUpgrade); |
| 105 | 105 |
| 106 V0CustomElementScheduler::resolveOrScheduleResolution(this, element, descrip
tor); | 106 V0CustomElementScheduler::resolveOrScheduleResolution(this, element, descrip
tor); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void V0CustomElementRegistrationContext::resolve(Element* element, const V0Custo
mElementDescriptor& descriptor) | 109 void V0CustomElementRegistrationContext::resolve(Element* element, const V0Custo
mElementDescriptor& descriptor) |
| 110 { | 110 { |
| 111 V0CustomElementDefinition* definition = m_registry.find(descriptor); | 111 V0CustomElementDefinition* definition = m_registry.find(descriptor); |
| 112 if (definition) { | 112 if (definition) { |
| 113 V0CustomElement::define(element, definition); | 113 V0CustomElement::define(element, definition); |
| 114 } else { | 114 } else { |
| 115 DCHECK_EQ(element->getCustomElementState(), Element::WaitingForUpgrade); | 115 DCHECK_EQ(element->getV0CustomElementState(), Element::V0WaitingForUpgra
de); |
| 116 m_candidates->add(descriptor, element); | 116 m_candidates->add(descriptor, element); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 void V0CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element*
element, const AtomicString& type) | 120 void V0CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element*
element, const AtomicString& type) |
| 121 { | 121 { |
| 122 DCHECK(element); | 122 DCHECK(element); |
| 123 DCHECK(!type.isEmpty()); | 123 DCHECK(!type.isEmpty()); |
| 124 element->setAttribute(HTMLNames::isAttr, type); | 124 element->setAttribute(HTMLNames::isAttr, type); |
| 125 setTypeExtension(element, type); | 125 setTypeExtension(element, type); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void V0CustomElementRegistrationContext::setTypeExtension(Element* element, cons
t AtomicString& type) | 128 void V0CustomElementRegistrationContext::setTypeExtension(Element* element, cons
t AtomicString& type) |
| 129 { | 129 { |
| 130 if (!element->isHTMLElement() && !element->isSVGElement()) | 130 if (!element->isHTMLElement() && !element->isSVGElement()) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 V0CustomElementRegistrationContext* context = element->document().registrati
onContext(); | 133 V0CustomElementRegistrationContext* context = element->document().registrati
onContext(); |
| 134 if (!context) | 134 if (!context) |
| 135 return; | 135 return; |
| 136 | 136 |
| 137 if (element->isCustomElement()) { | 137 if (element->isV0CustomElement()) { |
| 138 // This can happen if: | 138 // This can happen if: |
| 139 // 1. The element has a custom tag, which takes precedence over | 139 // 1. The element has a custom tag, which takes precedence over |
| 140 // type extensions. | 140 // type extensions. |
| 141 // 2. Undoing a command (eg ReplaceNodeWithSpan) recycles an | 141 // 2. Undoing a command (eg ReplaceNodeWithSpan) recycles an |
| 142 // element but tries to overwrite its attribute list. | 142 // element but tries to overwrite its attribute list. |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Custom tags take precedence over type extensions | 146 // Custom tags take precedence over type extensions |
| 147 DCHECK(!V0CustomElement::isValidName(element->localName())); | 147 DCHECK(!V0CustomElement::isValidName(element->localName())); |
| 148 | 148 |
| 149 if (!V0CustomElement::isValidName(type)) | 149 if (!V0CustomElement::isValidName(type)) |
| 150 return; | 150 return; |
| 151 | 151 |
| 152 element->setCustomElementState(Element::WaitingForUpgrade); | 152 element->setV0CustomElementState(Element::V0WaitingForUpgrade); |
| 153 context->didGiveTypeExtension(element, element->document().convertLocalName(
type)); | 153 context->didGiveTypeExtension(element, element->document().convertLocalName(
type)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool V0CustomElementRegistrationContext::nameIsDefined(const AtomicString& name)
const | 156 bool V0CustomElementRegistrationContext::nameIsDefined(const AtomicString& name)
const |
| 157 { | 157 { |
| 158 return m_registry.nameIsDefined(name); | 158 return m_registry.nameIsDefined(name); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void V0CustomElementRegistrationContext::setV1(const CustomElementsRegistry* v1) | 161 void V0CustomElementRegistrationContext::setV1(const CustomElementsRegistry* v1) |
| 162 { | 162 { |
| 163 m_registry.setV1(v1); | 163 m_registry.setV1(v1); |
| 164 } | 164 } |
| 165 | 165 |
| 166 DEFINE_TRACE(V0CustomElementRegistrationContext) | 166 DEFINE_TRACE(V0CustomElementRegistrationContext) |
| 167 { | 167 { |
| 168 visitor->trace(m_candidates); | 168 visitor->trace(m_candidates); |
| 169 visitor->trace(m_registry); | 169 visitor->trace(m_registry); |
| 170 } | 170 } |
| 171 | 171 |
| 172 } // namespace blink | 172 } // namespace blink |
| OLD | NEW |