2015-05-03 22:32:37 +03: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 15:12:37 +04: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-03 01:37:25 +04:00
|
|
|
|
|
|
|
/* representation of a SMIL-animatable CSS property on an element */
|
|
|
|
|
2019-01-08 10:55:14 +03:00
|
|
|
#include "SMILCSSProperty.h"
|
2015-05-29 23:10:41 +03:00
|
|
|
|
|
|
|
#include "mozilla/dom/Element.h"
|
2020-01-20 19:18:20 +03:00
|
|
|
#include <utility>
|
2017-04-26 07:00:12 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2019-01-09 03:34:14 +03:00
|
|
|
#include "mozilla/SMILCSSValueType.h"
|
2019-01-23 16:48:08 +03:00
|
|
|
#include "mozilla/SMILValue.h"
|
2017-04-03 10:49:27 +03:00
|
|
|
#include "mozilla/StyleAnimationValue.h"
|
2018-01-30 22:48:26 +03:00
|
|
|
#include "nsDOMCSSAttrDeclaration.h"
|
2013-03-03 04:31:48 +04:00
|
|
|
#include "nsCSSProps.h"
|
2009-10-03 01:37:25 +04:00
|
|
|
|
2019-01-08 10:55:14 +03:00
|
|
|
namespace mozilla {
|
2010-05-14 21:04:51 +04:00
|
|
|
|
2009-10-03 01:37:25 +04:00
|
|
|
// Class Methods
|
2019-01-08 10:55:14 +03:00
|
|
|
SMILCSSProperty::SMILCSSProperty(nsCSSPropertyID aPropID, Element* aElement,
|
|
|
|
ComputedStyle* aBaseComputedStyle)
|
2017-04-03 10:49:10 +03:00
|
|
|
: mPropID(aPropID),
|
|
|
|
mElement(aElement),
|
2018-03-22 21:20:41 +03:00
|
|
|
mBaseComputedStyle(aBaseComputedStyle) {
|
2018-03-28 18:34:34 +03:00
|
|
|
MOZ_ASSERT(IsPropertyAnimatable(mPropID),
|
2019-01-08 10:55:14 +03:00
|
|
|
"Creating a SMILCSSProperty for a property "
|
2015-02-10 01:34:50 +03:00
|
|
|
"that's not supported for animation");
|
2009-10-03 01:37:25 +04:00
|
|
|
}
|
|
|
|
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue SMILCSSProperty::GetBaseValue() const {
|
2010-03-26 22:24:13 +03: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:
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue baseValue;
|
2010-03-26 22:24:13 +03:00
|
|
|
|
2010-11-10 02:21:03 +03:00
|
|
|
// SPECIAL CASE: (a) Shorthands
|
|
|
|
// (b) 'display'
|
2018-03-23 16:49:21 +03:00
|
|
|
// (c) No base ComputedStyle
|
2017-04-03 10:49:27 +03:00
|
|
|
if (nsCSSProps::IsShorthand(mPropID) || mPropID == eCSSProperty_display ||
|
2018-03-22 21:20:41 +03:00
|
|
|
!mBaseComputedStyle) {
|
2010-02-02 05:46:13 +03:00
|
|
|
// We can't look up the base (computed-style) value of shorthand
|
2010-11-10 02:21:04 +03: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.
|
|
|
|
//
|
2018-03-23 16:49:21 +03:00
|
|
|
// Furthermore, if we don't (yet) have a base ComputedStyle we obviously
|
2017-04-03 10:49:27 +03:00
|
|
|
// can't resolve a base value.
|
|
|
|
//
|
|
|
|
// In any case, just return a dummy value (initialized with the right
|
2010-12-23 08:48:31 +03:00
|
|
|
// type, so as not to indicate failure).
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue tmpVal(&SMILCSSValueType::sSingleton);
|
2020-01-20 19:17:06 +03:00
|
|
|
std::swap(baseValue, tmpVal);
|
2010-03-26 22:24:13 +03:00
|
|
|
return baseValue;
|
2010-02-02 05:46:13 +03:00
|
|
|
}
|
|
|
|
|
2017-04-26 07:00:12 +03:00
|
|
|
AnimationValue computedValue;
|
2018-03-25 20:42:10 +03:00
|
|
|
computedValue.mServo =
|
|
|
|
Servo_ComputedValues_ExtractAnimationValue(mBaseComputedStyle, mPropID)
|
|
|
|
.Consume();
|
|
|
|
if (!computedValue.mServo) {
|
|
|
|
return baseValue;
|
2009-10-03 01:37:25 +04:00
|
|
|
}
|
|
|
|
|
2018-12-27 20:02:38 +03:00
|
|
|
baseValue = SMILCSSValueType::ValueFromAnimationValue(mPropID, mElement,
|
|
|
|
computedValue);
|
2009-10-03 01:37:25 +04:00
|
|
|
return baseValue;
|
|
|
|
}
|
|
|
|
|
2019-01-08 10:55:14 +03:00
|
|
|
nsresult SMILCSSProperty::ValueFromString(
|
2013-03-19 07:18:45 +04:00
|
|
|
const nsAString& aStr, const SVGAnimationElement* aSrcElement,
|
2019-01-23 16:48:08 +03:00
|
|
|
SMILValue& aValue, bool& aPreventCachingOfSandwich) const {
|
2018-03-28 18:34:34 +03:00
|
|
|
NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE);
|
2010-02-02 05:46:13 +03:00
|
|
|
|
2018-12-27 20:02:38 +03:00
|
|
|
SMILCSSValueType::ValueFromString(mPropID, mElement, aStr, aValue,
|
|
|
|
&aPreventCachingOfSandwich);
|
2011-08-23 03:34:16 +04:00
|
|
|
|
2012-02-13 22:24:51 +04:00
|
|
|
if (aValue.IsNull()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-08-23 03:34:16 +04: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 18:59:28 +04:00
|
|
|
aPreventCachingOfSandwich = true;
|
2011-08-23 03:34:16 +04:00
|
|
|
}
|
2012-02-13 22:24:51 +04:00
|
|
|
return NS_OK;
|
2009-10-03 01:37:25 +04:00
|
|
|
}
|
|
|
|
|
2019-01-23 16:48:08 +03:00
|
|
|
nsresult SMILCSSProperty::SetAnimValue(const SMILValue& aValue) {
|
2018-03-28 18:34:34 +03:00
|
|
|
NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE);
|
2018-05-20 20:45:02 +03:00
|
|
|
return mElement->SMILOverrideStyle()->SetSMILValue(mPropID, aValue);
|
2009-10-03 01:37:25 +04:00
|
|
|
}
|
|
|
|
|
2019-01-08 10:55:14 +03:00
|
|
|
void SMILCSSProperty::ClearAnimValue() {
|
2010-02-02 05:46:13 +03:00
|
|
|
// Put empty string in override style for our property
|
2020-01-04 13:36:49 +03:00
|
|
|
mElement->SMILOverrideStyle()->SetPropertyValue(mPropID, EmptyCString(),
|
2018-05-20 20:45:02 +03:00
|
|
|
nullptr);
|
2009-10-03 01:37:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Based on http://www.w3.org/TR/SVG/propidx.html
|
|
|
|
// static
|
2019-01-08 10:55:14 +03:00
|
|
|
bool SMILCSSProperty::IsPropertyAnimatable(nsCSSPropertyID aPropID) {
|
2009-10-03 01:37:25 +04:00
|
|
|
// NOTE: Right now, Gecko doesn't recognize the following properties from
|
|
|
|
// the SVG Property Index:
|
|
|
|
// alignment-baseline
|
|
|
|
// baseline-shift
|
|
|
|
// color-profile
|
|
|
|
// glyph-orientation-horizontal
|
|
|
|
// glyph-orientation-vertical
|
|
|
|
// kerning
|
|
|
|
// writing-mode
|
|
|
|
|
|
|
|
switch (aPropID) {
|
|
|
|
case eCSSProperty_clip:
|
2009-10-22 01:57:57 +04:00
|
|
|
case eCSSProperty_clip_rule:
|
2009-12-10 20:26:27 +03:00
|
|
|
case eCSSProperty_clip_path:
|
2009-10-03 01:37:25 +04:00
|
|
|
case eCSSProperty_color:
|
2009-10-22 01:57:57 +04:00
|
|
|
case eCSSProperty_color_interpolation:
|
|
|
|
case eCSSProperty_color_interpolation_filters:
|
2009-12-10 20:26:28 +03:00
|
|
|
case eCSSProperty_cursor:
|
2009-10-22 01:57:57 +04:00
|
|
|
case eCSSProperty_display:
|
|
|
|
case eCSSProperty_dominant_baseline:
|
2009-12-10 20:26:27 +03:00
|
|
|
case eCSSProperty_fill:
|
2009-10-09 05:30:50 +04:00
|
|
|
case eCSSProperty_fill_opacity:
|
2009-10-22 01:57:57 +04:00
|
|
|
case eCSSProperty_fill_rule:
|
2009-12-10 20:26:27 +03:00
|
|
|
case eCSSProperty_filter:
|
2009-10-03 01:37:25 +04:00
|
|
|
case eCSSProperty_flood_color:
|
2009-10-09 05:30:50 +04:00
|
|
|
case eCSSProperty_flood_opacity:
|
2010-01-05 03:32:11 +03:00
|
|
|
case eCSSProperty_font:
|
2009-12-10 20:26:27 +03:00
|
|
|
case eCSSProperty_font_family:
|
2009-10-03 01:37:25 +04:00
|
|
|
case eCSSProperty_font_size:
|
2009-10-09 05:30:53 +04:00
|
|
|
case eCSSProperty_font_size_adjust:
|
2009-11-18 09:08:19 +03:00
|
|
|
case eCSSProperty_font_stretch:
|
2009-10-22 01:57:57 +04:00
|
|
|
case eCSSProperty_font_style:
|
|
|
|
case eCSSProperty_font_variant:
|
2009-11-18 09:08:19 +03:00
|
|
|
case eCSSProperty_font_weight:
|
2012-06-16 19:47:40 +04:00
|
|
|
case eCSSProperty_height:
|
2009-10-22 01:57:57 +04:00
|
|
|
case eCSSProperty_image_rendering:
|
2009-10-03 01:37:25 +04:00
|
|
|
case eCSSProperty_letter_spacing:
|
|
|
|
case eCSSProperty_lighting_color:
|
2010-01-05 03:32:11 +03:00
|
|
|
case eCSSProperty_marker:
|
2009-12-10 20:26:27 +03:00
|
|
|
case eCSSProperty_marker_end:
|
|
|
|
case eCSSProperty_marker_mid:
|
|
|
|
case eCSSProperty_marker_start:
|
|
|
|
case eCSSProperty_mask:
|
2012-12-21 04:15:22 +04:00
|
|
|
case eCSSProperty_mask_type:
|
2009-10-09 05:30:50 +04:00
|
|
|
case eCSSProperty_opacity:
|
2010-01-05 03:32:11 +03:00
|
|
|
case eCSSProperty_overflow:
|
2009-10-22 01:57:57 +04:00
|
|
|
case eCSSProperty_pointer_events:
|
|
|
|
case eCSSProperty_shape_rendering:
|
2009-10-03 01:37:25 +04:00
|
|
|
case eCSSProperty_stop_color:
|
2009-10-09 05:30:50 +04:00
|
|
|
case eCSSProperty_stop_opacity:
|
2009-12-10 20:26:27 +03:00
|
|
|
case eCSSProperty_stroke:
|
|
|
|
case eCSSProperty_stroke_dasharray:
|
2009-10-03 01:37:25 +04:00
|
|
|
case eCSSProperty_stroke_dashoffset:
|
2009-10-22 01:57:57 +04:00
|
|
|
case eCSSProperty_stroke_linecap:
|
|
|
|
case eCSSProperty_stroke_linejoin:
|
2009-10-09 05:30:50 +04:00
|
|
|
case eCSSProperty_stroke_miterlimit:
|
|
|
|
case eCSSProperty_stroke_opacity:
|
2009-10-03 01:37:25 +04:00
|
|
|
case eCSSProperty_stroke_width:
|
2009-10-22 01:57:57 +04:00
|
|
|
case eCSSProperty_text_anchor:
|
|
|
|
case eCSSProperty_text_decoration:
|
2011-04-23 09:16:41 +04:00
|
|
|
case eCSSProperty_text_decoration_line:
|
2009-10-22 01:57:57 +04:00
|
|
|
case eCSSProperty_text_rendering:
|
2012-05-18 12:34:25 +04:00
|
|
|
case eCSSProperty_vector_effect:
|
2012-06-16 19:47:40 +04:00
|
|
|
case eCSSProperty_width:
|
2009-10-22 01:57:57 +04:00
|
|
|
case eCSSProperty_visibility:
|
2009-10-03 01:37:25 +04:00
|
|
|
case eCSSProperty_word_spacing:
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-10-03 01:37:25 +04: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 18:59:28 +04:00
|
|
|
return false;
|
2009-10-03 01:37:25 +04:00
|
|
|
|
|
|
|
default:
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-10-03 01:37:25 +04:00
|
|
|
}
|
|
|
|
}
|
2019-01-08 10:55:14 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|