2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2010-03-16 23:17:33 +00:00
|
|
|
|
|
|
|
/* representation of a SMIL-animatable mapped attribute on an element */
|
|
|
|
#include "nsSMILMappedAttribute.h"
|
2013-09-10 17:03:28 +00:00
|
|
|
#include "nsContentUtils.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h" // For NS_PROPTABLE_PROP_OVERWRITTEN
|
2010-03-16 23:17:33 +00:00
|
|
|
#include "nsSMILValue.h"
|
|
|
|
#include "nsSMILCSSValueType.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsCSSProps.h"
|
2011-07-20 19:18:54 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-03-16 23:17:33 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2010-04-02 16:34:31 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILMappedAttribute::ValueFromString(const nsAString& aStr,
|
2013-03-19 03:18:45 +00:00
|
|
|
const mozilla::dom::SVGAnimationElement* aSrcElement,
|
2010-04-02 16:34:31 +00:00
|
|
|
nsSMILValue& aValue,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool& aPreventCachingOfSandwich) const
|
2010-04-02 16:34:31 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE);
|
|
|
|
|
2011-08-22 23:34:03 +00:00
|
|
|
nsSMILCSSValueType::ValueFromString(mPropID, mElement, aStr, aValue,
|
|
|
|
&aPreventCachingOfSandwich);
|
|
|
|
return aValue.IsNull() ? NS_ERROR_FAILURE : NS_OK;
|
2010-04-02 16:34:31 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 23:17:33 +00:00
|
|
|
nsSMILValue
|
|
|
|
nsSMILMappedAttribute::GetBaseValue() const
|
|
|
|
{
|
|
|
|
nsAutoString baseStringValue;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsIAtom> attrName = GetAttrNameAtom();
|
2011-09-29 06:19:26 +00:00
|
|
|
bool success = mElement->GetAttr(kNameSpaceID_None, attrName,
|
2010-03-16 23:17:33 +00:00
|
|
|
baseStringValue);
|
|
|
|
nsSMILValue baseValue;
|
|
|
|
if (success) {
|
2011-08-22 23:34:03 +00:00
|
|
|
// 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.
|
2010-06-09 19:51:31 +00:00
|
|
|
nsSMILCSSValueType::ValueFromString(mPropID, mElement,
|
2012-07-30 14:20:58 +00:00
|
|
|
baseStringValue, baseValue, nullptr);
|
2010-03-16 23:17:33 +00:00
|
|
|
} 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,
|
2012-07-30 14:20:58 +00:00
|
|
|
attrName, nullptr);
|
2010-03-16 23:17:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsIAtom> attrName = GetAttrNameAtom();
|
2012-06-01 23:53:57 +00:00
|
|
|
nsStringBuffer* oldValStrBuf = static_cast<nsStringBuffer*>
|
|
|
|
(mElement->GetProperty(SMIL_MAPPED_ATTR_ANIMVAL, attrName));
|
2013-09-10 17:03:28 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-06-01 23:53:57 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 23:17:33 +00:00
|
|
|
// Set the string as this mapped attribute's animated value.
|
2010-12-05 13:17:29 +00:00
|
|
|
nsStringBuffer* valStrBuf =
|
2014-03-15 19:00:15 +00:00
|
|
|
nsCSSValue::BufferFromString(nsString(valStr)).take();
|
2010-03-16 23:17:33 +00:00
|
|
|
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()
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsIAtom> attrName = GetAttrNameAtom();
|
2010-05-20 14:41:00 +00:00
|
|
|
mElement->DeleteProperty(SMIL_MAPPED_ATTR_ANIMVAL, attrName);
|
|
|
|
FlushChangesToTargetAttr();
|
2010-03-16 23:17:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILMappedAttribute::FlushChangesToTargetAttr() const
|
|
|
|
{
|
|
|
|
// Clear animated content-style-rule
|
|
|
|
mElement->DeleteProperty(SMIL_MAPPED_ATTR_ANIMVAL,
|
|
|
|
SMIL_MAPPED_ATTR_STYLERULE_ATOM);
|
|
|
|
nsIDocument* doc = mElement->GetCurrentDoc();
|
|
|
|
|
|
|
|
// Request animation restyle
|
|
|
|
if (doc) {
|
2010-06-25 13:59:57 +00:00
|
|
|
nsIPresShell* shell = doc->GetShell();
|
2010-03-16 23:17:33 +00:00
|
|
|
if (shell) {
|
2010-07-01 01:54:29 +00:00
|
|
|
shell->RestyleForAnimation(mElement, eRestyle_Self);
|
2010-03-16 23:17:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIAtom>
|
|
|
|
nsSMILMappedAttribute::GetAttrNameAtom() const
|
|
|
|
{
|
|
|
|
return do_GetAtom(nsCSSProps::GetStringValue(mPropID));
|
|
|
|
}
|