Bug 1428610 part 7. Make the nsICSSDeclaration length API nicer. r=emilio

MozReview-Commit-ID: 2gs8npBJFJY
This commit is contained in:
Boris Zbarsky 2018-01-30 14:48:27 -05:00
parent c49370b74a
commit 4c01bdc27f
8 changed files with 20 additions and 35 deletions

View File

@ -229,8 +229,7 @@ sdnAccessible::get_computedStyle(unsigned short aMaxStyleProperties,
nsWinUtils::GetComputedStyleDeclaration(mNode->AsContent());
NS_ENSURE_TRUE(cssDecl, E_FAIL);
uint32_t length = 0;
cssDecl->GetLength(&length);
uint32_t length = cssDecl->Length();
uint32_t index = 0, realIndex = 0;
for (index = realIndex = 0; index < length && realIndex < aMaxStyleProperties;

View File

@ -1325,7 +1325,7 @@ CSSEditUtils::GetInlineStyles(Element* aElement,
MOZ_ASSERT(cssDecl);
cssDecl.forget(aCssDecl);
(*aCssDecl)->GetLength(aLength);
*aLength = (*aCssDecl)->Length();
return NS_OK;
}

View File

@ -220,9 +220,7 @@ ChangeStyleTransaction::DoTransaction()
}
// Let's be sure we don't keep an empty style attribute
uint32_t length;
rv = cssDecl->GetLength(&length);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t length = cssDecl->Length();
if (!length) {
rv = mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -225,18 +225,19 @@ nsCSSFontFaceStyleDecl::SetProperty(const nsAString& propertyName,
return NS_ERROR_NOT_IMPLEMENTED; // bug 443978
}
NS_IMETHODIMP
nsCSSFontFaceStyleDecl::GetLength(uint32_t *aLength)
uint32_t
nsCSSFontFaceStyleDecl::Length()
{
uint32_t len = 0;
for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
id < eCSSFontDesc_COUNT;
id = nsCSSFontDesc(id + 1))
if (mDescriptors.Get(id).GetUnit() != eCSSUnit_Null)
id = nsCSSFontDesc(id + 1)) {
if (mDescriptors.Get(id).GetUnit() != eCSSUnit_Null) {
len++;
}
}
*aLength = len;
return NS_OK;
return len;
}
void

View File

@ -439,11 +439,9 @@ nsComputedDOMStyle::SetCssText(const nsAString& aCssText,
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
}
NS_IMETHODIMP
nsComputedDOMStyle::GetLength(uint32_t* aLength)
uint32_t
nsComputedDOMStyle::Length()
{
NS_PRECONDITION(aLength, "Null aLength! Prepare to die!");
uint32_t length = GetComputedStyleMap()->Length();
// Make sure we have up to date style so that we can include custom
@ -455,11 +453,9 @@ nsComputedDOMStyle::GetLength(uint32_t* aLength)
: StyleVariables()->mVariables.Count();
}
*aLength = length;
ClearCurrentStyleSources();
return NS_OK;
return length;
}
css::Rule*

View File

@ -161,18 +161,16 @@ nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText,
aRv = SetCSSDeclaration(newdecl);
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetLength(uint32_t* aLength)
uint32_t
nsDOMCSSDeclaration::Length()
{
DeclarationBlock* decl = GetCSSDeclaration(eOperation_Read);
if (decl) {
*aLength = decl->Count();
} else {
*aLength = 0;
return decl->Count();
}
return NS_OK;
return 0;
}
already_AddRefed<dom::CSSValue>

View File

@ -43,8 +43,6 @@ public:
NS_IMETHOD_(MozExternalRefCountType) AddRef() override = 0;
NS_IMETHOD_(MozExternalRefCountType) Release() override = 0;
using nsICSSDeclaration::GetLength;
/**
* Method analogous to CSSStyleDeclaration::GetPropertyValue,
* which obeys all the same restrictions.
@ -81,7 +79,7 @@ public:
const nsAString& value,
const nsAString& priority,
nsIPrincipal* aSubjectPrincipal) override;
NS_IMETHOD GetLength(uint32_t *aLength) override;
uint32_t Length() override;
// WebIDL interface for CSS2Properties
#define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_

View File

@ -62,7 +62,6 @@ public:
const nsAString& aValue,
const nsAString& aPriority,
nsIPrincipal* aSubjectPrincipal = nullptr) = 0;
NS_IMETHOD GetLength(uint32_t* aLength) = 0;
void Item(uint32_t aIndex, nsAString& aReturn)
{
bool found;
@ -77,11 +76,7 @@ public:
nsIPrincipal* aSubjectPrincipal,
mozilla::ErrorResult& rv) = 0;
virtual void GetCssText(nsAString& aString) = 0;
uint32_t Length() {
uint32_t length;
GetLength(&length);
return length;
}
virtual uint32_t Length() = 0;
void Item(uint32_t aIndex, nsString& aPropName) {
Item(aIndex, static_cast<nsAString&>(aPropName));
}
@ -122,7 +117,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSDeclaration, NS_ICSSDECLARATION_IID)
const nsAString& value, \
const nsAString& priority, \
nsIPrincipal* aSubjectPrincipal = nullptr) override; \
NS_IMETHOD GetLength(uint32_t *aLength) override; \
uint32_t Length() override; \
mozilla::css::Rule* GetParentRule() override;
#endif // nsICSSDeclaration_h__