From d328a13fbbae792e41bf30db67d009155447155d Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 12 Feb 2017 16:02:29 -0800 Subject: [PATCH] Bug 1338936 - Part 2: stylo: Add necessary stubbed-out bindings for ServoSpecifiedValues; r=bz,emilio MozReview-Commit-ID: 6wg32flypt7 --- dom/html/nsGenericHTMLElement.cpp | 9 ++-- dom/mathml/nsMathMLElement.cpp | 6 +++ layout/style/ServoBindingList.h | 40 +++++++++++++- layout/style/ServoSpecifiedValues.cpp | 77 +++++++++++++++++++++++++++ layout/style/ServoSpecifiedValues.h | 65 +++++++++++----------- 5 files changed, 159 insertions(+), 38 deletions(-) diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index b52d37fd5c8c..2fe83ebb05d5 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -1522,6 +1522,12 @@ nsGenericHTMLElement::MapBackgroundInto(const nsMappedAttributes* aAttributes, if (!aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Background))) return; + if (aData->IsServo()) { + // FIXME(bug 1339711) + NS_WARNING("stylo: cannot handle background presentation attribute"); + return; + } + nsPresContext* presContext = aData->PresContext(); if (!aData->PropertyIsSet(eCSSProperty_background_image) && @@ -1545,9 +1551,6 @@ nsGenericHTMLElement::MapBackgroundInto(const nsMappedAttributes* aAttributes, nsCSSValueList* list = backImage->SetListValue(); list->mValue.SetImageValue(value->GetImageValue()); } - } else { - // FIXME(bug 1330041) - MOZ_ASSERT_UNREACHABLE("stylo: cannot handle background"); } } } diff --git a/dom/mathml/nsMathMLElement.cpp b/dom/mathml/nsMathMLElement.cpp index 479a76d0eff2..5adfef31fc75 100644 --- a/dom/mathml/nsMathMLElement.cpp +++ b/dom/mathml/nsMathMLElement.cpp @@ -490,6 +490,12 @@ void nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes, GenericSpecifiedValues* aGenericData) { + if (aGenericData->IsServo()) { + // FIXME (bug 1339711) handle MathML properties in Stylo + NS_WARNING("stylo: cannot handle MathML presentation attributes"); + return; + } + nsRuleData* aData = aGenericData->AsGecko(); if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) { // scriptsizemultiplier diff --git a/layout/style/ServoBindingList.h b/layout/style/ServoBindingList.h index e74b61bd049a..375781f07395 100644 --- a/layout/style/ServoBindingList.h +++ b/layout/style/ServoBindingList.h @@ -175,10 +175,46 @@ SERVO_BINDING_FUNC(Servo_DeclarationBlock_RemoveProperty, void, SERVO_BINDING_FUNC(Servo_DeclarationBlock_RemovePropertyById, void, RawServoDeclarationBlockBorrowed declarations, nsCSSPropertyID property) -SERVO_BINDING_FUNC(Servo_DeclarationBlock_AddPresValue, void, + +// presentation attributes +SERVO_BINDING_FUNC(Servo_DeclarationBlock_PropertyIsSet, bool, + RawServoDeclarationBlockBorrowed declarations, + nsCSSPropertyID property) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetIdentStringValue, void, RawServoDeclarationBlockBorrowed declarations, nsCSSPropertyID property, - nsCSSValueBorrowedMut css_value) + const nsAString& value) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetKeywordValue, void, + RawServoDeclarationBlockBorrowed declarations, + nsCSSPropertyID property, + int32_t value) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetIntValue, void, + RawServoDeclarationBlockBorrowed declarations, + nsCSSPropertyID property, + int32_t value) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetPixelValue, void, + RawServoDeclarationBlockBorrowed declarations, + nsCSSPropertyID property, + float value) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetPercentValue, void, + RawServoDeclarationBlockBorrowed declarations, + nsCSSPropertyID property, + float value) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetAutoValue, void, + RawServoDeclarationBlockBorrowed declarations, + nsCSSPropertyID property) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetCurrentColor, void, + RawServoDeclarationBlockBorrowed declarations, + nsCSSPropertyID property) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetColorValue, void, + RawServoDeclarationBlockBorrowed declarations, + nsCSSPropertyID property, + nscolor value) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetFontFamily, void, + RawServoDeclarationBlockBorrowed declarations, + const nsAString& value) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetTextDecorationColorOverride, void, + RawServoDeclarationBlockBorrowed declarations) // CSS supports() SERVO_BINDING_FUNC(Servo_CSSSupports2, bool, diff --git a/layout/style/ServoSpecifiedValues.cpp b/layout/style/ServoSpecifiedValues.cpp index a5a5f77309f6..236331143fe9 100644 --- a/layout/style/ServoSpecifiedValues.cpp +++ b/layout/style/ServoSpecifiedValues.cpp @@ -3,6 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "mozilla/ServoBindings.h" #include "mozilla/ServoSpecifiedValues.h" namespace { @@ -25,3 +26,79 @@ ServoSpecifiedValues::ServoSpecifiedValues(nsPresContext* aContext, { } + +bool +ServoSpecifiedValues::PropertyIsSet(nsCSSPropertyID aId) +{ + // We always create fresh ServoSpecifiedValues for each property + // mapping, so unlike Gecko there aren't existing properties from + // the cascade that we wish to avoid overwriting. + // + // If a property is being overwritten, that's a bug. Check for it + // in debug mode (this is O(n^2) behavior since Servo will traverse + // the array each time you add a new property) + MOZ_ASSERT(!Servo_DeclarationBlock_PropertyIsSet(mDecl, aId), + "Presentation attribute mappers should never attempt to set the same property twice"); + return false; +} + +void +ServoSpecifiedValues::SetIdentStringValue(nsCSSPropertyID aId, + const nsString& aValue) +{ + Servo_DeclarationBlock_SetIdentStringValue(mDecl, aId, aValue); +} + +void +ServoSpecifiedValues::SetKeywordValue(nsCSSPropertyID aId, int32_t aValue) +{ + Servo_DeclarationBlock_SetKeywordValue(mDecl, aId, aValue); +} + +void +ServoSpecifiedValues::SetIntValue(nsCSSPropertyID aId, int32_t aValue) +{ + Servo_DeclarationBlock_SetIntValue(mDecl, aId, aValue); +} + +void +ServoSpecifiedValues::SetPixelValue(nsCSSPropertyID aId, float aValue) +{ + Servo_DeclarationBlock_SetPixelValue(mDecl, aId, aValue); +} + +void +ServoSpecifiedValues::SetPercentValue(nsCSSPropertyID aId, float aValue) +{ + Servo_DeclarationBlock_SetPercentValue(mDecl, aId, aValue); +} + +void +ServoSpecifiedValues::SetAutoValue(nsCSSPropertyID aId) +{ + Servo_DeclarationBlock_SetAutoValue(mDecl, aId); +} + +void +ServoSpecifiedValues::SetCurrentColor(nsCSSPropertyID aId) +{ + Servo_DeclarationBlock_SetCurrentColor(mDecl, aId); +} + +void +ServoSpecifiedValues::SetColorValue(nsCSSPropertyID aId, nscolor aColor) +{ + Servo_DeclarationBlock_SetColorValue(mDecl, aId, aColor); +} + +void +ServoSpecifiedValues::SetFontFamily(const nsString& aValue) +{ + Servo_DeclarationBlock_SetFontFamily(mDecl, aValue); +} + +void +ServoSpecifiedValues::SetTextDecorationColorOverride() +{ + Servo_DeclarationBlock_SetTextDecorationColorOverride(mDecl); +} diff --git a/layout/style/ServoSpecifiedValues.h b/layout/style/ServoSpecifiedValues.h index 7b66ae64ac05..e53891bc6a98 100644 --- a/layout/style/ServoSpecifiedValues.h +++ b/layout/style/ServoSpecifiedValues.h @@ -24,81 +24,80 @@ public: ServoSpecifiedValues(nsPresContext* aContext, RawServoDeclarationBlock* aDecl); // GenericSpecifiedValues overrides - bool PropertyIsSet(nsCSSPropertyID aId) { - return false; - } + bool PropertyIsSet(nsCSSPropertyID aId); void SetIdentStringValue(nsCSSPropertyID aId, - const nsString& aValue) { - - } + const nsString& aValue); void SetIdentStringValueIfUnset(nsCSSPropertyID aId, const nsString& aValue) { - + if (!PropertyIsSet(aId)) { + SetIdentStringValue(aId, aValue); + } } void SetKeywordValue(nsCSSPropertyID aId, - int32_t aValue) { - } + int32_t aValue); void SetKeywordValueIfUnset(nsCSSPropertyID aId, int32_t aValue) { - + if (!PropertyIsSet(aId)) { + SetKeywordValue(aId, aValue); + } } void SetIntValue(nsCSSPropertyID aId, - int32_t aValue) { - } + int32_t aValue); void SetPixelValue(nsCSSPropertyID aId, - float aValue) { - } + float aValue); void SetPixelValueIfUnset(nsCSSPropertyID aId, float aValue) { + if (!PropertyIsSet(aId)) { + SetPixelValue(aId, aValue); + } } void SetPercentValue(nsCSSPropertyID aId, - float aValue) { - } + float aValue); - void SetAutoValue(nsCSSPropertyID aId) { - } + void SetAutoValue(nsCSSPropertyID aId); void SetAutoValueIfUnset(nsCSSPropertyID aId) { + if (!PropertyIsSet(aId)) { + SetAutoValue(aId); + } } void SetPercentValueIfUnset(nsCSSPropertyID aId, float aValue) { - + if (!PropertyIsSet(aId)) { + SetPercentValue(aId, aValue); + } } - void SetCurrentColor(nsCSSPropertyID aId) { - - } + void SetCurrentColor(nsCSSPropertyID aId); void SetCurrentColorIfUnset(nsCSSPropertyID aId) { - + if (!PropertyIsSet(aId)) { + SetCurrentColor(aId); + } } void SetColorValue(nsCSSPropertyID aId, - nscolor aValue) { - - } + nscolor aValue); void SetColorValueIfUnset(nsCSSPropertyID aId, nscolor aValue) { - + if (!PropertyIsSet(aId)) { + SetColorValue(aId, aValue); + } } - void SetFontFamily(const nsString& aValue) { - - } - void SetTextDecorationColorOverride() { - - } + void SetFontFamily(const nsString& aValue); + void SetTextDecorationColorOverride(); private: RefPtr mDecl;