Bug 1246185 - Do not collapsed <details> when preference off. r=bz
To retain backward compatibility, <details> tags should not collapse its
children when dom.details_element.enabled = false.
--- a/dom/html/HTMLDetailsElement.cpp
+++ b/dom/html/HTMLDetailsElement.cpp
@@ -19,17 +19,17 @@ NS_NewHTMLDetailsElement(already_AddRefe
}
return new mozilla::dom::HTMLDetailsElement(aNodeInfo);
}
namespace mozilla {
namespace dom {
-bool
+/* static */ bool
HTMLDetailsElement::IsDetailsEnabled()
{
static bool isDetailsEnabled = false;
static bool added = false;
if (!added) {
Preferences::AddBoolVarCache(&isDetailsEnabled,
"dom.details_element.enabled");
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -5636,17 +5636,17 @@ nsCSSFrameConstructor::AddFrameConstruct
}
return;
}
}
// When constructing a child of a non-open <details>, create only the frame
// for the main <summary> element, and skip other elements.
auto* details = HTMLDetailsElement::FromContentOrNull(parent);
- if (details && !details->Open()) {
+ if (details && details->IsDetailsEnabled() && !details->Open()) {
auto* summary = HTMLSummaryElement::FromContentOrNull(aContent);
if (!summary || !summary->IsMainSummary()) {
SetAsUndisplayedContent(aState, aItems, aContent, styleContext,
isGeneratedContent);
return;
}
}
new file mode 100644
--- /dev/null
+++ b/layout/reftests/details-summary/disabled-no-summary-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<!-- Any copyright is dedicated to the Public Domain.
+ - http://creativecommons.org/publicdomain/zero/1.0/ -->
+
+<html>
+ <body>
+ <div>
+ <p>This is the details.</p>
+ </div>
+ </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/details-summary/disabled-single-summary-ref.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<!-- Any copyright is dedicated to the Public Domain.
+ - http://creativecommons.org/publicdomain/zero/1.0/ -->
+
+<html>
+ <body>
+ <div>
+ <div>Summary</div>
+ <p>This is the details.</p>
+ </div>
+ </body>
+</html>
--- a/layout/reftests/details-summary/reftest.list
+++ b/layout/reftests/details-summary/reftest.list
@@ -1,8 +1,13 @@
+# Disable <details> and <summary>
+pref(dom.details_element.enabled,false) == single-summary.html disabled-single-summary-ref.html
+pref(dom.details_element.enabled,false) == open-single-summary.html disabled-single-summary-ref.html
+pref(dom.details_element.enabled,false) == no-summary.html disabled-no-summary-ref.html
+
# Basic <summary> handling
pref(dom.details_element.enabled,true) == multiple-summary.html single-summary.html
pref(dom.details_element.enabled,true) == open-multiple-summary.html open-multiple-summary-ref.html
pref(dom.details_element.enabled,true) == summary-not-first-child.html single-summary.html
pref(dom.details_element.enabled,true) == open-summary-not-first-child.html open-single-summary.html
pref(dom.details_element.enabled,true) == open-summary-block-style.html open-single-summary.html
pref(dom.details_element.enabled,true) == no-summary.html no-summary-ref.html
pref(dom.details_element.enabled,true) == open-no-summary.html open-no-summary-ref.html