| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 static String atomizeIfAllWhitespace(const String& string, WhitespaceMode whites
paceMode) | 225 static String atomizeIfAllWhitespace(const String& string, WhitespaceMode whites
paceMode) |
| 226 { | 226 { |
| 227 // Strings composed entirely of whitespace are likely to be repeated. | 227 // Strings composed entirely of whitespace are likely to be repeated. |
| 228 // Turn them into AtomicString so we share a single string for each. | 228 // Turn them into AtomicString so we share a single string for each. |
| 229 if (whitespaceMode == AllWhitespace || (whitespaceMode == WhitespaceUnknown
&& isAllWhitespace(string))) | 229 if (whitespaceMode == AllWhitespace || (whitespaceMode == WhitespaceUnknown
&& isAllWhitespace(string))) |
| 230 return AtomicString(string).string(); | 230 return AtomicString(string).string(); |
| 231 return string; | 231 return string; |
| 232 } | 232 } |
| 233 | 233 |
| 234 void HTMLConstructionSite::flushPendingText() | 234 void HTMLConstructionSite::flushPendingText(FlushMode mode) |
| 235 { | 235 { |
| 236 if (m_pendingText.isEmpty()) | 236 if (m_pendingText.isEmpty()) |
| 237 return; | 237 return; |
| 238 | 238 |
| 239 if (mode == FlushIfAtTextLimit |
| 240 && !shouldUseLengthLimit(*m_pendingText.parent)) |
| 241 return; |
| 242 |
| 239 PendingText pendingText; | 243 PendingText pendingText; |
| 240 // Hold onto the current pending text on the stack so that queueTask doesn't
recurse infinitely. | 244 // Hold onto the current pending text on the stack so that queueTask doesn't
recurse infinitely. |
| 241 m_pendingText.swap(pendingText); | 245 m_pendingText.swap(pendingText); |
| 242 ASSERT(m_pendingText.isEmpty()); | 246 ASSERT(m_pendingText.isEmpty()); |
| 243 | 247 |
| 244 // Splitting text nodes into smaller chunks contradicts HTML5 spec, but is n
ecessary | 248 // Splitting text nodes into smaller chunks contradicts HTML5 spec, but is n
ecessary |
| 245 // for performance, see: https://bugs.webkit.org/show_bug.cgi?id=55898 | 249 // for performance, see: https://bugs.webkit.org/show_bug.cgi?id=55898 |
| 246 unsigned lengthLimit = textLengthLimitForContainer(*pendingText.parent); | 250 unsigned lengthLimit = textLengthLimitForContainer(*pendingText.parent); |
| 247 | 251 |
| 248 unsigned currentPosition = 0; | 252 unsigned currentPosition = 0; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 262 | 266 |
| 263 ASSERT(breakIndex > currentPosition); | 267 ASSERT(breakIndex > currentPosition); |
| 264 ASSERT(breakIndex - currentPosition == substring.length()); | 268 ASSERT(breakIndex - currentPosition == substring.length()); |
| 265 ASSERT(toText(task.child.get())->length() == substring.length()); | 269 ASSERT(toText(task.child.get())->length() == substring.length()); |
| 266 currentPosition = breakIndex; | 270 currentPosition = breakIndex; |
| 267 } | 271 } |
| 268 } | 272 } |
| 269 | 273 |
| 270 void HTMLConstructionSite::queueTask(const HTMLConstructionSiteTask& task) | 274 void HTMLConstructionSite::queueTask(const HTMLConstructionSiteTask& task) |
| 271 { | 275 { |
| 272 flushPendingText(); | 276 flushPendingText(FlushAlways); |
| 273 ASSERT(m_pendingText.isEmpty()); | 277 ASSERT(m_pendingText.isEmpty()); |
| 274 m_taskQueue.append(task); | 278 m_taskQueue.append(task); |
| 275 } | 279 } |
| 276 | 280 |
| 277 void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtrWillBeRa
wPtr<Node> prpChild, bool selfClosing) | 281 void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtrWillBeRa
wPtr<Node> prpChild, bool selfClosing) |
| 278 { | 282 { |
| 279 ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()->
isElementNode() || !toScriptLoaderIfPossible(toElement(prpChild.get()))); | 283 ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()->
isElementNode() || !toScriptLoaderIfPossible(toElement(prpChild.get()))); |
| 280 ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !isHTMLPlugInElement
(prpChild)); | 284 ASSERT(pluginContentIsAllowed(m_parserContentPolicy) || !isHTMLPlugInElement
(prpChild)); |
| 281 | 285 |
| 282 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); | 286 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 return; | 530 return; |
| 527 } | 531 } |
| 528 | 532 |
| 529 // Otherwise we are No Quirks Mode. | 533 // Otherwise we are No Quirks Mode. |
| 530 setCompatibilityMode(Document::NoQuirksMode); | 534 setCompatibilityMode(Document::NoQuirksMode); |
| 531 } | 535 } |
| 532 | 536 |
| 533 void HTMLConstructionSite::processEndOfFile() | 537 void HTMLConstructionSite::processEndOfFile() |
| 534 { | 538 { |
| 535 ASSERT(currentNode()); | 539 ASSERT(currentNode()); |
| 536 flush(); | 540 flush(FlushAlways); |
| 537 openElements()->popAll(); | 541 openElements()->popAll(); |
| 538 } | 542 } |
| 539 | 543 |
| 540 void HTMLConstructionSite::finishedParsing() | 544 void HTMLConstructionSite::finishedParsing() |
| 541 { | 545 { |
| 542 // We shouldn't have any queued tasks but we might have pending text which w
e need to promote to tasks and execute. | 546 // We shouldn't have any queued tasks but we might have pending text which w
e need to promote to tasks and execute. |
| 543 ASSERT(m_taskQueue.isEmpty()); | 547 ASSERT(m_taskQueue.isEmpty()); |
| 544 flush(); | 548 flush(FlushAlways); |
| 545 m_document->finishedParsing(); | 549 m_document->finishedParsing(); |
| 546 } | 550 } |
| 547 | 551 |
| 548 void HTMLConstructionSite::insertDoctype(AtomicHTMLToken* token) | 552 void HTMLConstructionSite::insertDoctype(AtomicHTMLToken* token) |
| 549 { | 553 { |
| 550 ASSERT(token->type() == HTMLToken::DOCTYPE); | 554 ASSERT(token->type() == HTMLToken::DOCTYPE); |
| 551 | 555 |
| 552 const String& publicId = StringImpl::create8BitIfPossible(token->publicIdent
ifier()); | 556 const String& publicId = StringImpl::create8BitIfPossible(token->publicIdent
ifier()); |
| 553 const String& systemId = StringImpl::create8BitIfPossible(token->systemIdent
ifier()); | 557 const String& systemId = StringImpl::create8BitIfPossible(token->systemIdent
ifier()); |
| 554 RefPtrWillBeRawPtr<DocumentType> doctype = DocumentType::create(m_document,
token->name(), publicId, systemId); | 558 RefPtrWillBeRawPtr<DocumentType> doctype = DocumentType::create(m_document,
token->name(), publicId, systemId); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 findFosterSite(dummyTask); | 686 findFosterSite(dummyTask); |
| 683 | 687 |
| 684 // FIXME: This probably doesn't need to be done both here and in insert(Task
). | 688 // FIXME: This probably doesn't need to be done both here and in insert(Task
). |
| 685 if (isHTMLTemplateElement(*dummyTask.parent)) | 689 if (isHTMLTemplateElement(*dummyTask.parent)) |
| 686 dummyTask.parent = toHTMLTemplateElement(dummyTask.parent.get())->conten
t(); | 690 dummyTask.parent = toHTMLTemplateElement(dummyTask.parent.get())->conten
t(); |
| 687 | 691 |
| 688 // Unclear when parent != case occurs. Somehow we insert text into two separ
ate nodes while processing the same Token. | 692 // Unclear when parent != case occurs. Somehow we insert text into two separ
ate nodes while processing the same Token. |
| 689 // The nextChild != dummy.nextChild case occurs whenever foster parenting ha
ppened and we hit a new text node "<table>a</table>b" | 693 // The nextChild != dummy.nextChild case occurs whenever foster parenting ha
ppened and we hit a new text node "<table>a</table>b" |
| 690 // In either case we have to flush the pending text into the task queue befo
re making more. | 694 // In either case we have to flush the pending text into the task queue befo
re making more. |
| 691 if (!m_pendingText.isEmpty() && (m_pendingText.parent != dummyTask.parent ||
m_pendingText.nextChild != dummyTask.nextChild)) | 695 if (!m_pendingText.isEmpty() && (m_pendingText.parent != dummyTask.parent ||
m_pendingText.nextChild != dummyTask.nextChild)) |
| 692 flushPendingText(); | 696 flushPendingText(FlushAlways); |
| 693 m_pendingText.append(dummyTask.parent, dummyTask.nextChild, string, whitespa
ceMode); | 697 m_pendingText.append(dummyTask.parent, dummyTask.nextChild, string, whitespa
ceMode); |
| 694 } | 698 } |
| 695 | 699 |
| 696 void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord* newParent,
HTMLElementStack::ElementRecord* child) | 700 void HTMLConstructionSite::reparent(HTMLElementStack::ElementRecord* newParent,
HTMLElementStack::ElementRecord* child) |
| 697 { | 701 { |
| 698 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent); | 702 HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Reparent); |
| 699 task.parent = newParent->node(); | 703 task.parent = newParent->node(); |
| 700 task.child = child->node(); | 704 task.child = child->node(); |
| 701 queueTask(task); | 705 queueTask(task); |
| 702 } | 706 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 } | 875 } |
| 872 | 876 |
| 873 void HTMLConstructionSite::PendingText::trace(Visitor* visitor) | 877 void HTMLConstructionSite::PendingText::trace(Visitor* visitor) |
| 874 { | 878 { |
| 875 visitor->trace(parent); | 879 visitor->trace(parent); |
| 876 visitor->trace(nextChild); | 880 visitor->trace(nextChild); |
| 877 } | 881 } |
| 878 | 882 |
| 879 | 883 |
| 880 } | 884 } |
| OLD | NEW |