Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 3 * Copyright (C) 2011 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 || item->hasTagName(pTag) | 76 || item->hasTagName(pTag) |
| 77 || item->hasTagName(rpTag) | 77 || item->hasTagName(rpTag) |
| 78 || item->hasTagName(rtTag); | 78 || item->hasTagName(rtTag); |
| 79 } | 79 } |
| 80 | 80 |
| 81 static inline bool isAllWhitespace(const String& string) | 81 static inline bool isAllWhitespace(const String& string) |
| 82 { | 82 { |
| 83 return string.isAllSpecialCharacters<isHTMLSpace>(); | 83 return string.isAllSpecialCharacters<isHTMLSpace>(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 static inline void executeInsertTask(HTMLConstructionSiteTask& task) | 86 static inline void insert(HTMLConstructionSiteTask& task) |
| 87 { | 87 { |
| 88 ASSERT(task.operation == HTMLConstructionSiteTask::Insert); | |
| 89 | |
| 90 if (task.parent->hasTagName(templateTag)) | 88 if (task.parent->hasTagName(templateTag)) |
| 91 task.parent = toHTMLTemplateElement(task.parent.get())->content(); | 89 task.parent = toHTMLTemplateElement(task.parent.get())->content(); |
| 92 | 90 |
| 91 if (ContainerNode* parent = task.child->parentNode()) | |
| 92 parent->parserRemoveChild(task.child.get()); | |
| 93 | |
| 93 if (task.nextChild) | 94 if (task.nextChild) |
| 94 task.parent->parserInsertBefore(task.child.get(), task.nextChild.get()); | 95 task.parent->parserInsertBefore(task.child.get(), task.nextChild.get()); |
| 95 else | 96 else |
| 96 task.parent->parserAppendChild(task.child.get()); | 97 task.parent->parserAppendChild(task.child.get()); |
| 97 | 98 |
| 98 // JavaScript run from beforeload (or DOM Mutation or event handlers) | 99 // JavaScript run from beforeload (or DOM Mutation or event handlers) |
| 99 // might have removed the child, in which case we should not attach it. | 100 // might have removed the child, in which case we should not attach it. |
| 100 | 101 |
| 101 if (task.child->parentNode() && task.parent->attached() && !task.child->atta ched()) | 102 if (task.child->parentNode() && task.parent->attached() && !task.child->atta ched()) |
| 102 task.child->attach(); | 103 task.child->attach(); |
| 104 } | |
| 105 | |
| 106 static inline void executeInsertTask(HTMLConstructionSiteTask& task) | |
| 107 { | |
| 108 ASSERT(task.operation == HTMLConstructionSiteTask::Insert); | |
| 109 | |
| 110 insert(task); | |
| 103 | 111 |
| 104 task.child->beginParsingChildren(); | 112 task.child->beginParsingChildren(); |
| 105 | 113 |
| 106 if (task.selfClosing) | 114 if (task.selfClosing) |
| 107 task.child->finishParsingChildren(); | 115 task.child->finishParsingChildren(); |
| 108 } | 116 } |
| 109 | 117 |
| 110 static inline void executeReparentTask(HTMLConstructionSiteTask& task) | 118 static inline void executeReparentTask(HTMLConstructionSiteTask& task) |
| 111 { | 119 { |
| 112 ASSERT(task.operation == HTMLConstructionSiteTask::Reparent); | 120 ASSERT(task.operation == HTMLConstructionSiteTask::Reparent); |
| 113 | 121 |
| 114 if (ContainerNode* parent = task.child->parentNode()) | 122 if (ContainerNode* parent = task.child->parentNode()) |
| 115 parent->parserRemoveChild(task.child.get()); | 123 parent->parserRemoveChild(task.child.get()); |
| 116 | 124 |
| 117 task.parent->parserAppendChild(task.child); | 125 task.parent->parserAppendChild(task.child); |
| 118 | 126 |
| 119 if (task.child->parentElement()->attached() && !task.child->attached()) | 127 if (task.child->parentElement()->attached() && !task.child->attached()) |
| 120 task.child->lazyAttach(); | 128 task.child->lazyAttach(); |
| 121 } | 129 } |
| 122 | 130 |
| 131 static inline void executeInsertAgainTask(HTMLConstructionSiteTask& task) | |
| 132 { | |
| 133 ASSERT(task.operation == HTMLConstructionSiteTask::InsertAgain); | |
| 134 | |
| 135 insert(task); | |
| 136 } | |
| 137 | |
| 138 static inline void executeTakeAllChildrenTask(HTMLConstructionSiteTask& task) | |
| 139 { | |
| 140 ASSERT(task.operation == HTMLConstructionSiteTask::TakeAllChildren); | |
| 141 | |
| 142 // It's sort of ugly, but we store the |oldParent| in the |child| field | |
| 143 // of the task so that we don't bloat the HTMLConstructionSiteTask | |
| 144 // object in the common case of the Insert operation. | |
| 145 ContainerNode* oldParent = static_cast<ContainerNode*>(task.child.get()); | |
|
eseidel
2013/05/07 00:11:37
The only thing I would change here is making this
| |
| 146 | |
| 147 task.parent->takeAllChildrenFrom(oldParent); | |
| 148 // Notice that we don't need to manually attack the moved children | |
|
eseidel
2013/05/07 00:11:37
attack!
| |
| 149 // because takeAllChildrenFrom does that work for us. | |
| 150 } | |
| 151 | |
| 123 static inline void executeTask(HTMLConstructionSiteTask& task) | 152 static inline void executeTask(HTMLConstructionSiteTask& task) |
| 124 { | 153 { |
| 125 if (task.operation == HTMLConstructionSiteTask::Insert) | 154 if (task.operation == HTMLConstructionSiteTask::Insert) |
| 126 return executeInsertTask(task); | 155 return executeInsertTask(task); |
| 127 | 156 |
| 157 if (task.operation == HTMLConstructionSiteTask::InsertAgain) | |
|
eseidel
2013/05/07 00:11:37
I would put a comment that these below this commen
| |
| 158 return executeInsertAgainTask(task); | |
| 159 | |
| 128 if (task.operation == HTMLConstructionSiteTask::Reparent) | 160 if (task.operation == HTMLConstructionSiteTask::Reparent) |
| 129 return executeReparentTask(task); | 161 return executeReparentTask(task); |
| 130 | 162 |
| 163 if (task.operation == HTMLConstructionSiteTask::TakeAllChildren) | |
| 164 return executeTakeAllChildrenTask(task); | |
| 165 | |
| 131 ASSERT_NOT_REACHED(); | 166 ASSERT_NOT_REACHED(); |
| 132 } | 167 } |
| 133 | 168 |
| 134 void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtr<Node> p rpChild, bool selfClosing) | 169 void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtr<Node> p rpChild, bool selfClosing) |
| 135 { | 170 { |
| 136 ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()-> isElementNode() || !toScriptElementIfPossible(toElement(prpChild.get()))); | 171 ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()-> isElementNode() || !toScriptElementIfPossible(toElement(prpChild.get()))); |
| 137 ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !prpChild->isPluginE lement()); | 172 ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !prpChild->isPluginE lement()); |
| 138 | 173 |
| 139 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); | 174 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); |
| 140 task.parent = parent; | 175 task.parent = parent; |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 } | 577 } |
| 543 | 578 |
| 544 void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord* newParent, HTMLElementStack::ElementRecord* child) | 579 void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord* newParent, HTMLElementStack::ElementRecord* child) |
| 545 { | 580 { |
| 546 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent); | 581 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent); |
| 547 task.parent = newParent->element(); | 582 task.parent = newParent->element(); |
| 548 task.child = child->element(); | 583 task.child = child->element(); |
| 549 m_taskQueue.append(task); | 584 m_taskQueue.append(task); |
| 550 } | 585 } |
| 551 | 586 |
| 587 void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord* newParent, HTMLStackItem* child) | |
| 588 { | |
| 589 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent); | |
| 590 task.parent = newParent->element(); | |
| 591 task.child = child->element(); | |
| 592 m_taskQueue.append(task); | |
| 593 } | |
| 594 | |
| 595 void HTMLConstructionSite::insertAgain(HTMLStackItem* newParent, HTMLElementStac k::ElementRecord* child) | |
|
eseidel
2013/05/07 00:11:37
Need a name so that folks have a prayer of knowing
| |
| 596 { | |
| 597 if (newParent->causesFosterParenting()) { | |
| 598 fosterParent(child->element()); | |
| 599 return; | |
| 600 } | |
| 601 | |
| 602 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::InsertAgain); | |
| 603 task.parent = newParent->element(); | |
| 604 task.child = child->element(); | |
| 605 m_taskQueue.append(task); | |
| 606 } | |
| 607 | |
| 608 void HTMLConstructionSite::takeAllChildren(HTMLStackItem* newParent, HTMLElement Stack::ElementRecord* oldParent) | |
| 609 { | |
| 610 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::TakeAllChildren); | |
| 611 task.parent = newParent->element(); | |
| 612 task.child = oldParent->element(); | |
| 613 m_taskQueue.append(task); | |
| 614 } | |
| 615 | |
| 552 PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString& namespaceURI) | 616 PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString& namespaceURI) |
| 553 { | 617 { |
| 554 QualifiedName tagName(nullAtom, token->name(), namespaceURI); | 618 QualifiedName tagName(nullAtom, token->name(), namespaceURI); |
| 555 RefPtr<Element> element = ownerDocumentForCurrentNode()->createElement(tagNa me, true); | 619 RefPtr<Element> element = ownerDocumentForCurrentNode()->createElement(tagNa me, true); |
| 556 setAttributes(element.get(), token, m_parserContentPolicy); | 620 setAttributes(element.get(), token, m_parserContentPolicy); |
| 557 return element.release(); | 621 return element.release(); |
| 558 } | 622 } |
| 559 | 623 |
| 560 inline Document* HTMLConstructionSite::ownerDocumentForCurrentNode() | 624 inline Document* HTMLConstructionSite::ownerDocumentForCurrentNode() |
| 561 { | 625 { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 { | 746 { |
| 683 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); | 747 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); |
| 684 findFosterSite(task); | 748 findFosterSite(task); |
| 685 task.child = node; | 749 task.child = node; |
| 686 ASSERT(task.parent); | 750 ASSERT(task.parent); |
| 687 | 751 |
| 688 m_taskQueue.append(task); | 752 m_taskQueue.append(task); |
| 689 } | 753 } |
| 690 | 754 |
| 691 } | 755 } |
| OLD | NEW |