mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 22:07:41 +00:00
For elements that are in a document with a pres shell, always use that pres shell when getting computed style so we (a) return a more correct style and (b) don't mix rule nodes from two rule trees. (Bug 596245) r=bzbarsky a2.0=blocking2.0:betaN
This commit is contained in:
parent
c4f6132d18
commit
8592a24298
@ -0,0 +1,6 @@
|
||||
<!DOCTYPE HTML>
|
||||
<style>
|
||||
p { color: fuchsia }
|
||||
</style>
|
||||
<p>This is a paragraph inside the iframe.</p>
|
||||
<div style="display:none"><p>This is a paragraph inside the iframe.</p></div>
|
75
layout/reftests/cssom/computed-style-cross-window-ref.html
Normal file
75
layout/reftests/cssom/computed-style-cross-window-ref.html
Normal file
@ -0,0 +1,75 @@
|
||||
<!DOCTYPE HTML>
|
||||
<title>getComputedStyle across windows</title>
|
||||
<style>
|
||||
p { color: blue }
|
||||
|
||||
div { margin: 1em 0 }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
|
||||
var gRunCount = 2;
|
||||
|
||||
function run() {
|
||||
if (--gRunCount != 0)
|
||||
return;
|
||||
|
||||
var i = document.getElementById("i");
|
||||
|
||||
var pout = document.getElementById("out");
|
||||
var poutnone = document.getElementById("outnone");
|
||||
var poutdet = document.createElement("p");
|
||||
var pin = i.contentDocument.getElementsByTagName("p")[0];
|
||||
var pinnone = i.contentDocument.getElementsByTagName("p")[1];
|
||||
var pindet = i.contentDocument.createElement("p");
|
||||
|
||||
document.getElementById("res1").style.color =
|
||||
window.getComputedStyle(pin, "").color;
|
||||
|
||||
document.getElementById("res2").style.color =
|
||||
i.contentWindow.getComputedStyle(pout, "").color;
|
||||
|
||||
document.getElementById("res3").style.color =
|
||||
window.getComputedStyle(pinnone, "").color;
|
||||
|
||||
document.getElementById("res4").style.color =
|
||||
i.contentWindow.getComputedStyle(poutnone, "").color;
|
||||
|
||||
document.getElementById("res5").style.color =
|
||||
window.getComputedStyle(pindet, "").color;
|
||||
|
||||
document.getElementById("res6").style.color =
|
||||
i.contentWindow.getComputedStyle(poutdet, "").color;
|
||||
}
|
||||
|
||||
</script>
|
||||
<body onload="run()">
|
||||
|
||||
<p id="out">This is a paragraph outside the iframe.</p>
|
||||
<div style="display:none"><p id="outnone">This is a paragraph outside the iframe.</p></div>
|
||||
|
||||
<iframe id="i" src="computed-style-cross-window-inner.html" onload="run()"></iframe>
|
||||
|
||||
<div style="color:fuchsia">This paragraph is the color that
|
||||
outerWindow.getComputedStyle says the paragraph inside the iframe
|
||||
is.</div>
|
||||
|
||||
<div style="color:blue">This paragraph is the color that
|
||||
iframeWindow.getComputedStyle says the paragraph outside the iframe
|
||||
is.</div>
|
||||
|
||||
<div style="color:fuchsia">This paragraph is the color that
|
||||
outerWindow.getComputedStyle says the display:none paragraph inside the
|
||||
iframe is.</div>
|
||||
|
||||
<div style="color:blue">This paragraph is the color that
|
||||
iframeWindow.getComputedStyle says the display:none paragraph outside
|
||||
the iframe is.</div>
|
||||
|
||||
<div style="color:blue">This paragraph is the color that
|
||||
outerWindow.getComputedStyle says the detached paragraph inside the
|
||||
iframe is.</div>
|
||||
|
||||
<div style="color:fuchsia">This paragraph is the color that
|
||||
iframeWindow.getComputedStyle says the detached paragraph outside
|
||||
the iframe is.</div>
|
78
layout/reftests/cssom/computed-style-cross-window.html
Normal file
78
layout/reftests/cssom/computed-style-cross-window.html
Normal file
@ -0,0 +1,78 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html class="reftest-wait">
|
||||
<title>getComputedStyle across windows</title>
|
||||
<style>
|
||||
p { color: blue }
|
||||
|
||||
div { margin: 1em 0 }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
|
||||
var gRunCount = 2;
|
||||
|
||||
function run() {
|
||||
if (--gRunCount != 0)
|
||||
return;
|
||||
|
||||
var i = document.getElementById("i");
|
||||
|
||||
var pout = document.getElementById("out");
|
||||
var poutnone = document.getElementById("outnone");
|
||||
var poutdet = document.createElement("p");
|
||||
var pin = i.contentDocument.getElementsByTagName("p")[0];
|
||||
var pinnone = i.contentDocument.getElementsByTagName("p")[1];
|
||||
var pindet = i.contentDocument.createElement("p");
|
||||
|
||||
document.getElementById("res1").style.color =
|
||||
window.getComputedStyle(pin, "").color;
|
||||
|
||||
document.getElementById("res2").style.color =
|
||||
i.contentWindow.getComputedStyle(pout, "").color;
|
||||
|
||||
document.getElementById("res3").style.color =
|
||||
window.getComputedStyle(pinnone, "").color;
|
||||
|
||||
document.getElementById("res4").style.color =
|
||||
i.contentWindow.getComputedStyle(poutnone, "").color;
|
||||
|
||||
document.getElementById("res5").style.color =
|
||||
window.getComputedStyle(pindet, "").color;
|
||||
|
||||
document.getElementById("res6").style.color =
|
||||
i.contentWindow.getComputedStyle(poutdet, "").color;
|
||||
|
||||
document.documentElement.removeAttribute("class");
|
||||
}
|
||||
|
||||
</script>
|
||||
<body onload="run()">
|
||||
|
||||
<p id="out">This is a paragraph outside the iframe.</p>
|
||||
<div style="display:none"><p id="outnone">This is a paragraph outside the iframe.</p></div>
|
||||
|
||||
<iframe id="i" src="computed-style-cross-window-inner.html" onload="run()"></iframe>
|
||||
|
||||
<div id="res1">This paragraph is the color that
|
||||
outerWindow.getComputedStyle says the paragraph inside the iframe
|
||||
is.</div>
|
||||
|
||||
<div id="res2">This paragraph is the color that
|
||||
iframeWindow.getComputedStyle says the paragraph outside the iframe
|
||||
is.</div>
|
||||
|
||||
<div id="res3">This paragraph is the color that
|
||||
outerWindow.getComputedStyle says the display:none paragraph inside the
|
||||
iframe is.</div>
|
||||
|
||||
<div id="res4">This paragraph is the color that
|
||||
iframeWindow.getComputedStyle says the display:none paragraph outside
|
||||
the iframe is.</div>
|
||||
|
||||
<div id="res5">This paragraph is the color that
|
||||
outerWindow.getComputedStyle says the detached paragraph inside the
|
||||
iframe is.</div>
|
||||
|
||||
<div id="res6">This paragraph is the color that
|
||||
iframeWindow.getComputedStyle says the detached paragraph outside
|
||||
the iframe is.</div>
|
1
layout/reftests/cssom/reftest.list
Normal file
1
layout/reftests/cssom/reftest.list
Normal file
@ -0,0 +1 @@
|
||||
== computed-style-cross-window.html computed-style-cross-window-ref.html
|
@ -99,6 +99,8 @@ include css-valuesandunits/reftest.list
|
||||
# layout/style/test/test_visited_reftests instead of using the reftest
|
||||
# harness.
|
||||
|
||||
include cssom/reftest.list
|
||||
|
||||
# columns/
|
||||
include columns/reftest.list
|
||||
|
||||
|
@ -323,16 +323,21 @@ nsComputedDOMStyle::GetStyleContextForElement(Element* aElement,
|
||||
nsIAtom* aPseudo,
|
||||
nsIPresShell* aPresShell)
|
||||
{
|
||||
// If there's no pres shell, get it from the content
|
||||
if (!aPresShell) {
|
||||
aPresShell = GetPresShellForContent(aElement);
|
||||
if (!aPresShell)
|
||||
// If the content has a pres shell, we must use it. Otherwise we'd
|
||||
// potentially mix rule trees by using the wrong pres shell's style
|
||||
// set. Using the pres shell from the content also means that any
|
||||
// content that's actually *in* a document will get the style from the
|
||||
// correct document.
|
||||
nsIPresShell *presShell = GetPresShellForContent(aElement);
|
||||
if (!presShell) {
|
||||
presShell = aPresShell;
|
||||
if (!presShell)
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
aPresShell->FlushPendingNotifications(Flush_Style);
|
||||
presShell->FlushPendingNotifications(Flush_Style);
|
||||
|
||||
return GetStyleContextForElementNoFlush(aElement, aPseudo, aPresShell);
|
||||
return GetStyleContextForElementNoFlush(aElement, aPseudo, presShell);
|
||||
}
|
||||
|
||||
/* static */
|
||||
@ -342,11 +347,15 @@ nsComputedDOMStyle::GetStyleContextForElementNoFlush(Element* aElement,
|
||||
nsIPresShell* aPresShell)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aElement, "NULL element");
|
||||
|
||||
// If there's no pres shell, get it from the content
|
||||
if (!aPresShell) {
|
||||
aPresShell = GetPresShellForContent(aElement);
|
||||
if (!aPresShell)
|
||||
// If the content has a pres shell, we must use it. Otherwise we'd
|
||||
// potentially mix rule trees by using the wrong pres shell's style
|
||||
// set. Using the pres shell from the content also means that any
|
||||
// content that's actually *in* a document will get the style from the
|
||||
// correct document.
|
||||
nsIPresShell *presShell = GetPresShellForContent(aElement);
|
||||
if (!presShell) {
|
||||
presShell = aPresShell;
|
||||
if (!presShell)
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
@ -373,13 +382,13 @@ nsComputedDOMStyle::GetStyleContextForElementNoFlush(Element* aElement,
|
||||
// Don't resolve parent context for document fragments.
|
||||
if (parent && parent->IsElement())
|
||||
parentContext = GetStyleContextForElementNoFlush(parent->AsElement(),
|
||||
nsnull, aPresShell);
|
||||
nsnull, presShell);
|
||||
|
||||
nsPresContext *presContext = aPresShell->GetPresContext();
|
||||
nsPresContext *presContext = presShell->GetPresContext();
|
||||
if (!presContext)
|
||||
return nsnull;
|
||||
|
||||
nsStyleSet *styleSet = aPresShell->StyleSet();
|
||||
nsStyleSet *styleSet = presShell->StyleSet();
|
||||
|
||||
if (aPseudo) {
|
||||
nsCSSPseudoElements::Type type = nsCSSPseudoElements::GetPseudoType(aPseudo);
|
||||
|
Loading…
x
Reference in New Issue
Block a user