#ifndef CC_INPUT_SINGLE_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_
#define CC_INPUT_SINGLE_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "cc/cc_export.h"
#include "cc/input/scrollbar.h"
#include "cc/layers/layer_impl.h"
#include "cc/layers/scrollbar_layer_impl_base.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
class ScrollbarAnimationControllerClient;
class CC_EXPORT SingleScrollbarAnimationControllerThinning {
public:
#if BUILDFLAG(ARKWEB_SCROLLBAR)
static constexpr float kIdleThicknessScale = 0.5f;
static constexpr float kMouseMoveDistanceToTriggerExpand = 12.f;
#else
static constexpr float kIdleThicknessScale = 0.4f;
static constexpr float kMouseMoveDistanceToTriggerExpand = 25.f;
#endif
static std::unique_ptr<SingleScrollbarAnimationControllerThinning> Create(
ElementId scroll_element_id,
ScrollbarOrientation orientation,
ScrollbarAnimationControllerClient* client,
base::TimeDelta thinning_duration,
float idle_thickness_scale);
SingleScrollbarAnimationControllerThinning(
const SingleScrollbarAnimationControllerThinning&) = delete;
~SingleScrollbarAnimationControllerThinning() = default;
SingleScrollbarAnimationControllerThinning& operator=(
const SingleScrollbarAnimationControllerThinning&) = delete;
bool mouse_is_over_scrollbar_thumb() const {
return mouse_is_over_scrollbar_thumb_;
}
bool mouse_is_near_scrollbar_thumb() const {
return mouse_is_near_scrollbar_thumb_;
}
bool mouse_is_near_scrollbar() const { return mouse_is_near_scrollbar_; }
bool captured() const { return captured_; }
gfx::PointF device_viewport_last_pointer_location() const {
return device_viewport_last_pointer_location_;
}
bool Animate(base::TimeTicks now);
void StartAnimation();
void StopAnimation();
void DidScrollUpdate();
#if BUILDFLAG(ARKWEB_SCROLLBAR)
void DidRequestShow();
#endif
void DidMouseDown();
void DidMouseUp();
void DidMouseLeave();
void DidMouseMove(const gfx::PointF& device_viewport_point);
float MouseMoveDistanceToTriggerExpand();
float MouseMoveDistanceToTriggerFadeIn();
void UpdateTickmarksVisibility(bool show);
private:
SingleScrollbarAnimationControllerThinning(
ElementId scroll_element_id,
ScrollbarOrientation orientation,
ScrollbarAnimationControllerClient* client,
base::TimeDelta thinning_duration,
float idle_thickness_scale);
ScrollbarLayerImplBase* GetScrollbar() const;
float AnimationProgressAtTime(base::TimeTicks now);
void RunAnimationFrame(float progress);
enum class AnimationChange { kNone, kIncrease, kDecrease };
float ThumbThicknessScaleAt(float progress) const;
float CurrentForcedThumbThicknessScale() const;
void CalculateThicknessShouldChange(const gfx::PointF& device_viewport_point);
float AdjustScale(float new_value,
float current_value,
AnimationChange animation_change,
float min_value,
float max_value);
void UpdateThumbThicknessScale();
void ApplyThumbThicknessScale(float thumb_thickness_scale);
raw_ptr<ScrollbarAnimationControllerClient> client_;
base::TimeTicks last_awaken_time_;
bool is_animating_ = false;
const ElementId scroll_element_id_;
const ScrollbarOrientation orientation_;
bool captured_ = false;
bool mouse_is_over_scrollbar_thumb_ = false;
bool mouse_is_near_scrollbar_thumb_ = false;
bool mouse_is_near_scrollbar_ = false;
AnimationChange thickness_change_ = AnimationChange::kNone;
const base::TimeDelta thinning_duration_;
bool tickmarks_showing_ = false;
gfx::PointF device_viewport_last_pointer_location_{-1, -1};
const float idle_thickness_scale_;
};
}
#endif