Bug 1113238 - Part 3: Flush the styles before determining whether an element is preformatted; r=bzbarsky
☠☠ backed out by ff04b6d256b5 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 12 Jan 2015 12:00:09 -0500
changeset 236740 34b89a4f9deafb7ce540b9e2514cf9f1d78a8eb4
parent 236739 ce0ed9dc4d6d947df2d6b2131176ae7417468288
child 236741 25b04c1440c81d73c6a2a4879dae6c920bbfd7bf
push id411
push usermartin.thomson@gmail.com
push dateWed, 14 Jan 2015 00:17:02 +0000
reviewersbzbarsky
bugs1113238
milestone38.0a1
Bug 1113238 - Part 3: Flush the styles before determining whether an element is preformatted; r=bzbarsky This ensures that calls to nsComputedDOMStyle::GetStyleContextForElementNoFlush() in the part 1 of this series give us the correct results.
dom/base/nsDocumentEncoder.cpp
dom/base/nsIContentSerializer.h
dom/base/nsPlainTextSerializer.cpp
dom/base/nsPlainTextSerializer.h
dom/base/nsXHTMLContentSerializer.cpp
dom/base/nsXHTMLContentSerializer.h
dom/base/nsXMLContentSerializer.cpp
dom/base/nsXMLContentSerializer.h
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -1071,17 +1071,18 @@ nsDocumentEncoder::EncodeToStringWithMax
     NS_ENSURE_TRUE(mSerializer, NS_ERROR_NOT_IMPLEMENTED);
   }
 
   nsresult rv = NS_OK;
 
   nsCOMPtr<nsIAtom> charsetAtom;
   
   bool rewriteEncodingDeclaration = !(mSelection || mRange || mNode) && !(mFlags & OutputDontRewriteEncodingDeclaration);
-  mSerializer->Init(mFlags, mWrapColumn, mCharset.get(), mIsCopying, rewriteEncodingDeclaration);
+  mSerializer->Init(mDocument, mFlags, mWrapColumn, mCharset.get(),
+                    mIsCopying, rewriteEncodingDeclaration);
 
   if (mSelection) {
     nsCOMPtr<nsIDOMRange> range;
     int32_t i, count = 0;
 
     rv = mSelection->GetRangeCount(&count);
     NS_ENSURE_SUCCESS(rv, rv);
 
--- a/dom/base/nsIContentSerializer.h
+++ b/dom/base/nsIContentSerializer.h
@@ -14,27 +14,27 @@ class nsAString;
 
 namespace mozilla {
 namespace dom {
 class Element;
 } // namespace dom
 } // namespace mozilla
 
 #define NS_ICONTENTSERIALIZER_IID \
-{ 0xb1ee32f2, 0xb8c4, 0x49b9, \
-  { 0x93, 0xdf, 0xb6, 0xfa, 0xb5, 0xd5, 0x46, 0x88 } }
+{ 0x18a66082, 0x793f, 0x47f4, \
+  { 0xa1, 0xf0, 0xf0, 0xe4, 0x22, 0x9e, 0x52, 0x79 } }
 
 class nsIContentSerializer : public nsISupports {
  public: 
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENTSERIALIZER_IID)
 
-  NS_IMETHOD Init(uint32_t flags, uint32_t aWrapColumn,
-                  const char* aCharSet, bool aIsCopying,
-                  bool aIsWholeDocument) = 0;
+  NS_IMETHOD Init(nsIDocument* aDoc, uint32_t flags,
+                  uint32_t aWrapColumn, const char* aCharSet,
+                  bool aIsCopying, bool aIsWholeDocument) = 0;
 
   NS_IMETHOD AppendText(nsIContent* aText, int32_t aStartOffset,
                         int32_t aEndOffset, nsAString& aStr) = 0;
 
   NS_IMETHOD AppendCDATASection(nsIContent* aCDATASection,
                                 int32_t aStartOffset, int32_t aEndOffset,
                                 nsAString& aStr) = 0;
 
--- a/dom/base/nsPlainTextSerializer.cpp
+++ b/dom/base/nsPlainTextSerializer.cpp
@@ -114,20 +114,22 @@ nsPlainTextSerializer::~nsPlainTextSeria
   NS_WARN_IF_FALSE(mHeadLevel == 0, "Wrong head level!");
 }
 
 NS_IMPL_ISUPPORTS(nsPlainTextSerializer,
                   nsIContentSerializer)
 
 
 NS_IMETHODIMP 
-nsPlainTextSerializer::Init(uint32_t aFlags, uint32_t aWrapColumn,
-                            const char* aCharSet, bool aIsCopying,
-                            bool aIsWholeDocument)
+nsPlainTextSerializer::Init(nsIDocument* aDocument, uint32_t aFlags,
+                            uint32_t aWrapColumn, const char* aCharSet,
+                            bool aIsCopying, bool aIsWholeDocument)
 {
+  MOZ_ASSERT(aDocument);
+
 #ifdef DEBUG
   // Check if the major control flags are set correctly.
   if (aFlags & nsIDocumentEncoder::OutputFormatFlowed) {
     NS_ASSERTION(aFlags & nsIDocumentEncoder::OutputFormatted,
                  "If you want format=flowed, you must combine it with "
                  "nsIDocumentEncoder::OutputFormatted");
   }
 
@@ -182,16 +184,20 @@ nsPlainTextSerializer::Init(uint32_t aFl
         Preferences::GetBool("mail.compose.wrap_to_window_width",
                              mDontWrapAnyQuotes);
     }
   }
 
   // XXX We should let the caller decide whether to do this or not
   mFlags &= ~nsIDocumentEncoder::OutputNoFramesContent;
 
+  // Flush the styles on the document to ensure that we read the correct style
+  // information when determining whether an element is preformatted.
+  aDocument->FlushPendingNotifications(Flush_Style);
+
   return NS_OK;
 }
 
 bool
 nsPlainTextSerializer::GetLastBool(const nsTArray<bool>& aStack)
 {
   uint32_t size = aStack.Length();
   if (size == 0) {
--- a/dom/base/nsPlainTextSerializer.h
+++ b/dom/base/nsPlainTextSerializer.h
@@ -35,19 +35,19 @@ class Element;
 class nsPlainTextSerializer : public nsIContentSerializer
 {
 public:
   nsPlainTextSerializer();
 
   NS_DECL_ISUPPORTS
 
   // nsIContentSerializer
-  NS_IMETHOD Init(uint32_t flags, uint32_t aWrapColumn,
-                  const char* aCharSet, bool aIsCopying,
-                  bool aIsWholeDocument) MOZ_OVERRIDE;
+  NS_IMETHOD Init(nsIDocument* aDocument, uint32_t flags,
+                  uint32_t aWrapColumn, const char* aCharSet,
+                  bool aIsCopying, bool aRewriteEncodingDeclaration) MOZ_OVERRIDE;
 
   NS_IMETHOD AppendText(nsIContent* aText, int32_t aStartOffset,
                         int32_t aEndOffset, nsAString& aStr) MOZ_OVERRIDE;
   NS_IMETHOD AppendCDATASection(nsIContent* aCDATASection,
                                 int32_t aStartOffset, int32_t aEndOffset,
                                 nsAString& aStr) MOZ_OVERRIDE;
   NS_IMETHOD AppendProcessingInstruction(nsIContent* aPI,
                                          int32_t aStartOffset,
--- a/dom/base/nsXHTMLContentSerializer.cpp
+++ b/dom/base/nsXHTMLContentSerializer.cpp
@@ -56,44 +56,54 @@ nsXHTMLContentSerializer::nsXHTMLContent
 }
 
 nsXHTMLContentSerializer::~nsXHTMLContentSerializer()
 {
   NS_ASSERTION(mOLStateStack.IsEmpty(), "Expected OL State stack to be empty");
 }
 
 NS_IMETHODIMP
-nsXHTMLContentSerializer::Init(uint32_t aFlags, uint32_t aWrapColumn,
-                              const char* aCharSet, bool aIsCopying,
-                              bool aRewriteEncodingDeclaration)
+nsXHTMLContentSerializer::Init(nsIDocument* aDocument, uint32_t aFlags,
+                               uint32_t aWrapColumn, const char* aCharSet,
+                               bool aIsCopying, bool aRewriteEncodingDeclaration)
 {
+  MOZ_ASSERT(aDocument);
+
   // The previous version of the HTML serializer did implicit wrapping
   // when there is no flags, so we keep wrapping in order to keep
   // compatibility with the existing calling code
   // XXXLJ perhaps should we remove this default settings later ?
   if (aFlags & nsIDocumentEncoder::OutputFormatted ) {
       aFlags = aFlags | nsIDocumentEncoder::OutputWrap;
   }
 
   nsresult rv;
-  rv = nsXMLContentSerializer::Init(aFlags, aWrapColumn, aCharSet, aIsCopying, aRewriteEncodingDeclaration);
+  rv = nsXMLContentSerializer::Init(aDocument, aFlags, aWrapColumn, aCharSet,
+                                    aIsCopying, aRewriteEncodingDeclaration);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mRewriteEncodingDeclaration = aRewriteEncodingDeclaration;
   mIsCopying = aIsCopying;
   mIsFirstChildOfOL = false;
   mInBody = 0;
   mDisableEntityEncoding = 0;
   mBodyOnly = (mFlags & nsIDocumentEncoder::OutputBodyOnly) ? true
                                                             : false;
 
   // set up entity converter if we are going to need it
   if (mFlags & nsIDocumentEncoder::OutputEncodeW3CEntities) {
     mEntityConverter = do_CreateInstance(NS_ENTITYCONVERTER_CONTRACTID);
   }
+
+  // Flush the styles on the document to ensure that we read the correct style
+  // information when determining whether an element is preformatted.
+  if (ShouldMaintainPreLevel()) {
+    aDocument->FlushPendingNotifications(Flush_Style);
+  }
+
   return NS_OK;
 }
 
 
 // See if the string has any lines longer than longLineLen:
 // if so, we presume formatting is wonky (e.g. the node has been edited)
 // and we'd better rewrap the whole text node.
 bool
--- a/dom/base/nsXHTMLContentSerializer.h
+++ b/dom/base/nsXHTMLContentSerializer.h
@@ -21,19 +21,19 @@
 class nsIContent;
 class nsIAtom;
 
 class nsXHTMLContentSerializer : public nsXMLContentSerializer {
  public:
   nsXHTMLContentSerializer();
   virtual ~nsXHTMLContentSerializer();
 
-  NS_IMETHOD Init(uint32_t flags, uint32_t aWrapColumn,
-                  const char* aCharSet, bool aIsCopying,
-                  bool aRewriteEncodingDeclaration) MOZ_OVERRIDE;
+  NS_IMETHOD Init(nsIDocument* aDocument, uint32_t flags,
+                  uint32_t aWrapColumn, const char* aCharSet,
+                  bool aIsCopying, bool aRewriteEncodingDeclaration) MOZ_OVERRIDE;
 
   NS_IMETHOD AppendText(nsIContent* aText,
                         int32_t aStartOffset,
                         int32_t aEndOffset,
                         nsAString& aStr) MOZ_OVERRIDE;
 
   NS_IMETHOD AppendDocumentStart(nsIDocument *aDocument,
                                  nsAString& aStr) MOZ_OVERRIDE;
--- a/dom/base/nsXMLContentSerializer.cpp
+++ b/dom/base/nsXMLContentSerializer.cpp
@@ -69,19 +69,19 @@ nsXMLContentSerializer::nsXMLContentSeri
 
 nsXMLContentSerializer::~nsXMLContentSerializer()
 {
 }
 
 NS_IMPL_ISUPPORTS(nsXMLContentSerializer, nsIContentSerializer)
 
 NS_IMETHODIMP 
-nsXMLContentSerializer::Init(uint32_t aFlags, uint32_t aWrapColumn,
-                             const char* aCharSet, bool aIsCopying,
-                             bool aRewriteEncodingDeclaration)
+nsXMLContentSerializer::Init(nsIDocument* aDocument, uint32_t aFlags,
+                             uint32_t aWrapColumn, const char* aCharSet,
+                             bool aIsCopying, bool aRewriteEncodingDeclaration)
 {
   mPrefixIndex = 0;
   mColPos = 0;
   mIndentOverflow = 0;
   mIsIndentationAddedOnCurrentLine = false;
   mInAttribute = false;
   mAddNewlineForRootNode = false;
   mAddSpace = false;
--- a/dom/base/nsXMLContentSerializer.h
+++ b/dom/base/nsXMLContentSerializer.h
@@ -27,19 +27,19 @@ class nsIDOMNode;
 class nsINode;
 
 class nsXMLContentSerializer : public nsIContentSerializer {
  public:
   nsXMLContentSerializer();
 
   NS_DECL_ISUPPORTS
 
-  NS_IMETHOD Init(uint32_t flags, uint32_t aWrapColumn,
-                  const char* aCharSet, bool aIsCopying,
-                  bool aRewriteEncodingDeclaration) MOZ_OVERRIDE;
+  NS_IMETHOD Init(nsIDocument* aDocument, uint32_t flags,
+                  uint32_t aWrapColumn, const char* aCharSet,
+                  bool aIsCopying, bool aRewriteEncodingDeclaration) MOZ_OVERRIDE;
 
   NS_IMETHOD AppendText(nsIContent* aText, int32_t aStartOffset,
                         int32_t aEndOffset, nsAString& aStr) MOZ_OVERRIDE;
 
   NS_IMETHOD AppendCDATASection(nsIContent* aCDATASection,
                                 int32_t aStartOffset, int32_t aEndOffset,
                                 nsAString& aStr) MOZ_OVERRIDE;