Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/smil/nsSMILCSSProperty.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
/* representation of a SMIL-animatable CSS property on an element */
8
9
#include "nsSMILCSSProperty.h"
10
11
#include "mozilla/dom/Element.h"
12
#include "mozilla/Move.h"
13
#include "mozilla/ServoBindings.h"
14
#include "mozilla/StyleAnimationValue.h"
15
#include "nsDOMCSSAttrDeclaration.h"
16
#include "nsSMILCSSValueType.h"
17
#include "nsSMILValue.h"
18
#include "nsCSSProps.h"
19
20
using namespace mozilla;
21
using namespace mozilla::dom;
22
23
// Class Methods
24
nsSMILCSSProperty::nsSMILCSSProperty(nsCSSPropertyID aPropID,
25
                                     Element* aElement,
26
                                     ComputedStyle* aBaseComputedStyle)
27
  : mPropID(aPropID)
28
  , mElement(aElement)
29
  , mBaseComputedStyle(aBaseComputedStyle)
30
0
{
31
0
  MOZ_ASSERT(IsPropertyAnimatable(mPropID),
32
0
             "Creating a nsSMILCSSProperty for a property "
33
0
             "that's not supported for animation");
34
0
}
35
36
nsSMILValue
37
nsSMILCSSProperty::GetBaseValue() const
38
0
{
39
0
  // To benefit from Return Value Optimization and avoid copy constructor calls
40
0
  // due to our use of return-by-value, we must return the exact same object
41
0
  // from ALL return points. This function must only return THIS variable:
42
0
  nsSMILValue baseValue;
43
0
44
0
  // SPECIAL CASE: (a) Shorthands
45
0
  //               (b) 'display'
46
0
  //               (c) No base ComputedStyle
47
0
  if (nsCSSProps::IsShorthand(mPropID) ||
48
0
      mPropID == eCSSProperty_display ||
49
0
      !mBaseComputedStyle) {
50
0
    // We can't look up the base (computed-style) value of shorthand
51
0
    // properties because they aren't guaranteed to have a consistent computed
52
0
    // value.
53
0
    //
54
0
    // Also, although we can look up the base value of the display property,
55
0
    // doing so involves clearing and resetting the property which can cause
56
0
    // frames to be recreated which we'd like to avoid.
57
0
    //
58
0
    // Furthermore, if we don't (yet) have a base ComputedStyle we obviously
59
0
    // can't resolve a base value.
60
0
    //
61
0
    // In any case, just return a dummy value (initialized with the right
62
0
    // type, so as not to indicate failure).
63
0
    nsSMILValue tmpVal(&nsSMILCSSValueType::sSingleton);
64
0
    Swap(baseValue, tmpVal);
65
0
    return baseValue;
66
0
  }
67
0
68
0
  AnimationValue computedValue;
69
0
  computedValue.mServo =
70
0
    Servo_ComputedValues_ExtractAnimationValue(mBaseComputedStyle, mPropID)
71
0
    .Consume();
72
0
  if (!computedValue.mServo) {
73
0
    return baseValue;
74
0
  }
75
0
76
0
  baseValue =
77
0
    nsSMILCSSValueType::ValueFromAnimationValue(mPropID, mElement,
78
0
                                                computedValue);
79
0
  return baseValue;
80
0
}
81
82
nsresult
83
nsSMILCSSProperty::ValueFromString(const nsAString& aStr,
84
                                   const SVGAnimationElement* aSrcElement,
85
                                   nsSMILValue& aValue,
86
                                   bool& aPreventCachingOfSandwich) const
87
0
{
88
0
  NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE);
89
0
90
0
  nsSMILCSSValueType::ValueFromString(mPropID, mElement, aStr, aValue,
91
0
      &aPreventCachingOfSandwich);
92
0
93
0
  if (aValue.IsNull()) {
94
0
    return NS_ERROR_FAILURE;
95
0
  }
96
0
97
0
  // XXX Due to bug 536660 (or at least that seems to be the most likely
98
0
  // culprit), when we have animation setting display:none on a <use> element,
99
0
  // if we DON'T set the property every sample, chaos ensues.
100
0
  if (!aPreventCachingOfSandwich && mPropID == eCSSProperty_display) {
101
0
    aPreventCachingOfSandwich = true;
102
0
  }
103
0
  return NS_OK;
104
0
}
105
106
nsresult
107
nsSMILCSSProperty::SetAnimValue(const nsSMILValue& aValue)
108
0
{
109
0
  NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE);
110
0
  return mElement->SMILOverrideStyle()->SetSMILValue(mPropID, aValue);
111
0
}
112
113
void
114
nsSMILCSSProperty::ClearAnimValue()
115
0
{
116
0
  // Put empty string in override style for our property
117
0
  mElement->SMILOverrideStyle()->SetPropertyValue(mPropID, EmptyString(), nullptr);
118
0
}
119
120
// Based on http://www.w3.org/TR/SVG/propidx.html
121
// static
122
bool
123
nsSMILCSSProperty::IsPropertyAnimatable(nsCSSPropertyID aPropID)
124
0
{
125
0
  // Bug 1353918: Drop this check
126
0
  if (!Servo_Property_IsAnimatable(aPropID)) {
127
0
    return false;
128
0
  }
129
0
130
0
  // NOTE: Right now, Gecko doesn't recognize the following properties from
131
0
  // the SVG Property Index:
132
0
  //   alignment-baseline
133
0
  //   baseline-shift
134
0
  //   color-profile
135
0
  //   color-rendering
136
0
  //   glyph-orientation-horizontal
137
0
  //   glyph-orientation-vertical
138
0
  //   kerning
139
0
  //   writing-mode
140
0
141
0
  switch (aPropID) {
142
0
    case eCSSProperty_clip:
143
0
    case eCSSProperty_clip_rule:
144
0
    case eCSSProperty_clip_path:
145
0
    case eCSSProperty_color:
146
0
    case eCSSProperty_color_interpolation:
147
0
    case eCSSProperty_color_interpolation_filters:
148
0
    case eCSSProperty_cursor:
149
0
    case eCSSProperty_display:
150
0
    case eCSSProperty_dominant_baseline:
151
0
    case eCSSProperty_fill:
152
0
    case eCSSProperty_fill_opacity:
153
0
    case eCSSProperty_fill_rule:
154
0
    case eCSSProperty_filter:
155
0
    case eCSSProperty_flood_color:
156
0
    case eCSSProperty_flood_opacity:
157
0
    case eCSSProperty_font:
158
0
    case eCSSProperty_font_family:
159
0
    case eCSSProperty_font_size:
160
0
    case eCSSProperty_font_size_adjust:
161
0
    case eCSSProperty_font_stretch:
162
0
    case eCSSProperty_font_style:
163
0
    case eCSSProperty_font_variant:
164
0
    case eCSSProperty_font_weight:
165
0
    case eCSSProperty_height:
166
0
    case eCSSProperty_image_rendering:
167
0
    case eCSSProperty_letter_spacing:
168
0
    case eCSSProperty_lighting_color:
169
0
    case eCSSProperty_marker:
170
0
    case eCSSProperty_marker_end:
171
0
    case eCSSProperty_marker_mid:
172
0
    case eCSSProperty_marker_start:
173
0
    case eCSSProperty_mask:
174
0
    case eCSSProperty_mask_type:
175
0
    case eCSSProperty_opacity:
176
0
    case eCSSProperty_overflow:
177
0
    case eCSSProperty_pointer_events:
178
0
    case eCSSProperty_shape_rendering:
179
0
    case eCSSProperty_stop_color:
180
0
    case eCSSProperty_stop_opacity:
181
0
    case eCSSProperty_stroke:
182
0
    case eCSSProperty_stroke_dasharray:
183
0
    case eCSSProperty_stroke_dashoffset:
184
0
    case eCSSProperty_stroke_linecap:
185
0
    case eCSSProperty_stroke_linejoin:
186
0
    case eCSSProperty_stroke_miterlimit:
187
0
    case eCSSProperty_stroke_opacity:
188
0
    case eCSSProperty_stroke_width:
189
0
    case eCSSProperty_text_anchor:
190
0
    case eCSSProperty_text_decoration:
191
0
    case eCSSProperty_text_decoration_line:
192
0
    case eCSSProperty_text_rendering:
193
0
    case eCSSProperty_vector_effect:
194
0
    case eCSSProperty_width:
195
0
    case eCSSProperty_visibility:
196
0
    case eCSSProperty_word_spacing:
197
0
      return true;
198
0
199
0
    // EXPLICITLY NON-ANIMATABLE PROPERTIES:
200
0
    // (Some of these aren't supported at all in Gecko -- I've commented those
201
0
    // ones out. If/when we add support for them, uncomment their line here)
202
0
    // ----------------------------------------------------------------------
203
0
    // case eCSSProperty_enable_background:
204
0
    // case eCSSProperty_glyph_orientation_horizontal:
205
0
    // case eCSSProperty_glyph_orientation_vertical:
206
0
    // case eCSSProperty_writing_mode:
207
0
    case eCSSProperty_direction:
208
0
    case eCSSProperty_unicode_bidi:
209
0
      return false;
210
0
211
0
    default:
212
0
      return false;
213
0
  }
214
0
}