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

Side by Side Diff: Source/core/html/parser/HTMLElementStack.cpp

Issue 19098002: Introduce isHTMLHtmlElement and toHTMLHtmlElement (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 7 years, 5 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
« no previous file with comments | « Source/core/html/PluginDocument.cpp ('k') | Source/core/html/parser/HTMLTreeBuilder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/html/parser/HTMLElementStack.h" 28 #include "core/html/parser/HTMLElementStack.h"
29 29
30 #include "HTMLNames.h" 30 #include "HTMLNames.h"
31 #include "MathMLNames.h" 31 #include "MathMLNames.h"
32 #include "SVGNames.h" 32 #include "SVGNames.h"
33 #include "core/dom/Element.h" 33 #include "core/dom/Element.h"
34 #include "core/html/HTMLHtmlElement.h"
34 #include "core/html/HTMLOptGroupElement.h" 35 #include "core/html/HTMLOptGroupElement.h"
35 #include "core/html/HTMLTableElement.h" 36 #include "core/html/HTMLTableElement.h"
36 #include <wtf/PassOwnPtr.h> 37 #include <wtf/PassOwnPtr.h>
37 38
38 namespace WebCore { 39 namespace WebCore {
39 40
40 using namespace HTMLNames; 41 using namespace HTMLNames;
41 42
42 43
43 namespace { 44 namespace {
44 45
45 inline bool isRootNode(HTMLStackItem* item) 46 inline bool isRootNode(HTMLStackItem* item)
46 { 47 {
47 return item->isDocumentFragmentNode() 48 return item->isDocumentFragmentNode()
48 || item->hasTagName(htmlTag); 49 || isHTMLHtmlElement(item->node());
49 } 50 }
50 51
51 inline bool isScopeMarker(HTMLStackItem* item) 52 inline bool isScopeMarker(HTMLStackItem* item)
52 { 53 {
53 return item->hasTagName(appletTag) 54 return item->hasTagName(appletTag)
54 || item->hasTagName(captionTag) 55 || item->hasTagName(captionTag)
55 || item->hasTagName(marqueeTag) 56 || item->hasTagName(marqueeTag)
56 || item->hasTagName(objectTag) 57 || item->hasTagName(objectTag)
57 || isHTMLTableElement(item->node()) 58 || isHTMLTableElement(item->node())
58 || item->hasTagName(tdTag) 59 || item->hasTagName(tdTag)
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 303 }
303 304
304 void HTMLElementStack::pushRootNode(PassRefPtr<HTMLStackItem> rootItem) 305 void HTMLElementStack::pushRootNode(PassRefPtr<HTMLStackItem> rootItem)
305 { 306 {
306 ASSERT(rootItem->isDocumentFragmentNode()); 307 ASSERT(rootItem->isDocumentFragmentNode());
307 pushRootNodeCommon(rootItem); 308 pushRootNodeCommon(rootItem);
308 } 309 }
309 310
310 void HTMLElementStack::pushHTMLHtmlElement(PassRefPtr<HTMLStackItem> item) 311 void HTMLElementStack::pushHTMLHtmlElement(PassRefPtr<HTMLStackItem> item)
311 { 312 {
312 ASSERT(item->hasTagName(HTMLNames::htmlTag)); 313 ASSERT(isHTMLHtmlElement(item->node()));
313 pushRootNodeCommon(item); 314 pushRootNodeCommon(item);
314 } 315 }
315 316
316 void HTMLElementStack::pushRootNodeCommon(PassRefPtr<HTMLStackItem> rootItem) 317 void HTMLElementStack::pushRootNodeCommon(PassRefPtr<HTMLStackItem> rootItem)
317 { 318 {
318 ASSERT(!m_top); 319 ASSERT(!m_top);
319 ASSERT(!m_rootNode); 320 ASSERT(!m_rootNode);
320 m_rootNode = rootItem->node(); 321 m_rootNode = rootItem->node();
321 pushCommon(rootItem); 322 pushCommon(rootItem);
322 } 323 }
323 324
324 void HTMLElementStack::pushHTMLHeadElement(PassRefPtr<HTMLStackItem> item) 325 void HTMLElementStack::pushHTMLHeadElement(PassRefPtr<HTMLStackItem> item)
325 { 326 {
326 ASSERT(item->hasTagName(HTMLNames::headTag)); 327 ASSERT(item->hasTagName(HTMLNames::headTag));
327 ASSERT(!m_headElement); 328 ASSERT(!m_headElement);
328 m_headElement = item->element(); 329 m_headElement = item->element();
329 pushCommon(item); 330 pushCommon(item);
330 } 331 }
331 332
332 void HTMLElementStack::pushHTMLBodyElement(PassRefPtr<HTMLStackItem> item) 333 void HTMLElementStack::pushHTMLBodyElement(PassRefPtr<HTMLStackItem> item)
333 { 334 {
334 ASSERT(item->hasTagName(HTMLNames::bodyTag)); 335 ASSERT(item->hasTagName(HTMLNames::bodyTag));
335 ASSERT(!m_bodyElement); 336 ASSERT(!m_bodyElement);
336 m_bodyElement = item->element(); 337 m_bodyElement = item->element();
337 pushCommon(item); 338 pushCommon(item);
338 } 339 }
339 340
340 void HTMLElementStack::push(PassRefPtr<HTMLStackItem> item) 341 void HTMLElementStack::push(PassRefPtr<HTMLStackItem> item)
341 { 342 {
342 ASSERT(!item->hasTagName(HTMLNames::htmlTag)); 343 ASSERT(!isHTMLHtmlElement(item->node()));
343 ASSERT(!item->hasTagName(HTMLNames::headTag)); 344 ASSERT(!item->hasTagName(HTMLNames::headTag));
344 ASSERT(!item->hasTagName(HTMLNames::bodyTag)); 345 ASSERT(!item->hasTagName(HTMLNames::bodyTag));
345 ASSERT(m_rootNode); 346 ASSERT(m_rootNode);
346 pushCommon(item); 347 pushCommon(item);
347 } 348 }
348 349
349 void HTMLElementStack::insertAbove(PassRefPtr<HTMLStackItem> item, ElementRecord * recordBelow) 350 void HTMLElementStack::insertAbove(PassRefPtr<HTMLStackItem> item, ElementRecord * recordBelow)
350 { 351 {
351 ASSERT(item); 352 ASSERT(item);
352 ASSERT(recordBelow); 353 ASSERT(recordBelow);
353 ASSERT(m_top); 354 ASSERT(m_top);
354 ASSERT(!item->hasTagName(HTMLNames::htmlTag)); 355 ASSERT(!isHTMLHtmlElement(item->node()));
355 ASSERT(!item->hasTagName(HTMLNames::headTag)); 356 ASSERT(!item->hasTagName(HTMLNames::headTag));
356 ASSERT(!item->hasTagName(HTMLNames::bodyTag)); 357 ASSERT(!item->hasTagName(HTMLNames::bodyTag));
357 ASSERT(m_rootNode); 358 ASSERT(m_rootNode);
358 if (recordBelow == m_top) { 359 if (recordBelow == m_top) {
359 push(item); 360 push(item);
360 return; 361 return;
361 } 362 }
362 363
363 for (ElementRecord* recordAbove = m_top.get(); recordAbove; recordAbove = re cordAbove->next()) { 364 for (ElementRecord* recordAbove = m_top.get(); recordAbove; recordAbove = re cordAbove->next()) {
364 if (recordAbove->next() != recordBelow) 365 if (recordAbove->next() != recordBelow)
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 void HTMLElementStack::pushCommon(PassRefPtr<HTMLStackItem> item) 560 void HTMLElementStack::pushCommon(PassRefPtr<HTMLStackItem> item)
560 { 561 {
561 ASSERT(m_rootNode); 562 ASSERT(m_rootNode);
562 563
563 m_stackDepth++; 564 m_stackDepth++;
564 m_top = adoptPtr(new ElementRecord(item, m_top.release())); 565 m_top = adoptPtr(new ElementRecord(item, m_top.release()));
565 } 566 }
566 567
567 void HTMLElementStack::popCommon() 568 void HTMLElementStack::popCommon()
568 { 569 {
569 ASSERT(!topStackItem()->hasTagName(HTMLNames::htmlTag)); 570 ASSERT(!isHTMLHtmlElement(topStackItem()->node()));
570 ASSERT(!topStackItem()->hasTagName(HTMLNames::headTag) || !m_headElement); 571 ASSERT(!topStackItem()->hasTagName(HTMLNames::headTag) || !m_headElement);
571 ASSERT(!topStackItem()->hasTagName(HTMLNames::bodyTag) || !m_bodyElement); 572 ASSERT(!topStackItem()->hasTagName(HTMLNames::bodyTag) || !m_bodyElement);
572 top()->finishParsingChildren(); 573 top()->finishParsingChildren();
573 m_top = m_top->releaseNext(); 574 m_top = m_top->releaseNext();
574 575
575 m_stackDepth--; 576 m_stackDepth--;
576 } 577 }
577 578
578 void HTMLElementStack::removeNonTopCommon(Element* element) 579 void HTMLElementStack::removeNonTopCommon(Element* element)
579 { 580 {
580 ASSERT(!element->hasTagName(HTMLNames::htmlTag)); 581 ASSERT(!isHTMLHtmlElement(element));
581 ASSERT(!element->hasTagName(HTMLNames::bodyTag)); 582 ASSERT(!element->hasTagName(HTMLNames::bodyTag));
582 ASSERT(top() != element); 583 ASSERT(top() != element);
583 for (ElementRecord* pos = m_top.get(); pos; pos = pos->next()) { 584 for (ElementRecord* pos = m_top.get(); pos; pos = pos->next()) {
584 if (pos->next()->element() == element) { 585 if (pos->next()->element() == element) {
585 // FIXME: Is it OK to call finishParsingChildren() 586 // FIXME: Is it OK to call finishParsingChildren()
586 // when the children aren't actually finished? 587 // when the children aren't actually finished?
587 element->finishParsingChildren(); 588 element->finishParsingChildren();
588 pos->setNext(pos->next()->releaseNext()); 589 pos->setNext(pos->next()->releaseNext());
589 m_stackDepth--; 590 m_stackDepth--;
590 return; 591 return;
(...skipping 19 matching lines...) Expand all
610 611
611 void HTMLElementStack::show() 612 void HTMLElementStack::show()
612 { 613 {
613 for (ElementRecord* record = m_top.get(); record; record = record->next()) 614 for (ElementRecord* record = m_top.get(); record; record = record->next())
614 record->element()->showNode(); 615 record->element()->showNode();
615 } 616 }
616 617
617 #endif 618 #endif
618 619
619 } 620 }
OLDNEW
« no previous file with comments | « Source/core/html/PluginDocument.cpp ('k') | Source/core/html/parser/HTMLTreeBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698