Commit 8d7e6d70 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Document SVGAnimationElement::CheckAnimationParameters()

And its companion SVGAnimationElement::CalculateValuesAnimation().

Bug: 998526
Change-Id: I3895dc070d319f1cefa489e061a598b18a88cf98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1871509
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708119}
parent 6357f0f2
...@@ -522,19 +522,27 @@ bool SVGAnimationElement::CalculateValuesAnimation() { ...@@ -522,19 +522,27 @@ bool SVGAnimationElement::CalculateValuesAnimation() {
if (values_.IsEmpty()) if (values_.IsEmpty())
return false; return false;
CalcMode calc_mode = GetCalcMode(); CalcMode calc_mode = GetCalcMode();
// For 'values' animations, there should be exactly as many 'keyTimes' as
// 'values'.
if (calc_mode != kCalcModePaced && if (calc_mode != kCalcModePaced &&
FastHasAttribute(svg_names::kKeyTimesAttr) &&
!FastHasAttribute(svg_names::kKeyPointsAttr) && !FastHasAttribute(svg_names::kKeyPointsAttr) &&
FastHasAttribute(svg_names::kKeyTimesAttr) &&
values_.size() != KeyTimes().size()) values_.size() != KeyTimes().size())
return false; return false;
// If 'keyTimes' is specified its last value should be 1 (and the first 0)
// unless 'calcMode' is 'discrete'.
if (calc_mode != kCalcModeDiscrete && !KeyTimes().IsEmpty() && if (calc_mode != kCalcModeDiscrete && !KeyTimes().IsEmpty() &&
KeyTimes().back() != 1) KeyTimes().back() != 1)
return false; return false;
// If 'calcMode' is 'spline', there should be one less spline than there are
// 'keyPoints' or 'values'.
if (calc_mode == kCalcModeSpline) { if (calc_mode == kCalcModeSpline) {
if ((key_splines_.IsEmpty() || key_splines_.size() != values_.size() - 1) && if ((key_splines_.IsEmpty() || key_splines_.size() != values_.size() - 1) &&
key_splines_.size() != key_points_.size() - 1) key_splines_.size() != key_points_.size() - 1)
return false; return false;
} }
// If 'keyPoints' is specified it should have the same amount of points as
// 'keyTimes', and at least two points.
if (FastHasAttribute(svg_names::kKeyPointsAttr) && if (FastHasAttribute(svg_names::kKeyPointsAttr) &&
(KeyTimes().size() < 2 || KeyTimes().size() != key_points_.size())) (KeyTimes().size() < 2 || KeyTimes().size() != key_points_.size()))
return false; return false;
...@@ -554,12 +562,16 @@ bool SVGAnimationElement::CheckAnimationParameters() { ...@@ -554,12 +562,16 @@ bool SVGAnimationElement::CheckAnimationParameters() {
return false; return false;
// These validations are appropriate for all animation modes. // These validations are appropriate for all animation modes.
// If 'keyPoints' is specified it should have the same amount of points as
// 'keyTimes'.
if (FastHasAttribute(svg_names::kKeyPointsAttr) && if (FastHasAttribute(svg_names::kKeyPointsAttr) &&
KeyTimes().size() != key_points_.size()) KeyTimes().size() != key_points_.size())
return false; return false;
CalcMode calc_mode = GetCalcMode(); CalcMode calc_mode = GetCalcMode();
if (calc_mode == kCalcModeSpline) { if (calc_mode == kCalcModeSpline) {
// If 'calcMode' is 'spline', there should be one less spline than there
// are 'keyTimes' or 'keyPoints' - or 'values' if it is used.
if (key_splines_.IsEmpty() || if (key_splines_.IsEmpty() ||
(FastHasAttribute(svg_names::kKeyPointsAttr) && (FastHasAttribute(svg_names::kKeyPointsAttr) &&
key_splines_.size() != key_points_.size() - 1) || key_splines_.size() != key_points_.size() - 1) ||
...@@ -570,13 +582,17 @@ bool SVGAnimationElement::CheckAnimationParameters() { ...@@ -570,13 +582,17 @@ bool SVGAnimationElement::CheckAnimationParameters() {
return false; return false;
} }
if ((animation_mode == kFromToAnimation || if (animation_mode == kFromToAnimation ||
animation_mode == kFromByAnimation || animation_mode == kToAnimation || animation_mode == kFromByAnimation || animation_mode == kToAnimation ||
animation_mode == kByAnimation) && animation_mode == kByAnimation) {
(FastHasAttribute(svg_names::kKeyTimesAttr) && if (FastHasAttribute(svg_names::kKeyTimesAttr)) {
FastHasAttribute(svg_names::kKeyPointsAttr) && // If 'keyPoints' is specified it should have the same amount of points
(KeyTimes().size() < 2 || KeyTimes().size() != key_points_.size()))) // as 'keyTimes', and at least two points.
return false; if (FastHasAttribute(svg_names::kKeyPointsAttr) &&
(KeyTimes().size() < 2 || KeyTimes().size() != key_points_.size()))
return false;
}
}
const String& from = FromValue(); const String& from = FromValue();
const String& to = ToValue(); const String& to = ToValue();
const String& by = ByValue(); const String& by = ByValue();
...@@ -595,10 +611,14 @@ bool SVGAnimationElement::CheckAnimationParameters() { ...@@ -595,10 +611,14 @@ bool SVGAnimationElement::CheckAnimationParameters() {
if (animation_mode == kValuesAnimation) if (animation_mode == kValuesAnimation)
return CalculateValuesAnimation(); return CalculateValuesAnimation();
if (animation_mode == kPathAnimation) { if (animation_mode == kPathAnimation) {
return calc_mode == kCalcModePaced || if (calc_mode == kCalcModePaced)
!(FastHasAttribute(svg_names::kKeyPointsAttr) && return true;
(KeyTimes().size() < 2 || // If 'keyPoints' is specified it should have the same amount of points as
KeyTimes().size() != key_points_.size())); // 'keyTimes', and at least two points.
if (FastHasAttribute(svg_names::kKeyPointsAttr) &&
(KeyTimes().size() < 2 || KeyTimes().size() != key_points_.size()))
return false;
return true;
} }
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment