Skip to content

Commit

Permalink
Remove Scroll/ViewTimelineAttachment
Browse files Browse the repository at this point in the history
Since these classes were introduced we've changed the model
for deferred timeline attachment, and removed the *-attachment
properties. They no longer serve any purpose, so they can be
removed.

There should be no behavior change.

Change-Id: Ica59be48ace8d30dd881d517b78a49d55d78a37e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4793831
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: Robert Flack <flackr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1185359}
  • Loading branch information
andruud authored and Chromium LUCI CQ committed Aug 18, 2023
1 parent e03091a commit ba43664
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 255 deletions.
4 changes: 0 additions & 4 deletions third_party/blink/renderer/core/animation/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ blink_core_sources("animation") {
"scroll_snapshot_timeline.h",
"scroll_timeline.cc",
"scroll_timeline.h",
"scroll_timeline_attachment.cc",
"scroll_timeline_attachment.h",
"scroll_timeline_util.cc",
"scroll_timeline_util.h",
"side_index.h",
Expand Down Expand Up @@ -313,8 +311,6 @@ blink_core_sources("animation") {
"underlying_value_owner.h",
"view_timeline.cc",
"view_timeline.h",
"view_timeline_attachment.cc",
"view_timeline_attachment.h",
"worklet_animation_base.h",
"worklet_animation_controller.cc",
"worklet_animation_controller.h",
Expand Down
84 changes: 55 additions & 29 deletions third_party/blink/renderer/core/animation/scroll_timeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_scroll_timeline_options.h"
#include "third_party/blink/renderer/core/animation/scroll_timeline_util.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
Expand Down Expand Up @@ -73,22 +75,13 @@ ScrollTimeline::ScrollTimeline(Document* document,
ReferenceType reference_type,
Element* reference,
ScrollAxis axis)
: ScrollTimeline(
document,
MakeGarbageCollected<ScrollTimelineAttachment>(reference_type,
reference,
axis)) {}

ScrollTimeline::ScrollTimeline(Document* document,
ScrollTimelineAttachment* attachment)
: ScrollSnapshotTimeline(document) {
if (attachment) {
attachments_.push_back(attachment);
}
}
: ScrollSnapshotTimeline(document),
reference_type_(reference_type),
reference_element_(reference),
axis_(axis) {}

Element* ScrollTimeline::RetainingElement() const {
return CurrentAttachment()->GetReferenceElement();
return reference_element_;
}

// TODO(crbug.com/1060384): This section is missing from the spec rewrite.
Expand Down Expand Up @@ -174,7 +167,49 @@ void ScrollTimeline::CalculateOffsets(PaintLayerScrollableArea* scrollable_area,
}

Element* ScrollTimeline::source() const {
return CurrentAttachment() ? CurrentAttachment()->ComputeSource() : nullptr;
return ComputeSource();
}

Element* ScrollTimeline::ComputeSource() const {
if (reference_type_ == ReferenceType::kNearestAncestor &&
reference_element_) {
reference_element_->GetDocument().UpdateStyleAndLayout(
DocumentUpdateReason::kJavaScript);
}
return ComputeSourceNoLayout();
}

Element* ScrollTimeline::ComputeSourceNoLayout() const {
if (reference_type_ == ReferenceType::kSource) {
return reference_element_.Get();
}
DCHECK_EQ(ReferenceType::kNearestAncestor, reference_type_);

if (!reference_element_) {
return nullptr;
}

LayoutObject* layout_object = reference_element_->GetLayoutObject();
if (!layout_object) {
return nullptr;
}

const LayoutBox* scroll_container =
layout_object->ContainingScrollContainer();
if (!scroll_container) {
return reference_element_->GetDocument().ScrollingElementNoLayout();
}

Node* node = scroll_container->GetNode();
if (node->IsElementNode()) {
return DynamicTo<Element>(node);
}
if (node->IsDocumentNode()) {
return DynamicTo<Document>(node)->ScrollingElementNoLayout();
}

NOTREACHED();
return nullptr;
}

void ScrollTimeline::AnimationAttached(Animation* animation) {
Expand All @@ -194,32 +229,23 @@ void ScrollTimeline::AnimationDetached(Animation* animation) {
}

Node* ScrollTimeline::ComputeResolvedSource() const {
if (!CurrentAttachment()) {
return nullptr;
}
return ResolveSource(CurrentAttachment()->ComputeSourceNoLayout());
return ResolveSource(ComputeSourceNoLayout());
}

void ScrollTimeline::Trace(Visitor* visitor) const {
visitor->Trace(attachments_);
visitor->Trace(reference_element_);
ScrollSnapshotTimeline::Trace(visitor);
}

bool ScrollTimeline::Matches(ReferenceType reference_type,
Element* reference_element,
ScrollAxis axis) const {
const ScrollTimelineAttachment* attachment = CurrentAttachment();
DCHECK(attachment);
return (attachment->GetReferenceType() == reference_type) &&
(attachment->GetReferenceElement() == reference_element) &&
(attachment->GetAxis() == axis);
return (reference_type_ == reference_type) &&
(reference_element_ == reference_element) && (axis_ == axis);
}

ScrollAxis ScrollTimeline::GetAxis() const {
if (const ScrollTimelineAttachment* attachment = CurrentAttachment()) {
return attachment->GetAxis();
}
return ScrollAxis::kBlock;
return axis_;
}

absl::optional<double> ScrollTimeline::GetMaximumScrollPosition() const {
Expand Down
33 changes: 19 additions & 14 deletions third_party/blink/renderer/core/animation/scroll_timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_scroll_axis.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_typedefs.h"
#include "third_party/blink/renderer/core/animation/scroll_snapshot_timeline.h"
#include "third_party/blink/renderer/core/animation/scroll_timeline_attachment.h"
#include "third_party/blink/renderer/core/animation/timing.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/scroll/scroll_types.h"
Expand All @@ -22,7 +21,6 @@ namespace blink {
class Element;
class PaintLayerScrollableArea;
class ScrollTimelineOptions;
class ScrollTimelineAttachment;

// Implements the ScrollTimeline concept from the Scroll-linked Animations spec.
//
Expand All @@ -37,7 +35,13 @@ class CORE_EXPORT ScrollTimeline : public ScrollSnapshotTimeline {
DEFINE_WRAPPERTYPEINFO();

public:
using ReferenceType = ScrollTimelineAttachment::ReferenceType;
// Indicates the relation between the reference element and source of the
// scroll timeline.
enum class ReferenceType {
kSource, // The reference element matches the source.
kNearestAncestor // The source is the nearest scrollable ancestor to the
// reference element.
};

static constexpr double kScrollTimelineMicrosecondsPerPixel =
cc::ScrollTimeline::kScrollTimelineMicrosecondsPerPixel;
Expand Down Expand Up @@ -75,17 +79,7 @@ class CORE_EXPORT ScrollTimeline : public ScrollSnapshotTimeline {

void Trace(Visitor*) const override;

ScrollTimelineAttachment* CurrentAttachment() {
return (attachments_.size() == 1u) ? attachments_.back().Get() : nullptr;
}

const ScrollTimelineAttachment* CurrentAttachment() const {
return const_cast<ScrollTimeline*>(this)->CurrentAttachment();
}

protected:
ScrollTimeline(Document*, ScrollTimelineAttachment*);

Node* ComputeResolvedSource() const;

// Scroll offsets corresponding to 0% and 100% progress. By default, these
Expand All @@ -94,6 +88,15 @@ class CORE_EXPORT ScrollTimeline : public ScrollSnapshotTimeline {
ScrollOrientation physical_orientation,
TimelineState* state) const;

// Determines the source for the scroll timeline. It may be the reference
// element or its nearest scrollable ancestor, depending on |reference_type_|.
Element* ComputeSource() const;
// This version does not force a style update and is therefore safe to call
// during lifecycle update.
Element* ComputeSourceNoLayout() const;

Element* GetReferenceElement() const { return reference_element_.Get(); }

private:
FRIEND_TEST_ALL_PREFIXES(ScrollTimelineTest, MultipleScrollOffsetsClamping);
FRIEND_TEST_ALL_PREFIXES(ScrollTimelineTest, ResolveScrollOffsets);
Expand All @@ -106,7 +109,9 @@ class CORE_EXPORT ScrollTimeline : public ScrollSnapshotTimeline {

TimelineState ComputeTimelineState() const override;

HeapVector<Member<ScrollTimelineAttachment>, 1> attachments_;
ReferenceType reference_type_;
Member<Element> reference_element_;
ScrollAxis axis_;
};

template <>
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit ba43664

Please sign in to comment.