2009-10-02 21:37:25 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2009-10-02 21:37:25 +00:00
|
|
|
|
|
|
|
/* representation of a SMIL-animatable CSS property on an element */
|
|
|
|
|
|
|
|
#include "nsSMILCSSProperty.h"
|
|
|
|
#include "nsSMILCSSValueType.h"
|
|
|
|
#include "nsSMILValue.h"
|
|
|
|
#include "nsComputedDOMStyle.h"
|
2013-03-03 00:31:48 +00:00
|
|
|
#include "nsCSSProps.h"
|
2009-10-02 21:37:25 +00:00
|
|
|
#include "nsStyleAnimation.h"
|
2011-03-28 16:51:59 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-01-06 17:20:50 +00:00
|
|
|
#include "nsIDOMElement.h"
|
2013-10-02 20:09:18 +00:00
|
|
|
#include "nsIDocument.h"
|
2009-10-02 21:37:25 +00:00
|
|
|
|
2010-05-14 17:04:51 +00:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2010-02-02 02:46:13 +00:00
|
|
|
// Helper function
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2012-07-06 12:28:33 +00:00
|
|
|
GetCSSComputedValue(Element* aElem,
|
2009-10-02 21:37:25 +00:00
|
|
|
nsCSSProperty aPropID,
|
|
|
|
nsAString& aResult)
|
|
|
|
{
|
2010-02-02 02:46:13 +00:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aPropID),
|
|
|
|
"Can't look up computed value of shorthand property");
|
|
|
|
NS_ABORT_IF_FALSE(nsSMILCSSProperty::IsPropertyAnimatable(aPropID),
|
|
|
|
"Shouldn't get here for non-animatable properties");
|
2009-10-02 21:37:25 +00:00
|
|
|
|
|
|
|
nsIDocument* doc = aElem->GetCurrentDoc();
|
2009-12-24 00:19:29 +00:00
|
|
|
if (!doc) {
|
|
|
|
// This can happen if we process certain types of restyles mid-sample
|
|
|
|
// and remove anonymous animated content from the document as a result.
|
|
|
|
// See bug 534975.
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-12-24 00:19:29 +00:00
|
|
|
}
|
2009-11-01 00:06:47 +00:00
|
|
|
|
2010-06-25 13:59:57 +00:00
|
|
|
nsIPresShell* shell = doc->GetShell();
|
2010-01-06 17:20:50 +00:00
|
|
|
if (!shell) {
|
|
|
|
NS_WARNING("Unable to look up computed style -- no pres shell");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-01-06 17:20:50 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 12:28:33 +00:00
|
|
|
nsRefPtr<nsComputedDOMStyle> computedStyle =
|
|
|
|
NS_NewComputedDOMStyle(aElem, EmptyString(), shell);
|
2010-01-06 17:20:50 +00:00
|
|
|
|
2012-07-06 12:28:33 +00:00
|
|
|
computedStyle->GetPropertyValue(aPropID, aResult);
|
|
|
|
return true;
|
2009-10-02 21:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Class Methods
|
|
|
|
nsSMILCSSProperty::nsSMILCSSProperty(nsCSSProperty aPropID,
|
2010-05-14 17:04:51 +00:00
|
|
|
Element* aElement)
|
2009-10-02 21:37:25 +00:00
|
|
|
: mPropID(aPropID), mElement(aElement)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(IsPropertyAnimatable(mPropID),
|
|
|
|
"Creating a nsSMILCSSProperty for a property "
|
|
|
|
"that's not supported for animation");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILValue
|
|
|
|
nsSMILCSSProperty::GetBaseValue() const
|
|
|
|
{
|
2010-03-26 19:24:13 +00:00
|
|
|
// To benefit from Return Value Optimization and avoid copy constructor calls
|
|
|
|
// due to our use of return-by-value, we must return the exact same object
|
|
|
|
// from ALL return points. This function must only return THIS variable:
|
|
|
|
nsSMILValue baseValue;
|
|
|
|
|
2010-11-09 23:21:03 +00:00
|
|
|
// SPECIAL CASE: (a) Shorthands
|
|
|
|
// (b) 'display'
|
|
|
|
if (nsCSSProps::IsShorthand(mPropID) || mPropID == eCSSProperty_display) {
|
2010-02-02 02:46:13 +00:00
|
|
|
// We can't look up the base (computed-style) value of shorthand
|
2010-11-09 23:21:04 +00:00
|
|
|
// properties because they aren't guaranteed to have a consistent computed
|
|
|
|
// value.
|
|
|
|
//
|
|
|
|
// Also, although we can look up the base value of the display property,
|
|
|
|
// doing so involves clearing and resetting the property which can cause
|
|
|
|
// frames to be recreated which we'd like to avoid.
|
|
|
|
//
|
2010-12-23 05:48:31 +00:00
|
|
|
// In either case, just return a dummy value (initialized with the right
|
|
|
|
// type, so as not to indicate failure).
|
|
|
|
nsSMILValue tmpVal(&nsSMILCSSValueType::sSingleton);
|
|
|
|
baseValue.Swap(tmpVal);
|
2010-03-26 19:24:13 +00:00
|
|
|
return baseValue;
|
2010-02-02 02:46:13 +00:00
|
|
|
}
|
|
|
|
|
2010-03-26 19:24:13 +00:00
|
|
|
// GENERAL CASE: Non-Shorthands
|
2009-10-02 21:37:25 +00:00
|
|
|
// (1) Put empty string in override style for property mPropID
|
|
|
|
// (saving old override style value, so we can set it again when we're done)
|
2012-06-10 23:44:50 +00:00
|
|
|
nsICSSDeclaration* overrideDecl = mElement->GetSMILOverrideStyle();
|
2009-10-02 21:37:25 +00:00
|
|
|
nsAutoString cachedOverrideStyleVal;
|
|
|
|
if (overrideDecl) {
|
|
|
|
overrideDecl->GetPropertyValue(mPropID, cachedOverrideStyleVal);
|
|
|
|
// (Don't bother clearing override style if it's already empty)
|
|
|
|
if (!cachedOverrideStyleVal.IsEmpty()) {
|
|
|
|
overrideDecl->SetPropertyValue(mPropID, EmptyString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// (2) Get Computed Style
|
|
|
|
nsAutoString computedStyleVal;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool didGetComputedVal = GetCSSComputedValue(mElement, mPropID,
|
2009-10-02 21:37:25 +00:00
|
|
|
computedStyleVal);
|
|
|
|
|
|
|
|
// (3) Put cached override style back (if it's non-empty)
|
|
|
|
if (overrideDecl && !cachedOverrideStyleVal.IsEmpty()) {
|
|
|
|
overrideDecl->SetPropertyValue(mPropID, cachedOverrideStyleVal);
|
|
|
|
}
|
|
|
|
|
2010-03-26 19:24:13 +00:00
|
|
|
// (4) Populate our nsSMILValue from the computed style
|
2009-10-02 21:37:25 +00:00
|
|
|
if (didGetComputedVal) {
|
2011-08-22 23:34:03 +00:00
|
|
|
// When we parse animation values we check if they are context-sensitive or
|
|
|
|
// not so that we don't cache animation values whose meaning may change.
|
|
|
|
// For base values however this is unnecessary since on each sample the
|
|
|
|
// compositor will fetch the (computed) base value and compare it against
|
|
|
|
// the cached (computed) value and detect changes for us.
|
2010-06-09 19:51:31 +00:00
|
|
|
nsSMILCSSValueType::ValueFromString(mPropID, mElement,
|
2011-08-22 23:34:03 +00:00
|
|
|
computedStyleVal, baseValue,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr);
|
2009-10-02 21:37:25 +00:00
|
|
|
}
|
|
|
|
return baseValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILCSSProperty::ValueFromString(const nsAString& aStr,
|
2013-03-19 03:18:45 +00:00
|
|
|
const SVGAnimationElement* aSrcElement,
|
2010-02-20 21:13:11 +00:00
|
|
|
nsSMILValue& aValue,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool& aPreventCachingOfSandwich) const
|
2009-10-02 21:37:25 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE);
|
2010-02-02 02:46:13 +00:00
|
|
|
|
2011-08-22 23:34:03 +00:00
|
|
|
nsSMILCSSValueType::ValueFromString(mPropID, mElement, aStr, aValue,
|
|
|
|
&aPreventCachingOfSandwich);
|
2011-08-22 23:34:16 +00:00
|
|
|
|
2012-02-13 18:24:51 +00:00
|
|
|
if (aValue.IsNull()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-08-22 23:34:16 +00:00
|
|
|
// XXX Due to bug 536660 (or at least that seems to be the most likely
|
|
|
|
// culprit), when we have animation setting display:none on a <use> element,
|
|
|
|
// if we DON'T set the property every sample, chaos ensues.
|
|
|
|
if (!aPreventCachingOfSandwich && mPropID == eCSSProperty_display) {
|
2011-10-17 14:59:28 +00:00
|
|
|
aPreventCachingOfSandwich = true;
|
2011-08-22 23:34:16 +00:00
|
|
|
}
|
2012-02-13 18:24:51 +00:00
|
|
|
return NS_OK;
|
2009-10-02 21:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILCSSProperty::SetAnimValue(const nsSMILValue& aValue)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE);
|
|
|
|
|
2010-02-02 02:46:13 +00:00
|
|
|
// Convert nsSMILValue to string
|
2009-10-02 21:37:25 +00:00
|
|
|
nsAutoString valStr;
|
2010-02-02 02:46:13 +00:00
|
|
|
if (!nsSMILCSSValueType::ValueToString(aValue, valStr)) {
|
2009-10-02 21:37:25 +00:00
|
|
|
NS_WARNING("Failed to convert nsSMILValue for CSS property into a string");
|
2010-02-02 02:46:13 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-10-02 21:37:25 +00:00
|
|
|
}
|
|
|
|
|
2010-02-02 02:46:13 +00:00
|
|
|
// Use string value to style the target element
|
2012-06-10 23:44:50 +00:00
|
|
|
nsICSSDeclaration* overrideDecl = mElement->GetSMILOverrideStyle();
|
2010-02-02 02:46:13 +00:00
|
|
|
if (overrideDecl) {
|
2012-06-01 23:53:57 +00:00
|
|
|
nsAutoString oldValStr;
|
|
|
|
overrideDecl->GetPropertyValue(mPropID, oldValStr);
|
|
|
|
if (valStr.Equals(oldValStr)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-02-02 02:46:13 +00:00
|
|
|
overrideDecl->SetPropertyValue(mPropID, valStr);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2009-10-02 21:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILCSSProperty::ClearAnimValue()
|
|
|
|
{
|
2010-02-02 02:46:13 +00:00
|
|
|
// Put empty string in override style for our property
|
2012-06-10 23:44:50 +00:00
|
|
|
nsICSSDeclaration* overrideDecl = mElement->GetSMILOverrideStyle();
|
2009-10-02 21:37:25 +00:00
|
|
|
if (overrideDecl) {
|
|
|
|
overrideDecl->SetPropertyValue(mPropID, EmptyString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Based on http://www.w3.org/TR/SVG/propidx.html
|
|
|
|
// static
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-10-02 21:37:25 +00:00
|
|
|
nsSMILCSSProperty::IsPropertyAnimatable(nsCSSProperty aPropID)
|
|
|
|
{
|
|
|
|
// NOTE: Right now, Gecko doesn't recognize the following properties from
|
|
|
|
// the SVG Property Index:
|
|
|
|
// alignment-baseline
|
|
|
|
// baseline-shift
|
|
|
|
// color-profile
|
|
|
|
// color-rendering
|
|
|
|
// glyph-orientation-horizontal
|
|
|
|
// glyph-orientation-vertical
|
|
|
|
// kerning
|
|
|
|
// writing-mode
|
|
|
|
|
|
|
|
switch (aPropID) {
|
|
|
|
case eCSSProperty_clip:
|
2009-10-21 21:57:57 +00:00
|
|
|
case eCSSProperty_clip_rule:
|
2009-12-10 17:26:27 +00:00
|
|
|
case eCSSProperty_clip_path:
|
2009-10-02 21:37:25 +00:00
|
|
|
case eCSSProperty_color:
|
2009-10-21 21:57:57 +00:00
|
|
|
case eCSSProperty_color_interpolation:
|
|
|
|
case eCSSProperty_color_interpolation_filters:
|
2009-12-10 17:26:28 +00:00
|
|
|
case eCSSProperty_cursor:
|
2009-10-21 21:57:57 +00:00
|
|
|
case eCSSProperty_display:
|
|
|
|
case eCSSProperty_dominant_baseline:
|
2009-12-10 17:26:27 +00:00
|
|
|
case eCSSProperty_fill:
|
2009-10-09 01:30:50 +00:00
|
|
|
case eCSSProperty_fill_opacity:
|
2009-10-21 21:57:57 +00:00
|
|
|
case eCSSProperty_fill_rule:
|
2009-12-10 17:26:27 +00:00
|
|
|
case eCSSProperty_filter:
|
2009-10-02 21:37:25 +00:00
|
|
|
case eCSSProperty_flood_color:
|
2009-10-09 01:30:50 +00:00
|
|
|
case eCSSProperty_flood_opacity:
|
2010-01-05 00:32:11 +00:00
|
|
|
case eCSSProperty_font:
|
2009-12-10 17:26:27 +00:00
|
|
|
case eCSSProperty_font_family:
|
2009-10-02 21:37:25 +00:00
|
|
|
case eCSSProperty_font_size:
|
2009-10-09 01:30:53 +00:00
|
|
|
case eCSSProperty_font_size_adjust:
|
2009-11-18 06:08:19 +00:00
|
|
|
case eCSSProperty_font_stretch:
|
2009-10-21 21:57:57 +00:00
|
|
|
case eCSSProperty_font_style:
|
|
|
|
case eCSSProperty_font_variant:
|
2009-11-18 06:08:19 +00:00
|
|
|
case eCSSProperty_font_weight:
|
2012-06-16 15:47:40 +00:00
|
|
|
case eCSSProperty_height:
|
2009-10-21 21:57:57 +00:00
|
|
|
case eCSSProperty_image_rendering:
|
2009-10-02 21:37:25 +00:00
|
|
|
case eCSSProperty_letter_spacing:
|
|
|
|
case eCSSProperty_lighting_color:
|
2010-01-05 00:32:11 +00:00
|
|
|
case eCSSProperty_marker:
|
2009-12-10 17:26:27 +00:00
|
|
|
case eCSSProperty_marker_end:
|
|
|
|
case eCSSProperty_marker_mid:
|
|
|
|
case eCSSProperty_marker_start:
|
|
|
|
case eCSSProperty_mask:
|
2012-12-21 00:15:22 +00:00
|
|
|
case eCSSProperty_mask_type:
|
2009-10-09 01:30:50 +00:00
|
|
|
case eCSSProperty_opacity:
|
2010-01-05 00:32:11 +00:00
|
|
|
case eCSSProperty_overflow:
|
2009-10-21 21:57:57 +00:00
|
|
|
case eCSSProperty_pointer_events:
|
|
|
|
case eCSSProperty_shape_rendering:
|
2009-10-02 21:37:25 +00:00
|
|
|
case eCSSProperty_stop_color:
|
2009-10-09 01:30:50 +00:00
|
|
|
case eCSSProperty_stop_opacity:
|
2009-12-10 17:26:27 +00:00
|
|
|
case eCSSProperty_stroke:
|
|
|
|
case eCSSProperty_stroke_dasharray:
|
2009-10-02 21:37:25 +00:00
|
|
|
case eCSSProperty_stroke_dashoffset:
|
2009-10-21 21:57:57 +00:00
|
|
|
case eCSSProperty_stroke_linecap:
|
|
|
|
case eCSSProperty_stroke_linejoin:
|
2009-10-09 01:30:50 +00:00
|
|
|
case eCSSProperty_stroke_miterlimit:
|
|
|
|
case eCSSProperty_stroke_opacity:
|
2009-10-02 21:37:25 +00:00
|
|
|
case eCSSProperty_stroke_width:
|
2009-10-21 21:57:57 +00:00
|
|
|
case eCSSProperty_text_anchor:
|
|
|
|
case eCSSProperty_text_decoration:
|
2011-04-23 05:16:41 +00:00
|
|
|
case eCSSProperty_text_decoration_line:
|
2009-10-21 21:57:57 +00:00
|
|
|
case eCSSProperty_text_rendering:
|
2012-05-18 08:34:25 +00:00
|
|
|
case eCSSProperty_vector_effect:
|
2012-06-16 15:47:40 +00:00
|
|
|
case eCSSProperty_width:
|
2009-10-21 21:57:57 +00:00
|
|
|
case eCSSProperty_visibility:
|
2009-10-02 21:37:25 +00:00
|
|
|
case eCSSProperty_word_spacing:
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-10-02 21:37:25 +00:00
|
|
|
|
|
|
|
// EXPLICITLY NON-ANIMATABLE PROPERTIES:
|
|
|
|
// (Some of these aren't supported at all in Gecko -- I've commented those
|
|
|
|
// ones out. If/when we add support for them, uncomment their line here)
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// case eCSSProperty_enable_background:
|
|
|
|
// case eCSSProperty_glyph_orientation_horizontal:
|
|
|
|
// case eCSSProperty_glyph_orientation_vertical:
|
|
|
|
// case eCSSProperty_writing_mode:
|
|
|
|
case eCSSProperty_direction:
|
|
|
|
case eCSSProperty_unicode_bidi:
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-10-02 21:37:25 +00:00
|
|
|
|
|
|
|
default:
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-10-02 21:37:25 +00:00
|
|
|
}
|
|
|
|
}
|