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

Move some animation interface from SVGSMILElement to subclasses

This moves the "animation interface", i.e the methods:

  ResetAnimatedType(),
  ClearAnimatedType(),
  ApplyResultsToTarget(),
  OverwritesUnderlyingAnimationValue() and
  UpdateAnimation()

From SVGSMILElement to SVGAnimationElement.
This means that we can make the SMILAnimationSandwich only care
about SVGAnimationElements which is slightly more logical.
The |attribute_name_| field is also moved to more logical place, namely
SVGAnimateElement.

Bug: 1017723
Change-Id: I870cca66b44d42288b40cb5d09cd06c04160420d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1928775Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#717643}
parent 9a085676
......@@ -5,7 +5,6 @@
#include "third_party/blink/renderer/core/svg/animation/element_smil_animations.h"
#include "third_party/blink/renderer/core/svg/animation/smil_animation_sandwich.h"
#include "third_party/blink/renderer/core/svg/svg_animation_element.h"
namespace blink {
......
......@@ -27,7 +27,7 @@
#include <algorithm>
#include "third_party/blink/renderer/core/svg/animation/svg_smil_element.h"
#include "third_party/blink/renderer/core/svg/svg_animation_element.h"
namespace blink {
......@@ -46,12 +46,12 @@ struct PriorityCompare {
SMILAnimationSandwich::SMILAnimationSandwich() = default;
void SMILAnimationSandwich::Add(SVGSMILElement* animation) {
void SMILAnimationSandwich::Add(SVGAnimationElement* animation) {
DCHECK(!sandwich_.Contains(animation));
sandwich_.push_back(animation);
}
void SMILAnimationSandwich::Remove(SVGSMILElement* animation) {
void SMILAnimationSandwich::Remove(SVGAnimationElement* animation) {
auto* position = std::find(sandwich_.begin(), sandwich_.end(), animation);
DCHECK(sandwich_.end() != position);
sandwich_.erase(position);
......@@ -61,7 +61,7 @@ void SMILAnimationSandwich::Remove(SVGSMILElement* animation) {
}
}
SVGSMILElement* SMILAnimationSandwich::ResultElement() const {
SVGAnimationElement* SMILAnimationSandwich::ResultElement() const {
return !active_.IsEmpty() ? active_.front() : nullptr;
}
......@@ -73,7 +73,7 @@ void SMILAnimationSandwich::UpdateActiveAnimationStack(
PriorityCompare(presentation_time));
}
SVGSMILElement* old_result_element = ResultElement();
SVGAnimationElement* old_result_element = ResultElement();
active_.Shrink(0);
active_.ReserveCapacity(sandwich_.size());
// Build the contributing/active sandwich.
......@@ -89,7 +89,7 @@ void SMILAnimationSandwich::UpdateActiveAnimationStack(
}
bool SMILAnimationSandwich::ApplyAnimationValues() {
SVGSMILElement* result_element = ResultElement();
SVGAnimationElement* result_element = ResultElement();
if (!result_element)
return false;
......@@ -112,7 +112,7 @@ bool SMILAnimationSandwich::ApplyAnimationValues() {
for (auto* sandwich_it = sandwich_start; sandwich_it != active_.end();
sandwich_it++) {
(*sandwich_it)->UpdateAnimatedValue(result_element);
(*sandwich_it)->ApplyAnimation(result_element);
}
result_element->ApplyResultsToTarget();
......
......@@ -27,12 +27,13 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_ANIMATION_SMIL_ANIMATION_SANDWICH_H_
#include "third_party/blink/renderer/core/svg/animation/smil_time.h"
#include "third_party/blink/renderer/core/svg/animation/svg_smil_element.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
class SVGAnimationElement;
// This class implements/helps with implementing the "sandwich model" from SMIL.
// https://www.w3.org/TR/SMIL3/smil-animation.html#animationNS-AnimationSandwichModel
//
......@@ -95,11 +96,10 @@ namespace blink {
//
class SMILAnimationSandwich : public GarbageCollected<SMILAnimationSandwich> {
public:
using ScheduledVector = HeapVector<Member<SVGSMILElement>>;
SMILAnimationSandwich();
void Add(SVGSMILElement* animation);
void Remove(SVGSMILElement* animation);
void Add(SVGAnimationElement* animation);
void Remove(SVGAnimationElement* animation);
void UpdateActiveAnimationStack(SMILTime presentation_time);
bool ApplyAnimationValues();
......@@ -112,15 +112,17 @@ class SMILAnimationSandwich : public GarbageCollected<SMILAnimationSandwich> {
// Results are accumulated to the first animation element that animates and
// contributes to a particular element/attribute pair. We refer to this as
// the "result element".
SVGSMILElement* ResultElement() const;
SVGAnimationElement* ResultElement() const;
using AnimationsVector = HeapVector<Member<SVGAnimationElement>>;
// All the animation (really: timed) elements that make up the sandwich,
// sorted according to priority.
ScheduledVector sandwich_;
AnimationsVector sandwich_;
// The currently active animation elements in the sandwich. Retains the
// ordering of elements from |sandwich_| when created. This is the animation
// elements from which the animation value is computed.
ScheduledVector active_;
AnimationsVector active_;
};
} // namespace blink
......
......@@ -179,7 +179,6 @@ void SVGSMILElement::Condition::DisconnectEventBase(
SVGSMILElement::SVGSMILElement(const QualifiedName& tag_name, Document& doc)
: SVGElement(tag_name, doc),
SVGTests(this),
attribute_name_(AnyQName()),
target_element_(nullptr),
conditions_connected_(false),
has_end_event_conditions_(false),
......
......@@ -59,7 +59,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
bool HasValidTarget() const;
SVGElement* targetElement() const { return target_element_; }
const QualifiedName& AttributeName() const { return attribute_name_; }
void BeginByLinkActivation();
......@@ -90,10 +89,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
SMILTime ComputeNextIntervalTime(SMILTime presentation_time) const;
SMILTime NextProgressTime(SMILTime elapsed) const;
void UpdateAnimatedValue(SVGSMILElement* result_element) {
UpdateAnimation(last_progress_.progress, last_progress_.repeat,
result_element);
}
void Reset();
......@@ -107,15 +102,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
wtf_size_t& PriorityQueueHandle() { return queue_handle_; }
virtual void ResetAnimatedType() = 0;
virtual void ClearAnimatedType() = 0;
virtual void ApplyResultsToTarget() = 0;
// Returns true if this animation "sets" the
// value of the animation. Thus all previous
// animations are rendered useless.
virtual bool OverwritesUnderlyingAnimationValue() const = 0;
void ScheduleEvent(const AtomicString& event_type);
void ScheduleRepeatEvents();
......@@ -137,7 +123,11 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
virtual void StartedActiveInterval();
void QueueDiscard();
QualifiedName attribute_name_;
struct ProgressState {
float progress;
unsigned repeat;
};
const ProgressState& GetProgressState() const { return last_progress_; }
private:
void BuildPendingResource() override;
......@@ -145,9 +135,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
void ClearConditions();
void EndedActiveInterval();
virtual void UpdateAnimation(float percent,
unsigned repeat,
SVGSMILElement* result_element) = 0;
bool LayoutObjectIsNeeded(const ComputedStyle&) const override {
return false;
......@@ -243,10 +230,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
}
ActiveState DetermineActiveState(SMILTime elapsed) const;
struct ProgressState {
float progress;
unsigned repeat;
};
ProgressState CalculateProgressState(SMILTime presentation_time) const;
Member<SVGElement> target_element_;
......
......@@ -105,6 +105,7 @@ SVGAnimateElement::SVGAnimateElement(Document& document)
SVGAnimateElement::SVGAnimateElement(const QualifiedName& tag_name,
Document& document)
: SVGAnimationElement(tag_name, document),
attribute_name_(AnyQName()),
type_(kAnimatedUnknown),
css_property_id_(CSSPropertyID::kInvalid),
from_property_value_type_(kRegularPropertyValue),
......
......@@ -49,6 +49,7 @@ class CORE_EXPORT SVGAnimateElement : public SVGAnimationElement {
bool IsSVGAnimationAttributeSettingJavaScriptURL(
const Attribute&) const override;
const QualifiedName& AttributeName() const { return attribute_name_; }
AnimatedPropertyType GetAnimatedPropertyType() const;
bool AnimatedPropertyTypeSupportsAddition() const;
bool IsAdditive() const final;
......@@ -116,6 +117,7 @@ class CORE_EXPORT SVGAnimateElement : public SVGAnimationElement {
protected:
Member<SVGAnimatedPropertyBase> target_property_;
QualifiedName attribute_name_;
AnimatedPropertyType type_;
CSSPropertyID css_property_id_;
......
......@@ -647,9 +647,7 @@ bool SVGAnimationElement::CheckAnimationParameters() {
return false;
}
void SVGAnimationElement::UpdateAnimation(float percent,
unsigned repeat_count,
SVGSMILElement* result_element) {
void SVGAnimationElement::ApplyAnimation(SVGAnimationElement* result_element) {
if (animation_valid_ == AnimationValidity::kUnknown) {
if (CheckAnimationParameters()) {
animation_valid_ = AnimationValidity::kValid;
......@@ -668,6 +666,9 @@ void SVGAnimationElement::UpdateAnimation(float percent,
if (animation_valid_ != AnimationValidity::kValid || !targetElement())
return;
const ProgressState& progress_state = GetProgressState();
const float percent = progress_state.progress;
float effective_percent;
CalcMode calc_mode = GetCalcMode();
AnimationMode animation_mode = GetAnimationMode();
......@@ -696,7 +697,8 @@ void SVGAnimationElement::UpdateAnimation(float percent,
} else {
effective_percent = percent;
}
CalculateAnimatedValue(effective_percent, repeat_count, result_element);
CalculateAnimatedValue(effective_percent, progress_state.repeat,
result_element);
}
bool SVGAnimationElement::OverwritesUnderlyingAnimationValue() const {
......
......@@ -74,7 +74,13 @@ class CORE_EXPORT SVGAnimationElement : public SVGSMILElement {
AnimationMode GetAnimationMode() const { return animation_mode_; }
CalcMode GetCalcMode() const { return calc_mode_; }
bool OverwritesUnderlyingAnimationValue() const override;
virtual void ResetAnimatedType() = 0;
virtual void ClearAnimatedType() = 0;
virtual void ApplyResultsToTarget() = 0;
// Returns true if this animation "sets" the value of the animation. Thus all
// previous animations are rendered useless.
bool OverwritesUnderlyingAnimationValue() const;
void ApplyAnimation(SVGAnimationElement* result_element);
void AnimateAdditiveNumber(float percentage,
unsigned repeat_count,
......@@ -101,11 +107,6 @@ class CORE_EXPORT SVGAnimationElement : public SVGSMILElement {
void ParseAttribute(const AttributeModificationParams&) override;
// from SVGSMILElement
void UpdateAnimation(float percent,
unsigned repeat,
SVGSMILElement* result_element) override;
virtual void UpdateAnimationMode();
void SetAnimationMode(AnimationMode animation_mode) {
animation_mode_ = animation_mode;
......
......@@ -45,15 +45,6 @@ class SVGDiscardElement final : public SVGSMILElement {
private:
void StartedActiveInterval() override;
void ResetAnimatedType() override {}
void ClearAnimatedType() override {}
void ApplyResultsToTarget() override {}
bool OverwritesUnderlyingAnimationValue() const override { return false; }
void UpdateAnimation(float percent,
unsigned repeat,
SVGSMILElement* result_element) override {}
};
} // namespace blink
......
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