#include "cc/input/scroll_snap_data.h"
#include <algorithm>
#include <cmath>
#include <limits>
#include <memory>
#include <optional>
#include "base/auto_reset.h"
#include "base/check.h"
#include "base/notreached.h"
#include "cc/base/features.h"
#include "cc/input/snap_selection_strategy.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
namespace {
gfx::Vector2dF DistanceFromCorridor(double dx,
double dy,
const gfx::RectF& area) { … }
bool IsMutualVisible(const SnapSearchResult& a, const SnapSearchResult& b) { … }
void SetOrUpdateResult(const SnapSearchResult& candidate,
std::optional<SnapSearchResult>* result) { … }
const std::optional<SnapSearchResult>& ClosestSearchResult(
const gfx::PointF reference_point,
SearchAxis axis,
const std::optional<SnapSearchResult>& a,
const std::optional<SnapSearchResult>& b) { … }
std::optional<SnapSearchResult> SearchResultForDodgingRange(
const gfx::RangeF& area_range,
const gfx::RangeF& dodging_range,
const SnapSearchResult& aligned_candidate,
float preferred_offset,
float scroll_padding,
float snapport_size,
SnapAlignment alignment) { … }
bool CanCoverSnapportOnAxis(SearchAxis axis,
const gfx::RectF& container_rect,
const gfx::RectF& area_rect) { … }
}
SnapSearchResult::SnapSearchResult(float offset,
SearchAxis axis,
gfx::RangeF snapport_visible_range,
float snapport_max_visible)
: … { … }
void SnapSearchResult::Clip(float max_snap) { … }
void SnapSearchResult::Union(const SnapSearchResult& other) { … }
SnapContainerData::SnapContainerData()
: … { … }
SnapContainerData::SnapContainerData(ScrollSnapType type)
: … { … }
SnapContainerData::SnapContainerData(ScrollSnapType type,
const gfx::RectF& rect,
const gfx::PointF& max)
: … { … }
SnapContainerData::SnapContainerData(const SnapContainerData& other) = default;
SnapContainerData::SnapContainerData(SnapContainerData&& other) = default;
SnapContainerData::~SnapContainerData() = default;
SnapContainerData& SnapContainerData::operator=(
const SnapContainerData& other) = default;
SnapContainerData& SnapContainerData::operator=(SnapContainerData&& other) =
default;
void SnapContainerData::AddSnapAreaData(SnapAreaData snap_area_data) { … }
SnapPositionData SnapContainerData::FindSnapPositionWithViewportAdjustment(
const SnapSelectionStrategy& strategy,
double snapport_height_adjustment) { … }
SnapPositionData SnapContainerData::FindSnapPosition(
const SnapSelectionStrategy& strategy) const { … }
bool SnapContainerData::FindSnapPositionForMutualSnap(
const SnapSelectionStrategy& strategy,
gfx::PointF* snap_position) const { … }
std::optional<SnapSearchResult>
SnapContainerData::GetTargetSnapAreaSearchResult(
const SnapSelectionStrategy& strategy,
SearchAxis axis,
SnapSearchResult cross_axis_snap_result) const { … }
void SnapContainerData::UpdateSnapAreaForTesting(ElementId element_id,
SnapAreaData snap_area_data) { … }
const TargetSnapAreaElementIds& SnapContainerData::GetTargetSnapAreaElementIds()
const { … }
bool SnapContainerData::SetTargetSnapAreaElementIds(
TargetSnapAreaElementIds ids) { … }
std::optional<SnapSearchResult> SnapContainerData::FindClosestValidArea(
SearchAxis axis,
const SnapSelectionStrategy& strategy,
const SnapSearchResult& cross_axis_snap_result) const { … }
std::optional<SnapSearchResult> SnapContainerData::FindClosestValidAreaInternal(
SearchAxis axis,
const SnapSelectionStrategy& strategy,
const SnapSearchResult& cross_axis_snap_result,
bool should_consider_covering,
std::optional<gfx::RangeF> active_element_range) const { … }
SnapSearchResult SnapContainerData::GetSnapSearchResult(
SearchAxis axis,
const SnapAreaData& area) const { … }
std::optional<SnapSearchResult> SnapContainerData::FindCoveringCandidate(
const SnapAreaData& area,
SearchAxis axis,
const SnapSearchResult& aligned_candidate,
float intended_position) const { … }
constexpr float kSnapportCoveredTolerance = …;
bool SnapContainerData::IsSnapportCoveredOnAxis(
SearchAxis axis,
float current_offset,
const gfx::RectF& area_rect) const { … }
constexpr float kSnappedToTolerance = …;
bool SnapContainerData::IsSnappedToArea(
const SnapAreaData& area,
const gfx::PointF& scroll_offset) const { … }
gfx::RectF SnapContainerData::snapport() const { … }
void SnapContainerData::UpdateSearchAlternative(
SnapSearchResult& current_result,
const SnapSearchResult& candidate_result,
const SnapAreaData& candidate_area,
const SnapSelectionStrategy& strategy) const { … }
void SnapContainerData::SelectAlternativeIdForSearchResult(
SnapSearchResult& selection,
const std::optional<SnapSearchResult>& cross_selection,
float cross_current_position,
float cross_max_position) const { … }
SnapAxis SnapContainerData::SelectAxisToFollowForMutualVisibility(
const SnapSelectionStrategy& strategy,
const SnapSearchResult& selected_x,
const SnapSearchResult& selected_y) const { … }
std::ostream& operator<<(std::ostream& ostream, const SnapAreaData& area_data) { … }
std::ostream& operator<<(std::ostream& ostream,
const SnapContainerData& container_data) { … }
}