Bug 1643333: part 3) Change `IsInvisibleNodeAndShouldBeSkipped` to static method. r=masayuki
authorMirko Brodesser <mbrodesser@mozilla.com>
Fri, 05 Jun 2020 08:33:49 +0000
changeset 534098 9193efaf7d9dbed49287ddab72eda3cd6a5a3d2f
parent 534097 2c59ceb99ec48ea72192cc830dec0417870668e2
child 534099 a617ea1772f9927903aa2a9766112d9ca8d6b0d1
push id37482
push usernbeleuzu@mozilla.com
push dateFri, 05 Jun 2020 14:35:19 +0000
treeherdermozilla-central@c835da226e6d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1643333
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1643333: part 3) Change `IsInvisibleNodeAndShouldBeSkipped` to static method. r=masayuki Will help to factor out functionality of serializing a node. Differential Revision: https://phabricator.services.mozilla.com/D78310
dom/base/nsDocumentEncoder.cpp
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -251,18 +251,22 @@ class nsDocumentEncoder : public nsIDocu
   nsresult SerializeRangeContextStart(const nsTArray<nsINode*>& aAncestorArray);
   nsresult SerializeRangeContextEnd();
 
   virtual int32_t GetImmediateContextCount(
       const nsTArray<nsINode*>& aAncestorArray) {
     return -1;
   }
 
-  bool IsInvisibleNodeAndShouldBeSkipped(const nsINode& aNode) const {
-    if (mFlags & SkipInvisibleContent) {
+  /**
+   * @param aFlags multiple of the flags defined in nsIDocumentEncoder.idl.o
+   */
+  static bool IsInvisibleNodeAndShouldBeSkipped(const nsINode& aNode,
+                                                const uint32_t aFlags) {
+    if (aFlags & SkipInvisibleContent) {
       // Treat the visibility of the ShadowRoot as if it were
       // the host content.
       //
       // FIXME(emilio): I suspect instead of this a bunch of the GetParent()
       // calls here should be doing GetFlattenedTreeParent, then this condition
       // should be unreachable...
       const nsINode* node{&aNode};
       if (const ShadowRoot* shadowRoot = ShadowRoot::FromNode(node)) {
@@ -661,17 +665,17 @@ nsresult nsDocumentEncoder::SerializeNod
     } else if (aOriginalNode.IsText()) {
       const nsCOMPtr<nsINode> parent = aOriginalNode.GetParent();
       if (parent && parent->IsElement()) {
         mSerializer->ScanElementForPreformat(parent->AsElement());
       }
     }
   }
 
-  if (IsInvisibleNodeAndShouldBeSkipped(aOriginalNode)) {
+  if (IsInvisibleNodeAndShouldBeSkipped(aOriginalNode, mFlags)) {
     return NS_OK;
   }
 
   FixupNodeDeterminer fixupNodeDeterminer{mNodeFixup, aFixupNode,
                                           aOriginalNode};
   nsINode* node = &fixupNodeDeterminer.GetFixupNodeFallBackToOriginalNode();
 
   nsresult rv = NS_OK;
@@ -725,17 +729,17 @@ nsresult nsDocumentEncoder::SerializeNod
     } else if (aOriginalNode.IsText()) {
       const nsCOMPtr<nsINode> parent = aOriginalNode.GetParent();
       if (parent && parent->IsElement()) {
         mSerializer->ForgetElementForPreformat(parent->AsElement());
       }
     }
   }
 
-  if (IsInvisibleNodeAndShouldBeSkipped(aOriginalNode)) {
+  if (IsInvisibleNodeAndShouldBeSkipped(aOriginalNode, mFlags)) {
     return NS_OK;
   }
 
   nsresult rv = NS_OK;
 
   FixupNodeDeterminer fixupNodeDeterminer{mNodeFixup, aFixupNode,
                                           aOriginalNode};
   nsINode* node = &fixupNodeDeterminer.GetFixupNodeFallBackToOriginalNode();
@@ -756,17 +760,17 @@ nsresult nsDocumentEncoder::SerializeToS
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (aMaxLength > 0 && outputLength >= aMaxLength) {
     return NS_OK;
   }
 
   NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
-  if (IsInvisibleNodeAndShouldBeSkipped(*aNode)) {
+  if (IsInvisibleNodeAndShouldBeSkipped(*aNode, mFlags)) {
     return NS_OK;
   }
 
   FixupNodeDeterminer fixupNodeDeterminer{mNodeFixup, nullptr, *aNode};
   nsINode* maybeFixedNode =
       &fixupNodeDeterminer.GetFixupNodeFallBackToOriginalNode();
 
   if (mFlags & SkipInvisibleContent) {
@@ -847,17 +851,17 @@ nsresult nsDocumentEncoder::SerializeToS
 static bool IsTextNode(nsINode* aNode) { return aNode && aNode->IsText(); }
 
 nsresult nsDocumentEncoder::SerializeRangeNodes(const nsRange* const aRange,
                                                 nsINode* const aNode,
                                                 const int32_t aDepth) {
   nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
   NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
-  if (IsInvisibleNodeAndShouldBeSkipped(*aNode)) {
+  if (IsInvisibleNodeAndShouldBeSkipped(*aNode, mFlags)) {
     return NS_OK;
   }
 
   nsresult rv = NS_OK;
 
   // get start and end nodes for this recursion level
   nsCOMPtr<nsIContent> startNode, endNode;
   {
@@ -1086,17 +1090,17 @@ nsresult nsDocumentEncoder::SerializeRan
 
   if (startContainer == endContainer && IsTextNode(startContainer)) {
     if (mFlags & SkipInvisibleContent) {
       // Check that the parent is visible if we don't a frame.
       // IsInvisibleNodeAndShouldBeSkipped() will do it when there's a frame.
       nsCOMPtr<nsIContent> content = do_QueryInterface(startContainer);
       if (content && !content->GetPrimaryFrame()) {
         nsIContent* parent = content->GetParent();
-        if (!parent || IsInvisibleNodeAndShouldBeSkipped(*parent)) {
+        if (!parent || IsInvisibleNodeAndShouldBeSkipped(*parent, mFlags)) {
           return NS_OK;
         }
       }
     }
     rv = SerializeNodeStart(*startContainer, startOffset, endOffset);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = SerializeNodeEnd(*startContainer);
     NS_ENSURE_SUCCESS(rv, rv);