Bug 1467536: Split GetPropertyValue from GetPropertyCSSValueWithoutWarning. r?xidorn
And remove the later.
MozReview-Commit-ID: BO3epOMe70w
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -429,30 +429,52 @@ nsComputedDOMStyle::GetParentRule()
}
NS_IMETHODIMP
nsComputedDOMStyle::GetPropertyValue(const nsAString& aPropertyName,
nsAString& aReturn)
{
aReturn.Truncate();
- ErrorResult error;
- RefPtr<CSSValue> val =
- GetPropertyCSSValueWithoutWarning(aPropertyName, error);
- if (error.Failed()) {
- return error.StealNSResult();
- }
-
- if (val) {
+ nsCSSPropertyID prop =
+ nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eForAllContent);
+
+ const ComputedStyleMap::Entry* entry = nullptr;
+ if (prop != eCSSPropertyExtra_variable) {
+ entry = GetComputedStyleMap()->FindEntryForProperty(prop);
+ if (!entry) {
+ return NS_OK;
+ }
+ }
+
+ const bool layoutFlushIsNeeded = entry && entry->IsLayoutFlushNeeded();
+ UpdateCurrentStyleSources(layoutFlushIsNeeded);
+ if (!mComputedStyle) {
+ return NS_ERROR_NOT_AVAILABLE;
+ }
+
+ auto cleanup = mozilla::MakeScopeExit([&] {
+ ClearCurrentStyleSources();
+ });
+
+ if (!entry) {
+ MOZ_ASSERT(nsCSSProps::IsCustomPropertyName(aPropertyName));
+ const nsAString& name =
+ Substring(aPropertyName, CSS_CUSTOM_NAME_PREFIX_LENGTH);
+ Servo_GetCustomPropertyValue(mComputedStyle, &name, &aReturn);
+ return NS_OK;
+ }
+
+ if (RefPtr<CSSValue> value = (this->*entry->mGetter)()) {
+ ErrorResult rv;
nsString text;
- val->GetCssText(text, error);
+ value->GetCssText(text, rv);
aReturn.Assign(text);
- return error.StealNSResult();
- }
-
+ return rv.StealNSResult();
+ }
return NS_OK;
}
/* static */
already_AddRefed<ComputedStyle>
nsComputedDOMStyle::GetComputedStyle(Element* aElement,
nsAtom* aPseudo,
StyleType aStyleType)
@@ -981,67 +1003,16 @@ nsComputedDOMStyle::ClearCurrentStyleSou
ClearComputedStyle();
}
mOuterFrame = nullptr;
mInnerFrame = nullptr;
mPresShell = nullptr;
}
-already_AddRefed<CSSValue>
-nsComputedDOMStyle::GetPropertyCSSValueWithoutWarning(
- const nsAString& aPropertyName,
- ErrorResult& aRv)
-{
- nsCSSPropertyID prop =
- nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eForAllContent);
-
- bool needsLayoutFlush;
- ComputedStyleMap::Entry::ComputeMethod getter;
-
- if (prop == eCSSPropertyExtra_variable) {
- needsLayoutFlush = false;
- getter = nullptr;
- } else {
- const ComputedStyleMap::Entry* propEntry =
- GetComputedStyleMap()->FindEntryForProperty(prop);
-
- if (!propEntry) {
-#ifdef DEBUG_ComputedDOMStyle
- NS_WARNING(PromiseFlatCString(NS_ConvertUTF16toUTF8(aPropertyName) +
- NS_LITERAL_CSTRING(" is not queryable!")).get());
-#endif
-
- // NOTE: For branches, we should flush here for compatibility!
- return nullptr;
- }
-
- needsLayoutFlush = propEntry->IsLayoutFlushNeeded();
- getter = propEntry->mGetter;
- }
-
- UpdateCurrentStyleSources(needsLayoutFlush);
- if (!mComputedStyle) {
- aRv.Throw(NS_ERROR_NOT_AVAILABLE);
- return nullptr;
- }
-
- RefPtr<CSSValue> val;
- if (prop == eCSSPropertyExtra_variable) {
- val = DoGetCustomProperty(aPropertyName);
- } else {
- // Call our pointer-to-member-function.
- val = (this->*getter)();
- }
-
- ClearCurrentStyleSources();
-
- return val.forget();
-}
-
NS_IMETHODIMP
nsComputedDOMStyle::RemoveProperty(const nsAString& aPropertyName,
nsAString& aReturn)
{
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -54,20 +54,16 @@ class nsComputedDOMStyle final : public
, public nsStubMutationObserver
{
private:
// Convenience typedefs:
typedef nsCSSKTableEntry KTableEntry;
typedef mozilla::dom::CSSValue CSSValue;
typedef mozilla::StyleGeometryBox StyleGeometryBox;
- already_AddRefed<CSSValue>
- GetPropertyCSSValueWithoutWarning(const nsAString& aProp,
- mozilla::ErrorResult& aRv);
-
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsComputedDOMStyle,
nsICSSDeclaration)
NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER
nsresult GetPropertyValue(const nsCSSPropertyID aPropID,
nsAString& aValue) override;