Skip to content

Commit

Permalink
cc: Replace base::Optional and friends with absl counterparts
Browse files Browse the repository at this point in the history
This replaces:
- base::Optional -> absl::optional
- include "base/optional.h"
  ->
  include "third_party/abseil-cpp/absl/types/optional.h"
- base::nullopt -> absl::nullopt
- base::make_optional -> absl::make_optional

Bug: 1202909
Change-Id: I09475b2f0a2610914baac55d571c515a42d2dc06
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2897879
Commit-Queue: Anton Bikineev <bikineev@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Anton Bikineev <bikineev@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Owners-Override: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#883197}
  • Loading branch information
Anton Bikineev authored and Chromium LUCI CQ committed May 14, 2021
1 parent ec4dec4 commit 1b060a7
Show file tree
Hide file tree
Showing 137 changed files with 520 additions and 519 deletions.
2 changes: 1 addition & 1 deletion cc/animation/animation_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CC_ANIMATION_EXPORT AnimationDelegate {
base::TimeTicks animation_start_time,
std::unique_ptr<gfx::AnimationCurve> curve) = 0;
virtual void NotifyLocalTimeUpdated(
base::Optional<base::TimeDelta> local_time) = 0;
absl::optional<base::TimeDelta> local_time) = 0;

protected:
virtual ~AnimationDelegate() {}
Expand Down
2 changes: 1 addition & 1 deletion cc/animation/animation_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AnimationEvent::AnimationEvent(AnimationEvent::Type type,

AnimationEvent::AnimationEvent(int timeline_id,
int animation_id,
base::Optional<base::TimeDelta> local_time)
absl::optional<base::TimeDelta> local_time)
: type(TIME_UPDATED),
// Initializing model_id with an invalid value (0).
// Also initializing keyframe_id with 0 which in its case is a valid
Expand Down
4 changes: 2 additions & 2 deletions cc/animation/animation_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct CC_ANIMATION_EXPORT AnimationEvent {
// Constructs AnimationEvent of TIME_UPDATED type.
AnimationEvent(int timeline_id,
int animation_id,
base::Optional<base::TimeDelta> local_time);
absl::optional<base::TimeDelta> local_time);

AnimationEvent(const AnimationEvent& other);
AnimationEvent& operator=(const AnimationEvent& other);
Expand All @@ -54,7 +54,7 @@ struct CC_ANIMATION_EXPORT AnimationEvent {
std::unique_ptr<gfx::AnimationCurve> curve;

// Set for TIME_UPDATED events.
base::Optional<base::TimeDelta> local_time;
absl::optional<base::TimeDelta> local_time;
};

class CC_ANIMATION_EXPORT AnimationEvents : public MutatorEvents {
Expand Down
4 changes: 2 additions & 2 deletions cc/animation/keyframe_effect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void KeyframeEffect::RemoveFromTicking() {
is_ticking_ = false;
// Resetting last_tick_time_ here ensures that calling ::UpdateState
// before ::Animate doesn't start a keyframe model.
last_tick_time_ = base::nullopt;
last_tick_time_ = absl::nullopt;
animation_->RemoveFromTicking();
}

Expand All @@ -133,7 +133,7 @@ void KeyframeEffect::UpdateState(bool start_ready_keyframe_models,

// Animate hasn't been called, this happens if an element has been added
// between the Commit and Draw phases.
if (last_tick_time_ == base::nullopt)
if (last_tick_time_ == absl::nullopt)
start_ready_keyframe_models = false;

if (start_ready_keyframe_models)
Expand Down
2 changes: 1 addition & 1 deletion cc/animation/keyframe_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class CC_ANIMATION_EXPORT KeyframeEffect : public gfx::KeyframeEffect {
bool scroll_offset_animation_was_interrupted_;

bool is_ticking_;
base::Optional<base::TimeTicks> last_tick_time_;
absl::optional<base::TimeTicks> last_tick_time_;

bool needs_push_properties_;
};
Expand Down
2 changes: 1 addition & 1 deletion cc/animation/keyframe_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include <memory>
#include <string>

#include "base/optional.h"
#include "base/time/time.h"
#include "cc/animation/animation_export.h"
#include "cc/paint/element_id.h"
#include "cc/paint/paint_worklet_input.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/animation/keyframe/keyframe_model.h"

namespace cc {
Expand Down
8 changes: 4 additions & 4 deletions cc/animation/scroll_offset_animation_curve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ base::TimeDelta VelocityBasedDurationBound(gfx::Vector2dF old_delta,

} // namespace

base::Optional<double>
absl::optional<double>
ScrollOffsetAnimationCurve::animation_duration_for_testing_;

ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve(
const gfx::ScrollOffset& target_value,
AnimationType animation_type,
base::Optional<DurationBehavior> duration_behavior)
absl::optional<DurationBehavior> duration_behavior)
: target_value_(target_value),
animation_type_(animation_type),
duration_behavior_(duration_behavior),
Expand All @@ -161,7 +161,7 @@ ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve(
const gfx::ScrollOffset& target_value,
std::unique_ptr<TimingFunction> timing_function,
AnimationType animation_type,
base::Optional<DurationBehavior> duration_behavior)
absl::optional<DurationBehavior> duration_behavior)
: target_value_(target_value),
timing_function_(std::move(timing_function)),
animation_type_(animation_type),
Expand Down Expand Up @@ -227,7 +227,7 @@ base::TimeDelta ScrollOffsetAnimationCurve::EaseInOutBoundedSegmentDuration(
base::TimeDelta ScrollOffsetAnimationCurve::SegmentDuration(
const gfx::Vector2dF& delta,
base::TimeDelta delayed_by,
base::Optional<double> velocity) {
absl::optional<double> velocity) {
switch (animation_type_) {
case AnimationType::kEaseInOut:
DCHECK(duration_behavior_.has_value());
Expand Down
10 changes: 5 additions & 5 deletions cc/animation/scroll_offset_animation_curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ class CC_ANIMATION_EXPORT ScrollOffsetAnimationCurve
ScrollOffsetAnimationCurve(
const gfx::ScrollOffset& target_value,
AnimationType animation_type,
base::Optional<DurationBehavior> duration_behavior = base::nullopt);
absl::optional<DurationBehavior> duration_behavior = absl::nullopt);
ScrollOffsetAnimationCurve(
const gfx::ScrollOffset& target_value,
std::unique_ptr<gfx::TimingFunction> timing_function,
AnimationType animation_type,
base::Optional<DurationBehavior> duration_behavior);
absl::optional<DurationBehavior> duration_behavior);

base::TimeDelta SegmentDuration(
const gfx::Vector2dF& delta,
base::TimeDelta delayed_by,
base::Optional<double> velocity = base::nullopt);
absl::optional<double> velocity = absl::nullopt);

base::TimeDelta EaseInOutBoundedSegmentDuration(
const gfx::Vector2dF& new_delta,
Expand All @@ -155,11 +155,11 @@ class CC_ANIMATION_EXPORT ScrollOffsetAnimationCurve
AnimationType animation_type_;

// Only valid when |animation_type_| is EASE_IN_OUT.
base::Optional<DurationBehavior> duration_behavior_;
absl::optional<DurationBehavior> duration_behavior_;

bool has_set_initial_value_;

static base::Optional<double> animation_duration_for_testing_;
static absl::optional<double> animation_duration_for_testing_;

Target* target_ = nullptr;
};
Expand Down
2 changes: 1 addition & 1 deletion cc/animation/scroll_offset_animations_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CC_ANIMATION_EXPORT ScrollOffsetAnimationsImpl
base::TimeTicks animation_start_time,
std::unique_ptr<gfx::AnimationCurve> curve) override {}
void NotifyLocalTimeUpdated(
base::Optional<base::TimeDelta> local_time) override {}
absl::optional<base::TimeDelta> local_time) override {}

bool IsAnimating() const;
ElementId GetElementId() const;
Expand Down
12 changes: 6 additions & 6 deletions cc/animation/scroll_timeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ template double ComputeProgress<std::vector<double>>(
double,
const std::vector<double>&);

ScrollTimeline::ScrollTimeline(base::Optional<ElementId> scroller_id,
ScrollTimeline::ScrollTimeline(absl::optional<ElementId> scroller_id,
ScrollDirection direction,
const std::vector<double> scroll_offsets,
double time_range,
Expand All @@ -53,7 +53,7 @@ ScrollTimeline::ScrollTimeline(base::Optional<ElementId> scroller_id,
ScrollTimeline::~ScrollTimeline() = default;

scoped_refptr<ScrollTimeline> ScrollTimeline::Create(
base::Optional<ElementId> scroller_id,
absl::optional<ElementId> scroller_id,
ScrollTimeline::ScrollDirection direction,
const std::vector<double> scroll_offsets,
double time_range) {
Expand Down Expand Up @@ -86,14 +86,14 @@ bool ScrollTimeline::IsActive(const ScrollTree& scroll_tree,
}

// https://drafts.csswg.org/scroll-animations-1/#current-time-algorithm
base::Optional<base::TimeTicks> ScrollTimeline::CurrentTime(
absl::optional<base::TimeTicks> ScrollTimeline::CurrentTime(
const ScrollTree& scroll_tree,
bool is_active_tree) const {
// If the timeline is not active return unresolved value by the spec.
// https://github.com/WICG/scroll-animations/issues/31
// https://wicg.github.io/scroll-animations/#current-time-algorithm
if (!IsActive(scroll_tree, is_active_tree))
return base::nullopt;
return absl::nullopt;

ElementId scroller_id =
is_active_tree ? active_id_.value() : pending_id_.value();
Expand Down Expand Up @@ -175,7 +175,7 @@ bool ScrollTimeline::TickScrollLinkedAnimations(
const std::vector<scoped_refptr<Animation>>& ticking_animations,
const ScrollTree& scroll_tree,
bool is_active_tree) {
base::Optional<base::TimeTicks> tick_time =
absl::optional<base::TimeTicks> tick_time =
CurrentTime(scroll_tree, is_active_tree);
if (!tick_time)
return false;
Expand Down Expand Up @@ -204,7 +204,7 @@ bool ScrollTimeline::TickScrollLinkedAnimations(
}

void ScrollTimeline::UpdateScrollerIdAndScrollOffsets(
base::Optional<ElementId> pending_id,
absl::optional<ElementId> pending_id,
const std::vector<double> scroll_offsets) {
if (pending_id_ == pending_id && scroll_offsets_ == scroll_offsets) {
return;
Expand Down
28 changes: 14 additions & 14 deletions cc/animation/scroll_timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#define CC_ANIMATION_SCROLL_TIMELINE_H_

#include <vector>
#include "base/optional.h"
#include "base/time/time.h"
#include "cc/animation/animation_export.h"
#include "cc/animation/animation_timeline.h"
#include "cc/animation/keyframe_model.h"
#include "cc/paint/element_id.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace cc {

Expand All @@ -35,14 +35,14 @@ class CC_ANIMATION_EXPORT ScrollTimeline : public AnimationTimeline {
ScrollRight,
};

ScrollTimeline(base::Optional<ElementId> scroller_id,
ScrollTimeline(absl::optional<ElementId> scroller_id,
ScrollDirection direction,
const std::vector<double> scroll_offsets,
double time_range,
int animation_timeline_id);

static scoped_refptr<ScrollTimeline> Create(
base::Optional<ElementId> scroller_id,
absl::optional<ElementId> scroller_id,
ScrollDirection direction,
const std::vector<double> scroll_offsets,
double time_range);
Expand All @@ -57,15 +57,15 @@ class CC_ANIMATION_EXPORT ScrollTimeline : public AnimationTimeline {
bool is_active_tree) const;

// Calculate the current time of the ScrollTimeline. This is either a
// base::TimeTicks value or base::nullopt if the current time is unresolved.
// base::TimeTicks value or absl::nullopt if the current time is unresolved.
// The internal calculations are performed using doubles and the result is
// converted to base::TimeTicks. This limits the precision to 1us.
virtual base::Optional<base::TimeTicks> CurrentTime(
virtual absl::optional<base::TimeTicks> CurrentTime(
const ScrollTree& scroll_tree,
bool is_active_tree) const;

void UpdateScrollerIdAndScrollOffsets(
base::Optional<ElementId> scroller_id,
absl::optional<ElementId> scroller_id,
const std::vector<double> scroll_offsets);

void PushPropertiesTo(AnimationTimeline* impl_timeline) override;
Expand All @@ -76,17 +76,17 @@ class CC_ANIMATION_EXPORT ScrollTimeline : public AnimationTimeline {
const ScrollTree& scroll_tree,
bool is_active_tree) override;

base::Optional<ElementId> GetActiveIdForTest() const { return active_id_; }
base::Optional<ElementId> GetPendingIdForTest() const { return pending_id_; }
absl::optional<ElementId> GetActiveIdForTest() const { return active_id_; }
absl::optional<ElementId> GetPendingIdForTest() const { return pending_id_; }
ScrollDirection GetDirectionForTest() const { return direction_; }
base::Optional<double> GetStartScrollOffsetForTest() const {
absl::optional<double> GetStartScrollOffsetForTest() const {
if (scroll_offsets_.empty())
return base::nullopt;
return absl::nullopt;
return scroll_offsets_[0];
}
base::Optional<double> GetEndScrollOffsetForTest() const {
absl::optional<double> GetEndScrollOffsetForTest() const {
if (scroll_offsets_.empty())
return base::nullopt;
return absl::nullopt;
return scroll_offsets_[1];
}
double GetTimeRangeForTest() const { return time_range_; }
Expand All @@ -100,8 +100,8 @@ class CC_ANIMATION_EXPORT ScrollTimeline : public AnimationTimeline {
// The scroller which this ScrollTimeline is based on. The same underlying
// scroll source may have different ids in the pending and active tree (see
// http://crbug.com/847588).
base::Optional<ElementId> active_id_;
base::Optional<ElementId> pending_id_;
absl::optional<ElementId> active_id_;
absl::optional<ElementId> pending_id_;

// The direction of the ScrollTimeline indicates which axis of the scroller
// it should base its current time on, and where the origin point is.
Expand Down
6 changes: 3 additions & 3 deletions cc/animation/scroll_timeline_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ double CalculateCurrentTime(double current_scroll_offset,
// Helper method to convert base::TimeTicks to double.
// Returns double milliseconds if the input value is resolved or
// std::numeric_limits<double>::quiet_NaN() otherwise.
double ToDouble(base::Optional<base::TimeTicks> time_ticks) {
double ToDouble(absl::optional<base::TimeTicks> time_ticks) {
if (time_ticks)
return (time_ticks.value() - base::TimeTicks()).InMillisecondsF();
return std::numeric_limits<double>::quiet_NaN();
Expand Down Expand Up @@ -380,7 +380,7 @@ TEST_F(ScrollTimelineTest, CurrentTimeHandlesEndScrollOffset) {
double time_range = content_size().height() - container_size().height();
const double end_scroll_offset = time_range - 20;
std::vector<double> scroll_offsets;
scroll_offsets.push_back(0); // should be base::nullopt
scroll_offsets.push_back(0); // should be absl::nullopt
scroll_offsets.push_back(end_scroll_offset);
scoped_refptr<ScrollTimeline> timeline = ScrollTimeline::Create(
scroller_id(), ScrollTimeline::ScrollDown, scroll_offsets, time_range);
Expand Down Expand Up @@ -494,7 +494,7 @@ TEST_F(ScrollTimelineTest, Activeness) {
scroll_offsets.push_back(0);
scroll_offsets.push_back(time_range);
scoped_refptr<ScrollTimeline> inactive_timeline1 = ScrollTimeline::Create(
base::nullopt, ScrollTimeline::ScrollDown, scroll_offsets, 100);
absl::nullopt, ScrollTimeline::ScrollDown, scroll_offsets, 100);
EXPECT_FALSE(
inactive_timeline1->IsActive(scroll_tree(), false /*is_active_tree*/));
EXPECT_FALSE(
Expand Down
18 changes: 9 additions & 9 deletions cc/animation/worklet_animation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ WorkletAnimation::WorkletAnimation(
playback_rate_(playback_rate),
options_(std::move(options)),
effect_timings_(std::move(effect_timings)),
local_time_(base::nullopt),
last_synced_local_time_(base::nullopt),
start_time_(base::nullopt),
last_current_time_(base::nullopt),
local_time_(absl::nullopt),
last_synced_local_time_(absl::nullopt),
start_time_(absl::nullopt),
last_current_time_(absl::nullopt),
has_pending_tree_lock_(false),
state_(State::PENDING),
is_impl_instance_(is_controlling_instance) {}
Expand Down Expand Up @@ -140,7 +140,7 @@ void WorkletAnimation::UpdateInputState(MutatorInputState* input_state,
// TODO(https://crbug.com/1011138): Initialize current_time to null if the
// timeline is inactive. It might be inactive here when state is
// State::REMOVED.
base::Optional<base::TimeDelta> current_time =
absl::optional<base::TimeDelta> current_time =
CurrentTime(monotonic_time, scroll_tree, is_active_tree);

// When the timeline is inactive (only the case with scroll timelines), the
Expand Down Expand Up @@ -212,18 +212,18 @@ void WorkletAnimation::UpdatePlaybackRate(double playback_rate) {
SetNeedsPushProperties();
}

base::Optional<base::TimeDelta> WorkletAnimation::CurrentTime(
absl::optional<base::TimeDelta> WorkletAnimation::CurrentTime(
base::TimeTicks monotonic_time,
const ScrollTree& scroll_tree,
bool is_active_tree) {
DCHECK(IsTimelineActive(scroll_tree, is_active_tree));
base::TimeTicks timeline_time;
if (animation_timeline_->IsScrollTimeline()) {
base::Optional<base::TimeTicks> scroll_monotonic_time =
absl::optional<base::TimeTicks> scroll_monotonic_time =
ToScrollTimeline(animation_timeline_)
->CurrentTime(scroll_tree, is_active_tree);
if (!scroll_monotonic_time)
return base::nullopt;
return absl::nullopt;
timeline_time = scroll_monotonic_time.value();
} else {
timeline_time = monotonic_time;
Expand All @@ -242,7 +242,7 @@ bool WorkletAnimation::NeedsUpdate(base::TimeTicks monotonic_time,
if (!IsTimelineActive(scroll_tree, is_active_tree))
return false;

base::Optional<base::TimeDelta> current_time =
absl::optional<base::TimeDelta> current_time =
CurrentTime(monotonic_time, scroll_tree, is_active_tree);
bool needs_update = last_current_time_ != current_time;
return needs_update;
Expand Down
Loading

0 comments on commit 1b060a7

Please sign in to comment.