Bug 1719855 - Take over preventDefaulted infomation for long-tap events to the origin...
[gecko.git] / dom / smil / SMILCSSProperty.cpp
blob5e4adc45f923cc932a6c8fdce4b0102b7ce67ab8
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* representation of a SMIL-animatable CSS property on an element */
9 #include "SMILCSSProperty.h"
11 #include <utility>
13 #include "mozilla/SMILCSSValueType.h"
14 #include "mozilla/SMILValue.h"
15 #include "mozilla/ServoBindings.h"
16 #include "mozilla/StyleAnimationValue.h"
17 #include "mozilla/dom/Element.h"
18 #include "nsCSSProps.h"
19 #include "nsDOMCSSAttrDeclaration.h"
21 namespace mozilla {
23 // Class Methods
24 SMILCSSProperty::SMILCSSProperty(nsCSSPropertyID aPropID,
25 dom::Element* aElement,
26 const ComputedStyle* aBaseComputedStyle)
27 : mPropID(aPropID),
28 mElement(aElement),
29 mBaseComputedStyle(aBaseComputedStyle) {
30 MOZ_ASSERT(IsPropertyAnimatable(mPropID),
31 "Creating a SMILCSSProperty for a property "
32 "that's not supported for animation");
35 SMILValue SMILCSSProperty::GetBaseValue() const {
36 // To benefit from Return Value Optimization and avoid copy constructor calls
37 // due to our use of return-by-value, we must return the exact same object
38 // from ALL return points. This function must only return THIS variable:
39 SMILValue baseValue;
41 // SPECIAL CASE: (a) Shorthands
42 // (b) 'display'
43 // (c) No base ComputedStyle
44 if (nsCSSProps::IsShorthand(mPropID) || mPropID == eCSSProperty_display ||
45 !mBaseComputedStyle) {
46 // We can't look up the base (computed-style) value of shorthand
47 // properties because they aren't guaranteed to have a consistent computed
48 // value.
50 // Also, although we can look up the base value of the display property,
51 // doing so involves clearing and resetting the property which can cause
52 // frames to be recreated which we'd like to avoid.
54 // Furthermore, if we don't (yet) have a base ComputedStyle we obviously
55 // can't resolve a base value.
57 // In any case, just return a dummy value (initialized with the right
58 // type, so as not to indicate failure).
59 SMILValue tmpVal(&SMILCSSValueType::sSingleton);
60 std::swap(baseValue, tmpVal);
61 return baseValue;
64 AnimationValue computedValue;
65 computedValue.mServo =
66 Servo_ComputedValues_ExtractAnimationValue(mBaseComputedStyle, mPropID)
67 .Consume();
68 if (!computedValue.mServo) {
69 return baseValue;
72 baseValue = SMILCSSValueType::ValueFromAnimationValue(mPropID, mElement,
73 computedValue);
74 return baseValue;
77 nsresult SMILCSSProperty::ValueFromString(
78 const nsAString& aStr, const dom::SVGAnimationElement* aSrcElement,
79 SMILValue& aValue, bool& aPreventCachingOfSandwich) const {
80 NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE);
82 SMILCSSValueType::ValueFromString(mPropID, mElement, aStr, aValue,
83 &aPreventCachingOfSandwich);
85 if (aValue.IsNull()) {
86 return NS_ERROR_FAILURE;
89 // XXX Due to bug 536660 (or at least that seems to be the most likely
90 // culprit), when we have animation setting display:none on a <use> element,
91 // if we DON'T set the property every sample, chaos ensues.
92 if (!aPreventCachingOfSandwich && mPropID == eCSSProperty_display) {
93 aPreventCachingOfSandwich = true;
95 return NS_OK;
98 nsresult SMILCSSProperty::SetAnimValue(const SMILValue& aValue) {
99 NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE);
100 return mElement->SMILOverrideStyle()->SetSMILValue(mPropID, aValue);
103 void SMILCSSProperty::ClearAnimValue() {
104 // Put empty string in override style for our property
105 mElement->SMILOverrideStyle()->SetPropertyValue(mPropID, ""_ns, nullptr,
106 IgnoreErrors());
109 // Based on http://www.w3.org/TR/SVG/propidx.html
110 // static
111 bool SMILCSSProperty::IsPropertyAnimatable(nsCSSPropertyID aPropID) {
112 // NOTE: Right now, Gecko doesn't recognize the following properties from
113 // the SVG Property Index:
114 // alignment-baseline
115 // baseline-shift
116 // color-profile
117 // glyph-orientation-horizontal
118 // glyph-orientation-vertical
119 // kerning
120 // writing-mode
122 switch (aPropID) {
123 case eCSSProperty_clip:
124 case eCSSProperty_clip_rule:
125 case eCSSProperty_clip_path:
126 case eCSSProperty_color:
127 case eCSSProperty_color_interpolation:
128 case eCSSProperty_color_interpolation_filters:
129 case eCSSProperty_cursor:
130 case eCSSProperty_display:
131 case eCSSProperty_dominant_baseline:
132 case eCSSProperty_fill:
133 case eCSSProperty_fill_opacity:
134 case eCSSProperty_fill_rule:
135 case eCSSProperty_filter:
136 case eCSSProperty_flood_color:
137 case eCSSProperty_flood_opacity:
138 case eCSSProperty_font:
139 case eCSSProperty_font_family:
140 case eCSSProperty_font_size:
141 case eCSSProperty_font_size_adjust:
142 case eCSSProperty_font_stretch:
143 case eCSSProperty_font_style:
144 case eCSSProperty_font_variant:
145 case eCSSProperty_font_weight:
146 case eCSSProperty_height:
147 case eCSSProperty_image_rendering:
148 case eCSSProperty_letter_spacing:
149 case eCSSProperty_lighting_color:
150 case eCSSProperty_marker:
151 case eCSSProperty_marker_end:
152 case eCSSProperty_marker_mid:
153 case eCSSProperty_marker_start:
154 case eCSSProperty_mask:
155 case eCSSProperty_mask_type:
156 case eCSSProperty_opacity:
157 case eCSSProperty_overflow:
158 case eCSSProperty_pointer_events:
159 case eCSSProperty_shape_rendering:
160 case eCSSProperty_stop_color:
161 case eCSSProperty_stop_opacity:
162 case eCSSProperty_stroke:
163 case eCSSProperty_stroke_dasharray:
164 case eCSSProperty_stroke_dashoffset:
165 case eCSSProperty_stroke_linecap:
166 case eCSSProperty_stroke_linejoin:
167 case eCSSProperty_stroke_miterlimit:
168 case eCSSProperty_stroke_opacity:
169 case eCSSProperty_stroke_width:
170 case eCSSProperty_text_anchor:
171 case eCSSProperty_text_decoration:
172 case eCSSProperty_text_decoration_line:
173 case eCSSProperty_text_rendering:
174 case eCSSProperty_vector_effect:
175 case eCSSProperty_width:
176 case eCSSProperty_visibility:
177 case eCSSProperty_word_spacing:
178 return true;
180 // EXPLICITLY NON-ANIMATABLE PROPERTIES:
181 // (Some of these aren't supported at all in Gecko -- I've commented those
182 // ones out. If/when we add support for them, uncomment their line here)
183 // ----------------------------------------------------------------------
184 // case eCSSProperty_enable_background:
185 // case eCSSProperty_glyph_orientation_horizontal:
186 // case eCSSProperty_glyph_orientation_vertical:
187 // case eCSSProperty_writing_mode:
188 case eCSSProperty_direction:
189 case eCSSProperty_unicode_bidi:
190 return false;
192 default:
193 return false;
197 } // namespace mozilla