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

Return remapped percent from CurrentValuesForValuesAnimation

This makes it better match its semantic counterparts.
CurrentValuesFromKeyPoints(...) is adjusted in a similar since it is
called by the function in $subject.

Also fix coding-style in SVGAnimationElement::UpdateAnimation().

Bug: 998526
Change-Id: Ib232c0dd7dacd29fe74a9b696a4715d1f9ef2f6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869002
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708025}
parent 04be0df8
...@@ -407,9 +407,9 @@ float SVGAnimationElement::CalculatePercentForSpline( ...@@ -407,9 +407,9 @@ float SVGAnimationElement::CalculatePercentForSpline(
} }
float SVGAnimationElement::CalculatePercentFromKeyPoints(float percent) const { float SVGAnimationElement::CalculatePercentFromKeyPoints(float percent) const {
DCHECK(!key_points_.IsEmpty());
DCHECK_NE(GetCalcMode(), kCalcModePaced); DCHECK_NE(GetCalcMode(), kCalcModePaced);
DCHECK_GT(KeyTimes().size(), 1u); DCHECK_GT(KeyTimes().size(), 1u);
DCHECK(!key_points_.IsEmpty());
DCHECK_EQ(key_points_.size(), KeyTimes().size()); DCHECK_EQ(key_points_.size(), KeyTimes().size());
if (percent == 1) if (percent == 1)
...@@ -442,27 +442,25 @@ float SVGAnimationElement::CalculatePercentForFromTo(float percent) const { ...@@ -442,27 +442,25 @@ float SVGAnimationElement::CalculatePercentForFromTo(float percent) const {
return percent; return percent;
} }
void SVGAnimationElement::CurrentValuesFromKeyPoints(float percent, float SVGAnimationElement::CurrentValuesFromKeyPoints(float percent,
float& effective_percent,
String& from, String& from,
String& to) const { String& to) const {
DCHECK_NE(GetCalcMode(), kCalcModePaced);
DCHECK(!key_points_.IsEmpty()); DCHECK(!key_points_.IsEmpty());
DCHECK_EQ(key_points_.size(), KeyTimes().size()); DCHECK_EQ(key_points_.size(), KeyTimes().size());
DCHECK_NE(GetCalcMode(), kCalcModePaced); float effective_percent = CalculatePercentFromKeyPoints(percent);
effective_percent = CalculatePercentFromKeyPoints(percent);
unsigned index = unsigned index =
effective_percent == 1 effective_percent == 1
? values_.size() - 2 ? values_.size() - 2
: static_cast<unsigned>(effective_percent * (values_.size() - 1)); : static_cast<unsigned>(effective_percent * (values_.size() - 1));
from = values_[index]; from = values_[index];
to = values_[index + 1]; to = values_[index + 1];
return effective_percent;
} }
void SVGAnimationElement::CurrentValuesForValuesAnimation( float SVGAnimationElement::CurrentValuesForValuesAnimation(float percent,
float percent,
float& effective_percent,
String& from, String& from,
String& to) { String& to) const {
unsigned values_count = values_.size(); unsigned values_count = values_.size();
DCHECK_EQ(animation_valid_, AnimationValidity::kValid); DCHECK_EQ(animation_valid_, AnimationValidity::kValid);
DCHECK_GE(values_count, 1u); DCHECK_GE(values_count, 1u);
...@@ -470,8 +468,7 @@ void SVGAnimationElement::CurrentValuesForValuesAnimation( ...@@ -470,8 +468,7 @@ void SVGAnimationElement::CurrentValuesForValuesAnimation(
if (percent == 1 || values_count == 1) { if (percent == 1 || values_count == 1) {
from = values_[values_count - 1]; from = values_[values_count - 1];
to = values_[values_count - 1]; to = values_[values_count - 1];
effective_percent = 1; return 1;
return;
} }
CalcMode calc_mode = GetCalcMode(); CalcMode calc_mode = GetCalcMode();
...@@ -480,7 +477,7 @@ void SVGAnimationElement::CurrentValuesForValuesAnimation( ...@@ -480,7 +477,7 @@ void SVGAnimationElement::CurrentValuesForValuesAnimation(
calc_mode = kCalcModeDiscrete; calc_mode = kCalcModeDiscrete;
} }
if (!key_points_.IsEmpty() && calc_mode != kCalcModePaced) if (!key_points_.IsEmpty() && calc_mode != kCalcModePaced)
return CurrentValuesFromKeyPoints(percent, effective_percent, from, to); return CurrentValuesFromKeyPoints(percent, from, to);
unsigned key_times_count = KeyTimes().size(); unsigned key_times_count = KeyTimes().size();
DCHECK(!key_times_count || values_count == key_times_count); DCHECK(!key_times_count || values_count == key_times_count);
...@@ -492,8 +489,7 @@ void SVGAnimationElement::CurrentValuesForValuesAnimation( ...@@ -492,8 +489,7 @@ void SVGAnimationElement::CurrentValuesForValuesAnimation(
index = static_cast<unsigned>(percent * values_count); index = static_cast<unsigned>(percent * values_count);
from = values_[index]; from = values_[index];
to = values_[index]; to = values_[index];
effective_percent = 0; return 0;
return;
} }
float from_percent; float from_percent;
...@@ -512,12 +508,14 @@ void SVGAnimationElement::CurrentValuesForValuesAnimation( ...@@ -512,12 +508,14 @@ void SVGAnimationElement::CurrentValuesForValuesAnimation(
from = values_[index]; from = values_[index];
to = values_[index + 1]; to = values_[index + 1];
DCHECK_GT(to_percent, from_percent); DCHECK_GT(to_percent, from_percent);
effective_percent = (percent - from_percent) / (to_percent - from_percent); float effective_percent =
(percent - from_percent) / (to_percent - from_percent);
if (calc_mode == kCalcModeSpline) { if (calc_mode == kCalcModeSpline) {
DCHECK_EQ(key_splines_.size(), values_.size() - 1); DCHECK_EQ(key_splines_.size(), values_.size() - 1);
effective_percent = CalculatePercentForSpline(effective_percent, index); effective_percent = CalculatePercentForSpline(effective_percent, index);
} }
return effective_percent;
} }
bool SVGAnimationElement::CalculateValuesAnimation() { bool SVGAnimationElement::CalculateValuesAnimation() {
...@@ -631,7 +629,7 @@ void SVGAnimationElement::UpdateAnimation(float percent, ...@@ -631,7 +629,7 @@ void SVGAnimationElement::UpdateAnimation(float percent,
if (animation_mode == kValuesAnimation) { if (animation_mode == kValuesAnimation) {
String from; String from;
String to; String to;
CurrentValuesForValuesAnimation(percent, effective_percent, from, to); effective_percent = CurrentValuesForValuesAnimation(percent, from, to);
if (from != last_values_animation_from_ || if (from != last_values_animation_from_ ||
to != last_values_animation_to_) { to != last_values_animation_to_) {
if (!CalculateFromAndToValues(from, to)) { if (!CalculateFromAndToValues(from, to)) {
...@@ -641,17 +639,18 @@ void SVGAnimationElement::UpdateAnimation(float percent, ...@@ -641,17 +639,18 @@ void SVGAnimationElement::UpdateAnimation(float percent,
last_values_animation_from_ = from; last_values_animation_from_ = from;
last_values_animation_to_ = to; last_values_animation_to_ = to;
} }
} else if (!key_points_.IsEmpty() && calc_mode != kCalcModePaced) } else if (calc_mode != kCalcModePaced && !key_points_.IsEmpty()) {
effective_percent = CalculatePercentFromKeyPoints(percent); effective_percent = CalculatePercentFromKeyPoints(percent);
else if (key_points_.IsEmpty() && calc_mode == kCalcModeSpline && } else if (calc_mode == kCalcModeSpline && key_points_.IsEmpty() &&
KeyTimes().size() > 1) KeyTimes().size() > 1) {
effective_percent = effective_percent =
CalculatePercentForSpline(percent, CalculateKeyTimesIndex(percent)); CalculatePercentForSpline(percent, CalculateKeyTimesIndex(percent));
else if (animation_mode == kFromToAnimation || animation_mode == kToAnimation) } else if (animation_mode == kFromToAnimation ||
animation_mode == kToAnimation) {
effective_percent = CalculatePercentForFromTo(percent); effective_percent = CalculatePercentForFromTo(percent);
else } else {
effective_percent = percent; effective_percent = percent;
}
CalculateAnimatedValue(effective_percent, repeat_count, result_element); CalculateAnimatedValue(effective_percent, repeat_count, result_element);
} }
......
...@@ -162,10 +162,9 @@ class CORE_EXPORT SVGAnimationElement : public SVGSMILElement { ...@@ -162,10 +162,9 @@ class CORE_EXPORT SVGAnimationElement : public SVGSMILElement {
} }
bool CalculateValuesAnimation(); bool CalculateValuesAnimation();
void CurrentValuesForValuesAnimation(float percent, float CurrentValuesForValuesAnimation(float percent,
float& effective_percent,
String& from, String& from,
String& to); String& to) const;
// Also decides which list is to be used, either key_times_from_attribute_ // Also decides which list is to be used, either key_times_from_attribute_
// or key_times_for_paced_ by toggling the flag use_paced_key_times_. // or key_times_for_paced_ by toggling the flag use_paced_key_times_.
void CalculateKeyTimesForCalcModePaced(); void CalculateKeyTimesForCalcModePaced();
...@@ -176,8 +175,7 @@ class CORE_EXPORT SVGAnimationElement : public SVGSMILElement { ...@@ -176,8 +175,7 @@ class CORE_EXPORT SVGAnimationElement : public SVGSMILElement {
} }
float CalculatePercentFromKeyPoints(float percent) const; float CalculatePercentFromKeyPoints(float percent) const;
void CurrentValuesFromKeyPoints(float percent, float CurrentValuesFromKeyPoints(float percent,
float& effective_percent,
String& from, String& from,
String& to) const; String& to) const;
float CalculatePercentForSpline(float percent, unsigned spline_index) const; float CalculatePercentForSpline(float percent, unsigned spline_index) const;
......
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