| 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 void HTMLConstructionSite::finishedParsing() | 268 void HTMLConstructionSite::finishedParsing() |
| 269 { | 269 { |
| 270 // We shouldn't have any queued tasks but we might have pending text which w
e need to promote to tasks and execute. | 270 // We shouldn't have any queued tasks but we might have pending text which w
e need to promote to tasks and execute. |
| 271 ASSERT(m_taskQueue.isEmpty()); | 271 ASSERT(m_taskQueue.isEmpty()); |
| 272 flush(); | 272 flush(); |
| 273 m_document->finishedParsing(); | 273 m_document->finishedParsing(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void HTMLConstructionSite::insertHTMLElement(AtomicHTMLToken* token) | 276 void HTMLConstructionSite::insertHTMLElement(AtomicHTMLToken* token) |
| 277 { | 277 { |
| 278 RefPtr<HTMLElement> element = createHTMLElement(token); | 278 RefPtr<Element> element = createElement(token); |
| 279 attachLater(currentNode(), element); | 279 attachLater(currentNode(), element); |
| 280 m_openElements.push(element.release()); | 280 m_openElements.push(element.release()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 void HTMLConstructionSite::insertSelfClosingHTMLElement(AtomicHTMLToken* token) | 283 void HTMLConstructionSite::insertSelfClosingHTMLElement(AtomicHTMLToken* token) |
| 284 { | 284 { |
| 285 ASSERT(token->type() == HTMLToken::StartTag); | 285 ASSERT(token->type() == HTMLToken::StartTag); |
| 286 // Normally HTMLElementStack is responsible for calling finishParsingChildre
n, | 286 // Normally HTMLElementStack is responsible for calling finishParsingChildre
n, |
| 287 // but self-closing elements are never in the element stack so the stack | 287 // but self-closing elements are never in the element stack so the stack |
| 288 // doesn't get a chance to tell them that we're done parsing their children. | 288 // doesn't get a chance to tell them that we're done parsing their children. |
| 289 attachLater(currentNode(), createHTMLElement(token), true); | 289 attachLater(currentNode(), createElement(token), true); |
| 290 // FIXME: Do we want to acknowledge the token's self-closing flag? | 290 // FIXME: Do we want to acknowledge the token's self-closing flag? |
| 291 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.
html#acknowledge-self-closing-flag | 291 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.
html#acknowledge-self-closing-flag |
| 292 } | 292 } |
| 293 | 293 |
| 294 void HTMLConstructionSite::insertScriptElement(AtomicHTMLToken* token) | 294 void HTMLConstructionSite::insertScriptElement(AtomicHTMLToken* token) |
| 295 { | 295 { |
| 296 RefPtr<HTMLScriptElement> element = HTMLScriptElement::create(ownerDocumentF
orCurrentNode()); | 296 RefPtr<HTMLScriptElement> element = HTMLScriptElement::create(ownerDocumentF
orCurrentNode()); |
| 297 setAttributes(element.get(), token); | 297 setAttributes(element.get(), token); |
| 298 attachLater(currentNode(), element); | 298 attachLater(currentNode(), element); |
| 299 m_openElements.push(element.release()); | 299 m_openElements.push(element.release()); |
| 300 } | 300 } |
| 301 | 301 |
| 302 void HTMLConstructionSite::insertTextNode(const String& string) | 302 void HTMLConstructionSite::insertTextNode(const String& string) |
| 303 { | 303 { |
| 304 HTMLConstructionSiteTask dummyTask(HTMLConstructionSiteTask::Insert); | 304 HTMLConstructionSiteTask dummyTask(HTMLConstructionSiteTask::Insert); |
| 305 dummyTask.parent = currentNode(); | 305 dummyTask.parent = currentNode(); |
| 306 | 306 |
| 307 // FIXME: This probably doesn't need to be done both here and in insert(Task
). | 307 // FIXME: This probably doesn't need to be done both here and in insert(Task
). |
| 308 if (isHTMLTemplateElement(*dummyTask.parent)) | 308 if (isHTMLTemplateElement(*dummyTask.parent)) |
| 309 dummyTask.parent = toHTMLTemplateElement(dummyTask.parent.get())->conten
t(); | 309 dummyTask.parent = toHTMLTemplateElement(dummyTask.parent.get())->conten
t(); |
| 310 | 310 |
| 311 // Unclear when parent != case occurs. Somehow we insert text into two separ
ate | 311 // Unclear when parent != case occurs. Somehow we insert text into two separ
ate |
| 312 // nodes while processing the same Token. When it happens we have to flush t
he | 312 // nodes while processing the same Token. When it happens we have to flush t
he |
| 313 // pending text into the task queue before making more. | 313 // pending text into the task queue before making more. |
| 314 if (!m_pendingText.isEmpty() && (m_pendingText.parent != dummyTask.parent)) | 314 if (!m_pendingText.isEmpty() && (m_pendingText.parent != dummyTask.parent)) |
| 315 flushPendingText(); | 315 flushPendingText(); |
| 316 m_pendingText.append(dummyTask.parent, string); | 316 m_pendingText.append(dummyTask.parent, string); |
| 317 } | 317 } |
| 318 | 318 |
| 319 PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token,
const AtomicString& namespaceURI) | |
| 320 { | |
| 321 QualifiedName tagName(token->name()); | |
| 322 RefPtr<Element> element = ownerDocumentForCurrentNode().createElement(tagNam
e, true); | |
| 323 setAttributes(element.get(), token); | |
| 324 return element.release(); | |
| 325 } | |
| 326 | |
| 327 inline Document& HTMLConstructionSite::ownerDocumentForCurrentNode() | 319 inline Document& HTMLConstructionSite::ownerDocumentForCurrentNode() |
| 328 { | 320 { |
| 329 if (isHTMLTemplateElement(*currentNode())) | 321 if (isHTMLTemplateElement(*currentNode())) |
| 330 return toHTMLTemplateElement(currentElement())->content()->document(); | 322 return toHTMLTemplateElement(currentElement())->content()->document(); |
| 331 return currentNode()->document(); | 323 return currentNode()->document(); |
| 332 } | 324 } |
| 333 | 325 |
| 334 PassRefPtr<HTMLElement> HTMLConstructionSite::createHTMLElement(AtomicHTMLToken*
token) | 326 PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token) |
| 335 { | 327 { |
| 336 Document& document = ownerDocumentForCurrentNode(); | 328 Document& document = ownerDocumentForCurrentNode(); |
| 337 RefPtr<HTMLElement> element = HTMLElementFactory::createHTMLElement(token->n
ame(), document, true); | 329 RefPtr<Element> element = HTMLElementFactory::createElement(token->name(), d
ocument, true); |
| 338 setAttributes(element.get(), token); | 330 setAttributes(element.get(), token); |
| 339 return element.release(); | 331 return element.release(); |
| 340 } | 332 } |
| 341 | 333 |
| 342 } | 334 } |
| OLD | NEW |