1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 APPLE INC. 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.
*/
#pragma once
#include "CSSNumericValue.h"
#include "CSSPrimitiveValue.h"
#include "ScrollTimeline.h"
#include "Styleable.h"
#include "ViewTimelineOptions.h"
#include <wtf/Ref.h>
#include <wtf/WeakPtr.h>
namespace WebCore {
namespace Style {
class BuilderState;
}
class Element;
class StickyPositionViewportConstraints;
struct TimelineRange;
struct StickinessAdjustmentData {
bool operator==(const StickinessAdjustmentData& other) const = default;
enum class StickinessLocation {
BeforeEntry,
DuringEntry,
WhileContained,
DuringExit,
AfterExit
};
float entryDistanceAdjustment() const;
float exitDistanceAdjustment() const;
float rangeStartAdjustment() const;
float rangeEndAdjustment() const;
static StickinessAdjustmentData computeStickinessAdjustmentData(const StickyPositionViewportConstraints&, ScrollTimeline::ResolvedScrollDirection, float scrollContainerSize, float subjectSize, float subjectOffset);
float stickyTopOrLeftAdjustment { 0 };
StickinessLocation topOrLeftAdjustmentLocation { StickinessLocation::WhileContained };
float stickyBottomOrRightAdjustment { 0 };
StickinessLocation bottomOrRightAdjustmentLocation { StickinessLocation::WhileContained };
};
class ViewTimeline final : public ScrollTimeline {
public:
static ExceptionOr<Ref<ViewTimeline>> create(Document&, ViewTimelineOptions&& = { });
static Ref<ViewTimeline> create(const AtomString&, ScrollAxis, ViewTimelineInsets&&);
const Element* subject() const;
const WeakStyleable subjectStyleable() const { return m_subject; }
void setSubject(Element*);
void setSubject(const Styleable&);
const ViewTimelineInsets& insets() const { return m_insets; }
void setInsets(ViewTimelineInsets&& insets) { m_insets = WTFMove(insets); }
Ref<CSSNumericValue> startOffset() const;
Ref<CSSNumericValue> endOffset() const;
AnimationTimeline::ShouldUpdateAnimationsAndSendEvents documentWillUpdateAnimationsAndSendEvents() override;
AnimationTimelinesController* controller() const override;
const RenderBox* sourceScrollerRenderer() const;
const RenderElement* stickyContainer() const;
Element* source() const override;
TimelineRange defaultRange() const final;
std::pair<WebAnimationTime, WebAnimationTime> intervalForAttachmentRange(const TimelineRange&) const final;
std::pair<double, double> offsetIntervalForAttachmentRange(const TimelineRange&) const;
std::pair<double, double> offsetIntervalForTimelineRangeName(const SingleTimelineRange::Name) const;
private:
ScrollTimeline::Data computeTimelineData() const final;
std::pair<double, double> intervalForTimelineRangeName(const ScrollTimeline::Data&, const SingleTimelineRange::Name) const;
template<typename F> double mapOffsetToTimelineRange(const ScrollTimeline::Data&, const SingleTimelineRange::Name, F&&) const;
explicit ViewTimeline(ScrollAxis);
explicit ViewTimeline(const AtomString&, ScrollAxis, ViewTimelineInsets&&);
bool isViewTimeline() const final { return true; }
struct CurrentTimeData {
float scrollOffset { 0 };
float scrollContainerSize { 0 };
float subjectOffset { 0 };
float subjectSize { 0 };
float insetStart { 0 };
float insetEnd { 0 };
StickinessAdjustmentData stickinessData { };
};
void cacheCurrentTime();
struct SpecifiedViewTimelineInsets {
RefPtr<CSSPrimitiveValue> start;
RefPtr<CSSPrimitiveValue> end;
};
ExceptionOr<SpecifiedViewTimelineInsets> validateSpecifiedInsets(const ViewTimelineInsetValue, const Document&);
WeakStyleable m_subject;
std::optional<SpecifiedViewTimelineInsets> m_specifiedInsets;
ViewTimelineInsets m_insets;
CurrentTimeData m_cachedCurrentTimeData { };
};
WTF::TextStream& operator<<(WTF::TextStream&, const StickinessAdjustmentData&);
WTF::TextStream& operator<<(WTF::TextStream&, const StickinessAdjustmentData::StickinessLocation&);
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_ANIMATION_TIMELINE(ViewTimeline, isViewTimeline())
|