| 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, 2014 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011, 2014 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 HTMLTreeBuilder::FragmentParsingContext::~FragmentParsingContext() | 352 HTMLTreeBuilder::FragmentParsingContext::~FragmentParsingContext() |
| 353 { | 353 { |
| 354 } | 354 } |
| 355 | 355 |
| 356 DEFINE_TRACE(HTMLTreeBuilder::FragmentParsingContext) | 356 DEFINE_TRACE(HTMLTreeBuilder::FragmentParsingContext) |
| 357 { | 357 { |
| 358 visitor->trace(m_fragment); | 358 visitor->trace(m_fragment); |
| 359 visitor->trace(m_contextElementStackItem); | 359 visitor->trace(m_contextElementStackItem); |
| 360 } | 360 } |
| 361 | 361 |
| 362 PassRefPtrWillBeRawPtr<Element> HTMLTreeBuilder::takeScriptToProcess(TextPositio
n& scriptStartPosition) | 362 RawPtr<Element> HTMLTreeBuilder::takeScriptToProcess(TextPosition& scriptStartPo
sition) |
| 363 { | 363 { |
| 364 ASSERT(m_scriptToProcess); | 364 ASSERT(m_scriptToProcess); |
| 365 ASSERT(!m_tree.hasPendingTasks()); | 365 ASSERT(!m_tree.hasPendingTasks()); |
| 366 // Unpause ourselves, callers may pause us again when processing the script. | 366 // Unpause ourselves, callers may pause us again when processing the script. |
| 367 // The HTML5 spec is written as though scripts are executed inside the tree | 367 // The HTML5 spec is written as though scripts are executed inside the tree |
| 368 // builder. We pause the parser to exit the tree builder, and then resume | 368 // builder. We pause the parser to exit the tree builder, and then resume |
| 369 // before running scripts. | 369 // before running scripts. |
| 370 scriptStartPosition = m_scriptToProcessStartPosition; | 370 scriptStartPosition = m_scriptToProcessStartPosition; |
| 371 m_scriptToProcessStartPosition = uninitializedPositionValue1(); | 371 m_scriptToProcessStartPosition = uninitializedPositionValue1(); |
| 372 return m_scriptToProcess.release(); | 372 return m_scriptToProcess.release(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 } | 488 } |
| 489 | 489 |
| 490 } // namespace | 490 } // namespace |
| 491 | 491 |
| 492 template <bool shouldClose(const HTMLStackItem*)> | 492 template <bool shouldClose(const HTMLStackItem*)> |
| 493 void HTMLTreeBuilder::processCloseWhenNestedTag(AtomicHTMLToken* token) | 493 void HTMLTreeBuilder::processCloseWhenNestedTag(AtomicHTMLToken* token) |
| 494 { | 494 { |
| 495 m_framesetOk = false; | 495 m_framesetOk = false; |
| 496 HTMLElementStack::ElementRecord* nodeRecord = m_tree.openElements()->topReco
rd(); | 496 HTMLElementStack::ElementRecord* nodeRecord = m_tree.openElements()->topReco
rd(); |
| 497 while (1) { | 497 while (1) { |
| 498 RefPtrWillBeRawPtr<HTMLStackItem> item = nodeRecord->stackItem(); | 498 RawPtr<HTMLStackItem> item = nodeRecord->stackItem(); |
| 499 if (shouldClose(item.get())) { | 499 if (shouldClose(item.get())) { |
| 500 ASSERT(item->isElementNode()); | 500 ASSERT(item->isElementNode()); |
| 501 processFakeEndTag(item->localName()); | 501 processFakeEndTag(item->localName()); |
| 502 break; | 502 break; |
| 503 } | 503 } |
| 504 if (item->isSpecialNode() && !item->hasTagName(addressTag) && !item->has
TagName(divTag) && !item->hasTagName(pTag)) | 504 if (item->isSpecialNode() && !item->hasTagName(addressTag) && !item->has
TagName(divTag) && !item->hasTagName(pTag)) |
| 505 break; | 505 break; |
| 506 nodeRecord = nodeRecord->next(); | 506 nodeRecord = nodeRecord->next(); |
| 507 } | 507 } |
| 508 processFakePEndTagIfPInButtonScope(); | 508 processFakePEndTagIfPInButtonScope(); |
| (...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 return true; | 1468 return true; |
| 1469 } | 1469 } |
| 1470 | 1470 |
| 1471 void HTMLTreeBuilder::processAnyOtherEndTagForInBody(AtomicHTMLToken* token) | 1471 void HTMLTreeBuilder::processAnyOtherEndTagForInBody(AtomicHTMLToken* token) |
| 1472 { | 1472 { |
| 1473 ASSERT(token->type() == HTMLToken::EndTag); | 1473 ASSERT(token->type() == HTMLToken::EndTag); |
| 1474 if (token->name() == menuitemTag) | 1474 if (token->name() == menuitemTag) |
| 1475 UseCounter::count(m_tree.currentNode()->document(), UseCounter::MenuItem
CloseTag); | 1475 UseCounter::count(m_tree.currentNode()->document(), UseCounter::MenuItem
CloseTag); |
| 1476 HTMLElementStack::ElementRecord* record = m_tree.openElements()->topRecord()
; | 1476 HTMLElementStack::ElementRecord* record = m_tree.openElements()->topRecord()
; |
| 1477 while (1) { | 1477 while (1) { |
| 1478 RefPtrWillBeRawPtr<HTMLStackItem> item = record->stackItem(); | 1478 RawPtr<HTMLStackItem> item = record->stackItem(); |
| 1479 if (item->matchesHTMLTag(token->name())) { | 1479 if (item->matchesHTMLTag(token->name())) { |
| 1480 m_tree.generateImpliedEndTagsWithExclusion(token->name()); | 1480 m_tree.generateImpliedEndTagsWithExclusion(token->name()); |
| 1481 if (!m_tree.currentStackItem()->matchesHTMLTag(token->name())) | 1481 if (!m_tree.currentStackItem()->matchesHTMLTag(token->name())) |
| 1482 parseError(token); | 1482 parseError(token); |
| 1483 m_tree.openElements()->popUntilPopped(item->element()); | 1483 m_tree.openElements()->popUntilPopped(item->element()); |
| 1484 return; | 1484 return; |
| 1485 } | 1485 } |
| 1486 if (item->isSpecialNode()) { | 1486 if (item->isSpecialNode()) { |
| 1487 parseError(token); | 1487 parseError(token); |
| 1488 return; | 1488 return; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 // 5. | 1527 // 5. |
| 1528 HTMLElementStack::ElementRecord* furthestBlock = m_tree.openElements()->
furthestBlockForFormattingElement(formattingElement); | 1528 HTMLElementStack::ElementRecord* furthestBlock = m_tree.openElements()->
furthestBlockForFormattingElement(formattingElement); |
| 1529 // 6. | 1529 // 6. |
| 1530 if (!furthestBlock) { | 1530 if (!furthestBlock) { |
| 1531 m_tree.openElements()->popUntilPopped(formattingElement); | 1531 m_tree.openElements()->popUntilPopped(formattingElement); |
| 1532 m_tree.activeFormattingElements()->remove(formattingElement); | 1532 m_tree.activeFormattingElements()->remove(formattingElement); |
| 1533 return; | 1533 return; |
| 1534 } | 1534 } |
| 1535 // 7. | 1535 // 7. |
| 1536 ASSERT(furthestBlock->isAbove(formattingElementRecord)); | 1536 ASSERT(furthestBlock->isAbove(formattingElementRecord)); |
| 1537 RefPtrWillBeRawPtr<HTMLStackItem> commonAncestor = formattingElementReco
rd->next()->stackItem(); | 1537 RawPtr<HTMLStackItem> commonAncestor = formattingElementRecord->next()->
stackItem(); |
| 1538 // 8. | 1538 // 8. |
| 1539 HTMLFormattingElementList::Bookmark bookmark = m_tree.activeFormattingEl
ements()->bookmarkFor(formattingElement); | 1539 HTMLFormattingElementList::Bookmark bookmark = m_tree.activeFormattingEl
ements()->bookmarkFor(formattingElement); |
| 1540 // 9. | 1540 // 9. |
| 1541 HTMLElementStack::ElementRecord* node = furthestBlock; | 1541 HTMLElementStack::ElementRecord* node = furthestBlock; |
| 1542 HTMLElementStack::ElementRecord* nextNode = node->next(); | 1542 HTMLElementStack::ElementRecord* nextNode = node->next(); |
| 1543 HTMLElementStack::ElementRecord* lastNode = furthestBlock; | 1543 HTMLElementStack::ElementRecord* lastNode = furthestBlock; |
| 1544 // 9.1, 9.2, 9.3 and 9.11 are covered by the for() loop. | 1544 // 9.1, 9.2, 9.3 and 9.11 are covered by the for() loop. |
| 1545 for (int i = 0; i < innerIterationLimit; ++i) { | 1545 for (int i = 0; i < innerIterationLimit; ++i) { |
| 1546 // 9.4 | 1546 // 9.4 |
| 1547 node = nextNode; | 1547 node = nextNode; |
| 1548 ASSERT(node); | 1548 ASSERT(node); |
| 1549 nextNode = node->next(); // Save node->next() for the next iteration
in case node is deleted in 9.5. | 1549 nextNode = node->next(); // Save node->next() for the next iteration
in case node is deleted in 9.5. |
| 1550 // 9.5 | 1550 // 9.5 |
| 1551 if (!m_tree.activeFormattingElements()->contains(node->element())) { | 1551 if (!m_tree.activeFormattingElements()->contains(node->element())) { |
| 1552 m_tree.openElements()->remove(node->element()); | 1552 m_tree.openElements()->remove(node->element()); |
| 1553 node = 0; | 1553 node = 0; |
| 1554 continue; | 1554 continue; |
| 1555 } | 1555 } |
| 1556 // 9.6 | 1556 // 9.6 |
| 1557 if (node == formattingElementRecord) | 1557 if (node == formattingElementRecord) |
| 1558 break; | 1558 break; |
| 1559 // 9.7 | 1559 // 9.7 |
| 1560 RefPtrWillBeRawPtr<HTMLStackItem> newItem = m_tree.createElementFrom
SavedToken(node->stackItem().get()); | 1560 RawPtr<HTMLStackItem> newItem = m_tree.createElementFromSavedToken(n
ode->stackItem().get()); |
| 1561 | 1561 |
| 1562 HTMLFormattingElementList::Entry* nodeEntry = m_tree.activeFormattin
gElements()->find(node->element()); | 1562 HTMLFormattingElementList::Entry* nodeEntry = m_tree.activeFormattin
gElements()->find(node->element()); |
| 1563 nodeEntry->replaceElement(newItem); | 1563 nodeEntry->replaceElement(newItem); |
| 1564 node->replaceElement(newItem.release()); | 1564 node->replaceElement(newItem.release()); |
| 1565 | 1565 |
| 1566 // 9.8 | 1566 // 9.8 |
| 1567 if (lastNode == furthestBlock) | 1567 if (lastNode == furthestBlock) |
| 1568 bookmark.moveToAfter(nodeEntry); | 1568 bookmark.moveToAfter(nodeEntry); |
| 1569 // 9.9 | 1569 // 9.9 |
| 1570 m_tree.reparent(node, lastNode); | 1570 m_tree.reparent(node, lastNode); |
| 1571 // 9.10 | 1571 // 9.10 |
| 1572 lastNode = node; | 1572 lastNode = node; |
| 1573 } | 1573 } |
| 1574 // 10. | 1574 // 10. |
| 1575 m_tree.insertAlreadyParsedChild(commonAncestor.get(), lastNode); | 1575 m_tree.insertAlreadyParsedChild(commonAncestor.get(), lastNode); |
| 1576 // 11. | 1576 // 11. |
| 1577 RefPtrWillBeRawPtr<HTMLStackItem> newItem = m_tree.createElementFromSave
dToken(formattingElementRecord->stackItem().get()); | 1577 RawPtr<HTMLStackItem> newItem = m_tree.createElementFromSavedToken(forma
ttingElementRecord->stackItem().get()); |
| 1578 // 12. | 1578 // 12. |
| 1579 m_tree.takeAllChildren(newItem.get(), furthestBlock); | 1579 m_tree.takeAllChildren(newItem.get(), furthestBlock); |
| 1580 // 13. | 1580 // 13. |
| 1581 m_tree.reparent(furthestBlock, newItem.get()); | 1581 m_tree.reparent(furthestBlock, newItem.get()); |
| 1582 // 14. | 1582 // 14. |
| 1583 m_tree.activeFormattingElements()->swapTo(formattingElement, newItem, bo
okmark); | 1583 m_tree.activeFormattingElements()->swapTo(formattingElement, newItem, bo
okmark); |
| 1584 // 15. | 1584 // 15. |
| 1585 m_tree.openElements()->remove(formattingElement); | 1585 m_tree.openElements()->remove(formattingElement); |
| 1586 m_tree.openElements()->insertAbove(newItem, furthestBlock); | 1586 m_tree.openElements()->insertAbove(newItem, furthestBlock); |
| 1587 } | 1587 } |
| 1588 } | 1588 } |
| 1589 | 1589 |
| 1590 void HTMLTreeBuilder::resetInsertionModeAppropriately() | 1590 void HTMLTreeBuilder::resetInsertionModeAppropriately() |
| 1591 { | 1591 { |
| 1592 // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#
reset-the-insertion-mode-appropriately | 1592 // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#
reset-the-insertion-mode-appropriately |
| 1593 bool last = false; | 1593 bool last = false; |
| 1594 HTMLElementStack::ElementRecord* nodeRecord = m_tree.openElements()->topReco
rd(); | 1594 HTMLElementStack::ElementRecord* nodeRecord = m_tree.openElements()->topReco
rd(); |
| 1595 while (1) { | 1595 while (1) { |
| 1596 RefPtrWillBeRawPtr<HTMLStackItem> item = nodeRecord->stackItem(); | 1596 RawPtr<HTMLStackItem> item = nodeRecord->stackItem(); |
| 1597 if (item->node() == m_tree.openElements()->rootNode()) { | 1597 if (item->node() == m_tree.openElements()->rootNode()) { |
| 1598 last = true; | 1598 last = true; |
| 1599 if (isParsingFragment()) | 1599 if (isParsingFragment()) |
| 1600 item = m_fragmentContext.contextElementStackItem(); | 1600 item = m_fragmentContext.contextElementStackItem(); |
| 1601 } | 1601 } |
| 1602 if (item->hasTagName(templateTag)) | 1602 if (item->hasTagName(templateTag)) |
| 1603 return setInsertionMode(m_templateInsertionModes.last()); | 1603 return setInsertionMode(m_templateInsertionModes.last()); |
| 1604 if (item->hasTagName(selectTag)) { | 1604 if (item->hasTagName(selectTag)) { |
| 1605 if (!last) { | 1605 if (!last) { |
| 1606 while (item->node() != m_tree.openElements()->rootNode() && !ite
m->hasTagName(templateTag)) { | 1606 while (item->node() != m_tree.openElements()->rootNode() && !ite
m->hasTagName(templateTag)) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1802 parseError(token); | 1802 parseError(token); |
| 1803 return; | 1803 return; |
| 1804 } | 1804 } |
| 1805 m_tree.generateImpliedEndTags(); | 1805 m_tree.generateImpliedEndTags(); |
| 1806 if (!m_tree.currentStackItem()->matchesHTMLTag(token->name())) | 1806 if (!m_tree.currentStackItem()->matchesHTMLTag(token->name())) |
| 1807 parseError(token); | 1807 parseError(token); |
| 1808 m_tree.openElements()->popUntilPopped(token->name()); | 1808 m_tree.openElements()->popUntilPopped(token->name()); |
| 1809 return; | 1809 return; |
| 1810 } | 1810 } |
| 1811 if (token->name() == formTag) { | 1811 if (token->name() == formTag) { |
| 1812 RefPtrWillBeRawPtr<Element> node = m_tree.takeForm(); | 1812 RawPtr<Element> node = m_tree.takeForm(); |
| 1813 if (!node || !m_tree.openElements()->inScope(node.get())) { | 1813 if (!node || !m_tree.openElements()->inScope(node.get())) { |
| 1814 parseError(token); | 1814 parseError(token); |
| 1815 return; | 1815 return; |
| 1816 } | 1816 } |
| 1817 m_tree.generateImpliedEndTags(); | 1817 m_tree.generateImpliedEndTags(); |
| 1818 if (m_tree.currentElement() != node.get()) | 1818 if (m_tree.currentElement() != node.get()) |
| 1819 parseError(token); | 1819 parseError(token); |
| 1820 m_tree.openElements()->remove(node.get()); | 1820 m_tree.openElements()->remove(node.get()); |
| 1821 } | 1821 } |
| 1822 if (token->name() == pTag) { | 1822 if (token->name() == pTag) { |
| (...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2819 ASSERT(m_isAttached); | 2819 ASSERT(m_isAttached); |
| 2820 // Warning, this may detach the parser. Do not do anything else after this. | 2820 // Warning, this may detach the parser. Do not do anything else after this. |
| 2821 m_tree.finishedParsing(); | 2821 m_tree.finishedParsing(); |
| 2822 } | 2822 } |
| 2823 | 2823 |
| 2824 void HTMLTreeBuilder::parseError(AtomicHTMLToken*) | 2824 void HTMLTreeBuilder::parseError(AtomicHTMLToken*) |
| 2825 { | 2825 { |
| 2826 } | 2826 } |
| 2827 | 2827 |
| 2828 } // namespace blink | 2828 } // namespace blink |
| OLD | NEW |