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

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

Issue 23009004: Process Custom Elements in post-order. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 months 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
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 if (!definition) 51 if (!definition)
52 return; 52 return;
53 53
54 // Upgrade elements that were waiting for this definition. 54 // Upgrade elements that were waiting for this definition.
55 const CustomElementUpgradeCandidateMap::ElementSet& upgradeCandidates = m_ca ndidates.takeUpgradeCandidatesFor(definition->descriptor()); 55 const CustomElementUpgradeCandidateMap::ElementSet& upgradeCandidates = m_ca ndidates.takeUpgradeCandidatesFor(definition->descriptor());
56 for (CustomElementUpgradeCandidateMap::ElementSet::const_iterator it = upgra deCandidates.begin(); it != upgradeCandidates.end(); ++it) 56 for (CustomElementUpgradeCandidateMap::ElementSet::const_iterator it = upgra deCandidates.begin(); it != upgradeCandidates.end(); ++it)
57 didResolveElement(definition, *it); 57 didResolveElement(definition, *it);
58 } 58 }
59 59
60 PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Doc ument* document, const QualifiedName& tagName) 60 PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Doc ument* document, const QualifiedName& tagName, CreationMode mode)
61 { 61 {
62 ASSERT(CustomElement::isCustomTagName(tagName.localName())); 62 ASSERT(CustomElement::isCustomTagName(tagName.localName()));
63 63
64 if (!document) 64 if (!document)
65 return 0; 65 return 0;
66 66
67 RefPtr<Element> element; 67 RefPtr<Element> element;
68 68
69 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) { 69 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) {
70 element = HTMLElement::create(tagName, document); 70 element = HTMLElement::create(tagName, document);
71 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) { 71 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) {
72 element = SVGUnknownElement::create(tagName, document); 72 element = SVGUnknownElement::create(tagName, document);
73 } else { 73 } else {
74 // XML elements are not custom elements, so return early. 74 // XML elements are not custom elements, so return early.
75 return Element::create(tagName, document); 75 return Element::create(tagName, document);
76 } 76 }
77 77
78 if (mode == CreatedByParser)
79 CustomElement::setBeingParsed(element.get());
78 resolve(element.get(), nullAtom); 80 resolve(element.get(), nullAtom);
79 return element.release(); 81 return element.release();
80 } 82 }
81 83
82 void CustomElementRegistrationContext::didGiveTypeExtension(Element* element, co nst AtomicString& type) 84 void CustomElementRegistrationContext::didGiveTypeExtension(Element* element, co nst AtomicString& type)
83 { 85 {
84 resolve(element, type); 86 resolve(element, type);
85 } 87 }
86 88
87 void CustomElementRegistrationContext::resolve(Element* element, const AtomicStr ing& typeExtension) 89 void CustomElementRegistrationContext::resolve(Element* element, const AtomicStr ing& typeExtension)
(...skipping 16 matching lines...) Expand all
104 void CustomElementRegistrationContext::didResolveElement(CustomElementDefinition * definition, Element* element) 106 void CustomElementRegistrationContext::didResolveElement(CustomElementDefinition * definition, Element* element)
105 { 107 {
106 CustomElement::define(element, definition); 108 CustomElement::define(element, definition);
107 } 109 }
108 110
109 void CustomElementRegistrationContext::didCreateUnresolvedElement(const CustomEl ementDescriptor& descriptor, Element* element) 111 void CustomElementRegistrationContext::didCreateUnresolvedElement(const CustomEl ementDescriptor& descriptor, Element* element)
110 { 112 {
111 m_candidates.add(descriptor, element); 113 m_candidates.add(descriptor, element);
112 } 114 }
113 115
114 void CustomElementRegistrationContext::customElementWasDestroyed(Element* elemen t)
115 {
116 m_candidates.remove(element);
117 }
118
119 PassRefPtr<CustomElementRegistrationContext> CustomElementRegistrationContext::c reate() 116 PassRefPtr<CustomElementRegistrationContext> CustomElementRegistrationContext::c reate()
120 { 117 {
121 return adoptRef(new CustomElementRegistrationContext()); 118 return adoptRef(new CustomElementRegistrationContext());
122 } 119 }
123 120
124 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* e lement, const AtomicString& type) 121 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* e lement, const AtomicString& type)
125 { 122 {
126 ASSERT(element); 123 ASSERT(element);
127 ASSERT(!type.isEmpty()); 124 ASSERT(!type.isEmpty());
128 element->setAttribute(HTMLNames::isAttr, type); 125 element->setAttribute(HTMLNames::isAttr, type);
129 setTypeExtension(element, type); 126 setTypeExtension(element, type, CreatedByDOM);
130 } 127 }
131 128
132 void CustomElementRegistrationContext::setTypeExtension(Element* element, const AtomicString& type) 129 void CustomElementRegistrationContext::setTypeExtension(Element* element, const AtomicString& type, CreationMode mode)
133 { 130 {
134 if (!element->isHTMLElement() && !element->isSVGElement()) 131 if (!element->isHTMLElement() && !element->isSVGElement())
135 return; 132 return;
136 133
137 if (element->isCustomElement()) { 134 if (element->isCustomElement()) {
138 // This can happen if: 135 // This can happen if:
139 // 1. The element has a custom tag, which takes precedence over 136 // 1. The element has a custom tag, which takes precedence over
140 // type extensions. 137 // type extensions.
141 // 2. Undoing a command (eg ReplaceNodeWithSpan) recycles an 138 // 2. Undoing a command (eg ReplaceNodeWithSpan) recycles an
142 // element but tries to overwrite its attribute list. 139 // element but tries to overwrite its attribute list.
143 return; 140 return;
144 } 141 }
145 142
146 // Custom tags take precedence over type extensions 143 // Custom tags take precedence over type extensions
147 ASSERT(!CustomElement::isCustomTagName(element->localName())); 144 ASSERT(!CustomElement::isCustomTagName(element->localName()));
148 145
149 if (CustomElementRegistrationContext* context = element->document()->registr ationContext()) 146 if (CustomElementRegistrationContext* context = element->document()->registr ationContext()) {
147 if (CreatedByParser == mode)
dglazkov 2013/08/13 16:22:06 why'd you flip the condition like that? :)
148 CustomElement::setBeingParsed(element);
149
150 context->didGiveTypeExtension(element, type); 150 context->didGiveTypeExtension(element, type);
151 }
151 } 152 }
152 153
153 } // namespace WebCore 154 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698