Bug 1387481 - Part 1: Don't eagerly style editor-created NAC if it's appended to an element in a display:none subtree. r=hiro draft
authorCameron McCormack <cam@mcc.id.au>
Sat, 05 Aug 2017 17:36:09 +0800
changeset 641439 8a4fd542fe72c6abc0636784841d3851c69b6fb4
parent 641249 fe6609d22dfdd710b11e3ac7773aff89f7a8d12c
child 641440 65972249a062731c5d5a3e15ea860cf3e3ecdcb8
push id72517
push userbmo:cam@mcc.id.au
push dateMon, 07 Aug 2017 01:46:04 +0000
reviewershiro
bugs1387481
milestone57.0a1
Bug 1387481 - Part 1: Don't eagerly style editor-created NAC if it's appended to an element in a display:none subtree. r=hiro MozReview-Commit-ID: 7bucY7JKRS0
editor/libeditor/HTMLAnonymousNodeEditor.cpp
--- a/editor/libeditor/HTMLAnonymousNodeEditor.cpp
+++ b/editor/libeditor/HTMLAnonymousNodeEditor.cpp
@@ -234,17 +234,21 @@ HTMLEditor::CreateAnonymousElement(nsIAt
     }
   }
 
   ManualNACPtr newContent(newContentRaw.forget());
 
   // Must style the new element, otherwise the PostRecreateFramesFor call
   // below will do nothing.
   if (ServoStyleSet* styleSet = ps->StyleSet()->GetAsServo()) {
-    styleSet->StyleNewSubtree(newContent);
+    // Sometimes editor likes to append anonymous content to elements
+    // in display:none subtrees, so avoid styling in those cases.
+    if (styleSet->MayTraverseFrom(newContent)) {
+      styleSet->StyleNewSubtree(newContent);
+    }
   }
 
   ElementDeletionObserver* observer =
     new ElementDeletionObserver(newContent, parentContent);
   NS_ADDREF(observer); // NodeWillBeDestroyed releases.
   parentContent->AddMutationObserver(observer);
   newContent->AddMutationObserver(observer);