Bug 1355683 - Remove Window.getDefaultComputedStyle. r=bz

MozReview-Commit-ID: A2IwfiJiPL

--HG--
extra : rebase_source : 6e41985b2f9aa9528f2f660f8044f5e9f7970712
This commit is contained in:
Xidorn Quan 2017-04-13 16:50:37 +08:00
parent a2a4795bd3
commit 1f463380ce
8 changed files with 21 additions and 203 deletions

View File

@ -228,8 +228,7 @@ AnonymousContent::GetComputedStylePropertyValue(const nsAString& aElementId,
}
RefPtr<nsComputedDOMStyle> cs =
new nsComputedDOMStyle(element, NS_LITERAL_STRING(""), shell,
nsComputedDOMStyle::eAll);
new nsComputedDOMStyle(element, NS_LITERAL_STRING(""), shell);
aRv = cs->GetPropertyValue(aPropertyName, aResult);
}

View File

@ -11014,46 +11014,13 @@ nsGlobalWindow::GetComputedStyle(Element& aElt, const nsAString& aPseudoElt,
ErrorResult& aError)
{
MOZ_ASSERT(IsInnerWindow());
return GetComputedStyleHelper(aElt, aPseudoElt, false, aError);
FORWARD_TO_OUTER_OR_THROW(GetComputedStyleOuter,
(aElt, aPseudoElt), aError, nullptr);
}
already_AddRefed<nsICSSDeclaration>
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)
nsGlobalWindow::GetComputedStyleOuter(Element& aElt,
const nsAString& aPseudoElt)
{
MOZ_RELEASE_ASSERT(IsOuterWindow());
@ -11085,24 +11052,11 @@ nsGlobalWindow::GetComputedStyleHelperOuter(Element& aElt,
}
RefPtr<nsComputedDOMStyle> compStyle =
NS_NewComputedDOMStyle(&aElt, aPseudoElt, presShell,
aDefaultStylesOnly ? nsComputedDOMStyle::eDefaultOnly :
nsComputedDOMStyle::eAll);
NS_NewComputedDOMStyle(&aElt, aPseudoElt, presShell);
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)
{

View File

@ -1147,10 +1147,6 @@ 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,
@ -1729,20 +1725,9 @@ public:
nsDOMWindowList* GetWindowList();
protected:
// Helper for getComputedStyle and getDefaultComputedStyle
already_AddRefed<nsICSSDeclaration>
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);
GetComputedStyleOuter(mozilla::dom::Element& aElt,
const nsAString& aPseudoElt);
// Outer windows only.
void PreloadLocalStorage();

View File

@ -243,9 +243,6 @@ 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.

View File

@ -67,12 +67,10 @@ using namespace mozilla::dom;
already_AddRefed<nsComputedDOMStyle>
NS_NewComputedDOMStyle(dom::Element* aElement, const nsAString& aPseudoElt,
nsIPresShell* aPresShell,
nsComputedDOMStyle::StyleType aStyleType)
nsIPresShell* aPresShell)
{
RefPtr<nsComputedDOMStyle> computedStyle;
computedStyle = new nsComputedDOMStyle(aElement, aPseudoElt, aPresShell,
aStyleType);
computedStyle = new nsComputedDOMStyle(aElement, aPseudoElt, aPresShell);
return computedStyle.forget();
}
@ -245,13 +243,11 @@ nsComputedStyleMap::Update()
nsComputedDOMStyle::nsComputedDOMStyle(dom::Element* aElement,
const nsAString& aPseudoElt,
nsIPresShell* aPresShell,
StyleType aStyleType)
nsIPresShell* aPresShell)
: mDocumentWeak(nullptr)
, mOuterFrame(nullptr)
, mInnerFrame(nullptr)
, mPresShell(nullptr)
, mStyleType(aStyleType)
, mStyleContextGeneration(0)
, mExposeVisitedStyle(false)
, mResolvedStyleContext(false)
@ -429,8 +425,7 @@ nsComputedDOMStyle::GetAuthoredPropertyValue(const nsAString& aPropertyName,
already_AddRefed<nsStyleContext>
nsComputedDOMStyle::GetStyleContext(Element* aElement,
nsIAtom* aPseudo,
nsIPresShell* aPresShell,
StyleType aStyleType)
nsIPresShell* 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
@ -446,7 +441,7 @@ nsComputedDOMStyle::GetStyleContext(Element* aElement,
presShell->FlushPendingNotifications(FlushType::Style);
return GetStyleContextNoFlush(aElement, aPseudo, presShell, aStyleType);
return GetStyleContextNoFlush(aElement, aPseudo, presShell);
}
namespace {
@ -481,7 +476,6 @@ public:
Element* aElement,
CSSPseudoElementType aType,
nsStyleContext* aParentContext,
nsComputedDOMStyle::StyleType aStyleType,
bool aInDocWithShell)
{
MOZ_ASSERT(mAnimationFlag == nsComputedDOMStyle::eWithAnimation,
@ -500,30 +494,6 @@ 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();
}
@ -576,7 +546,6 @@ already_AddRefed<nsStyleContext>
nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement,
nsIAtom* aPseudo,
nsIPresShell* aPresShell,
StyleType aStyleType,
AnimationFlag aAnimationFlag)
{
MOZ_ASSERT(aElement, "NULL element");
@ -598,7 +567,6 @@ nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement,
// check is needed due to bug 135040 (to avoid using
// mPrimaryFrame). Remove it once that's fixed.
if (!aPseudo &&
aStyleType == eAll &&
inDocWithShell &&
!aElement->IsHTMLElement(nsGkAtoms::area)) {
nsIFrame* frame = nsLayoutUtils::GetStyleFrame(aElement);
@ -652,10 +620,6 @@ 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, type);
}
@ -664,7 +628,7 @@ nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement,
// Don't resolve parent context for document fragments.
if (parent && parent->IsElement()) {
parentContext = GetStyleContextNoFlush(parent->AsElement(), nullptr,
aPresShell, aStyleType);
aPresShell);
}
StyleResolver styleResolver(presContext, aAnimationFlag);
@ -673,7 +637,6 @@ nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement,
return styleResolver.ResolveWithAnimation(styleSet,
aElement, type,
parentContext,
aStyleType,
inDocWithShell);
}
@ -818,8 +781,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 (!mPseudo && mStyleType == eAll &&
!mContent->IsHTMLElement(nsGkAtoms::area)) {
if (!mPseudo && !mContent->IsHTMLElement(nsGkAtoms::area)) {
mOuterFrame = mContent->GetPrimaryFrame();
mInnerFrame = mOuterFrame;
if (mOuterFrame) {
@ -867,8 +829,7 @@ nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush)
RefPtr<nsStyleContext> resolvedStyleContext =
nsComputedDOMStyle::GetStyleContext(mContent->AsElement(),
mPseudo,
mPresShell,
mStyleType);
mPresShell);
if (!resolvedStyleContext) {
ClearStyleContext();
return;

View File

@ -69,15 +69,9 @@ 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
};
nsComputedDOMStyle(mozilla::dom::Element* aElement,
const nsAString& aPseudoElt,
nsIPresShell* aPresShell,
StyleType aStyleType);
nsIPresShell* aPresShell);
virtual nsINode *GetParentObject() override
{
@ -86,8 +80,7 @@ public:
static already_AddRefed<nsStyleContext>
GetStyleContext(mozilla::dom::Element* aElement, nsIAtom* aPseudo,
nsIPresShell* aPresShell,
StyleType aStyleType = eAll);
nsIPresShell* aPresShell);
enum AnimationFlag {
eWithAnimation,
@ -97,26 +90,22 @@ public:
static already_AddRefed<nsStyleContext>
GetStyleContextNoFlush(mozilla::dom::Element* aElement,
nsIAtom* aPseudo,
nsIPresShell* aPresShell,
StyleType aStyleType = eAll)
nsIPresShell* aPresShell)
{
return DoGetStyleContextNoFlush(aElement,
aPseudo,
aPresShell,
aStyleType,
eWithAnimation);
}
static already_AddRefed<nsStyleContext>
GetUnanimatedStyleContextNoFlush(mozilla::dom::Element* aElement,
nsIAtom* aPseudo,
nsIPresShell* aPresShell,
StyleType aStyleType = eAll)
nsIPresShell* aPresShell)
{
return DoGetStyleContextNoFlush(aElement,
aPseudo,
aPresShell,
aStyleType,
eWithoutAnimation);
}
@ -174,7 +163,6 @@ private:
DoGetStyleContextNoFlush(mozilla::dom::Element* aElement,
nsIAtom* aPseudo,
nsIPresShell* aPresShell,
StyleType aStyleType,
AnimationFlag aAnimationFlag);
#define STYLE_STRUCT(name_, checkdata_cb_) \
@ -745,11 +733,6 @@ 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.
@ -772,8 +755,6 @@ private:
already_AddRefed<nsComputedDOMStyle>
NS_NewComputedDOMStyle(mozilla::dom::Element* aElement,
const nsAString& aPseudoElt,
nsIPresShell* aPresShell,
nsComputedDOMStyle::StyleType aStyleType =
nsComputedDOMStyle::eAll);
nsIPresShell* aPresShell);
#endif /* nsComputedDOMStyle_h__ */

View File

@ -179,7 +179,6 @@ 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]

View File

@ -1,58 +0,0 @@
<!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>