[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

abarth at webkit.org abarth at webkit.org
Wed Dec 22 13:10:31 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit ca990ec10bf5e80d4c80d36242f9c761c968433f
Author: abarth at webkit.org <abarth at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Sep 8 08:52:17 2010 +0000

    2010-09-08  Adam Barth  <abarth at webkit.org>
    
            Reviewed by Eric Seidel.
    
            TextDocument should come in from the cold
            https://bugs.webkit.org/show_bug.cgi?id=45334
    
            Previously, TextDocument reinvented the wheel to parse text.  This
            patch replaces TextDocument's hand-rolled parser with a parser built on
            the HTML parser infrustructure, which gives us that stuff for free.  I
            also disentangled TextDocument from HTMLViewSourceDocument.
    
            In a future patch, I'll move TextDocument out of the "loader" directory.
    
            * Android.mk:
            * CMakeLists.txt:
            * GNUmakefile.am:
            * WebCore.gypi:
            * WebCore.pro:
            * WebCore.vcproj/WebCore.vcproj:
            * WebCore.xcodeproj/project.pbxproj:
            * html/HTMLViewSourceDocument.cpp:
            (WebCore::HTMLViewSourceDocument::createParser):
            * html/HTMLViewSourceDocument.h:
            * html/parser/HTMLTreeBuilder.cpp:
            (WebCore::HTMLTreeBuilder::constructTreeFromToken):
            (WebCore::HTMLTreeBuilder::constructTreeFromAtomicToken):
            * html/parser/HTMLTreeBuilder.h:
            * html/parser/HTMLViewSourceParser.cpp:
            (WebCore::HTMLViewSourceParser::forcePlaintext):
            * html/parser/HTMLViewSourceParser.h:
            * html/parser/TextDocumentParser.cpp: Added.
            (WebCore::TextDocumentParser::TextDocumentParser):
            (WebCore::TextDocumentParser::~TextDocumentParser):
            (WebCore::TextDocumentParser::insertFakePreElement):
            * html/parser/TextDocumentParser.h: Added.
            (WebCore::TextDocumentParser::create):
            * loader/TextDocument.cpp:
            * loader/TextDocument.h:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66957 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/Android.mk b/WebCore/Android.mk
index 4097823..8bd67d2 100644
--- a/WebCore/Android.mk
+++ b/WebCore/Android.mk
@@ -301,6 +301,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
 	html/parser/HTMLTokenizer.cpp \
 	html/parser/HTMLTreeBuilder.cpp \
 	html/parser/HTMLViewSourceParser.cpp \
+	html/parser/TextDocumentParser.cpp \
 	\
 	loader/Cache.cpp \
 	loader/CachedCSSStyleSheet.cpp \
diff --git a/WebCore/CMakeLists.txt b/WebCore/CMakeLists.txt
index a933a92..4249635 100644
--- a/WebCore/CMakeLists.txt
+++ b/WebCore/CMakeLists.txt
@@ -1047,6 +1047,7 @@ SET(WebCore_SOURCES
     html/parser/HTMLTokenizer.cpp
     html/parser/HTMLTreeBuilder.cpp
     html/parser/HTMLViewSourceParser.cpp
+    html/parser/TextDocumentParser.cpp
 
     inspector/ConsoleMessage.cpp
     inspector/InjectedScript.cpp
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 8947cfd..c330ad7 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,43 @@
+2010-09-08  Adam Barth  <abarth at webkit.org>
+
+        Reviewed by Eric Seidel.
+
+        TextDocument should come in from the cold
+        https://bugs.webkit.org/show_bug.cgi?id=45334
+
+        Previously, TextDocument reinvented the wheel to parse text.  This
+        patch replaces TextDocument's hand-rolled parser with a parser built on
+        the HTML parser infrustructure, which gives us that stuff for free.  I
+        also disentangled TextDocument from HTMLViewSourceDocument.
+
+        In a future patch, I'll move TextDocument out of the "loader" directory.
+
+        * Android.mk:
+        * CMakeLists.txt:
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/HTMLViewSourceDocument.cpp:
+        (WebCore::HTMLViewSourceDocument::createParser):
+        * html/HTMLViewSourceDocument.h:
+        * html/parser/HTMLTreeBuilder.cpp:
+        (WebCore::HTMLTreeBuilder::constructTreeFromToken):
+        (WebCore::HTMLTreeBuilder::constructTreeFromAtomicToken):
+        * html/parser/HTMLTreeBuilder.h:
+        * html/parser/HTMLViewSourceParser.cpp:
+        (WebCore::HTMLViewSourceParser::forcePlaintext):
+        * html/parser/HTMLViewSourceParser.h:
+        * html/parser/TextDocumentParser.cpp: Added.
+        (WebCore::TextDocumentParser::TextDocumentParser):
+        (WebCore::TextDocumentParser::~TextDocumentParser):
+        (WebCore::TextDocumentParser::insertFakePreElement):
+        * html/parser/TextDocumentParser.h: Added.
+        (WebCore::TextDocumentParser::create):
+        * loader/TextDocument.cpp:
+        * loader/TextDocument.h:
+
 2010-09-06  Tor Arne Vestbø  <tor.arne.vestbo at nokia.com>
 
         Reviewed by Andreas Kling.
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index 1caaa95..1e896c7 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -1569,6 +1569,8 @@ webcore_sources += \
 	WebCore/html/parser/HTMLTreeBuilder.h \
 	WebCore/html/parser/HTMLViewSourceParser.cpp \
 	WebCore/html/parser/HTMLViewSourceParser.h \
+	WebCore/html/parser/TextDocumentParser.cpp \
+	WebCore/html/parser/TextDocumentParser.h \
 	WebCore/html/ValidityState.cpp \
 	WebCore/html/ValidityState.h \
 	WebCore/html/VoidCallback.h \
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index 4b76a2a..a8f4574 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -1778,6 +1778,8 @@
             'html/parser/HTMLTreeBuilder.h',
             'html/parser/HTMLViewSourceParser.cpp',
             'html/parser/HTMLViewSourceParser.h',
+            'html/parser/TextDocumentParser.cpp',
+            'html/parser/TextDocumentParser.h',
             'inspector/InspectorClient.h',
             'inspector/ConsoleMessage.cpp',
             'inspector/ConsoleMessage.h',
diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index 1abaac3..4c263ae 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -751,6 +751,7 @@ SOURCES += \
     html/parser/HTMLTokenizer.cpp \
     html/parser/HTMLTreeBuilder.cpp \
     html/parser/HTMLViewSourceParser.cpp \
+    html/parser/TextDocumentParser.cpp \
     inspector/ConsoleMessage.cpp \
     inspector/InjectedScript.cpp \
     inspector/InjectedScriptHost.cpp \
diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj
index c931ddc..d39f650 100644
--- a/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -41971,6 +41971,14 @@
                     RelativePath="..\html\parser\HTMLViewSourceParser.h"
                     >
                 </File>
+                <File
+                    RelativePath="..\html\parser\TextDocumentParser.cpp"
+                    >
+                </File>
+                <File
+                    RelativePath="..\html\parser\TextDocumentParser.h"
+                    >
+                </File>
             </Filter>
 			<File
 				RelativePath="..\html\StepRange.cpp"
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index b1b9eea..5ac3c98 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -2787,6 +2787,8 @@
 		977B387A122883E900B81FF8 /* HTMLViewSourceParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 977B3861122883E900B81FF8 /* HTMLViewSourceParser.h */; };
 		979F43D31075E44A0000F83B /* RedirectScheduler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 979F43D11075E44A0000F83B /* RedirectScheduler.cpp */; };
 		979F43D41075E44A0000F83B /* RedirectScheduler.h in Headers */ = {isa = PBXBuildFile; fileRef = 979F43D21075E44A0000F83B /* RedirectScheduler.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		97BC84831236FD93000C6161 /* TextDocumentParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97BC84811236FD93000C6161 /* TextDocumentParser.cpp */; };
+		97BC84841236FD93000C6161 /* TextDocumentParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 97BC84821236FD93000C6161 /* TextDocumentParser.h */; };
 		97C078501165D5BE003A32EF /* SuffixTree.h in Headers */ = {isa = PBXBuildFile; fileRef = 97C0784F1165D5BE003A32EF /* SuffixTree.h */; };
 		97DCE20110807C750057D394 /* HistoryController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97DCE1FF10807C750057D394 /* HistoryController.cpp */; };
 		97DCE20210807C750057D394 /* HistoryController.h in Headers */ = {isa = PBXBuildFile; fileRef = 97DCE20010807C750057D394 /* HistoryController.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -8655,6 +8657,8 @@
 		977B3861122883E900B81FF8 /* HTMLViewSourceParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HTMLViewSourceParser.h; path = parser/HTMLViewSourceParser.h; sourceTree = "<group>"; };
 		979F43D11075E44A0000F83B /* RedirectScheduler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RedirectScheduler.cpp; sourceTree = "<group>"; };
 		979F43D21075E44A0000F83B /* RedirectScheduler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RedirectScheduler.h; sourceTree = "<group>"; };
+		97BC84811236FD93000C6161 /* TextDocumentParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TextDocumentParser.cpp; path = parser/TextDocumentParser.cpp; sourceTree = "<group>"; };
+		97BC84821236FD93000C6161 /* TextDocumentParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TextDocumentParser.h; path = parser/TextDocumentParser.h; sourceTree = "<group>"; };
 		97C0784F1165D5BE003A32EF /* SuffixTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SuffixTree.h; sourceTree = "<group>"; };
 		97C1F552122855CB00EDE616 /* HTMLToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HTMLToken.h; path = parser/HTMLToken.h; sourceTree = "<group>"; };
 		97DCE1FF10807C750057D394 /* HistoryController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HistoryController.cpp; sourceTree = "<group>"; };
@@ -14436,6 +14440,8 @@
 				977B37221228721700B81FF8 /* HTMLTreeBuilder.h */,
 				977B3860122883E900B81FF8 /* HTMLViewSourceParser.cpp */,
 				977B3861122883E900B81FF8 /* HTMLViewSourceParser.h */,
+				97BC84811236FD93000C6161 /* TextDocumentParser.cpp */,
+				97BC84821236FD93000C6161 /* TextDocumentParser.h */,
 			);
 			name = parser;
 			sourceTree = "<group>";
@@ -20443,6 +20449,7 @@
 				898785F1122E1E87003AABDA /* JSFileException.h in Headers */,
 				898785F5122E1EAC003AABDA /* JSFileReaderSync.h in Headers */,
 				BCDD454E1236C95C009A7985 /* ColumnInfo.h in Headers */,
+				97BC84841236FD93000C6161 /* TextDocumentParser.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -22907,6 +22914,7 @@
 				898785B8122CA2A7003AABDA /* JSMetadataCallback.cpp in Sources */,
 				898785F0122E1E87003AABDA /* JSFileException.cpp in Sources */,
 				898785F4122E1EAC003AABDA /* JSFileReaderSync.cpp in Sources */,
+				97BC84831236FD93000C6161 /* TextDocumentParser.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/WebCore/html/HTMLViewSourceDocument.cpp b/WebCore/html/HTMLViewSourceDocument.cpp
index 3299b27..cad8134 100644
--- a/WebCore/html/HTMLViewSourceDocument.cpp
+++ b/WebCore/html/HTMLViewSourceDocument.cpp
@@ -58,15 +58,17 @@ HTMLViewSourceDocument::HTMLViewSourceDocument(Frame* frame, const KURL& url, co
 
 PassRefPtr<DocumentParser> HTMLViewSourceDocument::createParser()
 {
+    RefPtr<HTMLViewSourceParser> parser = HTMLViewSourceParser::create(this);
     // Use HTMLDocumentParser if applicable, otherwise use TextDocumentParser.
     if (m_type == "text/html" || m_type == "application/xhtml+xml" || m_type == "image/svg+xml" || DOMImplementation::isXMLMIMEType(m_type)
 #if ENABLE(XHTMLMP)
         || m_type == "application/vnd.wap.xhtml+xml"
 #endif
         )
-        return HTMLViewSourceParser::create(this);
+        return parser.release();
 
-    return createTextDocumentParser(this);
+    parser->forcePlaintext();
+    return parser.release();
 }
 
 void HTMLViewSourceDocument::createContainingTable()
@@ -96,13 +98,6 @@ void HTMLViewSourceDocument::createContainingTable()
     m_current = m_tbody;
 }
 
-void HTMLViewSourceDocument::addViewSourceText(const String& text)
-{
-    if (!m_current)
-        createContainingTable();
-    addText(text, "");
-}
-
 void HTMLViewSourceDocument::addSource(const String& source, HTMLToken& token)
 {
     if (!m_current)
diff --git a/WebCore/html/HTMLViewSourceDocument.h b/WebCore/html/HTMLViewSourceDocument.h
index 445c95b..30e4df3 100644
--- a/WebCore/html/HTMLViewSourceDocument.h
+++ b/WebCore/html/HTMLViewSourceDocument.h
@@ -42,9 +42,6 @@ public:
 
     void addSource(const String&, HTMLToken&);
 
-    void addViewSourceToken(HTMLToken&); // Used by the HTMLDocumentParser.
-    void addViewSourceText(const String&); // Used by the TextDocumentParser.
-
 private:
     HTMLViewSourceDocument(Frame*, const KURL&, const String& mimeType);
 
diff --git a/WebCore/html/parser/HTMLDocumentParser.h b/WebCore/html/parser/HTMLDocumentParser.h
index 0e508da..6d5b6d7 100644
--- a/WebCore/html/parser/HTMLDocumentParser.h
+++ b/WebCore/html/parser/HTMLDocumentParser.h
@@ -69,16 +69,19 @@ public:
 
 protected:
     virtual void insert(const SegmentedString&);
+    virtual void append(const SegmentedString&);
     virtual void finish();
 
     HTMLDocumentParser(HTMLDocument*, bool reportErrors);
     HTMLDocumentParser(DocumentFragment*, Element* contextElement, FragmentScriptingPermission);
 
+    HTMLTokenizer* tokenizer() const { return m_tokenizer.get(); }
+    HTMLTreeBuilder* treeBuilder() const { return m_treeBuilder.get(); }
+
 private:
     // DocumentParser
     virtual void detach();
     virtual bool hasInsertionPoint();
-    virtual void append(const SegmentedString&);
     virtual bool finishWasCalled();
     virtual bool processingData() const;
     virtual void prepareToStopParsing();
diff --git a/WebCore/html/parser/HTMLTreeBuilder.cpp b/WebCore/html/parser/HTMLTreeBuilder.cpp
index 8c76fc0..406bb6c 100644
--- a/WebCore/html/parser/HTMLTreeBuilder.cpp
+++ b/WebCore/html/parser/HTMLTreeBuilder.cpp
@@ -463,6 +463,11 @@ HTMLTokenizer::State HTMLTreeBuilder::adjustedLexerState(HTMLTokenizer::State st
 void HTMLTreeBuilder::constructTreeFromToken(HTMLToken& rawToken)
 {
     AtomicHTMLToken token(rawToken);
+    constructTreeFromAtomicToken(token);
+}
+
+void HTMLTreeBuilder::constructTreeFromAtomicToken(AtomicHTMLToken& token)
+{
     processToken(token);
 
     // Swallowing U+0000 characters isn't in the HTML5 spec, but turning all
diff --git a/WebCore/html/parser/HTMLTreeBuilder.h b/WebCore/html/parser/HTMLTreeBuilder.h
index c30e6b8..4634f0a 100644
--- a/WebCore/html/parser/HTMLTreeBuilder.h
+++ b/WebCore/html/parser/HTMLTreeBuilder.h
@@ -68,6 +68,8 @@ public:
 
     // The token really should be passed as a const& since it's never modified.
     void constructTreeFromToken(HTMLToken&);
+    void constructTreeFromAtomicToken(AtomicHTMLToken&);
+
     // Must be called when parser is paused before calling the parser again.
     PassRefPtr<Element> takeScriptToProcess(int& scriptStartLine);
 
diff --git a/WebCore/html/parser/HTMLViewSourceParser.cpp b/WebCore/html/parser/HTMLViewSourceParser.cpp
index 8a7984d..4aac955 100644
--- a/WebCore/html/parser/HTMLViewSourceParser.cpp
+++ b/WebCore/html/parser/HTMLViewSourceParser.cpp
@@ -42,6 +42,11 @@ HTMLViewSourceParser::~HTMLViewSourceParser()
 {
 }
 
+void HTMLViewSourceParser::forcePlaintext()
+{
+    m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState);
+}
+
 void HTMLViewSourceParser::insert(const SegmentedString&)
 {
     ASSERT_NOT_REACHED();
diff --git a/WebCore/html/parser/HTMLViewSourceParser.h b/WebCore/html/parser/HTMLViewSourceParser.h
index 34caf43..28f05ec 100644
--- a/WebCore/html/parser/HTMLViewSourceParser.h
+++ b/WebCore/html/parser/HTMLViewSourceParser.h
@@ -50,6 +50,8 @@ public:
     }
     virtual ~HTMLViewSourceParser();
 
+    void forcePlaintext();
+
 private:
     HTMLViewSourceParser(HTMLViewSourceDocument*);
 
diff --git a/WebCore/html/parser/TextDocumentParser.cpp b/WebCore/html/parser/TextDocumentParser.cpp
new file mode 100644
index 0000000..d03b744
--- /dev/null
+++ b/WebCore/html/parser/TextDocumentParser.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TextDocumentParser.h"
+
+#include "HTMLDocument.h"
+#include "HTMLNames.h"
+#include "HTMLTokenizer.h"
+#include "HTMLTreeBuilder.h"
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+TextDocumentParser::TextDocumentParser(HTMLDocument* document)
+    : HTMLDocumentParser(document, false)
+    , m_haveInsertedFakePreElement(false)
+{
+    tokenizer()->setState(HTMLTokenizer::PLAINTEXTState);
+}
+
+TextDocumentParser::~TextDocumentParser()
+{
+}
+
+void TextDocumentParser::append(const SegmentedString& text)
+{
+    if (!m_haveInsertedFakePreElement)
+        insertFakePreElement();
+    HTMLDocumentParser::append(text);
+}
+
+void TextDocumentParser::insertFakePreElement()
+{
+    // In principle, we should create a specialized tree builder for
+    // TextDocuments, but instead we re-use the existing HTMLTreeBuilder.
+    // We create a fake token and give it to the tree builder rather than
+    // sending fake bytes through the front-end of the parser to avoid
+    // distrubing the line/column number calculations.
+
+    RefPtr<Attribute> styleAttribute = Attribute::createMapped("style", "word-wrap: break-word; white-space: pre-wrap;");
+    RefPtr<NamedNodeMap> attributes = NamedNodeMap::create();
+    attributes->insertAttribute(styleAttribute.release(), false);
+    AtomicHTMLToken fakePre(HTMLToken::StartTag, preTag.localName(), attributes.release());
+
+    treeBuilder()->constructTreeFromAtomicToken(fakePre);
+    m_haveInsertedFakePreElement = true;
+}
+
+}
diff --git a/WebCore/html/parser/TextDocumentParser.h b/WebCore/html/parser/TextDocumentParser.h
new file mode 100644
index 0000000..1cccc5b
--- /dev/null
+++ b/WebCore/html/parser/TextDocumentParser.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef TextDocumentParser_h
+#define TextDocumentParser_h
+
+#include "HTMLDocumentParser.h"
+
+namespace WebCore {
+
+class TextDocumentParser : public HTMLDocumentParser {
+public:
+    static PassRefPtr<TextDocumentParser> create(HTMLDocument* document)
+    {
+        return adoptRef(new TextDocumentParser(document));
+    }
+    virtual ~TextDocumentParser();
+
+private:
+    explicit TextDocumentParser(HTMLDocument*);
+
+    virtual void append(const SegmentedString&);
+    void insertFakePreElement();
+
+    bool m_haveInsertedFakePreElement;
+};
+
+}
+
+#endif
diff --git a/WebCore/loader/TextDocument.cpp b/WebCore/loader/TextDocument.cpp
index 4b09a9e..9334a39 100644
--- a/WebCore/loader/TextDocument.cpp
+++ b/WebCore/loader/TextDocument.cpp
@@ -19,186 +19,16 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
 #include "TextDocument.h"
 
-#include "DecodedDataDocumentParser.h"
-#include "Element.h"
-#include "HTMLNames.h"
-#include "HTMLViewSourceDocument.h"
-#include "SegmentedString.h"
-#include "Text.h"
-
-using namespace std;
+#include "TextDocumentParser.h"
 
 namespace WebCore {
 
-using namespace HTMLNames;
-
-// FIXME: TextDocumentParser could just be an HTMLDocumentParser
-// which started the Tokenizer in the PlainText state.
-class TextDocumentParser : public DecodedDataDocumentParser {
-public:
-    static PassRefPtr<TextDocumentParser> create(Document* document)
-    {
-        return adoptRef(new TextDocumentParser(document));
-    }
-
-    static PassRefPtr<TextDocumentParser> create(HTMLViewSourceDocument* document)
-    {
-        return adoptRef(new TextDocumentParser(document));
-    }
-
-    virtual ~TextDocumentParser();
-    
-private:
-    TextDocumentParser(Document*);
-    TextDocumentParser(HTMLViewSourceDocument*);
-
-    virtual void insert(const SegmentedString&);
-    virtual void append(const SegmentedString&);
-    virtual void finish();
-    virtual bool finishWasCalled();
-
-    inline void checkBuffer(int len = 10)
-    {
-        if ((m_dest - m_buffer) > m_size - len) {
-            // Enlarge buffer
-            int newSize = std::max(m_size * 2, m_size + len);
-            int oldOffset = m_dest - m_buffer;
-            m_buffer = static_cast<UChar*>(fastRealloc(m_buffer, newSize * sizeof(UChar)));
-            m_dest = m_buffer + oldOffset;
-            m_size = newSize;
-        }
-    }
-
-private:
-    Element* m_preElement;
-
-    bool m_skipLF;
-    
-    int m_size;
-    UChar* m_buffer;
-    UChar* m_dest;
-};
-
-TextDocumentParser::TextDocumentParser(Document* document)
-    : DecodedDataDocumentParser(document)
-    , m_preElement(0)
-    , m_skipLF(false)
-{    
-    // Allocate buffer
-    m_size = 254;
-    m_buffer = static_cast<UChar*>(fastMalloc(sizeof(UChar) * m_size));
-    m_dest = m_buffer;
-}    
-
-TextDocumentParser::TextDocumentParser(HTMLViewSourceDocument* document)
-    : DecodedDataDocumentParser(document, true)
-    , m_preElement(0)
-    , m_skipLF(false)
-{    
-    // Allocate buffer
-    m_size = 254;
-    m_buffer = static_cast<UChar*>(fastMalloc(sizeof(UChar) * m_size));
-    m_dest = m_buffer;
-}
-
-TextDocumentParser::~TextDocumentParser()
-{
-    // finish() should have been called to prevent any leaks
-    ASSERT(!m_buffer);
-}
-
-void TextDocumentParser::insert(const SegmentedString&)
-{
-    ASSERT_NOT_REACHED();
-}
-
-void TextDocumentParser::append(const SegmentedString& s)
-{
-    ExceptionCode ec;
-
-    m_dest = m_buffer;
-    
-    SegmentedString str = s;
-    while (!str.isEmpty()) {
-        UChar c = *str;
-        
-        if (c == '\r') {
-            *m_dest++ = '\n';
-            
-            // possibly skip an LF in the case of an CRLF sequence
-            m_skipLF = true;
-        } else if (c == '\n') {
-            if (!m_skipLF)
-                *m_dest++ = c;
-            else
-                m_skipLF = false;
-        } else {
-            *m_dest++ = c;
-            m_skipLF = false;
-        }
-        
-        str.advance();
-        
-        // Maybe enlarge the buffer
-        checkBuffer();
-    }
-
-    if (!m_preElement && !inViewSourceMode()) {
-        RefPtr<Element> rootElement = document()->createElement(htmlTag, false);
-        document()->appendChild(rootElement, ec);
-
-        RefPtr<Element> body = document()->createElement(bodyTag, false);
-        rootElement->appendChild(body, ec);
-
-        RefPtr<Element> preElement = document()->createElement(preTag, false);
-        preElement->setAttribute("style", "word-wrap: break-word; white-space: pre-wrap;", ec);
-
-        body->appendChild(preElement, ec);
-        
-        m_preElement = preElement.get();
-    } 
-    
-    String string = String(m_buffer, m_dest - m_buffer);
-    if (inViewSourceMode()) {
-        static_cast<HTMLViewSourceDocument*>(document())->addViewSourceText(string);
-        return;
-    }
-
-    unsigned charsLeft = string.length();
-    while (charsLeft) {
-        // split large text to nodes of manageable size
-        RefPtr<Text> text = Text::createWithLengthLimit(document(), string, charsLeft);
-        m_preElement->appendChild(text, ec);
-    }
-}
-
-void TextDocumentParser::finish()
-{
-    if (!m_preElement)
-        append(SegmentedString()); // Create document structure for an empty text document.
-    m_preElement = 0;
-    fastFree(m_buffer);
-    m_buffer = 0;
-    m_dest = 0;
-
-    // FIXME: Should this call finishParsing even if m_parserStopped is true?
-    // See equivalent implementation in RawDataDocumentParser.
-    document()->finishedParsing();
-}
-
-bool TextDocumentParser::finishWasCalled()
-{
-    // finish() always calls document()->finishedParsing() so we'll be deleted
-    // after finish().
-    return false;
-}
-
 TextDocument::TextDocument(Frame* frame, const KURL& url)
     : HTMLDocument(frame, url)
 {
@@ -211,9 +41,4 @@ PassRefPtr<DocumentParser> TextDocument::createParser()
     return TextDocumentParser::create(this);
 }
 
-PassRefPtr<DocumentParser> createTextDocumentParser(HTMLViewSourceDocument* document)
-{
-    return TextDocumentParser::create(document);
-}
-
 }
diff --git a/WebCore/loader/TextDocument.h b/WebCore/loader/TextDocument.h
index d5bf153..2ea49f8 100644
--- a/WebCore/loader/TextDocument.h
+++ b/WebCore/loader/TextDocument.h
@@ -29,8 +29,6 @@
 
 namespace WebCore {
 
-class HTMLViewSourceDocument;
-
 class TextDocument : public HTMLDocument {
 public:
     static PassRefPtr<TextDocument> create(Frame* frame, const KURL& url)
@@ -44,8 +42,6 @@ private:
     virtual PassRefPtr<DocumentParser> createParser();
 };
 
-PassRefPtr<DocumentParser> createTextDocumentParser(HTMLViewSourceDocument*);
-
 }
 
-#endif // TextDocument_h
+#endif

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list