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
--- 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