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

Unified Diff: sky/engine/core/html/parser/HTMLConstructionSite.cpp

Issue 867963006: Add the <t> element and ignore whitespace outside it. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Do it for a whole subtree. Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/engine/core/html/parser/HTMLConstructionSite.h ('k') | sky/engine/core/html/parser/HTMLElementStack.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/html/parser/HTMLConstructionSite.cpp
diff --git a/sky/engine/core/html/parser/HTMLConstructionSite.cpp b/sky/engine/core/html/parser/HTMLConstructionSite.cpp
index a0c22a47bb332221afb8f42fa26903f3a8570ba5..1d6c8b1f909d9e94561de838de6ea33551f8dfd5 100644
--- a/sky/engine/core/html/parser/HTMLConstructionSite.cpp
+++ b/sky/engine/core/html/parser/HTMLConstructionSite.cpp
@@ -140,15 +140,6 @@ static unsigned findBreakIndexBetween(const StringBuilder& string, unsigned curr
return 0;
}
-static String atomizeIfAllWhitespace(const String& string, WhitespaceMode whitespaceMode)
-{
- // Strings composed entirely of whitespace are likely to be repeated.
- // Turn them into AtomicString so we share a single string for each.
- if (whitespaceMode == AllWhitespace || (whitespaceMode == WhitespaceUnknown && isAllWhitespace(string)))
- return AtomicString(string).string();
- return string;
-}
-
void HTMLConstructionSite::flushPendingText()
{
if (m_pendingText.isEmpty())
@@ -170,17 +161,28 @@ void HTMLConstructionSite::flushPendingText()
unsigned breakIndex = findBreakIndexBetween(string, currentPosition, proposedBreakIndex);
ASSERT(breakIndex <= string.length());
String substring = string.substring(currentPosition, breakIndex - currentPosition);
- substring = atomizeIfAllWhitespace(substring, pendingText.whitespaceMode);
+
+ ASSERT(breakIndex > currentPosition);
+ ASSERT(breakIndex - currentPosition == substring.length());
+ currentPosition = breakIndex;
+
+ if (isAllWhitespace(substring)) {
+ // Ignore whitespace nodes not inside inside a <t>. If we're splitting
+ // a text node this isn't really a whitespace node and we can't ignore
+ // it either.
+ if (!m_openElements.preserveWhiteSpace() && string.length() == substring.length())
+ continue;
+
+ // Strings composed entirely of whitespace are likely to be repeated.
+ // Turn them into AtomicString so we share a single string for each.
+ substring = AtomicString(substring).string();
+ }
HTMLConstructionSiteTask task(HTMLConstructionSiteTask::InsertText);
task.parent = pendingText.parent;
task.child = Text::create(task.parent->document(), substring);
queueTask(task);
-
- ASSERT(breakIndex > currentPosition);
- ASSERT(breakIndex - currentPosition == substring.length());
ASSERT(toText(task.child.get())->length() == substring.length());
- currentPosition = breakIndex;
}
}
@@ -297,7 +299,7 @@ void HTMLConstructionSite::insertScriptElement(AtomicHTMLToken* token)
m_openElements.push(element.release());
}
-void HTMLConstructionSite::insertTextNode(const String& string, WhitespaceMode whitespaceMode)
+void HTMLConstructionSite::insertTextNode(const String& string)
{
HTMLConstructionSiteTask dummyTask(HTMLConstructionSiteTask::Insert);
dummyTask.parent = currentNode();
@@ -311,7 +313,7 @@ void HTMLConstructionSite::insertTextNode(const String& string, WhitespaceMode w
// pending text into the task queue before making more.
if (!m_pendingText.isEmpty() && (m_pendingText.parent != dummyTask.parent))
flushPendingText();
- m_pendingText.append(dummyTask.parent, string, whitespaceMode);
+ m_pendingText.append(dummyTask.parent, string);
}
PassRefPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLToken* token, const AtomicString& namespaceURI)
« no previous file with comments | « sky/engine/core/html/parser/HTMLConstructionSite.h ('k') | sky/engine/core/html/parser/HTMLElementStack.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698