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