Bug 1737918 - Part 2: Replace StyleScrollDirection with StyleAxis. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D143418
This commit is contained in:
Boris Chiou 2022-04-20 20:28:53 +00:00
Родитель e8ad45ee42
Коммит 53830b1b34
2 изменённых файлов: 42 добавлений и 29 удалений

Просмотреть файл

@ -45,14 +45,14 @@ NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(ScrollTimeline,
TimingParams ScrollTimeline::sTiming;
ScrollTimeline::ScrollTimeline(Document* aDocument, const Scroller& aScroller,
StyleScrollDirection aDirection)
StyleScrollAxis aAxis)
: AnimationTimeline(aDocument->GetParentObject()),
mDocument(aDocument),
// FIXME: Bug 1737918: We may have to udpate the constructor arguments
// because this can be nearest, root, or a specific container. For now,
// the input is a source element directly and it is the root element.
mSource(aScroller),
mDirection(aDirection) {
mAxis(aAxis) {
MOZ_ASSERT(aDocument);
// Use default values except for |mDuration| and |mFill|.
@ -63,6 +63,28 @@ ScrollTimeline::ScrollTimeline(Document* aDocument, const Scroller& aScroller,
PlaybackDirection::Alternate, FillMode::Both);
}
static StyleScrollAxis ToStyleScrollAxis(
const StyleScrollDirection aDirection) {
switch (aDirection) {
// The spec defines auto, but there is a spec issue:
// "ISSUE 5 Define these values." in this section. The DOM interface removed
// auto and use block as default value, so we treat auto as block now.
// https://drafts.csswg.org/scroll-animations-1/#descdef-scroll-timeline-orientation
case StyleScrollDirection::Auto:
case StyleScrollDirection::Block:
return StyleScrollAxis::Block;
case StyleScrollDirection::Inline:
return StyleScrollAxis::Inline;
case StyleScrollDirection::Horizontal:
return StyleScrollAxis::Horizontal;
case StyleScrollDirection::Vertical:
return StyleScrollAxis::Vertical;
}
MOZ_ASSERT_UNREACHABLE("Unsupported StyleScrollDirection");
return StyleScrollAxis::Block;
}
already_AddRefed<ScrollTimeline> ScrollTimeline::FromRule(
const RawServoScrollTimelineRule& aRule, Document* aDocument,
const NonOwningAnimationTarget& aTarget) {
@ -73,8 +95,8 @@ already_AddRefed<ScrollTimeline> ScrollTimeline::FromRule(
// dropped automatically becuase no animation owns it and its ref-count
// becomes zero.
StyleScrollDirection direction =
Servo_ScrollTimelineRule_GetOrientation(&aRule);
StyleScrollAxis axis =
ToStyleScrollAxis(Servo_ScrollTimelineRule_GetOrientation(&aRule));
// FIXME: Bug 1737918: applying new spec update, e.g. other scrollers and
// other style values.
@ -82,10 +104,10 @@ already_AddRefed<ScrollTimeline> ScrollTimeline::FromRule(
auto autoScroller = Scroller::Auto(aTarget.mElement->OwnerDoc());
auto* set =
ScrollTimelineSet::GetOrCreateScrollTimelineSet(autoScroller.mElement);
auto p = set->LookupForAdd(direction);
auto p = set->LookupForAdd(axis);
if (!p) {
timeline = new ScrollTimeline(aDocument, autoScroller, direction);
set->Add(p, direction, timeline);
timeline = new ScrollTimeline(aDocument, autoScroller, axis);
set->Add(p, axis, timeline);
} else {
timeline = p->value();
}
@ -134,12 +156,9 @@ layers::ScrollDirection ScrollTimeline::Axis() const {
MOZ_ASSERT(mSource && mSource.mElement->GetPrimaryFrame());
const WritingMode wm = mSource.mElement->GetPrimaryFrame()->GetWritingMode();
return mDirection == StyleScrollDirection::Horizontal ||
(!wm.IsVertical() &&
mDirection == StyleScrollDirection::Inline) ||
(wm.IsVertical() &&
(mDirection == StyleScrollDirection::Block ||
mDirection == StyleScrollDirection::Auto))
return mAxis == StyleScrollAxis::Horizontal ||
(!wm.IsVertical() && mAxis == StyleScrollAxis::Inline) ||
(wm.IsVertical() && mAxis == StyleScrollAxis::Block)
? layers::ScrollDirection::eHorizontal
: layers::ScrollDirection::eVertical;
}
@ -177,7 +196,7 @@ void ScrollTimeline::UnregisterFromScrollSource() {
if (ScrollTimelineSet* scrollTimelineSet =
ScrollTimelineSet::GetScrollTimelineSet(mSource.mElement)) {
scrollTimelineSet->Remove(mDirection);
scrollTimelineSet->Remove(mAxis);
if (scrollTimelineSet->IsEmpty()) {
ScrollTimelineSet::DestroyScrollTimelineSet(mSource.mElement);
}

Просмотреть файл

@ -99,7 +99,7 @@ class ScrollTimeline final : public AnimationTimeline {
bool operator==(const ScrollTimeline& aOther) const {
return mDocument == aOther.mDocument && mSource == aOther.mSource &&
mDirection == aOther.mDirection;
mAxis == aOther.mAxis;
}
NS_DECL_ISUPPORTS_INHERITED
@ -154,11 +154,6 @@ class ScrollTimeline final : public AnimationTimeline {
}
// A helper to get the physical orientation of this scroll-timeline.
//
// The spec defines auto, but there is a spec issue:
// "ISSUE 5 Define these values." in this section. The DOM interface removed
// auto and use block as default value, so we treat auto as block now.
// https://drafts.csswg.org/scroll-animations-1/#descdef-scroll-timeline-orientation
layers::ScrollDirection Axis() const;
StyleOverflow SourceScrollStyle() const;
@ -175,7 +170,7 @@ class ScrollTimeline final : public AnimationTimeline {
private:
ScrollTimeline() = delete;
ScrollTimeline(Document* aDocument, const Scroller& aScroller,
StyleScrollDirection aDirection);
StyleScrollAxis aAxis);
// Note: This function is required to be idempotent, as it can be called from
// both cycleCollection::Unlink() and ~ScrollTimeline(). When modifying this
@ -196,7 +191,7 @@ class ScrollTimeline final : public AnimationTimeline {
// 2. "scroll-offsets" is none (i.e. always 0% ~ 100%).
// So now we will only use the scroll direction from @scroll-timeline rule.
Scroller mSource;
StyleScrollDirection mDirection;
StyleScrollAxis mAxis;
// Note: it's unfortunate TimingParams cannot be a const variable because
// we have to use StickyTimingDuration::FromMilliseconds() in its
@ -220,16 +215,15 @@ class ScrollTimeline final : public AnimationTimeline {
*/
class ScrollTimelineSet {
public:
// Use StyleScrollDirection as the key, so we reuse the ScrollTimeline with
// the same source and the same direction.
// Use StyleScrollAxis as the key, so we reuse the ScrollTimeline with the
// same source and the same direction.
// Note: the drawback of using the direction as the key is that we have to
// update this once we support more descriptors. This implementation assumes
// scroll-offsets will be obsolute. However, I'm pretty sure @scroll-timeline
// will be obsolute, based on the spec issue. We may have to do a lot of
// updates after the spec updates, so this tentative implmentation should be
// enough for now.
using NonOwningScrollTimelineMap =
HashMap<StyleScrollDirection, ScrollTimeline*>;
using NonOwningScrollTimelineMap = HashMap<StyleScrollAxis, ScrollTimeline*>;
~ScrollTimelineSet() = default;
@ -237,14 +231,14 @@ class ScrollTimelineSet {
static ScrollTimelineSet* GetOrCreateScrollTimelineSet(Element* aElement);
static void DestroyScrollTimelineSet(Element* aElement);
NonOwningScrollTimelineMap::AddPtr LookupForAdd(StyleScrollDirection aKey) {
NonOwningScrollTimelineMap::AddPtr LookupForAdd(StyleScrollAxis aKey) {
return mScrollTimelines.lookupForAdd(aKey);
}
void Add(NonOwningScrollTimelineMap::AddPtr& aPtr, StyleScrollDirection aKey,
void Add(NonOwningScrollTimelineMap::AddPtr& aPtr, StyleScrollAxis aKey,
ScrollTimeline* aScrollTimeline) {
Unused << mScrollTimelines.add(aPtr, aKey, aScrollTimeline);
}
void Remove(StyleScrollDirection aKey) { mScrollTimelines.remove(aKey); }
void Remove(StyleScrollAxis aKey) { mScrollTimelines.remove(aKey); }
bool IsEmpty() const { return mScrollTimelines.empty(); }