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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLConstructionSite.cpp

Issue 2143833003: [Match Spec] Form element pointer should not be updated w/in <template> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: undo labels which have been split into separate CL Created 4 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
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 14 matching lines...) Expand all
25 */ 25 */
26 26
27 #include "core/html/parser/HTMLConstructionSite.h" 27 #include "core/html/parser/HTMLConstructionSite.h"
28 28
29 #include "core/HTMLElementFactory.h" 29 #include "core/HTMLElementFactory.h"
30 #include "core/HTMLNames.h" 30 #include "core/HTMLNames.h"
31 #include "core/dom/Comment.h" 31 #include "core/dom/Comment.h"
32 #include "core/dom/DocumentFragment.h" 32 #include "core/dom/DocumentFragment.h"
33 #include "core/dom/DocumentType.h" 33 #include "core/dom/DocumentType.h"
34 #include "core/dom/Element.h" 34 #include "core/dom/Element.h"
35 #include "core/dom/ElementTraversal.h"
35 #include "core/dom/ScriptLoader.h" 36 #include "core/dom/ScriptLoader.h"
36 #include "core/dom/TemplateContentDocumentFragment.h" 37 #include "core/dom/TemplateContentDocumentFragment.h"
37 #include "core/dom/Text.h" 38 #include "core/dom/Text.h"
38 #include "core/frame/LocalFrame.h" 39 #include "core/frame/LocalFrame.h"
39 #include "core/html/HTMLFormElement.h" 40 #include "core/html/HTMLFormElement.h"
40 #include "core/html/HTMLHtmlElement.h" 41 #include "core/html/HTMLHtmlElement.h"
41 #include "core/html/HTMLPlugInElement.h" 42 #include "core/html/HTMLPlugInElement.h"
42 #include "core/html/HTMLScriptElement.h" 43 #include "core/html/HTMLScriptElement.h"
43 #include "core/html/HTMLTemplateElement.h" 44 #include "core/html/HTMLTemplateElement.h"
44 #include "core/html/parser/AtomicHTMLToken.h" 45 #include "core/html/parser/AtomicHTMLToken.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 : m_document(&document) 318 : m_document(&document)
318 , m_attachmentRoot(document) 319 , m_attachmentRoot(document)
319 , m_parserContentPolicy(parserContentPolicy) 320 , m_parserContentPolicy(parserContentPolicy)
320 , m_isParsingFragment(false) 321 , m_isParsingFragment(false)
321 , m_redirectAttachToFosterParent(false) 322 , m_redirectAttachToFosterParent(false)
322 , m_inQuirksMode(document.inQuirksMode()) 323 , m_inQuirksMode(document.inQuirksMode())
323 { 324 {
324 ASSERT(m_document->isHTMLDocument() || m_document->isXHTMLDocument()); 325 ASSERT(m_document->isHTMLDocument() || m_document->isXHTMLDocument());
325 } 326 }
326 327
327 void HTMLConstructionSite::initFragmentParsing(DocumentFragment* fragment) 328 void HTMLConstructionSite::initFragmentParsing(DocumentFragment* fragment, Eleme nt* contextElement)
328 { 329 {
330 DCHECK(contextElement);
329 DCHECK_EQ(m_document, &fragment->document()); 331 DCHECK_EQ(m_document, &fragment->document());
330 DCHECK_EQ(m_inQuirksMode, fragment->document().inQuirksMode()); 332 DCHECK_EQ(m_inQuirksMode, fragment->document().inQuirksMode());
331 DCHECK(!m_isParsingFragment); 333 DCHECK(!m_isParsingFragment);
334 DCHECK(!m_form);
332 335
333 m_attachmentRoot = fragment; 336 m_attachmentRoot = fragment;
334 m_isParsingFragment = true; 337 m_isParsingFragment = true;
338
339 if (!contextElement->document().isTemplateDocument())
340 m_form = Traversal<HTMLFormElement>::firstAncestorOrSelf(*contextElement );
335 } 341 }
336 342
337 HTMLConstructionSite::~HTMLConstructionSite() 343 HTMLConstructionSite::~HTMLConstructionSite()
338 { 344 {
339 // Depending on why we're being destroyed it might be OK 345 // Depending on why we're being destroyed it might be OK
340 // to forget queued tasks, but currently we don't expect to. 346 // to forget queued tasks, but currently we don't expect to.
341 ASSERT(m_taskQueue.isEmpty()); 347 ASSERT(m_taskQueue.isEmpty());
342 // Currently we assume that text will never be the last token in the 348 // Currently we assume that text will never be the last token in the
343 // document and that we'll always queue some additional task to cause it to flush. 349 // document and that we'll always queue some additional task to cause it to flush.
344 ASSERT(m_pendingText.isEmpty()); 350 ASSERT(m_pendingText.isEmpty());
(...skipping 14 matching lines...) Expand all
359 void HTMLConstructionSite::detach() 365 void HTMLConstructionSite::detach()
360 { 366 {
361 // FIXME: We'd like to ASSERT here that we're canceling and not just discard ing 367 // FIXME: We'd like to ASSERT here that we're canceling and not just discard ing
362 // text that really should have made it into the DOM earlier, but there 368 // text that really should have made it into the DOM earlier, but there
363 // doesn't seem to be a nice way to do that. 369 // doesn't seem to be a nice way to do that.
364 m_pendingText.discard(); 370 m_pendingText.discard();
365 m_document = nullptr; 371 m_document = nullptr;
366 m_attachmentRoot = nullptr; 372 m_attachmentRoot = nullptr;
367 } 373 }
368 374
369 void HTMLConstructionSite::setForm(HTMLFormElement* form)
370 {
371 // This method should only be needed for HTMLTreeBuilder in the fragment cas e.
372 ASSERT(!m_form);
373 m_form = form;
374 }
375
376 HTMLFormElement* HTMLConstructionSite::takeForm() 375 HTMLFormElement* HTMLConstructionSite::takeForm()
377 { 376 {
378 return m_form.release(); 377 return m_form.release();
379 } 378 }
380 379
381 void HTMLConstructionSite::insertHTMLHtmlStartTagBeforeHTML(AtomicHTMLToken* tok en) 380 void HTMLConstructionSite::insertHTMLHtmlStartTagBeforeHTML(AtomicHTMLToken* tok en)
382 { 381 {
383 ASSERT(m_document); 382 ASSERT(m_document);
384 HTMLHtmlElement* element = HTMLHtmlElement::create(*m_document); 383 HTMLHtmlElement* element = HTMLHtmlElement::create(*m_document);
385 setAttributes(element, token, m_parserContentPolicy); 384 setAttributes(element, token, m_parserContentPolicy);
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 attachLater(currentNode(), body); 592 attachLater(currentNode(), body);
594 m_openElements.pushHTMLBodyElement(HTMLStackItem::create(body, token)); 593 m_openElements.pushHTMLBodyElement(HTMLStackItem::create(body, token));
595 if (m_document) 594 if (m_document)
596 m_document->willInsertBody(); 595 m_document->willInsertBody();
597 } 596 }
598 597
599 void HTMLConstructionSite::insertHTMLFormElement(AtomicHTMLToken* token, bool is Demoted) 598 void HTMLConstructionSite::insertHTMLFormElement(AtomicHTMLToken* token, bool is Demoted)
600 { 599 {
601 HTMLElement* element = createHTMLElement(token); 600 HTMLElement* element = createHTMLElement(token);
602 ASSERT(isHTMLFormElement(element)); 601 ASSERT(isHTMLFormElement(element));
603 m_form = toHTMLFormElement(element); 602 HTMLFormElement* formElement = toHTMLFormElement(element);
604 m_form->setDemoted(isDemoted); 603 if (!ownerDocumentForCurrentNode().isTemplateDocument())
605 attachLater(currentNode(), m_form.get()); 604 m_form = formElement;
606 m_openElements.push(HTMLStackItem::create(m_form.get(), token)); 605 formElement->setDemoted(isDemoted);
606 attachLater(currentNode(), formElement);
607 m_openElements.push(HTMLStackItem::create(formElement, token));
607 } 608 }
608 609
609 void HTMLConstructionSite::insertHTMLElement(AtomicHTMLToken* token) 610 void HTMLConstructionSite::insertHTMLElement(AtomicHTMLToken* token)
610 { 611 {
611 HTMLElement* element = createHTMLElement(token); 612 HTMLElement* element = createHTMLElement(token);
612 attachLater(currentNode(), element); 613 attachLater(currentNode(), element);
613 m_openElements.push(HTMLStackItem::create(element, token)); 614 m_openElements.push(HTMLStackItem::create(element, token));
614 } 615 }
615 616
616 void HTMLConstructionSite::insertSelfClosingHTMLElementDestroyingToken(AtomicHTM LToken* token) 617 void HTMLConstructionSite::insertSelfClosingHTMLElementDestroyingToken(AtomicHTM LToken* token)
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 if (isHTMLTemplateElement(*currentNode())) 745 if (isHTMLTemplateElement(*currentNode()))
745 return toHTMLTemplateElement(currentElement())->content()->document(); 746 return toHTMLTemplateElement(currentElement())->content()->document();
746 return currentNode()->document(); 747 return currentNode()->document();
747 } 748 }
748 749
749 HTMLElement* HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* token) 750 HTMLElement* HTMLConstructionSite::createHTMLElement(AtomicHTMLToken* token)
750 { 751 {
751 Document& document = ownerDocumentForCurrentNode(); 752 Document& document = ownerDocumentForCurrentNode();
752 // Only associate the element with the current form if we're creating the ne w element 753 // Only associate the element with the current form if we're creating the ne w element
753 // in a document with a browsing context (rather than in <template> contents ). 754 // in a document with a browsing context (rather than in <template> contents ).
754 HTMLFormElement* form = document.frame() ? m_form.get() : 0; 755 HTMLFormElement* form = document.frame() ? m_form.get() : nullptr;
755 // FIXME: This can't use HTMLConstructionSite::createElement because we 756 // FIXME: This can't use HTMLConstructionSite::createElement because we
756 // have to pass the current form element. We should rework form association 757 // have to pass the current form element. We should rework form association
757 // to occur after construction to allow better code sharing here. 758 // to occur after construction to allow better code sharing here.
758 HTMLElement* element = HTMLElementFactory::createHTMLElement(token->name(), document, form, getCreateElementFlags()); 759 HTMLElement* element = HTMLElementFactory::createHTMLElement(token->name(), document, form, getCreateElementFlags());
759 setAttributes(element, token, m_parserContentPolicy); 760 setAttributes(element, token, m_parserContentPolicy);
760 return element; 761 return element;
761 } 762 }
762 763
763 HTMLStackItem* HTMLConstructionSite::createElementFromSavedToken(HTMLStackItem* item) 764 HTMLStackItem* HTMLConstructionSite::createElementFromSavedToken(HTMLStackItem* item)
764 { 765 {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 queueTask(task); 875 queueTask(task);
875 } 876 }
876 877
877 DEFINE_TRACE(HTMLConstructionSite::PendingText) 878 DEFINE_TRACE(HTMLConstructionSite::PendingText)
878 { 879 {
879 visitor->trace(parent); 880 visitor->trace(parent);
880 visitor->trace(nextChild); 881 visitor->trace(nextChild);
881 } 882 }
882 883
883 } // namespace blink 884 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698