зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1323147 part 1 - Pass string and nsCSSPropertyID for property names across FFI. r=heycam,SimonSapin
MozReview-Commit-ID: 9m39cqaFfx --HG-- extra : source : fda47b4012965e9e767bad8a87e9b0b1a165d13a
This commit is contained in:
Родитель
404ab8e119
Коммит
200763a985
|
@ -1024,12 +1024,9 @@ KeyframeEffectReadOnly::GetKeyframes(JSContext*& aCx,
|
|||
for (const PropertyValuePair& propertyValue : keyframe.mPropertyValues) {
|
||||
nsAutoString stringValue;
|
||||
if (propertyValue.mServoDeclarationBlock) {
|
||||
// FIXME: When we support animations for custom properties on servo, we
|
||||
// should pass the flag to Servo_DeclarationBlock_SerializeOneValue.
|
||||
// Now, we pass false to simplify it.
|
||||
nsIAtom* atom = nsCSSProps::AtomForProperty(propertyValue.mProperty);
|
||||
Servo_DeclarationBlock_SerializeOneValue(
|
||||
propertyValue.mServoDeclarationBlock, atom, false, &stringValue);
|
||||
propertyValue.mServoDeclarationBlock,
|
||||
propertyValue.mProperty, &stringValue);
|
||||
} else {
|
||||
// nsCSSValue::AppendToString does not accept shorthands properties but
|
||||
// works with token stream values if we pass eCSSProperty_UNKNOWN as
|
||||
|
|
|
@ -101,7 +101,7 @@ SERVO_BINDING_FUNC(Servo_DeclarationBlock_GetCssText, void,
|
|||
nsAString* result)
|
||||
SERVO_BINDING_FUNC(Servo_DeclarationBlock_SerializeOneValue, void,
|
||||
RawServoDeclarationBlockBorrowed declarations,
|
||||
nsIAtom* property, bool is_custom, nsAString* buffer)
|
||||
nsCSSPropertyID property, nsAString* buffer)
|
||||
SERVO_BINDING_FUNC(Servo_DeclarationBlock_Count, uint32_t,
|
||||
RawServoDeclarationBlockBorrowed declarations)
|
||||
SERVO_BINDING_FUNC(Servo_DeclarationBlock_GetNthProperty, bool,
|
||||
|
@ -109,17 +109,27 @@ SERVO_BINDING_FUNC(Servo_DeclarationBlock_GetNthProperty, bool,
|
|||
uint32_t index, nsAString* result)
|
||||
SERVO_BINDING_FUNC(Servo_DeclarationBlock_GetPropertyValue, void,
|
||||
RawServoDeclarationBlockBorrowed declarations,
|
||||
nsIAtom* property, bool is_custom, nsAString* value)
|
||||
const nsACString* property, nsAString* value)
|
||||
SERVO_BINDING_FUNC(Servo_DeclarationBlock_GetPropertyValueById, void,
|
||||
RawServoDeclarationBlockBorrowed declarations,
|
||||
nsCSSPropertyID property, nsAString* value)
|
||||
SERVO_BINDING_FUNC(Servo_DeclarationBlock_GetPropertyIsImportant, bool,
|
||||
RawServoDeclarationBlockBorrowed declarations,
|
||||
nsIAtom* property, bool is_custom)
|
||||
const nsACString* property)
|
||||
SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetProperty, bool,
|
||||
RawServoDeclarationBlockBorrowed declarations,
|
||||
nsIAtom* property, bool is_custom,
|
||||
const nsACString* property,
|
||||
nsACString* value, bool is_important)
|
||||
SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetPropertyById, bool,
|
||||
RawServoDeclarationBlockBorrowed declarations,
|
||||
nsCSSPropertyID property,
|
||||
nsACString* value, bool is_important)
|
||||
SERVO_BINDING_FUNC(Servo_DeclarationBlock_RemoveProperty, void,
|
||||
RawServoDeclarationBlockBorrowed declarations,
|
||||
nsIAtom* property, bool is_custom)
|
||||
const nsACString* property)
|
||||
SERVO_BINDING_FUNC(Servo_DeclarationBlock_RemovePropertyById, void,
|
||||
RawServoDeclarationBlockBorrowed declarations,
|
||||
nsCSSPropertyID property)
|
||||
|
||||
// CSS supports()
|
||||
SERVO_BINDING_FUNC(Servo_CSSSupports, bool,
|
||||
|
|
|
@ -21,90 +21,41 @@ ServoDeclarationBlock::FromCssText(const nsAString& aCssText)
|
|||
return decl.forget();
|
||||
}
|
||||
|
||||
/**
|
||||
* An RAII class holding an atom for the given property.
|
||||
*/
|
||||
class MOZ_STACK_CLASS PropertyAtomHolder
|
||||
{
|
||||
public:
|
||||
explicit PropertyAtomHolder(const nsAString& aProperty)
|
||||
{
|
||||
nsCSSPropertyID propID =
|
||||
nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
|
||||
if (propID == eCSSPropertyExtra_variable) {
|
||||
mIsCustomProperty = true;
|
||||
mAtom = NS_Atomize(
|
||||
Substring(aProperty, CSS_CUSTOM_NAME_PREFIX_LENGTH)).take();
|
||||
} else {
|
||||
mIsCustomProperty = false;
|
||||
if (propID != eCSSProperty_UNKNOWN) {
|
||||
mAtom = nsCSSProps::AtomForProperty(propID);
|
||||
} else {
|
||||
mAtom = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~PropertyAtomHolder()
|
||||
{
|
||||
if (mIsCustomProperty) {
|
||||
NS_RELEASE(mAtom);
|
||||
}
|
||||
}
|
||||
|
||||
explicit operator bool() const { return !!mAtom; }
|
||||
nsIAtom* Atom() const { MOZ_ASSERT(mAtom); return mAtom; }
|
||||
bool IsCustomProperty() const { return mIsCustomProperty; }
|
||||
|
||||
private:
|
||||
nsIAtom* mAtom;
|
||||
bool mIsCustomProperty;
|
||||
};
|
||||
|
||||
void
|
||||
ServoDeclarationBlock::GetPropertyValue(const nsAString& aProperty,
|
||||
nsAString& aValue) const
|
||||
{
|
||||
if (PropertyAtomHolder holder{aProperty}) {
|
||||
Servo_DeclarationBlock_GetPropertyValue(
|
||||
mRaw, holder.Atom(), holder.IsCustomProperty(), &aValue);
|
||||
}
|
||||
NS_ConvertUTF16toUTF8 property(aProperty);
|
||||
Servo_DeclarationBlock_GetPropertyValue(mRaw, &property, &aValue);
|
||||
}
|
||||
|
||||
void
|
||||
ServoDeclarationBlock::GetPropertyValueByID(nsCSSPropertyID aPropID,
|
||||
nsAString& aValue) const
|
||||
{
|
||||
nsIAtom* atom = nsCSSProps::AtomForProperty(aPropID);
|
||||
Servo_DeclarationBlock_GetPropertyValue(mRaw, atom, false, &aValue);
|
||||
Servo_DeclarationBlock_GetPropertyValueById(mRaw, aPropID, &aValue);
|
||||
}
|
||||
|
||||
bool
|
||||
ServoDeclarationBlock::GetPropertyIsImportant(const nsAString& aProperty) const
|
||||
{
|
||||
if (PropertyAtomHolder holder{aProperty}) {
|
||||
return Servo_DeclarationBlock_GetPropertyIsImportant(
|
||||
mRaw, holder.Atom(), holder.IsCustomProperty());
|
||||
}
|
||||
return false;
|
||||
NS_ConvertUTF16toUTF8 property(aProperty);
|
||||
return Servo_DeclarationBlock_GetPropertyIsImportant(mRaw, &property);
|
||||
}
|
||||
|
||||
void
|
||||
ServoDeclarationBlock::RemoveProperty(const nsAString& aProperty)
|
||||
{
|
||||
AssertMutable();
|
||||
if (PropertyAtomHolder holder{aProperty}) {
|
||||
Servo_DeclarationBlock_RemoveProperty(mRaw, holder.Atom(),
|
||||
holder.IsCustomProperty());
|
||||
}
|
||||
NS_ConvertUTF16toUTF8 property(aProperty);
|
||||
Servo_DeclarationBlock_RemoveProperty(mRaw, &property);
|
||||
}
|
||||
|
||||
void
|
||||
ServoDeclarationBlock::RemovePropertyByID(nsCSSPropertyID aPropID)
|
||||
{
|
||||
AssertMutable();
|
||||
nsIAtom* atom = nsCSSProps::AtomForProperty(aPropID);
|
||||
Servo_DeclarationBlock_RemoveProperty(mRaw, atom, false);
|
||||
Servo_DeclarationBlock_RemovePropertyById(mRaw, aPropID);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -305,10 +305,9 @@ nsDOMCSSDeclaration::ParsePropertyValue(const nsCSSPropertyID aPropID,
|
|||
env.mSheetURI, env.mBaseURI, env.mPrincipal,
|
||||
decl->AsGecko(), &changed, aIsImportant);
|
||||
} else {
|
||||
nsIAtom* atom = nsCSSProps::AtomForProperty(aPropID);
|
||||
NS_ConvertUTF16toUTF8 value(aPropValue);
|
||||
changed = Servo_DeclarationBlock_SetProperty(
|
||||
decl->AsServo()->Raw(), atom, false, &value, aIsImportant);
|
||||
changed = Servo_DeclarationBlock_SetPropertyById(
|
||||
decl->AsServo()->Raw(), aPropID, &value, aIsImportant);
|
||||
}
|
||||
if (!changed) {
|
||||
// Parsing failed -- but we don't throw an exception for that.
|
||||
|
@ -345,17 +344,17 @@ nsDOMCSSDeclaration::ParseCustomPropertyValue(const nsAString& aPropertyName,
|
|||
RefPtr<DeclarationBlock> decl = olddecl->EnsureMutable();
|
||||
|
||||
bool changed;
|
||||
auto propName = Substring(aPropertyName, CSS_CUSTOM_NAME_PREFIX_LENGTH);
|
||||
if (decl->IsGecko()) {
|
||||
nsCSSParser cssParser(env.mCSSLoader);
|
||||
auto propName = Substring(aPropertyName, CSS_CUSTOM_NAME_PREFIX_LENGTH);
|
||||
cssParser.ParseVariable(propName, aPropValue, env.mSheetURI,
|
||||
env.mBaseURI, env.mPrincipal, decl->AsGecko(),
|
||||
&changed, aIsImportant);
|
||||
} else {
|
||||
RefPtr<nsIAtom> atom = NS_Atomize(propName);
|
||||
NS_ConvertUTF16toUTF8 property(aPropertyName);
|
||||
NS_ConvertUTF16toUTF8 value(aPropValue);
|
||||
changed = Servo_DeclarationBlock_SetProperty(
|
||||
decl->AsServo()->Raw(), atom, true, &value, aIsImportant);
|
||||
decl->AsServo()->Raw(), &property, &value, aIsImportant);
|
||||
}
|
||||
if (!changed) {
|
||||
// Parsing failed -- but we don't throw an exception for that.
|
||||
|
|
Загрузка…
Ссылка в новой задаче