Bug 790265. Changes that might attach a binding (e.g. state changes on <object> elements) should trigger a frame construction attempt even for display:none elements, so the binding will get attached. r=dholbert

This commit is contained in:
Boris Zbarsky 2012-10-05 23:50:55 -04:00
parent 04dde73476
commit 41e33df4f9
3 changed files with 85 additions and 10 deletions

View File

@ -37,6 +37,7 @@ MOCHITEST_FILES = \
file_bug591198_xbl.xml \
file_bug591198_inner.html \
test_bug639338.xhtml \
test_bug790265.xhtml \
$(NULL)
MOCHITEST_CHROME_FILES = \

View File

@ -0,0 +1,55 @@
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=790265
-->
<head>
<title>Test for Bug 790265</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<bindings xmlns="http://www.mozilla.org/xbl">
<binding id="binding">
<implementation>
<method name="foo">
<body><![CDATA[
return this;
]]></body>
</method>
</implementation>
</binding>
</bindings>
<style>
#toBind { display: none; }
#toBind.bound { -moz-binding: url(#binding); }
</style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=790265">Mozilla Bug 790265</a>
<p id="display"></p>
<div id="content">
<div id="toBind">Bound element</div>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
// Flush out style on $("toBind")
$("toBind").offsetWidth;
ok(!("foo" in $("toBind")), "Should not have binding applied");
is(getComputedStyle($("toBind")).MozBinding, "none",
"Computed binding should be none");
$("toBind").className = "bound";
// Flush the style change, so we kick off the binding load before onload
// fires and thus block onload.
$("toBind").offsetWidth;
addLoadEvent(function() {
ok("foo" in $("toBind"), "Should have binding applied");
is($("toBind").foo(), $("toBind"), "Should have correct return value");
SimpleTest.finish();
});
]]>
</script>
</pre>
</body>
</html>

View File

@ -9048,23 +9048,42 @@ nsCSSFrameConstructor::CaptureStateForFramesOf(nsIContent* aContent,
}
}
static bool EqualURIs(mozilla::css::URLValue *aURI1,
mozilla::css::URLValue *aURI2)
{
return aURI1 == aURI2 || // handle null==null, and optimize
(aURI1 && aURI2 && aURI1->URIEquals(*aURI2));
}
nsresult
nsCSSFrameConstructor::MaybeRecreateFramesForElement(Element* aElement)
{
nsresult result = NS_OK;
nsRefPtr<nsStyleContext> oldContext = GetUndisplayedContent(aElement);
if (!oldContext) {
return NS_OK;
}
nsStyleContext *oldContext = GetUndisplayedContent(aElement);
if (oldContext) {
// The parent has a frame, so try resolving a new context.
nsRefPtr<nsStyleContext> newContext = mPresShell->StyleSet()->
ResolveStyleFor(aElement, oldContext->GetParent());
// The parent has a frame, so try resolving a new context.
nsRefPtr<nsStyleContext> newContext = mPresShell->StyleSet()->
ResolveStyleFor(aElement, oldContext->GetParent());
ChangeUndisplayedContent(aElement, newContext);
if (newContext->GetStyleDisplay()->mDisplay != NS_STYLE_DISPLAY_NONE) {
result = RecreateFramesForContent(aElement, false);
ChangeUndisplayedContent(aElement, newContext);
const nsStyleDisplay* disp = newContext->GetStyleDisplay();
if (disp->mDisplay == NS_STYLE_DISPLAY_NONE) {
// We can skip trying to recreate frames here, but only if our style
// context does not have a binding URI that differs from our old one.
// Otherwise, we should try to recreate, because we may want to apply the
// new binding
if (!disp->mBinding) {
return NS_OK;
}
const nsStyleDisplay* oldDisp = oldContext->PeekStyleDisplay();
if (oldDisp && EqualURIs(disp->mBinding, oldDisp->mBinding)) {
return NS_OK;
}
}
return result;
return RecreateFramesForContent(aElement, false);
}
static nsIFrame*