Bug 1754897 - Part 5: Factor out the creation of ScrollTimeline object. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D146967
This commit is contained in:
Boris Chiou 2022-06-13 20:26:46 +00:00
Родитель 2b8751f919
Коммит b6e80527ff
2 изменённых файлов: 27 добавлений и 35 удалений

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

@ -61,6 +61,25 @@ ScrollTimeline::ScrollTimeline(Document* aDocument, const Scroller& aScroller,
PlaybackDirection::Alternate, FillMode::Both); PlaybackDirection::Alternate, FillMode::Both);
} }
/* static */
already_AddRefed<ScrollTimeline> ScrollTimeline::GetOrCreateScrollTimeline(
Document* aDocument, const Scroller& aScroller,
const StyleScrollAxis& aAxis) {
MOZ_ASSERT(aScroller);
RefPtr<ScrollTimeline> timeline;
auto* set =
ScrollTimelineSet::GetOrCreateScrollTimelineSet(aScroller.mElement);
auto p = set->LookupForAdd(aAxis);
if (!p) {
timeline = new ScrollTimeline(aDocument, aScroller, aAxis);
set->Add(p, aAxis, timeline);
} else {
timeline = p->value();
}
return timeline.forget();
}
static StyleScrollAxis ToStyleScrollAxis( static StyleScrollAxis ToStyleScrollAxis(
const StyleScrollDirection aDirection) { const StyleScrollDirection aDirection) {
switch (aDirection) { switch (aDirection) {
@ -83,6 +102,7 @@ static StyleScrollAxis ToStyleScrollAxis(
return StyleScrollAxis::Block; return StyleScrollAxis::Block;
} }
/* static */
already_AddRefed<ScrollTimeline> ScrollTimeline::FromRule( already_AddRefed<ScrollTimeline> ScrollTimeline::FromRule(
const RawServoScrollTimelineRule& aRule, Document* aDocument, const RawServoScrollTimelineRule& aRule, Document* aDocument,
const NonOwningAnimationTarget& aTarget) { const NonOwningAnimationTarget& aTarget) {
@ -96,18 +116,8 @@ already_AddRefed<ScrollTimeline> ScrollTimeline::FromRule(
StyleScrollAxis axis = StyleScrollAxis axis =
ToStyleScrollAxis(Servo_ScrollTimelineRule_GetOrientation(&aRule)); ToStyleScrollAxis(Servo_ScrollTimelineRule_GetOrientation(&aRule));
RefPtr<ScrollTimeline> timeline;
auto autoScroller = Scroller::Root(aTarget.mElement->OwnerDoc()); auto autoScroller = Scroller::Root(aTarget.mElement->OwnerDoc());
auto* set = return GetOrCreateScrollTimeline(aDocument, autoScroller, axis);
ScrollTimelineSet::GetOrCreateScrollTimelineSet(autoScroller.mElement);
auto p = set->LookupForAdd(axis);
if (!p) {
timeline = new ScrollTimeline(aDocument, autoScroller, axis);
set->Add(p, axis, timeline);
} else {
timeline = p->value();
}
return timeline.forget();
} }
/* static */ /* static */
@ -135,18 +145,7 @@ already_AddRefed<ScrollTimeline> ScrollTimeline::FromAnonymousScroll(
scroller = Scroller::Nearest(curr ? curr : root); scroller = Scroller::Nearest(curr ? curr : root);
} }
} }
return GetOrCreateScrollTimeline(aDocument, scroller, aAxis);
RefPtr<ScrollTimeline> timeline;
auto* set =
ScrollTimelineSet::GetOrCreateScrollTimelineSet(scroller.mElement);
auto p = set->LookupForAdd(aAxis);
if (!p) {
timeline = new ScrollTimeline(aDocument, scroller, aAxis);
set->Add(p, aAxis, timeline);
} else {
timeline = p->value();
}
return timeline.forget();
} }
/* static*/ already_AddRefed<ScrollTimeline> ScrollTimeline::FromNamedScroll( /* static*/ already_AddRefed<ScrollTimeline> ScrollTimeline::FromNamedScroll(
@ -202,18 +201,7 @@ already_AddRefed<ScrollTimeline> ScrollTimeline::FromAnonymousScroll(
return nullptr; return nullptr;
} }
Scroller scroller = Scroller::Named(result); Scroller scroller = Scroller::Named(result);
return GetOrCreateScrollTimeline(aDocument, scroller, axis);
RefPtr<ScrollTimeline> timeline;
auto* set =
ScrollTimelineSet::GetOrCreateScrollTimelineSet(scroller.mElement);
auto p = set->LookupForAdd(axis);
if (!p) {
timeline = new ScrollTimeline(aDocument, scroller, axis);
set->Add(p, axis, timeline);
} else {
timeline = p->value();
}
return timeline.forget();
} }
Nullable<TimeDuration> ScrollTimeline::GetCurrentTimeAsDuration() const { Nullable<TimeDuration> ScrollTimeline::GetCurrentTimeAsDuration() const {

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

@ -186,6 +186,10 @@ class ScrollTimeline final : public AnimationTimeline {
ScrollTimeline(Document* aDocument, const Scroller& aScroller, ScrollTimeline(Document* aDocument, const Scroller& aScroller,
StyleScrollAxis aAxis); StyleScrollAxis aAxis);
static already_AddRefed<ScrollTimeline> GetOrCreateScrollTimeline(
Document* aDocument, const Scroller& aScroller,
const StyleScrollAxis& aAxis);
// Note: This function is required to be idempotent, as it can be called from // Note: This function is required to be idempotent, as it can be called from
// both cycleCollection::Unlink() and ~ScrollTimeline(). When modifying this // both cycleCollection::Unlink() and ~ScrollTimeline(). When modifying this
// function, be sure to preserve this property. // function, be sure to preserve this property.