зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 94b5ea8bed5c (bug 1355683)
MozReview-Commit-ID: AJJ7hSuOQNX --HG-- extra : source : d149b46f49c26eae291cead8dc65d2844452b1b3
This commit is contained in:
Родитель
ce6328824f
Коммит
fbf065fd31
|
@ -228,7 +228,8 @@ AnonymousContent::GetComputedStylePropertyValue(const nsAString& aElementId,
|
|||
}
|
||||
|
||||
RefPtr<nsComputedDOMStyle> cs =
|
||||
new nsComputedDOMStyle(element, NS_LITERAL_STRING(""), shell);
|
||||
new nsComputedDOMStyle(element, NS_LITERAL_STRING(""), shell,
|
||||
nsComputedDOMStyle::eAll);
|
||||
aRv = cs->GetPropertyValue(aPropertyName, aResult);
|
||||
}
|
||||
|
||||
|
|
|
@ -2807,6 +2807,7 @@ nsDOMWindowUtils::GetUnanimatedComputedStyle(nsIDOMElement* aElement,
|
|||
RefPtr<nsComputedDOMStyle> computedStyle =
|
||||
NS_NewComputedDOMStyle(
|
||||
element, aPseudoElement, shell,
|
||||
nsComputedDOMStyle::StyleType::eAll,
|
||||
nsComputedDOMStyle::AnimationFlag::eWithoutAnimation);
|
||||
computedStyle->GetPropertyValue(propertyID, aResult);
|
||||
return NS_OK;
|
||||
|
|
|
@ -11062,13 +11062,46 @@ nsGlobalWindow::GetComputedStyle(Element& aElt, const nsAString& aPseudoElt,
|
|||
ErrorResult& aError)
|
||||
{
|
||||
MOZ_ASSERT(IsInnerWindow());
|
||||
FORWARD_TO_OUTER_OR_THROW(GetComputedStyleOuter,
|
||||
(aElt, aPseudoElt), aError, nullptr);
|
||||
return GetComputedStyleHelper(aElt, aPseudoElt, false, aError);
|
||||
}
|
||||
|
||||
already_AddRefed<nsICSSDeclaration>
|
||||
nsGlobalWindow::GetComputedStyleOuter(Element& aElt,
|
||||
const nsAString& aPseudoElt)
|
||||
nsGlobalWindow::GetDefaultComputedStyle(Element& aElt,
|
||||
const nsAString& aPseudoElt,
|
||||
ErrorResult& aError)
|
||||
{
|
||||
MOZ_ASSERT(IsInnerWindow());
|
||||
return GetComputedStyleHelper(aElt, aPseudoElt, true, aError);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGlobalWindow::GetComputedStyleHelper(nsIDOMElement* aElt,
|
||||
const nsAString& aPseudoElt,
|
||||
bool aDefaultStylesOnly,
|
||||
nsIDOMCSSStyleDeclaration** aReturn)
|
||||
{
|
||||
MOZ_ASSERT(IsInnerWindow());
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aReturn);
|
||||
*aReturn = nullptr;
|
||||
|
||||
nsCOMPtr<dom::Element> element = do_QueryInterface(aElt);
|
||||
if (!element) {
|
||||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
}
|
||||
|
||||
ErrorResult rv;
|
||||
nsCOMPtr<nsIDOMCSSStyleDeclaration> declaration =
|
||||
GetComputedStyleHelper(*element, aPseudoElt, aDefaultStylesOnly, rv);
|
||||
declaration.forget(aReturn);
|
||||
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
already_AddRefed<nsICSSDeclaration>
|
||||
nsGlobalWindow::GetComputedStyleHelperOuter(Element& aElt,
|
||||
const nsAString& aPseudoElt,
|
||||
bool aDefaultStylesOnly)
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(IsOuterWindow());
|
||||
|
||||
|
@ -11100,11 +11133,24 @@ nsGlobalWindow::GetComputedStyleOuter(Element& aElt,
|
|||
}
|
||||
|
||||
RefPtr<nsComputedDOMStyle> compStyle =
|
||||
NS_NewComputedDOMStyle(&aElt, aPseudoElt, presShell);
|
||||
NS_NewComputedDOMStyle(&aElt, aPseudoElt, presShell,
|
||||
aDefaultStylesOnly ? nsComputedDOMStyle::eDefaultOnly :
|
||||
nsComputedDOMStyle::eAll);
|
||||
|
||||
return compStyle.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<nsICSSDeclaration>
|
||||
nsGlobalWindow::GetComputedStyleHelper(Element& aElt,
|
||||
const nsAString& aPseudoElt,
|
||||
bool aDefaultStylesOnly,
|
||||
ErrorResult& aError)
|
||||
{
|
||||
FORWARD_TO_OUTER_OR_THROW(GetComputedStyleHelperOuter,
|
||||
(aElt, aPseudoElt, aDefaultStylesOnly),
|
||||
aError, nullptr);
|
||||
}
|
||||
|
||||
Storage*
|
||||
nsGlobalWindow::GetSessionStorage(ErrorResult& aError)
|
||||
{
|
||||
|
|
|
@ -1153,6 +1153,10 @@ public:
|
|||
GetSpeechSynthesis(mozilla::ErrorResult& aError);
|
||||
bool HasActiveSpeechSynthesis();
|
||||
#endif
|
||||
already_AddRefed<nsICSSDeclaration>
|
||||
GetDefaultComputedStyle(mozilla::dom::Element& aElt,
|
||||
const nsAString& aPseudoElt,
|
||||
mozilla::ErrorResult& aError);
|
||||
void SizeToContentOuter(mozilla::dom::CallerType aCallerType,
|
||||
mozilla::ErrorResult& aError);
|
||||
void SizeToContent(mozilla::dom::CallerType aCallerType,
|
||||
|
@ -1731,9 +1735,20 @@ public:
|
|||
nsDOMWindowList* GetWindowList();
|
||||
|
||||
protected:
|
||||
// Helper for getComputedStyle and getDefaultComputedStyle
|
||||
already_AddRefed<nsICSSDeclaration>
|
||||
GetComputedStyleOuter(mozilla::dom::Element& aElt,
|
||||
const nsAString& aPseudoElt);
|
||||
GetComputedStyleHelperOuter(mozilla::dom::Element& aElt,
|
||||
const nsAString& aPseudoElt,
|
||||
bool aDefaultStylesOnly);
|
||||
already_AddRefed<nsICSSDeclaration>
|
||||
GetComputedStyleHelper(mozilla::dom::Element& aElt,
|
||||
const nsAString& aPseudoElt,
|
||||
bool aDefaultStylesOnly,
|
||||
mozilla::ErrorResult& aError);
|
||||
nsresult GetComputedStyleHelper(nsIDOMElement* aElt,
|
||||
const nsAString& aPseudoElt,
|
||||
bool aDefaultStylesOnly,
|
||||
nsIDOMCSSStyleDeclaration** aReturn);
|
||||
|
||||
// Outer windows only.
|
||||
void PreloadLocalStorage();
|
||||
|
|
|
@ -243,6 +243,9 @@ Window implements WindowModal;
|
|||
|
||||
// Mozilla-specific stuff
|
||||
partial interface Window {
|
||||
//[NewObject, Throws] CSSStyleDeclaration getDefaultComputedStyle(Element elt, optional DOMString pseudoElt = "");
|
||||
[NewObject, Throws] CSSStyleDeclaration? getDefaultComputedStyle(Element elt, optional DOMString pseudoElt = "");
|
||||
|
||||
// Mozilla extensions
|
||||
/**
|
||||
* Method for scrolling this window by a number of lines.
|
||||
|
|
|
@ -67,11 +67,12 @@ using namespace mozilla::dom;
|
|||
already_AddRefed<nsComputedDOMStyle>
|
||||
NS_NewComputedDOMStyle(dom::Element* aElement, const nsAString& aPseudoElt,
|
||||
nsIPresShell* aPresShell,
|
||||
nsComputedDOMStyle::StyleType aStyleType,
|
||||
nsComputedDOMStyle::AnimationFlag aFlag)
|
||||
{
|
||||
RefPtr<nsComputedDOMStyle> computedStyle;
|
||||
computedStyle = new nsComputedDOMStyle(aElement, aPseudoElt,
|
||||
aPresShell, aFlag);
|
||||
aPresShell, aStyleType, aFlag);
|
||||
return computedStyle.forget();
|
||||
}
|
||||
|
||||
|
@ -245,11 +246,13 @@ nsComputedStyleMap::Update()
|
|||
nsComputedDOMStyle::nsComputedDOMStyle(dom::Element* aElement,
|
||||
const nsAString& aPseudoElt,
|
||||
nsIPresShell* aPresShell,
|
||||
StyleType aStyleType,
|
||||
AnimationFlag aFlag)
|
||||
: mDocumentWeak(nullptr)
|
||||
, mOuterFrame(nullptr)
|
||||
, mInnerFrame(nullptr)
|
||||
, mPresShell(nullptr)
|
||||
, mStyleType(aStyleType)
|
||||
, mStyleContextGeneration(0)
|
||||
, mExposeVisitedStyle(false)
|
||||
, mResolvedStyleContext(false)
|
||||
|
@ -402,7 +405,8 @@ nsComputedDOMStyle::GetAuthoredPropertyValue(const nsAString& aPropertyName,
|
|||
already_AddRefed<nsStyleContext>
|
||||
nsComputedDOMStyle::GetStyleContext(Element* aElement,
|
||||
nsIAtom* aPseudo,
|
||||
nsIPresShell* aPresShell)
|
||||
nsIPresShell* aPresShell,
|
||||
StyleType aStyleType)
|
||||
{
|
||||
// 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
|
||||
|
@ -418,7 +422,7 @@ nsComputedDOMStyle::GetStyleContext(Element* aElement,
|
|||
|
||||
presShell->FlushPendingNotifications(FlushType::Style);
|
||||
|
||||
return GetStyleContextNoFlush(aElement, aPseudo, presShell);
|
||||
return GetStyleContextNoFlush(aElement, aPseudo, presShell, aStyleType);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -453,6 +457,7 @@ public:
|
|||
Element* aElement,
|
||||
CSSPseudoElementType aType,
|
||||
nsStyleContext* aParentContext,
|
||||
nsComputedDOMStyle::StyleType aStyleType,
|
||||
bool aInDocWithShell)
|
||||
{
|
||||
MOZ_ASSERT(mAnimationFlag == nsComputedDOMStyle::eWithAnimation,
|
||||
|
@ -471,6 +476,30 @@ public:
|
|||
result = aStyleSet->ResolveStyleFor(aElement, aParentContext,
|
||||
LazyComputeBehavior::Allow);
|
||||
}
|
||||
if (aStyleType == nsComputedDOMStyle::StyleType::eDefaultOnly) {
|
||||
// We really only want the user and UA rules. Filter out the other ones.
|
||||
nsTArray< nsCOMPtr<nsIStyleRule> > rules;
|
||||
for (nsRuleNode* ruleNode = result->RuleNode();
|
||||
!ruleNode->IsRoot();
|
||||
ruleNode = ruleNode->GetParent()) {
|
||||
if (ruleNode->GetLevel() == SheetType::Agent ||
|
||||
ruleNode->GetLevel() == SheetType::User) {
|
||||
rules.AppendElement(ruleNode->GetRule());
|
||||
}
|
||||
}
|
||||
|
||||
// We want to build a list of user/ua rules that is in order from least to
|
||||
// most important, so we have to reverse the list.
|
||||
// Integer division to get "stop" is purposeful here: if length is odd, we
|
||||
// don't have to do anything with the middle element of the array.
|
||||
for (uint32_t i = 0, length = rules.Length(), stop = length / 2;
|
||||
i < stop; ++i) {
|
||||
rules[i].swap(rules[length - i - 1]);
|
||||
}
|
||||
|
||||
result = aStyleSet->AsGecko()->ResolveStyleForRules(aParentContext,
|
||||
rules);
|
||||
}
|
||||
return result.forget();
|
||||
}
|
||||
|
||||
|
@ -551,6 +580,7 @@ already_AddRefed<nsStyleContext>
|
|||
nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement,
|
||||
nsIAtom* aPseudo,
|
||||
nsIPresShell* aPresShell,
|
||||
StyleType aStyleType,
|
||||
AnimationFlag aAnimationFlag)
|
||||
{
|
||||
MOZ_ASSERT(aElement, "NULL element");
|
||||
|
@ -572,6 +602,7 @@ nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement,
|
|||
// check is needed due to bug 135040 (to avoid using
|
||||
// mPrimaryFrame). Remove it once that's fixed.
|
||||
if (inDocWithShell &&
|
||||
aStyleType == eAll &&
|
||||
!aElement->IsHTMLElement(nsGkAtoms::area)) {
|
||||
nsIFrame* frame = nullptr;
|
||||
if (aPseudo == nsCSSPseudoElements::before) {
|
||||
|
@ -631,6 +662,10 @@ nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement,
|
|||
// For Servo, compute the result directly without recursively building up
|
||||
// a throwaway style context chain.
|
||||
if (ServoStyleSet* servoSet = styleSet->GetAsServo()) {
|
||||
if (aStyleType == eDefaultOnly) {
|
||||
NS_WARNING("stylo: ServoStyleSets cannot supply UA-only styles yet");
|
||||
return nullptr;
|
||||
}
|
||||
return servoSet->ResolveTransientStyle(aElement, aPseudo, type);
|
||||
}
|
||||
|
||||
|
@ -639,7 +674,7 @@ nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement,
|
|||
// Don't resolve parent context for document fragments.
|
||||
if (parent && parent->IsElement()) {
|
||||
parentContext = GetStyleContextNoFlush(parent->AsElement(), nullptr,
|
||||
aPresShell);
|
||||
aPresShell, aStyleType);
|
||||
}
|
||||
|
||||
StyleResolver styleResolver(presContext, aAnimationFlag);
|
||||
|
@ -648,6 +683,7 @@ nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement,
|
|||
return styleResolver.ResolveWithAnimation(styleSet,
|
||||
aElement, type,
|
||||
parentContext,
|
||||
aStyleType,
|
||||
inDocWithShell);
|
||||
}
|
||||
|
||||
|
@ -789,7 +825,7 @@ nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush)
|
|||
// XXX the !mContent->IsHTMLElement(nsGkAtoms::area)
|
||||
// check is needed due to bug 135040 (to avoid using
|
||||
// mPrimaryFrame). Remove it once that's fixed.
|
||||
if (!mContent->IsHTMLElement(nsGkAtoms::area)) {
|
||||
if (mStyleType == eAll && !mContent->IsHTMLElement(nsGkAtoms::area)) {
|
||||
mOuterFrame = nullptr;
|
||||
|
||||
if (!mPseudo) {
|
||||
|
@ -850,7 +886,8 @@ nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush)
|
|||
RefPtr<nsStyleContext> resolvedStyleContext =
|
||||
nsComputedDOMStyle::GetStyleContext(mContent->AsElement(),
|
||||
mPseudo,
|
||||
mPresShell);
|
||||
mPresShell,
|
||||
mStyleType);
|
||||
if (!resolvedStyleContext) {
|
||||
ClearStyleContext();
|
||||
return;
|
||||
|
|
|
@ -69,6 +69,11 @@ public:
|
|||
using nsICSSDeclaration::GetPropertyCSSValue;
|
||||
virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) override;
|
||||
|
||||
enum StyleType {
|
||||
eDefaultOnly, // Only includes UA and user sheets
|
||||
eAll // Includes all stylesheets
|
||||
};
|
||||
|
||||
enum AnimationFlag {
|
||||
eWithAnimation,
|
||||
eWithoutAnimation,
|
||||
|
@ -77,6 +82,7 @@ public:
|
|||
nsComputedDOMStyle(mozilla::dom::Element* aElement,
|
||||
const nsAString& aPseudoElt,
|
||||
nsIPresShell* aPresShell,
|
||||
StyleType aStyleType,
|
||||
AnimationFlag aFlag = eWithAnimation);
|
||||
|
||||
virtual nsINode *GetParentObject() override
|
||||
|
@ -86,27 +92,32 @@ public:
|
|||
|
||||
static already_AddRefed<nsStyleContext>
|
||||
GetStyleContext(mozilla::dom::Element* aElement, nsIAtom* aPseudo,
|
||||
nsIPresShell* aPresShell);
|
||||
nsIPresShell* aPresShell,
|
||||
StyleType aStyleType = eAll);
|
||||
|
||||
static already_AddRefed<nsStyleContext>
|
||||
GetStyleContextNoFlush(mozilla::dom::Element* aElement,
|
||||
nsIAtom* aPseudo,
|
||||
nsIPresShell* aPresShell)
|
||||
nsIPresShell* aPresShell,
|
||||
StyleType aStyleType = eAll)
|
||||
{
|
||||
return DoGetStyleContextNoFlush(aElement,
|
||||
aPseudo,
|
||||
aPresShell,
|
||||
aStyleType,
|
||||
eWithAnimation);
|
||||
}
|
||||
|
||||
static already_AddRefed<nsStyleContext>
|
||||
GetUnanimatedStyleContextNoFlush(mozilla::dom::Element* aElement,
|
||||
nsIAtom* aPseudo,
|
||||
nsIPresShell* aPresShell)
|
||||
nsIPresShell* aPresShell,
|
||||
StyleType aStyleType = eAll)
|
||||
{
|
||||
return DoGetStyleContextNoFlush(aElement,
|
||||
aPseudo,
|
||||
aPresShell,
|
||||
aStyleType,
|
||||
eWithoutAnimation);
|
||||
}
|
||||
|
||||
|
@ -164,6 +175,7 @@ private:
|
|||
DoGetStyleContextNoFlush(mozilla::dom::Element* aElement,
|
||||
nsIAtom* aPseudo,
|
||||
nsIPresShell* aPresShell,
|
||||
StyleType aStyleType,
|
||||
AnimationFlag aAnimationFlag);
|
||||
|
||||
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
||||
|
@ -738,6 +750,11 @@ private:
|
|||
*/
|
||||
nsIPresShell* mPresShell;
|
||||
|
||||
/*
|
||||
* The kind of styles we should be returning.
|
||||
*/
|
||||
StyleType mStyleType;
|
||||
|
||||
/**
|
||||
* The nsComputedDOMStyle generation at the time we last resolved a style
|
||||
* context and stored it in mStyleContext.
|
||||
|
@ -766,6 +783,8 @@ already_AddRefed<nsComputedDOMStyle>
|
|||
NS_NewComputedDOMStyle(mozilla::dom::Element* aElement,
|
||||
const nsAString& aPseudoElt,
|
||||
nsIPresShell* aPresShell,
|
||||
nsComputedDOMStyle::StyleType aStyleType =
|
||||
nsComputedDOMStyle::eAll,
|
||||
nsComputedDOMStyle::AnimationFlag aFlag =
|
||||
nsComputedDOMStyle::eWithAnimation);
|
||||
|
||||
|
|
|
@ -180,6 +180,7 @@ skip-if = toolkit == 'android' #bug 536603
|
|||
[test_css_supports.html]
|
||||
[test_css_supports_variables.html]
|
||||
[test_default_bidi_css.html]
|
||||
[test_default_computed_style.html]
|
||||
[test_descriptor_storage.html]
|
||||
[test_descriptor_syntax_errors.html]
|
||||
[test_dont_use_document_colors.html]
|
||||
|
|
|
@ -173,6 +173,7 @@ to mochitest command.
|
|||
* test_css_supports.html: issues around @supports syntax servo/servo#15482 [8]
|
||||
* test_author_specified_style.html: support serializing color as author specified bug 1348165 [27]
|
||||
* browser_newtab_share_rule_processors.js: agent style sheet sharing [1]
|
||||
* test_default_computed_style.html: getDefaultComputedStyle bug 1366157 [1]
|
||||
|
||||
## Assertions
|
||||
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=800983
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 800983</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<style>
|
||||
#display::before { content: "Visible"; display: block }
|
||||
#display {
|
||||
display: inline;
|
||||
margin-top: 0;
|
||||
background: yellow;
|
||||
color: blue;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=800983">Mozilla Bug 800983</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 800983 **/
|
||||
var cs = getComputedStyle($("display"));
|
||||
var cs_pseudo = getComputedStyle($("display"), "::before")
|
||||
|
||||
var cs_default = getDefaultComputedStyle($("display"));
|
||||
var cs_default_pseudo = getDefaultComputedStyle($("display"), "::before");
|
||||
|
||||
// Sanity checks for normal computed style
|
||||
is(cs.display, "inline", "We have inline display");
|
||||
is(cs.marginTop, "0px", "We have 0 margin");
|
||||
is(cs.backgroundColor, "rgb(255, 255, 0)", "We have yellow background");
|
||||
is(cs.color, "rgb(0, 0, 255)", "We have blue text");
|
||||
is(cs_pseudo.content, '"Visible"', "We have some content");
|
||||
is(cs_pseudo.display, "block", "Our ::before is block");
|
||||
|
||||
// And now our actual tests
|
||||
is(cs_default.display, "block", "We have block display by default");
|
||||
is(cs_default.marginTop, "16px", "We have 16px margin by default");
|
||||
is(cs_default.backgroundColor, "rgba(0, 0, 0, 0)",
|
||||
"We have transparent background by default");
|
||||
is(cs_default.color, "rgb(0, 0, 0)", "We have black text by default");
|
||||
is(cs_default_pseudo.content, "none", "We have no content by default");
|
||||
is(cs_default_pseudo.display, "inline", "Our ::before is inline by default");
|
||||
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче