mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Bug 1062106 part 3 - Remove SMIL MappedAttribute mechanism. r=birtles
We can remove unnecesasary SMILMappedAttribute and SMILAttrAnimationRuleProcessor since earlier patches in this serieas mean this code is no longer used. MozReview-Commit-ID: 5Rl5WFW5zZ1 --HG-- extra : rebase_source : cf2efca8d01c7e6cd5bd3b3b44d994c6cbb760e9
This commit is contained in:
parent
90f3d3d4d0
commit
2558f6837e
@ -282,7 +282,6 @@ private:
|
||||
// Categories of node properties
|
||||
// 0 is global.
|
||||
#define DOM_USER_DATA 1
|
||||
#define SMIL_MAPPED_ATTR_ANIMVAL 2
|
||||
|
||||
// IID for the nsINode interface
|
||||
#define NS_INODE_IID \
|
||||
|
@ -19,7 +19,6 @@ EXPORTS += [
|
||||
'nsSMILInstanceTime.h',
|
||||
'nsSMILInterval.h',
|
||||
'nsSMILKeySpline.h',
|
||||
'nsSMILMappedAttribute.h',
|
||||
'nsSMILMilestone.h',
|
||||
'nsSMILNullType.h',
|
||||
'nsSMILRepeatCount.h',
|
||||
@ -48,7 +47,6 @@ UNIFIED_SOURCES += [
|
||||
'nsSMILInstanceTime.cpp',
|
||||
'nsSMILInterval.cpp',
|
||||
'nsSMILKeySpline.cpp',
|
||||
'nsSMILMappedAttribute.cpp',
|
||||
'nsSMILNullType.cpp',
|
||||
'nsSMILParserUtils.cpp',
|
||||
'nsSMILRepeatCount.cpp',
|
||||
|
@ -1,150 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
/* representation of a SMIL-animatable mapped attribute on an element */
|
||||
#include "nsSMILMappedAttribute.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsError.h" // For NS_PROPTABLE_PROP_OVERWRITTEN
|
||||
#include "nsSMILValue.h"
|
||||
#include "nsSMILCSSValueType.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsCSSProps.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
|
||||
// Callback function, for freeing string buffers stored in property table
|
||||
static void
|
||||
ReleaseStringBufferPropertyValue(void* aObject, /* unused */
|
||||
nsIAtom* aPropertyName, /* unused */
|
||||
void* aPropertyValue,
|
||||
void* aData /* unused */)
|
||||
{
|
||||
nsStringBuffer* buf = static_cast<nsStringBuffer*>(aPropertyValue);
|
||||
buf->Release();
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsSMILMappedAttribute::ValueFromString(const nsAString& aStr,
|
||||
const mozilla::dom::SVGAnimationElement* aSrcElement,
|
||||
nsSMILValue& aValue,
|
||||
bool& aPreventCachingOfSandwich) const
|
||||
{
|
||||
NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE);
|
||||
|
||||
nsSMILCSSValueType::ValueFromString(mPropID, mElement, aStr, aValue,
|
||||
&aPreventCachingOfSandwich);
|
||||
return aValue.IsNull() ? NS_ERROR_FAILURE : NS_OK;
|
||||
}
|
||||
|
||||
nsSMILValue
|
||||
nsSMILMappedAttribute::GetBaseValue() const
|
||||
{
|
||||
nsAutoString baseStringValue;
|
||||
RefPtr<nsIAtom> attrName = GetAttrNameAtom();
|
||||
bool success = mElement->GetAttr(kNameSpaceID_None, attrName,
|
||||
baseStringValue);
|
||||
nsSMILValue baseValue;
|
||||
if (success) {
|
||||
// For base values, we don't need to worry whether the value returned is
|
||||
// context-sensitive or not since the compositor will take care of comparing
|
||||
// the returned (computed) base value and its cached value and determining
|
||||
// if an update is required or not.
|
||||
nsSMILCSSValueType::ValueFromString(mPropID, mElement,
|
||||
baseStringValue, baseValue, nullptr);
|
||||
} else {
|
||||
// Attribute is unset -- use computed value.
|
||||
// FIRST: Temporarily clear animated value, to make sure it doesn't pollute
|
||||
// the computed value. (We want base value, _without_ animations applied.)
|
||||
void* buf = mElement->UnsetProperty(SMIL_MAPPED_ATTR_ANIMVAL,
|
||||
attrName, nullptr);
|
||||
FlushChangesToTargetAttr();
|
||||
|
||||
// SECOND: we use nsSMILCSSProperty::GetBaseValue to look up the property's
|
||||
// computed value. NOTE: This call will temporarily clear the SMIL
|
||||
// override-style for the corresponding CSS property on our target element.
|
||||
// This prevents any animations that target the CSS property from affecting
|
||||
// animations that target the mapped attribute.
|
||||
baseValue = nsSMILCSSProperty::GetBaseValue();
|
||||
|
||||
// FINALLY: If we originally had an animated value set, then set it again.
|
||||
if (buf) {
|
||||
mElement->SetProperty(SMIL_MAPPED_ATTR_ANIMVAL, attrName, buf,
|
||||
ReleaseStringBufferPropertyValue);
|
||||
FlushChangesToTargetAttr();
|
||||
}
|
||||
}
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSMILMappedAttribute::SetAnimValue(const nsSMILValue& aValue)
|
||||
{
|
||||
NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE);
|
||||
|
||||
// Convert nsSMILValue to string
|
||||
nsAutoString valStr;
|
||||
if (!nsSMILCSSValueType::ValueToString(aValue, valStr)) {
|
||||
NS_WARNING("Failed to convert nsSMILValue for mapped attr into a string");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
RefPtr<nsIAtom> attrName = GetAttrNameAtom();
|
||||
nsStringBuffer* oldValStrBuf = static_cast<nsStringBuffer*>
|
||||
(mElement->GetProperty(SMIL_MAPPED_ATTR_ANIMVAL, attrName));
|
||||
if (oldValStrBuf) {
|
||||
nsString oldValStr;
|
||||
nsContentUtils::PopulateStringFromStringBuffer(oldValStrBuf, oldValStr);
|
||||
if (valStr.Equals(oldValStr)) {
|
||||
// New animated value is the same as the old; nothing to do.
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the string as this mapped attribute's animated value.
|
||||
nsStringBuffer* valStrBuf =
|
||||
nsCSSValue::BufferFromString(nsString(valStr)).take();
|
||||
nsresult rv = mElement->SetProperty(SMIL_MAPPED_ATTR_ANIMVAL,
|
||||
attrName, valStrBuf,
|
||||
ReleaseStringBufferPropertyValue);
|
||||
if (rv == NS_PROPTABLE_PROP_OVERWRITTEN) {
|
||||
rv = NS_OK;
|
||||
}
|
||||
FlushChangesToTargetAttr();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
nsSMILMappedAttribute::ClearAnimValue()
|
||||
{
|
||||
RefPtr<nsIAtom> attrName = GetAttrNameAtom();
|
||||
mElement->DeleteProperty(SMIL_MAPPED_ATTR_ANIMVAL, attrName);
|
||||
FlushChangesToTargetAttr();
|
||||
}
|
||||
|
||||
void
|
||||
nsSMILMappedAttribute::FlushChangesToTargetAttr() const
|
||||
{
|
||||
// Clear animated content-style-rule
|
||||
mElement->DeleteProperty(SMIL_MAPPED_ATTR_ANIMVAL,
|
||||
SMIL_MAPPED_ATTR_STYLEDECL_ATOM);
|
||||
nsIDocument* doc = mElement->GetUncomposedDoc();
|
||||
|
||||
// Request animation restyle
|
||||
if (doc) {
|
||||
nsIPresShell* shell = doc->GetShell();
|
||||
if (shell) {
|
||||
shell->RestyleForAnimation(mElement, eRestyle_Self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<nsIAtom>
|
||||
nsSMILMappedAttribute::GetAttrNameAtom() const
|
||||
{
|
||||
return NS_Atomize(nsCSSProps::GetStringValue(mPropID));
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
/* representation of a SMIL-animatable mapped attribute on an element */
|
||||
|
||||
#ifndef NS_SMILMAPPEDATTRIBUTE_H_
|
||||
#define NS_SMILMAPPEDATTRIBUTE_H_
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsSMILCSSProperty.h"
|
||||
|
||||
/* We'll use the empty-string atom |nsGkAtoms::_empty| as the key for storing an
|
||||
* element's animated content style declaration in its Property Table, under the
|
||||
* property-category SMIL_MAPPED_ATTR_ANIMVAL. Everything else stored in that
|
||||
* category is keyed off of the XML attribute name, so the empty string is a
|
||||
* good "reserved" key to use for storing the style rule (since XML attributes
|
||||
* all have nonempty names).
|
||||
*/
|
||||
#define SMIL_MAPPED_ATTR_STYLEDECL_ATOM nsGkAtoms::_empty
|
||||
|
||||
/**
|
||||
* nsSMILMappedAttribute: Implements the nsISMILAttr interface for SMIL
|
||||
* animations whose targets are attributes that map to CSS properties. An
|
||||
* instance of this class represents a particular animation-targeted mapped
|
||||
* attribute on a particular element.
|
||||
*/
|
||||
class nsSMILMappedAttribute : public nsSMILCSSProperty {
|
||||
public:
|
||||
/**
|
||||
* Constructs a new nsSMILMappedAttribute.
|
||||
*
|
||||
* @param aPropID The CSS property for the mapped attribute we're
|
||||
* interested in animating.
|
||||
* @param aElement The element whose attribute is being animated.
|
||||
*/
|
||||
nsSMILMappedAttribute(nsCSSPropertyID aPropID, mozilla::dom::Element* aElement) :
|
||||
nsSMILCSSProperty(aPropID, aElement) {}
|
||||
|
||||
// nsISMILAttr methods
|
||||
virtual nsresult ValueFromString(const nsAString& aStr,
|
||||
const mozilla::dom::SVGAnimationElement* aSrcElement,
|
||||
nsSMILValue& aValue,
|
||||
bool& aPreventCachingOfSandwich) const override;
|
||||
virtual nsSMILValue GetBaseValue() const override;
|
||||
virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
|
||||
virtual void ClearAnimValue() override;
|
||||
|
||||
protected:
|
||||
// Helper Methods
|
||||
void FlushChangesToTargetAttr() const;
|
||||
already_AddRefed<nsIAtom> GetAttrNameAtom() const;
|
||||
};
|
||||
#endif // NS_SMILMAPPEDATTRIBUTE_H_
|
@ -11,6 +11,8 @@
|
||||
|
||||
#include "mozilla/AutoRestore.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
nsSMILTimeContainer::nsSMILTimeContainer()
|
||||
:
|
||||
mParent(nullptr),
|
||||
|
@ -47,7 +47,6 @@
|
||||
#include "nsIFrame.h"
|
||||
#include "nsQueryObject.h"
|
||||
#include <stdarg.h>
|
||||
#include "nsSMILMappedAttribute.h"
|
||||
#include "SVGMotionSMILAttr.h"
|
||||
#include "nsAttrValueOrString.h"
|
||||
#include "nsSMILAnimationController.h"
|
||||
@ -934,34 +933,6 @@ nsSVGElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsSVGElement::WalkAnimatedContentStyleRules(nsRuleWalker* aRuleWalker)
|
||||
{
|
||||
// Update & walk the animated content style rule, to include style from
|
||||
// animated mapped attributes. But first, get nsPresContext to check
|
||||
// whether this is a "no-animation restyle". (This should match the check
|
||||
// in nsHTMLCSSStyleSheet::RulesMatching(), where we determine whether to
|
||||
// apply the SMILOverrideStyle.)
|
||||
RestyleManager* restyleManager =
|
||||
aRuleWalker->PresContext()->RestyleManager();
|
||||
MOZ_ASSERT(restyleManager->IsGecko(),
|
||||
"stylo: Servo-backed style system should not be calling "
|
||||
"WalkAnimatedContentStyleRules");
|
||||
if (!restyleManager->AsGecko()->SkipAnimationRules()) {
|
||||
// update/walk the animated content style rule.
|
||||
DeclarationBlock* animContentDeclBlock = GetAnimatedContentDeclarationBlock();
|
||||
if (!animContentDeclBlock) {
|
||||
UpdateAnimatedContentDeclarationBlock();
|
||||
animContentDeclBlock = GetAnimatedContentDeclarationBlock();
|
||||
}
|
||||
if (animContentDeclBlock) {
|
||||
css::Declaration* declaration = animContentDeclBlock->AsGecko();
|
||||
declaration->SetImmutable();
|
||||
aRuleWalker->Forward(declaration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(bool)
|
||||
nsSVGElement::IsAttributeMapped(const nsIAtom* name) const
|
||||
{
|
||||
@ -1381,85 +1352,6 @@ nsSVGElement::GetContentDeclarationBlock() const
|
||||
return mContentDeclarationBlock;
|
||||
}
|
||||
|
||||
static void
|
||||
ParseMappedAttrAnimValueCallback(void* aObject,
|
||||
nsIAtom* aPropertyName,
|
||||
void* aPropertyValue,
|
||||
void* aData)
|
||||
{
|
||||
MOZ_ASSERT(aPropertyName != SMIL_MAPPED_ATTR_STYLEDECL_ATOM,
|
||||
"animated content style rule should have been removed "
|
||||
"from properties table already (we're rebuilding it now)");
|
||||
|
||||
MappedAttrParser* mappedAttrParser = static_cast<MappedAttrParser*>(aData);
|
||||
MOZ_ASSERT(mappedAttrParser, "parser should be non-null");
|
||||
|
||||
nsStringBuffer* animValBuf = static_cast<nsStringBuffer*>(aPropertyValue);
|
||||
MOZ_ASSERT(animValBuf, "animated value should be non-null");
|
||||
|
||||
nsString animValStr;
|
||||
nsContentUtils::PopulateStringFromStringBuffer(animValBuf, animValStr);
|
||||
|
||||
mappedAttrParser->ParseMappedAttrValue(aPropertyName, animValStr);
|
||||
}
|
||||
|
||||
// Callback for freeing animated content decl block, in property table.
|
||||
static void
|
||||
ReleaseDeclBlock(void* aObject, /* unused */
|
||||
nsIAtom* aPropertyName,
|
||||
void* aPropertyValue,
|
||||
void* aData /* unused */)
|
||||
{
|
||||
MOZ_ASSERT(aPropertyName == SMIL_MAPPED_ATTR_STYLEDECL_ATOM,
|
||||
"unexpected property name, for animated content style rule");
|
||||
auto decl = static_cast<DeclarationBlock*>(aPropertyValue);
|
||||
MOZ_ASSERT(decl, "unexpected null decl");
|
||||
decl->Release();
|
||||
}
|
||||
|
||||
void
|
||||
nsSVGElement::UpdateAnimatedContentDeclarationBlock()
|
||||
{
|
||||
MOZ_ASSERT(!GetAnimatedContentDeclarationBlock(),
|
||||
"Animated content declaration block already set");
|
||||
|
||||
nsIDocument* doc = OwnerDoc();
|
||||
if (!doc) {
|
||||
NS_ERROR("SVG element without owner document");
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME (bug 1342557): Support SMIL in Servo
|
||||
MappedAttrParser mappedAttrParser(doc->CSSLoader(), doc->GetDocumentURI(),
|
||||
GetBaseURI(), this, StyleBackendType::Gecko);
|
||||
doc->PropertyTable(SMIL_MAPPED_ATTR_ANIMVAL)->
|
||||
Enumerate(this, ParseMappedAttrAnimValueCallback, &mappedAttrParser);
|
||||
|
||||
RefPtr<DeclarationBlock> animContentDeclBlock =
|
||||
mappedAttrParser.GetDeclarationBlock();
|
||||
|
||||
if (animContentDeclBlock) {
|
||||
#ifdef DEBUG
|
||||
nsresult rv =
|
||||
#endif
|
||||
SetProperty(SMIL_MAPPED_ATTR_ANIMVAL,
|
||||
SMIL_MAPPED_ATTR_STYLEDECL_ATOM,
|
||||
animContentDeclBlock.forget().take(),
|
||||
ReleaseDeclBlock);
|
||||
MOZ_ASSERT(rv == NS_OK,
|
||||
"SetProperty failed (or overwrote something)");
|
||||
}
|
||||
}
|
||||
|
||||
DeclarationBlock*
|
||||
nsSVGElement::GetAnimatedContentDeclarationBlock()
|
||||
{
|
||||
return
|
||||
static_cast<DeclarationBlock*>(GetProperty(SMIL_MAPPED_ATTR_ANIMVAL,
|
||||
SMIL_MAPPED_ATTR_STYLEDECL_ATOM,
|
||||
nullptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper methods for the type-specific WillChangeXXX methods.
|
||||
*
|
||||
|
@ -357,9 +357,6 @@ protected:
|
||||
nsIAtom* aAttribute,
|
||||
const nsAString& aValue);
|
||||
|
||||
void UpdateAnimatedContentDeclarationBlock();
|
||||
mozilla::DeclarationBlock* GetAnimatedContentDeclarationBlock();
|
||||
|
||||
nsAttrValue WillChangeValue(nsIAtom* aName);
|
||||
// aNewValue is set to the old value. This value may be invalid if
|
||||
// !StoresOwnData.
|
||||
|
Loading…
Reference in New Issue
Block a user