Bug 1443492: Flush the document, not the shell, in cross-doc getComputedStyle situations. r?dbaron
We flushed the style of the original doc, but not layout, and thus the iframe
resize wasn't noticed, and the style flush on the child presShell wasn't
sufficient.
Do a style flush on the child document instead, so that it flushes layout on the
parent document too if needed.
MozReview-Commit-ID: 5ZhBuxpKIUg
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -981,18 +981,18 @@ nsComputedDOMStyle::UpdateCurrentStyleSo
}
#ifdef DEBUG
mFlushedPendingReflows = aNeedsLayoutFlush;
#endif
nsCOMPtr<nsIPresShell> presShellForContent =
nsContentUtils::GetPresShellForContent(mContent);
- if (presShellForContent && presShellForContent != document->GetShell()) {
- presShellForContent->FlushPendingNotifications(FlushType::Style);
+ if (presShellForContent && presShellForContent->GetDocument() != document) {
+ presShellForContent->GetDocument()->FlushPendingNotifications(FlushType::Style);
}
mPresShell = document->GetShell();
if (!mPresShell || !mPresShell->GetPresContext()) {
ClearStyleContext();
return;
}
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -314185,16 +314185,22 @@
]
],
"css/cssom/escape.html": [
[
"/css/cssom/escape.html",
{}
]
],
+ "css/cssom/getComputedStyle-dynamic-subdoc.html": [
+ [
+ "/css/cssom/getComputedStyle-dynamic-subdoc.html",
+ {}
+ ]
+ ],
"css/cssom/getComputedStyle-pseudo.html": [
[
"/css/cssom/getComputedStyle-pseudo.html",
{}
]
],
"css/cssom/historical.html": [
[
@@ -525298,16 +525304,20 @@
"css/cssom/cssstyledeclaration-mutability.html": [
"5f29436964d01c57f61d513cee5b83281643ac54",
"testharness"
],
"css/cssom/escape.html": [
"c9ed57c7ef7a035c25feff4ea60547a57d727f31",
"testharness"
],
+ "css/cssom/getComputedStyle-dynamic-subdoc.html": [
+ "4e5aa65acec48b1650ee69be3b3a2e564a963e22",
+ "testharness"
+ ],
"css/cssom/getComputedStyle-pseudo.html": [
"a2033405d6852cdeb4c3b8cf628f7c1d8f7cd1aa",
"testharness"
],
"css/cssom/historical.html": [
"2c78218b89efb9bdf60cf708920be142051347c7",
"testharness"
],
@@ -573267,17 +573277,17 @@
"9285ebf2cd716ea072c18fe668e95cf6ce4ec3de",
"manual"
],
"payment-request/historical.https.html": [
"6695acdcd1647fdd37702a7f63658dcd50f25596",
"testharness"
],
"payment-request/interfaces.https.html": [
- "d269e8378f2a84ba96c981536667817e0db9e2d1",
+ "2280f0ef821cdc3093e10c2162d3756f5eeb78de",
"testharness"
],
"payment-request/payment-request-abort-method.https.html": [
"30c62af4a05a4d83cbbd1e82d0df62bae9a85e96",
"testharness"
],
"payment-request/payment-request-canmakepayment-method.https.html": [
"0d863558b996df81a36207201bbf8c649688845d",
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/css/cssom/getComputedStyle-dynamic-subdoc.html
@@ -0,0 +1,37 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>CSSOM: getComputedStyle cross-doc properly reflects media query changes</title>
+<link rel="help" href="https://drafts.csswg.org/cssom/#dom-window-getcomputedstyle">
+<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<!--
+ NOTE: The way this test is written doesn't match the spec, but matches all
+ implementations, see https://github.com/w3c/csswg-drafts/issues/2403
+-->
+<iframe id="frm" style="width: 100px; heigth: 100px"></iframe>
+<script>
+test(function() {
+ let frm = document.getElementById('frm');
+ let frmDoc = frm.contentWindow.document;
+ frmDoc.open();
+ frmDoc.write('<style>body { color: red } @media all and (min-width: 101px) { body { color: green } }</style><body>Should be green</body>');
+ frmDoc.close();
+
+ document.body.offsetTop;
+
+ assert_equals(
+ getComputedStyle(frmDoc.body).color,
+ "rgb(255, 0, 0)",
+ "Initial color should be red"
+ );
+
+ frm.style.width = "200px";
+
+ assert_equals(
+ getComputedStyle(frmDoc.body).color,
+ "rgb(0, 128, 0)",
+ "style should have been updated to account for media query changes"
+ );
+}, "getComputedStyle cross-doc properly reflects media query changes");
+</script>