From f00af5f8c4975c141d3448107d063761ecac5a57 Mon Sep 17 00:00:00 2001 From: "akkana%netscape.com" Date: Tue, 30 May 2000 23:11:49 +0000 Subject: [PATCH] 39508: Use an int rather than a boolean to keep track of preformatting level, so that we don't get confused about when to output
vs newline. 41017: Add as an inline tag (a=beppe). r=jfrancis. git-svn-id: svn://10.0.0.236/trunk@71106 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/nsHTMLContentSinkStream.cpp | 35 +++++++++---------- .../htmlparser/src/nsHTMLContentSinkStream.h | 2 +- .../src/nsHTMLContentSinkStream.cpp | 35 +++++++++---------- .../htmlparser/src/nsHTMLContentSinkStream.h | 2 +- 4 files changed, 34 insertions(+), 40 deletions(-) diff --git a/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp b/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp index 6638d349d39..737fb566968 100644 --- a/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp +++ b/mozilla/htmlparser/src/nsHTMLContentSinkStream.cpp @@ -149,7 +149,7 @@ nsHTMLContentSinkStream::Initialize(nsIOutputStream* aOutStream, if (aCharsetOverride != nsnull) mCharsetOverride.AssignWithConversion(aCharsetOverride->GetUnicode()); - mInPre = PR_FALSE; + mPreLevel = 0; return NS_OK; } @@ -631,7 +631,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode) // too long for news servers (and some mail servers) to handle. // So we map all
tags inside
 to line breaks.
   // If this turns out to be a problem, we could do this only if gMozDirty.
-  else if (tag == eHTMLTag_br && mInPre)
+  else if (tag == eHTMLTag_br && mPreLevel > 0)
   {
     Write(NS_LINEBREAK);
     return;
@@ -652,12 +652,13 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode)
            BreakAfterClose(tag));
 #endif
 
-  if ((mDoFormat || isDirty) && !mInPre && mColPos != 0 && BreakBeforeOpen(tag))
+  if ((mDoFormat || isDirty) && mPreLevel == 0 && mColPos != 0
+      && BreakBeforeOpen(tag))
   {
     Write(NS_LINEBREAK);
     mColPos = 0;
   }
-  if ((mDoFormat || isDirty) && !mInPre && mColPos == 0)
+  if ((mDoFormat || isDirty) && mPreLevel == 0 && mColPos == 0)
     AddIndent();
 
   EnsureBufferSize(tagName.Length() + 1);
@@ -668,7 +669,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode)
 
   mColPos += 1 + tagName.Length();
 
-  if ((mDoFormat || isDirty) && !mInPre && tag == eHTMLTag_style)
+  if ((mDoFormat || isDirty) && mPreLevel == 0 && tag == eHTMLTag_style)
   {
     Write(kGreaterThan);
     Write(NS_LINEBREAK);
@@ -689,9 +690,9 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode)
   }
 
   if (tag == eHTMLTag_pre)
-    mInPre = PR_TRUE;
+    ++mPreLevel;
 
-  if (((mDoFormat || isDirty) && !mInPre && BreakAfterOpen(tag)))
+  if (((mDoFormat || isDirty) && mPreLevel == 0 && BreakAfterOpen(tag)))
   {
     Write(NS_LINEBREAK);
     mColPos = 0;
@@ -734,12 +735,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode)
   }
   else if (tag == eHTMLTag_pre)
   {
-    mInPre = PR_FALSE;  // we think we can clear the flag now
-    for (PRInt32 i = mHTMLStackPos-1; i >= 0; i--)
-    {
-      if (mHTMLTagStack[i] == eHTMLTag_pre)   // oops! Nested pre, still need flag
-        mInPre = PR_TRUE;
-    }
+    --mPreLevel;
     tagName.Assign(aNode.GetText());
   }
   else if (tag == eHTMLTag_comment)
@@ -768,7 +764,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode)
   if (IndentChildren(tag))
     mIndent--;
 
-  if ((mDoFormat || isDirty) && !mInPre && BreakBeforeClose(tag))
+  if ((mDoFormat || isDirty) && mPreLevel == 0 && BreakBeforeClose(tag))
   {
     if (mColPos != 0)
     {
@@ -776,7 +772,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode)
       mColPos = 0;
     }
   }
-  if ((mDoFormat || isDirty) && !mInPre && mColPos == 0)
+  if ((mDoFormat || isDirty) && mPreLevel == 0 && mColPos == 0)
     AddIndent();
 
   EnsureBufferSize(tagName.Length() + 1);
@@ -797,7 +793,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode)
   if (tag == eHTMLTag_body)
     mInBody = PR_FALSE;
 
-  if (((mDoFormat || isDirty) && !mInPre && BreakAfterClose(tag))
+  if (((mDoFormat || isDirty) && mPreLevel == 0 && BreakAfterClose(tag))
       || tag == eHTMLTag_body || tag == eHTMLTag_html)
   {
     Write(NS_LINEBREAK);
@@ -843,7 +839,7 @@ nsHTMLContentSinkStream::AddLeaf(const nsIParserNode& aNode)
       return NS_OK;
 
     const nsString& text = aNode.GetText();
-    if (mInPre)
+    if (mPreLevel > 0)
     {
       Write(text);
       mColPos += text.Length();
@@ -867,7 +863,7 @@ nsHTMLContentSinkStream::AddLeaf(const nsIParserNode& aNode)
   }
   else if (type == eHTMLTag_whitespace)
   {
-    if (!mDoFormat || mInPre)
+    if (!mDoFormat || mPreLevel > 0)
     {
       const nsString& text = aNode.GetText();
       Write(text);
@@ -876,7 +872,7 @@ nsHTMLContentSinkStream::AddLeaf(const nsIParserNode& aNode)
   }
   else if (type == eHTMLTag_newline)
   {
-    if (!mDoFormat || mInPre)
+    if (!mDoFormat || mPreLevel > 0)
     {
       Write(NS_LINEBREAK);
       mColPos = 0;
@@ -1181,6 +1177,7 @@ static PRBool IsInline(eHTMLTags aTag)
     case  eHTMLTag_sup:
     case  eHTMLTag_textarea:
     case  eHTMLTag_tt:
+    case  eHTMLTag_u:
     case  eHTMLTag_var:
     case  eHTMLTag_wbr:
       result = PR_TRUE;
diff --git a/mozilla/htmlparser/src/nsHTMLContentSinkStream.h b/mozilla/htmlparser/src/nsHTMLContentSinkStream.h
index d20302fe2b2..cec9fdb8c05 100644
--- a/mozilla/htmlparser/src/nsHTMLContentSinkStream.h
+++ b/mozilla/htmlparser/src/nsHTMLContentSinkStream.h
@@ -192,7 +192,7 @@ protected:
     PRBool    mDoHeader;
     PRBool    mBodyOnly;
     PRBool    mHasOpenHtmlTag;
-    PRBool    mInPre;
+    PRInt32   mPreLevel;
 
     PRInt32   mMaxColumn;
 
diff --git a/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.cpp b/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.cpp
index 6638d349d39..737fb566968 100644
--- a/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.cpp
+++ b/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.cpp
@@ -149,7 +149,7 @@ nsHTMLContentSinkStream::Initialize(nsIOutputStream* aOutStream,
   if (aCharsetOverride != nsnull)
     mCharsetOverride.AssignWithConversion(aCharsetOverride->GetUnicode());
 
-  mInPre = PR_FALSE;
+  mPreLevel = 0;
 
   return NS_OK;
 }
@@ -631,7 +631,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode)
   // too long for news servers (and some mail servers) to handle.
   // So we map all 
tags inside
 to line breaks.
   // If this turns out to be a problem, we could do this only if gMozDirty.
-  else if (tag == eHTMLTag_br && mInPre)
+  else if (tag == eHTMLTag_br && mPreLevel > 0)
   {
     Write(NS_LINEBREAK);
     return;
@@ -652,12 +652,13 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode)
            BreakAfterClose(tag));
 #endif
 
-  if ((mDoFormat || isDirty) && !mInPre && mColPos != 0 && BreakBeforeOpen(tag))
+  if ((mDoFormat || isDirty) && mPreLevel == 0 && mColPos != 0
+      && BreakBeforeOpen(tag))
   {
     Write(NS_LINEBREAK);
     mColPos = 0;
   }
-  if ((mDoFormat || isDirty) && !mInPre && mColPos == 0)
+  if ((mDoFormat || isDirty) && mPreLevel == 0 && mColPos == 0)
     AddIndent();
 
   EnsureBufferSize(tagName.Length() + 1);
@@ -668,7 +669,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode)
 
   mColPos += 1 + tagName.Length();
 
-  if ((mDoFormat || isDirty) && !mInPre && tag == eHTMLTag_style)
+  if ((mDoFormat || isDirty) && mPreLevel == 0 && tag == eHTMLTag_style)
   {
     Write(kGreaterThan);
     Write(NS_LINEBREAK);
@@ -689,9 +690,9 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode)
   }
 
   if (tag == eHTMLTag_pre)
-    mInPre = PR_TRUE;
+    ++mPreLevel;
 
-  if (((mDoFormat || isDirty) && !mInPre && BreakAfterOpen(tag)))
+  if (((mDoFormat || isDirty) && mPreLevel == 0 && BreakAfterOpen(tag)))
   {
     Write(NS_LINEBREAK);
     mColPos = 0;
@@ -734,12 +735,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode)
   }
   else if (tag == eHTMLTag_pre)
   {
-    mInPre = PR_FALSE;  // we think we can clear the flag now
-    for (PRInt32 i = mHTMLStackPos-1; i >= 0; i--)
-    {
-      if (mHTMLTagStack[i] == eHTMLTag_pre)   // oops! Nested pre, still need flag
-        mInPre = PR_TRUE;
-    }
+    --mPreLevel;
     tagName.Assign(aNode.GetText());
   }
   else if (tag == eHTMLTag_comment)
@@ -768,7 +764,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode)
   if (IndentChildren(tag))
     mIndent--;
 
-  if ((mDoFormat || isDirty) && !mInPre && BreakBeforeClose(tag))
+  if ((mDoFormat || isDirty) && mPreLevel == 0 && BreakBeforeClose(tag))
   {
     if (mColPos != 0)
     {
@@ -776,7 +772,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode)
       mColPos = 0;
     }
   }
-  if ((mDoFormat || isDirty) && !mInPre && mColPos == 0)
+  if ((mDoFormat || isDirty) && mPreLevel == 0 && mColPos == 0)
     AddIndent();
 
   EnsureBufferSize(tagName.Length() + 1);
@@ -797,7 +793,7 @@ void nsHTMLContentSinkStream::AddEndTag(const nsIParserNode& aNode)
   if (tag == eHTMLTag_body)
     mInBody = PR_FALSE;
 
-  if (((mDoFormat || isDirty) && !mInPre && BreakAfterClose(tag))
+  if (((mDoFormat || isDirty) && mPreLevel == 0 && BreakAfterClose(tag))
       || tag == eHTMLTag_body || tag == eHTMLTag_html)
   {
     Write(NS_LINEBREAK);
@@ -843,7 +839,7 @@ nsHTMLContentSinkStream::AddLeaf(const nsIParserNode& aNode)
       return NS_OK;
 
     const nsString& text = aNode.GetText();
-    if (mInPre)
+    if (mPreLevel > 0)
     {
       Write(text);
       mColPos += text.Length();
@@ -867,7 +863,7 @@ nsHTMLContentSinkStream::AddLeaf(const nsIParserNode& aNode)
   }
   else if (type == eHTMLTag_whitespace)
   {
-    if (!mDoFormat || mInPre)
+    if (!mDoFormat || mPreLevel > 0)
     {
       const nsString& text = aNode.GetText();
       Write(text);
@@ -876,7 +872,7 @@ nsHTMLContentSinkStream::AddLeaf(const nsIParserNode& aNode)
   }
   else if (type == eHTMLTag_newline)
   {
-    if (!mDoFormat || mInPre)
+    if (!mDoFormat || mPreLevel > 0)
     {
       Write(NS_LINEBREAK);
       mColPos = 0;
@@ -1181,6 +1177,7 @@ static PRBool IsInline(eHTMLTags aTag)
     case  eHTMLTag_sup:
     case  eHTMLTag_textarea:
     case  eHTMLTag_tt:
+    case  eHTMLTag_u:
     case  eHTMLTag_var:
     case  eHTMLTag_wbr:
       result = PR_TRUE;
diff --git a/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.h b/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.h
index d20302fe2b2..cec9fdb8c05 100644
--- a/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.h
+++ b/mozilla/parser/htmlparser/src/nsHTMLContentSinkStream.h
@@ -192,7 +192,7 @@ protected:
     PRBool    mDoHeader;
     PRBool    mBodyOnly;
     PRBool    mHasOpenHtmlTag;
-    PRBool    mInPre;
+    PRInt32   mPreLevel;
 
     PRInt32   mMaxColumn;