| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 inline bool isSelectScopeMarker(HTMLStackItem* item) | 114 inline bool isSelectScopeMarker(HTMLStackItem* item) |
| 115 { | 115 { |
| 116 return !item->hasTagName(optgroupTag) | 116 return !item->hasTagName(optgroupTag) |
| 117 && !item->hasTagName(optionTag); | 117 && !item->hasTagName(optionTag); |
| 118 } | 118 } |
| 119 | 119 |
| 120 } | 120 } |
| 121 | 121 |
| 122 HTMLElementStack::ElementRecord::ElementRecord(PassRefPtr<HTMLStackItem> item, P
assOwnPtr<ElementRecord> next) | 122 HTMLElementStack::ElementRecord::ElementRecord(PassRefPtrWillBeRawPtr<HTMLStackI
tem> item, PassOwnPtrWillBeRawPtr<ElementRecord> next) |
| 123 : m_item(item) | 123 : m_item(item) |
| 124 , m_next(next) | 124 , m_next(next) |
| 125 { | 125 { |
| 126 ASSERT(m_item); | 126 ASSERT(m_item); |
| 127 } | 127 } |
| 128 | 128 |
| 129 #if !ENABLE(OILPAN) |
| 129 HTMLElementStack::ElementRecord::~ElementRecord() | 130 HTMLElementStack::ElementRecord::~ElementRecord() |
| 130 { | 131 { |
| 131 } | 132 } |
| 133 #endif |
| 132 | 134 |
| 133 void HTMLElementStack::ElementRecord::replaceElement(PassRefPtr<HTMLStackItem> i
tem) | 135 void HTMLElementStack::ElementRecord::replaceElement(PassRefPtrWillBeRawPtr<HTML
StackItem> item) |
| 134 { | 136 { |
| 135 ASSERT(item); | 137 ASSERT(item); |
| 136 ASSERT(!m_item || m_item->isElementNode()); | 138 ASSERT(!m_item || m_item->isElementNode()); |
| 137 // FIXME: Should this call finishParsingChildren? | 139 // FIXME: Should this call finishParsingChildren? |
| 138 m_item = item; | 140 m_item = item; |
| 139 } | 141 } |
| 140 | 142 |
| 141 bool HTMLElementStack::ElementRecord::isAbove(ElementRecord* other) const | 143 bool HTMLElementStack::ElementRecord::isAbove(ElementRecord* other) const |
| 142 { | 144 { |
| 143 for (ElementRecord* below = next(); below; below = below->next()) { | 145 for (ElementRecord* below = next(); below; below = below->next()) { |
| 144 if (below == other) | 146 if (below == other) |
| 145 return true; | 147 return true; |
| 146 } | 148 } |
| 147 return false; | 149 return false; |
| 148 } | 150 } |
| 149 | 151 |
| 152 void HTMLElementStack::ElementRecord::trace(Visitor* visitor) |
| 153 { |
| 154 #if ENABLE(OILPAN) |
| 155 visitor->trace(m_item); |
| 156 visitor->trace(m_next); |
| 157 #endif |
| 158 } |
| 159 |
| 150 HTMLElementStack::HTMLElementStack() | 160 HTMLElementStack::HTMLElementStack() |
| 151 : m_rootNode(0) | 161 : m_rootNode(nullptr) |
| 152 , m_headElement(0) | 162 , m_headElement(nullptr) |
| 153 , m_bodyElement(0) | 163 , m_bodyElement(nullptr) |
| 154 , m_stackDepth(0) | 164 , m_stackDepth(0) |
| 155 { | 165 { |
| 156 } | 166 } |
| 157 | 167 |
| 158 HTMLElementStack::~HTMLElementStack() | 168 HTMLElementStack::~HTMLElementStack() |
| 159 { | 169 { |
| 160 } | 170 } |
| 161 | 171 |
| 162 bool HTMLElementStack::hasOnlyOneElement() const | 172 bool HTMLElementStack::hasOnlyOneElement() const |
| 163 { | 173 { |
| 164 return !topRecord()->next(); | 174 return !topRecord()->next(); |
| 165 } | 175 } |
| 166 | 176 |
| 167 bool HTMLElementStack::secondElementIsHTMLBodyElement() const | 177 bool HTMLElementStack::secondElementIsHTMLBodyElement() const |
| 168 { | 178 { |
| 169 // This is used the fragment case of <body> and <frameset> in the "in body" | 179 // This is used the fragment case of <body> and <frameset> in the "in body" |
| 170 // insertion mode. | 180 // insertion mode. |
| 171 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.
html#parsing-main-inbody | 181 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.
html#parsing-main-inbody |
| 172 ASSERT(m_rootNode); | 182 ASSERT(m_rootNode); |
| 173 // If we have a body element, it must always be the second element on the | 183 // If we have a body element, it must always be the second element on the |
| 174 // stack, as we always start with an html element, and any other element | 184 // stack, as we always start with an html element, and any other element |
| 175 // would cause the implicit creation of a body element. | 185 // would cause the implicit creation of a body element. |
| 176 return !!m_bodyElement; | 186 return !!m_bodyElement; |
| 177 } | 187 } |
| 178 | 188 |
| 179 void HTMLElementStack::popHTMLHeadElement() | 189 void HTMLElementStack::popHTMLHeadElement() |
| 180 { | 190 { |
| 181 ASSERT(top() == m_headElement); | 191 ASSERT(top() == m_headElement); |
| 182 m_headElement = 0; | 192 m_headElement = nullptr; |
| 183 popCommon(); | 193 popCommon(); |
| 184 } | 194 } |
| 185 | 195 |
| 186 void HTMLElementStack::popHTMLBodyElement() | 196 void HTMLElementStack::popHTMLBodyElement() |
| 187 { | 197 { |
| 188 ASSERT(top() == m_bodyElement); | 198 ASSERT(top() == m_bodyElement); |
| 189 m_bodyElement = 0; | 199 m_bodyElement = nullptr; |
| 190 popCommon(); | 200 popCommon(); |
| 191 } | 201 } |
| 192 | 202 |
| 193 void HTMLElementStack::popAll() | 203 void HTMLElementStack::popAll() |
| 194 { | 204 { |
| 195 m_rootNode = 0; | 205 m_rootNode = nullptr; |
| 196 m_headElement = 0; | 206 m_headElement = nullptr; |
| 197 m_bodyElement = 0; | 207 m_bodyElement = nullptr; |
| 198 m_stackDepth = 0; | 208 m_stackDepth = 0; |
| 199 while (m_top) { | 209 while (m_top) { |
| 200 Node& node = *topNode(); | 210 Node& node = *topNode(); |
| 201 if (node.isElementNode()) | 211 if (node.isElementNode()) |
| 202 toElement(node).finishParsingChildren(); | 212 toElement(node).finishParsingChildren(); |
| 203 m_top = m_top->releaseNext(); | 213 m_top = m_top->releaseNext(); |
| 204 } | 214 } |
| 205 } | 215 } |
| 206 | 216 |
| 207 void HTMLElementStack::pop() | 217 void HTMLElementStack::pop() |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 || item->hasTagName(SVGNames::descTag) | 304 || item->hasTagName(SVGNames::descTag) |
| 295 || item->hasTagName(SVGNames::titleTag); | 305 || item->hasTagName(SVGNames::titleTag); |
| 296 } | 306 } |
| 297 | 307 |
| 298 void HTMLElementStack::popUntilForeignContentScopeMarker() | 308 void HTMLElementStack::popUntilForeignContentScopeMarker() |
| 299 { | 309 { |
| 300 while (!isForeignContentScopeMarker(topStackItem())) | 310 while (!isForeignContentScopeMarker(topStackItem())) |
| 301 pop(); | 311 pop(); |
| 302 } | 312 } |
| 303 | 313 |
| 304 void HTMLElementStack::pushRootNode(PassRefPtr<HTMLStackItem> rootItem) | 314 void HTMLElementStack::pushRootNode(PassRefPtrWillBeRawPtr<HTMLStackItem> rootIt
em) |
| 305 { | 315 { |
| 306 ASSERT(rootItem->isDocumentFragmentNode()); | 316 ASSERT(rootItem->isDocumentFragmentNode()); |
| 307 pushRootNodeCommon(rootItem); | 317 pushRootNodeCommon(rootItem); |
| 308 } | 318 } |
| 309 | 319 |
| 310 void HTMLElementStack::pushHTMLHtmlElement(PassRefPtr<HTMLStackItem> item) | 320 void HTMLElementStack::pushHTMLHtmlElement(PassRefPtrWillBeRawPtr<HTMLStackItem>
item) |
| 311 { | 321 { |
| 312 ASSERT(item->hasTagName(htmlTag)); | 322 ASSERT(item->hasTagName(htmlTag)); |
| 313 pushRootNodeCommon(item); | 323 pushRootNodeCommon(item); |
| 314 } | 324 } |
| 315 | 325 |
| 316 void HTMLElementStack::pushRootNodeCommon(PassRefPtr<HTMLStackItem> rootItem) | 326 void HTMLElementStack::pushRootNodeCommon(PassRefPtrWillBeRawPtr<HTMLStackItem>
rootItem) |
| 317 { | 327 { |
| 318 ASSERT(!m_top); | 328 ASSERT(!m_top); |
| 319 ASSERT(!m_rootNode); | 329 ASSERT(!m_rootNode); |
| 320 m_rootNode = rootItem->node(); | 330 m_rootNode = rootItem->node(); |
| 321 pushCommon(rootItem); | 331 pushCommon(rootItem); |
| 322 } | 332 } |
| 323 | 333 |
| 324 void HTMLElementStack::pushHTMLHeadElement(PassRefPtr<HTMLStackItem> item) | 334 void HTMLElementStack::pushHTMLHeadElement(PassRefPtrWillBeRawPtr<HTMLStackItem>
item) |
| 325 { | 335 { |
| 326 ASSERT(item->hasTagName(HTMLNames::headTag)); | 336 ASSERT(item->hasTagName(HTMLNames::headTag)); |
| 327 ASSERT(!m_headElement); | 337 ASSERT(!m_headElement); |
| 328 m_headElement = item->element(); | 338 m_headElement = item->element(); |
| 329 pushCommon(item); | 339 pushCommon(item); |
| 330 } | 340 } |
| 331 | 341 |
| 332 void HTMLElementStack::pushHTMLBodyElement(PassRefPtr<HTMLStackItem> item) | 342 void HTMLElementStack::pushHTMLBodyElement(PassRefPtrWillBeRawPtr<HTMLStackItem>
item) |
| 333 { | 343 { |
| 334 ASSERT(item->hasTagName(HTMLNames::bodyTag)); | 344 ASSERT(item->hasTagName(HTMLNames::bodyTag)); |
| 335 ASSERT(!m_bodyElement); | 345 ASSERT(!m_bodyElement); |
| 336 m_bodyElement = item->element(); | 346 m_bodyElement = item->element(); |
| 337 pushCommon(item); | 347 pushCommon(item); |
| 338 } | 348 } |
| 339 | 349 |
| 340 void HTMLElementStack::push(PassRefPtr<HTMLStackItem> item) | 350 void HTMLElementStack::push(PassRefPtrWillBeRawPtr<HTMLStackItem> item) |
| 341 { | 351 { |
| 342 ASSERT(!item->hasTagName(htmlTag)); | 352 ASSERT(!item->hasTagName(htmlTag)); |
| 343 ASSERT(!item->hasTagName(headTag)); | 353 ASSERT(!item->hasTagName(headTag)); |
| 344 ASSERT(!item->hasTagName(bodyTag)); | 354 ASSERT(!item->hasTagName(bodyTag)); |
| 345 ASSERT(m_rootNode); | 355 ASSERT(m_rootNode); |
| 346 pushCommon(item); | 356 pushCommon(item); |
| 347 } | 357 } |
| 348 | 358 |
| 349 void HTMLElementStack::insertAbove(PassRefPtr<HTMLStackItem> item, ElementRecord
* recordBelow) | 359 void HTMLElementStack::insertAbove(PassRefPtrWillBeRawPtr<HTMLStackItem> item, E
lementRecord* recordBelow) |
| 350 { | 360 { |
| 351 ASSERT(item); | 361 ASSERT(item); |
| 352 ASSERT(recordBelow); | 362 ASSERT(recordBelow); |
| 353 ASSERT(m_top); | 363 ASSERT(m_top); |
| 354 ASSERT(!item->hasTagName(htmlTag)); | 364 ASSERT(!item->hasTagName(htmlTag)); |
| 355 ASSERT(!item->hasTagName(headTag)); | 365 ASSERT(!item->hasTagName(headTag)); |
| 356 ASSERT(!item->hasTagName(bodyTag)); | 366 ASSERT(!item->hasTagName(bodyTag)); |
| 357 ASSERT(m_rootNode); | 367 ASSERT(m_rootNode); |
| 358 if (recordBelow == m_top) { | 368 if (recordBelow == m_top) { |
| 359 push(item); | 369 push(item); |
| 360 return; | 370 return; |
| 361 } | 371 } |
| 362 | 372 |
| 363 for (ElementRecord* recordAbove = m_top.get(); recordAbove; recordAbove = re
cordAbove->next()) { | 373 for (ElementRecord* recordAbove = m_top.get(); recordAbove; recordAbove = re
cordAbove->next()) { |
| 364 if (recordAbove->next() != recordBelow) | 374 if (recordAbove->next() != recordBelow) |
| 365 continue; | 375 continue; |
| 366 | 376 |
| 367 m_stackDepth++; | 377 m_stackDepth++; |
| 368 recordAbove->setNext(adoptPtr(new ElementRecord(item, recordAbove->relea
seNext()))); | 378 recordAbove->setNext(adoptPtrWillBeNoop(new ElementRecord(item, recordAb
ove->releaseNext()))); |
| 369 recordAbove->next()->element()->beginParsingChildren(); | 379 recordAbove->next()->element()->beginParsingChildren(); |
| 370 return; | 380 return; |
| 371 } | 381 } |
| 372 ASSERT_NOT_REACHED(); | 382 ASSERT_NOT_REACHED(); |
| 373 } | 383 } |
| 374 | 384 |
| 375 HTMLElementStack::ElementRecord* HTMLElementStack::topRecord() const | 385 HTMLElementStack::ElementRecord* HTMLElementStack::topRecord() const |
| 376 { | 386 { |
| 377 ASSERT(m_top); | 387 ASSERT(m_top); |
| 378 return m_top.get(); | 388 return m_top.get(); |
| 379 } | 389 } |
| 380 | 390 |
| 381 HTMLStackItem* HTMLElementStack::oneBelowTop() const | 391 HTMLStackItem* HTMLElementStack::oneBelowTop() const |
| 382 { | 392 { |
| 383 // We should never call this if there are fewer than 2 elements on the stack
. | 393 // We should never call this if there are fewer than 2 elements on the stack
. |
| 384 ASSERT(m_top); | 394 ASSERT(m_top); |
| 385 ASSERT(m_top->next()); | 395 ASSERT(m_top->next()); |
| 386 if (m_top->next()->stackItem()->isElementNode()) | 396 if (m_top->next()->stackItem()->isElementNode()) |
| 387 return m_top->next()->stackItem().get(); | 397 return m_top->next()->stackItem().get(); |
| 388 return 0; | 398 return 0; |
| 389 } | 399 } |
| 390 | 400 |
| 391 void HTMLElementStack::removeHTMLHeadElement(Element* element) | 401 void HTMLElementStack::removeHTMLHeadElement(Element* element) |
| 392 { | 402 { |
| 393 ASSERT(m_headElement == element); | 403 ASSERT(m_headElement == element); |
| 394 if (m_top->element() == element) { | 404 if (m_top->element() == element) { |
| 395 popHTMLHeadElement(); | 405 popHTMLHeadElement(); |
| 396 return; | 406 return; |
| 397 } | 407 } |
| 398 m_headElement = 0; | 408 m_headElement = nullptr; |
| 399 removeNonTopCommon(element); | 409 removeNonTopCommon(element); |
| 400 } | 410 } |
| 401 | 411 |
| 402 void HTMLElementStack::remove(Element* element) | 412 void HTMLElementStack::remove(Element* element) |
| 403 { | 413 { |
| 404 ASSERT(!isHTMLHeadElement(element)); | 414 ASSERT(!isHTMLHeadElement(element)); |
| 405 if (m_top->element() == element) { | 415 if (m_top->element() == element) { |
| 406 pop(); | 416 pop(); |
| 407 return; | 417 return; |
| 408 } | 418 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 ASSERT(m_bodyElement); | 559 ASSERT(m_bodyElement); |
| 550 return m_bodyElement; | 560 return m_bodyElement; |
| 551 } | 561 } |
| 552 | 562 |
| 553 ContainerNode* HTMLElementStack::rootNode() const | 563 ContainerNode* HTMLElementStack::rootNode() const |
| 554 { | 564 { |
| 555 ASSERT(m_rootNode); | 565 ASSERT(m_rootNode); |
| 556 return m_rootNode; | 566 return m_rootNode; |
| 557 } | 567 } |
| 558 | 568 |
| 559 void HTMLElementStack::pushCommon(PassRefPtr<HTMLStackItem> item) | 569 void HTMLElementStack::pushCommon(PassRefPtrWillBeRawPtr<HTMLStackItem> item) |
| 560 { | 570 { |
| 561 ASSERT(m_rootNode); | 571 ASSERT(m_rootNode); |
| 562 | 572 |
| 563 m_stackDepth++; | 573 m_stackDepth++; |
| 564 m_top = adoptPtr(new ElementRecord(item, m_top.release())); | 574 m_top = adoptPtrWillBeNoop(new ElementRecord(item, m_top.release())); |
| 565 } | 575 } |
| 566 | 576 |
| 567 void HTMLElementStack::popCommon() | 577 void HTMLElementStack::popCommon() |
| 568 { | 578 { |
| 569 ASSERT(!topStackItem()->hasTagName(htmlTag)); | 579 ASSERT(!topStackItem()->hasTagName(htmlTag)); |
| 570 ASSERT(!topStackItem()->hasTagName(headTag) || !m_headElement); | 580 ASSERT(!topStackItem()->hasTagName(headTag) || !m_headElement); |
| 571 ASSERT(!topStackItem()->hasTagName(bodyTag) || !m_bodyElement); | 581 ASSERT(!topStackItem()->hasTagName(bodyTag) || !m_bodyElement); |
| 572 top()->finishParsingChildren(); | 582 top()->finishParsingChildren(); |
| 573 m_top = m_top->releaseNext(); | 583 m_top = m_top->releaseNext(); |
| 574 | 584 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 599 for (ElementRecord* pos = m_top.get(); pos; pos = pos->next()) { | 609 for (ElementRecord* pos = m_top.get(); pos; pos = pos->next()) { |
| 600 if (pos->element() == formattingElement) | 610 if (pos->element() == formattingElement) |
| 601 return furthestBlock; | 611 return furthestBlock; |
| 602 if (pos->stackItem()->isSpecialNode()) | 612 if (pos->stackItem()->isSpecialNode()) |
| 603 furthestBlock = pos; | 613 furthestBlock = pos; |
| 604 } | 614 } |
| 605 ASSERT_NOT_REACHED(); | 615 ASSERT_NOT_REACHED(); |
| 606 return 0; | 616 return 0; |
| 607 } | 617 } |
| 608 | 618 |
| 619 void HTMLElementStack::trace(Visitor* visitor) |
| 620 { |
| 621 visitor->trace(m_top); |
| 622 visitor->trace(m_rootNode); |
| 623 visitor->trace(m_headElement); |
| 624 visitor->trace(m_bodyElement); |
| 625 } |
| 626 |
| 609 #ifndef NDEBUG | 627 #ifndef NDEBUG |
| 610 | 628 |
| 611 void HTMLElementStack::show() | 629 void HTMLElementStack::show() |
| 612 { | 630 { |
| 613 for (ElementRecord* record = m_top.get(); record; record = record->next()) | 631 for (ElementRecord* record = m_top.get(); record; record = record->next()) |
| 614 record->element()->showNode(); | 632 record->element()->showNode(); |
| 615 } | 633 } |
| 616 | 634 |
| 617 #endif | 635 #endif |
| 618 | 636 |
| 619 } | 637 } |
| OLD | NEW |