From e384276b0ff6b13b93b515d6d982dda0919885cc Mon Sep 17 00:00:00 2001 From: "akkana%netscape.com" Date: Fri, 28 Jan 2000 01:17:23 +0000 Subject: [PATCH] 22662: Completely redesign the editor output formatting system. Now, instead of inserting text nodes containing whitespace and newlines into the content tree, the editor adds a fake attribute "_moz_dirty" to every node it creates, and relies upon the output system to format any node with that attribute (and, of course, not output the attribute). r=jfrancis git-svn-id: svn://10.0.0.236/trunk@58985 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsHTMLEditor.cpp | 14 +- .../editor/libeditor/html/nsHTMLEditor.cpp | 14 +- .../src/nsHTMLContentSinkStream.cpp | 422 ++++++++++-------- .../htmlparser/src/nsHTMLContentSinkStream.h | 10 +- .../src/nsHTMLContentSinkStream.cpp | 422 ++++++++++-------- .../htmlparser/src/nsHTMLContentSinkStream.h | 10 +- 6 files changed, 520 insertions(+), 372 deletions(-) diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index cb9d58be192..fa54953307e 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -2801,6 +2801,9 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* if (NS_FAILED(res) || !newElement) return NS_ERROR_FAILURE; + // Mark the new element dirty, so it will be formatted + newElement->SetAttribute("_moz_dirty", ""); + // Set default values for new elements if (TagName.Equals("hr")) { @@ -3451,6 +3454,13 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList) NS_IMETHODIMP nsHTMLEditor::InsertFormattingForNode(nsIDOMNode* aNode) { + // New formatting attempt: just mark the node dirty. + nsCOMPtr element (do_QueryInterface(aNode)); + if (element) + element->SetAttribute("_moz_dirty", ""); + return NS_OK; + +#ifdef FORMATTING_NODES_IN_DOM nsresult res; // Don't insert any formatting unless it's an element node @@ -3556,6 +3566,7 @@ nsHTMLEditor::InsertFormattingForNode(nsIDOMNode* aNode) #endif /* DEBUG_formatting */ return res; +#endif // FORMATTING_NODES_IN_DOM } NS_IMETHODIMP @@ -4094,8 +4105,7 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText, newElement->SetAttribute(cite, aCitation); // Set the selection inside the blockquote so aQuotedText will go there: - if (NS_SUCCEEDED(res)) - selection->Collapse(newNode, 0); + selection->Collapse(newNode, 0); } res = InsertHTMLWithCharset(aQuotedText, aCharset); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index cb9d58be192..fa54953307e 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -2801,6 +2801,9 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* if (NS_FAILED(res) || !newElement) return NS_ERROR_FAILURE; + // Mark the new element dirty, so it will be formatted + newElement->SetAttribute("_moz_dirty", ""); + // Set default values for new elements if (TagName.Equals("hr")) { @@ -3451,6 +3454,13 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList) NS_IMETHODIMP nsHTMLEditor::InsertFormattingForNode(nsIDOMNode* aNode) { + // New formatting attempt: just mark the node dirty. + nsCOMPtr element (do_QueryInterface(aNode)); + if (element) + element->SetAttribute("_moz_dirty", ""); + return NS_OK; + +#ifdef FORMATTING_NODES_IN_DOM nsresult res; // Don't insert any formatting unless it's an element node @@ -3556,6 +3566,7 @@ nsHTMLEditor::InsertFormattingForNode(nsIDOMNode* aNode) #endif /* DEBUG_formatting */ return res; +#endif // FORMATTING_NODES_IN_DOM } NS_IMETHODIMP @@ -4094,8 +4105,7 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText, newElement->SetAttribute(cite, aCitation); // Set the selection inside the blockquote so aQuotedText will go there: - if (NS_SUCCEEDED(res)) - selection->Collapse(newNode, 0); + selection->Collapse(newNode, 0); } res = InsertHTMLWithCharset(aQuotedText, aCharset); diff --git a/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp b/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp index 765bc39ebed..0dc23b19cf3 100644 --- a/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp +++ b/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp @@ -58,134 +58,8 @@ static char* gHeaderComment = "