diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/core/svg')
219 files changed, 2161 insertions, 1376 deletions
diff --git a/chromium/third_party/blink/renderer/core/svg/BUILD.gn b/chromium/third_party/blink/renderer/core/svg/BUILD.gn index 785be87b9c8..d69850b5ec9 100644 --- a/chromium/third_party/blink/renderer/core/svg/BUILD.gn +++ b/chromium/third_party/blink/renderer/core/svg/BUILD.gn @@ -99,8 +99,6 @@ blink_core_sources("svg") { "svg_defs_element.h", "svg_desc_element.cc", "svg_desc_element.h", - "svg_discard_element.cc", - "svg_discard_element.h", "svg_document_extensions.cc", "svg_document_extensions.h", "svg_element.cc", diff --git a/chromium/third_party/blink/renderer/core/svg/animation/smil_animation_sandwich.cc b/chromium/third_party/blink/renderer/core/svg/animation/smil_animation_sandwich.cc index e0689f43684..2efc2b2b522 100644 --- a/chromium/third_party/blink/renderer/core/svg/animation/smil_animation_sandwich.cc +++ b/chromium/third_party/blink/renderer/core/svg/animation/smil_animation_sandwich.cc @@ -119,7 +119,7 @@ bool SMILAnimationSandwich::ApplyAnimationValues() { return true; } -void SMILAnimationSandwich::Trace(blink::Visitor* visitor) { +void SMILAnimationSandwich::Trace(Visitor* visitor) { visitor->Trace(sandwich_); visitor->Trace(active_); } diff --git a/chromium/third_party/blink/renderer/core/svg/animation/smil_animation_sandwich.h b/chromium/third_party/blink/renderer/core/svg/animation/smil_animation_sandwich.h index c31ffb29647..7c0f5d26ec8 100644 --- a/chromium/third_party/blink/renderer/core/svg/animation/smil_animation_sandwich.h +++ b/chromium/third_party/blink/renderer/core/svg/animation/smil_animation_sandwich.h @@ -106,7 +106,7 @@ class SMILAnimationSandwich : public GarbageCollected<SMILAnimationSandwich> { bool IsEmpty() { return sandwich_.IsEmpty(); } - void Trace(blink::Visitor*); + void Trace(Visitor*); private: // Results are accumulated to the first animation element that animates and diff --git a/chromium/third_party/blink/renderer/core/svg/animation/smil_time.h b/chromium/third_party/blink/renderer/core/svg/animation/smil_time.h index 7433a3a1c85..10286c62091 100644 --- a/chromium/third_party/blink/renderer/core/svg/animation/smil_time.h +++ b/chromium/third_party/blink/renderer/core/svg/animation/smil_time.h @@ -30,6 +30,7 @@ #include <ostream> #include "base/time/time.h" +#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" #include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/hash_traits.h" @@ -136,7 +137,7 @@ class SMILTime { base::TimeDelta time_; }; -std::ostream& operator<<(std::ostream& os, SMILTime time); +CORE_EXPORT std::ostream& operator<<(std::ostream& os, SMILTime time); // What generated a SMILTime. enum class SMILTimeOrigin { @@ -208,4 +209,14 @@ inline bool operator!=(const SMILInterval& a, const SMILInterval& b) { } // namespace blink +namespace WTF { +template <> +struct HashTraits<blink::SMILInterval> + : GenericHashTraits<blink::SMILInterval> { + static blink::SMILInterval EmptyValue() { + return blink::SMILInterval::Unresolved(); + } +}; +} // namespace WTF + #endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_ANIMATION_SMIL_TIME_H_ diff --git a/chromium/third_party/blink/renderer/core/svg/animation/smil_time_container.cc b/chromium/third_party/blink/renderer/core/svg/animation/smil_time_container.cc index eeac5fd38aa..ad245c6aec1 100644 --- a/chromium/third_party/blink/renderer/core/svg/animation/smil_time_container.cc +++ b/chromium/third_party/blink/renderer/core/svg/animation/smil_time_container.cc @@ -26,7 +26,6 @@ #include "third_party/blink/renderer/core/svg/animation/smil_time_container.h" #include <algorithm> -#include "third_party/blink/renderer/core/animation/animation_clock.h" #include "third_party/blink/renderer/core/animation/document_timeline.h" #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/element_traversal.h" @@ -35,6 +34,7 @@ #include "third_party/blink/renderer/core/frame/web_feature.h" #include "third_party/blink/renderer/core/svg/animation/element_smil_animations.h" #include "third_party/blink/renderer/core/svg/animation/svg_smil_element.h" +#include "third_party/blink/renderer/core/svg/graphics/svg_image.h" #include "third_party/blink/renderer/core/svg/svg_svg_element.h" #include "third_party/blink/renderer/platform/instrumentation/use_counter.h" @@ -57,28 +57,115 @@ class AnimationTargetsMutationsForbidden { #endif }; -static constexpr base::TimeDelta kAnimationPolicyOnceDuration = - base::TimeDelta::FromSeconds(3); +class SMILTimeContainer::TimingUpdate { + STACK_ALLOCATED(); + + public: + // The policy used when performing the timing update. + enum MovePolicy { + // Used for regular updates, i.e when time is running. All events will be + // dispatched. + kNormal, + // Used for seeking updates, i.e when time is explicitly + // set/changed. Events are not dispatched for skipped intervals, and no + // repeats are generated. + kSeek, + }; + TimingUpdate(SMILTimeContainer& time_container, + SMILTime target_time, + MovePolicy policy) + : target_time_(target_time), + policy_(policy), + time_container_(&time_container) { + DCHECK_LE(target_time_, time_container_->max_presentation_time_); + } + ~TimingUpdate(); + + const SMILTime& Time() const { return time_container_->latest_update_time_; } + bool TryAdvanceTime(SMILTime next_time) { + if (time_container_->latest_update_time_ >= target_time_) + return false; + if (next_time > target_time_) { + time_container_->latest_update_time_ = target_time_; + return false; + } + time_container_->latest_update_time_ = next_time; + return true; + } + void RewindTimeToZero() { time_container_->latest_update_time_ = SMILTime(); } + const SMILTime& TargetTime() const { return target_time_; } + bool IsSeek() const { return policy_ == kSeek; } + void AddActiveElement(SVGSMILElement*, const SMILInterval&); + void HandleEvents(SVGSMILElement*, SVGSMILElement::EventDispatchMask); + bool ShouldDispatchEvents() const { + return time_container_->should_dispatch_events_; + } + + using UpdatedElementsMap = HeapHashMap<Member<SVGSMILElement>, SMILInterval>; + UpdatedElementsMap& UpdatedElements() { return updated_elements_; } + + TimingUpdate(const TimingUpdate&) = delete; + TimingUpdate& operator=(const TimingUpdate&) = delete; + + private: + SMILTime target_time_; + MovePolicy policy_; + SMILTimeContainer* time_container_; + UpdatedElementsMap updated_elements_; +}; + +SMILTimeContainer::TimingUpdate::~TimingUpdate() { + if (!ShouldDispatchEvents()) + return; + DCHECK(IsSeek() || updated_elements_.IsEmpty()); + for (const auto& entry : updated_elements_) { + SVGSMILElement* element = entry.key; + if (auto events_to_dispatch = element->ComputeSeekEvents(entry.value)) + element->DispatchEvents(events_to_dispatch); + } +} + +void SMILTimeContainer::TimingUpdate::AddActiveElement( + SVGSMILElement* element, + const SMILInterval& interval) { + DCHECK(IsSeek()); + DCHECK(ShouldDispatchEvents()); + updated_elements_.insert(element, interval); +} + +void SMILTimeContainer::TimingUpdate::HandleEvents( + SVGSMILElement* element, + SVGSMILElement::EventDispatchMask events_to_dispatch) { + if (!IsSeek()) { + if (ShouldDispatchEvents() && events_to_dispatch) + element->DispatchEvents(events_to_dispatch); + return; + } + // Even if no events will be dispatched, we still need to track the elements + // that has been updated so that we can adjust their next interval time when + // we're done. (If we tracked active elements separately this would not be + // necessary.) + updated_elements_.insert(element, SMILInterval::Unresolved()); +} SMILTimeContainer::SMILTimeContainer(SVGSVGElement& owner) : frame_scheduling_state_(kIdle), started_(false), paused_(false), + should_dispatch_events_(!SVGImage::IsInSVGImage(&owner)), document_order_indexes_dirty_(false), is_updating_intervals_(false), wakeup_timer_( owner.GetDocument().GetTaskRunner(TaskType::kInternalDefault), this, &SMILTimeContainer::WakeupTimerFired), - animation_policy_once_timer_( - owner.GetDocument().GetTaskRunner(TaskType::kInternalDefault), - this, - &SMILTimeContainer::AnimationPolicyTimerFired), - owner_svg_element_(&owner) {} + owner_svg_element_(&owner) { + // Update the max presentation time based on the animation policy in effect. + SetPresentationTime(presentation_time_); +} SMILTimeContainer::~SMILTimeContainer() { CancelAnimationFrame(); - CancelAnimationPolicyTimer(); DCHECK(!wakeup_timer_.IsActive()); DCHECK(AnimationTargetsMutationsAllowed()); } @@ -101,7 +188,6 @@ void SMILTimeContainer::Unschedule(SVGSMILElement* animation) { DCHECK(animated_targets_.Contains(animation->targetElement())); animated_targets_.erase(animation->targetElement()); - pending_discards_.erase(animation); priority_queue_.Remove(animation); } @@ -145,14 +231,14 @@ SMILTime SMILTimeContainer::Elapsed() const { return presentation_time_; base::TimeDelta time_offset = - GetDocument().Timeline().CurrentTimeInternal().value_or( + GetDocument().Timeline().CurrentPhaseAndTime().time.value_or( base::TimeDelta()) - reference_time_; DCHECK_GE(time_offset, base::TimeDelta()); SMILTime elapsed = presentation_time_ + SMILTime::FromMicroseconds(time_offset.InMicroseconds()); DCHECK_GE(elapsed, SMILTime()); - return elapsed; + return ClampPresentationTime(elapsed); } void SMILTimeContainer::ResetDocumentTime() { @@ -174,13 +260,14 @@ SMILTime SMILTimeContainer::LatestUpdatePresentationTime() const { } void SMILTimeContainer::SynchronizeToDocumentTimeline() { - reference_time_ = GetDocument().Timeline().CurrentTimeInternal().value_or( - base::TimeDelta()); + reference_time_ = + GetDocument().Timeline().CurrentPhaseAndTime().time.value_or( + base::TimeDelta()); } bool SMILTimeContainer::IsPaused() const { // If animation policy is "none", the timeline is always paused. - return paused_ || AnimationPolicy() == kImageAnimationPolicyNoAnimation; + return paused_ || AnimationsDisabled(); } bool SMILTimeContainer::IsStarted() const { @@ -194,10 +281,7 @@ bool SMILTimeContainer::IsTimelineRunning() const { void SMILTimeContainer::Start() { CHECK(!IsStarted()); - if (!GetDocument().IsActive()) - return; - - if (!HandleAnimationPolicy(kRestartOnceTimerIfNotPaused)) + if (AnimationsDisabled()) return; // Sample the document timeline to get a time reference for the "presentation @@ -205,24 +289,26 @@ void SMILTimeContainer::Start() { SynchronizeToDocumentTimeline(); started_ = true; - UpdateAnimationsAndScheduleFrameIfNeeded(presentation_time_); + TimingUpdate update(*this, presentation_time_, TimingUpdate::kSeek); + UpdateAnimationsAndScheduleFrameIfNeeded(update); } void SMILTimeContainer::Pause() { - if (!HandleAnimationPolicy(kCancelOnceTimer)) + if (AnimationsDisabled()) return; DCHECK(!IsPaused()); if (IsStarted()) { - presentation_time_ = Elapsed(); + SetPresentationTime(Elapsed()); CancelAnimationFrame(); } + // Update the flag after sampling elapsed(). paused_ = true; } void SMILTimeContainer::Unpause() { - if (!HandleAnimationPolicy(kRestartOnceTimer)) + if (AnimationsDisabled()) return; DCHECK(IsPaused()); @@ -235,10 +321,31 @@ void SMILTimeContainer::Unpause() { ScheduleWakeUp(base::TimeDelta(), kSynchronizeAnimations); } +void SMILTimeContainer::SetPresentationTime(SMILTime new_presentation_time) { + // Start by resetting the max presentation time, because if the + // animation-policy is "once" we'll set a new limit below regardless, and for + // the other cases it's the right thing to do. + // + // We can't seek beyond this time, because at Latest() any additions will + // yield the same value. + max_presentation_time_ = SMILTime::Latest() - SMILTime::Epsilon(); + presentation_time_ = ClampPresentationTime(new_presentation_time); + if (AnimationPolicy() != kImageAnimationPolicyAnimateOnce) + return; + const SMILTime kAnimationPolicyOnceDuration = SMILTime::FromSecondsD(3); + max_presentation_time_ = + ClampPresentationTime(presentation_time_ + kAnimationPolicyOnceDuration); +} + +SMILTime SMILTimeContainer::ClampPresentationTime( + SMILTime presentation_time) const { + return std::min(presentation_time, max_presentation_time_); +} + void SMILTimeContainer::SetElapsed(SMILTime elapsed) { - presentation_time_ = elapsed; + SetPresentationTime(elapsed); - if (!GetDocument().IsActive()) + if (AnimationsDisabled()) return; // If the document hasn't finished loading, |presentation_time_| will be @@ -246,22 +353,14 @@ void SMILTimeContainer::SetElapsed(SMILTime elapsed) { if (!IsStarted()) return; - if (!HandleAnimationPolicy(kRestartOnceTimerIfNotPaused)) - return; - CancelAnimationFrame(); if (!IsPaused()) SynchronizeToDocumentTimeline(); - // If we are rewinding the timeline, we need to start from 0 and then move - // forward to the new presentation time. If we're moving forward we can just - // perform the update in the normal fashion. - if (elapsed < latest_update_time_) { - ResetIntervals(); - latest_update_time_ = SMILTime(); - } - UpdateAnimationsAndScheduleFrameIfNeeded(elapsed); + TimingUpdate update(*this, presentation_time_, TimingUpdate::kSeek); + PrepareSeek(update); + UpdateAnimationsAndScheduleFrameIfNeeded(update); } void SMILTimeContainer::ScheduleAnimationFrame(base::TimeDelta delay_time) { @@ -306,62 +405,20 @@ void SMILTimeContainer::WakeupTimerFired(TimerBase*) { DCHECK(IsTimelineRunning()); ServiceOnNextFrame(); } else { - UpdateAnimationsAndScheduleFrameIfNeeded(Elapsed()); + TimingUpdate update(*this, Elapsed(), TimingUpdate::kNormal); + UpdateAnimationsAndScheduleFrameIfNeeded(update); } } -void SMILTimeContainer::ScheduleAnimationPolicyTimer() { - animation_policy_once_timer_.StartOneShot(kAnimationPolicyOnceDuration, - FROM_HERE); -} - -void SMILTimeContainer::CancelAnimationPolicyTimer() { - animation_policy_once_timer_.Stop(); -} - -void SMILTimeContainer::AnimationPolicyTimerFired(TimerBase*) { - Pause(); +ImageAnimationPolicy SMILTimeContainer::AnimationPolicy() const { + const Settings* settings = GetDocument().GetSettings(); + return settings ? settings->GetImageAnimationPolicy() + : kImageAnimationPolicyAllowed; } -ImageAnimationPolicy SMILTimeContainer::AnimationPolicy() const { - Settings* settings = GetDocument().GetSettings(); - if (!settings) - return kImageAnimationPolicyAllowed; - - return settings->GetImageAnimationPolicy(); -} - -bool SMILTimeContainer::HandleAnimationPolicy( - AnimationPolicyOnceAction once_action) { - ImageAnimationPolicy policy = AnimationPolicy(); - // If the animation policy is "none", control is not allowed. - // returns false to exit flow. - if (policy == kImageAnimationPolicyNoAnimation) - return false; - // If the animation policy is "once", - if (policy == kImageAnimationPolicyAnimateOnce) { - switch (once_action) { - case kRestartOnceTimerIfNotPaused: - if (IsPaused()) - break; - FALLTHROUGH; - case kRestartOnceTimer: - ScheduleAnimationPolicyTimer(); - break; - case kCancelOnceTimer: - CancelAnimationPolicyTimer(); - break; - } - } - if (policy == kImageAnimationPolicyAllowed) { - // When the SVG owner element becomes detached from its document, - // the policy defaults to ImageAnimationPolicyAllowed; there's - // no way back. If the policy had been "once" prior to that, - // ensure cancellation of its timer. - if (once_action == kCancelOnceTimer) - CancelAnimationPolicyTimer(); - } - return true; +bool SMILTimeContainer::AnimationsDisabled() const { + return !GetDocument().IsActive() || + AnimationPolicy() == kImageAnimationPolicyNoAnimation; } void SMILTimeContainer::UpdateDocumentOrderIndexes() { @@ -395,39 +452,38 @@ void SMILTimeContainer::ServiceAnimations() { // document, so this should be turned into a DCHECK. if (!GetDocument().IsActive()) return; - UpdateAnimationsAndScheduleFrameIfNeeded(Elapsed()); -} - -bool SMILTimeContainer::CanScheduleFrame(SMILTime earliest_fire_time) const { - // If there's synchronization pending (most likely due to syncbases), then - // let that complete first before attempting to schedule a frame. - if (HasPendingSynchronization()) - return false; - if (!IsTimelineRunning()) - return false; - return earliest_fire_time.IsFinite(); + TimingUpdate update(*this, Elapsed(), TimingUpdate::kNormal); + UpdateAnimationsAndScheduleFrameIfNeeded(update); } void SMILTimeContainer::UpdateAnimationsAndScheduleFrameIfNeeded( - SMILTime elapsed) { + TimingUpdate& update) { DCHECK(GetDocument().IsActive()); DCHECK(!wakeup_timer_.IsActive()); - - UpdateAnimationTimings(elapsed); - ApplyTimedEffects(elapsed); - - SMILTime next_progress_time = NextProgressTime(elapsed); + // If the priority queue is empty, there are no timed elements to process and + // no animations to apply, so we are done. + if (priority_queue_.IsEmpty()) + return; + AnimationTargetsMutationsForbidden scope(this); + UpdateTimedElements(update); + ApplyTimedEffects(update.TargetTime()); DCHECK(!wakeup_timer_.IsActive()); + DCHECK(!HasPendingSynchronization()); - if (!CanScheduleFrame(next_progress_time)) + if (!IsTimelineRunning()) + return; + SMILTime next_progress_time = NextProgressTime(update.TargetTime()); + if (!next_progress_time.IsFinite()) return; - SMILTime delay_time = next_progress_time - elapsed; + SMILTime delay_time = next_progress_time - update.TargetTime(); DCHECK(delay_time.IsFinite()); ScheduleAnimationFrame( base::TimeDelta::FromMicroseconds(delay_time.InMicroseconds())); } SMILTime SMILTimeContainer::NextProgressTime(SMILTime presentation_time) const { + if (presentation_time == max_presentation_time_) + return SMILTime::Unresolved(); SMILTime next_progress_time = SMILTime::Unresolved(); for (const auto& entry : priority_queue_) { next_progress_time = std::min( @@ -438,6 +494,32 @@ SMILTime SMILTimeContainer::NextProgressTime(SMILTime presentation_time) const { return next_progress_time; } +void SMILTimeContainer::PrepareSeek(TimingUpdate& update) { + DCHECK(update.IsSeek()); + if (update.ShouldDispatchEvents()) { + // Record which elements are active at the current time so that we can + // correctly determine the transitions when the seek finishes. + // TODO(fs): Maybe keep track of the set of active timed elements and use + // that here (and in NextProgressTime). + for (auto& entry : priority_queue_) { + SVGSMILElement* element = entry.second; + const SMILInterval& active_interval = + element->GetActiveInterval(update.Time()); + if (!active_interval.Contains(update.Time())) + continue; + update.AddActiveElement(element, active_interval); + } + } + // If we are rewinding the timeline, we need to start from 0 and then move + // forward to the new presentation time. If we're moving forward we can just + // perform the update in the normal fashion. + if (update.TargetTime() < update.Time()) { + ResetIntervals(); + // TODO(fs): Clear resolved end times. + update.RewindTimeToZero(); + } +} + void SMILTimeContainer::ResetIntervals() { base::AutoReset<bool> updating_intervals_scope(&is_updating_intervals_, true); AnimationTargetsMutationsForbidden scope(this); @@ -449,7 +531,8 @@ void SMILTimeContainer::ResetIntervals() { priority_queue_.ResetAllPriorities(SMILTime::Earliest()); } -void SMILTimeContainer::UpdateIntervals(SMILTime document_time) { +void SMILTimeContainer::UpdateIntervals(TimingUpdate& update) { + const SMILTime document_time = update.Time(); DCHECK(document_time.IsFinite()); DCHECK_GE(document_time, SMILTime()); DCHECK(!priority_queue_.IsEmpty()); @@ -457,111 +540,66 @@ void SMILTimeContainer::UpdateIntervals(SMILTime document_time) { const size_t kMaxIterations = std::max(priority_queue_.size() * 16, 1000000u); size_t current_iteration = 0; + SVGSMILElement::IncludeRepeats repeat_handling = + update.IsSeek() ? SVGSMILElement::kExcludeRepeats + : SVGSMILElement::kIncludeRepeats; + base::AutoReset<bool> updating_intervals_scope(&is_updating_intervals_, true); while (priority_queue_.Min() <= document_time) { SVGSMILElement* element = priority_queue_.MinElement(); element->UpdateInterval(document_time); - element->UpdateActiveState(document_time); + auto events_to_dispatch = + element->UpdateActiveState(document_time, update.IsSeek()); + update.HandleEvents(element, events_to_dispatch); SMILTime next_interval_time = - element->ComputeNextIntervalTime(document_time); + element->ComputeNextIntervalTime(document_time, repeat_handling); priority_queue_.Update(next_interval_time, element); // Debugging signal for crbug.com/1021630. CHECK_LT(current_iteration++, kMaxIterations); } } -void SMILTimeContainer::UpdateAnimationTimings(SMILTime presentation_time) { - DCHECK(GetDocument().IsActive()); - - AnimationTargetsMutationsForbidden scope(this); - - if (document_order_indexes_dirty_) - UpdateDocumentOrderIndexes(); +void SMILTimeContainer::UpdateTimedElements(TimingUpdate& update) { + // Flush any "late" interval updates. + UpdateIntervals(update); - if (priority_queue_.IsEmpty()) - return; + while (update.TryAdvanceTime(priority_queue_.Min())) + UpdateIntervals(update); - // Flush any "late" interval updates. - UpdateIntervals(latest_update_time_); - - while (latest_update_time_ < presentation_time) { - const SMILTime interval_time = priority_queue_.Min(); - if (interval_time <= presentation_time) { - latest_update_time_ = interval_time; - UpdateIntervals(latest_update_time_); - } else { - latest_update_time_ = presentation_time; - } + // Update the next interval time for all affected elements to compensate for + // any ignored repeats. + const SMILTime presentation_time = update.TargetTime(); + for (const auto& element : update.UpdatedElements().Keys()) { + SMILTime next_interval_time = element->ComputeNextIntervalTime( + presentation_time, SVGSMILElement::kIncludeRepeats); + priority_queue_.Update(next_interval_time, element); } } void SMILTimeContainer::ApplyTimedEffects(SMILTime elapsed) { + if (document_order_indexes_dirty_) + UpdateDocumentOrderIndexes(); + bool did_apply_effects = false; - { - AnimationTargetsMutationsForbidden scope(this); - for (auto& entry : animated_targets_) { - ElementSMILAnimations* animations = entry.key->GetSMILAnimations(); - if (animations && animations->Apply(elapsed)) - did_apply_effects = true; - } + for (auto& entry : animated_targets_) { + ElementSMILAnimations* animations = entry.key->GetSMILAnimations(); + if (animations && animations->Apply(elapsed)) + did_apply_effects = true; } - if (PerformDiscards()) - did_apply_effects = true; - if (did_apply_effects) { UseCounter::Count(&GetDocument(), WebFeature::kSVGSMILAnimationAppliedEffect); } } -void SMILTimeContainer::QueueDiscard(SVGSMILElement* discard_element) { - DCHECK(discard_element->IsSVGDiscardElement()); - pending_discards_.insert(discard_element); -} - -bool SMILTimeContainer::PerformDiscards() { - if (pending_discards_.IsEmpty()) - return false; - - HeapVector<Member<SVGSMILElement>> discards; - CopyToVector(pending_discards_, discards); - pending_discards_.clear(); - - // Sort by location in the document. (Should be based on the target rather - // than the timed element, but often enough they will order the same.) - std::sort( - discards.begin(), discards.end(), - [](const Member<SVGSMILElement>& a, const Member<SVGSMILElement>& b) { - return a->DocumentOrderIndex() < b->DocumentOrderIndex(); - }); - - for (SVGSMILElement* discard_element : discards) { - if (!discard_element->isConnected()) - continue; - SVGElement* target_element = discard_element->targetElement(); - if (target_element && target_element->isConnected()) { - UseCounter::Count(&GetDocument(), - WebFeature::kSVGSMILDiscardElementTriggered); - target_element->remove(IGNORE_EXCEPTION_FOR_TESTING); - DCHECK(!target_element->isConnected()); - } - if (discard_element->isConnected()) { - discard_element->remove(IGNORE_EXCEPTION_FOR_TESTING); - DCHECK(!discard_element->isConnected()); - } - } - return true; -} - void SMILTimeContainer::AdvanceFrameForTesting() { const SMILTime kFrameDuration = SMILTime::FromSecondsD(0.025); SetElapsed(Elapsed() + kFrameDuration); } -void SMILTimeContainer::Trace(blink::Visitor* visitor) { +void SMILTimeContainer::Trace(Visitor* visitor) { visitor->Trace(animated_targets_); - visitor->Trace(pending_discards_); visitor->Trace(priority_queue_); visitor->Trace(owner_svg_element_); } diff --git a/chromium/third_party/blink/renderer/core/svg/animation/smil_time_container.h b/chromium/third_party/blink/renderer/core/svg/animation/smil_time_container.h index aaa513c066d..a7201b8dea7 100644 --- a/chromium/third_party/blink/renderer/core/svg/animation/smil_time_container.h +++ b/chromium/third_party/blink/renderer/core/svg/animation/smil_time_container.h @@ -27,6 +27,7 @@ #define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_ANIMATION_SMIL_TIME_CONTAINER_H_ #include "base/time/time.h" +#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/svg/animation/priority_queue.h" #include "third_party/blink/renderer/core/svg/animation/smil_time.h" #include "third_party/blink/renderer/platform/graphics/image_animation_policy.h" @@ -41,7 +42,8 @@ class SVGElement; class SVGSMILElement; class SVGSVGElement; -class SMILTimeContainer final : public GarbageCollected<SMILTimeContainer> { +class CORE_EXPORT SMILTimeContainer final + : public GarbageCollected<SMILTimeContainer> { public: explicit SMILTimeContainer(SVGSVGElement& owner); ~SMILTimeContainer(); @@ -70,12 +72,11 @@ class SMILTimeContainer final : public GarbageCollected<SMILTimeContainer> { void ResetDocumentTime(); void SetDocumentOrderIndexesDirty() { document_order_indexes_dirty_ = true; } - void QueueDiscard(SVGSMILElement* discard_element); - // Advance the animation timeline a single frame. void AdvanceFrameForTesting(); + bool EventsDisabled() const { return !should_dispatch_events_; } - void Trace(blink::Visitor*); + void Trace(Visitor*); private: enum FrameSchedulingState { @@ -89,36 +90,26 @@ class SMILTimeContainer final : public GarbageCollected<SMILTimeContainer> { kAnimationFrame }; - enum AnimationPolicyOnceAction { - // Restart OnceTimer if the timeline is not paused. - kRestartOnceTimerIfNotPaused, - // Restart OnceTimer. - kRestartOnceTimer, - // Cancel OnceTimer. - kCancelOnceTimer - }; - bool IsTimelineRunning() const; void SynchronizeToDocumentTimeline(); void ScheduleAnimationFrame(base::TimeDelta delay_time); void CancelAnimationFrame(); void WakeupTimerFired(TimerBase*); - void ScheduleAnimationPolicyTimer(); - void CancelAnimationPolicyTimer(); - void AnimationPolicyTimerFired(TimerBase*); ImageAnimationPolicy AnimationPolicy() const; - bool HandleAnimationPolicy(AnimationPolicyOnceAction); - bool CanScheduleFrame(SMILTime earliest_fire_time) const; - void UpdateAnimationsAndScheduleFrameIfNeeded(SMILTime elapsed); + bool AnimationsDisabled() const; + class TimingUpdate; + void UpdateAnimationsAndScheduleFrameIfNeeded(TimingUpdate&); + void PrepareSeek(TimingUpdate&); void ResetIntervals(); - void UpdateIntervals(SMILTime presentation_time); - void UpdateAnimationTimings(SMILTime elapsed); + void UpdateIntervals(TimingUpdate&); + void UpdateTimedElements(TimingUpdate&); void ApplyTimedEffects(SMILTime elapsed); - bool PerformDiscards(); SMILTime NextProgressTime(SMILTime presentation_time) const; void ServiceOnNextFrame(); void ScheduleWakeUp(base::TimeDelta delay_time, FrameSchedulingState); bool HasPendingSynchronization() const; + void SetPresentationTime(SMILTime new_presentation_time); + SMILTime ClampPresentationTime(SMILTime presentation_time) const; void UpdateDocumentOrderIndexes(); @@ -128,6 +119,9 @@ class SMILTimeContainer final : public GarbageCollected<SMILTimeContainer> { // The latest "restart" time for the time container's timeline. If the // timeline has not been manipulated (seeked, paused) this will be zero. SMILTime presentation_time_; + // The maximum possible presentation time. When this time is reached + // animations will stop. + SMILTime max_presentation_time_; // The state all SVGSMILElements should be at. SMILTime latest_update_time_; // The time on the document timeline corresponding to |presentation_time_|. @@ -137,15 +131,14 @@ class SMILTimeContainer final : public GarbageCollected<SMILTimeContainer> { bool started_ : 1; // The timeline has been started. bool paused_ : 1; // The timeline is paused. + const bool should_dispatch_events_ : 1; bool document_order_indexes_dirty_ : 1; bool is_updating_intervals_; TaskRunnerTimer<SMILTimeContainer> wakeup_timer_; - TaskRunnerTimer<SMILTimeContainer> animation_policy_once_timer_; using AnimatedTargets = HeapHashCountedSet<WeakMember<SVGElement>>; AnimatedTargets animated_targets_; - HeapHashSet<Member<SVGSMILElement>> pending_discards_; PriorityQueue<SMILTime, SVGSMILElement> priority_queue_; diff --git a/chromium/third_party/blink/renderer/core/svg/animation/smil_time_container_test.cc b/chromium/third_party/blink/renderer/core/svg/animation/smil_time_container_test.cc new file mode 100644 index 00000000000..7af0c153fe3 --- /dev/null +++ b/chromium/third_party/blink/renderer/core/svg/animation/smil_time_container_test.cc @@ -0,0 +1,533 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "third_party/blink/renderer/core/svg/animation/smil_time_container.h" + +#include "third_party/blink/renderer/core/animation/document_timeline.h" +#include "third_party/blink/renderer/core/dom/document.h" +#include "third_party/blink/renderer/core/dom/element_traversal.h" +#include "third_party/blink/renderer/core/dom/events/native_event_listener.h" +#include "third_party/blink/renderer/core/frame/local_dom_window.h" +#include "third_party/blink/renderer/core/frame/settings.h" +#include "third_party/blink/renderer/core/svg/svg_document_extensions.h" +#include "third_party/blink/renderer/core/svg/svg_length.h" +#include "third_party/blink/renderer/core/svg/svg_length_context.h" +#include "third_party/blink/renderer/core/svg/svg_rect_element.h" +#include "third_party/blink/renderer/core/svg/svg_svg_element.h" +#include "third_party/blink/renderer/core/testing/page_test_base.h" +#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h" +#include "third_party/blink/renderer/platform/wtf/functional.h" + +namespace blink { +namespace { + +class ContentLoadedEventListener final : public NativeEventListener { + public: + using CallbackType = base::OnceCallback<void(Document&)>; + explicit ContentLoadedEventListener(CallbackType callback) + : callback_(std::move(callback)) {} + + void Invoke(ExecutionContext* execution_context, Event*) override { + std::move(callback_).Run(*Document::From(execution_context)); + } + + private: + CallbackType callback_; +}; + +class SMILTimeContainerAnimationPolicyOnceTest : public PageTestBase { + public: + void SetUp() override { + EnablePlatform(); + platform()->SetAutoAdvanceNowToPendingTasks(false); + PageTestBase::SetupPageWithClients(nullptr, nullptr, &OverrideSettings); + } + + void Load(base::span<const char> data) { + auto params = WebNavigationParams::CreateWithHTMLString( + data, KURL("http://example.com")); + GetFrame().Loader().CommitNavigation(std::move(params), + nullptr /* extra_data */); + GetAnimationClock().ResetTimeForTesting(); + GetAnimationClock().SetAllowedToDynamicallyUpdateTime(false); + GetDocument().Timeline().ResetForTesting(); + } + + void StepTime(base::TimeDelta delta) { + platform()->RunForPeriod(delta); + current_time_ += delta; + GetAnimationClock().UpdateTime(current_time_); + SVGDocumentExtensions::ServiceOnAnimationFrame(GetDocument()); + } + + void OnContentLoaded(base::OnceCallback<void(Document&)> callback) { + GetFrame().DomWindow()->addEventListener( + event_type_names::kDOMContentLoaded, + MakeGarbageCollected<ContentLoadedEventListener>(std::move(callback))); + } + + private: + static void OverrideSettings(Settings& settings) { + settings.SetImageAnimationPolicy(kImageAnimationPolicyAnimateOnce); + } + + base::TimeTicks current_time_; +}; + +TEST_F(SMILTimeContainerAnimationPolicyOnceTest, NoAction) { + Load(R"HTML( + <svg id="container"> + <rect width="100" height="0" fill="green"> + <animate begin="0s" dur="3s" repeatCount="indefinite" + attributeName="height" values="30;50;100" calcMode="discrete"/> + </rect> + </svg> + )HTML"); + platform()->RunUntilIdle(); + + auto* svg_root = To<SVGSVGElement>(GetElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_TRUE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(2500)); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(500)); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + EXPECT_EQ(SMILTime::FromSecondsD(3), time_container->Elapsed()); +} + +TEST_F(SMILTimeContainerAnimationPolicyOnceTest, SetElapsedAfterStart) { + Load(R"HTML( + <svg id="container"> + <rect width="100" height="0" fill="green"> + <animate begin="0s" dur="3s" repeatCount="indefinite" + attributeName="height" values="30;50;100" calcMode="discrete"/> + </rect> + </svg> + )HTML"); + platform()->RunUntilIdle(); + + auto* svg_root = To<SVGSVGElement>(GetElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_TRUE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + time_container->SetElapsed(SMILTime::FromSecondsD(5.5)); + EXPECT_EQ(SMILTime::FromSecondsD(5.5), time_container->Elapsed()); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(2000)); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + EXPECT_EQ(SMILTime::FromSecondsD(8.5), time_container->Elapsed()); +} + +TEST_F(SMILTimeContainerAnimationPolicyOnceTest, SetElapsedBeforeStart) { + Load(R"HTML( + <svg id="container"> + <rect width="100" height="0" fill="green"> + <animate begin="0s" dur="3s" repeatCount="indefinite" + attributeName="height" values="30;50;100" calcMode="discrete"/> + </rect> + </svg> + )HTML"); + OnContentLoaded(WTF::Bind([](Document& document) { + auto* svg_root = To<SVGSVGElement>(document.getElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_FALSE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + time_container->SetElapsed(SMILTime::FromSecondsD(5.5)); + EXPECT_EQ(0, rect->height()->CurrentValue()->Value(length_context)); + })); + platform()->RunUntilIdle(); + + auto* svg_root = To<SVGSVGElement>(GetElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_TRUE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(5.5), time_container->Elapsed()); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(2000)); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + EXPECT_EQ(SMILTime::FromSecondsD(8.5), time_container->Elapsed()); +} + +TEST_F(SMILTimeContainerAnimationPolicyOnceTest, PauseAfterStart) { + Load(R"HTML( + <svg id="container"> + <rect width="100" height="0" fill="green"> + <animate begin="0s" dur="3s" repeatCount="indefinite" + attributeName="height" values="30;50;100" calcMode="discrete"/> + </rect> + </svg> + )HTML"); + platform()->RunUntilIdle(); + + auto* svg_root = To<SVGSVGElement>(GetElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_TRUE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1500)); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + + time_container->Pause(); + EXPECT_TRUE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(1.5), time_container->Elapsed()); + + time_container->Unpause(); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(1.5), time_container->Elapsed()); + + StepTime(base::TimeDelta::FromMilliseconds(4000)); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + EXPECT_EQ(SMILTime::FromSecondsD(4.5), time_container->Elapsed()); +} + +TEST_F(SMILTimeContainerAnimationPolicyOnceTest, PauseBeforeStart) { + Load(R"HTML( + <svg id="container"> + <rect width="100" height="0" fill="green"> + <animate begin="0s" dur="3s" repeatCount="indefinite" + attributeName="height" values="30;50;100" calcMode="discrete"/> + </rect> + </svg> + )HTML"); + OnContentLoaded(WTF::Bind([](Document& document) { + auto* svg_root = To<SVGSVGElement>(document.getElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_FALSE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + time_container->Pause(); + EXPECT_TRUE(time_container->IsPaused()); + EXPECT_EQ(0, rect->height()->CurrentValue()->Value(length_context)); + })); + platform()->RunUntilIdle(); + + auto* svg_root = To<SVGSVGElement>(GetElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_TRUE(time_container->IsStarted()); + EXPECT_TRUE(time_container->IsPaused()); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1500)); + EXPECT_EQ(SMILTime::FromSecondsD(0), time_container->Elapsed()); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + time_container->Unpause(); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(0), time_container->Elapsed()); + + StepTime(base::TimeDelta::FromMilliseconds(1500)); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(2500)); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + EXPECT_EQ(SMILTime::FromSecondsD(3), time_container->Elapsed()); +} + +TEST_F(SMILTimeContainerAnimationPolicyOnceTest, PauseAndSetElapsedAfterStart) { + Load(R"HTML( + <svg id="container"> + <rect width="100" height="0" fill="green"> + <animate begin="0s" dur="3s" repeatCount="indefinite" + attributeName="height" values="30;50;100" calcMode="discrete"/> + </rect> + </svg> + )HTML"); + platform()->RunUntilIdle(); + + auto* svg_root = To<SVGSVGElement>(GetElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_TRUE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1500)); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + + time_container->Pause(); + EXPECT_TRUE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(1.5), time_container->Elapsed()); + + time_container->SetElapsed(SMILTime::FromSecondsD(0.5)); + EXPECT_EQ(SMILTime::FromSecondsD(0.5), time_container->Elapsed()); + + time_container->Unpause(); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(0.5), time_container->Elapsed()); + + StepTime(base::TimeDelta::FromMilliseconds(4000)); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + EXPECT_EQ(SMILTime::FromSecondsD(3.5), time_container->Elapsed()); +} + +TEST_F(SMILTimeContainerAnimationPolicyOnceTest, + PauseAndSetElapsedBeforeStart) { + Load(R"HTML( + <svg id="container"> + <rect width="100" height="0" fill="green"> + <animate begin="0s" dur="3s" repeatCount="indefinite" + attributeName="height" values="30;50;100" calcMode="discrete"/> + </rect> + </svg> + )HTML"); + OnContentLoaded(WTF::Bind([](Document& document) { + auto* svg_root = To<SVGSVGElement>(document.getElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_FALSE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + time_container->Pause(); + EXPECT_TRUE(time_container->IsPaused()); + time_container->SetElapsed(SMILTime::FromSecondsD(1.5)); + EXPECT_TRUE(time_container->IsPaused()); + EXPECT_EQ(0, rect->height()->CurrentValue()->Value(length_context)); + })); + platform()->RunUntilIdle(); + + auto* svg_root = To<SVGSVGElement>(GetElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_TRUE(time_container->IsStarted()); + EXPECT_TRUE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(1.5), time_container->Elapsed()); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1500)); + EXPECT_EQ(SMILTime::FromSecondsD(1.5), time_container->Elapsed()); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + + time_container->Unpause(); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(1.5), time_container->Elapsed()); + + StepTime(base::TimeDelta::FromMilliseconds(2000)); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(2000)); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + EXPECT_EQ(SMILTime::FromSecondsD(4.5), time_container->Elapsed()); +} + +TEST_F(SMILTimeContainerAnimationPolicyOnceTest, PauseAndResumeBeforeStart) { + Load(R"HTML( + <svg id="container"> + <rect width="100" height="0" fill="green"> + <animate begin="0s" dur="3s" repeatCount="indefinite" + attributeName="height" values="30;50;100" calcMode="discrete"/> + </rect> + </svg> + )HTML"); + OnContentLoaded(WTF::Bind([](Document& document) { + auto* svg_root = To<SVGSVGElement>(document.getElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_FALSE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + time_container->Pause(); + EXPECT_TRUE(time_container->IsPaused()); + time_container->Unpause(); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(0, rect->height()->CurrentValue()->Value(length_context)); + })); + platform()->RunUntilIdle(); + + auto* svg_root = To<SVGSVGElement>(GetElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_TRUE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(2500)); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(500)); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + EXPECT_EQ(SMILTime::FromSecondsD(3), time_container->Elapsed()); +} + +TEST_F(SMILTimeContainerAnimationPolicyOnceTest, PauseAndResumeAfterSuspended) { + Load(R"HTML( + <svg id="container"> + <rect width="100" height="0" fill="green"> + <animate begin="0s" dur="3s" repeatCount="indefinite" + attributeName="height" values="30;50;100" calcMode="discrete"/> + </rect> + </svg> + )HTML"); + platform()->RunUntilIdle(); + + auto* svg_root = To<SVGSVGElement>(GetElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_TRUE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(0), time_container->Elapsed()); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(SMILTime::FromSecondsD(1.0), time_container->Elapsed()); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(SMILTime::FromSecondsD(2.0), time_container->Elapsed()); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1500)); + EXPECT_EQ(SMILTime::FromSecondsD(3.0), time_container->Elapsed()); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + time_container->Pause(); + EXPECT_TRUE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(3.0), time_container->Elapsed()); + + time_container->Unpause(); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(3.0), time_container->Elapsed()); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(SMILTime::FromSecondsD(4.0), time_container->Elapsed()); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(SMILTime::FromSecondsD(5.0), time_container->Elapsed()); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1500)); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + EXPECT_EQ(SMILTime::FromSecondsD(6.0), time_container->Elapsed()); +} + +TEST_F(SMILTimeContainerAnimationPolicyOnceTest, SetElapsedAfterSuspended) { + Load(R"HTML( + <svg id="container"> + <rect width="100" height="0" fill="green"> + <animate begin="0s" dur="3s" repeatCount="indefinite" + attributeName="height" values="30;50;100" calcMode="discrete"/> + </rect> + </svg> + )HTML"); + platform()->RunUntilIdle(); + + auto* svg_root = To<SVGSVGElement>(GetElementById("container")); + ASSERT_TRUE(svg_root); + auto* rect = Traversal<SVGRectElement>::FirstChild(*svg_root); + ASSERT_TRUE(rect); + SVGLengthContext length_context(rect); + + SMILTimeContainer* time_container = svg_root->TimeContainer(); + EXPECT_TRUE(time_container->IsStarted()); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(0), time_container->Elapsed()); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(SMILTime::FromSecondsD(1.0), time_container->Elapsed()); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(SMILTime::FromSecondsD(2.0), time_container->Elapsed()); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1500)); + EXPECT_EQ(SMILTime::FromSecondsD(3.0), time_container->Elapsed()); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + time_container->SetElapsed(SMILTime::FromSecondsD(5.5)); + EXPECT_FALSE(time_container->IsPaused()); + EXPECT_EQ(SMILTime::FromSecondsD(5.5), time_container->Elapsed()); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(SMILTime::FromSecondsD(6.5), time_container->Elapsed()); + EXPECT_EQ(30, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1000)); + EXPECT_EQ(SMILTime::FromSecondsD(7.5), time_container->Elapsed()); + EXPECT_EQ(50, rect->height()->CurrentValue()->Value(length_context)); + + StepTime(base::TimeDelta::FromMilliseconds(1500)); + EXPECT_EQ(100, rect->height()->CurrentValue()->Value(length_context)); + EXPECT_EQ(SMILTime::FromSecondsD(8.5), time_container->Elapsed()); +} + +} // namespace +} // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/animation/svg_smil_element.cc b/chromium/third_party/blink/renderer/core/svg/animation/svg_smil_element.cc index 697d4c9b703..016afbac7c9 100644 --- a/chromium/third_party/blink/renderer/core/svg/animation/svg_smil_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/animation/svg_smil_element.cc @@ -65,6 +65,57 @@ SMILTime ComputeNextRepeatTime(SMILTime interval_begin, } // namespace +void SMILInstanceTimeList::Append(SMILTime time, SMILTimeOrigin origin) { + instance_times_.push_back(SMILTimeWithOrigin(time, origin)); + AddOrigin(origin); +} + +void SMILInstanceTimeList::InsertSortedAndUnique(SMILTime time, + SMILTimeOrigin origin) { + SMILTimeWithOrigin time_with_origin(time, origin); + auto* position = std::lower_bound(instance_times_.begin(), + instance_times_.end(), time_with_origin); + // Don't add it if we already have one of those. + for (auto* it = position; it != instance_times_.end(); ++it) { + if (position->Time() != time) + break; + // If they share both time and origin, we don't need to add it, + // we just need to react. + if (position->Origin() == origin) + return; + } + instance_times_.insert(position - instance_times_.begin(), time_with_origin); + AddOrigin(origin); +} + +void SMILInstanceTimeList::RemoveWithOrigin(SMILTimeOrigin origin) { + if (!HasOrigin(origin)) + return; + auto* tail = + std::remove_if(instance_times_.begin(), instance_times_.end(), + [origin](const SMILTimeWithOrigin& instance_time) { + return instance_time.Origin() == origin; + }); + instance_times_.Shrink(tail - instance_times_.begin()); + ClearOrigin(origin); +} + +void SMILInstanceTimeList::Sort() { + std::sort(instance_times_.begin(), instance_times_.end()); +} + +SMILTime SMILInstanceTimeList::NextAfter(SMILTime time) const { + // Find the value in |list| that is strictly greater than |time|. + auto* next_item = std::lower_bound( + instance_times_.begin(), instance_times_.end(), time, + [](const SMILTimeWithOrigin& instance_time, const SMILTime& time) { + return instance_time.Time() <= time; + }); + if (next_item == instance_times_.end()) + return SMILTime::Unresolved(); + return next_item->Time(); +} + // This is used for duration type time values that can't be negative. static constexpr SMILTime kInvalidCachedTime = SMILTime::Earliest(); @@ -84,7 +135,7 @@ class ConditionEventListener final : public NativeEventListener { animation_->Elapsed() + condition_->Offset(), SMILTimeOrigin::kEvent); } - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { visitor->Trace(animation_); visitor->Trace(condition_); NativeEventListener::Trace(visitor); @@ -110,7 +161,7 @@ SVGSMILElement::Condition::Condition(Type type, SVGSMILElement::Condition::~Condition() = default; -void SVGSMILElement::Condition::Trace(blink::Visitor* visitor) { +void SVGSMILElement::Condition::Trace(Visitor* visitor) { visitor->Trace(base_element_); visitor->Trace(base_id_observer_); visitor->Trace(event_listener_); @@ -241,15 +292,6 @@ void SVGSMILElement::BuildPendingResource() { ConnectConditions(); } -static inline void RemoveInstanceTimesWithOrigin( - Vector<SMILTimeWithOrigin>& time_list, - SMILTimeOrigin origin) { - for (int i = time_list.size() - 1; i >= 0; --i) { - if (time_list[i].Origin() == origin) - time_list.EraseAt(i); - } -} - void SVGSMILElement::Reset() { active_state_ = kInactive; is_waiting_for_first_interval_ = true; @@ -281,10 +323,8 @@ Node::InsertionNotificationRequest SVGSMILElement::InsertedInto( // "If no attribute is present, the default begin value (an offset-value of 0) // must be evaluated." - if (!FastHasAttribute(svg_names::kBeginAttr) && begin_times_.IsEmpty()) { - begin_times_.push_back( - SMILTimeWithOrigin(SMILTime(), SMILTimeOrigin::kAttribute)); - } + if (!FastHasAttribute(svg_names::kBeginAttr) && begin_times_.IsEmpty()) + begin_times_.Append(SMILTime(), SMILTimeOrigin::kAttribute); BuildPendingResource(); return kInsertionDone; @@ -431,34 +471,30 @@ bool SVGSMILElement::ParseCondition(const String& value, void SVGSMILElement::ParseBeginOrEnd(const String& parse_string, BeginOrEnd begin_or_end) { - Vector<SMILTimeWithOrigin>& time_list = - begin_or_end == kBegin ? begin_times_ : end_times_; + auto& time_list = begin_or_end == kBegin ? begin_times_ : end_times_; if (begin_or_end == kEnd) has_end_event_conditions_ = false; // Remove any previously added offset-values. // TODO(fs): Ought to remove instance times originating from sync-bases, // events etc. as well if those conditions are no longer in the attribute. - RemoveInstanceTimesWithOrigin(time_list, SMILTimeOrigin::kAttribute); + time_list.RemoveWithOrigin(SMILTimeOrigin::kAttribute); Vector<String> split_string; parse_string.Split(';', split_string); for (const auto& item : split_string) { SMILTime value = ParseClockValue(item); - if (value.IsUnresolved()) { + if (value.IsUnresolved()) ParseCondition(item, begin_or_end); - } else { - time_list.push_back( - SMILTimeWithOrigin(value, SMILTimeOrigin::kAttribute)); - } + else + time_list.Append(value, SMILTimeOrigin::kAttribute); } // "If no attribute is present, the default begin value (an offset-value of 0) // must be evaluated." - if (begin_or_end == kBegin && parse_string.IsNull()) { - begin_times_.push_back( - SMILTimeWithOrigin(SMILTime(), SMILTimeOrigin::kAttribute)); - } - std::sort(time_list.begin(), time_list.end()); + if (begin_or_end == kBegin && parse_string.IsNull()) + begin_times_.Append(SMILTime(), SMILTimeOrigin::kAttribute); + + time_list.Sort(); } void SVGSMILElement::ParseAttribute(const AttributeModificationParams& params) { @@ -530,6 +566,14 @@ void SVGSMILElement::SvgAttributeChanged(const QualifiedName& attr_name) { SVGElement::SvgAttributeChanged(attr_name); } +bool SVGSMILElement::IsPresentationAttribute( + const QualifiedName& attr_name) const { + // Don't map 'fill' to the 'fill' property for animation elements. + if (attr_name == svg_names::kFillAttr) + return false; + return SVGElement::IsPresentationAttribute(attr_name); +} + void SVGSMILElement::ConnectConditions() { if (conditions_connected_) DisconnectConditions(); @@ -655,27 +699,11 @@ SMILTime SVGSMILElement::SimpleDuration() const { return std::min(Dur(), SMILTime::Indefinite()); } -static void InsertSortedAndUnique(Vector<SMILTimeWithOrigin>& list, - SMILTimeWithOrigin time) { - auto* position = std::lower_bound(list.begin(), list.end(), time); - // Don't add it if we already have one of those. - for (auto* it = position; it < list.end(); ++it) { - if (position->Time() != time.Time()) - break; - // If they share both time and origin, we don't need to add it, - // we just need to react. - if (position->Origin() == time.Origin()) - return; - } - list.insert(position - list.begin(), time); -} - void SVGSMILElement::AddInstanceTime(BeginOrEnd begin_or_end, SMILTime time, SMILTimeOrigin origin) { - Vector<SMILTimeWithOrigin>& list = - begin_or_end == kBegin ? begin_times_ : end_times_; - InsertSortedAndUnique(list, SMILTimeWithOrigin(time, origin)); + auto& list = begin_or_end == kBegin ? begin_times_ : end_times_; + list.InsertSortedAndUnique(time, origin); instance_lists_have_changed_ = true; } @@ -691,30 +719,6 @@ void SVGSMILElement::AddInstanceTimeAndUpdate(BeginOrEnd begin_or_end, InstanceListChanged(); } -SMILTime SVGSMILElement::NextAfter(BeginOrEnd begin_or_end, - SMILTime time) const { - const Vector<SMILTimeWithOrigin>& list = - begin_or_end == kBegin ? begin_times_ : end_times_; - if (list.IsEmpty()) { - return begin_or_end == kBegin ? SMILTime::Unresolved() - : SMILTime::Indefinite(); - } - // Find the value in |list| that is strictly greater than |time|. - auto* next_item = std::lower_bound( - list.begin(), list.end(), time, - [](const SMILTimeWithOrigin& instance_time, const SMILTime& time) { - return instance_time.Time() <= time; - }); - if (next_item == list.end()) - return SMILTime::Unresolved(); - SMILTime next = next_item->Time(); - // The special value "indefinite" does not yield an instance time in the - // begin list. - if (begin_or_end == kBegin && next.IsIndefinite()) - return SMILTime::Unresolved(); - return next; -} - SMILTime SVGSMILElement::RepeatingDuration() const { // Computing the active duration // http://www.w3.org/TR/SMIL2/smil-timing.html#Timing-ComputingActiveDur @@ -732,11 +736,16 @@ SMILTime SVGSMILElement::RepeatingDuration() const { } SMILTime SVGSMILElement::ResolveActiveEnd(SMILTime resolved_begin) const { - SMILTime resolved_end = NextAfter(kEnd, resolved_begin); - if (resolved_end.IsUnresolved()) { - // If we have no pending end conditions, don't generate a new interval. - if (!end_times_.IsEmpty() && !has_end_event_conditions_) - return SMILTime::Unresolved(); + SMILTime resolved_end = SMILTime::Indefinite(); + if (!end_times_.IsEmpty()) { + SMILTime next_end = end_times_.NextAfter(resolved_begin); + if (next_end.IsUnresolved()) { + // If we have no pending end conditions, don't generate a new interval. + if (!has_end_event_conditions_) + return SMILTime::Unresolved(); + } else { + resolved_end = next_end; + } } // Computing the active duration // http://www.w3.org/TR/SMIL2/smil-timing.html#Timing-ComputingActiveDur @@ -809,12 +818,14 @@ void SVGSMILElement::SetNewIntervalEnd(SMILTime new_end) { } SMILTime SVGSMILElement::ComputeNextIntervalTime( - SMILTime presentation_time) const { + SMILTime presentation_time, + IncludeRepeats include_repeats) const { SMILTime next_interval_time = SMILTime::Unresolved(); if (interval_.BeginsAfter(presentation_time)) { next_interval_time = interval_.begin; } else if (interval_.EndsAfter(presentation_time)) { - if (SMILTime simple_duration = SimpleDuration()) { + SMILTime simple_duration = SimpleDuration(); + if (include_repeats == kIncludeRepeats && simple_duration) { SMILTime next_repeat_time = ComputeNextRepeatTime( interval_.begin, simple_duration, presentation_time); DCHECK(next_repeat_time.IsFinite()); @@ -823,7 +834,12 @@ SMILTime SVGSMILElement::ComputeNextIntervalTime( next_interval_time = interval_.end; } } - return std::min(next_interval_time, NextAfter(kBegin, presentation_time)); + SMILTime next_begin = begin_times_.NextAfter(presentation_time); + // The special value "indefinite" does not yield an instance time in the + // begin list, so only consider finite values here. + if (next_begin.IsFinite()) + next_interval_time = std::min(next_interval_time, next_begin); + return next_interval_time; } void SVGSMILElement::InstanceListChanged() { @@ -852,10 +868,12 @@ void SVGSMILElement::InstanceListChanged() { // If we switched interval and the previous interval did not end yet, we // need to consider it when computing the next interval time. if (previous_interval_.IsResolved() && - previous_interval_.EndsAfter(previous_presentation_time)) + previous_interval_.EndsAfter(previous_presentation_time)) { next_interval_time = previous_interval_.end; - else - next_interval_time = ComputeNextIntervalTime(previous_presentation_time); + } else { + next_interval_time = + ComputeNextIntervalTime(previous_presentation_time, kIncludeRepeats); + } time_container_->Reschedule(this, next_interval_time); } } @@ -895,7 +913,7 @@ bool SVGSMILElement::HandleIntervalRestart(SMILTime presentation_time) { if (!interval_.IsResolved() || interval_.EndsBefore(presentation_time)) return true; if (restart == kRestartAlways) { - SMILTime next_begin = NextAfter(kBegin, interval_.begin); + SMILTime next_begin = begin_times_.NextAfter(interval_.begin); if (interval_.EndsAfter(next_begin)) { SetNewIntervalEnd(next_begin); return interval_.EndsBefore(presentation_time); @@ -904,6 +922,23 @@ bool SVGSMILElement::HandleIntervalRestart(SMILTime presentation_time) { return false; } +SMILTime SVGSMILElement::LastIntervalEndTime() const { + // If we're still waiting for the first interval we lack a time reference. + if (!is_waiting_for_first_interval_) { + // If we have a current interval (which likely just ended or restarted) use + // the end of that. + if (interval_.IsResolved()) + return interval_.end; + // If we don't have a current interval (maybe because it got discarded for + // not having started yet) but we have a previous interval, then use the + // end of that. + if (previous_interval_.IsResolved()) + return previous_interval_.end; + } + // We have to start from the beginning. + return SMILTime::Earliest(); +} + void SVGSMILElement::UpdateInterval(SMILTime presentation_time) { if (instance_lists_have_changed_) { instance_lists_have_changed_ = false; @@ -911,10 +946,7 @@ void SVGSMILElement::UpdateInterval(SMILTime presentation_time) { } if (!HandleIntervalRestart(presentation_time)) return; - SMILTime begin_after = - !is_waiting_for_first_interval_ && interval_.IsResolved() - ? interval_.end - : SMILTime::Earliest(); + SMILTime begin_after = LastIntervalEndTime(); SMILInterval next_interval = ResolveInterval(begin_after, presentation_time); // It's the same interval that we resolved before. Do nothing. if (next_interval == interval_) @@ -943,7 +975,8 @@ void SVGSMILElement::AddedToTimeContainer() { current_presentation_time - SMILTime::Epsilon(); active_state_ = DetermineActiveState(interval_, previous_presentation_time); time_container_->Reschedule( - this, ComputeNextIntervalTime(previous_presentation_time)); + this, + ComputeNextIntervalTime(previous_presentation_time, kIncludeRepeats)); // If there's an active interval, then revalidate the animation value. if (GetActiveState() != kInactive) @@ -1056,32 +1089,85 @@ bool SVGSMILElement::IsContributing(SMILTime elapsed) const { GetActiveState() == kFrozen; } -void SVGSMILElement::UpdateActiveState(SMILTime elapsed) { +SVGSMILElement::EventDispatchMask SVGSMILElement::UpdateActiveState( + SMILTime presentation_time, + bool skip_repeat) { const bool was_active = GetActiveState() == kActive; - active_state_ = DetermineActiveState(interval_, elapsed); + active_state_ = DetermineActiveState(interval_, presentation_time); const bool is_active = GetActiveState() == kActive; const bool interval_restart = interval_has_changed_ && previous_interval_.end == interval_.begin; interval_has_changed_ = false; + unsigned events_to_dispatch = kDispatchNoEvent; if ((was_active && !is_active) || interval_restart) { - ScheduleEvent(event_type_names::kEndEvent); + events_to_dispatch |= kDispatchEndEvent; EndedActiveInterval(); } - if (IsContributing(elapsed)) { - if (!was_active || interval_restart) { - ScheduleEvent(event_type_names::kBeginEvent); + if (IsContributing(presentation_time)) { + if ((!was_active && is_active) || interval_restart) { + events_to_dispatch |= kDispatchBeginEvent; StartedActiveInterval(); } - ProgressState progress_state = CalculateProgressState(elapsed); - if (progress_state.repeat && - progress_state.repeat != last_progress_.repeat) { - NotifyDependentsOnRepeat(progress_state.repeat, elapsed); - ScheduleRepeatEvents(); + if (!skip_repeat) { + // TODO(fs): This is a bit fragile. Convert to be time-based (rather than + // based on |last_progress_|) and thus (at least more) idempotent. + ProgressState progress_state = CalculateProgressState(presentation_time); + if (progress_state.repeat && + progress_state.repeat != last_progress_.repeat) { + NotifyDependentsOnRepeat(progress_state.repeat, presentation_time); + events_to_dispatch |= kDispatchRepeatEvent; + } + last_progress_ = progress_state; } - last_progress_ = progress_state; + } + return static_cast<EventDispatchMask>(events_to_dispatch); +} + +SVGSMILElement::EventDispatchMask SVGSMILElement::ComputeSeekEvents( + const SMILInterval& starting_interval) const { + // Is the element active at the seeked-to time? + if (GetActiveState() != SVGSMILElement::kActive) { + // Was the element active at the previous time? + if (!starting_interval.IsResolved()) + return kDispatchNoEvent; + // Dispatch an 'endEvent' for ending |starting_interval|. + return kDispatchEndEvent; + } + // Was the element active at the previous time? + if (starting_interval.IsResolved()) { + // The same interval? + if (interval_ == starting_interval) + return kDispatchNoEvent; + // Dispatch an 'endEvent' for ending |starting_interval| and a 'beginEvent' + // for beginning the current interval. + unsigned to_dispatch = kDispatchBeginEvent | kDispatchEndEvent; + return static_cast<EventDispatchMask>(to_dispatch); + } + // Was not active at the previous time. Dispatch a 'beginEvent' for beginning + // the current interval. + return kDispatchBeginEvent; +} + +void SVGSMILElement::DispatchEvents(EventDispatchMask events_to_dispatch) { + // The ordering is based on the usual order in which these events should be + // dispatched (and should match the order the flags are set in + // UpdateActiveState(). + if (events_to_dispatch & kDispatchEndEvent) { + EnqueueEvent(*Event::Create(event_type_names::kEndEvent), + TaskType::kDOMManipulation); + } + if (events_to_dispatch & kDispatchBeginEvent) { + EnqueueEvent(*Event::Create(event_type_names::kBeginEvent), + TaskType::kDOMManipulation); + } + if (events_to_dispatch & kDispatchRepeatEvent) { + EnqueueEvent(*Event::Create(event_type_names::kRepeatEvent), + TaskType::kDOMManipulation); + EnqueueEvent(*Event::Create(AtomicString("repeatn")), + TaskType::kDOMManipulation); } } @@ -1198,21 +1284,8 @@ void SVGSMILElement::StartedActiveInterval() { } void SVGSMILElement::EndedActiveInterval() { - RemoveInstanceTimesWithOrigin(begin_times_, SMILTimeOrigin::kScript); - RemoveInstanceTimesWithOrigin(end_times_, SMILTimeOrigin::kScript); -} - -void SVGSMILElement::ScheduleRepeatEvents() { - ScheduleEvent(event_type_names::kRepeatEvent); - ScheduleEvent(AtomicString("repeatn")); -} - -void SVGSMILElement::ScheduleEvent(const AtomicString& event_type) { - DCHECK(event_type == event_type_names::kEndEvent || - event_type == event_type_names::kBeginEvent || - event_type == event_type_names::kRepeatEvent || - event_type == "repeatn"); - EnqueueEvent(*Event::Create(event_type), TaskType::kDOMManipulation); + begin_times_.RemoveWithOrigin(SMILTimeOrigin::kScript); + end_times_.RemoveWithOrigin(SMILTimeOrigin::kScript); } bool SVGSMILElement::HasValidTarget() const { @@ -1238,12 +1311,7 @@ void SVGSMILElement::DidChangeAnimationTarget() { is_scheduled_ = true; } -void SVGSMILElement::QueueDiscard() { - if (time_container_) - time_container_->QueueDiscard(this); -} - -void SVGSMILElement::Trace(blink::Visitor* visitor) { +void SVGSMILElement::Trace(Visitor* visitor) { visitor->Trace(target_element_); visitor->Trace(target_id_observer_); visitor->Trace(time_container_); diff --git a/chromium/third_party/blink/renderer/core/svg/animation/svg_smil_element.h b/chromium/third_party/blink/renderer/core/svg/animation/svg_smil_element.h index 457a1d31020..436c4979bb6 100644 --- a/chromium/third_party/blink/renderer/core/svg/animation/svg_smil_element.h +++ b/chromium/third_party/blink/renderer/core/svg/animation/svg_smil_element.h @@ -33,7 +33,7 @@ #include "third_party/blink/renderer/core/svg/svg_tests.h" #include "third_party/blink/renderer/core/svg_names.h" #include "third_party/blink/renderer/platform/heap/handle.h" -#include "third_party/blink/renderer/platform/wtf/hash_map.h" +#include "third_party/blink/renderer/platform/wtf/hash_set.h" namespace blink { @@ -42,6 +42,39 @@ class SMILTimeContainer; class IdTargetObserver; class SVGSMILElement; +class CORE_EXPORT SMILInstanceTimeList { + public: + void Append(SMILTime, SMILTimeOrigin); + void InsertSortedAndUnique(SMILTime, SMILTimeOrigin); + void RemoveWithOrigin(SMILTimeOrigin); + void Sort(); + SMILTime NextAfter(SMILTime) const; + + wtf_size_t size() const { return instance_times_.size(); } + bool IsEmpty() const { return instance_times_.IsEmpty(); } + + using const_iterator = typename Vector<SMILTimeWithOrigin>::const_iterator; + const_iterator begin() const { return instance_times_.begin(); } + const_iterator end() const { return instance_times_.end(); } + + private: + static unsigned OriginToMask(SMILTimeOrigin origin) { + return 1u << static_cast<unsigned>(origin); + } + void AddOrigin(SMILTimeOrigin origin) { + time_origin_mask_ |= OriginToMask(origin); + } + void ClearOrigin(SMILTimeOrigin origin) { + time_origin_mask_ &= ~OriginToMask(origin); + } + bool HasOrigin(SMILTimeOrigin origin) const { + return (time_origin_mask_ & OriginToMask(origin)) != 0; + } + + Vector<SMILTimeWithOrigin> instance_times_; + unsigned time_origin_mask_ = 0; +}; + // This class implements SMIL interval timing model as needed for SVG animation. class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { USING_GARBAGE_COLLECTED_MIXIN(SVGSMILElement); @@ -82,12 +115,24 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { SMILTime SimpleDuration() const; void UpdateInterval(SMILTime presentation_time); - void UpdateActiveState(SMILTime elapsed); + enum EventDispatchMask { + kDispatchNoEvent = 0, + kDispatchBeginEvent = 1u << 0, + kDispatchRepeatEvent = 1u << 1, + kDispatchEndEvent = 1u << 2, + }; + EventDispatchMask UpdateActiveState(SMILTime presentation_time, + bool skip_repeat); + EventDispatchMask ComputeSeekEvents( + const SMILInterval& starting_interval) const; + void DispatchEvents(EventDispatchMask); void UpdateProgressState(SMILTime presentation_time); bool IsHigherPriorityThan(const SVGSMILElement* other, SMILTime presentation_time) const; - SMILTime ComputeNextIntervalTime(SMILTime presentation_time) const; + enum IncludeRepeats { kIncludeRepeats, kExcludeRepeats }; + SMILTime ComputeNextIntervalTime(SMILTime presentation_time, + IncludeRepeats) const; SMILTime NextProgressTime(SMILTime elapsed) const; void Reset(); @@ -96,18 +141,14 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { static SMILTime ParseOffsetValue(const String&); bool IsContributing(SMILTime elapsed) const; + const SMILInterval& GetActiveInterval(SMILTime presentation_time) const; unsigned DocumentOrderIndex() const { return document_order_index_; } void SetDocumentOrderIndex(unsigned index) { document_order_index_ = index; } wtf_size_t& PriorityQueueHandle() { return queue_handle_; } - void ScheduleEvent(const AtomicString& event_type); - void ScheduleRepeatEvents(); - - virtual bool IsSVGDiscardElement() const { return false; } - - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: enum BeginOrEnd { kBegin, kEnd }; @@ -120,9 +161,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { virtual void WillChangeAnimationTarget(); virtual void DidChangeAnimationTarget(); - virtual void StartedActiveInterval(); - void QueueDiscard(); - struct ProgressState { float progress; unsigned repeat; @@ -130,10 +168,13 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { const ProgressState& GetProgressState() const { return last_progress_; } private: + bool IsPresentationAttribute(const QualifiedName&) const override; + void BuildPendingResource() override; void ClearResourceAndEventBaseReferences(); void ClearConditions(); + void StartedActiveInterval(); void EndedActiveInterval(); bool LayoutObjectIsNeeded(const ComputedStyle&) const override { @@ -151,7 +192,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { void DiscardOrRevalidateCurrentInterval(SMILTime presentation_time); SMILTime ResolveActiveEnd(SMILTime resolved_begin) const; SMILTime RepeatingDuration() const; - const SMILInterval& GetActiveInterval(SMILTime elapsed) const; void SetNewInterval(const SMILInterval&); void SetNewIntervalEnd(SMILTime new_end); @@ -175,7 +215,7 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { unsigned repeat); ~Condition(); - void Trace(blink::Visitor*); + void Trace(Visitor*); Type GetType() const { return type_; } BeginOrEnd GetBeginOrEnd() const { return begin_or_end_; } @@ -232,6 +272,8 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { ProgressState CalculateProgressState(SMILTime presentation_time) const; + SMILTime LastIntervalEndTime() const; + Member<SVGElement> target_element_; Member<IdTargetObserver> target_id_observer_; @@ -246,8 +288,8 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { TimeDependentSet sync_base_dependents_; // Instance time lists - Vector<SMILTimeWithOrigin> begin_times_; - Vector<SMILTimeWithOrigin> end_times_; + SMILInstanceTimeList begin_times_; + SMILInstanceTimeList end_times_; // This is the upcoming or current interval SMILInterval interval_; @@ -277,23 +319,24 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { friend class ConditionEventListener; }; -inline bool IsSVGSMILElement(const SVGElement& element) { - return element.HasTagName(svg_names::kSetTag) || - element.HasTagName(svg_names::kAnimateTag) || - element.HasTagName(svg_names::kAnimateMotionTag) || - element.HasTagName(svg_names::kAnimateTransformTag) || - element.HasTagName((svg_names::kDiscardTag)); +template <> +inline bool IsElementOfType<const SVGSMILElement>(const Node& node) { + return IsA<SVGSMILElement>(node); } - template <> struct DowncastTraits<SVGSMILElement> { static bool AllowFrom(const Node& node) { auto* svg_element = DynamicTo<SVGElement>(node); - return svg_element && IsSVGSMILElement(*svg_element); + return svg_element && AllowFrom(*svg_element); + } + static bool AllowFrom(const SVGElement& svg_element) { + return svg_element.HasTagName(svg_names::kSetTag) || + svg_element.HasTagName(svg_names::kAnimateTag) || + svg_element.HasTagName(svg_names::kAnimateMotionTag) || + svg_element.HasTagName(svg_names::kAnimateTransformTag); } }; -DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGSMILElement); } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_ANIMATION_SVG_SMIL_ELEMENT_H_ diff --git a/chromium/third_party/blink/renderer/core/svg/animation/svg_smil_element_test.cc b/chromium/third_party/blink/renderer/core/svg/animation/svg_smil_element_test.cc new file mode 100644 index 00000000000..1681ce8979e --- /dev/null +++ b/chromium/third_party/blink/renderer/core/svg/animation/svg_smil_element_test.cc @@ -0,0 +1,121 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "third_party/blink/renderer/core/svg/animation/svg_smil_element.h" + +#include "testing/gtest/include/gtest/gtest.h" + +namespace blink { + +namespace { + +Vector<std::pair<SMILTime, SMILTimeOrigin>> ExtractListContents( + const SMILInstanceTimeList& list) { + Vector<std::pair<SMILTime, SMILTimeOrigin>> times; + for (const auto& item : list) + times.push_back(std::make_pair(item.Time(), item.Origin())); + return times; +} + +TEST(SMILInstanceTimeListTest, Sort) { + SMILInstanceTimeList list; + list.Append(SMILTime::FromSecondsD(1), SMILTimeOrigin::kAttribute); + list.Append(SMILTime::FromSecondsD(5), SMILTimeOrigin::kAttribute); + list.Append(SMILTime::FromSecondsD(4), SMILTimeOrigin::kAttribute); + list.Append(SMILTime::FromSecondsD(2), SMILTimeOrigin::kAttribute); + list.Append(SMILTime::FromSecondsD(3), SMILTimeOrigin::kAttribute); + ASSERT_EQ(list.size(), 5u); + list.Sort(); + + Vector<std::pair<SMILTime, SMILTimeOrigin>> expected_times( + {{SMILTime::FromSecondsD(1), SMILTimeOrigin::kAttribute}, + {SMILTime::FromSecondsD(2), SMILTimeOrigin::kAttribute}, + {SMILTime::FromSecondsD(3), SMILTimeOrigin::kAttribute}, + {SMILTime::FromSecondsD(4), SMILTimeOrigin::kAttribute}, + {SMILTime::FromSecondsD(5), SMILTimeOrigin::kAttribute}}); + ASSERT_EQ(ExtractListContents(list), expected_times); +} + +TEST(SMILInstanceTimeListTest, InsertSortedAndUnique) { + SMILInstanceTimeList list; + list.Append(SMILTime::FromSecondsD(1), SMILTimeOrigin::kAttribute); + list.Append(SMILTime::FromSecondsD(2), SMILTimeOrigin::kScript); + list.Append(SMILTime::FromSecondsD(3), SMILTimeOrigin::kAttribute); + ASSERT_EQ(list.size(), 3u); + + // Unique time/item. + list.InsertSortedAndUnique(SMILTime::FromSecondsD(4), + SMILTimeOrigin::kScript); + ASSERT_EQ(list.size(), 4u); + Vector<std::pair<SMILTime, SMILTimeOrigin>> expected_times1( + {{SMILTime::FromSecondsD(1), SMILTimeOrigin::kAttribute}, + {SMILTime::FromSecondsD(2), SMILTimeOrigin::kScript}, + {SMILTime::FromSecondsD(3), SMILTimeOrigin::kAttribute}, + {SMILTime::FromSecondsD(4), SMILTimeOrigin::kScript}}); + ASSERT_EQ(ExtractListContents(list), expected_times1); + + // Non-unique item. + list.InsertSortedAndUnique(SMILTime::FromSecondsD(2), + SMILTimeOrigin::kScript); + ASSERT_EQ(list.size(), 4u); + ASSERT_EQ(ExtractListContents(list), expected_times1); + + // Same time but different origin. + list.InsertSortedAndUnique(SMILTime::FromSecondsD(2), + SMILTimeOrigin::kAttribute); + ASSERT_EQ(list.size(), 5u); + Vector<std::pair<SMILTime, SMILTimeOrigin>> expected_times2( + {{SMILTime::FromSecondsD(1), SMILTimeOrigin::kAttribute}, + {SMILTime::FromSecondsD(2), SMILTimeOrigin::kAttribute}, + {SMILTime::FromSecondsD(2), SMILTimeOrigin::kScript}, + {SMILTime::FromSecondsD(3), SMILTimeOrigin::kAttribute}, + {SMILTime::FromSecondsD(4), SMILTimeOrigin::kScript}}); + ASSERT_EQ(ExtractListContents(list), expected_times2); +} + +TEST(SMILInstanceTimeListTest, RemoveWithOrigin) { + SMILInstanceTimeList list; + list.Append(SMILTime::FromSecondsD(1), SMILTimeOrigin::kScript); + list.Append(SMILTime::FromSecondsD(2), SMILTimeOrigin::kAttribute); + list.Append(SMILTime::FromSecondsD(3), SMILTimeOrigin::kAttribute); + list.Append(SMILTime::FromSecondsD(4), SMILTimeOrigin::kScript); + list.Append(SMILTime::FromSecondsD(5), SMILTimeOrigin::kAttribute); + ASSERT_EQ(list.size(), 5u); + + list.RemoveWithOrigin(SMILTimeOrigin::kScript); + ASSERT_EQ(list.size(), 3u); + Vector<std::pair<SMILTime, SMILTimeOrigin>> expected_times( + {{SMILTime::FromSecondsD(2), SMILTimeOrigin::kAttribute}, + {SMILTime::FromSecondsD(3), SMILTimeOrigin::kAttribute}, + {SMILTime::FromSecondsD(5), SMILTimeOrigin::kAttribute}}); + ASSERT_EQ(ExtractListContents(list), expected_times); +} + +TEST(SMILInstanceTimeListTest, NextAfter) { + SMILInstanceTimeList list; + list.Append(SMILTime::FromSecondsD(1), SMILTimeOrigin::kScript); + list.Append(SMILTime::FromSecondsD(2), SMILTimeOrigin::kAttribute); + list.Append(SMILTime::FromSecondsD(3), SMILTimeOrigin::kAttribute); + list.Append(SMILTime::FromSecondsD(4), SMILTimeOrigin::kScript); + list.Append(SMILTime::FromSecondsD(5), SMILTimeOrigin::kAttribute); + ASSERT_EQ(list.size(), 5u); + + // Just before an entry in the list. + EXPECT_EQ(list.NextAfter(SMILTime::FromSecondsD(2) - SMILTime::Epsilon()), + SMILTime::FromSecondsD(2)); + // Equal to an entry in the list. + EXPECT_EQ(list.NextAfter(SMILTime::FromSecondsD(2)), + SMILTime::FromSecondsD(3)); + // Just after an entry in the list. + EXPECT_EQ(list.NextAfter(SMILTime::FromSecondsD(2) + SMILTime::Epsilon()), + SMILTime::FromSecondsD(3)); + // Equal to the last entry in the the list. + EXPECT_EQ(list.NextAfter(SMILTime::FromSecondsD(5)), SMILTime::Unresolved()); + // After the last entry in the the list. + EXPECT_EQ(list.NextAfter(SMILTime::FromSecondsD(6)), SMILTime::Unresolved()); +} + +} // namespace + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_fe_image.cc b/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_fe_image.cc index 3a1f782a139..cf6c426f47f 100644 --- a/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_fe_image.cc +++ b/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_fe_image.cc @@ -27,12 +27,12 @@ #include "third_party/blink/renderer/core/paint/svg_object_painter.h" #include "third_party/blink/renderer/core/svg/svg_element.h" #include "third_party/blink/renderer/core/svg/svg_length_context.h" -#include "third_party/blink/renderer/core/svg/svg_uri_reference.h" +#include "third_party/blink/renderer/core/svg/svg_preserve_aspect_ratio.h" #include "third_party/blink/renderer/platform/graphics/filters/filter.h" -#include "third_party/blink/renderer/platform/graphics/filters/paint_filter_builder.h" -#include "third_party/blink/renderer/platform/graphics/graphics_context.h" #include "third_party/blink/renderer/platform/graphics/paint/paint_record.h" #include "third_party/blink/renderer/platform/graphics/paint/paint_record_builder.h" +#include "third_party/blink/renderer/platform/graphics/paint/paint_recorder.h" +#include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h" #include "third_party/blink/renderer/platform/transforms/affine_transform.h" #include "third_party/blink/renderer/platform/wtf/text/text_stream.h" @@ -40,38 +40,35 @@ namespace blink { FEImage::FEImage(Filter* filter, scoped_refptr<Image> image, - SVGPreserveAspectRatio* preserve_aspect_ratio) + const SVGPreserveAspectRatio* preserve_aspect_ratio) : FilterEffect(filter), image_(std::move(image)), - tree_scope_(nullptr), preserve_aspect_ratio_(preserve_aspect_ratio) { FilterEffect::SetOperatingInterpolationSpace(kInterpolationSpaceSRGB); } FEImage::FEImage(Filter* filter, - TreeScope& tree_scope, - const String& href, - SVGPreserveAspectRatio* preserve_aspect_ratio) + const SVGElement* element, + const SVGPreserveAspectRatio* preserve_aspect_ratio) : FilterEffect(filter), - tree_scope_(&tree_scope), - href_(href), + element_(element), preserve_aspect_ratio_(preserve_aspect_ratio) { FilterEffect::SetOperatingInterpolationSpace(kInterpolationSpaceSRGB); } -void FEImage::Trace(blink::Visitor* visitor) { - visitor->Trace(tree_scope_); +void FEImage::Trace(Visitor* visitor) { + visitor->Trace(element_); visitor->Trace(preserve_aspect_ratio_); FilterEffect::Trace(visitor); } -static FloatRect GetLayoutObjectRepaintRect(LayoutObject* layout_object) { +static FloatRect GetLayoutObjectRepaintRect(const LayoutObject* layout_object) { return layout_object->LocalToSVGParentTransform().MapRect( layout_object->VisualRectInLocalSVGCoordinates()); } -AffineTransform MakeMapBetweenRects(const FloatRect& source, - const FloatRect& dest) { +static AffineTransform MakeMapBetweenRects(const FloatRect& source, + const FloatRect& dest) { AffineTransform transform; transform.Translate(dest.X() - source.X(), dest.Y() - source.Y()); transform.Scale(dest.Width() / source.Width(), @@ -79,48 +76,52 @@ AffineTransform MakeMapBetweenRects(const FloatRect& source, return transform; } -FloatRect FEImage::MapInputs(const FloatRect&) const { - LayoutObject* layout_object = ReferencedLayoutObject(); - if (!image_ && !layout_object) - return FloatRect(); +static base::Optional<AffineTransform> ComputeViewportAdjustmentTransform( + const SVGElement* element, + const FloatRect& target_rect) { + // If we're referencing an element with percentage units, eg. <rect + // with="30%"> those values were resolved against the viewport. Build up a + // transformation that maps from the viewport space to the filter primitive + // subregion. + // TODO(crbug/260709): This fixes relative lengths but breaks non-relative + // ones. + SVGLengthContext length_context(element); + FloatSize viewport_size; + if (!length_context.DetermineViewport(viewport_size)) + return base::nullopt; + return MakeMapBetweenRects(FloatRect(FloatPoint(), viewport_size), + target_rect); +} +FloatRect FEImage::MapInputs(const FloatRect&) const { FloatRect dest_rect = GetFilter()->MapLocalRectToAbsoluteRect(FilterPrimitiveSubregion()); - FloatRect src_rect; - if (layout_object) { - src_rect = GetLayoutObjectRepaintRect(layout_object); - auto* context_node = To<SVGElement>(layout_object->GetNode()); - - if (context_node->HasRelativeLengths()) { - // FIXME: This fixes relative lengths but breaks non-relative ones (see - // crbug/260709). - SVGLengthContext length_context(context_node); - FloatSize viewport_size; - if (length_context.DetermineViewport(viewport_size)) { - src_rect = MakeMapBetweenRects(FloatRect(FloatPoint(), viewport_size), - dest_rect) - .MapRect(src_rect); - } + if (const LayoutObject* layout_object = ReferencedLayoutObject()) { + FloatRect src_rect = GetLayoutObjectRepaintRect(layout_object); + if (element_->HasRelativeLengths()) { + auto viewport_transform = + ComputeViewportAdjustmentTransform(element_, dest_rect); + if (viewport_transform) + src_rect = viewport_transform->MapRect(src_rect); } else { src_rect = GetFilter()->MapLocalRectToAbsoluteRect(src_rect); src_rect.Move(dest_rect.X(), dest_rect.Y()); } dest_rect.Intersect(src_rect); - } else { - src_rect = FloatRect(FloatPoint(), FloatSize(image_->Size())); + return dest_rect; + } + if (image_) { + FloatRect src_rect = FloatRect(FloatPoint(), FloatSize(image_->Size())); preserve_aspect_ratio_->TransformRect(dest_rect, src_rect); + return dest_rect; } - return dest_rect; + return FloatRect(); } -LayoutObject* FEImage::ReferencedLayoutObject() const { - if (!tree_scope_) - return nullptr; - Element* href_element = - SVGURIReference::TargetElementFromIRIString(href_, *tree_scope_); - if (!href_element || !href_element->IsSVGElement()) +const LayoutObject* FEImage::ReferencedLayoutObject() const { + if (!element_) return nullptr; - return href_element->GetLayoutObject(); + return element_->GetLayoutObject(); } WTF::TextStream& FEImage::ExternalRepresentation(WTF::TextStream& ts, @@ -128,7 +129,7 @@ WTF::TextStream& FEImage::ExternalRepresentation(WTF::TextStream& ts, IntSize image_size; if (image_) { image_size = image_->Size(); - } else if (LayoutObject* layout_object = ReferencedLayoutObject()) { + } else if (const LayoutObject* layout_object = ReferencedLayoutObject()) { image_size = EnclosingIntRect(GetLayoutObjectRepaintRect(layout_object)).Size(); } @@ -143,59 +144,49 @@ WTF::TextStream& FEImage::ExternalRepresentation(WTF::TextStream& ts, sk_sp<PaintFilter> FEImage::CreateImageFilterForLayoutObject( const LayoutObject& layout_object) { - FloatRect dst_rect = FilterPrimitiveSubregion(); + FloatRect dst_rect = + GetFilter()->MapLocalRectToAbsoluteRect(FilterPrimitiveSubregion()); AffineTransform transform; - auto* context_node = To<SVGElement>(layout_object.GetNode()); - - if (context_node->HasRelativeLengths()) { - SVGLengthContext length_context(context_node); - FloatSize viewport_size; - - // If we're referencing an element with percentage units, eg. <rect - // with="30%"> those values were resolved against the viewport. Build up a - // transformation that maps from the viewport space to the filter primitive - // subregion. - if (length_context.DetermineViewport(viewport_size)) - transform = - MakeMapBetweenRects(FloatRect(FloatPoint(), viewport_size), dst_rect); + if (element_->HasRelativeLengths()) { + auto viewport_transform = + ComputeViewportAdjustmentTransform(element_, dst_rect); + if (viewport_transform) + transform = *viewport_transform; } else { transform.Translate(dst_rect.X(), dst_rect.Y()); } - PaintRecordBuilder builder; - SVGObjectPainter(layout_object).PaintResourceSubtree(builder.Context()); - PaintRecorder paint_recorder; cc::PaintCanvas* canvas = paint_recorder.beginRecording(dst_rect); canvas->concat(AffineTransformToSkMatrix(transform)); - builder.EndRecording(*canvas); - + { + PaintRecordBuilder builder; + SVGObjectPainter(layout_object).PaintResourceSubtree(builder.Context()); + builder.EndRecording(*canvas); + } return sk_make_sp<RecordPaintFilter>( paint_recorder.finishRecordingAsPicture(), dst_rect); } sk_sp<PaintFilter> FEImage::CreateImageFilter() { - if (auto* layout_object = ReferencedLayoutObject()) + if (const auto* layout_object = ReferencedLayoutObject()) return CreateImageFilterForLayoutObject(*layout_object); - PaintImage image = - image_ ? image_->PaintImageForCurrentFrame() : PaintImage(); - if (!image) { - // "A href reference that is an empty image (zero width or zero height), - // that fails to download, is non-existent, or that cannot be displayed - // (e.g. because it is not in a supported image format) fills the filter - // primitive subregion with transparent black." - return CreateTransparentBlack(); + if (PaintImage image = + image_ ? image_->PaintImageForCurrentFrame() : PaintImage()) { + FloatRect src_rect = FloatRect(FloatPoint(), FloatSize(image_->Size())); + FloatRect dst_rect = + GetFilter()->MapLocalRectToAbsoluteRect(FilterPrimitiveSubregion()); + preserve_aspect_ratio_->TransformRect(dst_rect, src_rect); + return sk_make_sp<ImagePaintFilter>(std::move(image), src_rect, dst_rect, + kHigh_SkFilterQuality); } - - FloatRect src_rect = FloatRect(FloatPoint(), FloatSize(image_->Size())); - FloatRect dst_rect = FilterPrimitiveSubregion(); - - preserve_aspect_ratio_->TransformRect(dst_rect, src_rect); - - return sk_make_sp<ImagePaintFilter>(std::move(image), src_rect, dst_rect, - kHigh_SkFilterQuality); + // "A href reference that is an empty image (zero width or zero height), + // that fails to download, is non-existent, or that cannot be displayed + // (e.g. because it is not in a supported image format) fills the filter + // primitive subregion with transparent black." + return CreateTransparentBlack(); } } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_fe_image.h b/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_fe_image.h index 05c641a0a6e..fd0be877c6b 100644 --- a/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_fe_image.h +++ b/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_fe_image.h @@ -24,19 +24,19 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SVG_GRAPHICS_FILTERS_SVG_FE_IMAGE_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_GRAPHICS_FILTERS_SVG_FE_IMAGE_H_ -#include "third_party/blink/renderer/core/dom/tree_scope.h" -#include "third_party/blink/renderer/core/svg/svg_preserve_aspect_ratio.h" #include "third_party/blink/renderer/platform/graphics/filters/filter_effect.h" namespace blink { class Image; class LayoutObject; +class SVGElement; +class SVGPreserveAspectRatio; class FEImage final : public FilterEffect { public: - FEImage(Filter*, scoped_refptr<Image>, SVGPreserveAspectRatio*); - FEImage(Filter*, TreeScope&, const String&, SVGPreserveAspectRatio*); + FEImage(Filter*, scoped_refptr<Image>, const SVGPreserveAspectRatio*); + FEImage(Filter*, const SVGElement*, const SVGPreserveAspectRatio*); // feImage does not perform color interpolation of any kind, so doesn't // depend on the value of color-interpolation-filters. @@ -45,11 +45,11 @@ class FEImage final : public FilterEffect { WTF::TextStream& ExternalRepresentation(WTF::TextStream&, int indention) const override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: ~FEImage() override = default; - LayoutObject* ReferencedLayoutObject() const; + const LayoutObject* ReferencedLayoutObject() const; FilterEffectType GetFilterEffectType() const override { return kFilterEffectTypeImage; @@ -61,12 +61,8 @@ class FEImage final : public FilterEffect { sk_sp<PaintFilter> CreateImageFilterForLayoutObject(const LayoutObject&); scoped_refptr<Image> image_; - - // m_treeScope will never be a dangling reference. See - // https://bugs.webkit.org/show_bug.cgi?id=99243 - Member<TreeScope> tree_scope_; - String href_; - Member<SVGPreserveAspectRatio> preserve_aspect_ratio_; + Member<const SVGElement> element_; + Member<const SVGPreserveAspectRatio> preserve_aspect_ratio_; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_filter_builder.cc b/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_filter_builder.cc index 751dc6ba66e..10bad549ae3 100644 --- a/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_filter_builder.cc +++ b/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_filter_builder.cc @@ -27,6 +27,7 @@ #include "third_party/blink/renderer/core/svg/svg_filter_element.h" #include "third_party/blink/renderer/core/svg/svg_filter_primitive_standard_attributes.h" #include "third_party/blink/renderer/platform/graphics/filters/filter.h" +#include "third_party/blink/renderer/platform/graphics/filters/filter_effect.h" #include "third_party/blink/renderer/platform/graphics/filters/paint_filter_effect.h" #include "third_party/blink/renderer/platform/graphics/filters/source_alpha.h" #include "third_party/blink/renderer/platform/graphics/filters/source_graphic.h" @@ -68,26 +69,21 @@ void SVGFilterGraphNodeMap::AddBuiltinEffect(FilterEffect* effect) { effect_references_.insert(effect, FilterEffectSet()); } -void SVGFilterGraphNodeMap::AddPrimitive(LayoutObject* object, - FilterEffect* effect) { +void SVGFilterGraphNodeMap::AddPrimitive( + SVGFilterPrimitiveStandardAttributes& primitive, + FilterEffect* effect) { // The effect must be a newly created filter effect. DCHECK(!effect_references_.Contains(effect)); - DCHECK(!object || !effect_renderer_.Contains(object)); + DCHECK(!effect_element_.Contains(&primitive)); effect_references_.insert(effect, FilterEffectSet()); - unsigned number_of_input_effects = effect->InputEffects().size(); - // Add references from the inputs of this effect to the effect itself, to // allow determining what effects needs to be invalidated when a certain // effect changes. - for (unsigned i = 0; i < number_of_input_effects; ++i) - EffectReferences(effect->InputEffect(i)).insert(effect); - - // If object is null, that means the element isn't attached for some - // reason, which in turn mean that certain types of invalidation will not - // work (the LayoutObject -> FilterEffect mapping will not be defined). - if (object) - effect_renderer_.insert(object, effect); + for (FilterEffect* input : effect->InputEffects()) + EffectReferences(input).insert(effect); + + effect_element_.insert(&primitive, effect); } void SVGFilterGraphNodeMap::InvalidateDependentEffects(FilterEffect* effect) { @@ -101,8 +97,8 @@ void SVGFilterGraphNodeMap::InvalidateDependentEffects(FilterEffect* effect) { InvalidateDependentEffects(effect_reference); } -void SVGFilterGraphNodeMap::Trace(blink::Visitor* visitor) { - visitor->Trace(effect_renderer_); +void SVGFilterGraphNodeMap::Trace(Visitor* visitor) { + visitor->Trace(effect_element_); visitor->Trace(effect_references_); } @@ -111,22 +107,19 @@ SVGFilterBuilder::SVGFilterBuilder(FilterEffect* source_graphic, const PaintFlags* fill_flags, const PaintFlags* stroke_flags) : node_map_(node_map) { - FilterEffect* source_graphic_ref = source_graphic; builtin_effects_.insert(FilterInputKeywords::GetSourceGraphic(), - source_graphic_ref); - builtin_effects_.insert( - FilterInputKeywords::SourceAlpha(), - MakeGarbageCollected<SourceAlpha>(source_graphic_ref)); + source_graphic); + builtin_effects_.insert(FilterInputKeywords::SourceAlpha(), + MakeGarbageCollected<SourceAlpha>(source_graphic)); if (fill_flags) { builtin_effects_.insert(FilterInputKeywords::FillPaint(), MakeGarbageCollected<PaintFilterEffect>( - source_graphic_ref->GetFilter(), *fill_flags)); + source_graphic->GetFilter(), *fill_flags)); } if (stroke_flags) { - builtin_effects_.insert( - FilterInputKeywords::StrokePaint(), - MakeGarbageCollected<PaintFilterEffect>(source_graphic_ref->GetFilter(), - *stroke_flags)); + builtin_effects_.insert(FilterInputKeywords::StrokePaint(), + MakeGarbageCollected<PaintFilterEffect>( + source_graphic->GetFilter(), *stroke_flags)); } AddBuiltinEffects(); } @@ -185,7 +178,7 @@ void SVGFilterBuilder::BuildGraph(Filter* filter, continue; if (node_map_) - node_map_->AddPrimitive(effect_element.GetLayoutObject(), effect); + node_map_->AddPrimitive(effect_element, effect); effect_element.SetStandardAttributes(effect, primitive_units, reference_box); @@ -223,7 +216,7 @@ FilterEffect* SVGFilterBuilder::GetEffectById(const AtomicString& id) const { } if (last_effect_) - return last_effect_.Get(); + return last_effect_; return builtin_effects_.at(FilterInputKeywords::GetSourceGraphic()); } diff --git a/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_filter_builder.h b/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_filter_builder.h index e532659f094..5aa68df7966 100644 --- a/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_filter_builder.h +++ b/chromium/third_party/blink/renderer/core/svg/graphics/filters/svg_filter_builder.h @@ -22,7 +22,7 @@ #define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_GRAPHICS_FILTERS_SVG_FILTER_BUILDER_H_ #include "third_party/blink/renderer/core/style/svg_computed_style_defs.h" -#include "third_party/blink/renderer/platform/graphics/filters/filter_effect.h" +#include "third_party/blink/renderer/platform/graphics/interpolation_space.h" #include "third_party/blink/renderer/platform/graphics/paint/paint_flags.h" #include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/wtf/hash_map.h" @@ -32,13 +32,15 @@ namespace blink { +class Filter; +class FilterEffect; class FloatRect; -class LayoutObject; class SVGFilterElement; +class SVGFilterPrimitiveStandardAttributes; -// A map from LayoutObject -> FilterEffect and FilterEffect -> dependent -// (downstream) FilterEffects ("reverse DAG"). Used during invalidations from -// changes to the primitives (graph nodes). +// A map from SVGFilterPrimitiveStandardAttributes -> FilterEffect and +// FilterEffect -> dependent (downstream) FilterEffects ("reverse DAG"). Used +// during invalidations for changes to the primitives (graph nodes). class SVGFilterGraphNodeMap final : public GarbageCollected<SVGFilterGraphNodeMap> { public: @@ -47,29 +49,32 @@ class SVGFilterGraphNodeMap final typedef HeapHashSet<Member<FilterEffect>> FilterEffectSet; void AddBuiltinEffect(FilterEffect*); - void AddPrimitive(LayoutObject*, FilterEffect*); - - inline FilterEffectSet& EffectReferences(FilterEffect* effect) { - // Only allowed for effects belongs to this builder. - DCHECK(effect_references_.Contains(effect)); - return effect_references_.find(effect)->value; - } + void AddPrimitive(SVGFilterPrimitiveStandardAttributes&, FilterEffect*); // Required to change the attributes of a filter during an - // svgAttributeChanged. - inline FilterEffect* EffectByRenderer(LayoutObject* object) { - return effect_renderer_.at(object); + // SvgAttributeChanged. + FilterEffect* EffectForElement( + SVGFilterPrimitiveStandardAttributes& primitive) { + return effect_element_.at(&primitive); } void InvalidateDependentEffects(FilterEffect*); - void Trace(blink::Visitor*); + void Trace(Visitor*); private: - // The value is a list, which contains those filter effects, - // which depends on the key filter effect. + FilterEffectSet& EffectReferences(FilterEffect* effect) { + // Only allowed for effects that are part of this node map. + DCHECK(effect_references_.Contains(effect)); + return effect_references_.find(effect)->value; + } + + // The value is the set of filter effects that depend on the key + // filter effect. HeapHashMap<Member<FilterEffect>, FilterEffectSet> effect_references_; - HeapHashMap<LayoutObject*, Member<FilterEffect>> effect_renderer_; + HeapHashMap<WeakMember<SVGFilterPrimitiveStandardAttributes>, + Member<FilterEffect>> + effect_element_; }; class SVGFilterBuilder { @@ -84,7 +89,7 @@ class SVGFilterBuilder { void BuildGraph(Filter*, SVGFilterElement&, const FloatRect&); FilterEffect* GetEffectById(const AtomicString& id) const; - FilterEffect* LastEffect() const { return last_effect_.Get(); } + FilterEffect* LastEffect() const { return last_effect_; } static InterpolationSpace ResolveInterpolationSpace(EColorInterpolation); @@ -97,8 +102,8 @@ class SVGFilterBuilder { NamedFilterEffectMap builtin_effects_; NamedFilterEffectMap named_effects_; - Member<FilterEffect> last_effect_; - Member<SVGFilterGraphNodeMap> node_map_; + FilterEffect* last_effect_ = nullptr; + SVGFilterGraphNodeMap* node_map_; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image.cc b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image.cc index 8fd0092e1eb..c67810593dd 100644 --- a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image.cc +++ b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image.cc @@ -28,6 +28,11 @@ #include "third_party/blink/renderer/core/svg/graphics/svg_image.h" #include "base/memory/scoped_refptr.h" +#include "base/memory/weak_ptr.h" +#include "third_party/blink/public/platform/web_url.h" +#include "third_party/blink/public/platform/web_url_loader.h" +#include "third_party/blink/public/platform/web_url_loader_client.h" +#include "third_party/blink/public/platform/web_url_loader_factory.h" #include "third_party/blink/renderer/core/animation/document_animations.h" #include "third_party/blink/renderer/core/animation/document_timeline.h" #include "third_party/blink/renderer/core/dom/document_parser.h" @@ -69,6 +74,65 @@ namespace blink { +namespace { + +using TaskRunnerHandle = scheduler::WebResourceLoadingTaskRunnerHandle; + +class FailingLoader final : public WebURLLoader { + public: + explicit FailingLoader(std::unique_ptr<TaskRunnerHandle> task_runner_handle) + : task_runner_handle_(std::move(task_runner_handle)) {} + ~FailingLoader() override = default; + + // WebURLLoader implementation: + void LoadSynchronously( + std::unique_ptr<network::ResourceRequest> request, + scoped_refptr<WebURLRequest::ExtraData> request_extra_data, + int requestor_id, + bool download_to_network_cache_only, + bool pass_response_pipe_to_client, + bool no_mime_sniffing, + base::TimeDelta timeout_interval, + WebURLLoaderClient*, + WebURLResponse&, + base::Optional<WebURLError>& error, + WebData&, + int64_t& encoded_data_length, + int64_t& encoded_body_length, + WebBlobInfo& downloaded_blob) override { + NOTREACHED(); + } + void LoadAsynchronously( + std::unique_ptr<network::ResourceRequest> request, + scoped_refptr<WebURLRequest::ExtraData> request_extra_data, + int requestor_id, + bool download_to_network_cache_only, + bool no_mime_sniffing, + WebURLLoaderClient* client) override { + NOTREACHED(); + } + void SetDefersLoading(bool) override {} + void DidChangePriority(WebURLRequest::Priority, int) override {} + scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override { + return task_runner_handle_->GetTaskRunner(); + } + + private: + const std::unique_ptr<TaskRunnerHandle> task_runner_handle_; +}; + +class FailingLoaderFactory final : public WebURLLoaderFactory { + public: + // WebURLLoaderFactory implementation: + std::unique_ptr<WebURLLoader> CreateURLLoader( + const WebURLRequest&, + std::unique_ptr<TaskRunnerHandle> task_runner_handle) override { + return std::make_unique<FailingLoader>(std::move(task_runner_handle)); + } +}; + +} // namespace + // SVGImageLocalFrameClient is used to wait until SVG document's load event // in the case where there are subresources asynchronously loaded. // @@ -82,7 +146,9 @@ class SVGImage::SVGImageLocalFrameClient : public EmptyLocalFrameClient { private: std::unique_ptr<WebURLLoaderFactory> CreateURLLoaderFactory() override { - return Platform::Current()->CreateDefaultURLLoaderFactory(); + // SVG Images have unique security rules that prevent all subresource + // requests except for data urls. + return std::make_unique<FailingLoaderFactory>(); } void DispatchDidHandleOnloadEvents() override { @@ -107,6 +173,11 @@ SVGImage::~SVGImage() { frame_client_->ClearImage(); if (page_) { + // It is safe to allow UA events within this scope, because event + // dispatching inside the SVG image's document doesn't trigger JavaScript + // execution. All script execution is forbidden when an SVG is loaded as an + // image subresource - see SetScriptEnabled in SVGImage::DataChanged(). + EventDispatchForbiddenScope::AllowUserAgentEvents allow_events; // Store m_page in a local variable, clearing m_page, so that // SVGImageChromeClient knows we're destructed. Page* current_page = page_.Release(); @@ -178,18 +249,18 @@ static SVGSVGElement* SvgRootElement(Page* page) { return frame->GetDocument()->AccessSVGExtensions().rootElement(); } -IntSize SVGImage::ContainerSize() const { +LayoutSize SVGImage::ContainerSize() const { SVGSVGElement* root_element = SvgRootElement(page_.Get()); if (!root_element) - return IntSize(); + return LayoutSize(); LayoutSVGRoot* layout_object = ToLayoutSVGRoot(root_element->GetLayoutObject()); if (!layout_object) - return IntSize(); + return LayoutSize(); // If a container size is available it has precedence. - IntSize container_size = layout_object->ContainerSize(); + LayoutSize container_size = layout_object->ContainerSize(); if (!container_size.IsEmpty()) return container_size; @@ -200,6 +271,10 @@ IntSize SVGImage::ContainerSize() const { return intrinsic_size_; } +IntSize SVGImage::Size() const { + return RoundedIntSize(intrinsic_size_); +} + static float ResolveWidthForRatio(float height, const FloatSize& intrinsic_ratio) { return height * intrinsic_ratio.Width() / intrinsic_ratio.Height(); @@ -298,7 +373,7 @@ void SVGImage::ForContainer(const FloatSize& container_size, Func&& func) { // re-laying out the image. ImageObserverDisabler image_observer_disabler(this); - IntSize rounded_container_size = RoundedIntSize(container_size); + LayoutSize rounded_container_size = RoundedLayoutSize(container_size); if (SVGSVGElement* root_element = SvgRootElement(page_.Get())) { if (LayoutSVGRoot* layout_object = @@ -326,8 +401,8 @@ void SVGImage::DrawForContainer(cc::PaintCanvas* canvas, adjusted_src_size.Scale(residual_scale.Width(), residual_scale.Height()); scaled_src.SetSize(adjusted_src_size); - DrawInternal(canvas, flags, dst_rect, scaled_src, - kDoNotRespectImageOrientation, kClampImageToSourceRect, url); + DrawInternal(canvas, flags, dst_rect, scaled_src, kRespectImageOrientation, + kClampImageToSourceRect, url); }); } @@ -443,12 +518,11 @@ static bool DrawNeedsLayer(const PaintFlags& flags) { bool SVGImage::ApplyShaderInternal(PaintFlags& flags, const SkMatrix& local_matrix, const KURL& url) { - const IntSize size(ContainerSize()); + const FloatSize size(ContainerSize()); if (size.IsEmpty()) return false; - IntRect bounds(IntPoint(), size); - + FloatRect bounds(FloatPoint(), size); flags.setShader(PaintShader::MakePaintRecord( PaintRecordForCurrentFrame(url), bounds, SkTileMode::kRepeat, SkTileMode::kRepeat, &local_matrix)); @@ -500,8 +574,9 @@ void SVGImage::Draw( sk_sp<PaintRecord> SVGImage::PaintRecordForCurrentFrame(const KURL& url) { DCHECK(page_); LocalFrameView* view = To<LocalFrame>(page_->MainFrame())->View(); - view->Resize(ContainerSize()); - page_->GetVisualViewport().SetSize(ContainerSize()); + IntSize rounded_container_size = RoundedIntSize(ContainerSize()); + view->Resize(rounded_container_size); + page_->GetVisualViewport().SetSize(rounded_container_size); // Always call processUrlFragment, even if the url is empty, because // there may have been a previous url/fragment that needs to be reset. @@ -515,12 +590,11 @@ sk_sp<PaintRecord> SVGImage::PaintRecordForCurrentFrame(const KURL& url) { FlushPendingTimelineRewind(); if (RuntimeEnabledFeatures::CompositeAfterPaintEnabled()) { - view->UpdateAllLifecyclePhases( - DocumentLifecycle::LifecycleUpdateReason::kOther); + view->UpdateAllLifecyclePhases(DocumentUpdateReason::kSVGImage); return view->GetPaintRecord(); } - view->UpdateAllLifecyclePhasesExceptPaint(); + view->UpdateAllLifecyclePhasesExceptPaint(DocumentUpdateReason::kSVGImage); PaintRecordBuilder builder(nullptr, nullptr, paint_controller_.get()); view->PaintOutsideOfLifecycle(builder.Context(), kGlobalPaintNormalPhase); return builder.EndRecording(); @@ -542,18 +616,10 @@ void SVGImage::DrawInternal(cc::PaintCanvas* canvas, // We can only draw the entire frame, clipped to the rect we want. So // compute where the top left of the image would be if we were drawing // without clipping, and translate accordingly. - FloatSize scale(dst_rect.Width() / src_rect.Width(), - dst_rect.Height() / src_rect.Height()); - FloatSize top_left_offset(src_rect.Location().X() * scale.Width(), - src_rect.Location().Y() * scale.Height()); - FloatPoint dest_offset = dst_rect.Location() - top_left_offset; - AffineTransform transform = - AffineTransform::Translation(dest_offset.X(), dest_offset.Y()); - transform.Scale(scale.Width(), scale.Height()); - canvas->save(); canvas->clipRect(EnclosingIntRect(dst_rect)); - canvas->concat(AffineTransformToSkMatrix(transform)); + canvas->concat(SkMatrix::MakeRectToRect(src_rect, dst_rect, + SkMatrix::kFill_ScaleToFit)); canvas->drawPicture(PaintRecordForCurrentFrame(url)); canvas->restore(); } @@ -653,16 +719,18 @@ void SVGImage::ServiceAnimations( // but to preserve correct coherence of the cache of the output with // the needsRepaint bits of the PaintLayers in the image. LocalFrameView* frame_view = To<LocalFrame>(page_->MainFrame())->View(); - frame_view->UpdateAllLifecyclePhasesExceptPaint(); + frame_view->UpdateAllLifecyclePhasesExceptPaint( + DocumentUpdateReason::kSVGImage); // We run UpdateAnimations after the paint phase, but per the above comment, // we don't want to run lifecycle through to paint for SVG images. Since we // know SVG images never have composited animations, we can update animations // directly without worrying about including PaintArtifactCompositor's // analysis of whether animations should be composited. - DocumentAnimations::UpdateAnimations( - frame_view->GetLayoutView()->GetDocument(), - DocumentLifecycle::kLayoutClean, nullptr); + frame_view->GetLayoutView() + ->GetDocument() + .GetDocumentAnimations() + .UpdateAnimations(DocumentLifecycle::kLayoutClean, nullptr); } void SVGImage::AdvanceAnimationForTesting() { @@ -785,6 +853,11 @@ Image::SizeAvailability SVGImage::DataChanged(bool all_data_received) { default_settings.GetDefaultFontSize()); page->GetSettings().SetDefaultFixedFontSize( default_settings.GetDefaultFixedFontSize()); + + // Also copy the preferred-color-scheme to ensure a responsiveness to + // dark/light color schemes. + page->GetSettings().SetPreferredColorScheme( + default_settings.GetPreferredColorScheme()); } } @@ -800,7 +873,7 @@ Image::SizeAvailability SVGImage::DataChanged(bool all_data_received) { } FrameLoader& loader = frame->Loader(); - loader.ForceSandboxFlags(WebSandboxFlags::kAll); + loader.ForceSandboxFlags(mojom::blink::WebSandboxFlags::kAll); // SVG Images will always synthesize a viewBox, if it's not available, and // thus never see scrollbars. @@ -819,7 +892,7 @@ Image::SizeAvailability SVGImage::DataChanged(bool all_data_received) { frame->GetDocument()->UpdateStyleAndLayoutTree(); // Set the concrete object size before a container size is available. - intrinsic_size_ = RoundedIntSize(ConcreteObjectSize(FloatSize( + intrinsic_size_ = RoundedLayoutSize(ConcreteObjectSize(FloatSize( LayoutReplaced::kDefaultWidth, LayoutReplaced::kDefaultHeight))); DCHECK(page_); diff --git a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image.h b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image.h index 8dd7b4acf3e..3841f0e2120 100644 --- a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image.h +++ b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image.h @@ -29,11 +29,13 @@ #include "base/macros.h" #include "third_party/blink/renderer/core/core_export.h" +#include "third_party/blink/renderer/platform/geometry/layout_size.h" #include "third_party/blink/renderer/platform/graphics/image.h" #include "third_party/blink/renderer/platform/graphics/paint/paint_record.h" #include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" #include "third_party/skia/include/core/SkRefCnt.h" namespace blink { @@ -66,7 +68,7 @@ class CORE_EXPORT SVGImage final : public Image { static bool IsInSVGImage(const Node*); bool IsSVGImage() const override { return true; } - IntSize Size() const override { return intrinsic_size_; } + IntSize Size() const override; void CheckLoaded() const; bool CurrentFrameHasSingleSecurityOrigin() const override; @@ -144,7 +146,7 @@ class CORE_EXPORT SVGImage final : public Image { String FilenameExtension() const override; - IntSize ContainerSize() const; + LayoutSize ContainerSize() const; SizeAvailability DataChanged(bool all_data_received) override; @@ -227,7 +229,7 @@ class CORE_EXPORT SVGImage final : public Image { // belong to multiple containers so the final image size can't be known in // SVGImage. SVGImageForContainer carries the final image size, also called // the "concrete object size". For more, see: SVGImageForContainer.h - IntSize intrinsic_size_; + LayoutSize intrinsic_size_; bool has_pending_timeline_rewind_; enum LoadState { @@ -246,9 +248,13 @@ class CORE_EXPORT SVGImage final : public Image { FRIEND_TEST_ALL_PREFIXES(SVGImageTest, LayoutShiftTrackerDisabled); FRIEND_TEST_ALL_PREFIXES(SVGImageTest, SetSizeOnVisualViewport); FRIEND_TEST_ALL_PREFIXES(SVGImageTest, IsSizeAvailable); + FRIEND_TEST_ALL_PREFIXES(SVGImageTest, DisablesSMILEvents); }; -DEFINE_IMAGE_TYPE_CASTS(SVGImage); +template <> +struct DowncastTraits<SVGImage> { + static bool AllowFrom(const Image& image) { return image.IsSVGImage(); } +}; class ImageObserverDisabler { STACK_ALLOCATED(); diff --git a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_chrome_client.h b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_chrome_client.h index 6460951775f..69506e85d6c 100644 --- a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_chrome_client.h +++ b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_chrome_client.h @@ -34,6 +34,7 @@ #include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/loader/empty_clients.h" #include "third_party/blink/renderer/platform/timer.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -76,11 +77,12 @@ class CORE_EXPORT SVGImageChromeClient final : public EmptyChromeClient { FRIEND_TEST_ALL_PREFIXES(SVGImageSimTest, PageVisibilityHiddenToVisible); }; -DEFINE_TYPE_CASTS(SVGImageChromeClient, - ChromeClient, - client, - client->IsSVGImageChromeClient(), - client.IsSVGImageChromeClient()); +template <> +struct DowncastTraits<SVGImageChromeClient> { + static bool AllowFrom(const ChromeClient& client) { + return client.IsSVGImageChromeClient(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_for_container.cc b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_for_container.cc index 9745ea45053..6e701174f98 100644 --- a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_for_container.cc +++ b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_for_container.cc @@ -28,9 +28,15 @@ namespace blink { IntSize SVGImageForContainer::Size() const { + // The image orientation is irrelevant because there is not concept of + // orientation for SVG images. + return RoundedIntSize(SizeAsFloat(kRespectImageOrientation)); +} + +FloatSize SVGImageForContainer::SizeAsFloat(RespectImageOrientationEnum) const { FloatSize scaled_container_size(container_size_); scaled_container_size.Scale(zoom_); - return RoundedIntSize(scaled_container_size); + return scaled_container_size; } void SVGImageForContainer::Draw(cc::PaintCanvas* canvas, @@ -50,7 +56,8 @@ void SVGImageForContainer::DrawPattern(GraphicsContext& context, const FloatPoint& phase, SkBlendMode op, const FloatRect& dst_rect, - const FloatSize& repeat_spacing) { + const FloatSize& repeat_spacing, + RespectImageOrientationEnum) { image_->DrawPatternForContainer(context, container_size_, zoom_, src_rect, scale, phase, op, dst_rect, repeat_spacing, url_); diff --git a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h index 1e617991b62..3a59c9578a4 100644 --- a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h +++ b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h @@ -70,6 +70,7 @@ class SVGImageForContainer final : public Image { } IntSize Size() const override; + FloatSize SizeAsFloat(RespectImageOrientationEnum) const override; bool HasIntrinsicSize() const override { return image_->HasIntrinsicSize(); } @@ -102,7 +103,8 @@ class SVGImageForContainer final : public Image { const FloatPoint&, SkBlendMode, const FloatRect&, - const FloatSize& repeat_spacing) override; + const FloatSize& repeat_spacing, + RespectImageOrientationEnum) override; private: SVGImageForContainer(SVGImage* image, diff --git a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_test.cc b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_test.cc index 25523b191cf..59944100bb6 100644 --- a/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_test.cc +++ b/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_test.cc @@ -15,7 +15,9 @@ #include "third_party/blink/renderer/core/layout/layout_shift_tracker.h" #include "third_party/blink/renderer/core/layout/layout_view.h" #include "third_party/blink/renderer/core/paint/paint_layer.h" +#include "third_party/blink/renderer/core/svg/animation/smil_time_container.h" #include "third_party/blink/renderer/core/svg/graphics/svg_image_chrome_client.h" +#include "third_party/blink/renderer/core/svg/svg_svg_element.h" #include "third_party/blink/renderer/core/testing/sim/sim_request.h" #include "third_party/blink/renderer/core/testing/sim/sim_test.h" #include "third_party/blink/renderer/platform/geometry/float_rect.h" @@ -36,7 +38,7 @@ const float kEpsilon = 0.00001; } // namespace -class SVGImageTest : public testing::Test { +class SVGImageTest : public testing::Test, private ScopedMockOverlayScrollbars { public: SVGImage& GetImage() { return *image_; } @@ -44,6 +46,7 @@ class SVGImageTest : public testing::Test { observer_ = MakeGarbageCollected<PauseControlImageObserver>(should_pause); image_ = SVGImage::Create(observer_); image_->SetData(SharedBuffer::Create(data, strlen(data)), true); + test::RunPendingTasks(); } void LoadUsingFileName(const String& file_name) { @@ -54,6 +57,7 @@ class SVGImageTest : public testing::Test { observer_ = MakeGarbageCollected<PauseControlImageObserver>(true); image_ = SVGImage::Create(observer_); image_->SetData(image_data, true); + test::RunPendingTasks(); } void PumpFrame() { @@ -63,8 +67,8 @@ class SVGImageTest : public testing::Test { PaintFlags flags; FloatRect dummy_rect(0, 0, 100, 100); image->Draw(&canvas, flags, dummy_rect, dummy_rect, - kDoNotRespectImageOrientation, - Image::kDoNotClampImageToSourceRect, Image::kSyncDecode); + kRespectImageOrientation, Image::kDoNotClampImageToSourceRect, + Image::kSyncDecode); } // Loads the image from |file_name|, computes features into |features|, @@ -109,9 +113,7 @@ class SVGImageTest : public testing::Test { void AsyncLoadCompleted(const blink::Image*) override {} - void Trace(blink::Visitor* visitor) override { - ImageObserver::Trace(visitor); - } + void Trace(Visitor* visitor) override { ImageObserver::Trace(visitor); } private: bool should_pause_; @@ -252,6 +254,18 @@ TEST_F(SVGImageTest, IsSizeAvailable) { EXPECT_FALSE(GetImage().IsSizeAvailable()); } +TEST_F(SVGImageTest, DisablesSMILEvents) { + const bool kShouldPause = true; + Load(kAnimatedDocument, kShouldPause); + LocalFrame* local_frame = + To<LocalFrame>(GetImage().GetPageForTesting()->MainFrame()); + EXPECT_TRUE(local_frame->GetDocument()->IsSVGDocument()); + SMILTimeContainer* time_container = + To<SVGSVGElement>(local_frame->GetDocument()->documentElement()) + ->TimeContainer(); + EXPECT_TRUE(time_container->EventsDisabled()); +} + TEST_F(SVGImageTest, DarkModeClassification) { DarkModeImageClassifier::Features features; @@ -316,7 +330,7 @@ TEST_F(SVGImageTest, DarkModeClassification) { EXPECT_NEAR(0.11f, features.background_ratio, kEpsilon); } -class SVGImageSimTest : public SimTest {}; +class SVGImageSimTest : public SimTest, private ScopedMockOverlayScrollbars {}; TEST_F(SVGImageSimTest, PageVisibilityHiddenToVisible) { SimRequest main_resource("https://example.com/", "text/html"); @@ -338,9 +352,9 @@ TEST_F(SVGImageSimTest, PageVisibilityHiddenToVisible) { ASSERT_TRUE(image_content->IsLoaded()); ASSERT_TRUE(image_content->HasImage()); Image* image = image_content->GetImage(); - ASSERT_TRUE(image->IsSVGImage()); + ASSERT_TRUE(IsA<SVGImage>(image)); SVGImageChromeClient& svg_image_chrome_client = - ToSVGImage(*image).ChromeClientForTesting(); + To<SVGImage>(*image).ChromeClientForTesting(); TimerBase* timer = svg_image_chrome_client.GetTimerForTesting(); // Wait for the next animation frame to be triggered, and then trigger a new diff --git a/chromium/third_party/blink/renderer/core/svg/linear_gradient_attributes.h b/chromium/third_party/blink/renderer/core/svg/linear_gradient_attributes.h index 0669fbb991d..aa759fa71bf 100644 --- a/chromium/third_party/blink/renderer/core/svg/linear_gradient_attributes.h +++ b/chromium/third_party/blink/renderer/core/svg/linear_gradient_attributes.h @@ -70,7 +70,7 @@ struct LinearGradientAttributes : GradientAttributes { bool HasX2() const { return x2_set_; } bool HasY2() const { return y2_set_; } - void Trace(blink::Visitor* visitor) { + void Trace(Visitor* visitor) { visitor->Trace(x1_); visitor->Trace(y1_); visitor->Trace(x2_); @@ -101,7 +101,7 @@ class LinearGradientAttributesWrapper final void Set(const LinearGradientAttributes& attributes) { attributes_ = attributes; } - void Trace(blink::Visitor* visitor) { visitor->Trace(attributes_); } + void Trace(Visitor* visitor) { visitor->Trace(attributes_); } private: LinearGradientAttributes attributes_; diff --git a/chromium/third_party/blink/renderer/core/svg/pattern_attributes.h b/chromium/third_party/blink/renderer/core/svg/pattern_attributes.h index 9f17ae8c23b..7aef7ddd25b 100644 --- a/chromium/third_party/blink/renderer/core/svg/pattern_attributes.h +++ b/chromium/third_party/blink/renderer/core/svg/pattern_attributes.h @@ -133,7 +133,7 @@ class PatternAttributes final { bool HasPatternTransform() const { return pattern_transform_set_; } bool HasPatternContentElement() const { return pattern_content_element_set_; } - void Trace(blink::Visitor* visitor) { + void Trace(Visitor* visitor) { visitor->Trace(x_); visitor->Trace(y_); visitor->Trace(width_); @@ -176,7 +176,7 @@ class PatternAttributesWrapper PatternAttributes& Attributes() { return attributes_; } void Set(const PatternAttributes& attributes) { attributes_ = attributes; } - void Trace(blink::Visitor* visitor) { visitor->Trace(attributes_); } + void Trace(Visitor* visitor) { visitor->Trace(attributes_); } private: PatternAttributes attributes_; diff --git a/chromium/third_party/blink/renderer/core/svg/properties/svg_animated_property.h b/chromium/third_party/blink/renderer/core/svg/properties/svg_animated_property.h index 3dd5b4a38f5..7bcf423b221 100644 --- a/chromium/third_party/blink/renderer/core/svg/properties/svg_animated_property.h +++ b/chromium/third_party/blink/renderer/core/svg/properties/svg_animated_property.h @@ -101,7 +101,7 @@ class SVGAnimatedPropertyBase : public GarbageCollectedMixin { private: static_assert(kNumberOfAnimatedPropertyTypes <= (1u << 5), "enough bits for AnimatedPropertyType (type_)"); - static constexpr int kCssPropertyBits = 9; + static constexpr int kCssPropertyBits = 10; static_assert((1u << kCssPropertyBits) - 1 >= kIntLastCSSProperty, "enough bits for CSS property ids"); @@ -161,7 +161,7 @@ class SVGAnimatedPropertyCommon : public SVGAnimatedPropertyBase { SVGAnimatedPropertyBase::AnimationEnded(); } - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { visitor->Trace(base_value_); visitor->Trace(current_value_); SVGAnimatedPropertyBase::Trace(visitor); @@ -273,7 +273,7 @@ class SVGAnimatedProperty<Property, TearOffType, void> return anim_val_tear_off_; } - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { visitor->Trace(base_val_tear_off_); visitor->Trace(anim_val_tear_off_); SVGAnimatedPropertyCommon<Property>::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/svg/properties/svg_list_property_helper.h b/chromium/third_party/blink/renderer/core/svg/properties/svg_list_property_helper.h index 251ea844c15..dfea5e8c7b6 100644 --- a/chromium/third_party/blink/renderer/core/svg/properties/svg_list_property_helper.h +++ b/chromium/third_party/blink/renderer/core/svg/properties/svg_list_property_helper.h @@ -124,7 +124,7 @@ class SVGListPropertyHelper : public SVGPropertyHelper<Derived> { ItemPropertyType* AppendItem(ItemPropertyType*); ItemPropertyType* ReplaceItem(ItemPropertyType*, uint32_t, ExceptionState&); - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { visitor->Trace(values_); SVGPropertyHelper<Derived>::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/properties/svg_list_property_tear_off_helper.h b/chromium/third_party/blink/renderer/core/svg/properties/svg_list_property_tear_off_helper.h index 6435cba39b1..a98b0cc5e5b 100644 --- a/chromium/third_party/blink/renderer/core/svg/properties/svg_list_property_tear_off_helper.h +++ b/chromium/third_party/blink/renderer/core/svg/properties/svg_list_property_tear_off_helper.h @@ -32,6 +32,7 @@ #define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_PROPERTIES_SVG_LIST_PROPERTY_TEAR_OFF_HELPER_H_ #include "third_party/blink/renderer/core/svg/properties/svg_property_tear_off.h" +#include "third_party/blink/renderer/platform/bindings/v8_binding.h" #include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/wtf/type_traits.h" @@ -141,11 +142,12 @@ class SVGListPropertyTearOffHelper : public SVGPropertyTearOff<ListProperty> { return CreateItemTearOff(value); } - bool AnonymousIndexedSetter(uint32_t index, - ItemTearOffType* item, - ExceptionState& exception_state) { + IndexedPropertySetterResult AnonymousIndexedSetter( + uint32_t index, + ItemTearOffType* item, + ExceptionState& exception_state) { replaceItem(item, index, exception_state); - return true; + return IndexedPropertySetterResult::kIntercepted; } ItemTearOffType* removeItem(uint32_t index, ExceptionState& exception_state) { diff --git a/chromium/third_party/blink/renderer/core/svg/properties/svg_property.h b/chromium/third_party/blink/renderer/core/svg/properties/svg_property.h index 752f1581be0..a58d5a8ea62 100644 --- a/chromium/third_party/blink/renderer/core/svg/properties/svg_property.h +++ b/chromium/third_party/blink/renderer/core/svg/properties/svg_property.h @@ -85,7 +85,7 @@ class SVGPropertyBase : public GarbageCollected<SVGPropertyBase> { owner_list_ = owner_list; } - virtual void Trace(blink::Visitor* visitor) {} + virtual void Trace(Visitor* visitor) {} protected: SVGPropertyBase() : owner_list_(nullptr) {} @@ -99,11 +99,6 @@ class SVGPropertyBase : public GarbageCollected<SVGPropertyBase> { DISALLOW_COPY_AND_ASSIGN(SVGPropertyBase); }; -#define DEFINE_SVG_PROPERTY_TYPE_CASTS(thisType) \ - DEFINE_TYPE_CASTS(thisType, SVGPropertyBase, value, \ - value->GetType() == thisType::ClassType(), \ - value.GetType() == thisType::ClassType()) - } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_PROPERTIES_SVG_PROPERTY_H_ diff --git a/chromium/third_party/blink/renderer/core/svg/properties/svg_property_tear_off.h b/chromium/third_party/blink/renderer/core/svg/properties/svg_property_tear_off.h index d8edb8847f3..a2c2a97d1c9 100644 --- a/chromium/third_party/blink/renderer/core/svg/properties/svg_property_tear_off.h +++ b/chromium/third_party/blink/renderer/core/svg/properties/svg_property_tear_off.h @@ -90,7 +90,7 @@ class SVGPropertyTearOff : public SVGPropertyTearOffBase { void SetTarget(Property* target) { target_ = target; } - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { visitor->Trace(target_); SVGPropertyTearOffBase::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/radial_gradient_attributes.h b/chromium/third_party/blink/renderer/core/svg/radial_gradient_attributes.h index 3947fe58940..9143d140e19 100644 --- a/chromium/third_party/blink/renderer/core/svg/radial_gradient_attributes.h +++ b/chromium/third_party/blink/renderer/core/svg/radial_gradient_attributes.h @@ -86,7 +86,7 @@ struct RadialGradientAttributes final : GradientAttributes { bool HasFy() const { return fy_set_; } bool HasFr() const { return fr_set_; } - void Trace(blink::Visitor* visitor) { + void Trace(Visitor* visitor) { visitor->Trace(cx_); visitor->Trace(cy_); visitor->Trace(r_); @@ -123,7 +123,7 @@ class RadialGradientAttributesWrapper final void Set(const RadialGradientAttributes& attributes) { attributes_ = attributes; } - void Trace(blink::Visitor* visitor) { visitor->Trace(attributes_); } + void Trace(Visitor* visitor) { visitor->Trace(attributes_); } private: RadialGradientAttributes attributes_; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_a_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_a_element.cc index 0626fca4b42..b27a8885972 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_a_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_a_element.cc @@ -22,6 +22,7 @@ #include "third_party/blink/renderer/core/svg/svg_a_element.h" +#include "third_party/blink/public/mojom/input/focus_type.mojom-blink.h" #include "third_party/blink/renderer/core/dom/attr.h" #include "third_party/blink/renderer/core/dom/attribute.h" #include "third_party/blink/renderer/core/dom/document.h" @@ -57,7 +58,7 @@ SVGAElement::SVGAElement(Document& document) AddToPropertyMap(svg_target_); } -void SVGAElement::Trace(blink::Visitor* visitor) { +void SVGAElement::Trace(Visitor* visitor) { visitor->Trace(svg_target_); SVGGraphicsElement::Trace(visitor); SVGURIReference::Trace(visitor); @@ -175,7 +176,7 @@ bool SVGAElement::SupportsFocus() const { } bool SVGAElement::ShouldHaveFocusAppearance() const { - return (GetDocument().LastFocusType() != kWebFocusTypeMouse) || + return (GetDocument().LastFocusType() != mojom::blink::FocusType::kMouse) || SVGGraphicsElement::SupportsFocus(); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_a_element.h b/chromium/third_party/blink/renderer/core/svg/svg_a_element.h index 795ec7e21e5..79e0722aa83 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_a_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_a_element.h @@ -38,7 +38,7 @@ class CORE_EXPORT SVGAElement final : public SVGGraphicsElement, explicit SVGAElement(Document&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: String title() const override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_angle.cc b/chromium/third_party/blink/renderer/core/svg/svg_angle.cc index 37936c945bf..87d2ce53ce4 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_angle.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_angle.cc @@ -47,7 +47,7 @@ SVGMarkerOrientEnumeration::SVGMarkerOrientEnumeration(SVGAngle* angle) SVGMarkerOrientEnumeration::~SVGMarkerOrientEnumeration() = default; -void SVGMarkerOrientEnumeration::Trace(blink::Visitor* visitor) { +void SVGMarkerOrientEnumeration::Trace(Visitor* visitor) { visitor->Trace(angle_); SVGEnumeration<SVGMarkerOrientType>::Trace(visitor); } @@ -98,7 +98,7 @@ SVGAngle::SVGAngle(SVGAngleType unit_type, SVGAngle::~SVGAngle() = default; -void SVGAngle::Trace(blink::Visitor* visitor) { +void SVGAngle::Trace(Visitor* visitor) { visitor->Trace(orient_type_); SVGPropertyHelper<SVGAngle>::Trace(visitor); } @@ -362,7 +362,7 @@ void SVGAngle::ConvertToSpecifiedUnits(SVGAngleType unit_type) { } void SVGAngle::Add(SVGPropertyBase* other, SVGElement*) { - SVGAngle* other_angle = ToSVGAngle(other); + auto* other_angle = To<SVGAngle>(other); // Only respect by animations, if from and by are both specified in angles // (and not, for example, 'auto'). @@ -391,8 +391,8 @@ void SVGAngle::CalculateAnimatedValue( SVGPropertyBase* to, SVGPropertyBase* to_at_end_of_duration, SVGElement*) { - SVGAngle* from_angle = ToSVGAngle(from); - SVGAngle* to_angle = ToSVGAngle(to); + auto* from_angle = To<SVGAngle>(from); + auto* to_angle = To<SVGAngle>(to); SVGMarkerOrientType from_orient_type = from_angle->OrientType()->EnumValue(); SVGMarkerOrientType to_orient_type = to_angle->OrientType()->EnumValue(); @@ -407,13 +407,13 @@ void SVGAngle::CalculateAnimatedValue( float animated_value = Value(); animation_element.AnimateAdditiveNumber( percentage, repeat_count, from_angle->Value(), to_angle->Value(), - ToSVGAngle(to_at_end_of_duration)->Value(), animated_value); + To<SVGAngle>(to_at_end_of_duration)->Value(), animated_value); OrientType()->SetEnumValue(kSVGMarkerOrientAngle); SetValue(animated_value); } float SVGAngle::CalculateDistance(SVGPropertyBase* other, SVGElement*) { - return fabsf(Value() - ToSVGAngle(other)->Value()); + return fabsf(Value() - To<SVGAngle>(other)->Value()); } void SVGAngle::OrientTypeChanged() { diff --git a/chromium/third_party/blink/renderer/core/svg/svg_angle.h b/chromium/third_party/blink/renderer/core/svg/svg_angle.h index 0544951fc90..4ec7825fb0a 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_angle.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_angle.h @@ -26,6 +26,7 @@ #include "third_party/blink/renderer/core/svg/svg_enumeration.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" #include "third_party/blink/renderer/platform/heap/handle.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -56,7 +57,7 @@ class SVGMarkerOrientEnumeration final SVGElement*) override; float CalculateDistance(SVGPropertyBase*, SVGElement*) override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void NotifyChange() override; @@ -130,7 +131,7 @@ class SVGAngle final : public SVGPropertyHelper<SVGAngle> { static AnimatedPropertyType ClassType() { return kAnimatedAngle; } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void Assign(const SVGAngle&); @@ -140,7 +141,12 @@ class SVGAngle final : public SVGPropertyHelper<SVGAngle> { Member<SVGMarkerOrientEnumeration> orient_type_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGAngle); +template <> +struct DowncastTraits<SVGAngle> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGAngle::ClassType(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animate_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_animate_element.cc index 326e8c2e901..16e66af4305 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animate_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_animate_element.cc @@ -24,6 +24,7 @@ #include "third_party/blink/renderer/core/css/css_computed_style_declaration.h" #include "third_party/blink/renderer/core/css/css_property_value_set.h" +#include "third_party/blink/renderer/core/css/css_style_sheet.h" #include "third_party/blink/renderer/core/css/style_change_reason.h" #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/qualified_name.h" @@ -180,9 +181,11 @@ void SVGAnimateElement::ResolveTargetProperty() { } } else { type_ = SVGElement::AnimatedPropertyTypeForCSSAttribute(AttributeName()); - css_property_id_ = type_ != kAnimatedUnknown - ? cssPropertyID(AttributeName().LocalName()) - : CSSPropertyID::kInvalid; + css_property_id_ = + type_ != kAnimatedUnknown + ? cssPropertyID(targetElement()->GetDocument().ToExecutionContext(), + AttributeName().LocalName()) + : CSSPropertyID::kInvalid; } // Blacklist <script> targets here for now to prevent unpleasantries. This // also disallows the perfectly "valid" animation of 'className' on said @@ -486,11 +489,10 @@ void SVGAnimateElement::ApplyResultsToTarget() { MutableCSSPropertyValueSet* properties = target_element->EnsureAnimatedSMILStyleProperties(); auto animated_value_string = animated_value_->ValueAsString(); - auto secure_context_mode = - target_element->GetDocument().GetSecureContextMode(); - auto set_result = - properties->SetProperty(css_property_id_, animated_value_string, false, - secure_context_mode, nullptr); + auto& document = target_element->GetDocument(); + auto set_result = properties->SetProperty( + css_property_id_, animated_value_string, false, + document.GetSecureContextMode(), document.ElementSheet().Contents()); if (set_result.did_change) { target_element->SetNeedsStyleRecalc( kLocalStyleChange, @@ -584,7 +586,7 @@ void SVGAnimateElement::SetAttributeType( AnimationAttributeChanged(); } -void SVGAnimateElement::Trace(blink::Visitor* visitor) { +void SVGAnimateElement::Trace(Visitor* visitor) { visitor->Trace(from_property_); visitor->Trace(to_property_); visitor->Trace(to_at_end_of_duration_property_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animate_element.h b/chromium/third_party/blink/renderer/core/svg/svg_animate_element.h index 367d1150063..4411ec1b9c5 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animate_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animate_element.h @@ -44,7 +44,7 @@ class CORE_EXPORT SVGAnimateElement : public SVGAnimationElement { SVGAnimateElement(const QualifiedName&, Document&); ~SVGAnimateElement() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; bool IsSVGAnimationAttributeSettingJavaScriptURL( const Attribute&) const override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animate_motion_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_animate_motion_element.cc index 4f9af01003f..6f5f39e60cb 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animate_motion_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_animate_motion_element.cc @@ -39,7 +39,7 @@ namespace { bool TargetCanHaveMotionTransform(const SVGElement& target) { // We don't have a special attribute name to verify the animation type. Check // the element name instead. - if (!target.IsSVGGraphicsElement()) + if (!IsA<SVGGraphicsElement>(target)) return false; // Spec: SVG 1.1 section 19.2.15 // FIXME: svgTag is missing. Needs to be checked, if transforming <svg> could diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_angle.cc b/chromium/third_party/blink/renderer/core/svg/svg_animated_angle.cc index fbff94c5b50..e1044af8017 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_angle.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_angle.cc @@ -47,7 +47,7 @@ SVGAnimatedAngle::SVGAnimatedAngle(SVGElement* context_element) SVGAnimatedAngle::~SVGAnimatedAngle() = default; -void SVGAnimatedAngle::Trace(blink::Visitor* visitor) { +void SVGAnimatedAngle::Trace(Visitor* visitor) { visitor->Trace(orient_type_); SVGAnimatedProperty<SVGAngle>::Trace(visitor); ScriptWrappable::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_angle.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_angle.h index ae5b0bdd051..4702d1e66b8 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_angle.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_angle.h @@ -58,7 +58,7 @@ class SVGAnimatedAngle final : public ScriptWrappable, void SetAnimatedValue(SVGPropertyBase*) override; void AnimationEnded() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: Member<SVGAnimatedEnumeration<SVGMarkerOrientType>> orient_type_; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_boolean.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_boolean.h index f657aaa0e28..1a1d4bd3619 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_boolean.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_boolean.h @@ -50,7 +50,7 @@ class SVGAnimatedBoolean final : public ScriptWrappable, attribute_name, MakeGarbageCollected<SVGBoolean>()) {} - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { SVGAnimatedProperty<SVGBoolean>::Trace(visitor); ScriptWrappable::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_color.cc b/chromium/third_party/blink/renderer/core/svg/svg_animated_color.cc index 3386504b0c9..355977b9ff7 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_color.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_color.cc @@ -60,7 +60,7 @@ void SVGColorProperty::Add(SVGPropertyBase* other, Color fallback_color = FallbackColorForCurrentColor(context_element); Color from_color = - ToSVGColorProperty(other)->style_color_.Resolve(fallback_color); + To<SVGColorProperty>(other)->style_color_.Resolve(fallback_color); Color to_color = style_color_.Resolve(fallback_color); style_color_ = StyleColor(ColorDistance::AddColors(from_color, to_color)); } @@ -73,10 +73,10 @@ void SVGColorProperty::CalculateAnimatedValue( SVGPropertyBase* to_value, SVGPropertyBase* to_at_end_of_duration_value, SVGElement* context_element) { - StyleColor from_style_color = ToSVGColorProperty(from_value)->style_color_; - StyleColor to_style_color = ToSVGColorProperty(to_value)->style_color_; + StyleColor from_style_color = To<SVGColorProperty>(from_value)->style_color_; + StyleColor to_style_color = To<SVGColorProperty>(to_value)->style_color_; StyleColor to_at_end_of_duration_style_color = - ToSVGColorProperty(to_at_end_of_duration_value)->style_color_; + To<SVGColorProperty>(to_at_end_of_duration_value)->style_color_; // Apply currentColor rules. DCHECK(context_element); @@ -119,7 +119,7 @@ float SVGColorProperty::CalculateDistance(SVGPropertyBase* to_value, Color from_color = style_color_.Resolve(fallback_color); Color to_color = - ToSVGColorProperty(to_value)->style_color_.Resolve(fallback_color); + To<SVGColorProperty>(to_value)->style_color_.Resolve(fallback_color); return ColorDistance::Distance(from_color, to_color); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_color.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_color.h index 4a277f7c014..18ea4d13162 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_color.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_color.h @@ -33,6 +33,7 @@ #include "third_party/blink/renderer/core/css/style_color.h" #include "third_party/blink/renderer/core/svg/properties/svg_property.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -63,7 +64,12 @@ class SVGColorProperty final : public SVGPropertyBase { StyleColor style_color_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGColorProperty); +template <> +struct DowncastTraits<SVGColorProperty> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGColorProperty::ClassType(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_enumeration_base.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_enumeration_base.h index 99e99ffb5b0..6ed348fb8a5 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_enumeration_base.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_enumeration_base.h @@ -48,7 +48,7 @@ class SVGAnimatedEnumerationBase void setBaseVal(uint16_t, ExceptionState&); - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { SVGAnimatedProperty<SVGEnumerationBase>::Trace(visitor); ScriptWrappable::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_href.cc b/chromium/third_party/blink/renderer/core/svg/svg_animated_href.cc index dbe66f415b2..9d0bce7ecb3 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_href.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_href.cc @@ -14,7 +14,7 @@ namespace blink { -void SVGAnimatedHref::Trace(blink::Visitor* visitor) { +void SVGAnimatedHref::Trace(Visitor* visitor) { visitor->Trace(xlink_href_); SVGAnimatedString::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_href.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_href.h index 77bb26bb19a..807f6145b48 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_href.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_href.h @@ -35,7 +35,7 @@ class SVGAnimatedHref final : public SVGAnimatedString { static bool IsKnownAttribute(const QualifiedName&); void AddToPropertyMap(SVGElement*); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: SVGAnimatedString* BackingString(); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_integer.cc b/chromium/third_party/blink/renderer/core/svg/svg_animated_integer.cc index 1b311097ddb..14c630b5ada 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_integer.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_integer.cc @@ -43,7 +43,7 @@ void SVGAnimatedInteger::SynchronizeAttribute() { SVGAnimatedProperty<SVGInteger>::SynchronizeAttribute(); } -void SVGAnimatedInteger::Trace(blink::Visitor* visitor) { +void SVGAnimatedInteger::Trace(Visitor* visitor) { visitor->Trace(parent_integer_optional_integer_); SVGAnimatedProperty<SVGInteger>::Trace(visitor); ScriptWrappable::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_integer.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_integer.h index 0f35ecc2bb1..ce95e61066c 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_integer.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_integer.h @@ -72,7 +72,7 @@ class SVGAnimatedInteger : public ScriptWrappable, parent_integer_optional_integer_ = number_optional_integer; } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: Member<SVGAnimatedIntegerOptionalInteger> parent_integer_optional_integer_; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_integer_optional_integer.cc b/chromium/third_party/blink/renderer/core/svg/svg_animated_integer_optional_integer.cc index 47a129e46fe..4e13a4a7be1 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_integer_optional_integer.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_integer_optional_integer.cc @@ -58,7 +58,7 @@ SVGAnimatedIntegerOptionalInteger::SVGAnimatedIntegerOptionalInteger( second_integer_->SetParentOptionalInteger(this); } -void SVGAnimatedIntegerOptionalInteger::Trace(blink::Visitor* visitor) { +void SVGAnimatedIntegerOptionalInteger::Trace(Visitor* visitor) { visitor->Trace(first_integer_); visitor->Trace(second_integer_); SVGAnimatedPropertyCommon<SVGIntegerOptionalInteger>::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_integer_optional_integer.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_integer_optional_integer.h index c637a4f1a08..2378c5ded90 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_integer_optional_integer.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_integer_optional_integer.h @@ -60,7 +60,7 @@ class SVGAnimatedIntegerOptionalInteger SVGAnimatedInteger* FirstInteger() { return first_integer_.Get(); } SVGAnimatedInteger* SecondInteger() { return second_integer_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: Member<SVGAnimatedInteger> first_integer_; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_length.cc b/chromium/third_party/blink/renderer/core/svg/svg_animated_length.cc index 72f7c264bda..bb89af577ec 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_length.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_length.cc @@ -50,7 +50,7 @@ SVGParsingError SVGAnimatedLength::AttributeChanged(const String& value) { return parse_status; } -void SVGAnimatedLength::Trace(blink::Visitor* visitor) { +void SVGAnimatedLength::Trace(Visitor* visitor) { SVGAnimatedProperty<SVGLength>::Trace(visitor); ScriptWrappable::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_length.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_length.h index 2c134fe3f2a..f2fb5351fc6 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_length.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_length.h @@ -62,7 +62,7 @@ class SVGAnimatedLength : public ScriptWrappable, return CurrentValue()->AsCSSPrimitiveValue(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_length_list.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_length_list.h index 56960d00991..e65babb3577 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_length_list.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_length_list.h @@ -52,7 +52,7 @@ class SVGAnimatedLengthList final : public ScriptWrappable, attribute_name, initial_value) {} - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { SVGAnimatedProperty<SVGLengthList>::Trace(visitor); ScriptWrappable::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_number.cc b/chromium/third_party/blink/renderer/core/svg/svg_animated_number.cc index 04abbd92fbb..5224f2b880e 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_number.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_number.cc @@ -43,7 +43,7 @@ void SVGAnimatedNumber::SynchronizeAttribute() { SVGAnimatedProperty<SVGNumber>::SynchronizeAttribute(); } -void SVGAnimatedNumber::Trace(blink::Visitor* visitor) { +void SVGAnimatedNumber::Trace(Visitor* visitor) { visitor->Trace(parent_number_optional_number_); SVGAnimatedProperty<SVGNumber>::Trace(visitor); ScriptWrappable::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_number.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_number.h index 6ac22951d51..1f31b2675a4 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_number.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_number.h @@ -73,7 +73,7 @@ class SVGAnimatedNumber : public ScriptWrappable, parent_number_optional_number_ = number_optional_number; } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: Member<SVGAnimatedNumberOptionalNumber> parent_number_optional_number_; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_number_list.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_number_list.h index 64c96c1b146..ed78b7a454f 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_number_list.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_number_list.h @@ -53,7 +53,7 @@ class SVGAnimatedNumberList final : public ScriptWrappable, attribute_name, MakeGarbageCollected<SVGNumberList>()) {} - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { SVGAnimatedProperty<SVGNumberList>::Trace(visitor); ScriptWrappable::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_number_optional_number.cc b/chromium/third_party/blink/renderer/core/svg/svg_animated_number_optional_number.cc index 3a465f15698..4f05129af86 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_number_optional_number.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_number_optional_number.cc @@ -46,7 +46,7 @@ SVGAnimatedNumberOptionalNumber::SVGAnimatedNumberOptionalNumber( second_number_->SetParentOptionalNumber(this); } -void SVGAnimatedNumberOptionalNumber::Trace(blink::Visitor* visitor) { +void SVGAnimatedNumberOptionalNumber::Trace(Visitor* visitor) { visitor->Trace(first_number_); visitor->Trace(second_number_); SVGAnimatedPropertyCommon<SVGNumberOptionalNumber>::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_number_optional_number.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_number_optional_number.h index dc7a84f099f..a8b0d462136 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_number_optional_number.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_number_optional_number.h @@ -60,7 +60,7 @@ class SVGAnimatedNumberOptionalNumber SVGAnimatedNumber* FirstNumber() { return first_number_.Get(); } SVGAnimatedNumber* SecondNumber() { return second_number_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: Member<SVGAnimatedNumber> first_number_; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_preserve_aspect_ratio.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_preserve_aspect_ratio.h index 99ef12fe3d8..b9643d84d78 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_preserve_aspect_ratio.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_preserve_aspect_ratio.h @@ -52,7 +52,7 @@ class SVGAnimatedPreserveAspectRatio attribute_name, MakeGarbageCollected<SVGPreserveAspectRatio>()) {} - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { SVGAnimatedProperty<SVGPreserveAspectRatio>::Trace(visitor); ScriptWrappable::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_rect.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_rect.h index e23c08021e9..da6dffd7fd6 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_rect.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_rect.h @@ -49,7 +49,7 @@ class SVGAnimatedRect : public ScriptWrappable, attribute_name, SVGRect::CreateInvalid()) {} - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { SVGAnimatedProperty<SVGRect>::Trace(visitor); ScriptWrappable::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_string.cc b/chromium/third_party/blink/renderer/core/svg/svg_animated_string.cc index 8804faf0356..649221ed5a7 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_string.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_string.cc @@ -19,7 +19,7 @@ String SVGAnimatedString::animVal() { return SVGAnimatedProperty<SVGString>::animVal(); } -void SVGAnimatedString::Trace(blink::Visitor* visitor) { +void SVGAnimatedString::Trace(Visitor* visitor) { SVGAnimatedProperty<SVGString>::Trace(visitor); ScriptWrappable::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_string.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_string.h index cf8f5e489fa..971ef0b4d9c 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_string.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_string.h @@ -54,7 +54,7 @@ class SVGAnimatedString : public ScriptWrappable, virtual void setBaseVal(const String&, ExceptionState&); virtual String animVal(); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_animated_transform_list.h b/chromium/third_party/blink/renderer/core/svg/svg_animated_transform_list.h index c5cad77f618..5e413bd8ff3 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_animated_transform_list.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_animated_transform_list.h @@ -56,7 +56,7 @@ class SVGAnimatedTransformList final MakeGarbageCollected<SVGTransformList>(), css_property_id) {} - void Trace(blink::Visitor* visitor) override { + void Trace(Visitor* visitor) override { SVGAnimatedProperty<SVGTransformList>::Trace(visitor); ScriptWrappable::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_boolean.h b/chromium/third_party/blink/renderer/core/svg/svg_boolean.h index f463bc03402..62858b532c2 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_boolean.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_boolean.h @@ -69,8 +69,6 @@ class SVGBoolean final : public SVGPropertyHelper<SVGBoolean> { bool value_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGBoolean); - } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_BOOLEAN_H_ diff --git a/chromium/third_party/blink/renderer/core/svg/svg_circle_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_circle_element.cc index 56a34701086..6ec31ddde90 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_circle_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_circle_element.cc @@ -51,7 +51,7 @@ SVGCircleElement::SVGCircleElement(Document& document) AddToPropertyMap(r_); } -void SVGCircleElement::Trace(blink::Visitor* visitor) { +void SVGCircleElement::Trace(Visitor* visitor) { visitor->Trace(cx_); visitor->Trace(cy_); visitor->Trace(r_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_circle_element.h b/chromium/third_party/blink/renderer/core/svg/svg_circle_element.h index fcc8e535427..56ef0c7bab8 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_circle_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_circle_element.h @@ -39,7 +39,7 @@ class SVGCircleElement final : public SVGGeometryElement { SVGAnimatedLength* cy() const { return cy_.Get(); } SVGAnimatedLength* r() const { return r_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_clip_path_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_clip_path_element.cc index 676b342ead2..c48dd93af9a 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_clip_path_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_clip_path_element.cc @@ -36,7 +36,7 @@ SVGClipPathElement::SVGClipPathElement(Document& document) AddToPropertyMap(clip_path_units_); } -void SVGClipPathElement::Trace(blink::Visitor* visitor) { +void SVGClipPathElement::Trace(Visitor* visitor) { visitor->Trace(clip_path_units_); SVGGraphicsElement::Trace(visitor); } @@ -58,7 +58,7 @@ void SVGClipPathElement::SvgAttributeChanged(const QualifiedName& attr_name) { void SVGClipPathElement::ChildrenChanged(const ChildrenChange& change) { SVGGraphicsElement::ChildrenChanged(change); - if (change.by_parser) + if (change.ByParser()) return; if (LayoutObject* object = GetLayoutObject()) { diff --git a/chromium/third_party/blink/renderer/core/svg/svg_clip_path_element.h b/chromium/third_party/blink/renderer/core/svg/svg_clip_path_element.h index ed32c00bd32..66fb5ba08c4 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_clip_path_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_clip_path_element.h @@ -42,7 +42,7 @@ class SVGClipPathElement final : public SVGGraphicsElement { bool SupportsFocus() const override { return false; } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_component_transfer_function_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_component_transfer_function_element.cc index a1d66a35b3a..c4148a8c1e1 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_component_transfer_function_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_component_transfer_function_element.cc @@ -79,7 +79,7 @@ SVGComponentTransferFunctionElement::SVGComponentTransferFunctionElement( AddToPropertyMap(type_); } -void SVGComponentTransferFunctionElement::Trace(blink::Visitor* visitor) { +void SVGComponentTransferFunctionElement::Trace(Visitor* visitor) { visitor->Trace(table_values_); visitor->Trace(slope_); visitor->Trace(intercept_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_component_transfer_function_element.h b/chromium/third_party/blink/renderer/core/svg/svg_component_transfer_function_element.h index 1d1eeb8162e..bb8c936f776 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_component_transfer_function_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_component_transfer_function_element.h @@ -46,7 +46,7 @@ class SVGComponentTransferFunctionElement : public SVGElement { SVGAnimatedNumber* offset() { return offset_.Get(); } SVGAnimatedEnumeration<ComponentTransferType>* type() { return type_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: SVGComponentTransferFunctionElement(const QualifiedName&, Document&); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_discard_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_discard_element.cc deleted file mode 100644 index f729bdf37b2..00000000000 --- a/chromium/third_party/blink/renderer/core/svg/svg_discard_element.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2014 Samsung Electronics. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "third_party/blink/renderer/core/svg/svg_discard_element.h" - -#include "third_party/blink/renderer/core/dom/document.h" -#include "third_party/blink/renderer/core/frame/web_feature.h" -#include "third_party/blink/renderer/core/svg_names.h" - -namespace blink { - -SVGDiscardElement::SVGDiscardElement(Document& document) - : SVGSMILElement(svg_names::kDiscardTag, document) { - UseCounter::Count(&GetDocument(), WebFeature::kSVGSMILDiscardElementParsed); -} - -void SVGDiscardElement::StartedActiveInterval() { - SVGSMILElement::StartedActiveInterval(); - QueueDiscard(); -} - -} // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_discard_element.h b/chromium/third_party/blink/renderer/core/svg/svg_discard_element.h deleted file mode 100644 index 8c9867f8d1a..00000000000 --- a/chromium/third_party/blink/renderer/core/svg/svg_discard_element.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2014 Samsung Electronics. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_DISCARD_ELEMENT_H_ -#define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_DISCARD_ELEMENT_H_ - -#include "third_party/blink/renderer/core/svg/animation/svg_smil_element.h" - -namespace blink { - -class SVGDiscardElement final : public SVGSMILElement { - DEFINE_WRAPPERTYPEINFO(); - - public: - explicit SVGDiscardElement(Document&); - - bool IsSVGDiscardElement() const override { return true; } - - private: - void StartedActiveInterval() override; -}; - -} // namespace blink - -#endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_DISCARD_ELEMENT_H_ diff --git a/chromium/third_party/blink/renderer/core/svg/svg_discard_element.idl b/chromium/third_party/blink/renderer/core/svg/svg_discard_element.idl deleted file mode 100644 index be85d164920..00000000000 --- a/chromium/third_party/blink/renderer/core/svg/svg_discard_element.idl +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2014 Samsung Electronics. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// https://svgwg.org/specs/animations/#InterfaceSVGDiscardElement - -interface SVGDiscardElement : SVGElement { -}; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_document_extensions.cc b/chromium/third_party/blink/renderer/core/svg/svg_document_extensions.cc index ebd83a85d12..28834f7ccdd 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_document_extensions.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_document_extensions.cc @@ -162,7 +162,7 @@ SVGSVGElement* SVGDocumentExtensions::rootElement() const { return rootElement(*document_); } -void SVGDocumentExtensions::Trace(blink::Visitor* visitor) { +void SVGDocumentExtensions::Trace(Visitor* visitor) { visitor->Trace(document_); visitor->Trace(time_containers_); visitor->Trace(web_animations_pending_svg_elements_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_document_extensions.h b/chromium/third_party/blink/renderer/core/svg/svg_document_extensions.h index abce5e913f8..cf22eaa6011 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_document_extensions.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_document_extensions.h @@ -22,6 +22,7 @@ #define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_DOCUMENT_EXTENSIONS_H_ #include "base/macros.h" +#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/layout/svg/svg_resources_cache.h" #include "third_party/blink/renderer/platform/geometry/float_point.h" #include "third_party/blink/renderer/platform/heap/handle.h" @@ -35,7 +36,7 @@ class SVGElement; class SVGSVGElement; class SubtreeLayoutScope; -class SVGDocumentExtensions final +class CORE_EXPORT SVGDocumentExtensions final : public GarbageCollected<SVGDocumentExtensions> { public: explicit SVGDocumentExtensions(Document*); @@ -70,7 +71,7 @@ class SVGDocumentExtensions final static SVGSVGElement* rootElement(const Document&); SVGSVGElement* rootElement() const; - void Trace(blink::Visitor*); + void Trace(Visitor*); private: Member<Document> document_; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_element.cc index 899109d37d5..71de49ebb40 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_element.cc @@ -38,6 +38,7 @@ #include "third_party/blink/renderer/core/css/resolver/style_resolver.h" #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/element_traversal.h" +#include "third_party/blink/renderer/core/dom/events/add_event_listener_options_resolved.h" #include "third_party/blink/renderer/core/dom/events/event.h" #include "third_party/blink/renderer/core/dom/flat_tree_traversal.h" #include "third_party/blink/renderer/core/dom/node_computed_style.h" @@ -88,13 +89,6 @@ void SVGElement::DetachLayoutTree(bool performing_reattach) { SvgRareData()->ClearOverriddenComputedStyle(); } -TreeScope& SVGElement::TreeScopeForIdResolution() const { - const SVGElement* tree_scope_element = this; - if (const SVGElement* element = CorrespondingUseElement()) - tree_scope_element = element; - return tree_scope_element->GetTreeScope(); -} - void SVGElement::WillRecalcStyle(const StyleRecalcChange change) { if (!HasSVGRareData()) return; @@ -145,10 +139,10 @@ void SVGElement::ReportAttributeParsingError(SVGParsingError error, // Don't report any errors on attribute removal. if (value.IsNull()) return; - GetDocument().AddConsoleMessage( - ConsoleMessage::Create(mojom::ConsoleMessageSource::kRendering, - mojom::ConsoleMessageLevel::kError, - "Error: " + error.Format(tagName(), name, value))); + GetDocument().AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kRendering, + mojom::ConsoleMessageLevel::kError, + "Error: " + error.Format(tagName(), name, value))); } String SVGElement::title() const { @@ -186,7 +180,7 @@ void SVGElement::SetInstanceUpdatesBlocked(bool value) { void SVGElement::SetWebAnimationsPending() { GetDocument().AccessSVGExtensions().AddWebAnimationsPendingSVGElement(*this); EnsureSVGRareData()->SetWebAnimatedAttributesDirty(true); - EnsureUniqueElementData().animated_svg_attributes_are_dirty_ = true; + EnsureUniqueElementData().SetAnimatedSvgAttributesAreDirty(true); } static bool IsSVGAttributeHandle(const PropertyHandle& property_handle) { @@ -302,28 +296,23 @@ AffineTransform SVGElement::CalculateTransform( Node::InsertionNotificationRequest SVGElement::InsertedInto( ContainerNode& root_parent) { Element::InsertedInto(root_parent); + HideNonce(); UpdateRelativeLengthsInformation(); - - const AtomicString& nonce_value = FastGetAttribute(html_names::kNonceAttr); - if (!nonce_value.IsEmpty()) { - setNonce(nonce_value); - if (InActiveDocument() && - GetDocument().GetContentSecurityPolicy()->HasHeaderDeliveredPolicy()) { - setAttribute(html_names::kNonceAttr, g_empty_atom); - } - } return kInsertionDone; } void SVGElement::RemovedFrom(ContainerNode& root_parent) { bool was_in_document = root_parent.isConnected(); - auto* root_parent_svg_element = DynamicTo<SVGElement>(root_parent); + auto* root_parent_svg_element = DynamicTo<SVGElement>( + root_parent.IsShadowRoot() ? root_parent.ParentOrShadowHostElement() + : &root_parent); + if (was_in_document && HasRelativeLengths()) { // The root of the subtree being removed should take itself out from its // parent's relative length set. For the other nodes in the subtree we don't // need to do anything: they will get their own removedFrom() notification // and just clear their sets. - if (root_parent_svg_element && !parentNode()) { + if (root_parent_svg_element && !ParentOrShadowHostElement()) { DCHECK(root_parent_svg_element->elements_with_relative_lengths_.Contains( this)); root_parent_svg_element->UpdateRelativeLengthsInformation(false, this); @@ -332,13 +321,15 @@ void SVGElement::RemovedFrom(ContainerNode& root_parent) { elements_with_relative_lengths_.clear(); } - SECURITY_DCHECK( + DCHECK( !root_parent_svg_element || !root_parent_svg_element->elements_with_relative_lengths_.Contains(this)); Element::RemovedFrom(root_parent); if (was_in_document) { + if (HasSVGRareData() && SvgRareData()->CorrespondingElement()) + SvgRareData()->CorrespondingElement()->RemoveInstanceMapping(this); RebuildAllIncomingReferences(); RemoveAllIncomingReferences(); } @@ -354,6 +345,7 @@ void SVGElement::ChildrenChanged(const ChildrenChange& change) { } CSSPropertyID SVGElement::CssPropertyIdForSVGAttributeName( + const ExecutionContext* execution_context, const QualifiedName& attr_name) { if (!attr_name.NamespaceURI().IsNull()) return CSSPropertyID::kInvalid; @@ -424,7 +416,8 @@ CSSPropertyID SVGElement::CssPropertyIdForSVGAttributeName( &svg_names::kWritingModeAttr, }; for (size_t i = 0; i < base::size(attr_names); i++) { - CSSPropertyID property_id = cssPropertyID(attr_names[i]->LocalName()); + CSSPropertyID property_id = + cssPropertyID(execution_context, attr_names[i]->LocalName()); DCHECK_GT(property_id, CSSPropertyID::kInvalid); property_name_to_id_map->Set(attr_names[i]->LocalName().Impl(), property_id); @@ -446,8 +439,9 @@ void SVGElement::UpdateRelativeLengthsInformation( // disconnected. // If we're not yet in a document, this function will be called again from // insertedInto(). Do nothing now. - for (Node& current_node : NodeTraversal::InclusiveAncestorsOf(*this)) { - if (!current_node.isConnected()) + for (Node* current_node = this; current_node; + current_node = current_node->ParentOrShadowHostNode()) { + if (!current_node->isConnected()) return; } @@ -455,10 +449,12 @@ void SVGElement::UpdateRelativeLengthsInformation( // Register it in the relative length map, and register us in the parent // relative length map. Register the parent in the grandparents map, etc. // Repeat procedure until the root of the SVG tree. - for (Node& current_node : NodeTraversal::InclusiveAncestorsOf(*this)) { + for (Element* current_node = this; current_node; + current_node = current_node->ParentOrShadowHostElement()) { auto* current_element = DynamicTo<SVGElement>(current_node); if (!current_element) break; + #if DCHECK_IS_ON() DCHECK(!current_element->in_relative_length_clients_invalidation_); #endif @@ -558,10 +554,8 @@ void SVGElement::MapInstanceToElement(SVGElement* instance) { void SVGElement::RemoveInstanceMapping(SVGElement* instance) { DCHECK(instance); - DCHECK(instance->InUseShadowTree()); - - if (!HasSVGRareData()) - return; + // Called during instance->RemovedFrom() after removal from shadow tree + DCHECK(!instance->isConnected()); HeapHashSet<WeakMember<SVGElement>>& instances = SvgRareData()->ElementInstances(); @@ -589,7 +583,7 @@ SVGElement* SVGElement::CorrespondingElement() const { return HasSVGRareData() ? SvgRareData()->CorrespondingElement() : nullptr; } -SVGUseElement* SVGElement::CorrespondingUseElement() const { +SVGUseElement* SVGElement::GeneratingUseElement() const { if (ShadowRoot* root = ContainingShadowRoot()) { return DynamicTo<SVGUseElement>(root->host()); } @@ -601,7 +595,7 @@ void SVGElement::SetCorrespondingElement(SVGElement* corresponding_element) { } bool SVGElement::InUseShadowTree() const { - return CorrespondingUseElement(); + return GeneratingUseElement(); } void SVGElement::ParseAttribute(const AttributeModificationParams& params) { @@ -618,6 +612,12 @@ void SVGElement::ParseAttribute(const AttributeModificationParams& params) { return; } + // SVGElement and HTMLElement are handling "nonce" the same way. + if (params.name == html_names::kNonceAttr) { + if (params.new_value != g_empty_atom) + setNonce(params.new_value); + } + const AtomicString& event_name = HTMLElement::EventNameForAttributeName(params.name); if (!event_name.IsNull()) { @@ -735,14 +735,16 @@ bool SVGElement::IsAnimatableCSSProperty(const QualifiedName& attr_name) { bool SVGElement::IsPresentationAttribute(const QualifiedName& name) const { if (const SVGAnimatedPropertyBase* property = PropertyFromAttribute(name)) return property->HasPresentationAttributeMapping(); - return CssPropertyIdForSVGAttributeName(name) > CSSPropertyID::kInvalid; + return CssPropertyIdForSVGAttributeName(GetDocument().ToExecutionContext(), + name) > CSSPropertyID::kInvalid; } void SVGElement::CollectStyleForPresentationAttribute( const QualifiedName& name, const AtomicString& value, MutableCSSPropertyValueSet* style) { - CSSPropertyID property_id = CssPropertyIdForSVGAttributeName(name); + CSSPropertyID property_id = CssPropertyIdForSVGAttributeName( + GetDocument().ToExecutionContext(), name); if (property_id > CSSPropertyID::kInvalid) AddPropertyToPresentationAttributeStyle(style, property_id, value); } @@ -875,8 +877,8 @@ void SVGElement::AttributeChanged(const AttributeModificationParams& params) { } void SVGElement::SvgAttributeChanged(const QualifiedName& attr_name) { - CSSPropertyID prop_id = - SVGElement::CssPropertyIdForSVGAttributeName(attr_name); + CSSPropertyID prop_id = SVGElement::CssPropertyIdForSVGAttributeName( + GetDocument().ToExecutionContext(), attr_name); if (prop_id > CSSPropertyID::kInvalid) { InvalidateInstances(); return; @@ -898,7 +900,7 @@ void SVGElement::SvgAttributeBaseValChanged(const QualifiedName& attribute) { // TODO(alancutter): Only mark attributes as dirty if their animation depends // on the underlying value. SvgRareData()->SetWebAnimatedAttributesDirty(true); - GetElementData()->animated_svg_attributes_are_dirty_ = true; + GetElementData()->SetAnimatedSvgAttributesAreDirty(true); } void SVGElement::EnsureAttributeAnimValUpdated() { @@ -907,8 +909,8 @@ void SVGElement::EnsureAttributeAnimValUpdated() { if ((HasSVGRareData() && SvgRareData()->WebAnimatedAttributesDirty()) || (GetElementAnimations() && - DocumentAnimations::NeedsAnimationTimingUpdate(GetDocument()))) { - DocumentAnimations::UpdateAnimationTimingIfNeeded(GetDocument()); + GetDocument().GetDocumentAnimations().NeedsAnimationTimingUpdate())) { + GetDocument().GetDocumentAnimations().UpdateAnimationTimingIfNeeded(); ApplyActiveWebAnimations(); } } @@ -916,7 +918,7 @@ void SVGElement::EnsureAttributeAnimValUpdated() { void SVGElement::SynchronizeAnimatedSVGAttribute( const QualifiedName& name) const { if (!GetElementData() || - !GetElementData()->animated_svg_attributes_are_dirty_) + !GetElementData()->animated_svg_attributes_are_dirty()) return; // We const_cast here because we have deferred baseVal mutation animation @@ -933,7 +935,7 @@ void SVGElement::SynchronizeAnimatedSVGAttribute( (*it)->SynchronizeAttribute(); } - GetElementData()->animated_svg_attributes_are_dirty_ = false; + GetElementData()->SetAnimatedSvgAttributesAreDirty(false); } else { SVGAnimatedPropertyBase* property = attribute_to_property_map_.at(name); if (property && property->NeedsSynchronizeAttribute()) @@ -1015,9 +1017,9 @@ void SVGElement::InvalidateInstances() { for (SVGElement* instance : set) { instance->SetCorrespondingElement(nullptr); - if (SVGUseElement* element = instance->CorrespondingUseElement()) { - if (element->isConnected()) - element->InvalidateShadowTree(); + if (SVGUseElement* element = instance->GeneratingUseElement()) { + DCHECK(element->isConnected()); + element->InvalidateShadowTree(); } } @@ -1218,17 +1220,17 @@ void SVGElement::RemoveAllOutgoingReferences() { outgoing_references.clear(); } -SVGResourceClient* SVGElement::GetSVGResourceClient() { +SVGElementResourceClient* SVGElement::GetSVGResourceClient() { if (!HasSVGRareData()) return nullptr; return SvgRareData()->GetSVGResourceClient(); } -SVGResourceClient& SVGElement::EnsureSVGResourceClient() { +SVGElementResourceClient& SVGElement::EnsureSVGResourceClient() { return EnsureSVGRareData()->EnsureSVGResourceClient(this); } -void SVGElement::Trace(blink::Visitor* visitor) { +void SVGElement::Trace(Visitor* visitor) { visitor->Trace(elements_with_relative_lengths_); visitor->Trace(attribute_to_property_map_); visitor->Trace(svg_rare_data_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_element.h b/chromium/third_party/blink/renderer/core/svg/svg_element.h index fd280a1383b..c11a50ffb0d 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_element.h @@ -38,13 +38,14 @@ namespace blink { class AffineTransform; class Document; class ElementSMILAnimations; +class ExecutionContext; class SVGAnimatedPropertyBase; class SubtreeLayoutScope; class SVGAnimatedString; class SVGElement; class SVGElementRareData; +class SVGElementResourceClient; class SVGPropertyBase; -class SVGResourceClient; class SVGSVGElement; class SVGUseElement; @@ -58,10 +59,6 @@ class CORE_EXPORT SVGElement : public Element { bool SupportsFocus() const override { return false; } - // The TreeScope this element should resolve id's against. This differs from - // the regular Node::treeScope() by taking <use> into account. - TreeScope& TreeScopeForIdResolution() const; - bool IsOutermostSVGSVGElement() const; bool HasTagName(const SVGQualifiedName& name) const { @@ -135,10 +132,10 @@ class CORE_EXPORT SVGElement : public Element { virtual AffineTransform* AnimateMotionTransform() { return nullptr; } void InvalidateSVGAttributes() { - EnsureUniqueElementData().animated_svg_attributes_are_dirty_ = true; + EnsureUniqueElementData().SetAnimatedSvgAttributesAreDirty(true); } void InvalidateSVGPresentationAttributeStyle() { - EnsureUniqueElementData().presentation_attribute_style_is_dirty_ = true; + EnsureUniqueElementData().SetPresentationAttributeStyleIsDirty(true); } const HeapHashSet<WeakMember<SVGElement>>& InstancesForElement() const; @@ -147,7 +144,7 @@ class CORE_EXPORT SVGElement : public Element { SVGElement* CorrespondingElement() const; void SetCorrespondingElement(SVGElement*); - SVGUseElement* CorrespondingUseElement() const; + SVGUseElement* GeneratingUseElement() const; void SynchronizeAnimatedSVGAttribute(const QualifiedName&) const; @@ -179,8 +176,8 @@ class CORE_EXPORT SVGElement : public Element { void RemoveAllIncomingReferences(); void RemoveAllOutgoingReferences(); - SVGResourceClient* GetSVGResourceClient(); - SVGResourceClient& EnsureSVGResourceClient(); + SVGElementResourceClient* GetSVGResourceClient(); + SVGElementResourceClient& EnsureSVGResourceClient(); class InvalidationGuard { STACK_ALLOCATED(); @@ -190,7 +187,7 @@ class CORE_EXPORT SVGElement : public Element { ~InvalidationGuard() { element_->InvalidateInstances(); } private: - Member<SVGElement> element_; + SVGElement* element_; DISALLOW_COPY_AND_ASSIGN(InvalidationGuard); }; @@ -202,7 +199,7 @@ class CORE_EXPORT SVGElement : public Element { ~InstanceUpdateBlocker(); private: - Member<SVGElement> target_element_; + SVGElement* target_element_; DISALLOW_COPY_AND_ASSIGN(InstanceUpdateBlocker); }; @@ -210,7 +207,7 @@ class CORE_EXPORT SVGElement : public Element { void SetNeedsStyleRecalcForInstances(StyleChangeType, const StyleChangeReasonForTracing&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; static const AtomicString& EventParameterName(); @@ -237,7 +234,8 @@ class CORE_EXPORT SVGElement : public Element { void DetachLayoutTree(bool performing_reattach) override; - static CSSPropertyID CssPropertyIdForSVGAttributeName(const QualifiedName&); + static CSSPropertyID CssPropertyIdForSVGAttributeName(const ExecutionContext*, + const QualifiedName&); void UpdateRelativeLengthsInformation() { UpdateRelativeLengthsInformation(SelfHasRelativeLengths(), this); } @@ -334,49 +332,25 @@ struct SVGAttributeHashTranslator { } }; -DEFINE_ELEMENT_TYPE_CASTS(SVGElement, IsSVGElement()); - -template <> -struct DowncastTraits<SVGElement> { - static bool AllowFrom(const Node& node) { return node.IsSVGElement(); } -}; - template <typename T> bool IsElementOfType(const SVGElement&); template <> inline bool IsElementOfType<const SVGElement>(const SVGElement&) { return true; } - +template <> +inline bool IsElementOfType<const SVGElement>(const Node& node) { + return IsA<SVGElement>(node); +} +template <> +struct DowncastTraits<SVGElement> { + static bool AllowFrom(const Node& node) { return node.IsSVGElement(); } +}; inline bool Node::HasTagName(const SVGQualifiedName& name) const { auto* svg_element = DynamicTo<SVGElement>(this); return svg_element && svg_element->HasTagName(name); } -// This requires IsSVG*Element(const SVGElement&). -#define DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \ - inline bool Is##thisType(const thisType* element); \ - inline bool Is##thisType(const thisType& element); \ - inline bool Is##thisType(const SVGElement* element) { \ - return element && Is##thisType(*element); \ - } \ - inline bool Is##thisType(const Node& node) { \ - auto* svg_element = DynamicTo<SVGElement>(node); \ - return svg_element && Is##thisType(svg_element); \ - } \ - inline bool Is##thisType(const Node* node) { \ - return node && Is##thisType(*node); \ - } \ - template <typename T> \ - inline bool Is##thisType(const Member<T>& node) { \ - return Is##thisType(node.Get()); \ - } \ - template <> \ - inline bool IsElementOfType<const thisType>(const SVGElement& element) { \ - return Is##thisType(element); \ - } \ - DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) - } // namespace blink #include "third_party/blink/renderer/core/svg_element_type_helpers.h" diff --git a/chromium/third_party/blink/renderer/core/svg/svg_element_rare_data.cc b/chromium/third_party/blink/renderer/core/svg/svg_element_rare_data.cc index 6232b3291b3..7e01c8db53f 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_element_rare_data.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_element_rare_data.cc @@ -50,14 +50,14 @@ void SVGElementRareData::ClearOverriddenComputedStyle() { override_computed_style_ = nullptr; } -SVGResourceClient& SVGElementRareData::EnsureSVGResourceClient( +SVGElementResourceClient& SVGElementRareData::EnsureSVGResourceClient( SVGElement* element) { if (!resource_client_) resource_client_ = MakeGarbageCollected<SVGElementResourceClient>(element); return *resource_client_; } -void SVGElementRareData::Trace(blink::Visitor* visitor) { +void SVGElementRareData::Trace(Visitor* visitor) { visitor->Trace(outgoing_references_); visitor->Trace(incoming_references_); visitor->Trace(animated_smil_style_properties_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_element_rare_data.h b/chromium/third_party/blink/renderer/core/svg/svg_element_rare_data.h index 79a801d5289..f68e1069979 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_element_rare_data.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_element_rare_data.h @@ -30,7 +30,7 @@ namespace blink { class ElementSMILAnimations; -class SVGResourceClient; +class SVGElementResourceClient; class SVGElementRareData final : public GarbageCollected<SVGElementRareData> { public: @@ -99,19 +99,19 @@ class SVGElementRareData final : public GarbageCollected<SVGElementRareData> { needs_override_computed_style_update_ = true; } - SVGResourceClient* GetSVGResourceClient() { return resource_client_; } - SVGResourceClient& EnsureSVGResourceClient(SVGElement*); + SVGElementResourceClient* GetSVGResourceClient() { return resource_client_; } + SVGElementResourceClient& EnsureSVGResourceClient(SVGElement*); AffineTransform* AnimateMotionTransform(); - void Trace(blink::Visitor*); + void Trace(Visitor*); private: SVGElementSet outgoing_references_; SVGElementSet incoming_references_; HeapHashSet<WeakMember<SVGElement>> element_instances_; Member<SVGElement> corresponding_element_; - Member<SVGResourceClient> resource_client_; + Member<SVGElementResourceClient> resource_client_; Member<ElementSMILAnimations> smil_animations_; bool instances_updates_blocked_ : 1; bool use_override_computed_style_ : 1; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_ellipse_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_ellipse_element.cc index a677606e52e..83220afa1a5 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_ellipse_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_ellipse_element.cc @@ -58,7 +58,7 @@ SVGEllipseElement::SVGEllipseElement(Document& document) AddToPropertyMap(ry_); } -void SVGEllipseElement::Trace(blink::Visitor* visitor) { +void SVGEllipseElement::Trace(Visitor* visitor) { visitor->Trace(cx_); visitor->Trace(cy_); visitor->Trace(rx_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_ellipse_element.h b/chromium/third_party/blink/renderer/core/svg/svg_ellipse_element.h index 82546aef9b9..7ba0af3f1db 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_ellipse_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_ellipse_element.h @@ -40,7 +40,7 @@ class SVGEllipseElement final : public SVGGeometryElement { SVGAnimatedLength* rx() const { return rx_.Get(); } SVGAnimatedLength* ry() const { return ry_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void CollectStyleForPresentationAttribute( diff --git a/chromium/third_party/blink/renderer/core/svg/svg_enumeration.cc b/chromium/third_party/blink/renderer/core/svg/svg_enumeration.cc index 6bb6c45c39e..3a7a398bf39 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_enumeration.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_enumeration.cc @@ -34,8 +34,6 @@ namespace blink { -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGEnumerationBase); - SVGEnumerationBase::~SVGEnumerationBase() = default; SVGPropertyBase* SVGEnumerationBase::CloneForAnimation( diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_blend_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_blend_element.cc index f54e33a9ead..996a30cc855 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_blend_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_blend_element.cc @@ -94,7 +94,7 @@ SVGFEBlendElement::SVGFEBlendElement(Document& document) AddToPropertyMap(mode_); } -void SVGFEBlendElement::Trace(blink::Visitor* visitor) { +void SVGFEBlendElement::Trace(Visitor* visitor) { visitor->Trace(in1_); visitor->Trace(in2_); visitor->Trace(mode_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_blend_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_blend_element.h index 04f23d4b581..4fd2ea96ca0 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_blend_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_blend_element.h @@ -57,7 +57,7 @@ class SVGFEBlendElement final : public SVGFilterPrimitiveStandardAttributes { SVGAnimatedString* in2() { return in2_.Get(); } SVGAnimatedEnumeration<Mode>* mode() { return mode_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: bool SetFilterEffectAttribute(FilterEffect*, diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_color_matrix_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_color_matrix_element.cc index 7f330c52c83..0a4651ec757 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_color_matrix_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_color_matrix_element.cc @@ -55,7 +55,7 @@ SVGFEColorMatrixElement::SVGFEColorMatrixElement(Document& document) AddToPropertyMap(type_); } -void SVGFEColorMatrixElement::Trace(blink::Visitor* visitor) { +void SVGFEColorMatrixElement::Trace(Visitor* visitor) { visitor->Trace(values_); visitor->Trace(in1_); visitor->Trace(type_); @@ -100,9 +100,8 @@ FilterEffect* SVGFEColorMatrixElement::Build(SVGFilterBuilder* filter_builder, DCHECK(input1); ColorMatrixType filter_type = type_->CurrentValue()->EnumValue(); - Vector<float> filter_values = values_->CurrentValue()->ToFloatVector(); - auto* effect = - MakeGarbageCollected<FEColorMatrix>(filter, filter_type, filter_values); + auto* effect = MakeGarbageCollected<FEColorMatrix>( + filter, filter_type, values_->CurrentValue()->ToFloatVector()); effect->InputEffects().push_back(input1); return effect; } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_color_matrix_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_color_matrix_element.h index 4485776b8e3..aedf2140077 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_color_matrix_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_color_matrix_element.h @@ -42,7 +42,7 @@ class SVGFEColorMatrixElement final SVGAnimatedString* in1() { return in1_.Get(); } SVGAnimatedEnumeration<ColorMatrixType>* type() { return type_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: bool SetFilterEffectAttribute(FilterEffect*, const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_component_transfer_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_component_transfer_element.cc index 484d848481d..1464024dc7c 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_component_transfer_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_component_transfer_element.cc @@ -39,7 +39,7 @@ SVGFEComponentTransferElement::SVGFEComponentTransferElement(Document& document) AddToPropertyMap(in1_); } -void SVGFEComponentTransferElement::Trace(blink::Visitor* visitor) { +void SVGFEComponentTransferElement::Trace(Visitor* visitor) { visitor->Trace(in1_); SVGFilterPrimitiveStandardAttributes::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_component_transfer_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_component_transfer_element.h index bde46e74aa6..2c2f3ed758c 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_component_transfer_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_component_transfer_element.h @@ -35,7 +35,7 @@ class SVGFEComponentTransferElement final SVGAnimatedString* in1() { return in1_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_composite_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_composite_element.cc index f5111a66c41..0613666c59d 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_composite_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_composite_element.cc @@ -74,7 +74,7 @@ SVGFECompositeElement::SVGFECompositeElement(Document& document) AddToPropertyMap(svg_operator_); } -void SVGFECompositeElement::Trace(blink::Visitor* visitor) { +void SVGFECompositeElement::Trace(Visitor* visitor) { visitor->Trace(k1_); visitor->Trace(k2_); visitor->Trace(k3_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_composite_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_composite_element.h index e00672c92a3..63cac0f631b 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_composite_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_composite_element.h @@ -48,7 +48,7 @@ class SVGFECompositeElement final return svg_operator_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: bool SetFilterEffectAttribute(FilterEffect*, const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_convolve_matrix_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_convolve_matrix_element.cc index c1037941375..d37f9815c99 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_convolve_matrix_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_convolve_matrix_element.cc @@ -116,7 +116,7 @@ SVGFEConvolveMatrixElement::SVGFEConvolveMatrixElement(Document& document) AddToPropertyMap(target_y_); } -void SVGFEConvolveMatrixElement::Trace(blink::Visitor* visitor) { +void SVGFEConvolveMatrixElement::Trace(Visitor* visitor) { visitor->Trace(bias_); visitor->Trace(divisor_); visitor->Trace(in1_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_convolve_matrix_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_convolve_matrix_element.h index 8653b5d5c35..c5916541436 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_convolve_matrix_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_convolve_matrix_element.h @@ -59,7 +59,7 @@ class SVGFEConvolveMatrixElement final SVGAnimatedInteger* targetX() { return target_x_.Get(); } SVGAnimatedInteger* targetY() { return target_y_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: IntSize MatrixOrder() const; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_diffuse_lighting_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_diffuse_lighting_element.cc index 40ef837d9c2..58e58653468 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_diffuse_lighting_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_diffuse_lighting_element.cc @@ -50,7 +50,7 @@ SVGFEDiffuseLightingElement::SVGFEDiffuseLightingElement(Document& document) AddToPropertyMap(in1_); } -void SVGFEDiffuseLightingElement::Trace(blink::Visitor* visitor) { +void SVGFEDiffuseLightingElement::Trace(Visitor* visitor) { visitor->Trace(diffuse_constant_); visitor->Trace(surface_scale_); visitor->Trace(kernel_unit_length_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_diffuse_lighting_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_diffuse_lighting_element.h index 840cbaf862c..d93cf6520e8 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_diffuse_lighting_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_diffuse_lighting_element.h @@ -49,7 +49,7 @@ class SVGFEDiffuseLightingElement final } SVGAnimatedString* in1() { return in1_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: bool SetFilterEffectAttribute(FilterEffect*, const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_displacement_map_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_displacement_map_element.cc index 429abf4d94a..bfd5b1e2997 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_displacement_map_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_displacement_map_element.cc @@ -60,7 +60,7 @@ SVGFEDisplacementMapElement::SVGFEDisplacementMapElement(Document& document) AddToPropertyMap(y_channel_selector_); } -void SVGFEDisplacementMapElement::Trace(blink::Visitor* visitor) { +void SVGFEDisplacementMapElement::Trace(Visitor* visitor) { visitor->Trace(scale_); visitor->Trace(in1_); visitor->Trace(in2_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_displacement_map_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_displacement_map_element.h index c29316a6023..0dafd29b177 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_displacement_map_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_displacement_map_element.h @@ -49,7 +49,7 @@ class SVGFEDisplacementMapElement final return y_channel_selector_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: bool SetFilterEffectAttribute(FilterEffect*, diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_drop_shadow_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_drop_shadow_element.cc index abe97601a32..7cced8f4409 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_drop_shadow_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_drop_shadow_element.cc @@ -45,7 +45,7 @@ SVGFEDropShadowElement::SVGFEDropShadowElement(Document& document) AddToPropertyMap(in1_); } -void SVGFEDropShadowElement::Trace(blink::Visitor* visitor) { +void SVGFEDropShadowElement::Trace(Visitor* visitor) { visitor->Trace(dx_); visitor->Trace(dy_); visitor->Trace(std_deviation_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_drop_shadow_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_drop_shadow_element.h index 8607927519a..ce229e782b2 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_drop_shadow_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_drop_shadow_element.h @@ -42,7 +42,7 @@ class SVGFEDropShadowElement final SVGAnimatedNumber* stdDeviationY() { return std_deviation_->SecondNumber(); } SVGAnimatedString* in1() { return in1_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_gaussian_blur_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_gaussian_blur_element.cc index a7d0e0571cd..51933a73a5f 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_gaussian_blur_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_gaussian_blur_element.cc @@ -39,7 +39,7 @@ SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(Document& document) AddToPropertyMap(in1_); } -void SVGFEGaussianBlurElement::Trace(blink::Visitor* visitor) { +void SVGFEGaussianBlurElement::Trace(Visitor* visitor) { visitor->Trace(std_deviation_); visitor->Trace(in1_); SVGFilterPrimitiveStandardAttributes::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_gaussian_blur_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_gaussian_blur_element.h index 3096ffcf616..9dc19929d39 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_gaussian_blur_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_gaussian_blur_element.h @@ -40,7 +40,7 @@ class SVGFEGaussianBlurElement final SVGAnimatedNumber* stdDeviationY() { return std_deviation_->SecondNumber(); } SVGAnimatedString* in1() { return in1_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_image_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_image_element.cc index 3668936a8eb..e56a87a6e2f 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_image_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_image_element.cc @@ -51,7 +51,7 @@ void SVGFEImageElement::Dispose() { ClearImageResource(); } -void SVGFEImageElement::Trace(blink::Visitor* visitor) { +void SVGFEImageElement::Trace(Visitor* visitor) { visitor->Trace(preserve_aspect_ratio_); visitor->Trace(cached_image_); visitor->Trace(target_id_observer_); @@ -158,8 +158,9 @@ FilterEffect* SVGFEImageElement::Build(SVGFilterBuilder*, Filter* filter) { return MakeGarbageCollected<FEImage>( filter, image, preserve_aspect_ratio_->CurrentValue()); } - - return MakeGarbageCollected<FEImage>(filter, GetTreeScope(), HrefString(), + const SVGElement* target = DynamicTo<SVGElement>( + TargetElementFromIRIString(HrefString(), GetTreeScope())); + return MakeGarbageCollected<FEImage>(filter, target, preserve_aspect_ratio_->CurrentValue()); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_image_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_image_element.h index 9d38de5e87e..ce245c2c170 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_image_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_image_element.h @@ -50,7 +50,7 @@ class SVGFEImageElement final : public SVGFilterPrimitiveStandardAttributes, void Dispose(); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_light_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_light_element.cc index 32407fb7b3e..80aa829c848 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_light_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_light_element.cc @@ -81,7 +81,7 @@ SVGFELightElement::SVGFELightElement(const QualifiedName& tag_name, AddToPropertyMap(limiting_cone_angle_); } -void SVGFELightElement::Trace(blink::Visitor* visitor) { +void SVGFELightElement::Trace(Visitor* visitor) { visitor->Trace(azimuth_); visitor->Trace(elevation_); visitor->Trace(x_); @@ -127,7 +127,7 @@ void SVGFELightElement::SvgAttributeChanged(const QualifiedName& attr_name) { return; LayoutObject* layout_object = parent->GetLayoutObject(); - if (!layout_object || !layout_object->IsSVGResourceFilterPrimitive()) + if (!layout_object || !layout_object->IsSVGFilterPrimitive()) return; SVGElement::InvalidationGuard invalidation_guard(this); @@ -145,10 +145,10 @@ void SVGFELightElement::SvgAttributeChanged(const QualifiedName& attr_name) { void SVGFELightElement::ChildrenChanged(const ChildrenChange& change) { SVGElement::ChildrenChanged(change); - if (!change.by_parser) { + if (!change.ByParser()) { if (ContainerNode* parent = parentNode()) { LayoutObject* layout_object = parent->GetLayoutObject(); - if (layout_object && layout_object->IsSVGResourceFilterPrimitive()) + if (layout_object && layout_object->IsSVGFilterPrimitive()) MarkForLayoutAndParentResourceInvalidation(*layout_object); } } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_light_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_light_element.h index aad4aad8f38..d416833aa04 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_light_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_light_element.h @@ -65,7 +65,7 @@ class SVGFELightElement : public SVGElement { return limiting_cone_angle_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: SVGFELightElement(const QualifiedName&, Document&); @@ -90,13 +90,22 @@ class SVGFELightElement : public SVGElement { Member<SVGAnimatedNumber> limiting_cone_angle_; }; -inline bool IsSVGFELightElement(const SVGElement& element) { - return element.HasTagName(svg_names::kFEDistantLightTag) || - element.HasTagName(svg_names::kFEPointLightTag) || - element.HasTagName(svg_names::kFESpotLightTag); +template <> +inline bool IsElementOfType<const SVGFELightElement>(const Node& node) { + return IsA<SVGFELightElement>(node); } - -DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGFELightElement); +template <> +struct DowncastTraits<SVGFELightElement> { + static bool AllowFrom(const Node& node) { + auto* svg_element = DynamicTo<SVGElement>(node); + return svg_element && AllowFrom(*svg_element); + } + static bool AllowFrom(const SVGElement& svg_element) { + return svg_element.HasTagName(svg_names::kFEDistantLightTag) || + svg_element.HasTagName(svg_names::kFEPointLightTag) || + svg_element.HasTagName(svg_names::kFESpotLightTag); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_merge_node_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_merge_node_element.cc index c1c49c5ede1..6df184e02c3 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_merge_node_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_merge_node_element.cc @@ -31,7 +31,7 @@ SVGFEMergeNodeElement::SVGFEMergeNodeElement(Document& document) AddToPropertyMap(in1_); } -void SVGFEMergeNodeElement::Trace(blink::Visitor* visitor) { +void SVGFEMergeNodeElement::Trace(Visitor* visitor) { visitor->Trace(in1_); SVGElement::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_merge_node_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_merge_node_element.h index 0a6ebe120be..c6491784fb4 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_merge_node_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_merge_node_element.h @@ -35,7 +35,7 @@ class SVGFEMergeNodeElement final : public SVGElement { SVGAnimatedString* in1() { return in1_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_morphology_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_morphology_element.cc index b833298ff83..5ee79e507d3 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_morphology_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_morphology_element.cc @@ -54,7 +54,7 @@ SVGFEMorphologyElement::SVGFEMorphologyElement(Document& document) AddToPropertyMap(svg_operator_); } -void SVGFEMorphologyElement::Trace(blink::Visitor* visitor) { +void SVGFEMorphologyElement::Trace(Visitor* visitor) { visitor->Trace(radius_); visitor->Trace(in1_); visitor->Trace(svg_operator_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_morphology_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_morphology_element.h index 198840c3450..80ab5105480 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_morphology_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_morphology_element.h @@ -44,7 +44,7 @@ class SVGFEMorphologyElement final return svg_operator_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: bool SetFilterEffectAttribute(FilterEffect*, const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_offset_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_offset_element.cc index 17df70ad967..b08be255166 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_offset_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_offset_element.cc @@ -41,7 +41,7 @@ SVGFEOffsetElement::SVGFEOffsetElement(Document& document) AddToPropertyMap(in1_); } -void SVGFEOffsetElement::Trace(blink::Visitor* visitor) { +void SVGFEOffsetElement::Trace(Visitor* visitor) { visitor->Trace(dx_); visitor->Trace(dy_); visitor->Trace(in1_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_offset_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_offset_element.h index 4fd07aaa4b4..908adbda57e 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_offset_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_offset_element.h @@ -37,7 +37,7 @@ class SVGFEOffsetElement final : public SVGFilterPrimitiveStandardAttributes { SVGAnimatedNumber* dy() { return dy_.Get(); } SVGAnimatedString* in1() { return in1_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_specular_lighting_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_specular_lighting_element.cc index d334feb951c..e857938b3fb 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_specular_lighting_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_specular_lighting_element.cc @@ -57,7 +57,7 @@ SVGFESpecularLightingElement::SVGFESpecularLightingElement(Document& document) AddToPropertyMap(in1_); } -void SVGFESpecularLightingElement::Trace(blink::Visitor* visitor) { +void SVGFESpecularLightingElement::Trace(Visitor* visitor) { visitor->Trace(specular_constant_); visitor->Trace(specular_exponent_); visitor->Trace(surface_scale_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_specular_lighting_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_specular_lighting_element.h index e653aca0f5e..64d75d05b10 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_specular_lighting_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_specular_lighting_element.h @@ -51,7 +51,7 @@ class SVGFESpecularLightingElement final } SVGAnimatedString* in1() { return in1_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: bool SetFilterEffectAttribute(FilterEffect*, const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_tile_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_tile_element.cc index bb89fb4853b..220b8e03787 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_tile_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_tile_element.cc @@ -33,7 +33,7 @@ SVGFETileElement::SVGFETileElement(Document& document) AddToPropertyMap(in1_); } -void SVGFETileElement::Trace(blink::Visitor* visitor) { +void SVGFETileElement::Trace(Visitor* visitor) { visitor->Trace(in1_); SVGFilterPrimitiveStandardAttributes::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_tile_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_tile_element.h index c2583c33367..b22f758db17 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_tile_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_tile_element.h @@ -34,7 +34,7 @@ class SVGFETileElement final : public SVGFilterPrimitiveStandardAttributes { SVGAnimatedString* in1() { return in1_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_turbulence_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_fe_turbulence_element.cc index 704eb3a68f2..1136c829f3f 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_turbulence_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_turbulence_element.cc @@ -75,7 +75,7 @@ SVGFETurbulenceElement::SVGFETurbulenceElement(Document& document) AddToPropertyMap(num_octaves_); } -void SVGFETurbulenceElement::Trace(blink::Visitor* visitor) { +void SVGFETurbulenceElement::Trace(Visitor* visitor) { visitor->Trace(base_frequency_); visitor->Trace(seed_); visitor->Trace(stitch_tiles_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fe_turbulence_element.h b/chromium/third_party/blink/renderer/core/svg/svg_fe_turbulence_element.h index d3a6e6094eb..39c953c95cd 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fe_turbulence_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fe_turbulence_element.h @@ -58,7 +58,7 @@ class SVGFETurbulenceElement final SVGAnimatedEnumeration<TurbulenceType>* type() { return type_.Get(); } SVGAnimatedInteger* numOctaves() { return num_octaves_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; // Turbulence takes no inputs and doesn't taint origin, so we can always // return false. diff --git a/chromium/third_party/blink/renderer/core/svg/svg_filter_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_filter_element.cc index bf723f0fb77..510b134064c 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_filter_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_filter_element.cc @@ -77,7 +77,7 @@ SVGFilterElement::SVGFilterElement(Document& document) SVGFilterElement::~SVGFilterElement() = default; -void SVGFilterElement::Trace(blink::Visitor* visitor) { +void SVGFilterElement::Trace(Visitor* visitor) { visitor->Trace(x_); visitor->Trace(y_); visitor->Trace(width_); @@ -113,18 +113,12 @@ LocalSVGResource* SVGFilterElement::AssociatedResource() const { void SVGFilterElement::PrimitiveAttributeChanged( SVGFilterPrimitiveStandardAttributes& primitive, const QualifiedName& attribute) { - if (LayoutObject* layout_object = GetLayoutObject()) { - ToLayoutSVGResourceFilter(layout_object) - ->PrimitiveAttributeChanged(primitive, attribute); - } else if (LocalSVGResource* resource = AssociatedResource()) { - resource->NotifyContentChanged(SVGResourceClient::kPaintInvalidation); - } + if (LocalSVGResource* resource = AssociatedResource()) + resource->NotifyFilterPrimitiveChanged(primitive, attribute); } void SVGFilterElement::InvalidateFilterChain() { - if (LayoutObject* layout_object = GetLayoutObject()) { - ToLayoutSVGResourceFilter(layout_object)->RemoveAllClientsFromCache(); - } else if (LocalSVGResource* resource = AssociatedResource()) { + if (LocalSVGResource* resource = AssociatedResource()) { resource->NotifyContentChanged(SVGResourceClient::kLayoutInvalidation | SVGResourceClient::kBoundariesInvalidation); } @@ -133,7 +127,7 @@ void SVGFilterElement::InvalidateFilterChain() { void SVGFilterElement::ChildrenChanged(const ChildrenChange& change) { SVGElement::ChildrenChanged(change); - if (change.by_parser) + if (change.ByParser()) return; if (LayoutObject* object = GetLayoutObject()) { diff --git a/chromium/third_party/blink/renderer/core/svg/svg_filter_element.h b/chromium/third_party/blink/renderer/core/svg/svg_filter_element.h index 02c1c251f3d..39d2c615efb 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_filter_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_filter_element.h @@ -42,7 +42,7 @@ class CORE_EXPORT SVGFilterElement final : public SVGElement, USING_GARBAGE_COLLECTED_MIXIN(SVGFilterElement); public: - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; explicit SVGFilterElement(Document&); ~SVGFilterElement() override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_filter_primitive_standard_attributes.cc b/chromium/third_party/blink/renderer/core/svg/svg_filter_primitive_standard_attributes.cc index a45e80ac4ca..5654af88baf 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_filter_primitive_standard_attributes.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_filter_primitive_standard_attributes.cc @@ -21,7 +21,7 @@ #include "third_party/blink/renderer/core/svg/svg_filter_primitive_standard_attributes.h" -#include "third_party/blink/renderer/core/layout/svg/layout_svg_resource_filter_primitive.h" +#include "third_party/blink/renderer/core/layout/svg/layout_svg_filter_primitive.h" #include "third_party/blink/renderer/core/svg/graphics/filters/svg_filter_builder.h" #include "third_party/blink/renderer/core/svg/svg_filter_element.h" #include "third_party/blink/renderer/core/svg/svg_length.h" @@ -69,7 +69,7 @@ SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes( AddToPropertyMap(result_); } -void SVGFilterPrimitiveStandardAttributes::Trace(blink::Visitor* visitor) { +void SVGFilterPrimitiveStandardAttributes::Trace(Visitor* visitor) { visitor->Trace(x_); visitor->Trace(y_); visitor->Trace(width_); @@ -111,7 +111,7 @@ void SVGFilterPrimitiveStandardAttributes::ChildrenChanged( const ChildrenChange& change) { SVGElement::ChildrenChanged(change); - if (!change.by_parser) + if (!change.ByParser()) Invalidate(); } @@ -167,7 +167,7 @@ void SVGFilterPrimitiveStandardAttributes::SetStandardAttributes( LayoutObject* SVGFilterPrimitiveStandardAttributes::CreateLayoutObject( const ComputedStyle&, LegacyLayout) { - return new LayoutSVGResourceFilterPrimitive(this); + return new LayoutSVGFilterPrimitive(this); } bool SVGFilterPrimitiveStandardAttributes::LayoutObjectIsNeeded( diff --git a/chromium/third_party/blink/renderer/core/svg/svg_filter_primitive_standard_attributes.h b/chromium/third_party/blink/renderer/core/svg/svg_filter_primitive_standard_attributes.h index b0271c5fe3b..50aba21ab89 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_filter_primitive_standard_attributes.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_filter_primitive_standard_attributes.h @@ -55,7 +55,7 @@ class SVGFilterPrimitiveStandardAttributes : public SVGElement { SVGAnimatedLength* height() const { return height_.Get(); } SVGAnimatedString* result() const { return result_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; void PrimitiveAttributeChanged(const QualifiedName&); void Invalidate(); @@ -81,15 +81,11 @@ class SVGFilterPrimitiveStandardAttributes : public SVGElement { void InvalidateFilterPrimitiveParent(SVGElement&); -inline bool IsSVGFilterPrimitiveStandardAttributes(const SVGElement& element) { - return element.IsFilterEffect(); -} - template <> struct DowncastTraits<SVGFilterPrimitiveStandardAttributes> { static bool AllowFrom(const Node& node) { auto* element = DynamicTo<SVGElement>(node); - return element && IsSVGFilterPrimitiveStandardAttributes(*element); + return element && element->IsFilterEffect(); } }; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fit_to_view_box.cc b/chromium/third_party/blink/renderer/core/svg/svg_fit_to_view_box.cc index 5c76ecdbf11..2284b380fae 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fit_to_view_box.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_fit_to_view_box.cc @@ -60,7 +60,7 @@ SVGFitToViewBox::SVGFitToViewBox(SVGElement* element) element->AddToPropertyMap(preserve_aspect_ratio_); } -void SVGFitToViewBox::Trace(blink::Visitor* visitor) { +void SVGFitToViewBox::Trace(Visitor* visitor) { visitor->Trace(view_box_); visitor->Trace(preserve_aspect_ratio_); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_fit_to_view_box.h b/chromium/third_party/blink/renderer/core/svg/svg_fit_to_view_box.h index 58d6af310fa..54d922bee5a 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_fit_to_view_box.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_fit_to_view_box.h @@ -54,7 +54,7 @@ class SVGFitToViewBox : public GarbageCollectedMixin { return preserve_aspect_ratio_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: explicit SVGFitToViewBox(SVGElement*); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element.cc index 676129d2787..e570ca8bc8e 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element.cc @@ -64,7 +64,7 @@ SVGForeignObjectElement::SVGForeignObjectElement(Document& document) UseCounter::Count(document, WebFeature::kSVGForeignObjectElement); } -void SVGForeignObjectElement::Trace(blink::Visitor* visitor) { +void SVGForeignObjectElement::Trace(Visitor* visitor) { visitor->Trace(x_); visitor->Trace(y_); visitor->Trace(width_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element.h b/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element.h index 94edd3e2e9b..b9559036a59 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element.h @@ -37,7 +37,7 @@ class SVGForeignObjectElement final : public SVGGraphicsElement { SVGAnimatedLength* width() const { return width_.Get(); } SVGAnimatedLength* height() const { return height_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void CollectStyleForPresentationAttribute( diff --git a/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element_test.cc b/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element_test.cc index 42d0805ac57..d3b93064f85 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element_test.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element_test.cc @@ -14,7 +14,7 @@ namespace blink { class SVGForeignObjectElementTest : public PageTestBase {}; TEST_F(SVGForeignObjectElementTest, NoLayoutObjectInNonRendered) { - GetDocument().body()->SetInnerHTMLFromString(R"HTML( + GetDocument().body()->setInnerHTML(R"HTML( <svg> <pattern> <foreignObject id="fo"></foreignObject> @@ -34,7 +34,7 @@ TEST_F(SVGForeignObjectElementTest, NoLayoutObjectInNonRendered) { } TEST_F(SVGForeignObjectElementTest, ReferenceForeignObjectInNonRenderedCrash) { - GetDocument().body()->SetInnerHTMLFromString(R"HTML( + GetDocument().body()->setInnerHTML(R"HTML( <style> div { writing-mode: vertical-rl; } div > svg { float: right; } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_geometry_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_geometry_element.cc index 3323dceb48d..78f2dbdb9d6 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_geometry_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_geometry_element.cc @@ -75,13 +75,14 @@ void SVGGeometryElement::SvgAttributeChanged(const QualifiedName& attr_name) { SVGGraphicsElement::SvgAttributeChanged(attr_name); } -void SVGGeometryElement::Trace(blink::Visitor* visitor) { +void SVGGeometryElement::Trace(Visitor* visitor) { visitor->Trace(path_length_); SVGGraphicsElement::Trace(visitor); } bool SVGGeometryElement::isPointInFill(SVGPointTearOff* point) const { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); // FIXME: Eventually we should support isPointInFill for display:none // elements. @@ -95,7 +96,8 @@ bool SVGGeometryElement::isPointInFill(SVGPointTearOff* point) const { } bool SVGGeometryElement::isPointInStroke(SVGPointTearOff* point) const { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); // FIXME: Eventually we should support isPointInStroke for display:none // elements. @@ -132,7 +134,8 @@ Path SVGGeometryElement::ToClipPath() const { } float SVGGeometryElement::getTotalLength(ExceptionState& exception_state) { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); if (!GetLayoutObject()) { exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, @@ -144,7 +147,8 @@ float SVGGeometryElement::getTotalLength(ExceptionState& exception_state) { } SVGPointTearOff* SVGGeometryElement::getPointAtLength(float length) { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); FloatPoint point; if (GetLayoutObject()) { diff --git a/chromium/third_party/blink/renderer/core/svg/svg_geometry_element.h b/chromium/third_party/blink/renderer/core/svg/svg_geometry_element.h index 6688c04c816..c6de7fb18db 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_geometry_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_geometry_element.h @@ -59,7 +59,7 @@ class SVGGeometryElement : public SVGGraphicsElement { static float PathLengthScaleFactor(float computed_path_length, float author_path_length); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: SVGGeometryElement(const QualifiedName&, @@ -79,11 +79,20 @@ class SVGGeometryElement : public SVGGraphicsElement { Member<SVGAnimatedNumber> path_length_; }; -inline bool IsSVGGeometryElement(const SVGElement& element) { - return element.IsSVGGeometryElement(); +template <> +inline bool IsElementOfType<const SVGGeometryElement>(const Node& node) { + return IsA<SVGGeometryElement>(node); } - -DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGGeometryElement); +template <> +struct DowncastTraits<SVGGeometryElement> { + static bool AllowFrom(const Node& node) { + auto* svg_element = DynamicTo<SVGElement>(node); + return svg_element && AllowFrom(*svg_element); + } + static bool AllowFrom(const SVGElement& svg_element) { + return svg_element.IsSVGGeometryElement(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_gradient_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_gradient_element.cc index c05a4394725..749dcbdcbcc 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_gradient_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_gradient_element.cc @@ -67,7 +67,7 @@ SVGGradientElement::SVGGradientElement(const QualifiedName& tag_name, AddToPropertyMap(gradient_units_); } -void SVGGradientElement::Trace(blink::Visitor* visitor) { +void SVGGradientElement::Trace(Visitor* visitor) { visitor->Trace(gradient_transform_); visitor->Trace(spread_method_); visitor->Trace(gradient_units_); @@ -146,10 +146,8 @@ void SVGGradientElement::RemovedFrom(ContainerNode& root_parent) { void SVGGradientElement::ChildrenChanged(const ChildrenChange& change) { SVGElement::ChildrenChanged(change); - if (change.by_parser) - return; - - InvalidateGradient(layout_invalidation_reason::kChildChanged); + if (!change.ByParser()) + InvalidateGradient(layout_invalidation_reason::kChildChanged); } void SVGGradientElement::InvalidateGradient( diff --git a/chromium/third_party/blink/renderer/core/svg/svg_gradient_element.h b/chromium/third_party/blink/renderer/core/svg/svg_gradient_element.h index bd9f7a365b8..4e8cf91995a 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_gradient_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_gradient_element.h @@ -64,7 +64,7 @@ class SVGGradientElement : public SVGElement, public SVGURIReference { const SVGGradientElement* ReferencedElement() const; void CollectCommonAttributes(GradientAttributes&) const; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: SVGGradientElement(const QualifiedName&, Document&); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_graphics_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_graphics_element.cc index 67275151c23..37d3f45a698 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_graphics_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_graphics_element.cc @@ -46,7 +46,7 @@ SVGGraphicsElement::SVGGraphicsElement(const QualifiedName& tag_name, SVGGraphicsElement::~SVGGraphicsElement() = default; -void SVGGraphicsElement::Trace(blink::Visitor* visitor) { +void SVGGraphicsElement::Trace(Visitor* visitor) { visitor->Trace(transform_); SVGElement::Trace(visitor); SVGTests::Trace(visitor); @@ -90,14 +90,16 @@ AffineTransform SVGGraphicsElement::ComputeCTM( } SVGMatrixTearOff* SVGGraphicsElement::getCTM() { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); return MakeGarbageCollected<SVGMatrixTearOff>( ComputeCTM(kNearestViewportScope)); } SVGMatrixTearOff* SVGGraphicsElement::getScreenCTM() { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); return MakeGarbageCollected<SVGMatrixTearOff>(ComputeCTM(kScreenScope)); } @@ -171,7 +173,7 @@ FloatRect SVGGraphicsElement::GetBBox() { } SVGRectTearOff* SVGGraphicsElement::getBBoxFromJavascript() { - GetDocument().UpdateStyleAndLayout(); + GetDocument().UpdateStyleAndLayout(DocumentUpdateReason::kJavaScript); // FIXME: Eventually we should support getBBox for detached elements. FloatRect boundingBox; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_graphics_element.h b/chromium/third_party/blink/renderer/core/svg/svg_graphics_element.h index 2b602085711..5fbcc82e5e2 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_graphics_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_graphics_element.h @@ -64,7 +64,7 @@ class CORE_EXPORT SVGGraphicsElement : public SVGElement, public SVGTests { CTMScope mode, const SVGGraphicsElement* ancestor = nullptr) const; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: SVGGraphicsElement(const QualifiedName&, @@ -87,20 +87,21 @@ class CORE_EXPORT SVGGraphicsElement : public SVGElement, public SVGTests { bool IsSVGGraphicsElement() const final { return true; } }; -inline bool IsSVGGraphicsElement(const SVGElement& element) { - return element.IsSVGGraphicsElement(); +template <> +inline bool IsElementOfType<const SVGGraphicsElement>(const Node& node) { + return IsA<SVGGraphicsElement>(node); } - template <> struct DowncastTraits<SVGGraphicsElement> { static bool AllowFrom(const Node& node) { auto* svg_element = DynamicTo<SVGElement>(node); - return svg_element && IsSVGGraphicsElement(*svg_element); + return svg_element && AllowFrom(*svg_element); + } + static bool AllowFrom(const SVGElement& svg_element) { + return svg_element.IsSVGGraphicsElement(); } }; -DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGGraphicsElement); - } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_GRAPHICS_ELEMENT_H_ diff --git a/chromium/third_party/blink/renderer/core/svg/svg_image_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_image_element.cc index 2cf3d0214b3..4ab1768f3a5 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_image_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_image_element.cc @@ -25,9 +25,7 @@ #include "third_party/blink/renderer/core/css/css_property_names.h" #include "third_party/blink/renderer/core/css/style_change_reason.h" #include "third_party/blink/renderer/core/frame/web_feature.h" -#include "third_party/blink/renderer/core/html/media/media_element_parser_helpers.h" #include "third_party/blink/renderer/core/layout/layout_image_resource.h" -#include "third_party/blink/renderer/core/layout/layout_replaced.h" #include "third_party/blink/renderer/core/layout/svg/layout_svg_image.h" #include "third_party/blink/renderer/core/svg_names.h" #include "third_party/blink/renderer/platform/heap/heap.h" @@ -38,7 +36,8 @@ namespace blink { SVGImageElement::SVGImageElement(Document& document) : SVGGraphicsElement(svg_names::kImageTag, document), SVGURIReference(this), - is_default_overridden_intrinsic_size_(false), + is_default_overridden_intrinsic_size_(!document.IsFeatureEnabled( + mojom::blink::DocumentPolicyFeature::kUnsizedMedia)), x_(MakeGarbageCollected<SVGAnimatedLength>( this, svg_names::kXAttr, @@ -73,16 +72,9 @@ SVGImageElement::SVGImageElement(Document& document) AddToPropertyMap(width_); AddToPropertyMap(height_); AddToPropertyMap(preserve_aspect_ratio_); - - if (media_element_parser_helpers::IsMediaElement(this) && - !document.IsFeatureEnabled(mojom::FeaturePolicyFeature::kUnsizedMedia)) { - is_default_overridden_intrinsic_size_ = true; - overridden_intrinsic_size_ = - IntSize(LayoutReplaced::kDefaultWidth, LayoutReplaced::kDefaultHeight); - } } -void SVGImageElement::Trace(blink::Visitor* visitor) { +void SVGImageElement::Trace(Visitor* visitor) { visitor->Trace(x_); visitor->Trace(y_); visitor->Trace(width_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_image_element.h b/chromium/third_party/blink/renderer/core/svg/svg_image_element.h index 7c7c3ee084d..049e9c7ab63 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_image_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_image_element.h @@ -43,7 +43,7 @@ class CORE_EXPORT SVGImageElement final public: explicit SVGImageElement(Document&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; bool CurrentFrameHasSingleSecurityOrigin() const; @@ -55,10 +55,6 @@ class CORE_EXPORT SVGImageElement final return preserve_aspect_ratio_.Get(); } - IntSize GetOverriddenIntrinsicSize() const { - return overridden_intrinsic_size_; - } - bool HasPendingActivity() const final { return GetImageLoader().HasPendingActivity(); } @@ -104,7 +100,6 @@ class CORE_EXPORT SVGImageElement final void DidMoveToNewDocument(Document& old_document) override; SVGImageLoader& GetImageLoader() const override { return *image_loader_; } - IntSize overridden_intrinsic_size_; bool is_default_overridden_intrinsic_size_; Member<SVGAnimatedLength> x_; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_integer.cc b/chromium/third_party/blink/renderer/core/svg/svg_integer.cc index 68592578b51..d39b494b67c 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_integer.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_integer.cc @@ -59,7 +59,7 @@ SVGParsingError SVGInteger::SetValueAsString(const String& string) { } void SVGInteger::Add(SVGPropertyBase* other, SVGElement*) { - SetValue(value_ + ToSVGInteger(other)->Value()); + SetValue(value_ + To<SVGInteger>(other)->Value()); } void SVGInteger::CalculateAnimatedValue( @@ -70,10 +70,9 @@ void SVGInteger::CalculateAnimatedValue( SVGPropertyBase* to, SVGPropertyBase* to_at_end_of_duration, SVGElement*) { - SVGInteger* from_integer = ToSVGInteger(from); - SVGInteger* to_integer = ToSVGInteger(to); - SVGInteger* to_at_end_of_duration_integer = - ToSVGInteger(to_at_end_of_duration); + auto* from_integer = To<SVGInteger>(from); + auto* to_integer = To<SVGInteger>(to); + auto* to_at_end_of_duration_integer = To<SVGInteger>(to_at_end_of_duration); float animated_float = value_; animation_element.AnimateAdditiveNumber( @@ -83,7 +82,7 @@ void SVGInteger::CalculateAnimatedValue( } float SVGInteger::CalculateDistance(SVGPropertyBase* other, SVGElement*) { - return abs(value_ - ToSVGInteger(other)->Value()); + return abs(value_ - To<SVGInteger>(other)->Value()); } } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_integer.h b/chromium/third_party/blink/renderer/core/svg/svg_integer.h index d1c2ab43402..90924b8d760 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_integer.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_integer.h @@ -33,6 +33,7 @@ #include "third_party/blink/renderer/core/svg/properties/svg_property_helper.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -71,7 +72,12 @@ class SVGInteger final : public SVGPropertyHelper<SVGInteger> { int value_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGInteger); +template <> +struct DowncastTraits<SVGInteger> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGInteger::ClassType(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_integer_optional_integer.cc b/chromium/third_party/blink/renderer/core/svg/svg_integer_optional_integer.cc index 467bcf2c436..2c9a363c780 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_integer_optional_integer.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_integer_optional_integer.cc @@ -39,7 +39,7 @@ SVGIntegerOptionalInteger::SVGIntegerOptionalInteger(SVGInteger* first_integer, SVGInteger* second_integer) : first_integer_(first_integer), second_integer_(second_integer) {} -void SVGIntegerOptionalInteger::Trace(blink::Visitor* visitor) { +void SVGIntegerOptionalInteger::Trace(Visitor* visitor) { visitor->Trace(first_integer_); visitor->Trace(second_integer_); SVGPropertyBase::Trace(visitor); @@ -89,7 +89,7 @@ void SVGIntegerOptionalInteger::SetInitial(unsigned value) { void SVGIntegerOptionalInteger::Add(SVGPropertyBase* other, SVGElement* context_element) { - auto* other_integer_optional_integer = ToSVGIntegerOptionalInteger(other); + auto* other_integer_optional_integer = To<SVGIntegerOptionalInteger>(other); first_integer_->Add(other_integer_optional_integer->FirstInteger(), context_element); second_integer_->Add(other_integer_optional_integer->SecondInteger(), @@ -104,10 +104,10 @@ void SVGIntegerOptionalInteger::CalculateAnimatedValue( SVGPropertyBase* to, SVGPropertyBase* to_at_end_of_duration, SVGElement* context_element) { - auto* from_integer = ToSVGIntegerOptionalInteger(from); - auto* to_integer = ToSVGIntegerOptionalInteger(to); + auto* from_integer = To<SVGIntegerOptionalInteger>(from); + auto* to_integer = To<SVGIntegerOptionalInteger>(to); auto* to_at_end_of_duration_integer = - ToSVGIntegerOptionalInteger(to_at_end_of_duration); + To<SVGIntegerOptionalInteger>(to_at_end_of_duration); first_integer_->CalculateAnimatedValue( animation_element, percentage, repeat_count, from_integer->FirstInteger(), diff --git a/chromium/third_party/blink/renderer/core/svg/svg_integer_optional_integer.h b/chromium/third_party/blink/renderer/core/svg/svg_integer_optional_integer.h index 69b587a82b0..334fef29f01 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_integer_optional_integer.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_integer_optional_integer.h @@ -34,6 +34,7 @@ #include "third_party/blink/renderer/core/svg/svg_integer.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" #include "third_party/blink/renderer/platform/heap/handle.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -73,14 +74,19 @@ class SVGIntegerOptionalInteger final : public SVGPropertyBase { SVGInteger* FirstInteger() const { return first_integer_; } SVGInteger* SecondInteger() const { return second_integer_; } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: Member<SVGInteger> first_integer_; Member<SVGInteger> second_integer_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGIntegerOptionalInteger); +template <> +struct DowncastTraits<SVGIntegerOptionalInteger> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGIntegerOptionalInteger::ClassType(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_length.cc b/chromium/third_party/blink/renderer/core/svg/svg_length.cc index 7533e316fb9..9a0108d1c29 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_length.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_length.cc @@ -88,7 +88,7 @@ SVGLength::SVGLength(const CSSPrimitiveValue& value, SVGLengthMode mode) SVGLength::SVGLength(const SVGLength& o) : value_(o.value_), unit_mode_(o.unit_mode_) {} -void SVGLength::Trace(blink::Visitor* visitor) { +void SVGLength::Trace(Visitor* visitor) { visitor->Trace(value_); SVGPropertyBase::Trace(visitor); } @@ -326,7 +326,7 @@ bool SVGLength::NegativeValuesForbiddenForAnimatedLengthAttribute( void SVGLength::Add(SVGPropertyBase* other, SVGElement* context_element) { SVGLengthContext length_context(context_element); - SetValue(Value(length_context) + ToSVGLength(other)->Value(length_context), + SetValue(Value(length_context) + To<SVGLength>(other)->Value(length_context), length_context); } @@ -338,10 +338,10 @@ void SVGLength::CalculateAnimatedValue( SVGPropertyBase* to_value, SVGPropertyBase* to_at_end_of_duration_value, SVGElement* context_element) { - SVGLength* from_length = ToSVGLength(from_value); - SVGLength* to_length = ToSVGLength(to_value); - SVGLength* to_at_end_of_duration_length = - ToSVGLength(to_at_end_of_duration_value); + auto* from_length = To<SVGLength>(from_value); + auto* to_length = To<SVGLength>(to_value); + auto* to_at_end_of_duration_length = + To<SVGLength>(to_at_end_of_duration_value); SVGLengthContext length_context(context_element); float animated_number = Value(length_context); @@ -374,7 +374,7 @@ void SVGLength::CalculateAnimatedValue( float SVGLength::CalculateDistance(SVGPropertyBase* to_value, SVGElement* context_element) { SVGLengthContext length_context(context_element); - SVGLength* to_length = ToSVGLength(to_value); + auto* to_length = To<SVGLength>(to_value); return fabsf(to_length->Value(length_context) - Value(length_context)); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_length.h b/chromium/third_party/blink/renderer/core/svg/svg_length.h index 3c286d3292c..4b883d10f98 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_length.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_length.h @@ -21,12 +21,14 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_LENGTH_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_LENGTH_H_ +#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/css/css_numeric_literal_value.h" #include "third_party/blink/renderer/core/css/css_primitive_value.h" #include "third_party/blink/renderer/core/svg/properties/svg_property.h" #include "third_party/blink/renderer/core/svg/svg_length_context.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" #include "third_party/blink/renderer/platform/heap/handle.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -34,7 +36,7 @@ class QualifiedName; class SVGLengthTearOff; -class SVGLength final : public SVGPropertyBase { +class CORE_EXPORT SVGLength final : public SVGPropertyBase { public: typedef SVGLengthTearOff TearOffType; @@ -60,7 +62,7 @@ class SVGLength final : public SVGPropertyBase { void SetInitial(unsigned); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; SVGLength* Clone() const; SVGPropertyBase* CloneForAnimation(const String&) const override; @@ -144,7 +146,12 @@ class SVGLength final : public SVGPropertyBase { unsigned unit_mode_ : 2; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGLength); +template <> +struct DowncastTraits<SVGLength> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGLength::ClassType(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_length_context.cc b/chromium/third_party/blink/renderer/core/svg/svg_length_context.cc index c2ea541dfcb..fb59b03afc3 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_length_context.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_length_context.cc @@ -450,7 +450,7 @@ bool SVGLengthContext::DetermineViewport(FloatSize& viewport_size) const { // Root <svg> element lengths are resolved against the top level viewport. if (context_->IsOutermostSVGSVGElement()) { - viewport_size = To<SVGSVGElement>(context_.Get())->CurrentViewportSize(); + viewport_size = To<SVGSVGElement>(context_)->CurrentViewportSize(); return true; } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_length_context.h b/chromium/third_party/blink/renderer/core/svg/svg_length_context.h index ba97426dd50..e98e74dc8ff 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_length_context.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_length_context.h @@ -20,6 +20,7 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_LENGTH_CONTEXT_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_LENGTH_CONTEXT_H_ +#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/css/css_primitive_value.h" #include "third_party/blink/renderer/core/svg/svg_unit_types.h" #include "third_party/blink/renderer/platform/geometry/float_rect.h" @@ -34,7 +35,7 @@ class UnzoomedLength; enum class SVGLengthMode { kWidth, kHeight, kOther }; -class SVGLengthContext { +class CORE_EXPORT SVGLengthContext { STACK_ALLOCATED(); public: @@ -97,7 +98,7 @@ class SVGLengthContext { float ConvertValueFromUserUnitsToCHS(float value) const; float ConvertValueFromCHSToUserUnits(float value) const; - Member<const SVGElement> context_; + const SVGElement* context_; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_length_list.cc b/chromium/third_party/blink/renderer/core/svg/svg_length_list.cc index c6d952c5933..795fac45775 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_length_list.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_length_list.cc @@ -90,7 +90,7 @@ SVGParsingError SVGLengthList::SetValueAsString(const String& value) { } void SVGLengthList::Add(SVGPropertyBase* other, SVGElement* context_element) { - SVGLengthList* other_list = ToSVGLengthList(other); + auto* other_list = To<SVGLengthList>(other); if (length() != other_list->length()) return; @@ -114,10 +114,10 @@ void SVGLengthList::CalculateAnimatedValue( SVGPropertyBase* to_value, SVGPropertyBase* to_at_end_of_duration_value, SVGElement* context_element) { - SVGLengthList* from_list = ToSVGLengthList(from_value); - SVGLengthList* to_list = ToSVGLengthList(to_value); - SVGLengthList* to_at_end_of_duration_list = - ToSVGLengthList(to_at_end_of_duration_value); + auto* from_list = To<SVGLengthList>(from_value); + auto* to_list = To<SVGLengthList>(to_value); + auto* to_at_end_of_duration_list = + To<SVGLengthList>(to_at_end_of_duration_value); SVGLengthContext length_context(context_element); DCHECK_EQ(mode_, SVGLength::LengthModeForAnimatedLengthAttribute( diff --git a/chromium/third_party/blink/renderer/core/svg/svg_length_list.h b/chromium/third_party/blink/renderer/core/svg/svg_length_list.h index 680a373748b..dea9d6740ce 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_length_list.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_length_list.h @@ -34,6 +34,7 @@ #include "third_party/blink/renderer/core/svg/properties/svg_list_property_helper.h" #include "third_party/blink/renderer/core/svg/svg_length.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -79,7 +80,12 @@ class SVGLengthList final SVGLengthMode mode_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGLengthList); +template <> +struct DowncastTraits<SVGLengthList> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGLengthList::ClassType(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_line_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_line_element.cc index 7d3911a280b..988db51b0dc 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_line_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_line_element.cc @@ -54,7 +54,7 @@ SVGLineElement::SVGLineElement(Document& document) AddToPropertyMap(y2_); } -void SVGLineElement::Trace(blink::Visitor* visitor) { +void SVGLineElement::Trace(Visitor* visitor) { visitor->Trace(x1_); visitor->Trace(y1_); visitor->Trace(x2_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_line_element.h b/chromium/third_party/blink/renderer/core/svg/svg_line_element.h index ce6fcf16a6f..04acb82a98f 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_line_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_line_element.h @@ -40,7 +40,7 @@ class SVGLineElement final : public SVGGeometryElement { SVGAnimatedLength* x2() const { return x2_.Get(); } SVGAnimatedLength* y2() const { return y2_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_linear_gradient_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_linear_gradient_element.cc index df26f2e700c..9c0c7072b12 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_linear_gradient_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_linear_gradient_element.cc @@ -62,7 +62,7 @@ SVGLinearGradientElement::SVGLinearGradientElement(Document& document) AddToPropertyMap(y2_); } -void SVGLinearGradientElement::Trace(blink::Visitor* visitor) { +void SVGLinearGradientElement::Trace(Visitor* visitor) { visitor->Trace(x1_); visitor->Trace(y1_); visitor->Trace(x2_); @@ -91,7 +91,6 @@ LayoutObject* SVGLinearGradientElement::CreateLayoutObject(const ComputedStyle&, static void SetGradientAttributes(const SVGGradientElement& element, LinearGradientAttributes& attributes, bool is_linear) { - element.SynchronizeAnimatedSVGAttribute(AnyQName()); element.CollectCommonAttributes(attributes); if (!is_linear) @@ -111,8 +110,8 @@ static void SetGradientAttributes(const SVGGradientElement& element, attributes.SetY2(linear.y2()->CurrentValue()); } -bool SVGLinearGradientElement::CollectGradientAttributes( - LinearGradientAttributes& attributes) { +void SVGLinearGradientElement::CollectGradientAttributes( + LinearGradientAttributes& attributes) const { DCHECK(GetLayoutObject()); VisitedSet visited; @@ -124,12 +123,14 @@ bool SVGLinearGradientElement::CollectGradientAttributes( visited.insert(current); current = current->ReferencedElement(); - if (!current || visited.Contains(current)) + + // Ignore the referenced gradient element if it is not attached. + if (!current || !current->GetLayoutObject()) + break; + // Cycle detection. + if (visited.Contains(current)) break; - if (!current->GetLayoutObject()) - return false; } - return true; } bool SVGLinearGradientElement::SelfHasRelativeLengths() const { diff --git a/chromium/third_party/blink/renderer/core/svg/svg_linear_gradient_element.h b/chromium/third_party/blink/renderer/core/svg/svg_linear_gradient_element.h index 9ba60cc3cec..1b1b218d836 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_linear_gradient_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_linear_gradient_element.h @@ -35,14 +35,14 @@ class SVGLinearGradientElement final : public SVGGradientElement { public: explicit SVGLinearGradientElement(Document&); - bool CollectGradientAttributes(LinearGradientAttributes&); + void CollectGradientAttributes(LinearGradientAttributes&) const; SVGAnimatedLength* x1() const { return x1_.Get(); } SVGAnimatedLength* y1() const { return y1_.Get(); } SVGAnimatedLength* x2() const { return x2_.Get(); } SVGAnimatedLength* y2() const { return y2_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_marker_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_marker_element.cc index 287c2586c99..4920b8ba495 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_marker_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_marker_element.cc @@ -79,7 +79,7 @@ SVGMarkerElement::SVGMarkerElement(Document& document) AddToPropertyMap(marker_units_); } -void SVGMarkerElement::Trace(blink::Visitor* visitor) { +void SVGMarkerElement::Trace(Visitor* visitor) { visitor->Trace(ref_x_); visitor->Trace(ref_y_); visitor->Trace(marker_width_); @@ -129,7 +129,7 @@ void SVGMarkerElement::SvgAttributeChanged(const QualifiedName& attr_name) { void SVGMarkerElement::ChildrenChanged(const ChildrenChange& change) { SVGElement::ChildrenChanged(change); - if (change.by_parser) + if (change.ByParser()) return; if (LayoutObject* object = GetLayoutObject()) { diff --git a/chromium/third_party/blink/renderer/core/svg/svg_marker_element.h b/chromium/third_party/blink/renderer/core/svg/svg_marker_element.h index 316b517b61e..542d5ba1bd5 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_marker_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_marker_element.h @@ -76,7 +76,7 @@ class SVGMarkerElement final : public SVGElement, public SVGFitToViewBox { return orient_angle_->OrientType(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_mask_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_mask_element.cc index e194b0fe21f..db873b16b0e 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_mask_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_mask_element.cc @@ -78,7 +78,7 @@ SVGMaskElement::SVGMaskElement(Document& document) AddToPropertyMap(mask_content_units_); } -void SVGMaskElement::Trace(blink::Visitor* visitor) { +void SVGMaskElement::Trace(Visitor* visitor) { visitor->Trace(x_); visitor->Trace(y_); visitor->Trace(width_); @@ -143,7 +143,7 @@ void SVGMaskElement::SvgAttributeChanged(const QualifiedName& attr_name) { void SVGMaskElement::ChildrenChanged(const ChildrenChange& change) { SVGElement::ChildrenChanged(change); - if (change.by_parser) + if (change.ByParser()) return; if (LayoutObject* object = GetLayoutObject()) { diff --git a/chromium/third_party/blink/renderer/core/svg/svg_mask_element.h b/chromium/third_party/blink/renderer/core/svg/svg_mask_element.h index ebb6a52b3fc..d45cdf20e87 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_mask_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_mask_element.h @@ -47,7 +47,7 @@ class SVGMaskElement final : public SVGElement, public SVGTests { return mask_content_units_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: bool IsValid() const override { return SVGTests::IsValid(); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_matrix_tear_off.cc b/chromium/third_party/blink/renderer/core/svg/svg_matrix_tear_off.cc index 07357ec83a8..e7db4ffa088 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_matrix_tear_off.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_matrix_tear_off.cc @@ -44,7 +44,7 @@ SVGMatrixTearOff::SVGMatrixTearOff(SVGTransformTearOff* transform) DCHECK(transform); } -void SVGMatrixTearOff::Trace(blink::Visitor* visitor) { +void SVGMatrixTearOff::Trace(Visitor* visitor) { visitor->Trace(context_transform_); ScriptWrappable::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_matrix_tear_off.h b/chromium/third_party/blink/renderer/core/svg/svg_matrix_tear_off.h index e36d716323c..3b8bf2fa439 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_matrix_tear_off.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_matrix_tear_off.h @@ -82,7 +82,7 @@ class CORE_EXPORT SVGMatrixTearOff final : public ScriptWrappable { const AffineTransform& Value() const; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: AffineTransform* MutableValue(); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_mpath_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_mpath_element.cc index 1f7f3c502d8..65eb8f47ce1 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_mpath_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_mpath_element.cc @@ -30,7 +30,7 @@ namespace blink { SVGMPathElement::SVGMPathElement(Document& document) : SVGElement(svg_names::kMPathTag, document), SVGURIReference(this) {} -void SVGMPathElement::Trace(blink::Visitor* visitor) { +void SVGMPathElement::Trace(Visitor* visitor) { visitor->Trace(target_id_observer_); SVGElement::Trace(visitor); SVGURIReference::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_mpath_element.h b/chromium/third_party/blink/renderer/core/svg/svg_mpath_element.h index ee6fa88384b..89ed7cca9c5 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_mpath_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_mpath_element.h @@ -39,7 +39,7 @@ class SVGMPathElement final : public SVGElement, public SVGURIReference { void TargetPathChanged(); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void BuildPendingResource() override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_number.cc b/chromium/third_party/blink/renderer/core/svg/svg_number.cc index 438ea1cb5e3..10e6f1a80a4 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_number.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_number.cc @@ -75,7 +75,7 @@ SVGParsingError SVGNumber::SetValueAsString(const String& string) { } void SVGNumber::Add(SVGPropertyBase* other, SVGElement*) { - SetValue(value_ + ToSVGNumber(other)->Value()); + SetValue(value_ + To<SVGNumber>(other)->Value()); } void SVGNumber::CalculateAnimatedValue( @@ -86,9 +86,9 @@ void SVGNumber::CalculateAnimatedValue( SVGPropertyBase* to, SVGPropertyBase* to_at_end_of_duration, SVGElement*) { - SVGNumber* from_number = ToSVGNumber(from); - SVGNumber* to_number = ToSVGNumber(to); - SVGNumber* to_at_end_of_duration_number = ToSVGNumber(to_at_end_of_duration); + auto* from_number = To<SVGNumber>(from); + auto* to_number = To<SVGNumber>(to); + auto* to_at_end_of_duration_number = To<SVGNumber>(to_at_end_of_duration); animation_element.AnimateAdditiveNumber( percentage, repeat_count, from_number->Value(), to_number->Value(), @@ -96,7 +96,7 @@ void SVGNumber::CalculateAnimatedValue( } float SVGNumber::CalculateDistance(SVGPropertyBase* other, SVGElement*) { - return fabsf(value_ - ToSVGNumber(other)->Value()); + return fabsf(value_ - To<SVGNumber>(other)->Value()); } SVGNumber* SVGNumberAcceptPercentage::Clone() const { diff --git a/chromium/third_party/blink/renderer/core/svg/svg_number.h b/chromium/third_party/blink/renderer/core/svg/svg_number.h index ec583810351..d081ee5c42f 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_number.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_number.h @@ -33,6 +33,7 @@ #include "third_party/blink/renderer/core/svg/properties/svg_property_helper.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -77,7 +78,12 @@ class SVGNumber : public SVGPropertyHelper<SVGNumber> { float value_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGNumber); +template <> +struct DowncastTraits<SVGNumber> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGNumber::ClassType(); + } +}; // SVGNumber which also accepts percentage as its value. // This is used for <stop> "offset" diff --git a/chromium/third_party/blink/renderer/core/svg/svg_number_list.cc b/chromium/third_party/blink/renderer/core/svg/svg_number_list.cc index e2002e79e5d..615df5ca93c 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_number_list.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_number_list.cc @@ -69,7 +69,7 @@ SVGParsingError SVGNumberList::SetValueAsString(const String& value) { } void SVGNumberList::Add(SVGPropertyBase* other, SVGElement* context_element) { - SVGNumberList* other_list = ToSVGNumberList(other); + auto* other_list = To<SVGNumberList>(other); if (length() != other_list->length()) return; @@ -86,10 +86,10 @@ void SVGNumberList::CalculateAnimatedValue( SVGPropertyBase* to_value, SVGPropertyBase* to_at_end_of_duration_value, SVGElement* context_element) { - SVGNumberList* from_list = ToSVGNumberList(from_value); - SVGNumberList* to_list = ToSVGNumberList(to_value); - SVGNumberList* to_at_end_of_duration_list = - ToSVGNumberList(to_at_end_of_duration_value); + auto* from_list = To<SVGNumberList>(from_value); + auto* to_list = To<SVGNumberList>(to_value); + auto* to_at_end_of_duration_list = + To<SVGNumberList>(to_at_end_of_duration_value); uint32_t from_list_size = from_list->length(); uint32_t to_list_size = to_list->length(); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_number_list.h b/chromium/third_party/blink/renderer/core/svg/svg_number_list.h index 89eb0affe06..860f379edbe 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_number_list.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_number_list.h @@ -34,6 +34,7 @@ #include "third_party/blink/renderer/core/svg/properties/svg_list_property_helper.h" #include "third_party/blink/renderer/core/svg/svg_number.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -72,7 +73,12 @@ class SVGNumberList final SVGParsingError Parse(const CharType*& ptr, const CharType* end); }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGNumberList); +template <> +struct DowncastTraits<SVGNumberList> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGNumberList::ClassType(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_number_optional_number.cc b/chromium/third_party/blink/renderer/core/svg/svg_number_optional_number.cc index cd154d4c343..a1477bae1c3 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_number_optional_number.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_number_optional_number.cc @@ -39,7 +39,7 @@ SVGNumberOptionalNumber::SVGNumberOptionalNumber(SVGNumber* first_number, SVGNumber* second_number) : first_number_(first_number), second_number_(second_number) {} -void SVGNumberOptionalNumber::Trace(blink::Visitor* visitor) { +void SVGNumberOptionalNumber::Trace(Visitor* visitor) { visitor->Trace(first_number_); visitor->Trace(second_number_); SVGPropertyBase::Trace(visitor); @@ -91,7 +91,7 @@ void SVGNumberOptionalNumber::SetInitial(unsigned value) { void SVGNumberOptionalNumber::Add(SVGPropertyBase* other, SVGElement* context_element) { - auto* other_number_optional_number = ToSVGNumberOptionalNumber(other); + auto* other_number_optional_number = To<SVGNumberOptionalNumber>(other); first_number_->Add(other_number_optional_number->FirstNumber(), context_element); second_number_->Add(other_number_optional_number->SecondNumber(), @@ -106,10 +106,10 @@ void SVGNumberOptionalNumber::CalculateAnimatedValue( SVGPropertyBase* to, SVGPropertyBase* to_at_end_of_duration, SVGElement* context_element) { - auto* from_number = ToSVGNumberOptionalNumber(from); - auto* to_number = ToSVGNumberOptionalNumber(to); + auto* from_number = To<SVGNumberOptionalNumber>(from); + auto* to_number = To<SVGNumberOptionalNumber>(to); auto* to_at_end_of_duration_number = - ToSVGNumberOptionalNumber(to_at_end_of_duration); + To<SVGNumberOptionalNumber>(to_at_end_of_duration); first_number_->CalculateAnimatedValue( animation_element, percentage, repeat_count, from_number->FirstNumber(), diff --git a/chromium/third_party/blink/renderer/core/svg/svg_number_optional_number.h b/chromium/third_party/blink/renderer/core/svg/svg_number_optional_number.h index 06f48ff8d7a..6f5f810cca4 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_number_optional_number.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_number_optional_number.h @@ -34,6 +34,7 @@ #include "third_party/blink/renderer/core/svg/svg_number.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" #include "third_party/blink/renderer/platform/heap/handle.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -72,14 +73,19 @@ class SVGNumberOptionalNumber final : public SVGPropertyBase { SVGNumber* FirstNumber() const { return first_number_; } SVGNumber* SecondNumber() const { return second_number_; } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: Member<SVGNumber> first_number_; Member<SVGNumber> second_number_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGNumberOptionalNumber); +template <> +struct DowncastTraits<SVGNumberOptionalNumber> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGNumberOptionalNumber::ClassType(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_path.cc b/chromium/third_party/blink/renderer/core/svg/svg_path.cc index d13e8ec8c8b..393b6f1d592 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_path.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_path.cc @@ -114,8 +114,7 @@ SVGPropertyBase* SVGPath::CloneForAnimation(const String& value) const { } void SVGPath::Add(SVGPropertyBase* other, SVGElement*) { - const SVGPathByteStream& other_path_byte_stream = - ToSVGPath(other)->ByteStream(); + const auto& other_path_byte_stream = To<SVGPath>(other)->ByteStream(); if (ByteStream().size() != other_path_byte_stream.size() || ByteStream().IsEmpty() || other_path_byte_stream.IsEmpty()) return; @@ -134,14 +133,14 @@ void SVGPath::CalculateAnimatedValue( SVGElement*) { bool is_to_animation = animation_element.GetAnimationMode() == kToAnimation; - const SVGPath& to = ToSVGPath(*to_value); + const auto& to = To<SVGPath>(*to_value); const SVGPathByteStream& to_stream = to.ByteStream(); // If no 'to' value is given, nothing to animate. if (!to_stream.size()) return; - const SVGPath& from = ToSVGPath(*from_value); + const auto& from = To<SVGPath>(*from_value); const SVGPathByteStream* from_stream = &from.ByteStream(); std::unique_ptr<SVGPathByteStream> copy; @@ -178,7 +177,7 @@ void SVGPath::CalculateAnimatedValue( if (repeat_count && animation_element.IsAccumulated()) { new_stream = ConditionallyAddPathByteStreams( std::move(new_stream), - ToSVGPath(to_at_end_of_duration_value)->ByteStream(), repeat_count); + To<SVGPath>(to_at_end_of_duration_value)->ByteStream(), repeat_count); } } path_value_ = MakeGarbageCollected<CSSPathValue>(std::move(new_stream)); @@ -189,7 +188,7 @@ float SVGPath::CalculateDistance(SVGPropertyBase* to, SVGElement*) { return -1; } -void SVGPath::Trace(blink::Visitor* visitor) { +void SVGPath::Trace(Visitor* visitor) { visitor->Trace(path_value_); SVGPropertyBase::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_path.h b/chromium/third_party/blink/renderer/core/svg/svg_path.h index c8351b23db5..b6376e5d1e3 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_path.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_path.h @@ -35,6 +35,7 @@ #include "third_party/blink/renderer/core/svg/properties/svg_property.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" #include "third_party/blink/renderer/core/svg/svg_path_byte_stream.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -71,13 +72,18 @@ class SVGPath final : public SVGPropertyBase { static AnimatedPropertyType ClassType() { return kAnimatedPath; } AnimatedPropertyType GetType() const override { return ClassType(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: Member<cssvalue::CSSPathValue> path_value_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGPath); +template <> +struct DowncastTraits<SVGPath> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGPath::ClassType(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_path_data.h b/chromium/third_party/blink/renderer/core/svg/svg_path_data.h index c58d9fd1610..0167d0824bf 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_path_data.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_path_data.h @@ -62,7 +62,7 @@ static inline bool IsAbsolutePathSegType(const SVGPathSegType type) { } struct PathSegmentData { - STACK_ALLOCATED(); + DISALLOW_NEW(); public: PathSegmentData() diff --git a/chromium/third_party/blink/renderer/core/svg/svg_path_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_path_element.cc index 04f61a23f1c..c57638d1bb9 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_path_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_path_element.cc @@ -37,7 +37,7 @@ SVGPathElement::SVGPathElement(Document& document) AddToPropertyMap(path_); } -void SVGPathElement::Trace(blink::Visitor* visitor) { +void SVGPathElement::Trace(Visitor* visitor) { visitor->Trace(path_); SVGGeometryElement::Trace(visitor); } @@ -65,12 +65,14 @@ Path SVGPathElement::AsPath() const { } float SVGPathElement::getTotalLength(ExceptionState& exception_state) { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); return SVGPathQuery(PathByteStream()).GetTotalLength(); } SVGPointTearOff* SVGPathElement::getPointAtLength(float length) { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); SVGPathQuery path_query(PathByteStream()); if (length < 0) { length = 0; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_path_element.h b/chromium/third_party/blink/renderer/core/svg/svg_path_element.h index 925d99b32b8..2b1540003fd 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_path_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_path_element.h @@ -49,7 +49,7 @@ class SVGPathElement final : public SVGGeometryElement { FloatRect GetBBox() override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: const StylePath* GetStylePath() const; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_path_parser.h b/chromium/third_party/blink/renderer/core/svg/svg_path_parser.h index 32191f188d1..a0a65565e85 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_path_parser.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_path_parser.h @@ -60,7 +60,7 @@ class SVGPathNormalizer { void EmitSegment(const PathSegmentData&); - private: + protected: bool DecomposeArcToCubic(const FloatPoint& current_point, const PathSegmentData&); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_pattern_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_pattern_element.cc index 9a481809915..cf4523d4a8d 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_pattern_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_pattern_element.cc @@ -25,6 +25,7 @@ #include "third_party/blink/renderer/core/css/style_change_reason.h" #include "third_party/blink/renderer/core/dom/element_traversal.h" #include "third_party/blink/renderer/core/layout/svg/layout_svg_resource_pattern.h" +#include "third_party/blink/renderer/core/layout/svg/svg_resources.h" #include "third_party/blink/renderer/core/layout/svg/svg_resources_cache.h" #include "third_party/blink/renderer/core/svg/pattern_attributes.h" #include "third_party/blink/renderer/core/svg/svg_resource.h" @@ -82,7 +83,7 @@ SVGPatternElement::SVGPatternElement(Document& document) AddToPropertyMap(pattern_content_units_); } -void SVGPatternElement::Trace(blink::Visitor* visitor) { +void SVGPatternElement::Trace(Visitor* visitor) { visitor->Trace(x_); visitor->Trace(y_); visitor->Trace(width_); @@ -185,10 +186,8 @@ void SVGPatternElement::RemovedFrom(ContainerNode& root_parent) { void SVGPatternElement::ChildrenChanged(const ChildrenChange& change) { SVGElement::ChildrenChanged(change); - if (change.by_parser) - return; - - InvalidatePattern(layout_invalidation_reason::kChildChanged); + if (!change.ByParser()) + InvalidatePattern(layout_invalidation_reason::kChildChanged); } void SVGPatternElement::InvalidatePattern( @@ -204,8 +203,6 @@ LayoutObject* SVGPatternElement::CreateLayoutObject(const ComputedStyle&, static void SetPatternAttributes(const SVGPatternElement& element, PatternAttributes& attributes) { - element.SynchronizeAnimatedSVGAttribute(AnyQName()); - if (!attributes.HasX() && element.x()->IsSpecified()) attributes.SetX(element.x()->CurrentValue()); @@ -267,10 +264,10 @@ void SVGPatternElement::CollectPatternAttributes( // from that element to override values this pattern didn't set. current = current->ReferencedElement(); - // Only consider attached SVG pattern elements. + // Ignore the referenced pattern element if it is not attached. if (!current || !current->GetLayoutObject()) break; - // Cycle detection + // Cycle detection. if (processed_patterns.Contains(current)) break; } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_pattern_element.h b/chromium/third_party/blink/renderer/core/svg/svg_pattern_element.h index 45b7af10525..8df0c30ad06 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_pattern_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_pattern_element.h @@ -80,7 +80,7 @@ class SVGPatternElement final : public SVGElement, const SVGPatternElement* ReferencedElement() const; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: bool IsValid() const override { return SVGTests::IsValid(); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_point.h b/chromium/third_party/blink/renderer/core/svg/svg_point.h index d7614c0f8a2..9f7d8d9c660 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_point.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_point.h @@ -82,8 +82,6 @@ class SVGPoint final : public SVGPropertyHelper<SVGPoint> { FloatPoint value_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGPoint); - } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_POINT_H_ diff --git a/chromium/third_party/blink/renderer/core/svg/svg_point_list.cc b/chromium/third_party/blink/renderer/core/svg/svg_point_list.cc index 842eb8fbf83..04ef9ffb647 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_point_list.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_point_list.cc @@ -83,7 +83,7 @@ SVGParsingError SVGPointList::SetValueAsString(const String& value) { } void SVGPointList::Add(SVGPropertyBase* other, SVGElement* context_element) { - SVGPointList* other_list = ToSVGPointList(other); + auto* other_list = To<SVGPointList>(other); if (length() != other_list->length()) return; @@ -100,10 +100,10 @@ void SVGPointList::CalculateAnimatedValue( SVGPropertyBase* to_value, SVGPropertyBase* to_at_end_of_duration_value, SVGElement* context_element) { - SVGPointList* from_list = ToSVGPointList(from_value); - SVGPointList* to_list = ToSVGPointList(to_value); - SVGPointList* to_at_end_of_duration_list = - ToSVGPointList(to_at_end_of_duration_value); + auto* from_list = To<SVGPointList>(from_value); + auto* to_list = To<SVGPointList>(to_value); + auto* to_at_end_of_duration_list = + To<SVGPointList>(to_at_end_of_duration_value); uint32_t from_point_list_size = from_list->length(); uint32_t to_point_list_size = to_list->length(); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_point_list.h b/chromium/third_party/blink/renderer/core/svg/svg_point_list.h index 4a4ff6171a1..ce06e5e5ac0 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_point_list.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_point_list.h @@ -34,6 +34,7 @@ #include "third_party/blink/renderer/core/svg/properties/svg_list_property_helper.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" #include "third_party/blink/renderer/core/svg/svg_point.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -70,7 +71,12 @@ class SVGPointList final SVGParsingError Parse(const CharType*& ptr, const CharType* end); }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGPointList); +template <> +struct DowncastTraits<SVGPointList> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGPointList::ClassType(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_poly_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_poly_element.cc index 6996f199b44..741dda2047e 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_poly_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_poly_element.cc @@ -36,7 +36,7 @@ SVGPolyElement::SVGPolyElement(const QualifiedName& tag_name, AddToPropertyMap(points_); } -void SVGPolyElement::Trace(blink::Visitor* visitor) { +void SVGPolyElement::Trace(Visitor* visitor) { visitor->Trace(points_); SVGGeometryElement::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_poly_element.h b/chromium/third_party/blink/renderer/core/svg/svg_poly_element.h index 87a146ced44..dd9c67e8a31 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_poly_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_poly_element.h @@ -35,7 +35,7 @@ class SVGPolyElement : public SVGGeometryElement { SVGPointListTearOff* pointsFromJavascript() { return points_->baseVal(); } SVGPointListTearOff* animatedPoints() { return points_->animVal(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: SVGPolyElement(const QualifiedName&, Document&); @@ -49,12 +49,21 @@ class SVGPolyElement : public SVGGeometryElement { Member<SVGAnimatedPointList> points_; }; -inline bool IsSVGPolyElement(const SVGElement& element) { - return element.HasTagName(svg_names::kPolygonTag) || - element.HasTagName(svg_names::kPolylineTag); +template <> +inline bool IsElementOfType<const SVGPolyElement>(const Node& node) { + return IsA<SVGPolyElement>(node); } - -DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGPolyElement); +template <> +struct DowncastTraits<SVGPolyElement> { + static bool AllowFrom(const Node& node) { + auto* svg_element = DynamicTo<SVGElement>(node); + return svg_element && AllowFrom(*svg_element); + } + static bool AllowFrom(const SVGElement& svg_element) { + return svg_element.HasTagName(svg_names::kPolygonTag) || + svg_element.HasTagName(svg_names::kPolylineTag); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_preserve_aspect_ratio.cc b/chromium/third_party/blink/renderer/core/svg/svg_preserve_aspect_ratio.cc index cf760eed072..dcad08c5391 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_preserve_aspect_ratio.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_preserve_aspect_ratio.cc @@ -186,7 +186,7 @@ bool SVGPreserveAspectRatio::Parse(const UChar*& ptr, } void SVGPreserveAspectRatio::TransformRect(FloatRect& dest_rect, - FloatRect& src_rect) { + FloatRect& src_rect) const { if (align_ == kSvgPreserveaspectratioNone) return; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_preserve_aspect_ratio.h b/chromium/third_party/blink/renderer/core/svg/svg_preserve_aspect_ratio.h index eaed2f3563a..aa90dba2e9e 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_preserve_aspect_ratio.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_preserve_aspect_ratio.h @@ -72,7 +72,7 @@ class SVGPreserveAspectRatio final } SVGMeetOrSliceType MeetOrSlice() const { return meet_or_slice_; } - void TransformRect(FloatRect& dest_rect, FloatRect& src_rect); + void TransformRect(FloatRect& dest_rect, FloatRect& src_rect) const; AffineTransform ComputeTransform(float logical_x, float logical_y, @@ -113,8 +113,6 @@ class SVGPreserveAspectRatio final SVGMeetOrSliceType meet_or_slice_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGPreserveAspectRatio); - } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_PRESERVE_ASPECT_RATIO_H_ diff --git a/chromium/third_party/blink/renderer/core/svg/svg_radial_gradient_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_radial_gradient_element.cc index 96045735027..3c96ac2b33e 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_radial_gradient_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_radial_gradient_element.cc @@ -73,7 +73,7 @@ SVGRadialGradientElement::SVGRadialGradientElement(Document& document) AddToPropertyMap(fr_); } -void SVGRadialGradientElement::Trace(blink::Visitor* visitor) { +void SVGRadialGradientElement::Trace(Visitor* visitor) { visitor->Trace(cx_); visitor->Trace(cy_); visitor->Trace(r_); @@ -105,7 +105,6 @@ LayoutObject* SVGRadialGradientElement::CreateLayoutObject(const ComputedStyle&, static void SetGradientAttributes(const SVGGradientElement& element, RadialGradientAttributes& attributes, bool is_radial) { - element.SynchronizeAnimatedSVGAttribute(AnyQName()); element.CollectCommonAttributes(attributes); if (!is_radial) @@ -131,8 +130,8 @@ static void SetGradientAttributes(const SVGGradientElement& element, attributes.SetFr(radial.fr()->CurrentValue()); } -bool SVGRadialGradientElement::CollectGradientAttributes( - RadialGradientAttributes& attributes) { +void SVGRadialGradientElement::CollectGradientAttributes( + RadialGradientAttributes& attributes) const { DCHECK(GetLayoutObject()); VisitedSet visited; @@ -144,10 +143,12 @@ bool SVGRadialGradientElement::CollectGradientAttributes( visited.insert(current); current = current->ReferencedElement(); - if (!current || visited.Contains(current)) + // Ignore the referenced gradient element if it is not attached. + if (!current || !current->GetLayoutObject()) + break; + // Cycle detection. + if (visited.Contains(current)) break; - if (!current->GetLayoutObject()) - return false; } // Handle default values for fx/fy @@ -156,8 +157,6 @@ bool SVGRadialGradientElement::CollectGradientAttributes( if (!attributes.HasFy()) attributes.SetFy(attributes.Cy()); - - return true; } bool SVGRadialGradientElement::SelfHasRelativeLengths() const { diff --git a/chromium/third_party/blink/renderer/core/svg/svg_radial_gradient_element.h b/chromium/third_party/blink/renderer/core/svg/svg_radial_gradient_element.h index b37d292595c..5aa965d0768 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_radial_gradient_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_radial_gradient_element.h @@ -35,7 +35,7 @@ class SVGRadialGradientElement final : public SVGGradientElement { public: explicit SVGRadialGradientElement(Document&); - bool CollectGradientAttributes(RadialGradientAttributes&); + void CollectGradientAttributes(RadialGradientAttributes&) const; SVGAnimatedLength* cx() const { return cx_.Get(); } SVGAnimatedLength* cy() const { return cy_.Get(); } @@ -44,7 +44,7 @@ class SVGRadialGradientElement final : public SVGGradientElement { SVGAnimatedLength* fy() const { return fy_.Get(); } SVGAnimatedLength* fr() const { return fr_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_rect.cc b/chromium/third_party/blink/renderer/core/svg/svg_rect.cc index 0e494da0967..096bd566ec8 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_rect.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_rect.cc @@ -91,7 +91,7 @@ String SVGRect::ValueAsString() const { } void SVGRect::Add(SVGPropertyBase* other, SVGElement*) { - value_ += ToSVGRect(other)->Value(); + value_ += To<SVGRect>(other)->Value(); } void SVGRect::CalculateAnimatedValue( @@ -102,9 +102,9 @@ void SVGRect::CalculateAnimatedValue( SVGPropertyBase* to_value, SVGPropertyBase* to_at_end_of_duration_value, SVGElement*) { - SVGRect* from_rect = ToSVGRect(from_value); - SVGRect* to_rect = ToSVGRect(to_value); - SVGRect* to_at_end_of_duration_rect = ToSVGRect(to_at_end_of_duration_value); + auto* from_rect = To<SVGRect>(from_value); + auto* to_rect = To<SVGRect>(to_value); + auto* to_at_end_of_duration_rect = To<SVGRect>(to_at_end_of_duration_value); float animated_x = X(); float animated_y = Y(); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_rect.h b/chromium/third_party/blink/renderer/core/svg/svg_rect.h index a3de5c7f0dc..e36f4c99ff2 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_rect.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_rect.h @@ -24,6 +24,7 @@ #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" #include "third_party/blink/renderer/platform/geometry/float_rect.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -83,7 +84,12 @@ class SVGRect final : public SVGPropertyHelper<SVGRect> { FloatRect value_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGRect); +template <> +struct DowncastTraits<SVGRect> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGRect::ClassType(); + } +}; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_rect_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_rect_element.cc index d8be687b603..d3386c383ee 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_rect_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_rect_element.cc @@ -72,7 +72,7 @@ SVGRectElement::SVGRectElement(Document& document) AddToPropertyMap(ry_); } -void SVGRectElement::Trace(blink::Visitor* visitor) { +void SVGRectElement::Trace(Visitor* visitor) { visitor->Trace(x_); visitor->Trace(y_); visitor->Trace(width_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_rect_element.h b/chromium/third_party/blink/renderer/core/svg/svg_rect_element.h index 1de73b696ea..15a81e7ef33 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_rect_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_rect_element.h @@ -42,7 +42,7 @@ class SVGRectElement final : public SVGGeometryElement { SVGAnimatedLength* rx() const { return rx_.Get(); } SVGAnimatedLength* ry() const { return ry_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void CollectStyleForPresentationAttribute( diff --git a/chromium/third_party/blink/renderer/core/svg/svg_resource.cc b/chromium/third_party/blink/renderer/core/svg/svg_resource.cc index 9421f732db6..110d32b4748 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_resource.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_resource.cc @@ -81,6 +81,16 @@ void LocalSVGResource::NotifyContentChanged( client->ResourceContentChanged(invalidation_mask); } +void LocalSVGResource::NotifyFilterPrimitiveChanged( + SVGFilterPrimitiveStandardAttributes& primitive, + const QualifiedName& attribute) { + HeapVector<Member<SVGResourceClient>> clients; + CopyToVector(clients_, clients); + + for (SVGResourceClient* client : clients) + client->FilterPrimitiveChanged(primitive, attribute); +} + void LocalSVGResource::NotifyResourceAttached( LayoutSVGResourceContainer& attached_resource) { // Checking the element here because @@ -129,9 +139,24 @@ void ExternalSVGResource::Load(const Document& document) { options.initiator_info.name = fetch_initiator_type_names::kCSS; FetchParameters params(ResourceRequest(url_), options); params.MutableResourceRequest().SetMode( - network::mojom::RequestMode::kSameOrigin); + network::mojom::blink::RequestMode::kSameOrigin); + resource_document_ = + DocumentResource::FetchSVGDocument(params, document, this); + target_ = ResolveTarget(); +} + +void ExternalSVGResource::LoadWithoutCSP(const Document& document) { + if (resource_document_) + return; + ResourceLoaderOptions options; + options.initiator_info.name = fetch_initiator_type_names::kCSS; + FetchParameters params(ResourceRequest(url_), options); + params.SetContentSecurityCheck( + network::mojom::blink::CSPDisposition::DO_NOT_CHECK); + params.MutableResourceRequest().SetMode( + network::mojom::blink::RequestMode::kSameOrigin); resource_document_ = - DocumentResource::FetchSVGDocument(params, document.Fetcher(), this); + DocumentResource::FetchSVGDocument(params, document, this); target_ = ResolveTarget(); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_resource.h b/chromium/third_party/blink/renderer/core/svg/svg_resource.h index 21c8ca6a5ca..aab5fd2da1a 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_resource.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_resource.h @@ -64,6 +64,7 @@ class SVGResource : public GarbageCollected<SVGResource> { virtual ~SVGResource(); virtual void Load(const Document&) {} + virtual void LoadWithoutCSP(const Document&) {} Element* Target() const { return target_; } LayoutSVGResourceContainer* ResourceContainer() const; @@ -71,8 +72,6 @@ class SVGResource : public GarbageCollected<SVGResource> { void AddClient(SVGResourceClient&); void RemoveClient(SVGResourceClient&); - bool HasClients() const { return !clients_.IsEmpty(); } - virtual void Trace(Visitor*); protected: @@ -95,6 +94,9 @@ class LocalSVGResource final : public SVGResource { void Unregister(); void NotifyContentChanged(InvalidationModeMask); + void NotifyFilterPrimitiveChanged( + SVGFilterPrimitiveStandardAttributes& primitive, + const QualifiedName& attribute); void NotifyResourceAttached(LayoutSVGResourceContainer&); void NotifyResourceDestroyed(LayoutSVGResourceContainer&); @@ -116,6 +118,7 @@ class ExternalSVGResource final : public SVGResource, private ResourceClient { explicit ExternalSVGResource(const KURL&); void Load(const Document&) override; + void LoadWithoutCSP(const Document&) override; void Trace(Visitor*) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_resource_client.h b/chromium/third_party/blink/renderer/core/svg/svg_resource_client.h index d63b3b53308..1b5a5876982 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_resource_client.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_resource_client.h @@ -11,6 +11,8 @@ namespace blink { class LayoutSVGResourceContainer; +class QualifiedName; +class SVGFilterPrimitiveStandardAttributes; typedef unsigned InvalidationModeMask; @@ -24,13 +26,17 @@ class CORE_EXPORT SVGResourceClient : public GarbageCollectedMixin { kLayoutInvalidation = 1 << 0, kBoundariesInvalidation = 1 << 1, kPaintInvalidation = 1 << 2, - kParentOnlyInvalidation = 1 << 3, - kSkipAncestorInvalidation = 1 << 4, }; virtual void ResourceContentChanged(InvalidationModeMask) = 0; virtual void ResourceElementChanged() = 0; virtual void ResourceDestroyed(LayoutSVGResourceContainer*) {} + virtual void FilterPrimitiveChanged( + SVGFilterPrimitiveStandardAttributes& primitive, + const QualifiedName& attribute) { + ResourceContentChanged(kPaintInvalidation); + } + protected: SVGResourceClient() = default; }; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_script_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_script_element.cc index 0147e9dfdef..4efb5d34b65 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_script_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_script_element.cc @@ -93,6 +93,8 @@ bool SVGScriptElement::IsURLAttribute(const Attribute& attribute) const { void SVGScriptElement::FinishParsingChildren() { SVGElement::FinishParsingChildren(); have_fired_load_ = true; + DCHECK(!script_text_internal_slot_.length()); + script_text_internal_slot_ = ParkableString(TextFromChildren().Impl()); } bool SVGScriptElement::HaveLoadedRequiredResources() { @@ -107,8 +109,12 @@ String SVGScriptElement::TypeAttributeValue() const { return getAttribute(svg_names::kTypeAttr).GetString(); } -String SVGScriptElement::TextFromChildren() { - return Element::TextFromChildren(); +String SVGScriptElement::ChildTextContent() { + return TextFromChildren(); +} + +String SVGScriptElement::ScriptTextInternalSlot() const { + return script_text_internal_slot_.ToString(); } bool SVGScriptElement::HasSourceAttribute() const { @@ -164,6 +170,10 @@ void SVGScriptElement::SetScriptElementForBinding( element.SetSVGScriptElement(this); } +ScriptElementBase::Type SVGScriptElement::GetScriptElementType() { + return ScriptElementBase::Type::kSVGScriptElement; +} + #if DCHECK_IS_ON() bool SVGScriptElement::IsAnimatableAttribute(const QualifiedName& name) const { if (name == svg_names::kTypeAttr || name == svg_names::kHrefAttr || @@ -175,15 +185,15 @@ bool SVGScriptElement::IsAnimatableAttribute(const QualifiedName& name) const { const AttrNameToTrustedType& SVGScriptElement::GetCheckedAttributeTypes() const { - DEFINE_STATIC_LOCAL(AttrNameToTrustedType, attribute_map, - ({ - {svg_names::kHrefAttr.LocalName(), - SpecificTrustedType::kTrustedScriptURL}, - })); + DEFINE_STATIC_LOCAL( + AttrNameToTrustedType, attribute_map, + ({ + {svg_names::kHrefAttr.LocalName(), SpecificTrustedType::kScriptURL}, + })); return attribute_map; } -void SVGScriptElement::Trace(blink::Visitor* visitor) { +void SVGScriptElement::Trace(Visitor* visitor) { visitor->Trace(loader_); SVGElement::Trace(visitor); SVGURIReference::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_script_element.h b/chromium/third_party/blink/renderer/core/svg/svg_script_element.h index cb4b1763331..91c98f76fb0 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_script_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_script_element.h @@ -26,6 +26,7 @@ #include "third_party/blink/renderer/core/svg/svg_element.h" #include "third_party/blink/renderer/core/svg/svg_uri_reference.h" #include "third_party/blink/renderer/core/svg_names.h" +#include "third_party/blink/renderer/platform/bindings/parkable_string.h" #include "third_party/blink/renderer/platform/heap/handle.h" namespace blink { @@ -51,7 +52,7 @@ class SVGScriptElement final : public SVGElement, const AttrNameToTrustedType& GetCheckedAttributeTypes() const override; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void ParseAttribute(const AttributeModificationParams&) override; @@ -81,7 +82,8 @@ class SVGScriptElement final : public SVGElement, bool NomoduleAttributeValue() const override { return false; } String SourceAttributeValue() const override; String TypeAttributeValue() const override; - String TextFromChildren() override; + String ChildTextContent() override; + String ScriptTextInternalSlot() const override; bool HasSourceAttribute() const override; bool IsConnected() const override; bool HasChildren() const override; @@ -98,6 +100,8 @@ class SVGScriptElement final : public SVGElement, void SetScriptElementForBinding( HTMLScriptElementOrSVGScriptElement&) override; + Type GetScriptElementType() override; + Element& CloneWithoutAttributesAndChildren(Document&) const override; bool LayoutObjectIsNeeded(const ComputedStyle&) const override { return false; @@ -105,6 +109,8 @@ class SVGScriptElement final : public SVGElement, bool have_fired_load_ = false; + ParkableString script_text_internal_slot_; + Member<ScriptLoader> loader_; }; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_static_string_list.cc b/chromium/third_party/blink/renderer/core/svg/svg_static_string_list.cc index 3efc7dc42f5..9f39bfd8f40 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_static_string_list.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_static_string_list.cc @@ -47,7 +47,7 @@ SVGStaticStringList::SVGStaticStringList(SVGElement* context_element, SVGStaticStringList::~SVGStaticStringList() = default; -void SVGStaticStringList::Trace(blink::Visitor* visitor) { +void SVGStaticStringList::Trace(Visitor* visitor) { visitor->Trace(value_); visitor->Trace(tear_off_); SVGAnimatedPropertyBase::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_static_string_list.h b/chromium/third_party/blink/renderer/core/svg/svg_static_string_list.h index 81beaf48b07..55547c440ed 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_static_string_list.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_static_string_list.h @@ -74,7 +74,7 @@ class SVGStaticStringList final : public GarbageCollected<SVGStaticStringList>, SVGStringListBase* Value() { return value_.Get(); } SVGStringListTearOff* TearOff(); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: Member<SVGStringListBase> value_; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_stop_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_stop_element.cc index 557ce8d9706..53d12cfe254 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_stop_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_stop_element.cc @@ -40,7 +40,7 @@ SVGStopElement::SVGStopElement(Document& document) DCHECK(HasCustomStyleCallbacks()); } -void SVGStopElement::Trace(blink::Visitor* visitor) { +void SVGStopElement::Trace(Visitor* visitor) { visitor->Trace(offset_); SVGElement::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_stop_element.h b/chromium/third_party/blink/renderer/core/svg/svg_stop_element.h index b8e3f0f26ad..32364f286ce 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_stop_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_stop_element.h @@ -39,7 +39,7 @@ class SVGStopElement final : public SVGElement { SVGAnimatedNumber* offset() const { return offset_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: void DidRecalcStyle(const StyleRecalcChange) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_string.h b/chromium/third_party/blink/renderer/core/svg/svg_string.h index ce240ba99f8..9125d80beca 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_string.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_string.h @@ -77,8 +77,6 @@ class SVGString final : public SVGPropertyBase { String value_; }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGString); - } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_STRING_H_ diff --git a/chromium/third_party/blink/renderer/core/svg/svg_string_list_tear_off.h b/chromium/third_party/blink/renderer/core/svg/svg_string_list_tear_off.h index f941d7cbf72..bbc7d879b0e 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_string_list_tear_off.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_string_list_tear_off.h @@ -33,6 +33,7 @@ #include "third_party/blink/renderer/core/svg/properties/svg_property_tear_off.h" #include "third_party/blink/renderer/core/svg/svg_string_list.h" +#include "third_party/blink/renderer/platform/bindings/v8_binding.h" namespace blink { @@ -96,11 +97,12 @@ class SVGStringListTearOff : public SVGPropertyTearOff<SVGStringListBase> { return item; } - bool AnonymousIndexedSetter(uint32_t index, - const String& item, - ExceptionState& exception_state) { + IndexedPropertySetterResult AnonymousIndexedSetter( + uint32_t index, + const String& item, + ExceptionState& exception_state) { replaceItem(item, index, exception_state); - return true; + return IndexedPropertySetterResult::kIntercepted; } String removeItem(uint32_t index, ExceptionState& exception_state) { diff --git a/chromium/third_party/blink/renderer/core/svg/svg_style_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_style_element.cc index 78852ecd570..09fd3f44911 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_style_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_style_element.cc @@ -138,7 +138,7 @@ void SVGStyleElement::DispatchPendingEvent() { DispatchEvent(*Event::Create(event_type_names::kError)); } -void SVGStyleElement::Trace(blink::Visitor* visitor) { +void SVGStyleElement::Trace(Visitor* visitor) { StyleElement::Trace(visitor); SVGElement::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_style_element.h b/chromium/third_party/blink/renderer/core/svg/svg_style_element.h index 1c540a0484c..d00ea8a36f5 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_style_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_style_element.h @@ -51,7 +51,7 @@ class SVGStyleElement final : public SVGElement, public StyleElement { void DispatchPendingEvent(); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void ParseAttribute(const AttributeModificationParams&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_svg_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_svg_element.cc index 84514df2368..78b88fee9ab 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_svg_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_svg_element.cc @@ -29,6 +29,7 @@ #include "third_party/blink/renderer/core/dom/element_traversal.h" #include "third_party/blink/renderer/core/dom/events/event_listener.h" #include "third_party/blink/renderer/core/dom/static_node_list.h" +#include "third_party/blink/renderer/core/dom/xml_document.h" #include "third_party/blink/renderer/core/editing/frame_selection.h" #include "third_party/blink/renderer/core/frame/deprecation.h" #include "third_party/blink/renderer/core/frame/local_frame.h" @@ -372,7 +373,8 @@ StaticNodeList* SVGSVGElement::CollectIntersectionOrEnclosureList( StaticNodeList* SVGSVGElement::getIntersectionList( SVGRectTearOff* rect, SVGElement* reference_element) const { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); return CollectIntersectionOrEnclosureList( rect->Target()->Value(), reference_element, kCheckIntersection); @@ -381,7 +383,8 @@ StaticNodeList* SVGSVGElement::getIntersectionList( StaticNodeList* SVGSVGElement::getEnclosureList( SVGRectTearOff* rect, SVGElement* reference_element) const { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); return CollectIntersectionOrEnclosureList(rect->Target()->Value(), reference_element, kCheckEnclosure); @@ -390,7 +393,8 @@ StaticNodeList* SVGSVGElement::getEnclosureList( bool SVGSVGElement::checkIntersection(SVGElement* element, SVGRectTearOff* rect) const { DCHECK(element); - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); return CheckIntersectionOrEnclosure(*element, rect->Target()->Value(), kCheckIntersection); @@ -399,7 +403,8 @@ bool SVGSVGElement::checkIntersection(SVGElement* element, bool SVGSVGElement::checkEnclosure(SVGElement* element, SVGRectTearOff* rect) const { DCHECK(element); - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); return CheckIntersectionOrEnclosure(*element, rect->Target()->Value(), kCheckEnclosure); @@ -511,7 +516,7 @@ Node::InsertionNotificationRequest SVGSVGElement::InsertedInto( ContainerNode& root_parent) { if (root_parent.isConnected()) { UseCounter::Count(GetDocument(), WebFeature::kSVGSVGElementInDocument); - if (root_parent.GetDocument().IsXMLDocument()) + if (IsA<XMLDocument>(root_parent.GetDocument())) UseCounter::Count(GetDocument(), WebFeature::kSVGSVGElementInXMLDocument); GetDocument().AccessSVGExtensions().AddTimeContainer(this); @@ -729,7 +734,7 @@ void SVGSVGElement::FinishParsingChildren() { SendSVGLoadEventIfPossible(); } -void SVGSVGElement::Trace(blink::Visitor* visitor) { +void SVGSVGElement::Trace(Visitor* visitor) { visitor->Trace(x_); visitor->Trace(y_); visitor->Trace(width_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_svg_element.h b/chromium/third_party/blink/renderer/core/svg/svg_svg_element.h index de276f257ed..d153b348082 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_svg_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_svg_element.h @@ -109,7 +109,7 @@ class SVGSVGElement final : public SVGGraphicsElement, SVGAnimatedLength* width() const { return width_.Get(); } SVGAnimatedLength* height() const { return height_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: ~SVGSVGElement() override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_symbol_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_symbol_element.cc index 1b8ebcd60e0..7341f491adb 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_symbol_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_symbol_element.cc @@ -28,7 +28,7 @@ namespace blink { SVGSymbolElement::SVGSymbolElement(Document& document) : SVGElement(svg_names::kSymbolTag, document), SVGFitToViewBox(this) {} -void SVGSymbolElement::Trace(blink::Visitor* visitor) { +void SVGSymbolElement::Trace(Visitor* visitor) { SVGElement::Trace(visitor); SVGFitToViewBox::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_symbol_element.h b/chromium/third_party/blink/renderer/core/svg/svg_symbol_element.h index 580a3b5cec7..f54c16d8535 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_symbol_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_symbol_element.h @@ -33,7 +33,7 @@ class SVGSymbolElement final : public SVGElement, public SVGFitToViewBox { public: explicit SVGSymbolElement(Document&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void SvgAttributeChanged(const QualifiedName&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_tag_names.json5 b/chromium/third_party/blink/renderer/core/svg/svg_tag_names.json5 index 53fc167c31b..59e6598d2c5 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_tag_names.json5 +++ b/chromium/third_party/blink/renderer/core/svg/svg_tag_names.json5 @@ -26,7 +26,6 @@ "clipPath", "defs", "desc", - "discard", "ellipse", "feBlend", "feColorMatrix", diff --git a/chromium/third_party/blink/renderer/core/svg/svg_tests.cc b/chromium/third_party/blink/renderer/core/svg/svg_tests.cc index dbbc2e9e5e7..fff3d4a17f9 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_tests.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_tests.cc @@ -20,12 +20,14 @@ #include "third_party/blink/renderer/core/svg/svg_tests.h" +#include "third_party/blink/renderer/core/mathml_names.h" #include "third_party/blink/renderer/core/page/chrome_client.h" #include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/svg/svg_element.h" #include "third_party/blink/renderer/core/svg/svg_static_string_list.h" #include "third_party/blink/renderer/core/svg_names.h" #include "third_party/blink/renderer/platform/language.h" +#include "third_party/blink/renderer/platform/runtime_enabled_features.h" namespace blink { @@ -42,7 +44,7 @@ SVGTests::SVGTests(SVGElement* context_element) context_element->AddToPropertyMap(system_language_); } -void SVGTests::Trace(blink::Visitor* visitor) { +void SVGTests::Trace(Visitor* visitor) { visitor->Trace(required_extensions_); visitor->Trace(system_language_); } @@ -91,9 +93,19 @@ bool SVGTests::IsValid() const { return false; } - if (!required_extensions_->Value()->Values().IsEmpty()) - return false; - + if (required_extensions_->IsSpecified()) { + const Vector<String>& extensions = required_extensions_->Value()->Values(); + // 'If a null string or empty string value is given to attribute + // 'requiredExtensions', the attribute evaluates to "false".' + if (extensions.IsEmpty()) + return false; + for (const auto& extension : extensions) { + if (extension != html_names::xhtmlNamespaceURI && + (!RuntimeEnabledFeatures::MathMLCoreEnabled() || + extension != mathml_names::kNamespaceURI)) + return false; + } + } return true; } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_tests.h b/chromium/third_party/blink/renderer/core/svg/svg_tests.h index fa58e7f1bff..ed920cf8899 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_tests.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_tests.h @@ -39,7 +39,7 @@ class CORE_EXPORT SVGTests : public GarbageCollectedMixin { bool IsValid() const; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: explicit SVGTests(SVGElement* context_element); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_text_content_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_text_content_element.cc index f81f3d4bf3b..542db849b2a 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_text_content_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_text_content_element.cc @@ -85,19 +85,21 @@ SVGTextContentElement::SVGTextContentElement(const QualifiedName& tag_name, AddToPropertyMap(length_adjust_); } -void SVGTextContentElement::Trace(blink::Visitor* visitor) { +void SVGTextContentElement::Trace(Visitor* visitor) { visitor->Trace(text_length_); visitor->Trace(length_adjust_); SVGGraphicsElement::Trace(visitor); } unsigned SVGTextContentElement::getNumberOfChars() { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); return SVGTextQuery(GetLayoutObject()).NumberOfCharacters(); } float SVGTextContentElement::getComputedTextLength() { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); return SVGTextQuery(GetLayoutObject()).TextLength(); } @@ -105,7 +107,8 @@ float SVGTextContentElement::getSubStringLength( unsigned charnum, unsigned nchars, ExceptionState& exception_state) { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); unsigned number_of_chars = getNumberOfChars(); if (charnum >= number_of_chars) { @@ -125,7 +128,8 @@ float SVGTextContentElement::getSubStringLength( SVGPointTearOff* SVGTextContentElement::getStartPositionOfChar( unsigned charnum, ExceptionState& exception_state) { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); if (charnum >= getNumberOfChars()) { exception_state.ThrowDOMException( @@ -143,7 +147,8 @@ SVGPointTearOff* SVGTextContentElement::getStartPositionOfChar( SVGPointTearOff* SVGTextContentElement::getEndPositionOfChar( unsigned charnum, ExceptionState& exception_state) { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); if (charnum >= getNumberOfChars()) { exception_state.ThrowDOMException( @@ -161,7 +166,8 @@ SVGPointTearOff* SVGTextContentElement::getEndPositionOfChar( SVGRectTearOff* SVGTextContentElement::getExtentOfChar( unsigned charnum, ExceptionState& exception_state) { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); if (charnum >= getNumberOfChars()) { exception_state.ThrowDOMException( @@ -178,7 +184,8 @@ SVGRectTearOff* SVGTextContentElement::getExtentOfChar( float SVGTextContentElement::getRotationOfChar( unsigned charnum, ExceptionState& exception_state) { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); if (charnum >= getNumberOfChars()) { exception_state.ThrowDOMException( @@ -194,7 +201,8 @@ float SVGTextContentElement::getRotationOfChar( int SVGTextContentElement::getCharNumAtPosition( SVGPointTearOff* point, ExceptionState& exception_state) { - GetDocument().UpdateStyleAndLayoutForNode(this); + GetDocument().UpdateStyleAndLayoutForNode(this, + DocumentUpdateReason::kJavaScript); return SVGTextQuery(GetLayoutObject()) .CharacterNumberAtPosition(point->Target()->Value()); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_text_content_element.h b/chromium/third_party/blink/renderer/core/svg/svg_text_content_element.h index 2538750acae..8f55e3b9d2a 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_text_content_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_text_content_element.h @@ -71,7 +71,7 @@ class CORE_EXPORT SVGTextContentElement : public SVGGraphicsElement { return length_adjust_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: SVGTextContentElement(const QualifiedName&, Document&); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_text_path_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_text_path_element.cc index b40655e04a2..392c4cb6fa8 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_text_path_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_text_path_element.cc @@ -71,7 +71,7 @@ SVGTextPathElement::SVGTextPathElement(Document& document) SVGTextPathElement::~SVGTextPathElement() = default; -void SVGTextPathElement::Trace(blink::Visitor* visitor) { +void SVGTextPathElement::Trace(Visitor* visitor) { visitor->Trace(start_offset_); visitor->Trace(method_); visitor->Trace(spacing_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_text_path_element.h b/chromium/third_party/blink/renderer/core/svg/svg_text_path_element.h index 05766023ca6..497cd084d99 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_text_path_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_text_path_element.h @@ -66,7 +66,7 @@ class SVGTextPathElement final : public SVGTextContentElement, return spacing_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: ~SVGTextPathElement() override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_text_positioning_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_text_positioning_element.cc index 58b7eeabb77..a0cb80821d1 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_text_positioning_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_text_positioning_element.cc @@ -58,7 +58,7 @@ SVGTextPositioningElement::SVGTextPositioningElement( AddToPropertyMap(rotate_); } -void SVGTextPositioningElement::Trace(blink::Visitor* visitor) { +void SVGTextPositioningElement::Trace(Visitor* visitor) { visitor->Trace(x_); visitor->Trace(y_); visitor->Trace(dx_); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_text_positioning_element.h b/chromium/third_party/blink/renderer/core/svg/svg_text_positioning_element.h index fd26dff2e08..ab1f9a77ef1 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_text_positioning_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_text_positioning_element.h @@ -38,7 +38,7 @@ class SVGTextPositioningElement : public SVGTextContentElement { SVGAnimatedLengthList* dy() { return dy_.Get(); } SVGAnimatedNumberList* rotate() { return rotate_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: SVGTextPositioningElement(const QualifiedName&, Document&); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_transform_list.cc b/chromium/third_party/blink/renderer/core/svg/svg_transform_list.cc index 10495982c46..91b88dab777 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_transform_list.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_transform_list.cc @@ -435,7 +435,7 @@ void SVGTransformList::Add(SVGPropertyBase* other, if (IsEmpty()) return; - SVGTransformList* other_list = ToSVGTransformList(other); + auto* other_list = To<SVGTransformList>(other); if (length() != other_list->length()) return; @@ -462,10 +462,10 @@ void SVGTransformList::CalculateAnimatedValue( // post-multiplied. As a consequence, in SVG 1.1 the behavior of to animations // for 'animateTransform' is undefined. // FIXME: This is not taken into account yet. - SVGTransformList* from_list = ToSVGTransformList(from_value); - SVGTransformList* to_list = ToSVGTransformList(to_value); - SVGTransformList* to_at_end_of_duration_list = - ToSVGTransformList(to_at_end_of_duration_value); + auto* from_list = To<SVGTransformList>(from_value); + auto* to_list = To<SVGTransformList>(to_value); + auto* to_at_end_of_duration_list = + To<SVGTransformList>(to_at_end_of_duration_value); size_t to_list_size = to_list->length(); if (!to_list_size) @@ -517,7 +517,7 @@ float SVGTransformList::CalculateDistance(SVGPropertyBase* to_value, // component (translate x and y for example) is paced separately. To implement // this we need to treat each component as individual animation everywhere. - SVGTransformList* to_list = ToSVGTransformList(to_value); + auto* to_list = To<SVGTransformList>(to_value); if (IsEmpty() || length() != to_list->length()) return -1; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_transform_list.h b/chromium/third_party/blink/renderer/core/svg/svg_transform_list.h index 084bf850540..28930b5d87d 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_transform_list.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_transform_list.h @@ -34,6 +34,7 @@ #include "third_party/blink/renderer/core/svg/properties/svg_list_property_helper.h" #include "third_party/blink/renderer/core/svg/svg_parsing_error.h" #include "third_party/blink/renderer/core/svg/svg_transform.h" +#include "third_party/blink/renderer/platform/wtf/casting.h" namespace blink { @@ -80,7 +81,12 @@ class SVGTransformList final SVGParsingError ParseInternal(const CharType*& ptr, const CharType* end); }; -DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGTransformList); +template <> +struct DowncastTraits<SVGTransformList> { + static bool AllowFrom(const SVGPropertyBase& value) { + return value.GetType() == SVGTransformList::ClassType(); + } +}; SVGTransformType ParseTransformType(const String&); diff --git a/chromium/third_party/blink/renderer/core/svg/svg_transform_tear_off.cc b/chromium/third_party/blink/renderer/core/svg/svg_transform_tear_off.cc index d147771a4d8..fb466b1f1e8 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_transform_tear_off.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_transform_tear_off.cc @@ -48,7 +48,7 @@ SVGTransformTearOff::SVGTransformTearOff( SVGTransformTearOff::~SVGTransformTearOff() = default; -void SVGTransformTearOff::Trace(blink::Visitor* visitor) { +void SVGTransformTearOff::Trace(Visitor* visitor) { visitor->Trace(matrix_tearoff_); SVGPropertyTearOff<SVGTransform>::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_transform_tear_off.h b/chromium/third_party/blink/renderer/core/svg/svg_transform_tear_off.h index 7d79e107e62..3fc02bc4a8c 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_transform_tear_off.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_transform_tear_off.h @@ -74,7 +74,7 @@ class SVGTransformTearOff final : public SVGPropertyTearOff<SVGTransform> { void setSkewX(float, ExceptionState&); void setSkewY(float, ExceptionState&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: Member<SVGMatrixTearOff> matrix_tearoff_; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_tree_scope_resources.cc b/chromium/third_party/blink/renderer/core/svg/svg_tree_scope_resources.cc index aa90abbf069..277bb59b4bd 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_tree_scope_resources.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_tree_scope_resources.cc @@ -14,8 +14,6 @@ namespace blink { SVGTreeScopeResources::SVGTreeScopeResources(TreeScope* tree_scope) : tree_scope_(tree_scope) {} -SVGTreeScopeResources::~SVGTreeScopeResources() = default; - LocalSVGResource* SVGTreeScopeResources::ResourceForId(const AtomicString& id) { if (id.IsEmpty()) return nullptr; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_tree_scope_resources.h b/chromium/third_party/blink/renderer/core/svg/svg_tree_scope_resources.h index 6cde6465c34..f0273986798 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_tree_scope_resources.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_tree_scope_resources.h @@ -22,7 +22,6 @@ class SVGTreeScopeResources final : public GarbageCollected<SVGTreeScopeResources> { public: explicit SVGTreeScopeResources(TreeScope*); - ~SVGTreeScopeResources(); LocalSVGResource* ResourceForId(const AtomicString& id); LocalSVGResource* ExistingResourceForId(const AtomicString& id) const; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_uri_reference.cc b/chromium/third_party/blink/renderer/core/svg/svg_uri_reference.cc index 99471e10c92..4a3bb14b8d0 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_uri_reference.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_uri_reference.cc @@ -52,7 +52,7 @@ SVGURIReference::SVGURIReference(SVGElement* element) href_->AddToPropertyMap(element); } -void SVGURIReference::Trace(blink::Visitor* visitor) { +void SVGURIReference::Trace(Visitor* visitor) { visitor->Trace(href_); } @@ -124,7 +124,7 @@ Element* SVGURIReference::ObserveTarget(Member<IdTargetObserver>& observer, Element* SVGURIReference::ObserveTarget(Member<IdTargetObserver>& observer, SVGElement& context_element, const String& href_string) { - TreeScope& tree_scope = context_element.GetTreeScope(); + TreeScope& tree_scope = context_element.OriginatingTreeScope(); AtomicString id = FragmentIdentifierFromIRIString(href_string, tree_scope); return ObserveTarget( observer, tree_scope, id, diff --git a/chromium/third_party/blink/renderer/core/svg/svg_uri_reference.h b/chromium/third_party/blink/renderer/core/svg/svg_uri_reference.h index 6d3347ac51f..d36385c2700 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_uri_reference.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_uri_reference.h @@ -81,7 +81,7 @@ class CORE_EXPORT SVGURIReference : public GarbageCollectedMixin { // JS API SVGAnimatedHref* href() const { return href_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; protected: explicit SVGURIReference(SVGElement*); @@ -104,7 +104,7 @@ class SVGURLReferenceResolver { private: const String& relative_url_; - Member<const Document> document_; + const Document* document_; mutable KURL absolute_url_; bool is_local_; }; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_use_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_use_element.cc index af673fe75f7..8cd5633c98c 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_use_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_use_element.cc @@ -25,7 +25,6 @@ #include "third_party/blink/renderer/core/svg/svg_use_element.h" -#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/platform/task_type.h" #include "third_party/blink/renderer/core/css/style_change_reason.h" #include "third_party/blink/renderer/core/dom/document.h" @@ -33,6 +32,7 @@ #include "third_party/blink/renderer/core/dom/events/event.h" #include "third_party/blink/renderer/core/dom/id_target_observer.h" #include "third_party/blink/renderer/core/dom/shadow_root.h" +#include "third_party/blink/renderer/core/dom/xml_document.h" #include "third_party/blink/renderer/core/layout/svg/layout_svg_transformable_container.h" #include "third_party/blink/renderer/core/svg/svg_g_element.h" #include "third_party/blink/renderer/core/svg/svg_length_context.h" @@ -94,7 +94,7 @@ void SVGUseElement::Dispose() { ClearResource(); } -void SVGUseElement::Trace(blink::Visitor* visitor) { +void SVGUseElement::Trace(Visitor* visitor) { visitor->Trace(x_); visitor->Trace(y_); visitor->Trace(width_); @@ -107,7 +107,7 @@ void SVGUseElement::Trace(blink::Visitor* visitor) { #if DCHECK_IS_ON() static inline bool IsWellFormedDocument(const Document& document) { - if (document.IsXMLDocument()) + if (IsA<XMLDocument>(document)) return static_cast<XMLDocumentParser*>(document.Parser())->WellFormed(); return true; } @@ -204,10 +204,8 @@ void SVGUseElement::UpdateTargetReference() { FetchParameters params(ResourceRequest(element_url_), options); params.MutableResourceRequest().SetMode( network::mojom::RequestMode::kSameOrigin); - ResourceFetcher* fetcher = GetDocument().Fetcher(); - if (base::FeatureList::IsEnabled( - features::kHtmlImportsRequestInitiatorLock) && - GetDocument().ImportsController()) { + auto* context_document = &GetDocument(); + if (GetDocument().ImportsController()) { // For @imports from HTML imported Documents, we use the // context document for getting origin and ResourceFetcher to use the // main Document's origin, while using the element document for @@ -216,9 +214,9 @@ void SVGUseElement::UpdateTargetReference() { ClearResource(); return; } - fetcher = GetDocument().ContextDocument()->Fetcher(); + context_document = GetDocument().ContextDocument(); } - DocumentResource::FetchSVGDocument(params, fetcher, this); + DocumentResource::FetchSVGDocument(params, *context_document, this); } void SVGUseElement::SvgAttributeChanged(const QualifiedName& attr_name) { @@ -284,8 +282,6 @@ static bool IsDisallowedElement(const Element& element) { } void SVGUseElement::ScheduleShadowTreeRecreation() { - if (InUseShadowTree()) - return; needs_shadow_tree_recreation_ = true; GetDocument().ScheduleUseShadowTreeUpdate(*this); } @@ -300,22 +296,27 @@ void SVGUseElement::ClearResourceReference() { RemoveAllOutgoingReferences(); } -Element* SVGUseElement::ResolveTargetElement(ObserveBehavior observe_behavior) { +Element* SVGUseElement::ResolveTargetElement() { if (!element_url_.HasFragmentIdentifier()) return nullptr; AtomicString element_identifier(DecodeURLEscapeSequences( element_url_.FragmentIdentifier(), DecodeURLMode::kUTF8OrIsomorphic)); + if (!IsStructurallyExternal()) { - if (observe_behavior == kDontAddObserver) - return GetTreeScope().getElementById(element_identifier); - return ObserveTarget( - target_id_observer_, GetTreeScope(), element_identifier, - WTF::BindRepeating(&SVGUseElement::InvalidateShadowTree, - WrapWeakPersistent(this))); + // Only create observers for non-instance use elements. + // Instances will be updated by their corresponding elements. + if (InUseShadowTree()) { + return OriginatingTreeScope().getElementById(element_identifier); + } else { + return ObserveTarget( + target_id_observer_, OriginatingTreeScope(), element_identifier, + WTF::BindRepeating(&SVGUseElement::InvalidateTargetReference, + WrapWeakPersistent(this))); + } } if (!ResourceIsValid()) return nullptr; - return ToDocumentResource(GetResource()) + return To<DocumentResource>(GetResource()) ->GetDocument() ->getElementById(element_identifier); } @@ -327,20 +328,24 @@ SVGElement* SVGUseElement::InstanceRoot() const { } void SVGUseElement::BuildPendingResource() { - // This runs just before computed style is updated, so this SVGUseElement - // should always be connected to the Document. It should also not be an - // SVGUseElement that is part of a shadow tree, since we should never - // schedule shadow tree updates for those. - DCHECK(!InUseShadowTree()); - DCHECK(isConnected()); + if (!isConnected()) { + DCHECK(!needs_shadow_tree_recreation_); + return; // Already replaced by rebuilding ancestor. + } + CancelShadowTreeRecreation(); + + // Check if this element is scheduled (by an ancestor) to be replaced. + SVGUseElement* ancestor = GeneratingUseElement(); + while (ancestor) { + if (ancestor->needs_shadow_tree_recreation_) + return; + ancestor = ancestor->GeneratingUseElement(); + } DetachShadowTree(); ClearResourceReference(); - CancelShadowTreeRecreation(); - DCHECK(isConnected()); - auto* target = DynamicTo<SVGElement>(ResolveTargetElement(kAddObserver)); - if (target) { + if (auto* target = DynamicTo<SVGElement>(ResolveTargetElement())) { DCHECK(target->isConnected()); AttachShadowTree(*target); } @@ -438,7 +443,6 @@ SVGElement* SVGUseElement::CreateInstanceTree(SVGElement& target_root) const { void SVGUseElement::AttachShadowTree(SVGElement& target) { DCHECK(!InstanceRoot()); DCHECK(!needs_shadow_tree_recreation_); - DCHECK(!InUseShadowTree()); // Do not allow self-referencing. if (IsDisallowedElement(target) || HasCycleUseReferencing(*this, target)) @@ -449,17 +453,11 @@ void SVGUseElement::AttachShadowTree(SVGElement& target) { // <symbol> yet. UseShadowRoot().AppendChild(CreateInstanceTree(target)); - AddReferencesToFirstDegreeNestedUseElements(target); - // Assure shadow tree building was successful. DCHECK(InstanceRoot()); - DCHECK_EQ(InstanceRoot()->CorrespondingUseElement(), this); + DCHECK_EQ(InstanceRoot()->GeneratingUseElement(), this); DCHECK_EQ(InstanceRoot()->CorrespondingElement(), &target); - // Expand all <use> elements in the shadow tree. - // Expand means: replace the actual <use> element by what it references. - ExpandUseElementsInShadowTree(); - for (SVGElement& instance : Traversal<SVGElement>::DescendantsOf(UseShadowRoot())) { SVGElement* corresponding_element = instance.CorrespondingElement(); @@ -472,22 +470,10 @@ void SVGUseElement::AttachShadowTree(SVGElement& target) { // instance. corresponding_element->MapInstanceToElement(&instance); } - - // Update relative length information. - UpdateRelativeLengthsInformation(); } void SVGUseElement::DetachShadowTree() { ShadowRoot& shadow_root = UseShadowRoot(); - // Tear down the mapping from the corresponding (original) element back to - // the instance. - for (SVGElement& instance : - Traversal<SVGElement>::DescendantsOf(shadow_root)) { - // When the instances of an element are invalidated the corresponding - // element is cleared, so it can be null here. - if (SVGElement* corresponding_element = instance.CorrespondingElement()) - corresponding_element->RemoveInstanceMapping(&instance); - } // FIXME: We should try to optimize this, to at least allow partial reclones. shadow_root.RemoveChildren(kOmitSubtreeModifiedEvent); } @@ -506,11 +492,12 @@ static bool IsDirectReference(const SVGElement& element) { Path SVGUseElement::ToClipPath() const { const SVGGraphicsElement* element = VisibleTargetGraphicsElementForClipping(); - if (!element || !element->IsSVGGeometryElement()) + auto* geometry_element = DynamicTo<SVGGeometryElement>(element); + if (!geometry_element) return Path(); DCHECK(GetLayoutObject()); - Path path = ToSVGGeometryElement(*element).ToClipPath(); + Path path = geometry_element->ToClipPath(); AffineTransform transform = GetLayoutObject()->LocalSVGTransform(); if (!transform.IsIdentity()) path.Transform(transform); @@ -535,24 +522,6 @@ SVGGraphicsElement* SVGUseElement::VisibleTargetGraphicsElementForClipping() return svg_graphics_element; } -void SVGUseElement::AddReferencesToFirstDegreeNestedUseElements( - SVGElement& target) { - // Don't track references to external documents. - if (IsStructurallyExternal()) - return; - // We only need to track first degree <use> dependencies. Indirect - // references are handled as the invalidation bubbles up the dependency - // chain. - SVGUseElement* use_element = - IsA<SVGUseElement>(target) - ? To<SVGUseElement>(&target) - : Traversal<SVGUseElement>::FirstWithin(target); - for (; use_element; - use_element = Traversal<SVGUseElement>::NextSkippingChildren( - *use_element, &target)) - AddReferenceTo(use_element); -} - bool SVGUseElement::HasCycleUseReferencing(const ContainerNode& target_instance, const SVGElement& target) const { // Shortcut for self-references @@ -571,61 +540,6 @@ bool SVGUseElement::HasCycleUseReferencing(const ContainerNode& target_instance, return false; } -// Spec: In the generated content, the 'use' will be replaced by 'g', where all -// attributes from the 'use' element except for x, y, width, height and -// xlink:href are transferred to the generated 'g' element. -static void RemoveAttributesFromReplacementElement( - SVGElement& replacement_element) { - replacement_element.removeAttribute(svg_names::kXAttr); - replacement_element.removeAttribute(svg_names::kYAttr); - replacement_element.removeAttribute(svg_names::kWidthAttr); - replacement_element.removeAttribute(svg_names::kHeightAttr); - replacement_element.removeAttribute(svg_names::kHrefAttr); - replacement_element.removeAttribute(xlink_names::kHrefAttr); -} - -void SVGUseElement::ExpandUseElementsInShadowTree() { - // Why expand the <use> elements in the shadow tree here, and not just - // do this directly in buildShadowTree, if we encounter a <use> element? - // - // Short answer: Because we may miss to expand some elements. For example, if - // a <symbol> contains <use> tags, we'd miss them. So once we're done with - // setting up the actual shadow tree (after the special case modification for - // svg/symbol) we have to walk it completely and expand all <use> elements. - ShadowRoot& shadow_root = UseShadowRoot(); - for (SVGUseElement* use = Traversal<SVGUseElement>::FirstWithin(shadow_root); - use;) { - auto& original_use = To<SVGUseElement>(*use->CorrespondingElement()); - auto* target = DynamicTo<SVGElement>( - original_use.ResolveTargetElement(kDontAddObserver)); - if (target) { - if (IsDisallowedElement(*target) || HasCycleUseReferencing(*use, *target)) - return; - } - - // Don't DCHECK(target) here, it may be "pending", too. - // Setup sub-shadow tree root node - auto* clone_parent = - MakeGarbageCollected<SVGGElement>(original_use.GetDocument()); - // Transfer all data (attributes, etc.) from <use> to the new <g> element. - clone_parent->CloneAttributesFrom(*use); - clone_parent->SetCorrespondingElement(&original_use); - - RemoveAttributesFromReplacementElement(*clone_parent); - - // Move already cloned elements to the new <g> element. - MoveChildrenToReplacementElement(*use, *clone_parent); - - if (target) - clone_parent->AppendChild(use->CreateInstanceTree(*target)); - - // Replace <use> with referenced content. - use->parentNode()->ReplaceChild(clone_parent, use); - - use = Traversal<SVGUseElement>::Next(*clone_parent, &shadow_root); - } -} - bool SVGUseElement::ShadowTreeRebuildPending() const { // The shadow tree is torn down lazily, so check if there's a pending rebuild // or if we're disconnected from the document. @@ -636,30 +550,18 @@ void SVGUseElement::InvalidateShadowTree() { if (ShadowTreeRebuildPending()) return; ScheduleShadowTreeRecreation(); - InvalidateDependentShadowTrees(); -} - -void SVGUseElement::InvalidateDependentShadowTrees() { - // Recursively invalidate dependent <use> shadow trees - const HeapHashSet<WeakMember<SVGElement>>& raw_instances = - InstancesForElement(); - HeapVector<Member<SVGElement>> instances; - instances.AppendRange(raw_instances.begin(), raw_instances.end()); - for (auto& instance : instances) { - if (SVGUseElement* element = instance->CorrespondingUseElement()) { - DCHECK(element->isConnected()); - element->InvalidateShadowTree(); - } - } +} + +void SVGUseElement::InvalidateTargetReference() { + InvalidateShadowTree(); + for (SVGElement* instance : InstancesForElement()) + To<SVGUseElement>(instance)->InvalidateShadowTree(); } bool SVGUseElement::SelfHasRelativeLengths() const { - if (x_->CurrentValue()->IsRelative() || y_->CurrentValue()->IsRelative() || - width_->CurrentValue()->IsRelative() || - height_->CurrentValue()->IsRelative()) - return true; - SVGElement* instance_root = InstanceRoot(); - return instance_root && instance_root->HasRelativeLengths(); + return x_->CurrentValue()->IsRelative() || y_->CurrentValue()->IsRelative() || + width_->CurrentValue()->IsRelative() || + height_->CurrentValue()->IsRelative(); } FloatRect SVGUseElement::GetBBox() { @@ -723,7 +625,7 @@ bool SVGUseElement::ResourceIsValid() const { // TODO(fs): Handle revalidations that return a new/different resource. if (!resource->IsLoaded() && !resource->IsCacheValidator()) return false; - return ToDocumentResource(resource)->GetDocument(); + return To<DocumentResource>(resource)->GetDocument(); } } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/svg/svg_use_element.h b/chromium/third_party/blink/renderer/core/svg/svg_use_element.h index 3209a63904a..6d20db0dd8d 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_use_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_use_element.h @@ -45,6 +45,7 @@ class SVGUseElement final : public SVGGraphicsElement, ~SVGUseElement() override; void InvalidateShadowTree(); + void InvalidateTargetReference(); // Return the element that should be used for clipping, // or null if a valid clip element is not directly referenced. @@ -61,7 +62,7 @@ class SVGUseElement final : public SVGGraphicsElement, void DispatchPendingEvent(); Path ToClipPath() const; - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void Dispose(); @@ -96,12 +97,7 @@ class SVGUseElement final : public SVGGraphicsElement, return *ClosedShadowRoot(); } - // Instance tree handling - enum ObserveBehavior { - kAddObserver, - kDontAddObserver, - }; - Element* ResolveTargetElement(ObserveBehavior); + Element* ResolveTargetElement(); void AttachShadowTree(SVGElement& target); void DetachShadowTree(); CORE_EXPORT SVGElement* InstanceRoot() const; @@ -109,10 +105,6 @@ class SVGUseElement final : public SVGGraphicsElement, void ClearResourceReference(); bool HasCycleUseReferencing(const ContainerNode& target_instance, const SVGElement& new_target) const; - void ExpandUseElementsInShadowTree(); - void AddReferencesToFirstDegreeNestedUseElements(SVGElement& target); - - void InvalidateDependentShadowTrees(); bool ResourceIsValid() const; void NotifyFinished(Resource*) override; diff --git a/chromium/third_party/blink/renderer/core/svg/svg_use_element_test.cc b/chromium/third_party/blink/renderer/core/svg/svg_use_element_test.cc index 8d06d595899..e26665fc54a 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_use_element_test.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_use_element_test.cc @@ -12,12 +12,12 @@ namespace blink { -using LifecycleUpdateReason = DocumentLifecycle::LifecycleUpdateReason; +using LifecycleUpdateReason = DocumentUpdateReason; class SVGUseElementTest : public PageTestBase {}; TEST_F(SVGUseElementTest, InstanceInvalidatedWhenNonAttachedTargetRemoved) { - GetDocument().body()->SetInnerHTMLFromString(R"HTML( + GetDocument().body()->setInnerHTML(R"HTML( <style></style> <svg> <unknown> @@ -47,7 +47,7 @@ TEST_F(SVGUseElementTest, InstanceInvalidatedWhenNonAttachedTargetRemoved) { TEST_F(SVGUseElementTest, InstanceInvalidatedWhenNonAttachedTargetMovedInDocument) { - GetDocument().body()->SetInnerHTMLFromString(R"HTML( + GetDocument().body()->setInnerHTML(R"HTML( <svg> <use id="use" href="#path"/> <textPath id="path"> @@ -76,7 +76,7 @@ TEST_F(SVGUseElementTest, } TEST_F(SVGUseElementTest, NullInstanceRootWhenNotConnectedToDocument) { - GetDocument().body()->SetInnerHTMLFromString(R"HTML( + GetDocument().body()->setInnerHTML(R"HTML( <svg> <defs> <rect id="r" width="100" height="100" fill="blue"/> @@ -96,7 +96,7 @@ TEST_F(SVGUseElementTest, NullInstanceRootWhenNotConnectedToDocument) { } TEST_F(SVGUseElementTest, NullInstanceRootWhenConnectedToInactiveDocument) { - GetDocument().body()->SetInnerHTMLFromString(R"HTML( + GetDocument().body()->setInnerHTML(R"HTML( <svg> <defs> <rect id="r" width="100" height="100" fill="blue"/> @@ -118,7 +118,7 @@ TEST_F(SVGUseElementTest, NullInstanceRootWhenConnectedToInactiveDocument) { } TEST_F(SVGUseElementTest, NullInstanceRootWhenShadowTreePendingRebuild) { - GetDocument().body()->SetInnerHTMLFromString(R"HTML( + GetDocument().body()->setInnerHTML(R"HTML( <svg> <defs> <rect id="r" width="100" height="100" fill="blue"/> diff --git a/chromium/third_party/blink/renderer/core/svg/svg_view_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_view_element.cc index 6fb063483e0..ac872c18cd3 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_view_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_view_element.cc @@ -32,7 +32,7 @@ SVGViewElement::SVGViewElement(Document& document) UseCounter::Count(document, WebFeature::kSVGViewElement); } -void SVGViewElement::Trace(blink::Visitor* visitor) { +void SVGViewElement::Trace(Visitor* visitor) { SVGElement::Trace(visitor); SVGFitToViewBox::Trace(visitor); } diff --git a/chromium/third_party/blink/renderer/core/svg/svg_view_element.h b/chromium/third_party/blink/renderer/core/svg/svg_view_element.h index bdde4bf5682..f42c137721c 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_view_element.h +++ b/chromium/third_party/blink/renderer/core/svg/svg_view_element.h @@ -37,7 +37,7 @@ class SVGViewElement final : public SVGElement, public: explicit SVGViewElement(Document&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void ParseAttribute(const AttributeModificationParams&) override; diff --git a/chromium/third_party/blink/renderer/core/svg/unsafe_svg_attribute_sanitization_test.cc b/chromium/third_party/blink/renderer/core/svg/unsafe_svg_attribute_sanitization_test.cc index 20a4843225a..f34d987083d 100644 --- a/chromium/third_party/blink/renderer/core/svg/unsafe_svg_attribute_sanitization_test.cc +++ b/chromium/third_party/blink/renderer/core/svg/unsafe_svg_attribute_sanitization_test.cc @@ -7,6 +7,7 @@ #include <memory> #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/blink/public/common/browser_interface_broker_proxy.h" #include "third_party/blink/renderer/core/clipboard/system_clipboard.h" #include "third_party/blink/renderer/core/dom/qualified_name.h" #include "third_party/blink/renderer/core/editing/editor.h" @@ -20,10 +21,11 @@ #include "third_party/blink/renderer/core/svg/properties/svg_property_info.h" #include "third_party/blink/renderer/core/svg/svg_a_element.h" #include "third_party/blink/renderer/core/svg/svg_animate_element.h" -#include "third_party/blink/renderer/core/svg/svg_discard_element.h" #include "third_party/blink/renderer/core/svg/svg_set_element.h" #include "third_party/blink/renderer/core/svg_names.h" #include "third_party/blink/renderer/core/testing/dummy_page_holder.h" +#include "third_party/blink/renderer/core/testing/mock_clipboard_host.h" +#include "third_party/blink/renderer/core/testing/page_test_base.h" #include "third_party/blink/renderer/core/xlink_names.h" #include "third_party/blink/renderer/platform/geometry/int_size.h" #include "third_party/blink/renderer/platform/heap/heap.h" @@ -46,7 +48,6 @@ // The following SVG elements, although related to animation, cannot // set JavaScript URLs: // -// - 'discard' can only remove elements, not set their attributes // - 'animateMotion' does not use attribute name and produces floats // - 'animateTransform' can only animate transform lists @@ -57,12 +58,17 @@ namespace blink { String ContentAfterPastingHTML(DummyPageHolder* page_holder, const char* html_to_paste) { LocalFrame& frame = page_holder->GetFrame(); + + // Setup a mock clipboard host. + PageTestBase::MockClipboardHostProvider mock_clipboard_host_provider( + frame.GetBrowserInterfaceBroker()); + HTMLElement* body = page_holder->GetDocument().body(); // Make the body editable, and put the caret in it. body->setAttribute(html_names::kContenteditableAttr, "true"); body->focus(); - frame.GetDocument()->UpdateStyleAndLayout(); + frame.GetDocument()->UpdateStyleAndLayout(DocumentUpdateReason::kTest); frame.Selection().SetSelectionAndEndTyping( SelectionInDOMTree::Builder().SelectAllChildren(*body).Build()); EXPECT_TRUE(frame.Selection().ComputeVisibleSelectionInDOMTree().IsCaret()); @@ -70,15 +76,15 @@ String ContentAfterPastingHTML(DummyPageHolder* page_holder, frame.Selection().ComputeVisibleSelectionInDOMTree().IsContentEditable()) << "We should be pasting into something editable."; - SystemClipboard::GetInstance().WriteHTML( - html_to_paste, BlankURL(), "", SystemClipboard::kCannotSmartReplace); - SystemClipboard::GetInstance().CommitWrite(); + frame.GetSystemClipboard()->WriteHTML(html_to_paste, BlankURL(), "", + SystemClipboard::kCannotSmartReplace); + frame.GetSystemClipboard()->CommitWrite(); // Run all tasks in a message loop to allow asynchronous clipboard writing // to happen before reading from it synchronously. test::RunPendingTasks(); EXPECT_TRUE(frame.GetEditor().ExecuteCommand("Paste")); - return body->InnerHTMLAsString(); + return body->innerHTML(); } // Integration tests. |