Bug 1245424 Part 1 - Fix assert for a display:none summary on debug build. draft
authorTing-Yu Lin <tlin@mozilla.com>
Thu, 24 Mar 2016 15:05:29 +0800
changeset 344293 991fe7cd31c1547407254f5aecbbec0f580a471e
parent 343962 6202ade0e6d688ffb67932398e56cfc6fa04ceb3
child 344294 9cdcf6e1faf12a4710fde87546b9a7a59724942c
push id13786
push usertlin@mozilla.com
push dateThu, 24 Mar 2016 07:09:38 +0000
bugs1245424, 1258657
milestone48.0a1
Bug 1245424 Part 1 - Fix assert for a display:none summary on debug build. If the main summary element has 'display: none' style, it won't generates a summary frame as the first child of the details. However, if a details element have two summaries and the first summary has 'display: none', the second summary still generates a SummaryFrame event if it isn't the main summary. So instead of checking on the SummaryFrame as before, I check the content tree for the main summary by using the idea in bug 1245424 comment 8. Another reason might be the potential removal of SummaryFrame in bug 1258657. MozReview-Commit-ID: H0evZ17zj5k
layout/generic/DetailsFrame.cpp
layout/generic/crashtests/crashtests.list
layout/generic/crashtests/details-display-none-summary-1.html
layout/generic/crashtests/details-display-none-summary-2.html
layout/generic/crashtests/details-display-none-summary-3.html
--- a/layout/generic/DetailsFrame.cpp
+++ b/layout/generic/DetailsFrame.cpp
@@ -42,17 +42,17 @@ DetailsFrame::GetType() const
 {
   return nsGkAtoms::detailsFrame;
 }
 
 void
 DetailsFrame::SetInitialChildList(ChildListID aListID, nsFrameList& aChildList)
 {
   if (aListID == kPrincipalList) {
-    auto* details = HTMLDetailsElement::FromContent(GetContent());
+    HTMLDetailsElement* details = HTMLDetailsElement::FromContent(GetContent());
     bool isOpen = details->Open();
 
     if (isOpen) {
       // If details is open, the first summary needs to be rendered as if it is
       // the first child.
       for (nsIFrame* child : aChildList) {
         auto* realFrame = nsPlaceholderFrame::GetRealFrameFor(child);
         auto* cif = realFrame->GetContentInsertionFrame();
@@ -62,24 +62,30 @@ DetailsFrame::SetInitialChildList(ChildL
           aChildList.RemoveFrame(child);
           aChildList.InsertFrame(nullptr, nullptr, child);
           break;
         }
       }
     }
 
 #ifdef DEBUG
-    nsIFrame* realFrame =
-      nsPlaceholderFrame::GetRealFrameFor(isOpen ?
-                                          aChildList.FirstChild() :
-                                          aChildList.OnlyChild());
-    MOZ_ASSERT(realFrame, "Principal list of details should not be empty!");
-    nsIFrame* summaryFrame = realFrame->GetContentInsertionFrame();
-    MOZ_ASSERT(summaryFrame->GetType() == nsGkAtoms::summaryFrame,
-               "The frame should be summary frame!");
+    for (nsIFrame* child : aChildList) {
+      HTMLSummaryElement* summary =
+        HTMLSummaryElement::FromContent(child->GetContent());
+
+      if (child == aChildList.FirstChild()) {
+        if (summary && summary->IsMainSummary()) {
+          break;
+        }
+      } else {
+        MOZ_ASSERT(!summary || !summary->IsMainSummary(),
+                   "Rest of the children are neither summary elements nor"
+                   "the main summary!");
+      }
+    }
 #endif
 
   }
 
   nsBlockFrame::SetInitialChildList(aListID, aChildList);
 }
 
 void
--- a/layout/generic/crashtests/crashtests.list
+++ b/layout/generic/crashtests/crashtests.list
@@ -598,16 +598,19 @@ load 1223568-1.html
 load 1223568-2.html
 load 1224230-1.html
 pref(layout.css.grid.enabled,true) load 1225118.html
 pref(layout.css.grid.enabled,true) load 1225376.html
 pref(layout.css.grid.enabled,true) load 1225592.html
 load 1229437-1.html
 load 1229437-2.html
 pref(dom.details_element.enabled,true) load details-containing-only-text.html
+pref(dom.details_element.enabled,true) load details-display-none-summary-1.html
+pref(dom.details_element.enabled,true) load details-display-none-summary-2.html
+pref(dom.details_element.enabled,true) load details-display-none-summary-3.html
 pref(dom.details_element.enabled,true) load details-open-overflow-auto.html
 pref(dom.details_element.enabled,true) load details-open-overflow-hidden.html
 pref(dom.details_element.enabled,true) load details-three-columns.html
 load first-letter-638937-1.html
 load first-letter-638937-2.html
 pref(dom.meta-viewport.enabled,true) test-pref(font.size.inflation.emPerLine,15) asserts(0-100) load font-inflation-762332.html # bug 762332
 load outline-on-frameset.xhtml
 pref(dom.details_element.enabled,true) load summary-position-out-of-flow.html
new file mode 100644
--- /dev/null
+++ b/layout/generic/crashtests/details-display-none-summary-1.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<!-- Any copyright is dedicated to the Public Domain.
+   - http://creativecommons.org/publicdomain/zero/1.0/ -->
+
+<html>
+  <body>
+    <details open>
+      <summary style="display: none;">summary (display: none)</summary>
+    </details>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/generic/crashtests/details-display-none-summary-2.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<!-- Any copyright is dedicated to the Public Domain.
+   - http://creativecommons.org/publicdomain/zero/1.0/ -->
+
+<html>
+  <body>
+    <details open>
+      <summary style="display: none;">summary (display: none)</summary>
+      <p>This is the details.</p>
+    </details>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/generic/crashtests/details-display-none-summary-3.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<!-- Any copyright is dedicated to the Public Domain.
+   - http://creativecommons.org/publicdomain/zero/1.0/ -->
+
+<html>
+  <body>
+    <details open>
+      <summary style="display: none;">summary (display: none)</summary>
+      <summary>summary 2</summary>
+      <p>This is the details.</p>
+    </details>
+  </body>
+</html>