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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 , m_attachmentRoot(document) | 203 , m_attachmentRoot(document) |
204 , m_parserContentPolicy(parserContentPolicy) | 204 , m_parserContentPolicy(parserContentPolicy) |
205 , m_isParsingFragment(false) | 205 , m_isParsingFragment(false) |
206 , m_redirectAttachToFosterParent(false) | 206 , m_redirectAttachToFosterParent(false) |
207 , m_inQuirksMode(document->inQuirksMode()) | 207 , m_inQuirksMode(document->inQuirksMode()) |
208 { | 208 { |
209 ASSERT(m_document->isHTMLDocument() || m_document->isSVGDocument() || m_docu
ment->isXHTMLDocument()); | 209 ASSERT(m_document->isHTMLDocument() || m_document->isSVGDocument() || m_docu
ment->isXHTMLDocument()); |
210 } | 210 } |
211 | 211 |
212 HTMLConstructionSite::HTMLConstructionSite(DocumentFragment* fragment, ParserCon
tentPolicy parserContentPolicy) | 212 HTMLConstructionSite::HTMLConstructionSite(DocumentFragment* fragment, ParserCon
tentPolicy parserContentPolicy) |
213 : m_document(fragment->document()) | 213 : m_document(&fragment->document()) |
214 , m_attachmentRoot(fragment) | 214 , m_attachmentRoot(fragment) |
215 , m_parserContentPolicy(parserContentPolicy) | 215 , m_parserContentPolicy(parserContentPolicy) |
216 , m_isParsingFragment(true) | 216 , m_isParsingFragment(true) |
217 , m_redirectAttachToFosterParent(false) | 217 , m_redirectAttachToFosterParent(false) |
218 , m_inQuirksMode(fragment->document()->inQuirksMode()) | 218 , m_inQuirksMode(fragment->document().inQuirksMode()) |
219 { | 219 { |
220 ASSERT(m_document->isHTMLDocument() || m_document->isSVGDocument() || m_docu
ment->isXHTMLDocument()); | 220 ASSERT(m_document->isHTMLDocument() || m_document->isSVGDocument() || m_docu
ment->isXHTMLDocument()); |
221 } | 221 } |
222 | 222 |
223 HTMLConstructionSite::~HTMLConstructionSite() | 223 HTMLConstructionSite::~HTMLConstructionSite() |
224 { | 224 { |
225 } | 225 } |
226 | 226 |
227 void HTMLConstructionSite::detach() | 227 void HTMLConstructionSite::detach() |
228 { | 228 { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 if (token->forceQuirks()) | 417 if (token->forceQuirks()) |
418 setCompatibilityMode(Document::QuirksMode); | 418 setCompatibilityMode(Document::QuirksMode); |
419 else { | 419 else { |
420 setCompatibilityModeFromDoctype(token->name(), publicId, systemId); | 420 setCompatibilityModeFromDoctype(token->name(), publicId, systemId); |
421 } | 421 } |
422 } | 422 } |
423 | 423 |
424 void HTMLConstructionSite::insertComment(AtomicHTMLToken* token) | 424 void HTMLConstructionSite::insertComment(AtomicHTMLToken* token) |
425 { | 425 { |
426 ASSERT(token->type() == HTMLToken::Comment); | 426 ASSERT(token->type() == HTMLToken::Comment); |
427 attachLater(currentNode(), Comment::create(ownerDocumentForCurrentNode(), to
ken->comment())); | 427 attachLater(currentNode(), Comment::create(&ownerDocumentForCurrentNode(), t
oken->comment())); |
428 } | 428 } |
429 | 429 |
430 void HTMLConstructionSite::insertCommentOnDocument(AtomicHTMLToken* token) | 430 void HTMLConstructionSite::insertCommentOnDocument(AtomicHTMLToken* token) |
431 { | 431 { |
432 ASSERT(token->type() == HTMLToken::Comment); | 432 ASSERT(token->type() == HTMLToken::Comment); |
433 attachLater(m_attachmentRoot, Comment::create(m_document, token->comment()))
; | 433 attachLater(m_attachmentRoot, Comment::create(m_document, token->comment()))
; |
434 } | 434 } |
435 | 435 |
436 void HTMLConstructionSite::insertCommentOnHTMLHtmlElement(AtomicHTMLToken* token
) | 436 void HTMLConstructionSite::insertCommentOnHTMLHtmlElement(AtomicHTMLToken* token
) |
437 { | 437 { |
438 ASSERT(token->type() == HTMLToken::Comment); | 438 ASSERT(token->type() == HTMLToken::Comment); |
439 ContainerNode* parent = m_openElements.rootNode(); | 439 ContainerNode* parent = m_openElements.rootNode(); |
440 attachLater(parent, Comment::create(parent->document(), token->comment())); | 440 attachLater(parent, Comment::create(&parent->document(), token->comment())); |
441 } | 441 } |
442 | 442 |
443 void HTMLConstructionSite::insertHTMLHeadElement(AtomicHTMLToken* token) | 443 void HTMLConstructionSite::insertHTMLHeadElement(AtomicHTMLToken* token) |
444 { | 444 { |
445 ASSERT(!shouldFosterParent()); | 445 ASSERT(!shouldFosterParent()); |
446 m_head = HTMLStackItem::create(createHTMLElement(token), token); | 446 m_head = HTMLStackItem::create(createHTMLElement(token), token); |
447 attachLater(currentNode(), m_head->element()); | 447 attachLater(currentNode(), m_head->element()); |
448 m_openElements.pushHTMLHeadElement(m_head); | 448 m_openElements.pushHTMLHeadElement(m_head); |
449 } | 449 } |
450 | 450 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 497 |
498 void HTMLConstructionSite::insertScriptElement(AtomicHTMLToken* token) | 498 void HTMLConstructionSite::insertScriptElement(AtomicHTMLToken* token) |
499 { | 499 { |
500 // http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.h
tml#already-started | 500 // http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.h
tml#already-started |
501 // http://html5.org/specs/dom-parsing.html#dom-range-createcontextualfragmen
t | 501 // http://html5.org/specs/dom-parsing.html#dom-range-createcontextualfragmen
t |
502 // For createContextualFragment, the specifications say to mark it parser-in
serted and already-started and later unmark them. | 502 // For createContextualFragment, the specifications say to mark it parser-in
serted and already-started and later unmark them. |
503 // However, we short circuit that logic to avoid the subtree traversal to fi
nd script elements since scripts can never see | 503 // However, we short circuit that logic to avoid the subtree traversal to fi
nd script elements since scripts can never see |
504 // those flags or effects thereof. | 504 // those flags or effects thereof. |
505 const bool parserInserted = m_parserContentPolicy != AllowScriptingContentAn
dDoNotMarkAlreadyStarted; | 505 const bool parserInserted = m_parserContentPolicy != AllowScriptingContentAn
dDoNotMarkAlreadyStarted; |
506 const bool alreadyStarted = m_isParsingFragment && parserInserted; | 506 const bool alreadyStarted = m_isParsingFragment && parserInserted; |
507 RefPtr<HTMLScriptElement> element = HTMLScriptElement::create(scriptTag, own
erDocumentForCurrentNode(), parserInserted, alreadyStarted); | 507 RefPtr<HTMLScriptElement> element = HTMLScriptElement::create(scriptTag, &ow
nerDocumentForCurrentNode(), parserInserted, alreadyStarted); |
508 setAttributes(element.get(), token, m_parserContentPolicy); | 508 setAttributes(element.get(), token, m_parserContentPolicy); |
509 if (scriptingContentIsAllowed(m_parserContentPolicy)) | 509 if (scriptingContentIsAllowed(m_parserContentPolicy)) |
510 attachLater(currentNode(), element); | 510 attachLater(currentNode(), element); |
511 m_openElements.push(HTMLStackItem::create(element.release(), token)); | 511 m_openElements.push(HTMLStackItem::create(element.release(), token)); |
512 } | 512 } |
513 | 513 |
514 void HTMLConstructionSite::insertForeignElement(AtomicHTMLToken* token, const At
omicString& namespaceURI) | 514 void HTMLConstructionSite::insertForeignElement(AtomicHTMLToken* token, const At
omicString& namespaceURI) |
515 { | 515 { |
516 ASSERT(token->type() == HTMLToken::StartTag); | 516 ASSERT(token->type() == HTMLToken::StartTag); |
517 notImplemented(); // parseError when xmlns or xmlns:xlink are wrong. | 517 notImplemented(); // parseError when xmlns or xmlns:xlink are wrong. |
(...skipping 29 matching lines...) Expand all Loading... |
547 | 547 |
548 Node* previousChild = task.nextChild ? task.nextChild->previousSibling() : t
ask.parent->lastChild(); | 548 Node* previousChild = task.nextChild ? task.nextChild->previousSibling() : t
ask.parent->lastChild(); |
549 if (previousChild && previousChild->isTextNode()) { | 549 if (previousChild && previousChild->isTextNode()) { |
550 // FIXME: We're only supposed to append to this text node if it | 550 // FIXME: We're only supposed to append to this text node if it |
551 // was the last text node inserted by the parser. | 551 // was the last text node inserted by the parser. |
552 CharacterData* textNode = static_cast<CharacterData*>(previousChild); | 552 CharacterData* textNode = static_cast<CharacterData*>(previousChild); |
553 currentPosition = textNode->parserAppendData(characters, 0, lengthLimit)
; | 553 currentPosition = textNode->parserAppendData(characters, 0, lengthLimit)
; |
554 } | 554 } |
555 | 555 |
556 while (currentPosition < characters.length()) { | 556 while (currentPosition < characters.length()) { |
557 RefPtr<Text> textNode = Text::createWithLengthLimit(task.parent->documen
t(), shouldUseAtomicString ? AtomicString(characters).string() : characters, cur
rentPosition, lengthLimit); | 557 RefPtr<Text> textNode = Text::createWithLengthLimit(&task.parent->docume
nt(), shouldUseAtomicString ? AtomicString(characters).string() : characters, cu
rrentPosition, lengthLimit); |
558 // If we have a whole string of unbreakable characters the above could l
ead to an infinite loop. Exceeding the length limit is the lesser evil. | 558 // If we have a whole string of unbreakable characters the above could l
ead to an infinite loop. Exceeding the length limit is the lesser evil. |
559 if (!textNode->length()) { | 559 if (!textNode->length()) { |
560 String substring = characters.substring(currentPosition); | 560 String substring = characters.substring(currentPosition); |
561 textNode = Text::create(task.parent->document(), shouldUseAtomicStri
ng ? AtomicString(substring).string() : substring); | 561 textNode = Text::create(&task.parent->document(), shouldUseAtomicStr
ing ? AtomicString(substring).string() : substring); |
562 } | 562 } |
563 | 563 |
564 currentPosition += textNode->length(); | 564 currentPosition += textNode->length(); |
565 ASSERT(currentPosition <= characters.length()); | 565 ASSERT(currentPosition <= characters.length()); |
566 task.child = textNode.release(); | 566 task.child = textNode.release(); |
567 | 567 |
568 executeTask(task); | 568 executeTask(task); |
569 } | 569 } |
570 } | 570 } |
571 | 571 |
(...skipping 30 matching lines...) Expand all Loading... |
602 { | 602 { |
603 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::TakeAllChildren); | 603 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::TakeAllChildren); |
604 task.parent = newParent->node(); | 604 task.parent = newParent->node(); |
605 task.child = oldParent->node(); | 605 task.child = oldParent->node(); |
606 m_taskQueue.append(task); | 606 m_taskQueue.append(task); |
607 } | 607 } |
608 | 608 |
609 PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token,
const AtomicString& namespaceURI) | 609 PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token,
const AtomicString& namespaceURI) |
610 { | 610 { |
611 QualifiedName tagName(nullAtom, token->name(), namespaceURI); | 611 QualifiedName tagName(nullAtom, token->name(), namespaceURI); |
612 RefPtr<Element> element = ownerDocumentForCurrentNode()->createElement(tagNa
me, true); | 612 RefPtr<Element> element = ownerDocumentForCurrentNode().createElement(tagNam
e, true); |
613 setAttributes(element.get(), token, m_parserContentPolicy); | 613 setAttributes(element.get(), token, m_parserContentPolicy); |
614 return element.release(); | 614 return element.release(); |
615 } | 615 } |
616 | 616 |
617 inline Document* HTMLConstructionSite::ownerDocumentForCurrentNode() | 617 inline Document& HTMLConstructionSite::ownerDocumentForCurrentNode() |
618 { | 618 { |
619 if (currentNode()->hasTagName(templateTag)) | 619 if (currentNode()->hasTagName(templateTag)) |
620 return toHTMLTemplateElement(currentElement())->content()->document(); | 620 return toHTMLTemplateElement(currentElement())->content()->document(); |
621 return currentNode()->document(); | 621 return currentNode()->document(); |
622 } | 622 } |
623 | 623 |
624 PassRefPtr<Element> HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* tok
en) | 624 PassRefPtr<Element> HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* tok
en) |
625 { | 625 { |
626 QualifiedName tagName(nullAtom, token->name(), xhtmlNamespaceURI); | 626 QualifiedName tagName(nullAtom, token->name(), xhtmlNamespaceURI); |
627 Document* document = ownerDocumentForCurrentNode(); | 627 Document& document = ownerDocumentForCurrentNode(); |
628 // Only associate the element with the current form if we're creating the ne
w element | 628 // Only associate the element with the current form if we're creating the ne
w element |
629 // in a document with a browsing context (rather than in <template> contents
). | 629 // in a document with a browsing context (rather than in <template> contents
). |
630 HTMLFormElement* form = document->frame() ? m_form.get() : 0; | 630 HTMLFormElement* form = document.frame() ? m_form.get() : 0; |
631 // FIXME: This can't use HTMLConstructionSite::createElement because we | 631 // FIXME: This can't use HTMLConstructionSite::createElement because we |
632 // have to pass the current form element. We should rework form association | 632 // have to pass the current form element. We should rework form association |
633 // to occur after construction to allow better code sharing here. | 633 // to occur after construction to allow better code sharing here. |
634 RefPtr<Element> element = HTMLElementFactory::createHTMLElement(tagName, doc
ument, form, true); | 634 RefPtr<Element> element = HTMLElementFactory::createHTMLElement(tagName, &do
cument, form, true); |
635 setAttributes(element.get(), token, m_parserContentPolicy); | 635 setAttributes(element.get(), token, m_parserContentPolicy); |
636 ASSERT(element->isHTMLElement()); | 636 ASSERT(element->isHTMLElement()); |
637 return element.release(); | 637 return element.release(); |
638 } | 638 } |
639 | 639 |
640 PassRefPtr<HTMLStackItem> HTMLConstructionSite::createElementFromSavedToken(HTML
StackItem* item) | 640 PassRefPtr<HTMLStackItem> HTMLConstructionSite::createElementFromSavedToken(HTML
StackItem* item) |
641 { | 641 { |
642 RefPtr<Element> element; | 642 RefPtr<Element> element; |
643 // NOTE: Moving from item -> token -> item copies the Attribute vector twice
! | 643 // NOTE: Moving from item -> token -> item copies the Attribute vector twice
! |
644 AtomicHTMLToken fakeToken(HTMLToken::StartTag, item->localName(), item->attr
ibutes()); | 644 AtomicHTMLToken fakeToken(HTMLToken::StartTag, item->localName(), item->attr
ibutes()); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 { | 743 { |
744 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); | 744 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); |
745 findFosterSite(task); | 745 findFosterSite(task); |
746 task.child = node; | 746 task.child = node; |
747 ASSERT(task.parent); | 747 ASSERT(task.parent); |
748 | 748 |
749 m_taskQueue.append(task); | 749 m_taskQueue.append(task); |
750 } | 750 } |
751 | 751 |
752 } | 752 } |
OLD | NEW |