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

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

Issue 69533003: Upgrade parser-created Custom Elements in creation order. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Bring patch to head. Created 7 years, 1 month 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
« no previous file with comments | « Source/core/dom/custom/CustomElementRegistrationContext.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 if (!definition) 52 if (!definition)
53 return; 53 return;
54 54
55 // Upgrade elements that were waiting for this definition. 55 // Upgrade elements that were waiting for this definition.
56 const CustomElementUpgradeCandidateMap::ElementSet& upgradeCandidates = m_ca ndidates.takeUpgradeCandidatesFor(definition->descriptor()); 56 const CustomElementUpgradeCandidateMap::ElementSet& upgradeCandidates = m_ca ndidates.takeUpgradeCandidatesFor(definition->descriptor());
57 for (CustomElementUpgradeCandidateMap::ElementSet::const_iterator it = upgra deCandidates.begin(); it != upgradeCandidates.end(); ++it) 57 for (CustomElementUpgradeCandidateMap::ElementSet::const_iterator it = upgra deCandidates.begin(); it != upgradeCandidates.end(); ++it)
58 didResolveElement(definition, *it); 58 didResolveElement(definition, *it);
59 } 59 }
60 60
61 PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Doc ument& document, const QualifiedName& tagName, CreationMode mode) 61 PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Doc ument& document, const QualifiedName& tagName)
62 { 62 {
63 ASSERT(CustomElement::isValidName(tagName.localName())); 63 ASSERT(CustomElement::isValidName(tagName.localName()));
64 64
65 RefPtr<Element> element; 65 RefPtr<Element> element;
66 66
67 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) { 67 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) {
68 element = HTMLElement::create(tagName, document); 68 element = HTMLElement::create(tagName, document);
69 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) { 69 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) {
70 element = SVGUnknownElement::create(tagName, document); 70 element = SVGUnknownElement::create(tagName, document);
71 } else { 71 } else {
72 // XML elements are not custom elements, so return early. 72 // XML elements are not custom elements, so return early.
73 return Element::create(tagName, &document); 73 return Element::create(tagName, &document);
74 } 74 }
75 75
76 element->setCustomElementState(mode == CreatedByParser ? Element::WaitingFor Parser : Element::WaitingForUpgrade); 76 element->setCustomElementState(Element::WaitingForUpgrade);
77 resolve(element.get(), nullAtom); 77 resolve(element.get(), nullAtom);
78 return element.release(); 78 return element.release();
79 } 79 }
80 80
81 void CustomElementRegistrationContext::didGiveTypeExtension(Element* element, co nst AtomicString& type) 81 void CustomElementRegistrationContext::didGiveTypeExtension(Element* element, co nst AtomicString& type)
82 { 82 {
83 resolve(element, type); 83 resolve(element, type);
84 } 84 }
85 85
86 void CustomElementRegistrationContext::resolve(Element* element, const AtomicStr ing& typeExtension) 86 void CustomElementRegistrationContext::resolve(Element* element, const AtomicStr ing& typeExtension)
(...skipping 13 matching lines...) Expand all
100 didCreateUnresolvedElement(descriptor, element); 100 didCreateUnresolvedElement(descriptor, element);
101 } 101 }
102 102
103 void CustomElementRegistrationContext::didResolveElement(CustomElementDefinition * definition, Element* element) 103 void CustomElementRegistrationContext::didResolveElement(CustomElementDefinition * definition, Element* element)
104 { 104 {
105 CustomElement::define(element, definition); 105 CustomElement::define(element, definition);
106 } 106 }
107 107
108 void CustomElementRegistrationContext::didCreateUnresolvedElement(const CustomEl ementDescriptor& descriptor, Element* element) 108 void CustomElementRegistrationContext::didCreateUnresolvedElement(const CustomEl ementDescriptor& descriptor, Element* element)
109 { 109 {
110 ASSERT(element->customElementState() == Element::WaitingForParser || element ->customElementState() == Element::WaitingForUpgrade); 110 ASSERT(element->customElementState() == Element::WaitingForUpgrade);
111 m_candidates.add(descriptor, element); 111 m_candidates.add(descriptor, element);
112 } 112 }
113 113
114 PassRefPtr<CustomElementRegistrationContext> CustomElementRegistrationContext::c reate() 114 PassRefPtr<CustomElementRegistrationContext> CustomElementRegistrationContext::c reate()
115 { 115 {
116 return adoptRef(new CustomElementRegistrationContext()); 116 return adoptRef(new CustomElementRegistrationContext());
117 } 117 }
118 118
119 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* e lement, const AtomicString& type) 119 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* e lement, const AtomicString& type)
120 { 120 {
121 ASSERT(element); 121 ASSERT(element);
122 ASSERT(!type.isEmpty()); 122 ASSERT(!type.isEmpty());
123 element->setAttribute(HTMLNames::isAttr, type); 123 element->setAttribute(HTMLNames::isAttr, type);
124 setTypeExtension(element, type); 124 setTypeExtension(element, type);
125 } 125 }
126 126
127 void CustomElementRegistrationContext::setTypeExtension(Element* element, const AtomicString& type, CreationMode mode) 127 void CustomElementRegistrationContext::setTypeExtension(Element* element, const AtomicString& type)
128 { 128 {
129 if (!element->isHTMLElement() && !element->isSVGElement()) 129 if (!element->isHTMLElement() && !element->isSVGElement())
130 return; 130 return;
131 131
132 if (element->isCustomElement()) { 132 if (element->isCustomElement()) {
133 // This can happen if: 133 // This can happen if:
134 // 1. The element has a custom tag, which takes precedence over 134 // 1. The element has a custom tag, which takes precedence over
135 // type extensions. 135 // type extensions.
136 // 2. Undoing a command (eg ReplaceNodeWithSpan) recycles an 136 // 2. Undoing a command (eg ReplaceNodeWithSpan) recycles an
137 // element but tries to overwrite its attribute list. 137 // element but tries to overwrite its attribute list.
138 return; 138 return;
139 } 139 }
140 140
141 // Custom tags take precedence over type extensions 141 // Custom tags take precedence over type extensions
142 ASSERT(!CustomElement::isValidName(element->localName())); 142 ASSERT(!CustomElement::isValidName(element->localName()));
143 143
144 element->setCustomElementState(mode == CreatedByParser ? Element::WaitingFor Parser : Element::WaitingForUpgrade); 144 element->setCustomElementState(Element::WaitingForUpgrade);
145 145
146 if (CustomElementRegistrationContext* context = element->document().registra tionContext()) 146 if (CustomElementRegistrationContext* context = element->document().registra tionContext())
147 context->didGiveTypeExtension(element, type); 147 context->didGiveTypeExtension(element, type);
148 } 148 }
149 149
150 } // namespace WebCore 150 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/custom/CustomElementRegistrationContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698