Bug 1377648 - Check summary frame instead of summary element on removing the summary. r?heycam draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 05 Jul 2017 15:52:37 +0900
changeset 604081 0ffe978c99eeac3f981448ccd82a1b3264ee7133
parent 604080 edf029c94e37d369039d45726a161ccf5035949f
child 604082 244bbf49173434fa19ec92f680f1fdb51aae7825
push id66947
push userhikezoe@mozilla.com
push dateWed, 05 Jul 2017 08:39:33 +0000
reviewersheycam
bugs1377648
milestone56.0a1
Bug 1377648 - Check summary frame instead of summary element on removing the summary. r?heycam In case of removing summary element, we need to check details *frame* children instead of details *element* children since the summary element has been already removed from details element children list. MozReview-Commit-ID: GEzDId9CYf9
layout/base/nsCSSFrameConstructor.cpp
layout/generic/DetailsFrame.cpp
layout/generic/DetailsFrame.h
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -9727,18 +9727,22 @@ nsCSSFrameConstructor::MaybeRecreateCont
   MOZ_ASSERT(inFlowFrame, "How did that happen?");
   MOZ_ASSERT(inFlowFrame == inFlowFrame->FirstContinuation(),
              "placeholder for primary frame has previous continuations?");
   nsIFrame* parent = inFlowFrame->GetParent();
 
   if (parent && parent->IsDetailsFrame()) {
     HTMLSummaryElement* summary =
       HTMLSummaryElement::FromContent(aFrame->GetContent());
-
-    if (summary && summary->IsMainSummary()) {
+    DetailsFrame* detailsFrame = static_cast<DetailsFrame*>(parent);
+
+    // Unlike adding summary element cases, we need to check children of the
+    // parent details frame since at this moment the summary element has been
+    // already removed from the parent details element's child list.
+    if (summary && detailsFrame->HasMainSummaryFrame(aFrame)) {
       // When removing a summary, we should reframe the parent details frame to
       // ensure that another summary is used or the default summary is
       // generated.
       RecreateFramesForContent(parent->GetContent(),
                                false, REMOVE_FOR_RECONSTRUCTION,
                                aDestroyedFramesFor);
       return true;
     }
--- a/layout/generic/DetailsFrame.cpp
+++ b/layout/generic/DetailsFrame.cpp
@@ -121,9 +121,18 @@ void
 DetailsFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
                                        uint32_t aFilter)
 {
   if (mDefaultSummary) {
     aElements.AppendElement(mDefaultSummary);
   }
 }
 
+bool
+DetailsFrame::HasMainSummaryFrame(nsIFrame* aSummaryFrame)
+{
+  nsIFrame* firstChild =
+    nsPlaceholderFrame::GetRealFrameFor(mFrames.FirstChild());
+
+  return aSummaryFrame == firstChild;
+}
+
 } // namespace mozilla
--- a/layout/generic/DetailsFrame.h
+++ b/layout/generic/DetailsFrame.h
@@ -48,16 +48,22 @@ public:
 
   void DestroyFrom(nsIFrame* aDestructRoot) override;
 
   // nsIAnonymousContentCreator
   nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
 
   void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
                                 uint32_t aFilter) override;
+  // Returns true if |aSummaryFrame| is the main summary (i.e. the first child
+  // of this details frame).
+  // This function is used when the summary element is removed from the parent
+  // details element since at that moment the summary element has been already
+  // removed from the details element children.
+  bool HasMainSummaryFrame(nsIFrame* aSummaryFrame);
 
 private:
   nsCOMPtr<nsIContent> mDefaultSummary;
 };
 
 } // namespace mozilla
 
 #endif // DetailsFrame_h