0

Use gfx::Point[F] for scroll offsets (out of blink renderer)

As discussed in https://bit.ly/3qtrn9s we want to use gfx::PointF for
scroll offset (out of blink renderer) and gfx::Vector2dF for scroll
delta, instead of gfx::Vector2dF for both, for the following purposes:

1. To make it easier to do the correct thing: passing blink scroll
   position (currently using FloatPoint, will be changed to gfx::PointF)
   to out-of-blink scroll offset (and vice versa); and to make it
   difficult to do the incorrect thing: passing blink scroll offset [1]
   to out-of-blink scroll offset. Without this CL, the incorrect thing
   would be easier to do than the correct thing because of the data
   type mismatches.

2. We can better distinguish scroll offset and scroll delta with
   different data types.

3. Make it consistent to use gfx::Point[F] for absolute scroll offsets
   throughout Chromium.

[1] See third_party/blink/core/layout/README.md for detailed explanation
    for of scroll position and scroll offset in blink renderer.

Bug: 738465
Change-Id: Ic9ac9658b8f3154514608ef4039780d0f20883bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3267944
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Steve Kobes <skobes@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Kentaro Hara <haraken@chromium.org>
Owners-Override: Kentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/main@{#941498}
This commit is contained in:
Xianzhu Wang
2021-11-14 16:12:06 +00:00
committed by Chromium LUCI CQ
parent 2046b47bf8
commit b1973a98d6
197 changed files with 2100 additions and 2205 deletions
android_webview/browser
cc
animation
input
layers
mojom
test
trees
chrome/browser
android
compositor
apps
page_load_metrics
components
content
services/viz/public
third_party/blink
ui

@ -1068,7 +1068,7 @@ bool AwContents::OnDraw(JNIEnv* env,
jint visible_bottom,
jboolean force_auxiliary_bitmap_rendering) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
gfx::Vector2d scroll(scroll_x, scroll_y);
gfx::Point scroll(scroll_x, scroll_y);
browser_view_renderer_.PrepareToDraw(
scroll, gfx::Rect(visible_left, visible_top, visible_right - visible_left,
visible_bottom - visible_top));
@ -1168,7 +1168,7 @@ gfx::Point AwContents::GetLocationOnScreen() {
return gfx::Point(location[0], location[1]);
}
void AwContents::ScrollContainerViewTo(const gfx::Vector2d& new_value) {
void AwContents::ScrollContainerViewTo(const gfx::Point& new_value) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
@ -1177,7 +1177,7 @@ void AwContents::ScrollContainerViewTo(const gfx::Vector2d& new_value) {
Java_AwContents_scrollContainerViewTo(env, obj, new_value.x(), new_value.y());
}
void AwContents::UpdateScrollState(const gfx::Vector2d& max_scroll_offset,
void AwContents::UpdateScrollState(const gfx::Point& max_scroll_offset,
const gfx::SizeF& contents_size_dip,
float page_scale_factor,
float min_page_scale_factor,
@ -1240,7 +1240,7 @@ void AwContents::ScrollTo(JNIEnv* env,
jint x,
jint y) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
browser_view_renderer_.ScrollTo(gfx::Vector2d(x, y));
browser_view_renderer_.ScrollTo(gfx::Point(x, y));
}
void AwContents::RestoreScrollAfterTransition(JNIEnv* env,
@ -1248,7 +1248,7 @@ void AwContents::RestoreScrollAfterTransition(JNIEnv* env,
jint x,
jint y) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
browser_view_renderer_.RestoreScrollAfterTransition(gfx::Vector2d(x, y));
browser_view_renderer_.RestoreScrollAfterTransition(gfx::Point(x, y));
}
void AwContents::SmoothScroll(JNIEnv* env,

@ -319,9 +319,9 @@ class AwContents : public FindHelper::Listener,
bool view_tree_force_dark_state) override;
// |new_value| is in physical pixel scale.
void ScrollContainerViewTo(const gfx::Vector2d& new_value) override;
void ScrollContainerViewTo(const gfx::Point& new_value) override;
void UpdateScrollState(const gfx::Vector2d& max_scroll_offset,
void UpdateScrollState(const gfx::Point& max_scroll_offset,
const gfx::SizeF& contents_size_dip,
float page_scale_factor,
float min_page_scale_factor,

@ -38,7 +38,7 @@ void AwPicture::Draw(JNIEnv* env,
return;
}
std::unique_ptr<SoftwareCanvasHolder> canvas_holder =
SoftwareCanvasHolder::Create(canvas, gfx::Vector2d(),
SoftwareCanvasHolder::Create(canvas, gfx::Point(),
gfx::Size(bounds.width(), bounds.height()),
false);
if (!canvas_holder || !canvas_holder->GetCanvas()) {

@ -35,6 +35,8 @@
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_conversions.h"
#include "ui/gfx/geometry/vector2d_f.h"
@ -248,7 +250,7 @@ content::SynchronousCompositor* BrowserViewRenderer::FindCompositor(
return compositor_iterator->second;
}
void BrowserViewRenderer::PrepareToDraw(const gfx::Vector2d& scroll,
void BrowserViewRenderer::PrepareToDraw(const gfx::Point& scroll,
const gfx::Rect& global_visible_rect) {
last_on_draw_scroll_offset_ = scroll;
last_on_draw_global_visible_rect_ = global_visible_rect;
@ -432,8 +434,8 @@ sk_sp<SkPicture> BrowserViewRenderer::CapturePicture(int width,
{
// Reset scroll back to the origin, will go back to the old
// value when scroll_reset is out of scope.
base::AutoReset<gfx::Vector2dF> scroll_reset(&scroll_offset_unscaled_,
gfx::Vector2dF());
base::AutoReset<gfx::PointF> scroll_reset(&scroll_offset_unscaled_,
gfx::PointF());
compositor_->DidChangeRootLayerScrollOffset(scroll_offset_unscaled_);
CompositeSW(rec_canvas, /*software_canvas=*/false);
}
@ -648,18 +650,18 @@ void BrowserViewRenderer::SetDipScale(float dip_scale) {
CHECK_GT(dip_scale_, 0.f);
}
gfx::Vector2d BrowserViewRenderer::max_scroll_offset() const {
gfx::Point BrowserViewRenderer::max_scroll_offset() const {
DCHECK_GT(dip_scale_, 0.f);
float scale = content::IsUseZoomForDSFEnabled()
? page_scale_factor_
: dip_scale_ * page_scale_factor_;
return gfx::ToCeiledVector2d(
gfx::ScaleVector2d(max_scroll_offset_unscaled_, scale));
return gfx::ToCeiledPoint(
gfx::ScalePoint(max_scroll_offset_unscaled_, scale));
}
void BrowserViewRenderer::ScrollTo(const gfx::Vector2d& scroll_offset) {
gfx::Vector2d max_offset = max_scroll_offset();
gfx::Vector2dF scroll_offset_unscaled;
void BrowserViewRenderer::ScrollTo(const gfx::Point& scroll_offset) {
gfx::Point max_offset = max_scroll_offset();
gfx::PointF scroll_offset_unscaled;
// To preserve the invariant that scrolling to the maximum physical pixel
// value also scrolls to the maximum dip pixel value we transform the physical
// offset into the dip offset by using a proportion (instead of dividing by
@ -699,9 +701,9 @@ void BrowserViewRenderer::ScrollTo(const gfx::Vector2d& scroll_offset) {
}
void BrowserViewRenderer::RestoreScrollAfterTransition(
const gfx::Vector2d& scroll_offset) {
const gfx::Point& scroll_offset) {
// Determine if the clipped scroll offset.
gfx::Vector2d clipped_offset = scroll_offset;
gfx::Point clipped_offset = scroll_offset;
clipped_offset.SetToMin(max_scroll_offset());
// If the scroll will be clipped due to the max scroll then we haven't
@ -730,13 +732,13 @@ void BrowserViewRenderer::DidUpdateContent(
}
void BrowserViewRenderer::SetTotalRootLayerScrollOffset(
const gfx::Vector2dF& scroll_offset_unscaled) {
const gfx::PointF& scroll_offset_unscaled) {
if (scroll_offset_unscaled_ == scroll_offset_unscaled)
return;
scroll_offset_unscaled_ = scroll_offset_unscaled;
gfx::Vector2d max_offset = max_scroll_offset();
gfx::Vector2d scroll_offset;
gfx::Point max_offset = max_scroll_offset();
gfx::Point scroll_offset;
// For an explanation as to why this is done this way see the comment in
// BrowserViewRenderer::ScrollTo.
if (max_scroll_offset_unscaled_.x()) {
@ -761,8 +763,8 @@ void BrowserViewRenderer::SetTotalRootLayerScrollOffset(
void BrowserViewRenderer::UpdateRootLayerState(
content::SynchronousCompositor* compositor,
const gfx::Vector2dF& total_scroll_offset,
const gfx::Vector2dF& total_max_scroll_offset,
const gfx::PointF& total_scroll_offset,
const gfx::PointF& total_max_scroll_offset,
const gfx::SizeF& scrollable_size,
float page_scale_factor,
float min_page_scale_factor,
@ -813,7 +815,7 @@ void BrowserViewRenderer::UpdateRootLayerState(
std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
BrowserViewRenderer::RootLayerStateAsValue(
const gfx::Vector2dF& total_scroll_offset,
const gfx::PointF& total_scroll_offset,
const gfx::SizeF& scrollable_size_dip) {
std::unique_ptr<base::trace_event::TracedValue> state(
new base::trace_event::TracedValue());

@ -24,6 +24,7 @@
#include "content/public/browser/android/synchronous_compositor_client.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
@ -74,7 +75,7 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
// state of this frame. |scroll| is the view's current scroll offset.
// |global_visible_rect| is the intersection of the view size and the window
// in window coordinates.
void PrepareToDraw(const gfx::Vector2d& scroll,
void PrepareToDraw(const gfx::Point& scroll,
const gfx::Rect& global_visible_rect);
// Main handlers for view drawing. A false return value indicates no new
@ -109,10 +110,10 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
// Set the root layer scroll offset to |new_value|. The |new_value| here is in
// physical pixel.
void ScrollTo(const gfx::Vector2d& new_value);
void ScrollTo(const gfx::Point& new_value);
// Set root layer scroll offset on the next scroll state update.
void RestoreScrollAfterTransition(const gfx::Vector2d& new_value);
void RestoreScrollAfterTransition(const gfx::Point& new_value);
// Android views hierarchy gluing.
bool IsVisible() const;
@ -139,8 +140,8 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
// in DIP scale when --use-zoom-for-dsf is disabled. Otherwise, they are in
// physical pixel scale.
void UpdateRootLayerState(content::SynchronousCompositor* compositor,
const gfx::Vector2dF& total_scroll_offset,
const gfx::Vector2dF& total_max_scroll_offset,
const gfx::PointF& total_scroll_offset,
const gfx::PointF& total_max_scroll_offset,
const gfx::SizeF& scrollable_size,
float page_scale_factor,
float min_page_scale_factor,
@ -187,11 +188,11 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
private:
void SetActiveCompositor(content::SynchronousCompositor* compositor);
void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip);
void SetTotalRootLayerScrollOffset(const gfx::PointF& new_value_dip);
bool CanOnDraw();
bool CompositeSW(SkCanvas* canvas, bool software_canvas);
std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
RootLayerStateAsValue(const gfx::Vector2dF& total_scroll_offset_dip,
RootLayerStateAsValue(const gfx::PointF& total_scroll_offset_dip,
const gfx::SizeF& scrollable_size_dip);
void ReturnUncommittedFrames(ChildFrameQueue frame);
@ -202,7 +203,7 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
bool DoUpdateParentDrawData();
void UpdateBeginFrameSource();
gfx::Vector2d max_scroll_offset() const;
gfx::Point max_scroll_offset() const;
// Return the tile rect in view space.
gfx::Rect ComputeTileRectAndUpdateMemoryPolicy();
@ -251,7 +252,7 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
CopyOutputRequestQueue copy_requests_;
gfx::Vector2d last_on_draw_scroll_offset_;
gfx::Point last_on_draw_scroll_offset_;
gfx::Rect last_on_draw_global_visible_rect_;
gfx::Size size_;
@ -260,8 +261,8 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
// When zoom-for-dsf enabled |max_scroll_offset_unscaled_| and
// |scroll_offset_unscaled_| is in physical pixel; otherwise, they are in dip
gfx::Vector2dF scroll_offset_unscaled_;
gfx::Vector2dF max_scroll_offset_unscaled_;
gfx::PointF scroll_offset_unscaled_;
gfx::PointF max_scroll_offset_unscaled_;
// Used to prevent rounding errors from accumulating enough to generate
// visible skew (especially noticeable when scrolling up and down in the same
@ -269,7 +270,7 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
gfx::Vector2dF overscroll_rounding_error_;
// The scroll to apply after the next scroll state update.
absl::optional<gfx::Vector2d> scroll_on_scroll_state_update_;
absl::optional<gfx::Point> scroll_on_scroll_state_update_;
ParentCompositorDrawConstraints external_draw_constraints_;

@ -32,14 +32,14 @@ class BrowserViewRendererClient {
virtual gfx::Point GetLocationOnScreen() = 0;
// Try to set the view's scroll offset to |new_value|.
virtual void ScrollContainerViewTo(const gfx::Vector2d& new_value) = 0;
virtual void ScrollContainerViewTo(const gfx::Point& new_value) = 0;
// Sets the following:
// view's scroll offset cap to |max_scroll_offset|,
// current contents_size to |contents_size_dip|,
// the current page scale to |page_scale_factor| and page scale limits
// to |min_page_scale_factor|..|max_page_scale_factor|.
virtual void UpdateScrollState(const gfx::Vector2d& max_scroll_offset,
virtual void UpdateScrollState(const gfx::Point& max_scroll_offset,
const gfx::SizeF& contents_size_dip,
float page_scale_factor,
float min_page_scale_factor,

@ -183,7 +183,7 @@ class TestAnimateInAndOutOfScreen : public RenderingTest {
// webview onto the screen on render thread. End the test when the parent
// draw constraints of BVR is updated to initial constraints.
if (on_draw_count_ == 1 || on_draw_count_ == 2)
browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect());
browser_view_renderer_->PrepareToDraw(gfx::Point(), gfx::Rect());
}
void DidOnDraw(bool success) override {
@ -264,7 +264,7 @@ class TestAnimateOnScreenWithoutOnDraw : public RenderingTest {
void WillOnDraw() override {
RenderingTest::WillOnDraw();
// Set empty tile viewport on first frame.
browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect());
browser_view_renderer_->PrepareToDraw(gfx::Point(), gfx::Rect());
}
void DidOnDraw(bool success) override {
@ -690,8 +690,8 @@ class DidReachMaximalScrollOffsetTest : public RenderingTest {
public:
void StartTest() override {
browser_view_renderer_->SetDipScale(kDipScale);
gfx::Vector2dF total_scroll_offset = kTotalScrollOffset;
gfx::Vector2dF total_max_scroll_offset = kTotalMaxScrollOffset;
gfx::PointF total_scroll_offset = kTotalScrollOffset;
gfx::PointF total_max_scroll_offset = kTotalMaxScrollOffset;
gfx::SizeF scrollable_size = kScrollableSize;
// When --use-zoom-for-dsf is enabled, these values are in physical pixels.
if (content::IsUseZoomForDSFEnabled()) {
@ -706,37 +706,37 @@ class DidReachMaximalScrollOffsetTest : public RenderingTest {
kMaxPageScaleFactor);
}
void ScrollContainerViewTo(const gfx::Vector2d& new_value) override {
EXPECT_EQ(kExpectedScrollOffset.ToString(), new_value.ToString());
void ScrollContainerViewTo(const gfx::Point& new_value) override {
EXPECT_EQ(kExpectedScrollOffset, new_value);
EndTest();
}
private:
static constexpr float kDipScale = 2.625f;
static const gfx::Vector2dF kTotalScrollOffset;
static const gfx::Vector2dF kTotalMaxScrollOffset;
static const gfx::PointF kTotalScrollOffset;
static const gfx::PointF kTotalMaxScrollOffset;
static const gfx::SizeF kScrollableSize;
static constexpr float kPageScaleFactor = 1.f;
// These two are not used in this test.
static constexpr float kMinPageScaleFactor = 1.f;
static constexpr float kMaxPageScaleFactor = 5.f;
static const gfx::Vector2d kExpectedScrollOffset;
static const gfx::Point kExpectedScrollOffset;
};
// The current scroll offset in logical pixel, which is at the end.
const gfx::Vector2dF DidReachMaximalScrollOffsetTest::kTotalScrollOffset =
gfx::Vector2dF(0.f, 6132.f);
const gfx::PointF DidReachMaximalScrollOffsetTest::kTotalScrollOffset =
gfx::PointF(0.f, 6132.f);
// The maximum possible scroll offset in logical pixel.
const gfx::Vector2dF DidReachMaximalScrollOffsetTest::kTotalMaxScrollOffset =
gfx::Vector2dF(0.f, 6132.f);
const gfx::PointF DidReachMaximalScrollOffsetTest::kTotalMaxScrollOffset =
gfx::PointF(0.f, 6132.f);
// This is what passed to CTS test, not used for this test.
const gfx::SizeF DidReachMaximalScrollOffsetTest::kScrollableSize =
gfx::SizeF(412.f, 6712.f);
// In max_scroll_offset() we are using ceiling rounding for scaled scroll
// offset. Therefore ceiling(2.625 * 6132 = 16096.5) = 16097.
const gfx::Vector2d DidReachMaximalScrollOffsetTest::kExpectedScrollOffset =
gfx::Vector2d(0, 16097);
const gfx::Point DidReachMaximalScrollOffsetTest::kExpectedScrollOffset =
gfx::Point(0, 16097);
RENDERING_TEST_F(DidReachMaximalScrollOffsetTest);

@ -9,7 +9,7 @@
#include "android_webview/browser/gfx/parent_compositor_draw_constraints.h"
#include "android_webview/browser/gfx/root_frame_sink.h"
#include "components/viz/common/frame_timing_details_map.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/point.h"
namespace viz {
class FrameSinkId;
@ -32,7 +32,7 @@ class CompositorFrameConsumer {
virtual void SetCompositorFrameProducer(
CompositorFrameProducer* compositor_frame_producer,
RootFrameSinkGetter root_frame_sink_getter) = 0;
virtual void SetScrollOffsetOnUI(gfx::Vector2d scroll_offset) = 0;
virtual void SetScrollOffsetOnUI(gfx::Point scroll_offset) = 0;
// Returns uncommitted frame to be returned, if any.
virtual std::unique_ptr<ChildFrame> SetFrameOnUI(
std::unique_ptr<ChildFrame> frame) = 0;

@ -104,7 +104,7 @@ class HardwareRenderer {
bool did_submit_compositor_frame_ = false;
// Information from UI on last commit.
gfx::Vector2d scroll_offset_;
gfx::Point scroll_offset_;
// HardwareRendererSingleThread guarantees resources are returned in the order
// of layer_tree_frame_sink_id, and resources for old output surfaces are

@ -29,7 +29,7 @@ class JavaCanvasHolder : public SoftwareCanvasHolder {
public:
JavaCanvasHolder(JNIEnv* env,
jobject java_canvas,
const gfx::Vector2d& scroll_correction);
const gfx::Point& scroll_correction);
JavaCanvasHolder(const JavaCanvasHolder&) = delete;
JavaCanvasHolder& operator=(const JavaCanvasHolder&) = delete;
@ -45,7 +45,7 @@ class JavaCanvasHolder : public SoftwareCanvasHolder {
JavaCanvasHolder::JavaCanvasHolder(JNIEnv* env,
jobject java_canvas,
const gfx::Vector2d& scroll)
const gfx::Point& scroll)
: pixels_(nullptr) {
if (!g_sw_draw_functions)
return;
@ -80,7 +80,7 @@ class AuxiliaryCanvasHolder : public SoftwareCanvasHolder {
public:
AuxiliaryCanvasHolder(JNIEnv* env,
jobject java_canvas,
const gfx::Vector2d& scroll_correction,
const gfx::Point& scroll_correction,
const gfx::Size size);
AuxiliaryCanvasHolder(const AuxiliaryCanvasHolder&) = delete;
@ -93,7 +93,7 @@ class AuxiliaryCanvasHolder : public SoftwareCanvasHolder {
private:
ScopedJavaLocalRef<jobject> jcanvas_;
ScopedJavaLocalRef<jobject> jbitmap_;
gfx::Vector2d scroll_;
gfx::Point scroll_;
std::unique_ptr<SkBitmap> bitmap_;
std::unique_ptr<SkCanvas> canvas_;
};
@ -101,7 +101,7 @@ class AuxiliaryCanvasHolder : public SoftwareCanvasHolder {
AuxiliaryCanvasHolder::AuxiliaryCanvasHolder(
JNIEnv* env,
jobject java_canvas,
const gfx::Vector2d& scroll_correction,
const gfx::Point& scroll_correction,
const gfx::Size size)
: jcanvas_(env, java_canvas), scroll_(scroll_correction) {
DCHECK(size.width() > 0);
@ -156,7 +156,7 @@ void RasterHelperSetAwDrawSWFunctionTable(AwDrawSWFunctionTable* table) {
// static
std::unique_ptr<SoftwareCanvasHolder> SoftwareCanvasHolder::Create(
jobject java_canvas,
const gfx::Vector2d& scroll_correction,
const gfx::Point& scroll_correction,
const gfx::Size& auxiliary_bitmap_size,
bool force_auxiliary_bitmap) {
JNIEnv* env = base::android::AttachCurrentThread();

@ -9,8 +9,8 @@
#include <memory>
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
class SkCanvas;
struct AwDrawSWFunctionTable;
@ -21,7 +21,7 @@ class SoftwareCanvasHolder {
public:
static std::unique_ptr<SoftwareCanvasHolder> Create(
jobject java_canvas,
const gfx::Vector2d& scroll_correction,
const gfx::Point& scroll_correction,
const gfx::Size& auxiliary_bitmap_size,
bool force_auxiliary_bitmap);

@ -56,14 +56,14 @@ void RenderThreadManager::ViewTreeForceDarkStateChangedOnUI(
}
}
void RenderThreadManager::SetScrollOffsetOnUI(gfx::Vector2d scroll_offset) {
void RenderThreadManager::SetScrollOffsetOnUI(gfx::Point scroll_offset) {
DCHECK(ui_loop_->BelongsToCurrentThread());
CheckUiCallsAllowed();
base::AutoLock lock(lock_);
scroll_offset_ = scroll_offset;
}
gfx::Vector2d RenderThreadManager::GetScrollOffsetOnRT() {
gfx::Point RenderThreadManager::GetScrollOffsetOnRT() {
base::AutoLock lock(lock_);
return scroll_offset_;
}

@ -16,7 +16,7 @@
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/point.h"
namespace android_webview {
@ -39,7 +39,7 @@ class RenderThreadManager : public CompositorFrameConsumer {
void SetCompositorFrameProducer(
CompositorFrameProducer* compositor_frame_producer,
RootFrameSinkGetter root_frame_sink_getter) override;
void SetScrollOffsetOnUI(gfx::Vector2d scroll_offset) override;
void SetScrollOffsetOnUI(gfx::Point scroll_offset) override;
std::unique_ptr<ChildFrame> SetFrameOnUI(
std::unique_ptr<ChildFrame> frame) override;
void TakeParentDrawDataOnUI(ParentCompositorDrawConstraints* constraints,
@ -51,7 +51,7 @@ class RenderThreadManager : public CompositorFrameConsumer {
void RemoveFromCompositorFrameProducerOnUI();
// Render thread methods.
gfx::Vector2d GetScrollOffsetOnRT();
gfx::Point GetScrollOffsetOnRT();
ChildFrameQueue PassFramesOnRT();
void PostParentDrawDataToChildCompositorOnRT(
const ParentCompositorDrawConstraints& parent_draw_constraints,
@ -120,7 +120,7 @@ class RenderThreadManager : public CompositorFrameConsumer {
// Accessed by both UI and RT thread.
mutable base::Lock lock_;
RootFrameSinkGetter root_frame_sink_getter_;
gfx::Vector2d scroll_offset_;
gfx::Point scroll_offset_;
ChildFrameQueue child_frames_;
bool mark_hardware_release_;
ParentCompositorDrawConstraints parent_draw_constraints_;

@ -126,7 +126,7 @@ void FakeWindow::OnDrawHardware() {
DCHECK(on_draw_hardware_pending_);
on_draw_hardware_pending_ = false;
view_->PrepareToDraw(gfx::Vector2d(), location_);
view_->PrepareToDraw(gfx::Point(), location_);
hooks_->WillOnDraw();
bool success = view_->OnDrawHardware();
hooks_->DidOnDraw(success);

@ -51,8 +51,8 @@ class RenderingTest : public testing::Test,
void OnNewPicture() override;
void PostInvalidate() override;
gfx::Point GetLocationOnScreen() override;
void ScrollContainerViewTo(const gfx::Vector2d& new_value) override {}
void UpdateScrollState(const gfx::Vector2d& max_scroll_offset,
void ScrollContainerViewTo(const gfx::Point& new_value) override {}
void UpdateScrollState(const gfx::Point& max_scroll_offset,
const gfx::SizeF& contents_size_dip,
float page_scale_factor,
float min_page_scale_factor,

@ -691,8 +691,8 @@ bool AnimationHost::HasTickingKeyframeModelForTesting(
void AnimationHost::ImplOnlyAutoScrollAnimationCreate(
ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
float autoscroll_velocity,
base::TimeDelta animation_start_offset) {
DCHECK(scroll_offset_animations_impl_);
@ -703,8 +703,8 @@ void AnimationHost::ImplOnlyAutoScrollAnimationCreate(
void AnimationHost::ImplOnlyScrollAnimationCreate(
ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
base::TimeDelta delayed_by,
base::TimeDelta animation_start_offset) {
DCHECK(scroll_offset_animations_impl_);
@ -715,7 +715,7 @@ void AnimationHost::ImplOnlyScrollAnimationCreate(
bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget(
const gfx::Vector2dF& scroll_delta,
const gfx::Vector2dF& max_scroll_offset,
const gfx::PointF& max_scroll_offset,
base::TimeTicks frame_monotonic_time,
base::TimeDelta delayed_by) {
DCHECK(scroll_offset_animations_impl_);

@ -17,6 +17,7 @@
#include "cc/trees/mutator_host.h"
#include "cc/trees/mutator_host_client.h"
#include "ui/gfx/geometry/box_f.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
@ -159,22 +160,21 @@ class CC_ANIMATION_EXPORT AnimationHost : public MutatorHost,
void ImplOnlyAutoScrollAnimationCreate(
ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
float autoscroll_velocity,
base::TimeDelta animation_start_offset) override;
void ImplOnlyScrollAnimationCreate(
ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
base::TimeDelta delayed_by,
base::TimeDelta animation_start_offset) override;
bool ImplOnlyScrollAnimationUpdateTarget(
const gfx::Vector2dF& scroll_delta,
const gfx::Vector2dF& max_scroll_offset,
base::TimeTicks frame_monotonic_time,
base::TimeDelta delayed_by) override;
bool ImplOnlyScrollAnimationUpdateTarget(const gfx::Vector2dF& scroll_delta,
const gfx::PointF& max_scroll_offset,
base::TimeTicks frame_monotonic_time,
base::TimeDelta delayed_by) override;
void ScrollAnimationAbort() override;

@ -124,14 +124,14 @@ TEST_F(AnimationHostTest, ImplOnlyScrollAnimationUpdateTargetIfDetached) {
client_.RegisterElementId(element_id_, ElementListType::ACTIVE);
client_impl_.RegisterElementId(element_id_, ElementListType::PENDING);
gfx::Vector2dF target_offset(0., 2.);
gfx::Vector2dF current_offset(0., 1.);
gfx::PointF target_offset(0., 2.);
gfx::PointF current_offset(0., 1.);
host_impl_->ImplOnlyScrollAnimationCreate(element_id_, target_offset,
current_offset, base::TimeDelta(),
base::TimeDelta());
gfx::Vector2dF scroll_delta(0, 0.5);
gfx::Vector2dF max_scroll_offset(0., 3.);
gfx::PointF max_scroll_offset(0., 3.);
base::TimeTicks time;
@ -291,7 +291,7 @@ void CreateScrollingNodeForElement(ElementId element_id,
void SetScrollOffset(PropertyTrees* property_trees,
ElementId element_id,
gfx::Vector2dF offset) {
gfx::PointF offset) {
// Update both scroll and transform trees
property_trees->scroll_tree.SetScrollOffset(element_id, offset);
TransformNode* transform_node =
@ -317,14 +317,14 @@ TEST_F(AnimationHostTest, LayerTreeMutatorUpdateReflectsScrollAnimations) {
CreateScrollingNodeForElement(element_id, &property_trees);
// Set an initial scroll value.
SetScrollOffset(&property_trees, element_id, gfx::Vector2dF(10, 10));
SetScrollOffset(&property_trees, element_id, gfx::PointF(10, 10));
scoped_refptr<MockAnimation> mock_scroll_animation(
new MockAnimation(animation_id1));
EXPECT_CALL(*mock_scroll_animation, Tick(_))
.WillOnce(InvokeWithoutArgs([&]() {
// Scroll to 20% of the max value.
SetScrollOffset(&property_trees, element_id, gfx::Vector2dF(20, 20));
SetScrollOffset(&property_trees, element_id, gfx::PointF(20, 20));
}));
// Ensure scroll animation is ticking.
@ -398,7 +398,7 @@ TEST_F(AnimationHostTest, TickScrollLinkedAnimation) {
KeyframeModel::WAITING_FOR_TARGET_AVAILABILITY);
auto& scroll_tree = property_trees.scroll_tree;
SetScrollOffset(&property_trees, element_id_, gfx::Vector2dF(0, 20));
SetScrollOffset(&property_trees, element_id_, gfx::PointF(0, 20));
EXPECT_TRUE(host_impl_->TickAnimations(base::TimeTicks(),
property_trees.scroll_tree, false));
@ -447,7 +447,7 @@ TEST_F(AnimationHostTest, ScrollTimelineOffsetUpdatedByScrollAnimation) {
EXPECT_CALL(*mock_scroll_animation, Tick(_))
.WillOnce(InvokeWithoutArgs([&]() {
// Scroll to 20% of the max value.
SetScrollOffset(&property_trees, element_id_, gfx::Vector2dF(0, 20));
SetScrollOffset(&property_trees, element_id_, gfx::PointF(0, 20));
}));
// Ensure scroll animation is ticking.

@ -288,7 +288,7 @@ void ElementAnimations::OnTransformAnimated(
}
void ElementAnimations::OnScrollOffsetAnimated(
const gfx::Vector2dF& scroll_offset,
const gfx::PointF& scroll_offset,
int target_property_id,
gfx::KeyframeModel* keyframe_model) {
if (KeyframeModelAffectsActiveElements(keyframe_model))
@ -533,7 +533,7 @@ void ElementAnimations::OnTransformAnimated(
void ElementAnimations::OnScrollOffsetAnimated(
ElementListType list_type,
const gfx::Vector2dF& scroll_offset,
const gfx::PointF& scroll_offset,
gfx::KeyframeModel* keyframe_model) {
ElementId target_element_id = CalculateTargetElementId(this, keyframe_model);
DCHECK(target_element_id);
@ -543,14 +543,14 @@ void ElementAnimations::OnScrollOffsetAnimated(
target_element_id, list_type, scroll_offset);
}
gfx::Vector2dF ElementAnimations::ScrollOffsetForAnimation() const {
gfx::PointF ElementAnimations::ScrollOffsetForAnimation() const {
if (animation_host_) {
DCHECK(animation_host_->mutator_host_client());
return animation_host_->mutator_host_client()->GetScrollOffsetForAnimation(
element_id());
}
return gfx::Vector2dF();
return gfx::PointF();
}
PropertyToElementIdMap ElementAnimations::GetPropertyToElementIdMap() const {

@ -16,8 +16,8 @@
#include "cc/trees/target_property.h"
#include "ui/gfx/animation/keyframe/animation_curve.h"
#include "ui/gfx/animation/keyframe/target_property.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/transform.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace gfx {
class TransformOperations;
@ -151,11 +151,11 @@ class CC_ANIMATION_EXPORT ElementAnimations
void OnTransformAnimated(const gfx::TransformOperations& operations,
int target_property_id,
gfx::KeyframeModel* keyframe_model) override;
void OnScrollOffsetAnimated(const gfx::Vector2dF& scroll_offset,
void OnScrollOffsetAnimated(const gfx::PointF& scroll_offset,
int target_property_id,
gfx::KeyframeModel* keyframe_model) override;
gfx::Vector2dF ScrollOffsetForAnimation() const;
gfx::PointF ScrollOffsetForAnimation() const;
// Returns a map of target property to the ElementId for that property, for
// KeyframeEffects associated with this ElementAnimations.
@ -202,7 +202,7 @@ class CC_ANIMATION_EXPORT ElementAnimations
const gfx::Transform& transform,
gfx::KeyframeModel* keyframe_model);
void OnScrollOffsetAnimated(ElementListType list_type,
const gfx::Vector2dF& scroll_offset,
const gfx::PointF& scroll_offset,
gfx::KeyframeModel* keyframe_model);
static gfx::TargetProperties GetPropertiesMaskForAnimationState();

@ -258,9 +258,9 @@ TEST_F(ElementAnimationsTest,
EXPECT_FALSE(
animation_impl_->GetKeyframeModel(TargetProperty::SCROLL_OFFSET));
gfx::Vector2dF initial_value(100.f, 300.f);
gfx::Vector2dF provider_initial_value(150.f, 300.f);
gfx::Vector2dF target_value(300.f, 200.f);
gfx::PointF initial_value(100.f, 300.f);
gfx::PointF provider_initial_value(150.f, 300.f);
gfx::PointF target_value(300.f, 200.f);
client_impl_.SetScrollOffsetForAnimation(provider_initial_value);
@ -279,7 +279,7 @@ TEST_F(ElementAnimationsTest,
animation_impl_->keyframe_effect()
->GetKeyframeModelById(animation1_id)
->curve());
EXPECT_VECTOR2DF_EQ(initial_value, scroll_curve->GetValue(base::TimeDelta()));
EXPECT_POINTF_EQ(initial_value, scroll_curve->GetValue(base::TimeDelta()));
animation_->RemoveKeyframeModel(animation1_id);
// Animation without initial value set.
@ -296,8 +296,8 @@ TEST_F(ElementAnimationsTest,
animation_impl_->keyframe_effect()
->GetKeyframeModelById(animation2_id)
->curve());
EXPECT_VECTOR2DF_EQ(provider_initial_value,
scroll_curve->GetValue(base::TimeDelta()));
EXPECT_POINTF_EQ(provider_initial_value,
scroll_curve->GetValue(base::TimeDelta()));
animation_->RemoveKeyframeModel(animation2_id);
}
@ -889,8 +889,8 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransition) {
auto events = CreateEventsForTesting();
gfx::Vector2dF initial_value(100.f, 300.f);
gfx::Vector2dF target_value(300.f, 200.f);
gfx::PointF initial_value(100.f, 300.f);
gfx::PointF target_value(300.f, 200.f);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
target_value));
@ -930,26 +930,26 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransition) {
animation_->Tick(kInitialTickTime + duration / 2);
animation_->UpdateState(true, nullptr);
EXPECT_TRUE(animation_->keyframe_effect()->HasTickingKeyframeModel());
EXPECT_VECTOR2DF_EQ(
gfx::Vector2dF(200.f, 250.f),
EXPECT_POINTF_EQ(
gfx::PointF(200.f, 250.f),
client_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
animation_impl_->Tick(kInitialTickTime + duration / 2);
animation_impl_->UpdateState(true, events.get());
EXPECT_VECTOR2DF_EQ(
gfx::Vector2dF(200.f, 250.f),
EXPECT_POINTF_EQ(
gfx::PointF(200.f, 250.f),
client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
animation_impl_->Tick(kInitialTickTime + duration);
animation_impl_->UpdateState(true, events.get());
EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
EXPECT_POINTF_EQ(target_value, client_impl_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
EXPECT_FALSE(animation_impl_->keyframe_effect()->HasTickingKeyframeModel());
animation_->Tick(kInitialTickTime + duration);
animation_->UpdateState(true, nullptr);
EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
EXPECT_POINTF_EQ(target_value, client_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
EXPECT_FALSE(animation_->keyframe_effect()->HasTickingKeyframeModel());
}
@ -960,8 +960,8 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransitionOnImplOnly) {
auto events = CreateEventsForTesting();
gfx::Vector2dF initial_value(100.f, 300.f);
gfx::Vector2dF target_value(300.f, 200.f);
gfx::PointF initial_value(100.f, 300.f);
gfx::PointF target_value(300.f, 200.f);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
target_value));
@ -985,14 +985,14 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransitionOnImplOnly) {
animation_impl_->Tick(kInitialTickTime + duration / 2);
animation_impl_->UpdateState(true, events.get());
EXPECT_VECTOR2DF_EQ(
gfx::Vector2dF(200.f, 250.f),
EXPECT_POINTF_EQ(
gfx::PointF(200.f, 250.f),
client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
animation_impl_->Tick(kInitialTickTime + duration);
animation_impl_->UpdateState(true, events.get());
EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
EXPECT_POINTF_EQ(target_value, client_impl_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
EXPECT_FALSE(animation_impl_->keyframe_effect()->HasTickingKeyframeModel());
}
@ -1009,8 +1009,8 @@ TEST_F(ElementAnimationsTest, UpdateStateWithoutAnimate) {
// Add first scroll offset animation.
AddScrollOffsetAnimationToAnimation(animation_impl_.get(),
gfx::Vector2dF(100.f, 300.f),
gfx::Vector2dF(100.f, 200.f));
gfx::PointF(100.f, 300.f),
gfx::PointF(100.f, 200.f));
// Calling UpdateState after Animate should promote the animation to running
// state.
@ -1027,8 +1027,8 @@ TEST_F(ElementAnimationsTest, UpdateStateWithoutAnimate) {
// Add second scroll offset animation.
AddScrollOffsetAnimationToAnimation(animation_impl_.get(),
gfx::Vector2dF(100.f, 200.f),
gfx::Vector2dF(100.f, 100.f));
gfx::PointF(100.f, 200.f),
gfx::PointF(100.f, 100.f));
// Calling UpdateState without Animate should NOT promote the animation to
// running state.
@ -1043,8 +1043,8 @@ TEST_F(ElementAnimationsTest, UpdateStateWithoutAnimate) {
EXPECT_EQ(KeyframeModel::RUNNING,
animation_impl_->GetKeyframeModel(TargetProperty::SCROLL_OFFSET)
->run_state());
EXPECT_VECTOR2DF_EQ(
gfx::Vector2dF(100.f, 200.f),
EXPECT_POINTF_EQ(
gfx::PointF(100.f, 200.f),
client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
}
@ -1062,8 +1062,8 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransitionNoImplProvider) {
auto events = CreateEventsForTesting();
gfx::Vector2dF initial_value(500.f, 100.f);
gfx::Vector2dF target_value(300.f, 200.f);
gfx::PointF initial_value(500.f, 100.f);
gfx::PointF target_value(300.f, 200.f);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
target_value));
@ -1093,8 +1093,8 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransitionNoImplProvider) {
EXPECT_TRUE(animation_->keyframe_effect()->HasTickingKeyframeModel());
EXPECT_EQ(initial_value,
client_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
EXPECT_EQ(gfx::Vector2dF(), client_impl_.GetScrollOffset(
element_id_, ElementListType::PENDING));
EXPECT_EQ(gfx::PointF(), client_impl_.GetScrollOffset(
element_id_, ElementListType::PENDING));
animation_impl_->Tick(kInitialTickTime);
@ -1111,26 +1111,26 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransitionNoImplProvider) {
animation_->Tick(kInitialTickTime + duration / 2);
animation_->UpdateState(true, nullptr);
EXPECT_TRUE(animation_->keyframe_effect()->HasTickingKeyframeModel());
EXPECT_VECTOR2DF_EQ(
gfx::Vector2dF(400.f, 150.f),
EXPECT_POINTF_EQ(
gfx::PointF(400.f, 150.f),
client_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
animation_impl_->Tick(kInitialTickTime + duration / 2);
animation_impl_->UpdateState(true, events.get());
EXPECT_VECTOR2DF_EQ(
gfx::Vector2dF(400.f, 150.f),
EXPECT_POINTF_EQ(
gfx::PointF(400.f, 150.f),
client_impl_.GetScrollOffset(element_id_, ElementListType::PENDING));
animation_impl_->Tick(kInitialTickTime + duration);
animation_impl_->UpdateState(true, events.get());
EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset(
element_id_, ElementListType::PENDING));
EXPECT_POINTF_EQ(target_value, client_impl_.GetScrollOffset(
element_id_, ElementListType::PENDING));
EXPECT_FALSE(animation_impl_->keyframe_effect()->HasTickingKeyframeModel());
animation_->Tick(kInitialTickTime + duration);
animation_->UpdateState(true, nullptr);
EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
EXPECT_POINTF_EQ(target_value, client_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
EXPECT_FALSE(animation_->keyframe_effect()->HasTickingKeyframeModel());
}
@ -1142,7 +1142,7 @@ TEST_F(ElementAnimationsTest, ScrollOffsetRemovalClearsScrollDelta) {
auto events = CreateEventsForTesting();
// First test the 1-argument version of RemoveKeyframeModel.
gfx::Vector2dF target_value(300.f, 200.f);
gfx::PointF target_value(300.f, 200.f);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
target_value));
@ -1265,8 +1265,8 @@ TEST_F(ElementAnimationsTest,
TestAnimationDelegate delegate;
animation_impl_->set_animation_delegate(&delegate);
gfx::Vector2dF initial_value(100.f, 300.f);
gfx::Vector2dF target_value(300.f, 200.f);
gfx::PointF initial_value(100.f, 300.f);
gfx::PointF target_value(300.f, 200.f);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
target_value));
@ -2071,8 +2071,8 @@ TEST_F(ElementAnimationsTest, ImplThreadTakeoverAnimationGetsDeleted) {
// Add impl-only scroll offset animation.
const int keyframe_model_id = 1;
gfx::Vector2dF initial_value(100.f, 300.f);
gfx::Vector2dF target_value(300.f, 200.f);
gfx::PointF initial_value(100.f, 300.f);
gfx::PointF target_value(300.f, 200.f);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
target_value));

@ -600,7 +600,7 @@ void KeyframeEffect::PushNewKeyframeModelsToImplThread(
!ScrollOffsetAnimationCurve::ToScrollOffsetAnimationCurve(
keyframe_model->curve())
->HasSetInitialValue()) {
gfx::Vector2dF current_scroll_offset;
gfx::PointF current_scroll_offset;
if (keyframe_effect_impl->HasElementInActiveList()) {
current_scroll_offset =
keyframe_effect_impl->ScrollOffsetForAnimation();
@ -1028,7 +1028,7 @@ bool KeyframeEffect::HasElementInActiveList() const {
return element_animations_->has_element_in_active_list();
}
gfx::Vector2dF KeyframeEffect::ScrollOffsetForAnimation() const {
gfx::PointF KeyframeEffect::ScrollOffsetForAnimation() const {
DCHECK(has_bound_element_animations());
return element_animations_->ScrollOffsetForAnimation();
}

@ -20,7 +20,7 @@
#include "cc/trees/target_property.h"
#include "ui/gfx/animation/keyframe/keyframe_effect.h"
#include "ui/gfx/geometry/box_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/geometry/point_f.h"
namespace cc {
@ -169,7 +169,7 @@ class CC_ANIMATION_EXPORT KeyframeEffect : public gfx::KeyframeEffect {
void MarkFinishedKeyframeModels(base::TimeTicks monotonic_time);
bool HasElementInActiveList() const;
gfx::Vector2dF ScrollOffsetForAnimation() const;
gfx::PointF ScrollOffsetForAnimation() const;
void GenerateEvent(AnimationEvents* events,
const KeyframeModel& keyframe_model,
AnimationEvent::Type type,

@ -81,9 +81,9 @@ std::unique_ptr<TimingFunction> ImpulseCurveWithInitialSlope(double slope) {
return CubicBezierTimingFunction::Create(x1, y1, x2, y2);
}
bool IsNewTargetInOppositeDirection(const gfx::Vector2dF& current_position,
const gfx::Vector2dF& old_target,
const gfx::Vector2dF& new_target) {
bool IsNewTargetInOppositeDirection(const gfx::PointF& current_position,
const gfx::PointF& old_target,
const gfx::PointF& new_target) {
gfx::Vector2dF old_delta = old_target - current_position;
gfx::Vector2dF new_delta = new_target - current_position;
@ -132,7 +132,7 @@ absl::optional<double>
ScrollOffsetAnimationCurve::animation_duration_for_testing_;
ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve(
const gfx::Vector2dF& target_value,
const gfx::PointF& target_value,
AnimationType animation_type,
absl::optional<DurationBehavior> duration_behavior)
: target_value_(target_value),
@ -157,7 +157,7 @@ ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve(
}
ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve(
const gfx::Vector2dF& target_value,
const gfx::PointF& target_value,
std::unique_ptr<TimingFunction> timing_function,
AnimationType animation_type,
absl::optional<DurationBehavior> duration_behavior)
@ -276,7 +276,7 @@ base::TimeDelta ScrollOffsetAnimationCurve::ImpulseSegmentDuration(
}
void ScrollOffsetAnimationCurve::SetInitialValue(
const gfx::Vector2dF& initial_value,
const gfx::PointF& initial_value,
base::TimeDelta delayed_by,
float velocity) {
initial_value_ = initial_value;
@ -296,7 +296,7 @@ void ScrollOffsetAnimationCurve::ApplyAdjustment(
target_value_ = target_value_ + adjustment;
}
gfx::Vector2dF ScrollOffsetAnimationCurve::GetValue(base::TimeDelta t) const {
gfx::PointF ScrollOffsetAnimationCurve::GetValue(base::TimeDelta t) const {
const base::TimeDelta duration = total_animation_duration_ - last_retarget_;
t -= last_retarget_;
@ -306,10 +306,10 @@ gfx::Vector2dF ScrollOffsetAnimationCurve::GetValue(base::TimeDelta t) const {
return initial_value_;
const double progress = timing_function_->GetValue(t / duration);
return gfx::Vector2dF(gfx::Tween::FloatValueBetween(
progress, initial_value_.x(), target_value_.x()),
gfx::Tween::FloatValueBetween(
progress, initial_value_.y(), target_value_.y()));
return gfx::PointF(gfx::Tween::FloatValueBetween(progress, initial_value_.x(),
target_value_.x()),
gfx::Tween::FloatValueBetween(progress, initial_value_.y(),
target_value_.y()));
}
base::TimeDelta ScrollOffsetAnimationCurve::Duration() const {
@ -368,9 +368,8 @@ double ScrollOffsetAnimationCurve::CalculateVelocity(base::TimeDelta t) {
return slope * (MaximumDimension(delta) / duration.InSecondsF());
}
void ScrollOffsetAnimationCurve::UpdateTarget(
base::TimeDelta t,
const gfx::Vector2dF& new_target) {
void ScrollOffsetAnimationCurve::UpdateTarget(base::TimeDelta t,
const gfx::PointF& new_target) {
DCHECK_NE(animation_type_, AnimationType::kLinear)
<< "UpdateTarget is not supported on linear scroll animations.";
@ -398,7 +397,7 @@ void ScrollOffsetAnimationCurve::UpdateTarget(
return;
}
gfx::Vector2dF current_position = GetValue(t);
gfx::PointF current_position = GetValue(t);
gfx::Vector2dF new_delta = new_target - current_position;
// We are already at or very close to the new target. Stop animating.

@ -12,6 +12,7 @@
#include "cc/animation/animation_export.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/animation/keyframe/animation_curve.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace gfx {
@ -34,7 +35,7 @@ class CC_ANIMATION_EXPORT ScrollOffsetAnimationCurve
public:
~Target() = default;
virtual void OnScrollOffsetAnimated(const gfx::Vector2dF& value,
virtual void OnScrollOffsetAnimated(const gfx::PointF& value,
int target_property_id,
gfx::KeyframeModel* keyframe_model) = 0;
};
@ -83,18 +84,18 @@ class CC_ANIMATION_EXPORT ScrollOffsetAnimationCurve
delete;
// Sets the initial offset and velocity (in pixels per second).
void SetInitialValue(const gfx::Vector2dF& initial_value,
void SetInitialValue(const gfx::PointF& initial_value,
base::TimeDelta delayed_by = base::TimeDelta(),
float velocity = 0);
bool HasSetInitialValue() const;
gfx::Vector2dF GetValue(base::TimeDelta t) const;
gfx::Vector2dF target_value() const { return target_value_; }
gfx::PointF GetValue(base::TimeDelta t) const;
gfx::PointF target_value() const { return target_value_; }
// Updates the current curve to aim at a new target, starting at time t
// relative to the start of the animation. The duration is recomputed based
// on the animation type the curve was constructed with. The timing function
// is modified to preserve velocity at t.
void UpdateTarget(base::TimeDelta t, const gfx::Vector2dF& new_target);
void UpdateTarget(base::TimeDelta t, const gfx::PointF& new_target);
// Shifts the entire curve by a delta without affecting its shape or timing.
// Used for scroll anchoring adjustments that happen during scroll animations
@ -124,11 +125,11 @@ class CC_ANIMATION_EXPORT ScrollOffsetAnimationCurve
// |duration_behavior| should be provided if (and only if) |animation_type| is
// kEaseInOut.
ScrollOffsetAnimationCurve(
const gfx::Vector2dF& target_value,
const gfx::PointF& target_value,
AnimationType animation_type,
absl::optional<DurationBehavior> duration_behavior = absl::nullopt);
ScrollOffsetAnimationCurve(
const gfx::Vector2dF& target_value,
const gfx::PointF& target_value,
std::unique_ptr<gfx::TimingFunction> timing_function,
AnimationType animation_type,
absl::optional<DurationBehavior> duration_behavior);
@ -146,8 +147,8 @@ class CC_ANIMATION_EXPORT ScrollOffsetAnimationCurve
// Returns the velocity at time t in units of pixels per second.
double CalculateVelocity(base::TimeDelta t);
gfx::Vector2dF initial_value_;
gfx::Vector2dF target_value_;
gfx::PointF initial_value_;
gfx::PointF target_value_;
base::TimeDelta total_animation_duration_;
// Time from animation start to most recent UpdateTarget.

@ -32,7 +32,7 @@ ScrollOffsetAnimationCurve::DurationBehavior GetDurationBehaviorFromScrollType(
// static
std::unique_ptr<ScrollOffsetAnimationCurve>
ScrollOffsetAnimationCurveFactory::CreateAnimation(
const gfx::Vector2dF& target_value,
const gfx::PointF& target_value,
ScrollType scroll_type) {
if (scroll_type == ScrollType::kAutoScroll)
return CreateLinearAnimation(target_value);
@ -47,7 +47,7 @@ ScrollOffsetAnimationCurveFactory::CreateAnimation(
// static
std::unique_ptr<ScrollOffsetAnimationCurve>
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
const gfx::Vector2dF& target_value,
const gfx::PointF& target_value,
ScrollOffsetAnimationCurve::DurationBehavior duration_behavior) {
return CreateEaseInOutAnimation(target_value, duration_behavior);
}
@ -55,21 +55,21 @@ ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
// static
std::unique_ptr<ScrollOffsetAnimationCurve>
ScrollOffsetAnimationCurveFactory::CreateLinearAnimationForTesting(
const gfx::Vector2dF& target_value) {
const gfx::PointF& target_value) {
return CreateLinearAnimation(target_value);
}
// static
std::unique_ptr<ScrollOffsetAnimationCurve>
ScrollOffsetAnimationCurveFactory::CreateImpulseAnimationForTesting(
const gfx::Vector2dF& target_value) {
const gfx::PointF& target_value) {
return CreateImpulseAnimation(target_value);
}
// static
std::unique_ptr<ScrollOffsetAnimationCurve>
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimation(
const gfx::Vector2dF& target_value,
const gfx::PointF& target_value,
ScrollOffsetAnimationCurve::DurationBehavior duration_behavior) {
return base::WrapUnique(new ScrollOffsetAnimationCurve(
target_value, ScrollOffsetAnimationCurve::AnimationType::kEaseInOut,
@ -79,7 +79,7 @@ ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimation(
// static
std::unique_ptr<ScrollOffsetAnimationCurve>
ScrollOffsetAnimationCurveFactory::CreateLinearAnimation(
const gfx::Vector2dF& target_value) {
const gfx::PointF& target_value) {
return base::WrapUnique(new ScrollOffsetAnimationCurve(
target_value, ScrollOffsetAnimationCurve::AnimationType::kLinear));
}
@ -87,7 +87,7 @@ ScrollOffsetAnimationCurveFactory::CreateLinearAnimation(
// static
std::unique_ptr<ScrollOffsetAnimationCurve>
ScrollOffsetAnimationCurveFactory::CreateImpulseAnimation(
const gfx::Vector2dF& target_value) {
const gfx::PointF& target_value) {
return base::WrapUnique(new ScrollOffsetAnimationCurve(
target_value, ScrollOffsetAnimationCurve::AnimationType::kImpulse,
ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA));

@ -15,31 +15,31 @@ class CC_ANIMATION_EXPORT ScrollOffsetAnimationCurveFactory {
enum class ScrollType { kProgrammatic, kKeyboard, kMouseWheel, kAutoScroll };
static std::unique_ptr<ScrollOffsetAnimationCurve> CreateAnimation(
const gfx::Vector2dF& target_value,
const gfx::PointF& target_value,
ScrollType scroll_type);
static std::unique_ptr<ScrollOffsetAnimationCurve>
CreateEaseInOutAnimationForTesting(
const gfx::Vector2dF& target_value,
const gfx::PointF& target_value,
ScrollOffsetAnimationCurve::DurationBehavior duration_behavior =
ScrollOffsetAnimationCurve::DurationBehavior::DELTA_BASED);
static std::unique_ptr<ScrollOffsetAnimationCurve>
CreateLinearAnimationForTesting(const gfx::Vector2dF& target_value);
CreateLinearAnimationForTesting(const gfx::PointF& target_value);
static std::unique_ptr<ScrollOffsetAnimationCurve>
CreateImpulseAnimationForTesting(const gfx::Vector2dF& target_value);
CreateImpulseAnimationForTesting(const gfx::PointF& target_value);
private:
static std::unique_ptr<ScrollOffsetAnimationCurve> CreateEaseInOutAnimation(
const gfx::Vector2dF& target_value,
const gfx::PointF& target_value,
ScrollOffsetAnimationCurve::DurationBehavior duration_hint);
static std::unique_ptr<ScrollOffsetAnimationCurve> CreateLinearAnimation(
const gfx::Vector2dF& target_value);
const gfx::PointF& target_value);
static std::unique_ptr<ScrollOffsetAnimationCurve> CreateImpulseAnimation(
const gfx::Vector2dF& target_value);
const gfx::PointF& target_value);
};
} // namespace cc

@ -24,7 +24,7 @@ constexpr double halfway_through_default_impulse_curve = 0.874246;
} // namespace
TEST(ScrollOffsetAnimationCurveTest, DeltaBasedDuration) {
gfx::Vector2dF target_value(100.f, 200.f);
gfx::PointF target_value(100.f, 200.f);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
target_value));
@ -33,41 +33,41 @@ TEST(ScrollOffsetAnimationCurveTest, DeltaBasedDuration) {
EXPECT_DOUBLE_EQ(0.0, curve->Duration().InSecondsF());
// x decreases, y stays the same.
curve->SetInitialValue(gfx::Vector2dF(136.f, 200.f));
curve->SetInitialValue(gfx::PointF(136.f, 200.f));
EXPECT_DOUBLE_EQ(0.1, curve->Duration().InSecondsF());
// x increases, y stays the same.
curve->SetInitialValue(gfx::Vector2dF(19.f, 200.f));
curve->SetInitialValue(gfx::PointF(19.f, 200.f));
EXPECT_DOUBLE_EQ(0.15, curve->Duration().InSecondsF());
// x stays the same, y decreases.
curve->SetInitialValue(gfx::Vector2dF(100.f, 344.f));
curve->SetInitialValue(gfx::PointF(100.f, 344.f));
EXPECT_DOUBLE_EQ(0.2, curve->Duration().InSecondsF());
// x stays the same, y increases.
curve->SetInitialValue(gfx::Vector2dF(100.f, 191.f));
curve->SetInitialValue(gfx::PointF(100.f, 191.f));
EXPECT_DOUBLE_EQ(0.05, curve->Duration().InSecondsF());
// x decreases, y decreases.
curve->SetInitialValue(gfx::Vector2dF(32500.f, 500.f));
curve->SetInitialValue(gfx::PointF(32500.f, 500.f));
EXPECT_DOUBLE_EQ(0.7, curve->Duration().InSecondsF());
// x decreases, y increases.
curve->SetInitialValue(gfx::Vector2dF(150.f, 119.f));
curve->SetInitialValue(gfx::PointF(150.f, 119.f));
EXPECT_DOUBLE_EQ(0.15, curve->Duration().InSecondsF());
// x increases, y decreases.
curve->SetInitialValue(gfx::Vector2dF(0.f, 14600.f));
curve->SetInitialValue(gfx::PointF(0.f, 14600.f));
EXPECT_DOUBLE_EQ(0.7, curve->Duration().InSecondsF());
// x increases, y increases.
curve->SetInitialValue(gfx::Vector2dF(95.f, 191.f));
curve->SetInitialValue(gfx::PointF(95.f, 191.f));
EXPECT_DOUBLE_EQ(0.05, curve->Duration().InSecondsF());
}
TEST(ScrollOffsetAnimationCurveTest, GetValue) {
gfx::Vector2dF initial_value(2.f, 40.f);
gfx::Vector2dF target_value(10.f, 20.f);
gfx::PointF initial_value(2.f, 40.f);
gfx::PointF target_value(10.f, 20.f);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
target_value));
@ -79,24 +79,24 @@ TEST(ScrollOffsetAnimationCurveTest, GetValue) {
EXPECT_EQ(duration, curve->Duration());
EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(base::Seconds(-1.0)));
EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(base::TimeDelta()));
EXPECT_VECTOR2DF_NEAR(gfx::Vector2dF(6.f, 30.f),
curve->GetValue(duration * 0.5f), 0.00025);
EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration));
EXPECT_VECTOR2DF_EQ(target_value,
curve->GetValue(duration + base::Seconds(1.0)));
EXPECT_POINTF_EQ(initial_value, curve->GetValue(base::Seconds(-1.0)));
EXPECT_POINTF_EQ(initial_value, curve->GetValue(base::TimeDelta()));
EXPECT_POINTF_NEAR(gfx::PointF(6.f, 30.f), curve->GetValue(duration * 0.5f),
0.00025);
EXPECT_POINTF_EQ(target_value, curve->GetValue(duration));
EXPECT_POINTF_EQ(target_value,
curve->GetValue(duration + base::Seconds(1.0)));
// Verify that GetValue takes the timing function into account.
gfx::Vector2dF value = curve->GetValue(duration * 0.25f);
gfx::PointF value = curve->GetValue(duration * 0.25f);
EXPECT_NEAR(3.0333f, value.x(), 0.0002f);
EXPECT_NEAR(37.4168f, value.y(), 0.0002f);
}
// Verify that a clone behaves exactly like the original.
TEST(ScrollOffsetAnimationCurveTest, Clone) {
gfx::Vector2dF initial_value(2.f, 40.f);
gfx::Vector2dF target_value(10.f, 20.f);
gfx::PointF initial_value(2.f, 40.f);
gfx::PointF target_value(10.f, 20.f);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
target_value));
@ -110,24 +110,23 @@ TEST(ScrollOffsetAnimationCurveTest, Clone) {
ScrollOffsetAnimationCurve* cloned_curve =
ScrollOffsetAnimationCurve::ToScrollOffsetAnimationCurve(clone.get());
EXPECT_VECTOR2DF_EQ(initial_value,
cloned_curve->GetValue(base::Seconds(-1.0)));
EXPECT_VECTOR2DF_EQ(initial_value, cloned_curve->GetValue(base::TimeDelta()));
EXPECT_VECTOR2DF_NEAR(gfx::Vector2dF(6.f, 30.f),
cloned_curve->GetValue(duration * 0.5f), 0.00025);
EXPECT_VECTOR2DF_EQ(target_value, cloned_curve->GetValue(duration));
EXPECT_VECTOR2DF_EQ(target_value,
cloned_curve->GetValue(duration + base::Seconds(1.f)));
EXPECT_POINTF_EQ(initial_value, cloned_curve->GetValue(base::Seconds(-1.0)));
EXPECT_POINTF_EQ(initial_value, cloned_curve->GetValue(base::TimeDelta()));
EXPECT_POINTF_NEAR(gfx::PointF(6.f, 30.f),
cloned_curve->GetValue(duration * 0.5f), 0.00025);
EXPECT_POINTF_EQ(target_value, cloned_curve->GetValue(duration));
EXPECT_POINTF_EQ(target_value,
cloned_curve->GetValue(duration + base::Seconds(1.f)));
// Verify that the timing function was cloned correctly.
gfx::Vector2dF value = cloned_curve->GetValue(duration * 0.25f);
gfx::PointF value = cloned_curve->GetValue(duration * 0.25f);
EXPECT_NEAR(3.0333f, value.x(), 0.0002f);
EXPECT_NEAR(37.4168f, value.y(), 0.0002f);
}
TEST(ScrollOffsetAnimationCurveTest, EaseInOutUpdateTarget) {
gfx::Vector2dF initial_value(0.f, 0.f);
gfx::Vector2dF target_value(0.f, 3600.f);
gfx::PointF initial_value(0.f, 0.f);
gfx::PointF target_value(0.f, 3600.f);
double duration = kConstantDuration / kDurationDivisor;
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
@ -138,7 +137,7 @@ TEST(ScrollOffsetAnimationCurveTest, EaseInOutUpdateTarget) {
0.0002f);
EXPECT_NEAR(3600.0, curve->GetValue(base::Seconds(duration)).y(), 0.0002f);
curve->UpdateTarget(base::Seconds(duration / 2), gfx::Vector2dF(0.0, 9900.0));
curve->UpdateTarget(base::Seconds(duration / 2), gfx::PointF(0.0, 9900.0));
EXPECT_NEAR(duration * 1.5, curve->Duration().InSecondsF(), 0.0002f);
EXPECT_NEAR(1800.0, curve->GetValue(base::Seconds(duration / 2.0)).y(),
@ -147,7 +146,7 @@ TEST(ScrollOffsetAnimationCurveTest, EaseInOutUpdateTarget) {
EXPECT_NEAR(9900.0, curve->GetValue(base::Seconds(duration * 1.5)).y(),
0.0002f);
curve->UpdateTarget(base::Seconds(duration), gfx::Vector2dF(0.0, 7200.0));
curve->UpdateTarget(base::Seconds(duration), gfx::PointF(0.0, 7200.0));
// A closer target at high velocity reduces the duration.
EXPECT_NEAR(duration * 1.0794, curve->Duration().InSecondsF(), 0.0002f);
@ -157,8 +156,8 @@ TEST(ScrollOffsetAnimationCurveTest, EaseInOutUpdateTarget) {
}
TEST(ScrollOffsetAnimationCurveTest, ImpulseUpdateTarget) {
gfx::Vector2dF initial_value(0.f, 0.f);
gfx::Vector2dF initial_target_value(0.f, 3600.f);
gfx::PointF initial_value(0.f, 0.f);
gfx::PointF initial_target_value(0.f, 3600.f);
gfx::Vector2dF initial_delta = initial_target_value - initial_value;
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateImpulseAnimationForTesting(
@ -176,10 +175,10 @@ TEST(ScrollOffsetAnimationCurveTest, ImpulseUpdateTarget) {
0.0002f);
base::TimeDelta time_of_update = initial_duration / 2;
gfx::Vector2dF distance_halfway_through_initial_animation =
gfx::PointF distance_halfway_through_initial_animation =
curve->GetValue(time_of_update);
gfx::Vector2dF new_target_value(0.f, 9900.f);
gfx::PointF new_target_value(0.f, 9900.f);
curve->UpdateTarget(time_of_update, new_target_value);
gfx::Vector2dF new_delta =
@ -207,11 +206,12 @@ TEST(ScrollOffsetAnimationCurveTest, ImpulseUpdateTarget) {
}
TEST(ScrollOffsetAnimationCurveTest, ImpulseUpdateTargetSwitchDirections) {
gfx::Vector2dF initial_value(0.f, 0.f);
gfx::Vector2dF initial_target_value(0.f, 200.f);
double initial_duration = ScrollOffsetAnimationCurve::ImpulseSegmentDuration(
initial_target_value, base::TimeDelta())
.InSecondsF();
gfx::PointF initial_value(0.f, 0.f);
gfx::PointF initial_target_value(0.f, 200.f);
double initial_duration =
ScrollOffsetAnimationCurve::ImpulseSegmentDuration(
initial_target_value.OffsetFromOrigin(), base::TimeDelta())
.InSecondsF();
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateImpulseAnimationForTesting(
@ -224,9 +224,9 @@ TEST(ScrollOffsetAnimationCurveTest, ImpulseUpdateTargetSwitchDirections) {
// Animate back to 0. This should force the new curve's initial velocity to be
// 0, so the default curve will be generated.
gfx::Vector2dF updated_initial_value = gfx::Vector2dF(
gfx::PointF updated_initial_value(
0, initial_target_value.y() * halfway_through_default_impulse_curve);
gfx::Vector2dF updated_target(0.f, 0.f);
gfx::PointF updated_target(0.f, 0.f);
curve->UpdateTarget(base::Seconds(initial_duration / 2), updated_target);
EXPECT_NEAR(initial_target_value.y() * halfway_through_default_impulse_curve,
@ -235,11 +235,11 @@ TEST(ScrollOffsetAnimationCurveTest, ImpulseUpdateTargetSwitchDirections) {
// Once the impulse style curve is updated, it turns to an ease-in ease-out
// type curve.
double updated_duration =
curve
->EaseInOutBoundedSegmentDuration(
updated_initial_value, base::TimeDelta(), base::TimeDelta())
.InSecondsF();
double updated_duration = curve
->EaseInOutBoundedSegmentDuration(
updated_initial_value.OffsetFromOrigin(),
base::TimeDelta(), base::TimeDelta())
.InSecondsF();
EXPECT_NEAR(updated_initial_value.y() * 0.5,
curve
->GetValue(base::Seconds(initial_duration / 2.0 +
@ -256,28 +256,28 @@ TEST(ScrollOffsetAnimationCurveTest, ImpulseUpdateTargetSwitchDirections) {
TEST(ScrollOffsetAnimationCurveTest, InverseDeltaDuration) {
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
gfx::Vector2dF(0.f, 100.f), DurationBehavior::INVERSE_DELTA));
gfx::PointF(0.f, 100.f), DurationBehavior::INVERSE_DELTA));
curve->SetInitialValue(gfx::Vector2dF());
curve->SetInitialValue(gfx::PointF());
double smallDeltaDuration = curve->Duration().InSecondsF();
curve->UpdateTarget(base::Seconds(0.01f), gfx::Vector2dF(0.f, 300.f));
curve->UpdateTarget(base::Seconds(0.01f), gfx::PointF(0.f, 300.f));
double mediumDeltaDuration = curve->Duration().InSecondsF();
curve->UpdateTarget(base::Seconds(0.01f), gfx::Vector2dF(0.f, 500.f));
curve->UpdateTarget(base::Seconds(0.01f), gfx::PointF(0.f, 500.f));
double largeDeltaDuration = curve->Duration().InSecondsF();
EXPECT_GT(smallDeltaDuration, mediumDeltaDuration);
EXPECT_GT(mediumDeltaDuration, largeDeltaDuration);
curve->UpdateTarget(base::Seconds(0.01f), gfx::Vector2dF(0.f, 5000.f));
curve->UpdateTarget(base::Seconds(0.01f), gfx::PointF(0.f, 5000.f));
EXPECT_EQ(largeDeltaDuration, curve->Duration().InSecondsF());
}
TEST(ScrollOffsetAnimationCurveTest, LinearAnimation) {
// Testing autoscroll downwards for a scroller of length 1000px.
gfx::Vector2dF current_offset(0.f, 0.f);
gfx::Vector2dF target_offset(0.f, 1000.f);
gfx::PointF current_offset(0.f, 0.f);
gfx::PointF target_offset(0.f, 1000.f);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateLinearAnimationForTesting(
target_offset));
@ -288,13 +288,13 @@ TEST(ScrollOffsetAnimationCurveTest, LinearAnimation) {
EXPECT_FLOAT_EQ(1.25f, curve->Duration().InSecondsF());
// Test scrolling down from half way.
current_offset = gfx::Vector2dF(0.f, 500.f);
current_offset = gfx::PointF(0.f, 500.f);
curve->SetInitialValue(current_offset, base::TimeDelta(),
autoscroll_velocity);
EXPECT_FLOAT_EQ(0.625f, curve->Duration().InSecondsF());
// Test scrolling down when max_offset is reached.
current_offset = gfx::Vector2dF(0.f, 1000.f);
current_offset = gfx::PointF(0.f, 1000.f);
curve->SetInitialValue(current_offset, base::TimeDelta(),
autoscroll_velocity);
EXPECT_FLOAT_EQ(0.f, curve->Duration().InSecondsF());
@ -304,9 +304,9 @@ TEST(ScrollOffsetAnimationCurveTest, ImpulseDuration) {
// The duration of an impulse-style curve in milliseconds is simply 1.5x the
// scroll distance in physical pixels, with a minimum of 200ms and a maximum
// of 500ms.
gfx::Vector2dF small_delta = gfx::Vector2dF(0.f, 100.f);
gfx::Vector2dF moderate_delta = gfx::Vector2dF(0.f, 250.f);
gfx::Vector2dF large_delta = gfx::Vector2dF(0.f, 400.f);
gfx::Vector2dF small_delta(0.f, 100.f);
gfx::Vector2dF moderate_delta(0.f, 250.f);
gfx::Vector2dF large_delta(0.f, 400.f);
base::TimeDelta duration = ScrollOffsetAnimationCurve::ImpulseSegmentDuration(
small_delta, base::TimeDelta());
@ -324,29 +324,29 @@ TEST(ScrollOffsetAnimationCurveTest, ImpulseDuration) {
TEST(ScrollOffsetAnimationCurveTest, CurveWithDelay) {
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
gfx::Vector2dF(0.f, 100.f), DurationBehavior::INVERSE_DELTA));
gfx::PointF(0.f, 100.f), DurationBehavior::INVERSE_DELTA));
double duration_in_seconds = kInverseDeltaMaxDuration / kDurationDivisor;
double delay_in_seconds = 0.02;
double curve_duration = duration_in_seconds - delay_in_seconds;
curve->SetInitialValue(gfx::Vector2dF(), base::Seconds(delay_in_seconds));
curve->SetInitialValue(gfx::PointF(), base::Seconds(delay_in_seconds));
EXPECT_NEAR(curve_duration, curve->Duration().InSecondsF(), 0.0002f);
curve->UpdateTarget(base::Seconds(0.01f), gfx::Vector2dF(0.f, 500.f));
curve->UpdateTarget(base::Seconds(0.01f), gfx::PointF(0.f, 500.f));
EXPECT_GT(curve_duration, curve->Duration().InSecondsF());
EXPECT_EQ(gfx::Vector2dF(0.f, 500.f), curve->target_value());
EXPECT_EQ(gfx::PointF(0.f, 500.f), curve->target_value());
}
TEST(ScrollOffsetAnimationCurveTest, CurveWithLargeDelay) {
DurationBehavior duration_hint = DurationBehavior::INVERSE_DELTA;
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
gfx::Vector2dF(0.f, 100.f), duration_hint));
curve->SetInitialValue(gfx::Vector2dF(), base::Seconds(0.2));
gfx::PointF(0.f, 100.f), duration_hint));
curve->SetInitialValue(gfx::PointF(), base::Seconds(0.2));
EXPECT_EQ(0.f, curve->Duration().InSecondsF());
// Re-targeting when animation duration is 0.
curve->UpdateTarget(base::Seconds(-0.01), gfx::Vector2dF(0.f, 300.f));
curve->UpdateTarget(base::Seconds(-0.01), gfx::PointF(0.f, 300.f));
double duration =
ScrollOffsetAnimationCurve::EaseInOutSegmentDuration(
gfx::Vector2dF(0.f, 200.f), duration_hint, base::Seconds(0.01))
@ -355,14 +355,14 @@ TEST(ScrollOffsetAnimationCurveTest, CurveWithLargeDelay) {
// Re-targeting before last_retarget_, the difference should be accounted for
// in duration.
curve->UpdateTarget(base::Seconds(-0.01), gfx::Vector2dF(0.f, 500.f));
curve->UpdateTarget(base::Seconds(-0.01), gfx::PointF(0.f, 500.f));
duration = ScrollOffsetAnimationCurve::EaseInOutSegmentDuration(
gfx::Vector2dF(0.f, 500.f), duration_hint, base::Seconds(0.01))
.InSecondsF();
EXPECT_EQ(duration, curve->Duration().InSecondsF());
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0.f, 500.f),
curve->GetValue(base::Seconds(1.0)));
EXPECT_POINTF_EQ(gfx::PointF(0.f, 500.f),
curve->GetValue(base::Seconds(1.0)));
}
// This test verifies that if the last segment duration is zero, ::UpdateTarget
@ -371,37 +371,37 @@ TEST(ScrollOffsetAnimationCurveTest, UpdateTargetZeroLastSegmentDuration) {
DurationBehavior duration_hint = DurationBehavior::INVERSE_DELTA;
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
gfx::Vector2dF(0.f, 100.f), duration_hint));
gfx::PointF(0.f, 100.f), duration_hint));
double duration_in_seconds = kInverseDeltaMaxDuration / kDurationDivisor;
double delay_in_seconds = 0.02;
double curve_duration = duration_in_seconds - delay_in_seconds;
curve->SetInitialValue(gfx::Vector2dF(), base::Seconds(delay_in_seconds));
curve->SetInitialValue(gfx::PointF(), base::Seconds(delay_in_seconds));
EXPECT_NEAR(curve_duration, curve->Duration().InSecondsF(), 0.0002f);
// Re-target 1, this should set last_retarget_ to 0.05.
gfx::Vector2dF new_delta =
gfx::Vector2dF(0.f, 200.f) - curve->GetValue(base::Seconds(0.05));
gfx::PointF(0.f, 200.f) - curve->GetValue(base::Seconds(0.05));
double expected_duration =
ScrollOffsetAnimationCurve::EaseInOutSegmentDuration(
new_delta, duration_hint, base::TimeDelta())
.InSecondsF() +
0.05;
curve->UpdateTarget(base::Seconds(0.05), gfx::Vector2dF(0.f, 200.f));
curve->UpdateTarget(base::Seconds(0.05), gfx::PointF(0.f, 200.f));
EXPECT_NEAR(expected_duration, curve->Duration().InSecondsF(), 0.0002f);
// Re-target 2, this should set total_animation_duration to t, which is
// last_retarget_. This is what would cause the DCHECK failure in
// crbug.com/645317.
curve->UpdateTarget(base::Seconds(-0.145), gfx::Vector2dF(0.f, 300.f));
curve->UpdateTarget(base::Seconds(-0.145), gfx::PointF(0.f, 300.f));
EXPECT_NEAR(0.05, curve->Duration().InSecondsF(), 0.0002f);
// Re-target 3, this should set total_animation_duration based on new_delta.
new_delta = gfx::Vector2dF(0.f, 500.f) - curve->GetValue(base::Seconds(0.05));
new_delta = gfx::PointF(0.f, 500.f) - curve->GetValue(base::Seconds(0.05));
expected_duration = ScrollOffsetAnimationCurve::EaseInOutSegmentDuration(
new_delta, duration_hint, base::Seconds(0.15))
.InSecondsF();
curve->UpdateTarget(base::Seconds(-0.1), gfx::Vector2dF(0.f, 500.f));
curve->UpdateTarget(base::Seconds(-0.1), gfx::PointF(0.f, 500.f));
EXPECT_NEAR(expected_duration, curve->Duration().InSecondsF(), 0.0002f);
}

@ -39,8 +39,8 @@ ScrollOffsetAnimationsImpl::~ScrollOffsetAnimationsImpl() {
void ScrollOffsetAnimationsImpl::AutoScrollAnimationCreate(
ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
float autoscroll_velocity,
base::TimeDelta animation_start_offset) {
std::unique_ptr<ScrollOffsetAnimationCurve> curve =
@ -55,8 +55,8 @@ void ScrollOffsetAnimationsImpl::AutoScrollAnimationCreate(
void ScrollOffsetAnimationsImpl::MouseWheelScrollAnimationCreate(
ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
base::TimeDelta delayed_by,
base::TimeDelta animation_start_offset) {
std::unique_ptr<ScrollOffsetAnimationCurve> curve =
@ -92,7 +92,7 @@ void ScrollOffsetAnimationsImpl::ScrollAnimationCreateInternal(
bool ScrollOffsetAnimationsImpl::ScrollAnimationUpdateTarget(
const gfx::Vector2dF& scroll_delta,
const gfx::Vector2dF& max_scroll_offset,
const gfx::PointF& max_scroll_offset,
base::TimeTicks frame_monotonic_time,
base::TimeDelta delayed_by) {
DCHECK(scroll_offset_animation_);
@ -117,8 +117,8 @@ bool ScrollOffsetAnimationsImpl::ScrollAnimationUpdateTarget(
ScrollOffsetAnimationCurve::ToScrollOffsetAnimationCurve(
keyframe_model->curve());
gfx::Vector2dF new_target = curve->target_value() + scroll_delta;
new_target.SetToMax(gfx::Vector2dF());
gfx::PointF new_target = curve->target_value() + scroll_delta;
new_target.SetToMax(gfx::PointF());
new_target.SetToMin(max_scroll_offset);
// TODO(ymalik): KeyframeModel::TrimTimeToCurrentIteration should probably

@ -35,8 +35,8 @@ class CC_ANIMATION_EXPORT ScrollOffsetAnimationsImpl
delete;
void AutoScrollAnimationCreate(ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
float autoscroll_velocity,
base::TimeDelta animation_start_offset);
@ -44,13 +44,13 @@ class CC_ANIMATION_EXPORT ScrollOffsetAnimationsImpl
// animation. |animation_start_offset| causes us to start the animation
// partway through.
void MouseWheelScrollAnimationCreate(ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
base::TimeDelta delayed_by,
base::TimeDelta animation_start_offset);
bool ScrollAnimationUpdateTarget(const gfx::Vector2dF& scroll_delta,
const gfx::Vector2dF& max_scroll_offset,
const gfx::PointF& max_scroll_offset,
base::TimeTicks frame_monotonic_time,
base::TimeDelta delayed_by);

@ -11,8 +11,8 @@
#include "cc/animation/worklet_animation.h"
#include "cc/trees/property_tree.h"
#include "cc/trees/scroll_node.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
@ -97,13 +97,11 @@ absl::optional<base::TimeTicks> ScrollTimeline::CurrentTime(
const ScrollNode* scroll_node =
scroll_tree.FindNodeFromElementId(scroller_id);
gfx::Vector2dF offset =
scroll_tree.GetPixelSnappedScrollOffset(scroll_node->id);
gfx::PointF offset = scroll_tree.GetPixelSnappedScrollOffset(scroll_node->id);
DCHECK_GE(offset.x(), 0);
DCHECK_GE(offset.y(), 0);
gfx::Vector2dF scroll_dimensions =
scroll_tree.MaxScrollOffset(scroll_node->id);
gfx::PointF scroll_dimensions = scroll_tree.MaxScrollOffset(scroll_node->id);
double max_offset =
IsVertical(direction_) ? scroll_dimensions.y() : scroll_dimensions.x();

@ -11,7 +11,7 @@
#include "cc/trees/scroll_node.h"
#include "cc/trees/transform_node.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/geometry/point_f.h"
namespace cc {
@ -26,7 +26,7 @@ static constexpr double time_error_ms = 0.001;
void SetScrollOffset(PropertyTrees* property_trees,
ElementId scroller_id,
gfx::Vector2dF offset) {
gfx::PointF offset) {
// Update both scroll and transform trees
property_trees->scroll_tree.SetScrollOffset(scroller_id, offset);
TransformNode* transform_node =
@ -121,14 +121,14 @@ TEST_F(ScrollTimelineTest, BasicCurrentTimeCalculations) {
scroller_id(), ScrollTimeline::ScrollRight, scroll_offsets);
// Unscrolled, both timelines should read a current time of 0.
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF());
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF());
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
0, vertical_timeline->CurrentTime(scroll_tree(), false));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
0, horizontal_timeline->CurrentTime(scroll_tree(), false));
// Now do some scrolling and make sure that the ScrollTimelines update.
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(75, 50));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(75, 50));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
0.5 * ScrollTimeline::kScrollTimelineDurationMs,
@ -158,44 +158,44 @@ TEST_F(ScrollTimelineTest, MultipleScrollOffsetsCurrentTimeCalculations) {
// Scale necessary to convert absolute unit times to progress based values
double scale = ScrollTimeline::kScrollTimelineDurationMs / scroll_size;
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF());
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF());
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
(offset + p) * w * scroll_size * scale,
vertical_timeline->CurrentTime(scroll_tree(), false));
p = (70.0 - 0.0) / (100.0 - 0.0);
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 70));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 70));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
(offset + p) * w * scroll_size * scale,
vertical_timeline->CurrentTime(scroll_tree(), false));
offset = 1;
p = 0;
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 100));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 100));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
(offset + p) * w * scroll_size * scale,
vertical_timeline->CurrentTime(scroll_tree(), false));
p = (150.0 - 100.0) / (250.0 - 100.0);
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 150));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 150));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
(offset + p) * w * scroll_size * scale,
vertical_timeline->CurrentTime(scroll_tree(), false));
offset = 2;
p = 0;
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 250));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 250));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
(offset + p) * w * scroll_size * scale,
vertical_timeline->CurrentTime(scroll_tree(), false));
p = (350.0 - 250.0) / (400.0 - 250.0);
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 350));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 350));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
(offset + p) * w * scroll_size * scale,
vertical_timeline->CurrentTime(scroll_tree(), false));
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 400));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 400));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
ScrollTimeline::kScrollTimelineDurationMs,
vertical_timeline->CurrentTime(scroll_tree(), false));
@ -212,7 +212,7 @@ TEST_F(ScrollTimelineTest, OverlappingScrollOffsets) {
scroller_id(), ScrollTimeline::ScrollDown, scroll_offsets);
// Offset is less than start offset ==> current time is 0.
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 300));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 300));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
0, vertical_timeline->CurrentTime(scroll_tree(), false));
@ -220,7 +220,7 @@ TEST_F(ScrollTimelineTest, OverlappingScrollOffsets) {
double scale = ScrollTimeline::kScrollTimelineDurationMs / scroll_size;
// Offset is greater than end offset ==> current time is 100%.
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 360));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 360));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
scroll_size * scale,
vertical_timeline->CurrentTime(scroll_tree(), false));
@ -230,7 +230,7 @@ TEST_F(ScrollTimelineTest, OverlappingScrollOffsets) {
vertical_timeline = ScrollTimeline::Create(
scroller_id(), ScrollTimeline::ScrollDown, scroll_offsets);
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 100));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 100));
// Scroll offset is 25% of [0, 400) range, which maps to [0% 50%) of the
// entire scroll range.
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
@ -242,7 +242,7 @@ TEST_F(ScrollTimelineTest, OverlappingScrollOffsets) {
vertical_timeline = ScrollTimeline::Create(
scroller_id(), ScrollTimeline::ScrollDown, scroll_offsets);
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 300));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 300));
// Scroll offset is 75% of [0, 400) range, which maps to [50% 100%) of the
// entire scroll range.
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
@ -277,7 +277,7 @@ TEST_F(ScrollTimelineTest, ActiveTimeIsSetOnlyAfterPromotion) {
double halfwayY = scroll_size / 2.;
double expectedTime = 0.5 * ScrollTimeline::kScrollTimelineDurationMs;
SetScrollOffset(&pending_tree, scroller_id, gfx::Vector2dF(0, halfwayY));
SetScrollOffset(&pending_tree, scroller_id, gfx::PointF(0, halfwayY));
scoped_refptr<ScrollTimeline> main_timeline = ScrollTimeline::Create(
scroller_id, ScrollTimeline::ScrollDown, scroll_offsets);
@ -314,7 +314,7 @@ TEST_F(ScrollTimelineTest, CurrentTimeIsAdjustedForPixelSnapping) {
scoped_refptr<ScrollTimeline> timeline = ScrollTimeline::Create(
scroller_id(), ScrollTimeline::ScrollDown, scroll_offsets);
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 50));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 50));
// For simplicity emulate snapping by directly setting snap_amount of
// transform node.
@ -340,24 +340,24 @@ TEST_F(ScrollTimelineTest, CurrentTimeHandlesStartScrollOffset) {
// Unscrolled, the timeline should read a current time of 0 since the current
// offset (0) will be less than the startScrollOffset.
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF());
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF());
EXPECT_SCROLL_TIMELINE_TIME_NEAR(0,
timeline->CurrentTime(scroll_tree(), false));
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 19));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 19));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(0,
timeline->CurrentTime(scroll_tree(), false));
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 20));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 20));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(0,
timeline->CurrentTime(scroll_tree(), false));
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 50));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 50));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
CalculateCurrentTime(50, start_scroll_offset, scroll_size),
timeline->CurrentTime(scroll_tree(), false));
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 200));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 200));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
CalculateCurrentTime(200, start_scroll_offset, scroll_size),
timeline->CurrentTime(scroll_tree(), false));
@ -373,23 +373,23 @@ TEST_F(ScrollTimelineTest, CurrentTimeHandlesEndScrollOffset) {
scroller_id(), ScrollTimeline::ScrollDown, scroll_offsets);
SetScrollOffset(&property_trees(), scroller_id(),
gfx::Vector2dF(0, scroll_size));
gfx::PointF(0, scroll_size));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(ScrollTimeline::kScrollTimelineDurationMs,
timeline->CurrentTime(scroll_tree(), false));
SetScrollOffset(&property_trees(), scroller_id(),
gfx::Vector2dF(0, scroll_size - 20));
gfx::PointF(0, scroll_size - 20));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(ScrollTimeline::kScrollTimelineDurationMs,
timeline->CurrentTime(scroll_tree(), false));
SetScrollOffset(&property_trees(), scroller_id(),
gfx::Vector2dF(0, scroll_size - 50));
gfx::PointF(0, scroll_size - 50));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
CalculateCurrentTime(scroll_size - 50, 0, end_scroll_offset),
timeline->CurrentTime(scroll_tree(), false));
SetScrollOffset(&property_trees(), scroller_id(),
gfx::Vector2dF(0, scroll_size - 200));
gfx::PointF(0, scroll_size - 200));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
CalculateCurrentTime(scroll_size - 200, 0, end_scroll_offset),
timeline->CurrentTime(scroll_tree(), false));
@ -405,7 +405,7 @@ TEST_F(ScrollTimelineTest, CurrentTimeHandlesCombinedStartAndEndScrollOffset) {
scoped_refptr<ScrollTimeline> timeline = ScrollTimeline::Create(
scroller_id(), ScrollTimeline::ScrollDown, scroll_offsets);
SetScrollOffset(&property_trees(), scroller_id(),
gfx::Vector2dF(0, scroll_size - 150));
gfx::PointF(0, scroll_size - 150));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(
CalculateCurrentTime(scroll_size - 150, start_scroll_offset,
end_scroll_offset),
@ -418,7 +418,7 @@ TEST_F(ScrollTimelineTest, CurrentTimeHandlesEqualStartAndEndScrollOffset) {
scroll_offsets.push_back(20);
scoped_refptr<ScrollTimeline> timeline = ScrollTimeline::Create(
scroller_id(), ScrollTimeline::ScrollDown, scroll_offsets);
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 150));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 150));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(ScrollTimeline::kScrollTimelineDurationMs,
timeline->CurrentTime(scroll_tree(), false));
@ -431,11 +431,11 @@ TEST_F(ScrollTimelineTest,
scroll_offsets.push_back(10);
scoped_refptr<ScrollTimeline> timeline = ScrollTimeline::Create(
scroller_id(), ScrollTimeline::ScrollDown, scroll_offsets);
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 40));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 40));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(0,
timeline->CurrentTime(scroll_tree(), false));
SetScrollOffset(&property_trees(), scroller_id(), gfx::Vector2dF(0, 150));
SetScrollOffset(&property_trees(), scroller_id(), gfx::PointF(0, 150));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(ScrollTimeline::kScrollTimelineDurationMs,
timeline->CurrentTime(scroll_tree(), false));
@ -455,19 +455,19 @@ TEST_F(ScrollTimelineTest, CurrentTimeHandlesScrollOffsets) {
// Before the start_scroll_offset the current time should be 0
SetScrollOffset(&property_trees(), scroller_id(),
gfx::Vector2dF(0, start_scroll_offset - 10));
gfx::PointF(0, start_scroll_offset - 10));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(0,
timeline->CurrentTime(scroll_tree(), false));
// At the end_scroll_offset the current time should be 100%
SetScrollOffset(&property_trees(), scroller_id(),
gfx::Vector2dF(0, end_scroll_offset));
gfx::PointF(0, end_scroll_offset));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(ScrollTimeline::kScrollTimelineDurationMs,
timeline->CurrentTime(scroll_tree(), false));
// After the end_scroll_offset the current time should be 100%
SetScrollOffset(&property_trees(), scroller_id(),
gfx::Vector2dF(0, end_scroll_offset + 10));
gfx::PointF(0, end_scroll_offset + 10));
EXPECT_SCROLL_TIMELINE_TIME_NEAR(ScrollTimeline::kScrollTimelineDurationMs,
timeline->CurrentTime(scroll_tree(), false));
}

@ -6,7 +6,7 @@
#define CC_INPUT_BROWSER_CONTROLS_OFFSET_MANAGER_CLIENT_H_
namespace gfx {
class Vector2dF;
class PointF;
}
namespace cc {
@ -21,7 +21,7 @@ class CC_EXPORT BrowserControlsOffsetManagerClient {
float bottom_ratio) = 0;
virtual float CurrentTopControlsShownRatio() const = 0;
virtual float CurrentBottomControlsShownRatio() const = 0;
virtual gfx::Vector2dF ViewportScrollOffset() const = 0;
virtual gfx::PointF ViewportScrollOffset() const = 0;
virtual void DidChangeBrowserControlsPosition() = 0;
virtual bool OnlyExpandTopControlsAtPageTop() const = 0;
virtual bool HaveRootScrollNode() const = 0;

@ -72,7 +72,7 @@ class MockBrowserControlsOffsetManagerClient
return browser_controls_params_.only_expand_top_controls_at_page_top;
}
gfx::Vector2dF ViewportScrollOffset() const override {
gfx::PointF ViewportScrollOffset() const override {
return viewport_scroll_offset_;
}
@ -121,12 +121,12 @@ class MockBrowserControlsOffsetManagerClient
}
void SetViewportScrollOffset(float x, float y) {
viewport_scroll_offset_ = gfx::Vector2dF(x, y);
viewport_scroll_offset_ = gfx::PointF(x, y);
}
void ScrollVerticallyBy(float dy) {
gfx::Vector2dF viewport_scroll_delta = manager()->ScrollBy({0.f, dy});
viewport_scroll_offset_.Add(viewport_scroll_delta);
viewport_scroll_offset_ += viewport_scroll_delta;
}
private:
@ -144,7 +144,7 @@ class MockBrowserControlsOffsetManagerClient
float top_controls_shown_ratio_;
float browser_controls_show_threshold_;
float browser_controls_hide_threshold_;
gfx::Vector2dF viewport_scroll_offset_;
gfx::PointF viewport_scroll_offset_;
};
TEST(BrowserControlsOffsetManagerTest, EnsureScrollThresholdApplied) {

@ -20,11 +20,12 @@
#include "components/viz/common/frame_sinks/begin_frame_args.h"
#include "ui/events/types/scroll_input_type.h"
#include "ui/events/types/scroll_types.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace gfx {
class Point;
class SizeF;
class Vector2dF;
} // namespace gfx
namespace ui {
@ -64,7 +65,7 @@ struct CC_EXPORT InputHandlerPointerResult {
// instead of the input handler performing it as a part of handling the
// pointer event (due to the latency attribution that happens at the
// InputHandlerProxy level).
gfx::Vector2dF scroll_offset;
gfx::Vector2dF scroll_delta;
// Used to determine which scroll_node needs to be scrolled. The primary
// purpose of this is to avoid hit testing for gestures that already know
@ -92,7 +93,7 @@ struct CC_EXPORT InputHandlerScrollResult {
// physical pixels depending on the use-zoom-for-dsf flag. If the currently
// scrolling node is the viewport, this would be the sum of the scroll offsets
// of the inner and outer node, representing the visual scroll offset.
gfx::Vector2dF current_visual_offset;
gfx::PointF current_visual_offset;
};
class CC_EXPORT InputHandlerClient {
@ -107,8 +108,8 @@ class CC_EXPORT InputHandlerClient {
virtual void ReconcileElasticOverscrollAndRootScroll() = 0;
virtual void SetPrefersReducedMotion(bool prefers_reduced_motion) = 0;
virtual void UpdateRootLayerStateForSynchronousInputHandler(
const gfx::Vector2dF& total_scroll_offset,
const gfx::Vector2dF& max_scroll_offset,
const gfx::PointF& total_scroll_offset,
const gfx::PointF& max_scroll_offset,
const gfx::SizeF& scrollable_size,
float page_scale_factor,
float min_page_scale_factor,
@ -296,7 +297,7 @@ class CC_EXPORT InputHandler {
// input handler by the application (outside of input event handling). Offset
// is expected in "content/page coordinates".
virtual void SetSynchronousInputHandlerRootScrollOffset(
const gfx::Vector2dF& root_content_offset) = 0;
const gfx::PointF& root_content_offset) = 0;
virtual void PinchGestureBegin() = 0;
virtual void PinchGestureUpdate(float magnify_delta,
@ -357,9 +358,9 @@ class CC_EXPORT InputHandler {
// Called by the single-threaded UI Compositor to get or set the scroll offset
// on the impl side. Returns false if |element_id| isn't in the active tree.
virtual bool GetScrollOffsetForLayer(ElementId element_id,
gfx::Vector2dF* offset) = 0;
gfx::PointF* offset) = 0;
virtual bool ScrollLayerTo(ElementId element_id,
const gfx::Vector2dF& offset) = 0;
const gfx::PointF& offset) = 0;
virtual bool ScrollingShouldSwitchtoMainThread() = 0;
@ -371,8 +372,8 @@ class CC_EXPORT InputHandler {
// Returns false if their is no position to snap to.
virtual bool GetSnapFlingInfoAndSetAnimatingSnapTarget(
const gfx::Vector2dF& natural_displacement_in_viewport,
gfx::Vector2dF* initial_offset,
gfx::Vector2dF* target_offset) = 0;
gfx::PointF* initial_offset,
gfx::PointF* target_offset) = 0;
// |did_finish| is true if the animation reached its target position (i.e.
// it wasn't aborted).

@ -43,7 +43,7 @@ namespace cc {
using base::TimeTicks;
std::unique_ptr<PageScaleAnimation> PageScaleAnimation::Create(
const gfx::Vector2dF& start_scroll_offset,
const gfx::PointF& start_scroll_offset,
float start_page_scale_factor,
const gfx::SizeF& viewport_size,
const gfx::SizeF& root_layer_size) {
@ -52,11 +52,10 @@ std::unique_ptr<PageScaleAnimation> PageScaleAnimation::Create(
viewport_size, root_layer_size));
}
PageScaleAnimation::PageScaleAnimation(
const gfx::Vector2dF& start_scroll_offset,
float start_page_scale_factor,
const gfx::SizeF& viewport_size,
const gfx::SizeF& root_layer_size)
PageScaleAnimation::PageScaleAnimation(const gfx::PointF& start_scroll_offset,
float start_page_scale_factor,
const gfx::SizeF& viewport_size,
const gfx::SizeF& root_layer_size)
: start_page_scale_factor_(start_page_scale_factor),
target_page_scale_factor_(0.f),
start_scroll_offset_(start_scroll_offset),
@ -69,7 +68,7 @@ PageScaleAnimation::PageScaleAnimation(
PageScaleAnimation::~PageScaleAnimation() = default;
void PageScaleAnimation::ZoomTo(const gfx::Vector2dF& target_scroll_offset,
void PageScaleAnimation::ZoomTo(const gfx::PointF& target_scroll_offset,
float target_page_scale_factor,
double duration) {
target_page_scale_factor_ = target_page_scale_factor;
@ -89,7 +88,7 @@ void PageScaleAnimation::ZoomTo(const gfx::Vector2dF& target_scroll_offset,
start_anchor_ = target_anchor_;
}
void PageScaleAnimation::ZoomWithAnchor(const gfx::Vector2dF& anchor,
void PageScaleAnimation::ZoomWithAnchor(const gfx::PointF& anchor,
float target_page_scale_factor,
double duration) {
start_anchor_ = anchor;
@ -140,11 +139,11 @@ void PageScaleAnimation::InferTargetAnchorFromScrollOffsets() {
}
void PageScaleAnimation::ClampTargetScrollOffset() {
gfx::Vector2dF max_scroll_offset =
gfx::PointF max_scroll_offset = gfx::PointAtOffsetFromOrigin(
gfx::RectF(root_layer_size_).bottom_right() -
gfx::RectF(gfx::SizeF(TargetViewportSize())).bottom_right();
gfx::RectF(gfx::SizeF(TargetViewportSize())).bottom_right());
target_scroll_offset_.SetToMin(max_scroll_offset);
target_scroll_offset_.SetToMax(gfx::Vector2dF());
target_scroll_offset_.SetToMax(gfx::PointF());
}
gfx::SizeF PageScaleAnimation::StartViewportSize() const {
@ -168,8 +167,7 @@ void PageScaleAnimation::StartAnimation(base::TimeTicks time) {
start_time_ = time;
}
gfx::Vector2dF PageScaleAnimation::ScrollOffsetAtTime(
base::TimeTicks time) const {
gfx::PointF PageScaleAnimation::ScrollOffsetAtTime(base::TimeTicks time) const {
DCHECK(!start_time_.is_null());
return ScrollOffsetAt(InterpAtTime(time));
}
@ -194,7 +192,7 @@ float PageScaleAnimation::InterpAtTime(base::TimeTicks monotonic_time) const {
return static_cast<float>(timing_function_.Solve(normalized_time));
}
gfx::Vector2dF PageScaleAnimation::ScrollOffsetAt(float interp) const {
gfx::PointF PageScaleAnimation::ScrollOffsetAt(float interp) const {
if (interp <= 0.f)
return start_scroll_offset_;
if (interp >= 1.f)
@ -203,9 +201,11 @@ gfx::Vector2dF PageScaleAnimation::ScrollOffsetAt(float interp) const {
return AnchorAt(interp) - ViewportRelativeAnchorAt(interp);
}
gfx::Vector2dF PageScaleAnimation::AnchorAt(float interp) const {
gfx::PointF PageScaleAnimation::AnchorAt(float interp) const {
// Interpolate from start to target anchor in absolute space.
return InterpolateBetween(start_anchor_, target_anchor_, interp);
return gfx::PointAtOffsetFromOrigin(
InterpolateBetween(start_anchor_.OffsetFromOrigin(),
target_anchor_.OffsetFromOrigin(), interp));
}
gfx::Vector2dF PageScaleAnimation::ViewportRelativeAnchorAt(

@ -10,8 +10,9 @@
#include "base/time/time.h"
#include "cc/cc_export.h"
#include "ui/gfx/geometry/cubic_bezier.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
@ -19,7 +20,7 @@ namespace cc {
// Used in the CC to pass around a scale animation that hasn't yet been
// initialized.
struct PendingPageScaleAnimation {
PendingPageScaleAnimation(const gfx::Vector2d& target_offset,
PendingPageScaleAnimation(const gfx::Point& target_offset,
bool use_anchor,
float scale,
const base::TimeDelta& duration)
@ -27,7 +28,7 @@ struct PendingPageScaleAnimation {
use_anchor(use_anchor),
scale(scale),
duration(duration) {}
gfx::Vector2d target_offset;
gfx::Point target_offset;
bool use_anchor;
float scale;
base::TimeDelta duration;
@ -45,7 +46,7 @@ class CC_EXPORT PageScaleAnimation {
public:
// Construct with the state at the beginning of the animation.
static std::unique_ptr<PageScaleAnimation> Create(
const gfx::Vector2dF& start_scroll_offset,
const gfx::PointF& start_scroll_offset,
float start_page_scale_factor,
const gfx::SizeF& viewport_size,
const gfx::SizeF& root_layer_size);
@ -59,7 +60,7 @@ class CC_EXPORT PageScaleAnimation {
// immediately after construction to set the final scroll and page scale.
// Zoom while explicitly specifying the top-left scroll position.
void ZoomTo(const gfx::Vector2dF& target_scroll_offset,
void ZoomTo(const gfx::PointF& target_scroll_offset,
float target_page_scale_factor,
double duration);
@ -67,7 +68,7 @@ class CC_EXPORT PageScaleAnimation {
// at the same position on the physical display throughout the animation,
// unless the edges of the root layer are hit. The anchor is specified
// as an offset from the content layer.
void ZoomWithAnchor(const gfx::Vector2dF& anchor,
void ZoomWithAnchor(const gfx::PointF& anchor,
float target_page_scale_factor,
double duration);
@ -78,7 +79,7 @@ class CC_EXPORT PageScaleAnimation {
// Call these functions while the animation is in progress to output the
// current state.
gfx::Vector2dF ScrollOffsetAtTime(base::TimeTicks time) const;
gfx::PointF ScrollOffsetAtTime(base::TimeTicks time) const;
float PageScaleFactorAtTime(base::TimeTicks time) const;
bool IsAnimationCompleteAtTime(base::TimeTicks time) const;
@ -87,11 +88,11 @@ class CC_EXPORT PageScaleAnimation {
base::TimeTicks start_time() const { return start_time_; }
base::TimeDelta duration() const { return duration_; }
base::TimeTicks end_time() const { return start_time_ + duration_; }
gfx::Vector2dF target_scroll_offset() const { return target_scroll_offset_; }
gfx::PointF target_scroll_offset() const { return target_scroll_offset_; }
float target_page_scale_factor() const { return target_page_scale_factor_; }
protected:
PageScaleAnimation(const gfx::Vector2dF& start_scroll_offset,
PageScaleAnimation(const gfx::PointF& start_scroll_offset,
float start_page_scale_factor,
const gfx::SizeF& viewport_size,
const gfx::SizeF& root_layer_size);
@ -105,18 +106,18 @@ class CC_EXPORT PageScaleAnimation {
gfx::SizeF TargetViewportSize() const;
float InterpAtTime(base::TimeTicks time) const;
gfx::SizeF ViewportSizeAt(float interp) const;
gfx::Vector2dF ScrollOffsetAt(float interp) const;
gfx::Vector2dF AnchorAt(float interp) const;
gfx::PointF ScrollOffsetAt(float interp) const;
gfx::PointF AnchorAt(float interp) const;
gfx::Vector2dF ViewportRelativeAnchorAt(float interp) const;
float PageScaleFactorAt(float interp) const;
float start_page_scale_factor_;
float target_page_scale_factor_;
gfx::Vector2dF start_scroll_offset_;
gfx::Vector2dF target_scroll_offset_;
gfx::PointF start_scroll_offset_;
gfx::PointF target_scroll_offset_;
gfx::Vector2dF start_anchor_;
gfx::Vector2dF target_anchor_;
gfx::PointF start_anchor_;
gfx::PointF target_anchor_;
gfx::SizeF viewport_size_;
gfx::SizeF root_layer_size_;

@ -20,8 +20,8 @@ class ScrollElasticityHelperImpl : public ScrollElasticityHelper {
gfx::Vector2dF StretchAmount() const override;
gfx::Size ScrollBounds() const override;
void SetStretchAmount(const gfx::Vector2dF& stretch_amount) override;
gfx::Vector2dF ScrollOffset() const override;
gfx::Vector2dF MaxScrollOffset() const override;
gfx::PointF ScrollOffset() const override;
gfx::PointF MaxScrollOffset() const override;
void ScrollBy(const gfx::Vector2dF& delta) override;
void RequestOneBeginFrame() override;
@ -65,11 +65,11 @@ void ScrollElasticityHelperImpl::SetStretchAmount(
host_impl_->SetFullViewportDamage();
}
gfx::Vector2dF ScrollElasticityHelperImpl::ScrollOffset() const {
gfx::PointF ScrollElasticityHelperImpl::ScrollOffset() const {
return host_impl_->active_tree()->TotalScrollOffset();
}
gfx::Vector2dF ScrollElasticityHelperImpl::MaxScrollOffset() const {
gfx::PointF ScrollElasticityHelperImpl::MaxScrollOffset() const {
return host_impl_->active_tree()->TotalMaxScrollOffset();
}

@ -6,6 +6,7 @@
#define CC_INPUT_SCROLL_ELASTICITY_HELPER_H_
#include "cc/cc_export.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d_f.h"
@ -61,8 +62,8 @@ class CC_EXPORT ScrollElasticityHelper {
virtual void SetStretchAmount(const gfx::Vector2dF& stretch_amount) = 0;
// Functions for the scrolling of the root scroll layer.
virtual gfx::Vector2dF ScrollOffset() const = 0;
virtual gfx::Vector2dF MaxScrollOffset() const = 0;
virtual gfx::PointF ScrollOffset() const = 0;
virtual gfx::PointF MaxScrollOffset() const = 0;
virtual void ScrollBy(const gfx::Vector2dF& delta) = 0;
// Requests that another frame happens for the controller to continue ticking

@ -58,7 +58,7 @@ void SetOrUpdateResult(const SnapSearchResult& candidate,
}
const absl::optional<SnapSearchResult>& ClosestSearchResult(
const gfx::Vector2dF reference_point,
const gfx::PointF reference_point,
SearchAxis axis,
const absl::optional<SnapSearchResult>& a,
const absl::optional<SnapSearchResult>& b) {
@ -108,22 +108,22 @@ void SnapSearchResult::Union(const SnapSearchResult& other) {
}
SnapContainerData::SnapContainerData()
: proximity_range_(gfx::Vector2dF(std::numeric_limits<float>::max(),
std::numeric_limits<float>::max())) {}
: proximity_range_(gfx::PointF(std::numeric_limits<float>::max(),
std::numeric_limits<float>::max())) {}
SnapContainerData::SnapContainerData(ScrollSnapType type)
: scroll_snap_type_(type),
proximity_range_(gfx::Vector2dF(std::numeric_limits<float>::max(),
std::numeric_limits<float>::max())) {}
proximity_range_(gfx::PointF(std::numeric_limits<float>::max(),
std::numeric_limits<float>::max())) {}
SnapContainerData::SnapContainerData(ScrollSnapType type,
const gfx::RectF& rect,
const gfx::Vector2dF& max)
const gfx::PointF& max)
: scroll_snap_type_(type),
rect_(rect),
max_position_(max),
proximity_range_(gfx::Vector2dF(std::numeric_limits<float>::max(),
std::numeric_limits<float>::max())) {}
proximity_range_(gfx::PointF(std::numeric_limits<float>::max(),
std::numeric_limits<float>::max())) {}
SnapContainerData::SnapContainerData(const SnapContainerData& other) = default;
@ -143,14 +143,14 @@ void SnapContainerData::AddSnapAreaData(SnapAreaData snap_area_data) {
bool SnapContainerData::FindSnapPosition(
const SnapSelectionStrategy& strategy,
gfx::Vector2dF* snap_position,
gfx::PointF* snap_position,
TargetSnapAreaElementIds* target_element_ids,
const ElementId& active_element_id) const {
*target_element_ids = TargetSnapAreaElementIds();
if (scroll_snap_type_.is_none)
return false;
gfx::Vector2dF base_position = strategy.base_position();
gfx::PointF base_position = strategy.base_position();
SnapAxis axis = scroll_snap_type_.axis;
bool should_snap_on_x = strategy.ShouldSnapOnX() &&
(axis == SnapAxis::kX || axis == SnapAxis::kBoth);
@ -262,7 +262,7 @@ bool SnapContainerData::FindSnapPosition(
// of the corridors.
bool SnapContainerData::FindSnapPositionForMutualSnap(
const SnapSelectionStrategy& strategy,
gfx::Vector2dF* snap_position) const {
gfx::PointF* snap_position) const {
DCHECK(strategy.ShouldSnapOnX() && strategy.ShouldSnapOnY());
bool found = false;
gfx::Vector2dF smallest_distance(std::numeric_limits<float>::max(),

@ -198,7 +198,7 @@ class CC_EXPORT SnapContainerData {
explicit SnapContainerData(ScrollSnapType type);
SnapContainerData(ScrollSnapType type,
const gfx::RectF& rect,
const gfx::Vector2dF& max);
const gfx::PointF& max);
SnapContainerData(const SnapContainerData& other);
SnapContainerData(SnapContainerData&& other);
~SnapContainerData();
@ -221,7 +221,7 @@ class CC_EXPORT SnapContainerData {
// Returns true if a snap position was found.
bool FindSnapPosition(const SnapSelectionStrategy& strategy,
gfx::Vector2dF* snap_position,
gfx::PointF* snap_position,
TargetSnapAreaElementIds* target_element_ids,
const ElementId& active_element_id = ElementId()) const;
@ -239,13 +239,13 @@ class CC_EXPORT SnapContainerData {
void set_rect(const gfx::RectF& rect) { rect_ = rect; }
gfx::RectF rect() const { return rect_; }
void set_max_position(gfx::Vector2dF position) { max_position_ = position; }
gfx::Vector2dF max_position() const { return max_position_; }
void set_max_position(gfx::PointF position) { max_position_ = position; }
gfx::PointF max_position() const { return max_position_; }
void set_proximity_range(const gfx::Vector2dF& range) {
void set_proximity_range(const gfx::PointF& range) {
proximity_range_ = range;
}
gfx::Vector2dF proximity_range() const { return proximity_range_; }
gfx::PointF proximity_range() const { return proximity_range_; }
private:
// Finds the best SnapArea candidate that's optimal for the given selection
@ -278,7 +278,7 @@ class CC_EXPORT SnapContainerData {
const ElementId& active_element_id) const;
bool FindSnapPositionForMutualSnap(const SnapSelectionStrategy& strategy,
gfx::Vector2dF* snap_position) const;
gfx::PointF* snap_position) const;
// Finds the snap area associated with the target snap area element id for the
// given axis.
@ -311,11 +311,11 @@ class CC_EXPORT SnapContainerData {
// The maximal scroll position of the SnapContainer, in the same coordinate
// with blink's scroll position.
gfx::Vector2dF max_position_;
gfx::PointF max_position_;
// A valid snap position should be within the |proximity_range_| of the
// current offset on the snapping axis.
gfx::Vector2dF proximity_range_;
gfx::PointF proximity_range_;
// The SnapAreaData for the snap areas in this snap container. When a scroll
// happens, we iterate through the snap_area_list to find the best snap

@ -18,14 +18,14 @@ class ScrollSnapDataTest : public testing::Test {
TEST_F(ScrollSnapDataTest, StartAlignmentCalculation) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(10, 10, 200, 300), gfx::Vector2dF(600, 800));
gfx::RectF(10, 10, 200, 300), gfx::PointF(600, 800));
SnapAreaData area(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(100, 150, 100, 100), false, ElementId(10));
container.AddSnapAreaData(area);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndPosition(gfx::Vector2dF(0, 0), true,
SnapSelectionStrategy::CreateForEndPosition(gfx::PointF(0, 0), true,
true);
EXPECT_TRUE(
@ -39,14 +39,14 @@ TEST_F(ScrollSnapDataTest, StartAlignmentCalculation) {
TEST_F(ScrollSnapDataTest, CenterAlignmentCalculation) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(10, 10, 200, 300), gfx::Vector2dF(600, 800));
gfx::RectF(10, 10, 200, 300), gfx::PointF(600, 800));
SnapAreaData area(ScrollSnapAlign(SnapAlignment::kCenter),
gfx::RectF(100, 150, 100, 100), false, ElementId(10));
container.AddSnapAreaData(area);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndPosition(gfx::Vector2dF(0, 0), true,
SnapSelectionStrategy::CreateForEndPosition(gfx::PointF(0, 0), true,
true);
EXPECT_TRUE(
container.FindSnapPosition(*strategy, &snap_position, &target_elements));
@ -59,14 +59,14 @@ TEST_F(ScrollSnapDataTest, CenterAlignmentCalculation) {
TEST_F(ScrollSnapDataTest, EndAlignmentCalculation) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(10, 10, 200, 200), gfx::Vector2dF(600, 800));
gfx::RectF(10, 10, 200, 200), gfx::PointF(600, 800));
SnapAreaData area(ScrollSnapAlign(SnapAlignment::kEnd),
gfx::RectF(150, 200, 100, 100), false, ElementId(10));
container.AddSnapAreaData(area);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndPosition(gfx::Vector2dF(0, 0), true,
SnapSelectionStrategy::CreateForEndPosition(gfx::PointF(0, 0), true,
true);
EXPECT_TRUE(
container.FindSnapPosition(*strategy, &snap_position, &target_elements));
@ -79,14 +79,14 @@ TEST_F(ScrollSnapDataTest, EndAlignmentCalculation) {
TEST_F(ScrollSnapDataTest, UnreachableSnapPositionCalculation) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 200), gfx::Vector2dF(100, 100));
gfx::RectF(0, 0, 200, 200), gfx::PointF(100, 100));
SnapAreaData area(ScrollSnapAlign(SnapAlignment::kEnd, SnapAlignment::kStart),
gfx::RectF(200, 0, 100, 100), false, ElementId(10));
container.AddSnapAreaData(area);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndPosition(gfx::Vector2dF(50, 50), true,
SnapSelectionStrategy::CreateForEndPosition(gfx::PointF(50, 50), true,
true);
EXPECT_TRUE(
container.FindSnapPosition(*strategy, &snap_position, &target_elements));
@ -102,7 +102,7 @@ TEST_F(ScrollSnapDataTest, UnreachableSnapPositionCalculation) {
TEST_F(ScrollSnapDataTest, FindsClosestSnapPositionIndependently) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 200), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 200, 200), gfx::PointF(600, 800));
SnapAreaData snap_x_only(
ScrollSnapAlign(SnapAlignment::kNone, SnapAlignment::kStart),
gfx::RectF(80, 0, 150, 150), false, ElementId(10));
@ -116,10 +116,10 @@ TEST_F(ScrollSnapDataTest, FindsClosestSnapPositionIndependently) {
container.AddSnapAreaData(snap_y_only);
container.AddSnapAreaData(snap_on_both);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndPosition(gfx::Vector2dF(100, 100),
true, true);
SnapSelectionStrategy::CreateForEndPosition(gfx::PointF(100, 100), true,
true);
EXPECT_TRUE(
container.FindSnapPosition(*strategy, &snap_position, &target_elements));
EXPECT_EQ(80, snap_position.x());
@ -131,7 +131,7 @@ TEST_F(ScrollSnapDataTest, FindsClosestSnapPositionIndependently) {
TEST_F(ScrollSnapDataTest, FindsClosestSnapPositionOnAxisValueBoth) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 200), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 200, 200), gfx::PointF(600, 800));
SnapAreaData snap_x_only(
ScrollSnapAlign(SnapAlignment::kNone, SnapAlignment::kStart),
gfx::RectF(80, 0, 150, 150), false, ElementId(10));
@ -145,9 +145,9 @@ TEST_F(ScrollSnapDataTest, FindsClosestSnapPositionOnAxisValueBoth) {
container.AddSnapAreaData(snap_x_only);
container.AddSnapAreaData(snap_y_only);
container.AddSnapAreaData(snap_on_both);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndPosition(gfx::Vector2dF(40, 120), true,
SnapSelectionStrategy::CreateForEndPosition(gfx::PointF(40, 120), true,
true);
EXPECT_TRUE(
container.FindSnapPosition(*strategy, &snap_position, &target_elements));
@ -160,7 +160,7 @@ TEST_F(ScrollSnapDataTest, FindsClosestSnapPositionOnAxisValueBoth) {
TEST_F(ScrollSnapDataTest, DoesNotSnapOnNonScrolledAxis) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 200), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 200, 200), gfx::PointF(600, 800));
SnapAreaData snap_x_only(
ScrollSnapAlign(SnapAlignment::kNone, SnapAlignment::kStart),
gfx::RectF(80, 0, 150, 150), false, ElementId(10));
@ -170,10 +170,10 @@ TEST_F(ScrollSnapDataTest, DoesNotSnapOnNonScrolledAxis) {
container.AddSnapAreaData(snap_x_only);
container.AddSnapAreaData(snap_y_only);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndPosition(gfx::Vector2dF(100, 100),
true, false);
SnapSelectionStrategy::CreateForEndPosition(gfx::PointF(100, 100), true,
false);
EXPECT_TRUE(
container.FindSnapPosition(*strategy, &snap_position, &target_elements));
EXPECT_EQ(80, snap_position.x());
@ -185,7 +185,7 @@ TEST_F(ScrollSnapDataTest, DoesNotSnapOnNonScrolledAxis) {
TEST_F(ScrollSnapDataTest, DoesNotSnapOnNonVisibleAreas) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 200), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 200, 200), gfx::PointF(600, 800));
SnapAreaData snap_x_only(
ScrollSnapAlign(SnapAlignment::kNone, SnapAlignment::kStart),
gfx::RectF(300, 400, 100, 100), false, ElementId(10));
@ -195,9 +195,9 @@ TEST_F(ScrollSnapDataTest, DoesNotSnapOnNonVisibleAreas) {
container.AddSnapAreaData(snap_x_only);
container.AddSnapAreaData(snap_y_only);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndPosition(gfx::Vector2dF(0, 0), true,
SnapSelectionStrategy::CreateForEndPosition(gfx::PointF(0, 0), true,
true);
EXPECT_FALSE(
container.FindSnapPosition(*strategy, &snap_position, &target_elements));
@ -207,7 +207,7 @@ TEST_F(ScrollSnapDataTest, DoesNotSnapOnNonVisibleAreas) {
TEST_F(ScrollSnapDataTest, SnapOnClosestAxisFirstIfVisibilityConflicts) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 200), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 200, 200), gfx::PointF(600, 800));
// Both the areas are currently visible.
// However, if we snap to them on x and y independently, none is visible after
@ -227,9 +227,9 @@ TEST_F(ScrollSnapDataTest, SnapOnClosestAxisFirstIfVisibilityConflicts) {
container.AddSnapAreaData(snap_y1);
container.AddSnapAreaData(snap_y2);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndPosition(gfx::Vector2dF(0, 0), true,
SnapSelectionStrategy::CreateForEndPosition(gfx::PointF(0, 0), true,
true);
EXPECT_TRUE(
container.FindSnapPosition(*strategy, &snap_position, &target_elements));
@ -242,17 +242,17 @@ TEST_F(ScrollSnapDataTest, SnapOnClosestAxisFirstIfVisibilityConflicts) {
TEST_F(ScrollSnapDataTest, DoesNotSnapToPositionsOutsideProximityRange) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 200), gfx::Vector2dF(600, 800));
container.set_proximity_range(gfx::Vector2dF(50, 50));
gfx::RectF(0, 0, 200, 200), gfx::PointF(600, 800));
container.set_proximity_range(gfx::PointF(50, 50));
SnapAreaData area(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(80, 160, 100, 100), false, ElementId(10));
container.AddSnapAreaData(area);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndPosition(gfx::Vector2dF(100, 100),
true, true);
SnapSelectionStrategy::CreateForEndPosition(gfx::PointF(100, 100), true,
true);
EXPECT_TRUE(
container.FindSnapPosition(*strategy, &snap_position, &target_elements));
@ -268,15 +268,15 @@ TEST_F(ScrollSnapDataTest, DoesNotSnapToPositionsOutsideProximityRange) {
TEST_F(ScrollSnapDataTest, MandatoryReturnsToCurrentIfNoValidAreaForward) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 200), gfx::Vector2dF(2000, 2000));
gfx::RectF(0, 0, 200, 200), gfx::PointF(2000, 2000));
SnapAreaData area(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(600, 0, 100, 100), false, ElementId(10));
container.AddSnapAreaData(area);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> direction_strategy =
SnapSelectionStrategy::CreateForDirection(
gfx::Vector2dF(600, 0), gfx::Vector2dF(5, 0),
gfx::PointF(600, 0), gfx::Vector2dF(5, 0),
false /* use_fractional_deltas */);
EXPECT_TRUE(container.FindSnapPosition(*direction_strategy, &snap_position,
&target_elements));
@ -290,7 +290,7 @@ TEST_F(ScrollSnapDataTest, MandatoryReturnsToCurrentIfNoValidAreaForward) {
std::unique_ptr<SnapSelectionStrategy> end_direction_strategy =
SnapSelectionStrategy::CreateForEndAndDirection(
gfx::Vector2dF(600, 0), gfx::Vector2dF(15, 15),
gfx::PointF(600, 0), gfx::Vector2dF(15, 15),
false /* use_fractional_deltas */);
EXPECT_TRUE(container.FindSnapPosition(*end_direction_strategy,
&snap_position, &target_elements));
@ -316,15 +316,15 @@ TEST_F(ScrollSnapDataTest, MandatoryReturnsToCurrentIfNoValidAreaForward) {
TEST_F(ScrollSnapDataTest, MandatorySnapsBackwardIfNoValidAreaForward) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 200), gfx::Vector2dF(2000, 2000));
gfx::RectF(0, 0, 200, 200), gfx::PointF(2000, 2000));
SnapAreaData area(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(600, 0, 100, 100), false, ElementId(10));
container.AddSnapAreaData(area);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> direction_strategy =
SnapSelectionStrategy::CreateForDirection(
gfx::Vector2dF(650, 0), gfx::Vector2dF(5, 0),
gfx::PointF(650, 0), gfx::Vector2d(5, 0),
false /* use_fractional_deltas */);
EXPECT_TRUE(container.FindSnapPosition(*direction_strategy, &snap_position,
&target_elements));
@ -338,7 +338,7 @@ TEST_F(ScrollSnapDataTest, MandatorySnapsBackwardIfNoValidAreaForward) {
std::unique_ptr<SnapSelectionStrategy> end_direction_strategy =
SnapSelectionStrategy::CreateForEndAndDirection(
gfx::Vector2dF(650, 10), gfx::Vector2dF(15, 15),
gfx::PointF(650, 10), gfx::Vector2d(15, 15),
false /* use_fractional_deltas */);
EXPECT_TRUE(container.FindSnapPosition(*end_direction_strategy,
&snap_position, &target_elements));
@ -364,7 +364,7 @@ TEST_F(ScrollSnapDataTest, MandatorySnapsBackwardIfNoValidAreaForward) {
TEST_F(ScrollSnapDataTest, ShouldNotPassScrollSnapStopAlwaysElement) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 200), gfx::Vector2dF(2000, 2000));
gfx::RectF(0, 0, 200, 200), gfx::PointF(2000, 2000));
SnapAreaData must_snap_1(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(200, 0, 100, 100), true, ElementId(10));
SnapAreaData must_snap_2(ScrollSnapAlign(SnapAlignment::kStart),
@ -375,11 +375,11 @@ TEST_F(ScrollSnapDataTest, ShouldNotPassScrollSnapStopAlwaysElement) {
container.AddSnapAreaData(must_snap_1);
container.AddSnapAreaData(must_snap_2);
container.AddSnapAreaData(closer_to_target);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> end_direction_strategy =
SnapSelectionStrategy::CreateForEndAndDirection(
gfx::Vector2dF(0, 0), gfx::Vector2dF(600, 0),
gfx::PointF(0, 0), gfx::Vector2d(600, 0),
false /* use_fractional_deltas */);
EXPECT_TRUE(container.FindSnapPosition(*end_direction_strategy,
@ -397,7 +397,7 @@ TEST_F(ScrollSnapDataTest, ShouldNotPassScrollSnapStopAlwaysElement) {
TEST_F(ScrollSnapDataTest, SnapStopAlwaysOverridesCoveringSnapArea) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 200), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 200, 200), gfx::PointF(600, 800));
SnapAreaData stop_area(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(100, 0, 100, 100), true, ElementId(10));
SnapAreaData covering_area(ScrollSnapAlign(SnapAlignment::kStart),
@ -406,10 +406,10 @@ TEST_F(ScrollSnapDataTest, SnapStopAlwaysOverridesCoveringSnapArea) {
container.AddSnapAreaData(stop_area);
container.AddSnapAreaData(covering_area);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndAndDirection(
gfx::Vector2dF(0, 0), gfx::Vector2dF(300, 0),
gfx::PointF(0, 0), gfx::Vector2d(300, 0),
false /* use_fractional_deltas */);
// The fling is from (0, 0) to (300, 0), and the destination would make
@ -427,15 +427,15 @@ TEST_F(ScrollSnapDataTest, SnapStopAlwaysOverridesCoveringSnapArea) {
TEST_F(ScrollSnapDataTest, SnapStopAlwaysInReverseDirection) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 300), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 200, 300), gfx::PointF(600, 800));
SnapAreaData stop_area(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(100, 0, 100, 100), true, ElementId(10));
container.AddSnapAreaData(stop_area);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForEndAndDirection(
gfx::Vector2dF(150, 0), gfx::Vector2dF(200, 0),
gfx::PointF(150, 0), gfx::Vector2d(200, 0),
false /* use_fractional_deltas */);
// The fling is from (150, 0) to (350, 0), but the snap position is in the
@ -452,7 +452,7 @@ TEST_F(ScrollSnapDataTest, SnapStopAlwaysInReverseDirection) {
TEST_F(ScrollSnapDataTest, SnapStopAlwaysNotInterferingWithDirectionStrategy) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 300), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 200, 300), gfx::PointF(600, 800));
SnapAreaData closer_area(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(100, 0, 1, 1), false, ElementId(10));
SnapAreaData stop_area(ScrollSnapAlign(SnapAlignment::kStart),
@ -462,12 +462,12 @@ TEST_F(ScrollSnapDataTest, SnapStopAlwaysNotInterferingWithDirectionStrategy) {
// The DirectionStrategy should always choose the first snap position
// regardless its scroll-snap-stop value.
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
std::unique_ptr<SnapSelectionStrategy> direction_strategy =
SnapSelectionStrategy::CreateForDirection(
gfx::Vector2dF(90, 0), gfx::Vector2dF(50, 0),
gfx::PointF(90, 0), gfx::Vector2d(50, 0),
false /* use_fractional_deltas */);
snap_position = gfx::Vector2dF();
snap_position = gfx::PointF();
EXPECT_TRUE(container.FindSnapPosition(*direction_strategy, &snap_position,
&target_elements));
EXPECT_EQ(100, snap_position.x());
@ -479,7 +479,7 @@ TEST_F(ScrollSnapDataTest, SnapStopAlwaysNotInterferingWithDirectionStrategy) {
TEST_F(ScrollSnapDataTest, SnapToOneTargetElementOnX) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 300), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 200, 300), gfx::PointF(600, 800));
SnapAreaData closer_area_x(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(100, 0, 1, 1), false, ElementId(10));
@ -498,9 +498,9 @@ TEST_F(ScrollSnapDataTest, SnapToOneTargetElementOnX) {
// should snap to the target for the x-axis. However, since the target is not
// set for the y-axis, the target on the y-axis should be closer_area_y.
std::unique_ptr<SnapSelectionStrategy> target_element_strategy =
SnapSelectionStrategy::CreateForTargetElement(gfx::Vector2dF(0, 0));
SnapSelectionStrategy::CreateForTargetElement(gfx::PointF(0, 0));
gfx::Vector2dF snap_position = gfx::Vector2dF();
gfx::PointF snap_position = gfx::PointF();
EXPECT_TRUE(container.FindSnapPosition(*target_element_strategy,
&snap_position, &target_elements));
@ -513,7 +513,7 @@ TEST_F(ScrollSnapDataTest, SnapToOneTargetElementOnX) {
TEST_F(ScrollSnapDataTest, SnapToOneTargetElementOnY) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 200, 300), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 200, 300), gfx::PointF(600, 800));
SnapAreaData closer_area_y(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(0, 100, 1, 1), false, ElementId(10));
@ -532,9 +532,9 @@ TEST_F(ScrollSnapDataTest, SnapToOneTargetElementOnY) {
// should snap to the target for the y-axis. However, since the target is not
// set for the x-axis, the target on the x-axis should be closer_area_x.
std::unique_ptr<SnapSelectionStrategy> target_element_strategy =
SnapSelectionStrategy::CreateForTargetElement(gfx::Vector2dF(0, 0));
SnapSelectionStrategy::CreateForTargetElement(gfx::PointF(0, 0));
gfx::Vector2dF snap_position = gfx::Vector2dF();
gfx::PointF snap_position = gfx::PointF();
EXPECT_TRUE(container.FindSnapPosition(*target_element_strategy,
&snap_position, &target_elements));
@ -547,7 +547,7 @@ TEST_F(ScrollSnapDataTest, SnapToOneTargetElementOnY) {
TEST_F(ScrollSnapDataTest, SnapToTwoTargetElementsMutualVisible) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 300, 300), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 300, 300), gfx::PointF(600, 800));
SnapAreaData target_area_x(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(100, 200, 1, 1), false, ElementId(10));
@ -565,9 +565,9 @@ TEST_F(ScrollSnapDataTest, SnapToTwoTargetElementsMutualVisible) {
// The container should snap to both target areas since they are mutually
// visible, while ignoring the snap area that is closest to the scroll offset.
std::unique_ptr<SnapSelectionStrategy> target_element_strategy =
SnapSelectionStrategy::CreateForTargetElement(gfx::Vector2dF(0, 0));
SnapSelectionStrategy::CreateForTargetElement(gfx::PointF(0, 0));
gfx::Vector2dF snap_position = gfx::Vector2dF();
gfx::PointF snap_position = gfx::PointF();
EXPECT_TRUE(container.FindSnapPosition(*target_element_strategy,
&snap_position, &target_elements));
@ -580,7 +580,7 @@ TEST_F(ScrollSnapDataTest, SnapToTwoTargetElementsMutualVisible) {
TEST_F(ScrollSnapDataTest, SnapToTwoTargetElementsNotMutualVisible) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 300, 300), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 300, 300), gfx::PointF(600, 800));
SnapAreaData target_area_x(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(100, 500, 1, 1), false, ElementId(10));
@ -600,9 +600,9 @@ TEST_F(ScrollSnapDataTest, SnapToTwoTargetElementsNotMutualVisible) {
// closer to the scroll offset, and then snap to the closest mutually visible
// snap area on the other axis.
std::unique_ptr<SnapSelectionStrategy> target_element_strategy =
SnapSelectionStrategy::CreateForTargetElement(gfx::Vector2dF(10, 0));
SnapSelectionStrategy::CreateForTargetElement(gfx::PointF(10, 0));
gfx::Vector2dF snap_position = gfx::Vector2dF();
gfx::PointF snap_position = gfx::PointF();
EXPECT_TRUE(container.FindSnapPosition(*target_element_strategy,
&snap_position, &target_elements));
@ -615,7 +615,7 @@ TEST_F(ScrollSnapDataTest, SnapToTwoTargetElementsNotMutualVisible) {
TEST_F(ScrollSnapDataTest, SnapToFocusedElementHorizontal) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kX, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 300, 300), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 300, 300), gfx::PointF(600, 800));
SnapAreaData snapped_area(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(0, 0, 100, 100), false, ElementId(10));
SnapAreaData focused_area(ScrollSnapAlign(SnapAlignment::kStart),
@ -624,11 +624,11 @@ TEST_F(ScrollSnapDataTest, SnapToFocusedElementHorizontal) {
container.AddSnapAreaData(focused_area);
// Initially both snap areas are horizontally aligned with the snap position.
gfx::Vector2dF origin(0, 0);
gfx::PointF origin(0, 0);
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForTargetElement(origin);
gfx::Vector2dF snap_position = gfx::Vector2dF();
gfx::PointF snap_position = gfx::PointF();
EXPECT_TRUE(container.FindSnapPosition(*strategy, &snap_position,
&target_elements, ElementId(20)));
EXPECT_EQ(0, snap_position.x());
@ -647,7 +647,7 @@ TEST_F(ScrollSnapDataTest, SnapToFocusedElementHorizontal) {
TEST_F(ScrollSnapDataTest, SnapToFocusedElementVertical) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kY, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 300, 300), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 300, 300), gfx::PointF(600, 800));
SnapAreaData snapped_area(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(0, 0, 100, 100), false, ElementId(10));
SnapAreaData focused_area(ScrollSnapAlign(SnapAlignment::kStart),
@ -656,11 +656,11 @@ TEST_F(ScrollSnapDataTest, SnapToFocusedElementVertical) {
container.AddSnapAreaData(focused_area);
// Initially both snap areas are vertically aligned with the snap position.
gfx::Vector2dF origin(0, 0);
gfx::PointF origin(0, 0);
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForTargetElement(origin);
gfx::Vector2dF snap_position = gfx::Vector2dF();
gfx::PointF snap_position = gfx::PointF();
EXPECT_TRUE(container.FindSnapPosition(*strategy, &snap_position,
&target_elements, ElementId(20)));
EXPECT_EQ(0, snap_position.y());
@ -679,7 +679,7 @@ TEST_F(ScrollSnapDataTest, SnapToFocusedElementVertical) {
TEST_F(ScrollSnapDataTest, SnapToFocusedElementBoth) {
SnapContainerData container(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 300, 300), gfx::Vector2dF(600, 800));
gfx::RectF(0, 0, 300, 300), gfx::PointF(600, 800));
SnapAreaData snapped_area(ScrollSnapAlign(SnapAlignment::kStart),
gfx::RectF(0, 0, 100, 100), false, ElementId(10));
SnapAreaData focused_area(ScrollSnapAlign(SnapAlignment::kStart),
@ -688,11 +688,11 @@ TEST_F(ScrollSnapDataTest, SnapToFocusedElementBoth) {
container.AddSnapAreaData(focused_area);
// Initially both snap areas are coincident with the snap position.
gfx::Vector2dF origin(0, 0);
gfx::PointF origin(0, 0);
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForTargetElement(origin);
gfx::Vector2dF snap_position = gfx::Vector2dF();
gfx::PointF snap_position = gfx::PointF();
EXPECT_TRUE(container.FindSnapPosition(*strategy, &snap_position,
&target_elements, ElementId(20)));
EXPECT_EQ(0, snap_position.x());

@ -7,8 +7,6 @@
#include "cc/cc_export.h"
#include "cc/input/scroll_state_data.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {

@ -104,7 +104,7 @@ InputHandlerPointerResult ScrollbarController::HandlePointerDown(
GetScrollbarPartFromPointerDown(position_in_widget);
const bool perform_jump_click_on_track =
scrollbar->JumpOnTrackClick() != jump_key_modifier;
scroll_result.scroll_offset = GetScrollOffsetForScrollbarPart(
scroll_result.scroll_delta = GetScrollDeltaForScrollbarPart(
scrollbar_part, perform_jump_click_on_track);
last_known_pointer_position_ = position_in_widget;
scrollbar_scroll_is_active_ = true;
@ -127,18 +127,18 @@ InputHandlerPointerResult ScrollbarController::HandlePointerDown(
// from the track during a thumb drag. Additionally, if a thumb drag is
// being initiated *after* a jump click, scroll_position_at_start_ needs
// to account for that.
const float jump_click_thumb_drag_offset =
const float jump_click_thumb_drag_delta =
scrollbar->orientation() == ScrollbarOrientation::HORIZONTAL
? scroll_result.scroll_offset.x()
: scroll_result.scroll_offset.y();
? scroll_result.scroll_delta.x()
: scroll_result.scroll_delta.y();
drag_state_->scroll_position_at_start_ =
scrollbar->current_pos() +
(perform_jump_click_on_track ? jump_click_thumb_drag_offset : 0);
(perform_jump_click_on_track ? jump_click_thumb_drag_delta : 0);
drag_state_->scroller_length_at_previous_move =
scrollbar->scroll_layer_length();
}
if (!scroll_result.scroll_offset.IsZero() && !perform_jump_click_on_track) {
if (!scroll_result.scroll_delta.IsZero() && !perform_jump_click_on_track) {
// Thumb drag is the only scrollbar manipulation that cannot produce an
// autoscroll. All other interactions like clicking on arrows/trackparts
// have the potential of initiating an autoscroll (if held down for long
@ -148,7 +148,7 @@ InputHandlerPointerResult ScrollbarController::HandlePointerDown(
std::make_unique<base::CancelableOnceClosure>(base::BindOnce(
&ScrollbarController::StartAutoScrollAnimation,
base::Unretained(this),
InitialDeltaToAutoscrollVelocity(scroll_result.scroll_offset),
InitialDeltaToAutoscrollVelocity(scroll_result.scroll_delta),
scrollbar_part));
layer_tree_host_impl_->GetTaskRunner()->PostDelayedTask(
FROM_HERE, cancelable_autoscroll_task_->callback(),
@ -232,7 +232,7 @@ ui::ScrollGranularity ScrollbarController::Granularity(
return ui::ScrollGranularity::kScrollByPixel;
}
float ScrollbarController::GetScrollDeltaForAbsoluteJump() const {
float ScrollbarController::GetScrollDistanceForAbsoluteJump() const {
layer_tree_host_impl_->active_tree()->UpdateScrollbarGeometries();
bool clipped = false;
@ -261,12 +261,13 @@ float ScrollbarController::GetScrollDeltaForAbsoluteJump() const {
? thumb_rect.y()
: thumb_rect.x();
const float delta =
const float distance =
round(std::abs(desired_thumb_origin - current_thumb_origin));
return delta * GetScrollerToScrollbarRatio() * GetPageScaleFactorForScroll();
return distance * GetScrollerToScrollbarRatio() *
GetPageScaleFactorForScroll();
}
float ScrollbarController::GetScrollDeltaForDragPosition(
float ScrollbarController::GetScrollDistanceForDragPosition(
const gfx::PointF pointer_position_in_widget) const {
const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
// Convert the move position to scrollbar layer relative for comparison with
@ -282,14 +283,14 @@ float ScrollbarController::GetScrollDeltaForDragPosition(
: scrollbar_relative_position.x() - drag_state_->drag_origin.x();
const float new_offset = pointer_delta * GetScrollerToScrollbarRatio();
float scroll_delta = drag_state_->scroll_position_at_start_ + new_offset -
scrollbar->current_pos();
float distance = drag_state_->scroll_position_at_start_ + new_offset -
scrollbar->current_pos();
// The scroll delta computed is layer relative. In order to scroll the
// correct amount, we have to convert the delta to be unscaled (i.e. multiply
// by the page scale factor), as GSU deltas are always unscaled.
scroll_delta *= GetPageScaleFactorForScroll();
return scroll_delta;
distance *= GetPageScaleFactorForScroll();
return distance;
}
// Performs hit test and prepares scroll deltas that will be used by GSU.
@ -320,7 +321,7 @@ InputHandlerPointerResult ScrollbarController::HandlePointerMove(
const float delta =
scrollbar->current_pos() - drag_state_->scroll_position_at_start_;
scroll_result.scroll_units = ui::ScrollGranularity::kScrollByPrecisePixel;
scroll_result.scroll_offset =
scroll_result.scroll_delta =
scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? gfx::Vector2dF(0, -delta)
: gfx::Vector2dF(-delta, 0);
@ -342,10 +343,10 @@ InputHandlerPointerResult ScrollbarController::HandlePointerMove(
// valid ScrollNode.
DCHECK(target_node);
float delta = GetScrollDeltaForDragPosition(position_in_widget);
float distance = GetScrollDistanceForDragPosition(position_in_widget);
if (drag_state_->scroller_length_at_previous_move !=
scrollbar->scroll_layer_length()) {
drag_state_->scroller_displacement = delta;
drag_state_->scroller_displacement = distance;
drag_state_->scroller_length_at_previous_move =
scrollbar->scroll_layer_length();
@ -356,23 +357,23 @@ InputHandlerPointerResult ScrollbarController::HandlePointerMove(
// scroller expands while a thumb drag is in progress.
return scroll_result;
}
delta -= drag_state_->scroller_displacement;
distance -= drag_state_->scroller_displacement;
// If scroll_offset can't be consumed, there's no point in continuing on.
const gfx::Vector2dF scroll_offset(scrollbar->orientation() ==
ScrollbarOrientation::VERTICAL
? gfx::Vector2dF(0, delta)
: gfx::Vector2dF(delta, 0));
const gfx::Vector2dF clamped_scroll_offset =
ComputeClampedDelta(*target_node, scroll_offset);
const gfx::Vector2dF scroll_delta =
scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? gfx::Vector2dF(0, distance)
: gfx::Vector2dF(distance, 0);
const gfx::Vector2dF clamped_scroll_delta =
ComputeClampedDelta(*target_node, scroll_delta);
if (clamped_scroll_offset.IsZero())
if (clamped_scroll_delta.IsZero())
return scroll_result;
// Thumb drags have more granularity and are purely dependent on the pointer
// movement. Hence we use kPrecisePixel when dragging the thumb.
scroll_result.scroll_units = ui::ScrollGranularity::kScrollByPrecisePixel;
scroll_result.scroll_offset = clamped_scroll_offset;
scroll_result.scroll_delta = clamped_scroll_delta;
drag_processed_for_current_frame_ = true;
return scroll_result;
@ -546,13 +547,13 @@ void ScrollbarController::RecomputeAutoscrollStateIfNeeded() {
// Helper to calculate the autoscroll velocity.
float ScrollbarController::InitialDeltaToAutoscrollVelocity(
gfx::Vector2dF scroll_offset) const {
gfx::Vector2dF scroll_delta) const {
DCHECK(captured_scrollbar_metadata_.has_value());
const float scroll_delta =
const float delta =
ScrollbarLayer()->orientation() == ScrollbarOrientation::VERTICAL
? scroll_offset.y()
: scroll_offset.x();
return scroll_delta * kAutoscrollMultiplier;
? scroll_delta.y()
: scroll_delta.x();
return delta * kAutoscrollMultiplier;
}
void ScrollbarController::StartAutoScrollAnimation(
@ -579,17 +580,18 @@ void ScrollbarController::StartAutoScrollAnimation(
layer_tree_host_impl_->active_tree()->UpdateScrollbarGeometries();
float scroll_layer_length = scrollbar->scroll_layer_length();
gfx::Vector2dF current_offset =
gfx::PointF current_offset =
scroll_tree.current_scroll_offset(scroll_node->element_id);
// Determine the max offset for the scroll based on the scrolling direction.
// Negative scroll velocity indicates backwards scrolling whereas a positive
// value indicates forwards scrolling.
const float target_offset = velocity < 0 ? 0 : scroll_layer_length;
const gfx::Vector2dF target_offset_vector =
const float target_offset_in_orientation =
velocity < 0 ? 0 : scroll_layer_length;
const gfx::PointF target_offset_2d =
scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? gfx::Vector2dF(current_offset.x(), target_offset)
: gfx::Vector2dF(target_offset, current_offset.y());
? gfx::PointF(current_offset.x(), target_offset_in_orientation)
: gfx::PointF(target_offset_in_orientation, current_offset.y());
autoscroll_state_ = AutoScrollState();
autoscroll_state_->velocity = velocity;
@ -601,7 +603,7 @@ void ScrollbarController::StartAutoScrollAnimation(
layer_tree_host_impl_->mutator_host()->ScrollAnimationAbort();
layer_tree_host_impl_->AutoScrollAnimationCreate(
*scroll_node, target_offset_vector, std::abs(velocity));
*scroll_node, target_offset_2d, std::abs(velocity));
}
// Performs hit test and prepares scroll deltas that will be used by GSE.
@ -659,7 +661,7 @@ float ScrollbarController::GetViewportLength() const {
return length / GetPageScaleFactorForScroll();
}
float ScrollbarController::GetScrollDeltaForPercentBasedScroll() const {
float ScrollbarController::GetScrollDistanceForPercentBasedScroll() const {
const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
const ScrollNode* scroll_node =
@ -687,7 +689,7 @@ float ScrollbarController::GetPageScaleFactorForScroll() const {
return layer_tree_host_impl_->active_tree()->page_scale_factor_for_scroll();
}
float ScrollbarController::GetScrollDeltaForScrollbarPart(
float ScrollbarController::GetScrollDistanceForScrollbarPart(
const ScrollbarPart scrollbar_part,
const bool jump_key_modifier) const {
float scroll_delta = 0;
@ -696,7 +698,7 @@ float ScrollbarController::GetScrollDeltaForScrollbarPart(
case ScrollbarPart::BACK_BUTTON:
case ScrollbarPart::FORWARD_BUTTON:
if (layer_tree_host_impl_->settings().percent_based_scrolling) {
scroll_delta = GetScrollDeltaForPercentBasedScroll();
scroll_delta = GetScrollDistanceForPercentBasedScroll();
} else {
scroll_delta = kPixelsPerLineStep * ScreenSpaceScaleFactor();
}
@ -704,7 +706,7 @@ float ScrollbarController::GetScrollDeltaForScrollbarPart(
case ScrollbarPart::BACK_TRACK:
case ScrollbarPart::FORWARD_TRACK: {
if (jump_key_modifier) {
scroll_delta = GetScrollDeltaForAbsoluteJump();
scroll_delta = GetScrollDistanceForAbsoluteJump();
break;
}
// TODO(savella) Use snapport length instead of viewport length to match
@ -787,33 +789,33 @@ gfx::Rect ScrollbarController::GetRectForScrollbarPart(
return gfx::Rect(0, 0);
}
// Determines the scroll offsets based on the ScrollbarPart and the scrollbar
// orientation.
gfx::Vector2dF ScrollbarController::GetScrollOffsetForScrollbarPart(
// Determines the scroll delta as a gfx::Vector2dF based on the ScrollbarPart
// and the scrollbar orientation.
gfx::Vector2dF ScrollbarController::GetScrollDeltaForScrollbarPart(
const ScrollbarPart scrollbar_part,
const bool jump_key_modifier) const {
const ScrollbarLayerImplBase* scrollbar = ScrollbarLayer();
float scroll_delta =
GetScrollDeltaForScrollbarPart(scrollbar_part, jump_key_modifier);
float distance =
GetScrollDistanceForScrollbarPart(scrollbar_part, jump_key_modifier);
// See CreateScrollStateForGesture for more information on how these values
// will be interpreted.
if (scrollbar_part == ScrollbarPart::BACK_BUTTON) {
return scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? gfx::Vector2dF(0, -scroll_delta) // Up arrow
: gfx::Vector2dF(-scroll_delta, 0); // Left arrow
? gfx::Vector2dF(0, -distance) // Up arrow
: gfx::Vector2dF(-distance, 0); // Left arrow
} else if (scrollbar_part == ScrollbarPart::FORWARD_BUTTON) {
return scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? gfx::Vector2dF(0, scroll_delta) // Down arrow
: gfx::Vector2dF(scroll_delta, 0); // Right arrow
? gfx::Vector2dF(0, distance) // Down arrow
: gfx::Vector2dF(distance, 0); // Right arrow
} else if (scrollbar_part == ScrollbarPart::BACK_TRACK) {
return scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? gfx::Vector2dF(0, -scroll_delta) // Track click up
: gfx::Vector2dF(-scroll_delta, 0); // Track click left
? gfx::Vector2dF(0, -distance) // Track click up
: gfx::Vector2dF(-distance, 0); // Track click left
} else if (scrollbar_part == ScrollbarPart::FORWARD_TRACK) {
return scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? gfx::Vector2dF(0, scroll_delta) // Track click down
: gfx::Vector2dF(scroll_delta, 0); // Track click right
? gfx::Vector2dF(0, distance) // Track click down
: gfx::Vector2dF(distance, 0); // Track click right
}
return gfx::Vector2dF(0, 0);

@ -218,17 +218,12 @@ class CC_EXPORT ScrollbarController {
float ScreenSpaceScaleFactor() const;
// Helper to convert scroll offset to autoscroll velocity.
float InitialDeltaToAutoscrollVelocity(gfx::Vector2dF scroll_offset) const;
float InitialDeltaToAutoscrollVelocity(gfx::Vector2dF scroll_delta) const;
// Returns the hit tested ScrollbarPart based on the position_in_widget.
ScrollbarPart GetScrollbarPartFromPointerDown(
const gfx::PointF position_in_widget) const;
// Returns scroll offsets based on which ScrollbarPart was hit tested.
gfx::Vector2dF GetScrollOffsetForScrollbarPart(
const ScrollbarPart scrollbar_part,
const bool jump_key_modifier) const;
// Clamps |scroll_delta| based on the available scrollable amount of
// |target_node|. The returned delta includes the page scale factor and is
// appropriate for use directly as a delta for GSU.
@ -239,8 +234,15 @@ class CC_EXPORT ScrollbarController {
gfx::Rect GetRectForScrollbarPart(const ScrollbarPart scrollbar_part) const;
LayerImpl* GetLayerHitByPoint(const gfx::PointF position_in_widget) const;
float GetScrollDeltaForScrollbarPart(const ScrollbarPart scrollbar_part,
const bool jump_key_modifier) const;
// Returns scroll delta as Vector2dF based on which ScrollbarPart was hit
// tested.
gfx::Vector2dF GetScrollDeltaForScrollbarPart(
const ScrollbarPart scrollbar_part,
const bool jump_key_modifier) const;
// Returns scroll delta in the direction of the scrollbar's orientation.
float GetScrollDistanceForScrollbarPart(const ScrollbarPart scrollbar_part,
const bool jump_key_modifier) const;
// Makes position_in_widget relative to the scrollbar.
gfx::PointF GetScrollbarRelativePosition(const gfx::PointF position_in_widget,
@ -257,14 +259,14 @@ class CC_EXPORT ScrollbarController {
// Shift (or "Option" in case of Mac) + click is expected to do a non-animated
// jump to a certain offset.
float GetScrollDeltaForAbsoluteJump() const;
float GetScrollDistanceForAbsoluteJump() const;
// Determines if the delta needs to be animated.
ui::ScrollGranularity Granularity(const ScrollbarPart scrollbar_part,
bool jump_key_modifier) const;
// Calculates the delta based on position_in_widget and drag_origin.
float GetScrollDeltaForDragPosition(
// Calculates the distance based on position_in_widget and drag_origin.
float GetScrollDistanceForDragPosition(
const gfx::PointF pointer_position_in_widget) const;
// Returns the ratio of the scroller length to the scrollbar length. This is
@ -273,8 +275,8 @@ class CC_EXPORT ScrollbarController {
float GetViewportLength() const;
// Returns the pixel delta for a percent-based scroll of the scrollbar
float GetScrollDeltaForPercentBasedScroll() const;
// Returns the pixel distance for a percent-based scroll of the scrollbar
float GetScrollDistanceForPercentBasedScroll() const;
// Returns the page scale factor (i.e. pinch zoom factor). This is relevant
// for root viewport scrollbar scrolling.

@ -4,6 +4,7 @@
#include "cc/input/snap_fling_controller.h"
#include <utility>
#include "cc/input/snap_fling_curve.h"
namespace cc {
@ -49,7 +50,7 @@ bool SnapFlingController::HandleGestureScrollUpdate(
gfx::Vector2dF ending_displacement =
SnapFlingCurve::EstimateDisplacement(info.delta);
gfx::Vector2dF target_offset, start_offset;
gfx::PointF target_offset, start_offset;
if (!client_->GetSnapFlingInfoAndSetAnimatingSnapTarget(
ending_displacement, &start_offset, &target_offset)) {
state_ = State::kIgnored;
@ -78,7 +79,7 @@ void SnapFlingController::Animate(base::TimeTicks time) {
return;
}
gfx::Vector2dF snapped_delta = curve_->GetScrollDelta(time);
gfx::Vector2dF current_offset = client_->ScrollByForSnapFling(snapped_delta);
gfx::PointF current_offset = client_->ScrollByForSnapFling(snapped_delta);
curve_->UpdateCurrentOffset(current_offset);
client_->RequestAnimationForSnapFling();
}

@ -9,6 +9,7 @@
#include "base/time/time.h"
#include "cc/cc_export.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
@ -25,9 +26,9 @@ class SnapFlingClient {
public:
virtual bool GetSnapFlingInfoAndSetAnimatingSnapTarget(
const gfx::Vector2dF& natural_displacement,
gfx::Vector2dF* out_initial_position,
gfx::Vector2dF* out_target_position) const = 0;
virtual gfx::Vector2dF ScrollByForSnapFling(const gfx::Vector2dF& delta) = 0;
gfx::PointF* out_initial_position,
gfx::PointF* out_target_position) const = 0;
virtual gfx::PointF ScrollByForSnapFling(const gfx::Vector2dF& delta) = 0;
virtual void ScrollEndForSnapFling(bool did_finish) = 0;
virtual void RequestAnimationForSnapFling() = 0;
};

@ -4,6 +4,8 @@
#include "cc/input/snap_fling_controller.h"
#include <utility>
#include "cc/input/snap_fling_curve.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -16,19 +18,17 @@ class MockSnapFlingClient : public SnapFlingClient {
public:
MOCK_CONST_METHOD3(GetSnapFlingInfoAndSetAnimatingSnapTarget,
bool(const gfx::Vector2dF& natural_displacement,
gfx::Vector2dF* initial_offset,
gfx::Vector2dF* target_offset));
gfx::PointF* initial_offset,
gfx::PointF* target_offset));
MOCK_METHOD1(ScrollEndForSnapFling, void(bool));
MOCK_METHOD0(RequestAnimationForSnapFling, void());
MOCK_METHOD1(ScrollByForSnapFling, gfx::Vector2dF(const gfx::Vector2dF&));
MOCK_METHOD1(ScrollByForSnapFling, gfx::PointF(const gfx::Vector2dF&));
};
class MockSnapFlingCurve : public SnapFlingCurve {
public:
MockSnapFlingCurve()
: SnapFlingCurve(gfx::Vector2dF(),
gfx::Vector2dF(0, 100),
base::TimeTicks()) {}
: SnapFlingCurve(gfx::PointF(), gfx::PointF(0, 100), base::TimeTicks()) {}
MOCK_CONST_METHOD0(IsFinished, bool());
MOCK_METHOD1(GetScrollDelta, gfx::Vector2dF(base::TimeTicks));
};
@ -77,10 +77,9 @@ TEST_F(SnapFlingControllerTest, CreatesAndAnimatesCurveOnFirstInertialGSU) {
EXPECT_CALL(mock_client_, GetSnapFlingInfoAndSetAnimatingSnapTarget(
testing::_, testing::_, testing::_))
.WillOnce(
testing::DoAll(testing::SetArgPointee<1>(gfx::Vector2dF(0, 0)),
testing::SetArgPointee<2>(gfx::Vector2dF(0, 100)),
testing::Return(true)));
.WillOnce(testing::DoAll(testing::SetArgPointee<1>(gfx::PointF(0, 0)),
testing::SetArgPointee<2>(gfx::PointF(0, 100)),
testing::Return(true)));
EXPECT_CALL(mock_client_, RequestAnimationForSnapFling()).Times(1);
EXPECT_CALL(mock_client_, ScrollByForSnapFling(testing::_)).Times(1);
EXPECT_TRUE(controller_->HandleGestureScrollUpdate(gsu));

@ -57,8 +57,8 @@ gfx::Vector2dF SnapFlingCurve::EstimateDisplacement(
return destination;
}
SnapFlingCurve::SnapFlingCurve(const gfx::Vector2dF& start_offset,
const gfx::Vector2dF& target_offset,
SnapFlingCurve::SnapFlingCurve(const gfx::PointF& start_offset,
const gfx::PointF& target_offset,
base::TimeTicks first_gsu_time)
: start_offset_(start_offset),
total_displacement_(target_offset - start_offset),
@ -104,7 +104,7 @@ gfx::Vector2dF SnapFlingCurve::GetScrollDelta(base::TimeTicks time_stamp) {
return new_displacement - current_displacement_;
}
void SnapFlingCurve::UpdateCurrentOffset(const gfx::Vector2dF& current_offset) {
void SnapFlingCurve::UpdateCurrentOffset(const gfx::PointF& current_offset) {
current_displacement_ = current_offset - start_offset_;
}

@ -18,8 +18,8 @@ class CC_EXPORT SnapFlingCurve {
public:
// Creates the curve based on the start offset, target offset, and the first
// inertial GSU's time_stamp.
SnapFlingCurve(const gfx::Vector2dF& start_offset,
const gfx::Vector2dF& target_offset,
SnapFlingCurve(const gfx::PointF& start_offset,
const gfx::PointF& target_offset,
base::TimeTicks first_gsu_time);
virtual ~SnapFlingCurve();
@ -33,7 +33,7 @@ class CC_EXPORT SnapFlingCurve {
// Updates |current_displacement_|. This sync is necessary because the node
// might be scrolled by other calls and the scrolls might be clamped.
void UpdateCurrentOffset(const gfx::Vector2dF& current_offset);
void UpdateCurrentOffset(const gfx::PointF& current_offset);
// Returns true if the scroll has arrived at the snap destination.
virtual bool IsFinished() const;
@ -45,7 +45,7 @@ class CC_EXPORT SnapFlingCurve {
double GetCurrentCurveDistance(base::TimeDelta current_time);
// The initial scroll offset of the scroller.
const gfx::Vector2dF start_offset_;
const gfx::PointF start_offset_;
// The total displacement to the snap position.
const gfx::Vector2dF total_displacement_;

@ -10,17 +10,17 @@ namespace cc {
namespace test {
TEST(SnapFlingCurveTest, CurveInitialization) {
SnapFlingCurve active_curve(gfx::Vector2dF(100, 100),
gfx::Vector2dF(500, 500), base::TimeTicks());
SnapFlingCurve active_curve(gfx::PointF(100, 100), gfx::PointF(500, 500),
base::TimeTicks());
EXPECT_FALSE(active_curve.IsFinished());
SnapFlingCurve finished_curve(gfx::Vector2dF(100, 100),
gfx::Vector2dF(100, 100), base::TimeTicks());
SnapFlingCurve finished_curve(gfx::PointF(100, 100), gfx::PointF(100, 100),
base::TimeTicks());
EXPECT_TRUE(finished_curve.IsFinished());
}
TEST(SnapFlingCurveTest, AdvanceHalfwayThrough) {
SnapFlingCurve curve(gfx::Vector2dF(100, 100), gfx::Vector2dF(500, 500),
SnapFlingCurve curve(gfx::PointF(100, 100), gfx::PointF(500, 500),
base::TimeTicks());
base::TimeDelta duration = curve.duration();
gfx::Vector2dF delta1 =
@ -36,12 +36,12 @@ TEST(SnapFlingCurveTest, AdvanceHalfwayThrough) {
EXPECT_EQ(delta1, delta2);
EXPECT_FALSE(curve.IsFinished());
curve.UpdateCurrentOffset(gfx::Vector2dF(100, 100) + delta1);
curve.UpdateCurrentOffset(gfx::PointF(100, 100) + delta1);
EXPECT_FALSE(curve.IsFinished());
}
TEST(SnapFlingCurveTest, AdvanceFullyThrough) {
SnapFlingCurve curve(gfx::Vector2dF(100, 100), gfx::Vector2dF(500, 500),
SnapFlingCurve curve(gfx::PointF(100, 100), gfx::PointF(500, 500),
base::TimeTicks());
gfx::Vector2dF delta =
curve.GetScrollDelta(base::TimeTicks() + curve.duration());
@ -50,9 +50,9 @@ TEST(SnapFlingCurveTest, AdvanceFullyThrough) {
}
TEST(SnapFlingCurveTest, ReturnsZeroAfterFinished) {
SnapFlingCurve curve(gfx::Vector2dF(100, 100), gfx::Vector2dF(500, 500),
SnapFlingCurve curve(gfx::PointF(100, 100), gfx::PointF(500, 500),
base::TimeTicks());
curve.UpdateCurrentOffset(gfx::Vector2dF(500, 500));
curve.UpdateCurrentOffset(gfx::PointF(500, 500));
gfx::Vector2dF delta = curve.GetScrollDelta(base::TimeTicks());
EXPECT_EQ(gfx::Vector2dF(), delta);
EXPECT_TRUE(curve.IsFinished());
@ -63,16 +63,16 @@ TEST(SnapFlingCurveTest, ReturnsZeroAfterFinished) {
}
TEST(SnapFlingCurveTest, FlingFinishesWithinOnePixel) {
SnapFlingCurve curve(gfx::Vector2dF(0, 0), gfx::Vector2dF(100.5, 99.5),
SnapFlingCurve curve(gfx::PointF(0, 0), gfx::PointF(100.5, 99.5),
base::TimeTicks());
EXPECT_FALSE(curve.IsFinished());
curve.UpdateCurrentOffset(gfx::Vector2dF(99, 101));
curve.UpdateCurrentOffset(gfx::PointF(99, 101));
// IsFinished() is updated in GetScrollDelta().
curve.GetScrollDelta(base::TimeTicks());
EXPECT_FALSE(curve.IsFinished());
curve.UpdateCurrentOffset(gfx::Vector2dF(100, 100));
curve.UpdateCurrentOffset(gfx::PointF(100, 100));
curve.GetScrollDelta(base::TimeTicks());
EXPECT_TRUE(curve.IsFinished());
}

@ -10,7 +10,7 @@ namespace cc {
std::unique_ptr<SnapSelectionStrategy>
SnapSelectionStrategy::CreateForEndPosition(
const gfx::Vector2dF& current_position,
const gfx::PointF& current_position,
bool scrolled_x,
bool scrolled_y,
SnapTargetsPrioritization prioritization) {
@ -19,7 +19,7 @@ SnapSelectionStrategy::CreateForEndPosition(
}
std::unique_ptr<SnapSelectionStrategy>
SnapSelectionStrategy::CreateForDirection(gfx::Vector2dF current_position,
SnapSelectionStrategy::CreateForDirection(gfx::PointF current_position,
gfx::Vector2dF step,
bool use_fractional_offsets,
SnapStopAlwaysFilter filter) {
@ -28,7 +28,7 @@ SnapSelectionStrategy::CreateForDirection(gfx::Vector2dF current_position,
}
std::unique_ptr<SnapSelectionStrategy>
SnapSelectionStrategy::CreateForEndAndDirection(gfx::Vector2dF current_position,
SnapSelectionStrategy::CreateForEndAndDirection(gfx::PointF current_position,
gfx::Vector2dF displacement,
bool use_fractional_offsets) {
return std::make_unique<EndAndDirectionStrategy>(
@ -36,7 +36,7 @@ SnapSelectionStrategy::CreateForEndAndDirection(gfx::Vector2dF current_position,
}
std::unique_ptr<SnapSelectionStrategy>
SnapSelectionStrategy::CreateForTargetElement(gfx::Vector2dF current_position) {
SnapSelectionStrategy::CreateForTargetElement(gfx::PointF current_position) {
return std::make_unique<EndPositionStrategy>(
current_position, true /* scrolled_x */, true /* scrolled_y */,
SnapTargetsPrioritization::kRequire);
@ -73,11 +73,11 @@ bool EndPositionStrategy::ShouldSnapOnY() const {
return scrolled_y_;
}
gfx::Vector2dF EndPositionStrategy::intended_position() const {
gfx::PointF EndPositionStrategy::intended_position() const {
return current_position_;
}
gfx::Vector2dF EndPositionStrategy::base_position() const {
gfx::PointF EndPositionStrategy::base_position() const {
return current_position_;
}
@ -110,11 +110,11 @@ bool DirectionStrategy::ShouldSnapOnY() const {
return step_.y() != 0;
}
gfx::Vector2dF DirectionStrategy::intended_position() const {
gfx::PointF DirectionStrategy::intended_position() const {
return current_position_ + step_;
}
gfx::Vector2dF DirectionStrategy::base_position() const {
gfx::PointF DirectionStrategy::base_position() const {
return current_position_;
}
@ -184,11 +184,11 @@ bool EndAndDirectionStrategy::ShouldSnapOnY() const {
return displacement_.y() != 0;
}
gfx::Vector2dF EndAndDirectionStrategy::intended_position() const {
gfx::PointF EndAndDirectionStrategy::intended_position() const {
return current_position_ + displacement_;
}
gfx::Vector2dF EndAndDirectionStrategy::base_position() const {
gfx::PointF EndAndDirectionStrategy::base_position() const {
return current_position_ + displacement_;
}

@ -23,7 +23,7 @@ class CC_EXPORT SnapSelectionStrategy {
SnapSelectionStrategy() = default;
virtual ~SnapSelectionStrategy() = default;
static std::unique_ptr<SnapSelectionStrategy> CreateForEndPosition(
const gfx::Vector2dF& current_position,
const gfx::PointF& current_position,
bool scrolled_x,
bool scrolled_y,
SnapTargetsPrioritization prioritization =
@ -32,12 +32,12 @@ class CC_EXPORT SnapSelectionStrategy {
// |use_fractional_offsets| should be true when the current position is
// provided in fractional pixels.
static std::unique_ptr<SnapSelectionStrategy> CreateForDirection(
gfx::Vector2dF current_position,
gfx::PointF current_position,
gfx::Vector2dF step,
bool use_fractional_offsets,
SnapStopAlwaysFilter filter = SnapStopAlwaysFilter::kIgnore);
static std::unique_ptr<SnapSelectionStrategy> CreateForEndAndDirection(
gfx::Vector2dF current_position,
gfx::PointF current_position,
gfx::Vector2dF displacement,
bool use_fractional_offsets);
@ -45,7 +45,7 @@ class CC_EXPORT SnapSelectionStrategy {
// targets if possible, but defaults to finding the closest snap point if
// the target no longer exists.
static std::unique_ptr<SnapSelectionStrategy> CreateForTargetElement(
gfx::Vector2dF current_position);
gfx::PointF current_position);
// Returns whether it's snappable on x or y depending on the scroll performed.
virtual bool ShouldSnapOnX() const = 0;
@ -56,12 +56,12 @@ class CC_EXPORT SnapSelectionStrategy {
virtual bool ShouldPrioritizeSnapTargets() const;
// Returns the end position of the scroll if no snap interferes.
virtual gfx::Vector2dF intended_position() const = 0;
virtual gfx::PointF intended_position() const = 0;
// Returns the scroll position from which the snap position should minimize
// its distance.
virtual gfx::Vector2dF base_position() const = 0;
virtual gfx::PointF base_position() const = 0;
// Returns the current scroll position of the snap container.
const gfx::Vector2dF& current_position() const { return current_position_; }
const gfx::PointF& current_position() const { return current_position_; }
// Returns true if the selection strategy considers the given snap offset
// valid for the current axis.
@ -89,9 +89,9 @@ class CC_EXPORT SnapSelectionStrategy {
virtual bool UsingFractionalOffsets() const;
protected:
explicit SnapSelectionStrategy(const gfx::Vector2dF& current_position)
explicit SnapSelectionStrategy(const gfx::PointF& current_position)
: current_position_(current_position) {}
const gfx::Vector2dF current_position_;
const gfx::PointF current_position_;
};
// Examples for intended end position scrolls include
@ -106,7 +106,7 @@ class CC_EXPORT SnapSelectionStrategy {
// * Return the end position if that makes a snap area covers the snapport.
class EndPositionStrategy : public SnapSelectionStrategy {
public:
EndPositionStrategy(const gfx::Vector2dF& current_position,
EndPositionStrategy(const gfx::PointF& current_position,
bool scrolled_x,
bool scrolled_y,
SnapTargetsPrioritization snap_targets_prioritization)
@ -119,8 +119,8 @@ class EndPositionStrategy : public SnapSelectionStrategy {
bool ShouldSnapOnX() const override;
bool ShouldSnapOnY() const override;
gfx::Vector2dF intended_position() const override;
gfx::Vector2dF base_position() const override;
gfx::PointF intended_position() const override;
gfx::PointF base_position() const override;
bool IsValidSnapPosition(SearchAxis axis, float position) const override;
bool HasIntendedDirection() const override;
@ -149,7 +149,7 @@ class DirectionStrategy : public SnapSelectionStrategy {
public:
// |use_fractional_offsets| should be true when the current position is
// provided in fractional pixels.
DirectionStrategy(const gfx::Vector2dF& current_position,
DirectionStrategy(const gfx::PointF& current_position,
const gfx::Vector2dF& step,
SnapStopAlwaysFilter filter,
bool use_fractional_offsets)
@ -162,8 +162,8 @@ class DirectionStrategy : public SnapSelectionStrategy {
bool ShouldSnapOnX() const override;
bool ShouldSnapOnY() const override;
gfx::Vector2dF intended_position() const override;
gfx::Vector2dF base_position() const override;
gfx::PointF intended_position() const override;
gfx::PointF base_position() const override;
bool IsValidSnapPosition(SearchAxis axis, float position) const override;
bool IsValidSnapArea(SearchAxis axis,
@ -194,7 +194,7 @@ class EndAndDirectionStrategy : public SnapSelectionStrategy {
public:
// |use_fractional_offsets| should be true when the current position is
// provided in fractional pixels.
EndAndDirectionStrategy(const gfx::Vector2dF& current_position,
EndAndDirectionStrategy(const gfx::PointF& current_position,
const gfx::Vector2dF& displacement,
bool use_fractional_offsets)
: SnapSelectionStrategy(current_position),
@ -205,8 +205,8 @@ class EndAndDirectionStrategy : public SnapSelectionStrategy {
bool ShouldSnapOnX() const override;
bool ShouldSnapOnY() const override;
gfx::Vector2dF intended_position() const override;
gfx::Vector2dF base_position() const override;
gfx::PointF intended_position() const override;
gfx::PointF base_position() const override;
bool IsValidSnapPosition(SearchAxis axis, float position) const override;

@ -489,7 +489,7 @@ void ThreadedInputHandler::AdjustScrollDeltaForScrollbarSnap(
// properly set. Currently, track and arrow scrolls both use a direction
// strategy; however, the track should be using an "end and direction"
// strategy.
gfx::Vector2dF current_position = GetVisualScrollOffset(*scroll_node);
gfx::PointF current_position = GetVisualScrollOffset(*scroll_node);
const SnapContainerData& data = scroll_node->snap_container_data.value();
std::unique_ptr<SnapSelectionStrategy> strategy =
SnapSelectionStrategy::CreateForDirection(
@ -497,7 +497,7 @@ void ThreadedInputHandler::AdjustScrollDeltaForScrollbarSnap(
gfx::Vector2dF(scroll_state->delta_x(), scroll_state->delta_y()),
true);
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
TargetSnapAreaElementIds snap_target_ids;
if (!data.FindSnapPosition(*strategy, &snap_position, &snap_target_ids))
return;
@ -693,7 +693,7 @@ void ThreadedInputHandler::RequestUpdateForSynchronousInputHandler() {
}
void ThreadedInputHandler::SetSynchronousInputHandlerRootScrollOffset(
const gfx::Vector2dF& root_content_offset) {
const gfx::PointF& root_content_offset) {
TRACE_EVENT2(
"cc", "ThreadedInputHandler::SetSynchronousInputHandlerRootScrollOffset",
"offset_x", root_content_offset.x(), "offset_y", root_content_offset.y());
@ -879,7 +879,7 @@ void ThreadedInputHandler::DestroyScrollElasticityHelper() {
}
bool ThreadedInputHandler::GetScrollOffsetForLayer(ElementId element_id,
gfx::Vector2dF* offset) {
gfx::PointF* offset) {
ScrollTree& scroll_tree = GetScrollTree();
ScrollNode* scroll_node = scroll_tree.FindNodeFromElementId(element_id);
if (!scroll_node)
@ -889,7 +889,7 @@ bool ThreadedInputHandler::GetScrollOffsetForLayer(ElementId element_id,
}
bool ThreadedInputHandler::ScrollLayerTo(ElementId element_id,
const gfx::Vector2dF& offset) {
const gfx::PointF& offset) {
ScrollTree& scroll_tree = GetScrollTree();
ScrollNode* scroll_node = scroll_tree.FindNodeFromElementId(element_id);
if (!scroll_node)
@ -920,8 +920,8 @@ bool ThreadedInputHandler::ScrollingShouldSwitchtoMainThread() {
bool ThreadedInputHandler::GetSnapFlingInfoAndSetAnimatingSnapTarget(
const gfx::Vector2dF& natural_displacement_in_viewport,
gfx::Vector2dF* out_initial_position,
gfx::Vector2dF* out_target_position) {
gfx::PointF* out_initial_position,
gfx::PointF* out_target_position) {
ScrollNode* scroll_node = CurrentlyScrollingNode();
if (!scroll_node || !scroll_node->snap_container_data.has_value())
return false;
@ -931,7 +931,7 @@ bool ThreadedInputHandler::GetSnapFlingInfoAndSetAnimatingSnapTarget(
gfx::Vector2dF natural_displacement_in_content =
gfx::ScaleVector2d(natural_displacement_in_viewport, 1.f / scale_factor);
gfx::Vector2dF current_offset = GetVisualScrollOffset(*scroll_node);
gfx::PointF current_offset = GetVisualScrollOffset(*scroll_node);
*out_initial_position = current_offset;
// CC side always uses fractional scroll deltas.
@ -1316,8 +1316,7 @@ InputHandler::ScrollStatus ThreadedInputHandler::TryScroll(
// The a viewport node should be scrolled even if it has no scroll extent
// since it'll scroll using the Viewport class which will generate browser
// controls movement and overscroll delta.
gfx::Vector2dF max_scroll_offset =
scroll_tree.MaxScrollOffset(scroll_node->id);
gfx::PointF max_scroll_offset = scroll_tree.MaxScrollOffset(scroll_node->id);
if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0 &&
!GetViewport().ShouldScroll(*scroll_node)) {
TRACE_EVENT0("cc",
@ -1593,9 +1592,9 @@ gfx::Vector2dF ThreadedInputHandler::ComputeScrollDelta(
adjusted_scroll.Scale(1.f / scale_factor);
adjusted_scroll = UserScrollableDelta(scroll_node, adjusted_scroll);
gfx::Vector2dF old_offset =
gfx::PointF old_offset =
scroll_tree.current_scroll_offset(scroll_node.element_id);
gfx::Vector2dF new_offset = scroll_tree.ClampScrollOffsetToLimits(
gfx::PointF new_offset = scroll_tree.ClampScrollOffsetToLimits(
old_offset + adjusted_scroll, scroll_node);
return new_offset - old_offset;
@ -1666,7 +1665,7 @@ gfx::Vector2dF ThreadedInputHandler::ScrollNodeWithViewportSpaceDelta(
local_scroll_delta.y(), "is_outer", scrolls_outer_viewport);
// Apply the scroll delta.
gfx::Vector2dF previous_offset =
gfx::PointF previous_offset =
scroll_tree.current_scroll_offset(scroll_node.element_id);
scroll_tree.ScrollBy(scroll_node, local_scroll_delta, &ActiveTree());
gfx::Vector2dF scrolled =
@ -1706,7 +1705,7 @@ gfx::Vector2dF ThreadedInputHandler::ScrollNodeWithLocalDelta(
float page_scale_factor = compositor_delegate_.PageScaleFactor();
ScrollTree& scroll_tree = GetScrollTree();
gfx::Vector2dF previous_offset =
gfx::PointF previous_offset =
scroll_tree.current_scroll_offset(scroll_node.element_id);
gfx::Vector2dF delta = local_delta;
delta.Scale(1.f / page_scale_factor);
@ -2024,7 +2023,7 @@ bool ThreadedInputHandler::SnapAtScrollEnd(SnapReason reason) {
return false;
SnapContainerData& data = scroll_node->snap_container_data.value();
gfx::Vector2dF current_position = GetVisualScrollOffset(*scroll_node);
gfx::PointF current_position = GetVisualScrollOffset(*scroll_node);
// You might think that if a scroll never received a scroll update we could
// just drop the snap. However, if the GSB+GSE arrived while we were mid-snap
@ -2058,7 +2057,7 @@ bool ThreadedInputHandler::SnapAtScrollEnd(SnapReason reason) {
did_scroll_y_for_scroll_gesture_);
}
gfx::Vector2dF snap_position;
gfx::PointF snap_position;
TargetSnapAreaElementIds snap_target_ids;
if (!data.FindSnapPosition(*strategy, &snap_position, &snap_target_ids))
return false;
@ -2096,7 +2095,7 @@ bool ThreadedInputHandler::IsAnimatingForSnap() const {
return scroll_animating_snap_target_ids_ != TargetSnapAreaElementIds();
}
gfx::Vector2dF ThreadedInputHandler::GetVisualScrollOffset(
gfx::PointF ThreadedInputHandler::GetVisualScrollOffset(
const ScrollNode& scroll_node) const {
if (scroll_node.scrolls_outer_viewport)
return GetViewport().TotalScrollOffset();

@ -71,7 +71,7 @@ class CC_EXPORT ThreadedInputHandler : public InputHandler,
const gfx::PointF& viewport_point) override;
void RequestUpdateForSynchronousInputHandler() override;
void SetSynchronousInputHandlerRootScrollOffset(
const gfx::Vector2dF& root_content_offset) override;
const gfx::PointF& root_content_offset) override;
void PinchGestureBegin() override;
void PinchGestureUpdate(float magnify_delta,
const gfx::Point& anchor) override;
@ -94,14 +94,13 @@ class CC_EXPORT ThreadedInputHandler : public InputHandler,
ScrollElasticityHelper* CreateScrollElasticityHelper() override;
void DestroyScrollElasticityHelper() override;
bool GetScrollOffsetForLayer(ElementId element_id,
gfx::Vector2dF* offset) override;
bool ScrollLayerTo(ElementId element_id,
const gfx::Vector2dF& offset) override;
gfx::PointF* offset) override;
bool ScrollLayerTo(ElementId element_id, const gfx::PointF& offset) override;
bool ScrollingShouldSwitchtoMainThread() override;
bool GetSnapFlingInfoAndSetAnimatingSnapTarget(
const gfx::Vector2dF& natural_displacement_in_viewport,
gfx::Vector2dF* out_initial_position,
gfx::Vector2dF* out_target_position) override;
gfx::PointF* out_initial_position,
gfx::PointF* out_target_position) override;
void ScrollEndForSnapFling(bool did_finish) override;
void NotifyInputEvent() override;
bool ScrollbarScrollIsActive() override;
@ -184,7 +183,7 @@ class CC_EXPORT ThreadedInputHandler : public InputHandler,
// This method gets the scroll offset for a regular scroller, or the combined
// visual and layout offsets of the viewport.
gfx::Vector2dF GetVisualScrollOffset(const ScrollNode& scroll_node) const;
gfx::PointF GetVisualScrollOffset(const ScrollNode& scroll_node) const;
bool IsScrolledBy(LayerImpl* child, ScrollNode* ancestor);
bool IsAnimatingForSnap() const;

@ -957,7 +957,7 @@ void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) {
SetNeedsCommit();
}
void Layer::SetScrollOffset(const gfx::Vector2dF& scroll_offset) {
void Layer::SetScrollOffset(const gfx::PointF& scroll_offset) {
DCHECK(IsPropertyChangeAllowed());
auto& inputs = EnsureLayerTreeInputs();
@ -973,7 +973,7 @@ void Layer::SetScrollOffset(const gfx::Vector2dF& scroll_offset) {
SetNeedsCommit();
}
void Layer::SetScrollOffsetFromImplSide(const gfx::Vector2dF& scroll_offset) {
void Layer::SetScrollOffsetFromImplSide(const gfx::PointF& scroll_offset) {
DCHECK(IsPropertyChangeAllowed());
// This function only gets called during a BeginMainFrame, so there
// is no need to call SetNeedsUpdate here.
@ -1018,7 +1018,7 @@ void Layer::UpdatePropertyTreeScrollOffset() {
}
void Layer::SetDidScrollCallback(
base::RepeatingCallback<void(const gfx::Vector2dF&, const ElementId&)>
base::RepeatingCallback<void(const gfx::PointF&, const ElementId&)>
callback) {
EnsureLayerTreeInputs().did_scroll_callback = std::move(callback);
}

@ -33,6 +33,7 @@
#include "components/viz/common/surfaces/subtree_capture_id.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/geometry/rrect_f.h"
@ -395,16 +396,16 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
// position of its subtree, as well as other layers for which this layer is
// their scroll parent, and their subtrees) is moved up by the amount of
// offset specified here.
void SetScrollOffset(const gfx::Vector2dF& scroll_offset);
gfx::Vector2dF scroll_offset() const {
void SetScrollOffset(const gfx::PointF& scroll_offset);
gfx::PointF scroll_offset() const {
return layer_tree_inputs() ? layer_tree_inputs()->scroll_offset
: gfx::Vector2dF();
: gfx::PointF();
}
// For layer tree mode only.
// Called internally during commit to update the layer with state from the
// compositor thread. Not to be called externally by users of this class.
void SetScrollOffsetFromImplSide(const gfx::Vector2dF& scroll_offset);
void SetScrollOffsetFromImplSide(const gfx::PointF& scroll_offset);
// For layer tree mode only.
// Marks this layer as being scrollable and needing an associated scroll node,
@ -480,7 +481,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
// which case nothing is called. This is for layer tree mode only. Should use
// ScrollTree::SetScrollCallbacks() in layer list mode.
void SetDidScrollCallback(
base::RepeatingCallback<void(const gfx::Vector2dF&, const ElementId&)>);
base::RepeatingCallback<void(const gfx::PointF&, const ElementId&)>);
// For layer tree mode only.
// Sets the given |subtree_id| on this layer, so that the layer subtree rooted
@ -942,7 +943,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
int mirror_count = 0;
gfx::Vector2dF scroll_offset;
gfx::PointF scroll_offset;
// Size of the scroll container that this layer scrolls in.
gfx::Size scroll_container_bounds;
@ -950,7 +951,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
// top left, top right, bottom right, bottom left
gfx::RoundedCornersF corner_radii;
base::RepeatingCallback<void(const gfx::Vector2dF&, const ElementId&)>
base::RepeatingCallback<void(const gfx::PointF&, const ElementId&)>
did_scroll_callback;
std::vector<std::unique_ptr<viz::CopyOutputRequest>> copy_requests;
};

@ -610,7 +610,7 @@ gfx::Rect LayerImpl::GetDamageRect() const {
return gfx::Rect();
}
void LayerImpl::SetCurrentScrollOffset(const gfx::Vector2dF& scroll_offset) {
void LayerImpl::SetCurrentScrollOffset(const gfx::PointF& scroll_offset) {
DCHECK(IsActive());
if (GetScrollTree().SetScrollOffset(element_id(), scroll_offset))
layer_tree_impl()->DidUpdateScrollOffset(element_id());

@ -35,6 +35,7 @@
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/display_color_spaces.h"
#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/transform.h"
@ -244,7 +245,7 @@ class CC_EXPORT LayerImpl {
is_inner_viewport_scroll_layer_ = true;
}
void SetCurrentScrollOffset(const gfx::Vector2dF& scroll_offset);
void SetCurrentScrollOffset(const gfx::PointF& scroll_offset);
// Returns the delta of the scroll that was outside of the bounds of the
// initial scroll

@ -162,6 +162,8 @@ TEST_F(LayerImplTest, VerifyNeedsUpdateDrawProperties) {
float arbitrary_number = 0.352f;
gfx::Size arbitrary_size = gfx::Size(111, 222);
gfx::Vector2d arbitrary_vector2d = gfx::Vector2d(111, 222);
gfx::PointF arbitrary_scroll_offset(
gfx::PointAtOffsetFromOrigin(arbitrary_vector2d));
gfx::Size large_size = gfx::Size(1000, 1000);
SkColor arbitrary_color = SkColorSetRGB(10, 20, 30);
gfx::Transform arbitrary_transform;
@ -208,9 +210,9 @@ TEST_F(LayerImplTest, VerifyNeedsUpdateDrawProperties) {
->scroll_tree.SetScrollOffsetDeltaForTesting(layer->element_id(),
gfx::Vector2dF());
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
layer->SetCurrentScrollOffset(arbitrary_vector2d));
layer->SetCurrentScrollOffset(arbitrary_scroll_offset));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
layer->SetCurrentScrollOffset(arbitrary_vector2d));
layer->SetCurrentScrollOffset(arbitrary_scroll_offset));
// Unrelated functions, always set to new values, always set needs update.
host_impl()->active_tree()->set_needs_update_draw_properties();
@ -340,63 +342,63 @@ TEST_F(LayerImplScrollTest, ScrollByWithZeroOffset) {
// Test that LayerImpl::ScrollBy only affects ScrollDelta and total scroll
// offset is bounded by the range [0, max scroll offset].
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(),
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_POINTF_EQ(gfx::PointF(), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(),
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(layer()));
layer()->ScrollBy(gfx::Vector2dF(-100, 100));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0, 80), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(0, 80), CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(ScrollDelta(layer())),
CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(),
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_POINTF_EQ(gfx::PointAtOffsetFromOrigin(ScrollDelta(layer())),
CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(),
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
layer()->ScrollBy(gfx::Vector2dF(100, -100));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(50, 0), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(50, 0), CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(ScrollDelta(layer())),
CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(),
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_POINTF_EQ(gfx::PointAtOffsetFromOrigin(ScrollDelta(layer())),
CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(),
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
}
TEST_F(LayerImplScrollTest, ScrollByWithNonZeroOffset) {
gfx::Vector2dF scroll_offset(10, 5);
gfx::PointF scroll_offset(10, 5);
scroll_tree(layer())->UpdateScrollOffsetBaseForTesting(layer()->element_id(),
scroll_offset);
EXPECT_VECTOR2DF_EQ(scroll_offset, CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_POINTF_EQ(scroll_offset, CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(layer()));
layer()->ScrollBy(gfx::Vector2dF(-100, 100));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0, 80), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(0, 80), CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(scroll_offset + ScrollDelta(layer()),
CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_POINTF_EQ(scroll_offset + ScrollDelta(layer()),
CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
layer()->ScrollBy(gfx::Vector2dF(100, -100));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(50, 0), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(50, 0), CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(scroll_offset + ScrollDelta(layer()),
CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_POINTF_EQ(scroll_offset + ScrollDelta(layer()),
CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
}
TEST_F(LayerImplScrollTest, ApplySentScrollsNoListener) {
gfx::Vector2dF scroll_offset(10, 5);
gfx::PointF scroll_offset(10, 5);
gfx::Vector2dF scroll_delta(20.5f, 8.5f);
gfx::Vector2d sent_scroll_delta(12, -3);
@ -406,25 +408,23 @@ TEST_F(LayerImplScrollTest, ApplySentScrollsNoListener) {
scroll_tree(layer())->CollectScrollDeltasForTesting();
layer()->SetCurrentScrollOffset(scroll_offset + scroll_delta);
EXPECT_VECTOR2DF_EQ(scroll_offset + scroll_delta,
CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(scroll_offset + scroll_delta, CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(scroll_delta, ScrollDelta(layer()));
EXPECT_VECTOR2DF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_POINTF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
scroll_tree(layer())->ApplySentScrollDeltasFromAbortedCommit();
EXPECT_VECTOR2DF_EQ(scroll_offset + scroll_delta,
CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(scroll_offset + scroll_delta, CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(scroll_delta - sent_scroll_delta, ScrollDelta(layer()));
EXPECT_VECTOR2DF_EQ(scroll_offset + sent_scroll_delta,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_POINTF_EQ(scroll_offset + sent_scroll_delta,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
}
TEST_F(LayerImplScrollTest, ScrollUserUnscrollableLayer) {
gfx::Vector2dF scroll_offset(10, 5);
gfx::PointF scroll_offset(10, 5);
gfx::Vector2dF scroll_delta(20.5f, 8.5f);
GetScrollNode(layer())->user_scrollable_vertical = false;
@ -434,7 +434,7 @@ TEST_F(LayerImplScrollTest, ScrollUserUnscrollableLayer) {
gfx::Vector2dF unscrolled = layer()->ScrollBy(scroll_delta);
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0, 8.5f), unscrolled);
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(30.5f, 5), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(30.5f, 5), CurrentScrollOffset(layer()));
}
// |LayerImpl::all_touch_action_regions_| is a cache of all regions on
@ -464,7 +464,7 @@ TEST_F(LayerImplScrollTest, TouchActionRegionCacheInvalidation) {
TEST_F(CommitToPendingTreeLayerImplScrollTest,
PushPropertiesToMirrorsCurrentScrollOffset) {
gfx::Vector2dF scroll_offset(10, 5);
gfx::PointF scroll_offset(10, 5);
gfx::Vector2dF scroll_delta(12, 18);
host_impl()->CreatePendingTree();
@ -474,7 +474,7 @@ TEST_F(CommitToPendingTreeLayerImplScrollTest,
gfx::Vector2dF unscrolled = layer()->ScrollBy(scroll_delta);
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0, 0), unscrolled);
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(22, 23), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(22, 23), CurrentScrollOffset(layer()));
scroll_tree(layer())->CollectScrollDeltasForTesting();
@ -488,9 +488,9 @@ TEST_F(CommitToPendingTreeLayerImplScrollTest,
pending_layer->PushPropertiesTo(layer());
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(22, 23), CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(CurrentScrollOffset(layer()),
CurrentScrollOffset(pending_layer.get()));
EXPECT_POINTF_EQ(gfx::PointF(22, 23), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(CurrentScrollOffset(layer()),
CurrentScrollOffset(pending_layer.get()));
}
TEST_F(LayerImplTest, JitterTest) {
@ -516,7 +516,7 @@ TEST_F(LayerImplTest, JitterTest) {
accumulated_scroll += scroll;
SetScrollOffset(
host_impl()->active_tree()->InnerViewportScrollLayerForTesting(),
gfx::Vector2dF(0, accumulated_scroll));
gfx::PointF(0, accumulated_scroll));
UpdateActiveTreeDrawProperties();
host_impl()->CreatePendingTree();
@ -524,7 +524,7 @@ TEST_F(LayerImplTest, JitterTest) {
pending_tree->set_source_frame_number(i + 1);
pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f);
// Simulate scroll offset pushed from the main thread.
SetScrollOffset(scroll_layer, gfx::Vector2dF(0, accumulated_scroll));
SetScrollOffset(scroll_layer, gfx::PointF(0, accumulated_scroll));
// The scroll done on the active tree is undone on the pending tree.
content_layer->SetOffsetToTransformParent(
gfx::Vector2dF(0, accumulated_scroll));

@ -985,8 +985,7 @@ TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) {
// We can use any layer pointer here since we aren't syncing for real.
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetScrollable(gfx::Size(1, 1)));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUserScrollable(true, false));
EXPECT_SET_NEEDS_COMMIT(1,
test_layer->SetScrollOffset(gfx::Vector2dF(10, 10)));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetScrollOffset(gfx::PointF(10, 10)));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNonFastScrollableRegion(
Region(gfx::Rect(1, 1, 2, 2))));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(
@ -1570,7 +1569,7 @@ TEST_F(LayerTest, AnimationSchedulesLayerUpdate) {
// handled similarly to normal compositor scroll updates.
EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0);
layer_tree_host_->SetElementScrollOffsetMutated(
element_id, ElementListType::ACTIVE, gfx::Vector2dF(10, 10));
element_id, ElementListType::ACTIVE, gfx::PointF(10, 10));
Mock::VerifyAndClearExpectations(layer_tree_host_.get());
}

@ -97,8 +97,7 @@ class PictureLayerImplPerfTest : public LayerTreeImplTestBase,
->pending_tree()
->property_trees()
->scroll_tree.UpdateScrollOffsetBaseForTesting(
pending_layer_->element_id(),
gfx::Vector2dF(viewport.x(), viewport.y()));
pending_layer_->element_id(), gfx::PointF(viewport.origin()));
host_impl()->pending_tree()->UpdateDrawProperties();
timer_.Reset();
@ -145,8 +144,7 @@ class PictureLayerImplPerfTest : public LayerTreeImplTestBase,
->pending_tree()
->property_trees()
->scroll_tree.UpdateScrollOffsetBaseForTesting(
pending_layer_->element_id(),
gfx::Vector2dF(viewport.x(), viewport.y()));
pending_layer_->element_id(), gfx::PointF(viewport.origin()));
host_impl()->pending_tree()->UpdateDrawProperties();
timer_.Reset();

@ -5225,7 +5225,7 @@ TEST_F(LegacySWPictureLayerImplTest, ScrollPropagatesToPending) {
SetupDefaultTrees(layer_bounds);
active_layer()->SetCurrentScrollOffset(gfx::Vector2dF(0.0, 50.0));
active_layer()->SetCurrentScrollOffset(gfx::PointF(0.0, 50.0));
UpdateDrawProperties(host_impl()->active_tree());
EXPECT_EQ("0,50 100x100", active_layer()
->HighResTiling()

@ -386,7 +386,7 @@ TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) {
// Choose bounds to give max_scroll_offset = (30, 50).
layer_tree_root->SetBounds(gfx::Size(70, 150));
scroll_layer->SetScrollOffset(gfx::Vector2dF(10, 20));
scroll_layer->SetScrollOffset(gfx::PointF(10, 20));
scroll_layer->SetBounds(gfx::Size(100, 200));
scroll_layer->SetScrollable(gfx::Size(70, 150));
content_layer->SetBounds(gfx::Size(100, 200));
@ -413,7 +413,7 @@ TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) {
layer_tree_root->SetBounds(gfx::Size(700, 1500));
scroll_layer->SetScrollable(gfx::Size(700, 1500));
scroll_layer->SetBounds(gfx::Size(1000, 2000));
scroll_layer->SetScrollOffset(gfx::Vector2dF(100, 200));
scroll_layer->SetScrollOffset(gfx::PointF(100, 200));
content_layer->SetBounds(gfx::Size(1000, 2000));
layer_tree_host_->UpdateLayers();
@ -459,7 +459,7 @@ TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) {
root_layer->AddChild(content_layer);
root_layer->AddChild(scrollbar_layer);
root_layer->SetScrollOffset(gfx::Vector2dF(0, 0));
root_layer->SetScrollOffset(gfx::PointF(0, 0));
scrollbar_layer->SetBounds(gfx::Size(70, 10));
// The track_rect should be relative to the scrollbar's origin.
@ -497,7 +497,7 @@ TEST_F(ScrollbarLayerTest, ThumbRect) {
root_layer->AddChild(content_layer);
root_layer->AddChild(scrollbar_layer);
root_layer->SetScrollOffset(gfx::Vector2dF(0, 0));
root_layer->SetScrollOffset(gfx::PointF(0, 0));
scrollbar_layer->SetBounds(gfx::Size(70, 10));
// The track_rect should be relative to the scrollbar's origin.
@ -516,14 +516,14 @@ TEST_F(ScrollbarLayerTest, ThumbRect) {
scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
// Under-scroll (thumb position should clamp and be unchanged).
root_layer->SetScrollOffset(gfx::Vector2dF(-5, 0));
root_layer->SetScrollOffset(gfx::PointF(-5, 0));
UPDATE_AND_EXTRACT_LAYER_POINTERS();
EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
// Over-scroll (thumb position should clamp on the far side).
root_layer->SetScrollOffset(gfx::Vector2dF(85, 0));
root_layer->SetScrollOffset(gfx::PointF(85, 0));
layer_tree_host_->UpdateLayers();
UPDATE_AND_EXTRACT_LAYER_POINTERS();
@ -568,7 +568,7 @@ TEST_F(ScrollbarLayerTest, ThumbRectForOverlayLeftSideVerticalScrollbar) {
layer_tree_host_->SetRootLayer(root_layer);
root_layer->AddChild(scrollbar_layer);
root_layer->SetScrollOffset(gfx::Vector2dF(0, 0));
root_layer->SetScrollOffset(gfx::PointF(0, 0));
scrollbar_layer->SetBounds(gfx::Size(10, 20));
scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(0, 0, 10, 20));
scrollbar_layer->fake_scrollbar()->set_thumb_size(gfx::Size(10, 4));
@ -1144,7 +1144,7 @@ class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest {
scrollbar_layer->SetIsDrawable(true);
scrollbar_layer->SetBounds(gfx::Size(100, 100));
layer_tree_root->SetScrollable(gfx::Size(100, 200));
layer_tree_root->SetScrollOffset(gfx::Vector2dF(10, 20));
layer_tree_root->SetScrollOffset(gfx::PointF(10, 20));
layer_tree_root->SetBounds(gfx::Size(100, 200));
content_layer->SetBounds(gfx::Size(100, 200));

@ -12,7 +12,7 @@
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/scroll_node.h"
#include "ui/gfx/geometry/vector2d_conversions.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
@ -267,10 +267,10 @@ void Viewport::PinchEnd(const gfx::Point& anchor, bool snap_to_min) {
gfx::PointF(anchor + pinch_anchor_adjustment_);
adjusted_anchor =
gfx::ScalePoint(adjusted_anchor, min_scale / page_scale);
adjusted_anchor += TotalScrollOffset();
host_impl_->StartPageScaleAnimation(
ToRoundedVector2d(adjusted_anchor.OffsetFromOrigin()), true,
min_scale, kSnapToMinZoomAnimationDuration);
adjusted_anchor += TotalScrollOffset().OffsetFromOrigin();
host_impl_->StartPageScaleAnimation(gfx::ToRoundedPoint(adjusted_anchor),
true, min_scale,
kSnapToMinZoomAnimationDuration);
}
}
@ -325,29 +325,32 @@ gfx::Vector2dF Viewport::AdjustOverscroll(const gfx::Vector2dF& delta) const {
return adjusted;
}
gfx::Vector2dF Viewport::MaxTotalScrollOffset() const {
gfx::Vector2dF offset;
offset += scroll_tree().MaxScrollOffset(InnerScrollNode()->id);
gfx::PointF Viewport::MaxTotalScrollOffset() const {
gfx::Vector2dF offset =
scroll_tree().MaxScrollOffset(InnerScrollNode()->id).OffsetFromOrigin();
if (auto* outer_node = OuterScrollNode())
offset += scroll_tree().MaxScrollOffset(outer_node->id);
offset += scroll_tree().MaxScrollOffset(outer_node->id).OffsetFromOrigin();
return offset;
return gfx::PointAtOffsetFromOrigin(offset);
}
gfx::Vector2dF Viewport::TotalScrollOffset() const {
gfx::Vector2dF offset;
gfx::PointF Viewport::TotalScrollOffset() const {
if (!InnerScrollNode())
return offset;
return gfx::PointF();
offset += scroll_tree().current_scroll_offset(InnerScrollNode()->element_id);
gfx::Vector2dF offset =
scroll_tree()
.current_scroll_offset(InnerScrollNode()->element_id)
.OffsetFromOrigin();
if (auto* outer_node = OuterScrollNode())
offset += scroll_tree().current_scroll_offset(outer_node->element_id);
if (auto* outer_node = OuterScrollNode()) {
offset += scroll_tree()
.current_scroll_offset(outer_node->element_id)
.OffsetFromOrigin();
}
return offset;
return gfx::PointAtOffsetFromOrigin(offset);
}
ScrollNode* Viewport::InnerScrollNode() const {

@ -73,7 +73,7 @@ class CC_EXPORT Viewport {
gfx::Vector2dF ScrollAnimated(const gfx::Vector2dF& delta,
base::TimeDelta delayed_by);
gfx::Vector2dF TotalScrollOffset() const;
gfx::PointF TotalScrollOffset() const;
void PinchUpdate(float magnify_delta, const gfx::Point& anchor);
void PinchEnd(const gfx::Point& anchor, bool snap_to_min);
@ -117,7 +117,7 @@ class CC_EXPORT Viewport {
// Sends the delta to the browser controls, returns the amount applied.
gfx::Vector2dF ScrollBrowserControls(const gfx::Vector2dF& delta);
gfx::Vector2dF MaxTotalScrollOffset() const;
gfx::PointF MaxTotalScrollOffset() const;
ScrollNode* InnerScrollNode() const;
ScrollNode* OuterScrollNode() const;

@ -31,7 +31,7 @@ struct RenderFrameMetadata {
// Scroll offset of the root layer. This optional parameter is only sent
// during tests.
gfx.mojom.Vector2dF? root_scroll_offset;
gfx.mojom.PointF? root_scroll_offset;
// Indicates whether the scroll offset of the root layer is at top, i.e.,
// whether scroll_offset.y() == 0.
@ -153,5 +153,5 @@ interface RenderFrameMetadataObserverClient {
// Only called if ReportAllRootScrolls(true) has been called. See
// ReportAllRootScrolls() for details.
[EnableIf=is_android]
OnRootScrollOffsetChanged(gfx.mojom.Vector2dF root_scroll_offset);
OnRootScrollOffsetChanged(gfx.mojom.PointF root_scroll_offset);
};

@ -36,7 +36,7 @@ struct COMPONENT_EXPORT(CC_SHARED_MOJOM_TRAITS)
return metadata.root_background_color;
}
static absl::optional<gfx::Vector2dF> root_scroll_offset(
static absl::optional<gfx::PointF> root_scroll_offset(
const cc::RenderFrameMetadata& metadata) {
return metadata.root_scroll_offset;
}

@ -246,8 +246,8 @@ std::unique_ptr<gfx::AnimationCurve> FakeFloatTransition::Clone() const {
}
int AddScrollOffsetAnimationToAnimation(Animation* animation,
gfx::Vector2dF initial_value,
gfx::Vector2dF target_value) {
gfx::PointF initial_value,
gfx::PointF target_value) {
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
target_value));

@ -15,7 +15,7 @@
#include "ui/gfx/geometry/transform_operations.h"
namespace gfx {
class Vector2dF;
class PointF;
}
namespace cc {
@ -67,8 +67,8 @@ class FakeFloatTransition : public gfx::FloatAnimationCurve {
};
int AddScrollOffsetAnimationToAnimation(Animation* animation,
gfx::Vector2dF initial_value,
gfx::Vector2dF target_value);
gfx::PointF initial_value,
gfx::PointF target_value);
int AddAnimatedTransformToAnimation(Animation* animation,
double duration,

@ -35,7 +35,7 @@ void TestLayer::ClearMutatedProperties() {
opacity_ = 0;
filters_ = FilterOperations();
backdrop_filters_ = FilterOperations();
scroll_offset_ = gfx::Vector2dF();
scroll_offset_ = gfx::PointF();
has_potential_animation_.reset();
is_currently_animating_.reset();
@ -141,7 +141,7 @@ void TestHostClient::SetElementTransformMutated(
void TestHostClient::SetElementScrollOffsetMutated(
ElementId element_id,
ElementListType list_type,
const gfx::Vector2dF& scroll_offset) {
const gfx::PointF& scroll_offset) {
TestLayer* layer = FindTestLayer(element_id, list_type);
if (layer)
layer->set_scroll_offset(scroll_offset);
@ -176,11 +176,11 @@ void TestHostClient::MaximumScaleChanged(ElementId element_id,
}
void TestHostClient::SetScrollOffsetForAnimation(
const gfx::Vector2dF& scroll_offset) {
const gfx::PointF& scroll_offset) {
scroll_offset_ = scroll_offset;
}
gfx::Vector2dF TestHostClient::GetScrollOffsetForAnimation(
gfx::PointF TestHostClient::GetScrollOffsetForAnimation(
ElementId element_id) const {
return scroll_offset_;
}
@ -247,9 +247,8 @@ gfx::Transform TestHostClient::GetTransform(ElementId element_id,
return layer->transform();
}
gfx::Vector2dF TestHostClient::GetScrollOffset(
ElementId element_id,
ElementListType list_type) const {
gfx::PointF TestHostClient::GetScrollOffset(ElementId element_id,
ElementListType list_type) const {
TestLayer* layer = FindTestLayer(element_id, list_type);
EXPECT_TRUE(layer);
return layer->scroll_offset();

@ -15,8 +15,8 @@
#include "cc/trees/mutator_host_client.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/animation/keyframe/target_property.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/transform.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
@ -59,8 +59,8 @@ class TestLayer {
mutated_properties_[TargetProperty::BACKDROP_FILTER] = true;
}
gfx::Vector2dF scroll_offset() const { return scroll_offset_; }
void set_scroll_offset(const gfx::Vector2dF& scroll_offset) {
gfx::PointF scroll_offset() const { return scroll_offset_; }
void set_scroll_offset(const gfx::PointF& scroll_offset) {
scroll_offset_ = scroll_offset;
mutated_properties_[TargetProperty::SCROLL_OFFSET] = true;
}
@ -97,7 +97,7 @@ class TestLayer {
float opacity_;
FilterOperations filters_;
FilterOperations backdrop_filters_;
gfx::Vector2dF scroll_offset_;
gfx::PointF scroll_offset_;
gfx::TargetProperties has_potential_animation_;
gfx::TargetProperties is_currently_animating_;
@ -135,10 +135,9 @@ class TestHostClient : public MutatorHostClient {
ElementListType list_type,
const gfx::Transform& transform) override;
void SetElementScrollOffsetMutated(
ElementId element_id,
ElementListType list_type,
const gfx::Vector2dF& scroll_offset) override;
void SetElementScrollOffsetMutated(ElementId element_id,
ElementListType list_type,
const gfx::PointF& scroll_offset) override;
void ElementIsAnimatingChanged(const PropertyToElementIdMap& element_id_map,
ElementListType list_type,
@ -150,9 +149,8 @@ class TestHostClient : public MutatorHostClient {
void ScrollOffsetAnimationFinished() override {}
void SetScrollOffsetForAnimation(const gfx::Vector2dF& scroll_offset);
gfx::Vector2dF GetScrollOffsetForAnimation(
ElementId element_id) const override;
void SetScrollOffsetForAnimation(const gfx::PointF& scroll_offset);
gfx::PointF GetScrollOffsetForAnimation(ElementId element_id) const override;
void NotifyAnimationWorkletStateChange(AnimationWorkletMutationState state,
ElementListType tree_type) override {}
@ -183,8 +181,8 @@ class TestHostClient : public MutatorHostClient {
float GetOpacity(ElementId element_id, ElementListType list_type) const;
gfx::Transform GetTransform(ElementId element_id,
ElementListType list_type) const;
gfx::Vector2dF GetScrollOffset(ElementId element_id,
ElementListType list_type) const;
gfx::PointF GetScrollOffset(ElementId element_id,
ElementListType list_type) const;
bool GetHasPotentialTransformAnimation(ElementId element_id,
ElementListType list_type) const;
bool GetTransformIsCurrentlyAnimating(ElementId element_id,
@ -227,7 +225,7 @@ class TestHostClient : public MutatorHostClient {
ElementIdToTestLayer layers_in_active_tree_;
ElementIdToTestLayer layers_in_pending_tree_;
gfx::Vector2dF scroll_offset_;
gfx::PointF scroll_offset_;
bool mutators_need_commit_;
};

@ -75,19 +75,19 @@ class MockMutatorHost : public MutatorHost {
bool(ElementId element_id));
MOCK_METHOD5(ImplOnlyAutoScrollAnimationCreate,
void(ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
float autoscroll_velocity,
base::TimeDelta animation_start_offset));
MOCK_METHOD5(ImplOnlyScrollAnimationCreate,
void(ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
base::TimeDelta delayed_by,
base::TimeDelta animation_start_offset));
MOCK_METHOD4(ImplOnlyScrollAnimationUpdateTarget,
bool(const gfx::Vector2dF& scroll_delta,
const gfx::Vector2dF& max_scroll_offset,
const gfx::PointF& max_scroll_offset,
base::TimeTicks frame_monotonic_time,
base::TimeDelta delayed_by));
MOCK_METHOD0(ScrollAnimationAbort, void());

@ -166,7 +166,7 @@ ScrollNode& CreateScrollNodeInternal(LayerType* layer,
transform_node->should_be_snapped = true;
transform_node->scrolls = true;
scroll_tree.SetScrollOffset(layer->element_id(), gfx::Vector2dF());
scroll_tree.SetScrollOffset(layer->element_id(), gfx::PointF());
return *node;
}
@ -193,7 +193,7 @@ void SetupMaskPropertiesInternal(LayerType* masked_layer,
template <typename LayerType>
void SetScrollOffsetInternal(LayerType* layer,
const gfx::Vector2dF& scroll_offset) {
const gfx::PointF& scroll_offset) {
DCHECK(layer->has_transform_node());
auto* transform_node = GetTransformNode(layer);
transform_node->scroll_offset = scroll_offset;
@ -376,7 +376,7 @@ ScrollNode& CreateScrollNodeForUncompositedScroller(
node->transform_id = transform_node->id;
}
scroll_tree.SetScrollOffset(element_id, gfx::Vector2dF());
scroll_tree.SetScrollOffset(element_id, gfx::PointF());
return *node;
}
@ -391,7 +391,7 @@ void SetupMaskProperties(LayerImpl* masked_layer,
SetupMaskPropertiesInternal(masked_layer, mask_layer);
}
void SetScrollOffset(Layer* layer, const gfx::Vector2dF& scroll_offset) {
void SetScrollOffset(Layer* layer, const gfx::PointF& scroll_offset) {
if (layer->layer_tree_host()->IsUsingLayerLists()) {
if (CurrentScrollOffset(layer) != scroll_offset)
layer->SetNeedsCommit();
@ -402,14 +402,14 @@ void SetScrollOffset(Layer* layer, const gfx::Vector2dF& scroll_offset) {
}
void SetScrollOffsetFromImplSide(Layer* layer,
const gfx::Vector2dF& scroll_offset) {
const gfx::PointF& scroll_offset) {
if (layer->layer_tree_host()->IsUsingLayerLists())
SetScrollOffsetInternal(layer, scroll_offset);
else
layer->SetScrollOffsetFromImplSide(scroll_offset);
}
void SetScrollOffset(LayerImpl* layer, const gfx::Vector2dF& scroll_offset) {
void SetScrollOffset(LayerImpl* layer, const gfx::PointF& scroll_offset) {
if (layer->IsActive())
layer->SetCurrentScrollOffset(scroll_offset);
SetScrollOffsetInternal(layer, scroll_offset);
@ -510,7 +510,7 @@ const RenderSurfaceImpl* GetRenderSurface(const LayerImpl* layer) {
return effect_tree.GetRenderSurface(GetEffectNode(layer)->target_id);
}
gfx::Vector2dF ScrollOffsetBase(const LayerImpl* layer) {
gfx::PointF ScrollOffsetBase(const LayerImpl* layer) {
return GetPropertyTrees(layer)->scroll_tree.GetScrollOffsetBaseForTesting(
layer->element_id());
}
@ -520,7 +520,7 @@ gfx::Vector2dF ScrollDelta(const LayerImpl* layer) {
layer->element_id());
}
gfx::Vector2dF CurrentScrollOffset(const Layer* layer) {
gfx::PointF CurrentScrollOffset(const Layer* layer) {
auto result = GetPropertyTrees(layer)->scroll_tree.current_scroll_offset(
layer->element_id());
if (!layer->layer_tree_host()->IsUsingLayerLists())
@ -528,12 +528,12 @@ gfx::Vector2dF CurrentScrollOffset(const Layer* layer) {
return result;
}
gfx::Vector2dF CurrentScrollOffset(const LayerImpl* layer) {
gfx::PointF CurrentScrollOffset(const LayerImpl* layer) {
return GetPropertyTrees(layer)->scroll_tree.current_scroll_offset(
layer->element_id());
}
gfx::Vector2dF MaxScrollOffset(const LayerImpl* layer) {
gfx::PointF MaxScrollOffset(const LayerImpl* layer) {
return GetPropertyTrees(layer)->scroll_tree.MaxScrollOffset(
layer->scroll_tree_index());
}

@ -10,6 +10,7 @@
#include "cc/trees/property_tree.h"
#include "cc/trees/scroll_node.h"
#include "cc/trees/transform_node.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
@ -115,11 +116,11 @@ const ScrollNode* GetScrollNode(const LayerType* layer) {
return GetPropertyTrees(layer)->scroll_tree.Node(layer->scroll_tree_index());
}
void SetScrollOffset(Layer*, const gfx::Vector2dF&);
void SetScrollOffset(LayerImpl*, const gfx::Vector2dF&);
void SetScrollOffset(Layer*, const gfx::PointF&);
void SetScrollOffset(LayerImpl*, const gfx::PointF&);
// Used to synchronize the main-thread scroll offset with the impl-side. The
// difference from SetScrollOffset() is this function doesn't schedule commit.
void SetScrollOffsetFromImplSide(Layer*, const gfx::Vector2dF&);
void SetScrollOffsetFromImplSide(Layer*, const gfx::PointF&);
template <typename LayerType>
void SetLocalTransformChanged(LayerType* layer) {
@ -224,11 +225,11 @@ void SetupViewport(LayerImpl* root,
RenderSurfaceImpl* GetRenderSurface(LayerImpl* layer);
const RenderSurfaceImpl* GetRenderSurface(const LayerImpl* layer);
gfx::Vector2dF ScrollOffsetBase(const LayerImpl* layer);
gfx::PointF ScrollOffsetBase(const LayerImpl* layer);
gfx::Vector2dF ScrollDelta(const LayerImpl* layer);
gfx::Vector2dF CurrentScrollOffset(const Layer* layer);
gfx::Vector2dF CurrentScrollOffset(const LayerImpl* layer);
gfx::Vector2dF MaxScrollOffset(const LayerImpl* layer);
gfx::PointF CurrentScrollOffset(const Layer* layer);
gfx::PointF CurrentScrollOffset(const LayerImpl* layer);
gfx::PointF MaxScrollOffset(const LayerImpl* layer);
} // namespace cc

@ -309,7 +309,7 @@ TEST_F(DrawPropertiesTest, TransformsForSingleLayer) {
}
TEST_F(DrawPropertiesTest, TransformsAboutScrollOffset) {
const gfx::Vector2dF kScrollOffset(50, 100);
const gfx::PointF kScrollOffset(50, 100);
const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
const gfx::Vector2d kMaxScrollOffset(200, 200);
const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
@ -4177,7 +4177,7 @@ TEST_F(DrawPropertiesTest, ClipParentScrolledInterveningLayer) {
CopyProperties(render_surface2, clip_child);
clip_child->SetClipTreeIndex(clip_parent->clip_tree_index());
SetScrollOffset(intervening, gfx::Vector2dF(3, 3));
SetScrollOffset(intervening, gfx::PointF(3, 3));
UpdateActiveTreeDrawProperties();
EXPECT_TRUE(GetRenderSurface(root));
@ -5121,7 +5121,7 @@ TEST_F(DrawPropertiesStickyPositionTest, StickyPositionMainThreadUpdates) {
sticky_pos_impl_->ScreenSpaceTransform().To2dTranslation());
// Now the main thread commits the new position of the sticky element.
SetScrollOffset(scroller_.get(), gfx::Vector2dF(15, 15));
SetScrollOffset(scroller_.get(), gfx::PointF(15, 15));
// Shift the layer by -offset_for_position_sticky.
SetPostTranslation(sticky_pos_.get(),
gfx::PointF(10, 25) - gfx::PointF(0, 5));
@ -5192,7 +5192,7 @@ TEST_F(DrawPropertiesStickyPositionTest, StickyPositionCompositedContainer) {
sticky_pos_impl_->ScreenSpaceTransform().To2dTranslation());
// Now the main thread commits the new position of the sticky element.
SetScrollOffset(scroller_.get(), gfx::Vector2dF(0, 25));
SetScrollOffset(scroller_.get(), gfx::PointF(0, 25));
// Shift the layer by -offset_for_position_sticky.
SetPostTranslation(sticky_pos_.get(),
gfx::PointF(0, 15) - gfx::PointF(0, 5) +
@ -6365,7 +6365,7 @@ TEST_F(DrawPropertiesTest, UpdateScrollChildPosition) {
UpdateActiveTreeDrawProperties();
EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect());
SetScrollOffset(scroll_parent, gfx::Vector2dF(0.f, 10.f));
SetScrollOffset(scroll_parent, gfx::PointF(0.f, 10.f));
UpdateActiveTreeDrawProperties();
EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect());

@ -1192,10 +1192,12 @@ void UpdateElasticOverscroll(
// On other platforms, we modify the translation offset to match the
// overscroll amount.
if (overscroll_elasticity_transform_node->scroll_offset == elastic_overscroll)
gfx::PointF overscroll_offset =
gfx::PointAtOffsetFromOrigin(elastic_overscroll);
if (overscroll_elasticity_transform_node->scroll_offset == overscroll_offset)
return;
overscroll_elasticity_transform_node->scroll_offset = elastic_overscroll;
overscroll_elasticity_transform_node->scroll_offset = overscroll_offset;
overscroll_elasticity_transform_node->needs_local_transform_update = true;
property_trees->transform_tree.set_needs_update(true);

@ -1445,7 +1445,7 @@ void LayerTreeHost::SetPageScaleFactorAndLimits(float page_scale_factor,
SetNeedsCommit();
}
void LayerTreeHost::StartPageScaleAnimation(const gfx::Vector2d& target_offset,
void LayerTreeHost::StartPageScaleAnimation(const gfx::Point& target_offset,
bool use_anchor,
float scale,
base::TimeDelta duration) {
@ -1961,7 +1961,7 @@ void LayerTreeHost::SetElementTransformMutated(
void LayerTreeHost::SetElementScrollOffsetMutated(
ElementId element_id,
ElementListType list_type,
const gfx::Vector2dF& scroll_offset) {
const gfx::PointF& scroll_offset) {
// Do nothing. Scroll deltas will be sent from the compositor thread back
// to the main thread in the same manner as during non-animated
// compositor-driven scrolling.
@ -1984,7 +1984,7 @@ void LayerTreeHost::MaximumScaleChanged(ElementId element_id,
property_trees()->MaximumAnimationScaleChanged(element_id, maximum_scale);
}
gfx::Vector2dF LayerTreeHost::GetScrollOffsetForAnimation(
gfx::PointF LayerTreeHost::GetScrollOffsetForAnimation(
ElementId element_id) const {
return property_trees()->scroll_tree.current_scroll_offset(element_id);
}

@ -507,7 +507,7 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient {
return pending_commit_state()->display_transform_hint;
}
void StartPageScaleAnimation(const gfx::Vector2d& target_offset,
void StartPageScaleAnimation(const gfx::Point& target_offset,
bool use_anchor,
float scale,
base::TimeDelta duration);
@ -742,10 +742,9 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient {
void SetElementTransformMutated(ElementId element_id,
ElementListType list_type,
const gfx::Transform& transform) override;
void SetElementScrollOffsetMutated(
ElementId element_id,
ElementListType list_type,
const gfx::Vector2dF& scroll_offset) override;
void SetElementScrollOffsetMutated(ElementId element_id,
ElementListType list_type,
const gfx::PointF& scroll_offset) override;
void ElementIsAnimatingChanged(const PropertyToElementIdMap& element_id_map,
ElementListType list_type,
@ -760,8 +759,7 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient {
PaintWorkletInput::PropertyValue property_value) override {}
void ScrollOffsetAnimationFinished() override {}
gfx::Vector2dF GetScrollOffsetForAnimation(
ElementId element_id) const override;
gfx::PointF GetScrollOffsetForAnimation(ElementId element_id) const override;
void NotifyAnimationWorkletStateChange(AnimationWorkletMutationState state,
ElementListType tree_type) override {}

@ -947,11 +947,10 @@ bool LayerTreeHostImpl::PrepareTiles() {
return did_prepare_tiles;
}
void LayerTreeHostImpl::StartPageScaleAnimation(
const gfx::Vector2d& target_offset,
bool anchor_point,
float page_scale,
base::TimeDelta duration) {
void LayerTreeHostImpl::StartPageScaleAnimation(const gfx::Point& target_offset,
bool anchor_point,
float page_scale,
base::TimeDelta duration) {
// Temporary crash logging for https://crbug.com/845097.
static bool has_dumped_without_crashing = false;
if (settings().is_layer_tree_for_subframe && !has_dumped_without_crashing) {
@ -968,7 +967,7 @@ void LayerTreeHostImpl::StartPageScaleAnimation(
if (!InnerViewportScrollNode())
return;
gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset();
gfx::PointF scroll_total = active_tree_->TotalScrollOffset();
gfx::SizeF scrollable_size = active_tree_->ScrollableSize();
gfx::SizeF viewport_size(
active_tree_->InnerViewportScrollNode()->container_bounds);
@ -979,11 +978,11 @@ void LayerTreeHostImpl::StartPageScaleAnimation(
scrollable_size);
if (anchor_point) {
gfx::Vector2dF anchor(target_offset);
gfx::PointF anchor(target_offset);
page_scale_animation_->ZoomWithAnchor(anchor, page_scale,
duration.InSecondsF());
} else {
gfx::Vector2dF scaled_target_offset = target_offset;
gfx::PointF scaled_target_offset(target_offset);
page_scale_animation_->ZoomTo(scaled_target_offset, page_scale,
duration.InSecondsF());
}
@ -2340,7 +2339,7 @@ RenderFrameMetadata LayerTreeHostImpl::MakeRenderFrameMetadata(
if (last_draw_render_frame_metadata_) {
const float last_root_scroll_offset_y =
last_draw_render_frame_metadata_->root_scroll_offset
.value_or(gfx::Vector2dF())
.value_or(gfx::PointF())
.y();
const float new_root_scroll_offset_y =
@ -3926,35 +3925,38 @@ float LayerTreeHostImpl::CurrentBottomControlsShownRatio() const {
return active_tree_->CurrentBottomControlsShownRatio();
}
gfx::Vector2dF LayerTreeHostImpl::ViewportScrollOffset() const {
gfx::PointF LayerTreeHostImpl::ViewportScrollOffset() const {
return viewport_->TotalScrollOffset();
}
bool LayerTreeHostImpl::AutoScrollAnimationCreate(const ScrollNode& scroll_node,
const gfx::Vector2dF& delta,
float autoscroll_velocity) {
return ScrollAnimationCreateInternal(scroll_node, delta, base::TimeDelta(),
autoscroll_velocity);
void LayerTreeHostImpl::AutoScrollAnimationCreate(
const ScrollNode& scroll_node,
const gfx::PointF& target_offset,
float autoscroll_velocity) {
// Start the animation one full frame in. Without any offset, the animation
// doesn't start until next frame, increasing latency, and preventing our
// input latency tracking architecture from working.
base::TimeDelta animation_start_offset = CurrentBeginFrameArgs().interval;
ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
gfx::PointF current_offset =
scroll_tree.current_scroll_offset(scroll_node.element_id);
mutator_host_->ImplOnlyAutoScrollAnimationCreate(
scroll_node.element_id, target_offset, current_offset,
autoscroll_velocity, animation_start_offset);
SetNeedsOneBeginImplFrame();
}
bool LayerTreeHostImpl::ScrollAnimationCreate(const ScrollNode& scroll_node,
const gfx::Vector2dF& delta,
base::TimeDelta delayed_by) {
return ScrollAnimationCreateInternal(scroll_node, delta, delayed_by,
absl::nullopt);
}
bool LayerTreeHostImpl::ScrollAnimationCreateInternal(
const ScrollNode& scroll_node,
const gfx::Vector2dF& delta,
base::TimeDelta delayed_by,
absl::optional<float> autoscroll_velocity) {
ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
const float kEpsilon = 0.1f;
bool scroll_animated =
(std::abs(delta.x()) > kEpsilon || std::abs(delta.y()) > kEpsilon) ||
autoscroll_velocity;
std::abs(delta.x()) > kEpsilon || std::abs(delta.y()) > kEpsilon;
if (!scroll_animated) {
scroll_tree.ScrollBy(scroll_node, delta, active_tree());
TRACE_EVENT_INSTANT0("cc", "no scroll animation due to small delta",
@ -3962,9 +3964,9 @@ bool LayerTreeHostImpl::ScrollAnimationCreateInternal(
return false;
}
gfx::Vector2dF current_offset =
gfx::PointF current_offset =
scroll_tree.current_scroll_offset(scroll_node.element_id);
gfx::Vector2dF target_offset = scroll_tree.ClampScrollOffsetToLimits(
gfx::PointF target_offset = scroll_tree.ClampScrollOffsetToLimits(
current_offset + delta, scroll_node);
// Start the animation one full frame in. Without any offset, the animation
@ -3972,15 +3974,9 @@ bool LayerTreeHostImpl::ScrollAnimationCreateInternal(
// input latency tracking architecture from working.
base::TimeDelta animation_start_offset = CurrentBeginFrameArgs().interval;
if (autoscroll_velocity) {
mutator_host_->ImplOnlyAutoScrollAnimationCreate(
scroll_node.element_id, delta, current_offset,
autoscroll_velocity.value(), animation_start_offset);
} else {
mutator_host_->ImplOnlyScrollAnimationCreate(
scroll_node.element_id, target_offset, current_offset, delayed_by,
animation_start_offset);
}
mutator_host_->ImplOnlyScrollAnimationCreate(
scroll_node.element_id, target_offset, current_offset, delayed_by,
animation_start_offset);
SetNeedsOneBeginImplFrame();
@ -4143,15 +4139,15 @@ bool LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) {
if (!page_scale_animation_)
return false;
gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset();
gfx::PointF scroll_total = active_tree_->TotalScrollOffset();
if (!page_scale_animation_->IsAnimationStarted())
page_scale_animation_->StartAnimation(monotonic_time);
active_tree_->SetPageScaleOnActiveTree(
page_scale_animation_->PageScaleFactorAtTime(monotonic_time));
gfx::Vector2dF next_scroll =
gfx::Vector2dF(page_scale_animation_->ScrollOffsetAtTime(monotonic_time));
gfx::PointF next_scroll =
page_scale_animation_->ScrollOffsetAtTime(monotonic_time);
viewport().ScrollByInnerFirst(next_scroll - scroll_total);
@ -4810,7 +4806,7 @@ void LayerTreeHostImpl::SetMutatorsNeedRebuildPropertyTrees() {}
void LayerTreeHostImpl::SetTreeLayerScrollOffsetMutated(
ElementId element_id,
LayerTreeImpl* tree,
const gfx::Vector2dF& scroll_offset) {
const gfx::PointF& scroll_offset) {
if (!tree)
return;
@ -4892,7 +4888,7 @@ void LayerTreeHostImpl::SetElementTransformMutated(
void LayerTreeHostImpl::SetElementScrollOffsetMutated(
ElementId element_id,
ElementListType list_type,
const gfx::Vector2dF& scroll_offset) {
const gfx::PointF& scroll_offset) {
if (list_type == ElementListType::ACTIVE) {
SetTreeLayerScrollOffsetMutated(element_id, active_tree(), scroll_offset);
ShowScrollbarsForImplScroll(element_id);
@ -4947,14 +4943,14 @@ void LayerTreeHostImpl::NotifyAnimationWorkletStateChange(
}
}
gfx::Vector2dF LayerTreeHostImpl::GetScrollOffsetForAnimation(
gfx::PointF LayerTreeHostImpl::GetScrollOffsetForAnimation(
ElementId element_id) const {
if (active_tree()) {
return active_tree()->property_trees()->scroll_tree.current_scroll_offset(
element_id);
}
return gfx::Vector2dF();
return gfx::PointF();
}
bool LayerTreeHostImpl::CommitToActiveTree() const {

@ -78,7 +78,7 @@
#include "ui/gfx/geometry/rect.h"
namespace gfx {
class Vector2dF;
class PointF;
}
namespace viz {
@ -290,7 +290,7 @@ class CC_EXPORT LayerTreeHostImpl : public TileManagerClient,
ThreadedInputHandler& GetInputHandler();
const ThreadedInputHandler& GetInputHandler() const;
void StartPageScaleAnimation(const gfx::Vector2d& target_offset,
void StartPageScaleAnimation(const gfx::Point& target_offset,
bool anchor_point,
float page_scale,
base::TimeDelta duration);
@ -311,7 +311,7 @@ class CC_EXPORT LayerTreeHostImpl : public TileManagerClient,
float bottom_ratio) override;
float CurrentTopControlsShownRatio() const override;
float CurrentBottomControlsShownRatio() const override;
gfx::Vector2dF ViewportScrollOffset() const override;
gfx::PointF ViewportScrollOffset() const override;
void DidChangeBrowserControlsPosition() override;
void DidObserveScrollDelay(base::TimeDelta scroll_delay,
base::TimeTicks scroll_timestamp);
@ -422,7 +422,7 @@ class CC_EXPORT LayerTreeHostImpl : public TileManagerClient,
void SetTreeLayerScrollOffsetMutated(ElementId element_id,
LayerTreeImpl* tree,
const gfx::Vector2dF& scroll_offset);
const gfx::PointF& scroll_offset);
void SetNeedUpdateGpuRasterizationStatus();
bool NeedUpdateGpuRasterizationStatusForTesting() const {
return need_update_gpu_rasterization_status_;
@ -446,10 +446,9 @@ class CC_EXPORT LayerTreeHostImpl : public TileManagerClient,
void SetElementTransformMutated(ElementId element_id,
ElementListType list_type,
const gfx::Transform& transform) override;
void SetElementScrollOffsetMutated(
ElementId element_id,
ElementListType list_type,
const gfx::Vector2dF& scroll_offset) override;
void SetElementScrollOffsetMutated(ElementId element_id,
ElementListType list_type,
const gfx::PointF& scroll_offset) override;
void ElementIsAnimatingChanged(const PropertyToElementIdMap& element_id_map,
ElementListType list_type,
const PropertyAnimationState& mask,
@ -462,8 +461,7 @@ class CC_EXPORT LayerTreeHostImpl : public TileManagerClient,
PaintWorkletInput::PropertyValue property_value) override;
void ScrollOffsetAnimationFinished() override;
gfx::Vector2dF GetScrollOffsetForAnimation(
ElementId element_id) const override;
gfx::PointF GetScrollOffsetForAnimation(ElementId element_id) const override;
void NotifyAnimationWorkletStateChange(AnimationWorkletMutationState state,
ElementListType tree_type) override;
@ -800,8 +798,8 @@ class CC_EXPORT LayerTreeHostImpl : public TileManagerClient,
bool ScrollAnimationCreate(const ScrollNode& scroll_node,
const gfx::Vector2dF& scroll_amount,
base::TimeDelta delayed_by);
bool AutoScrollAnimationCreate(const ScrollNode& scroll_node,
const gfx::Vector2dF& scroll_amount,
void AutoScrollAnimationCreate(const ScrollNode& scroll_node,
const gfx::PointF& target_offset,
float autoscroll_velocity);
void SetLayerTreeMutator(std::unique_ptr<LayerTreeMutator> mutator);
@ -922,10 +920,6 @@ class CC_EXPORT LayerTreeHostImpl : public TileManagerClient,
private:
void CollectScrollbarUpdatesForCommit(
CompositorCommitData* commit_data) const;
bool ScrollAnimationCreateInternal(const ScrollNode& scroll_node,
const gfx::Vector2dF& delta,
base::TimeDelta delayed_by,
absl::optional<float> autoscroll_velocity);
void CleanUpTileManagerResources();
void CreateTileManagerResources();

File diff suppressed because it is too large Load Diff

@ -3505,7 +3505,7 @@ class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest {
scroll_layer_->SetBounds(gfx::Size(2 * root_layer->bounds().width(),
2 * root_layer->bounds().height()));
scroll_layer_->SetScrollOffset(gfx::Vector2dF());
scroll_layer_->SetScrollOffset(gfx::PointF());
SetupViewport(root_layer, scroll_layer_, root_layer->bounds());
@ -3516,7 +3516,7 @@ class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest {
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void ApplyViewportChanges(const ApplyViewportChangesArgs& args) override {
gfx::Vector2dF offset = CurrentScrollOffset(scroll_layer_.get());
gfx::PointF offset = CurrentScrollOffset(scroll_layer_.get());
SetScrollOffset(scroll_layer_.get(), offset + args.inner_delta);
layer_tree_host()->SetPageScaleFactorAndLimits(args.page_scale_delta, 0.5f,
2.f);
@ -3548,8 +3548,8 @@ class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest {
void DidCommitAndDrawFrame() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
layer_tree_host()->StartPageScaleAnimation(gfx::Vector2d(), false,
1.25f, base::TimeDelta());
layer_tree_host()->StartPageScaleAnimation(gfx::Point(), false, 1.25f,
base::TimeDelta());
break;
}
}
@ -3597,12 +3597,12 @@ class ViewportDeltasAppliedDuringPinch : public LayerTreeHostTest,
auto* scroll_layer =
layer_tree_host()->InnerViewportScrollLayerForTesting();
EXPECT_EQ(scroll_layer->element_id(), last_scrolled_element_id_);
EXPECT_EQ(gfx::Vector2dF(50, 50), last_scrolled_offset_);
EXPECT_EQ(gfx::PointF(50, 50), last_scrolled_offset_);
// The scroll offset in the scroll tree is typically updated from blink
// which doesn't exist in this test. Because we preemptively apply the
// scroll offset in LayerTreeHost::UpdateScrollOffsetFromImpl, the current
// scroll offset will still be updated.
EXPECT_EQ(gfx::Vector2dF(50, 50), CurrentScrollOffset(scroll_layer));
EXPECT_EQ(gfx::PointF(50, 50), CurrentScrollOffset(scroll_layer));
EndTest();
}
@ -3610,7 +3610,7 @@ class ViewportDeltasAppliedDuringPinch : public LayerTreeHostTest,
// ScrollCallbacks
void DidCompositorScroll(ElementId element_id,
const gfx::Vector2dF& scroll_offset,
const gfx::PointF& scroll_offset,
const absl::optional<TargetSnapAreaElementIds>&
snap_target_ids) override {
last_scrolled_element_id_ = element_id;
@ -3621,7 +3621,7 @@ class ViewportDeltasAppliedDuringPinch : public LayerTreeHostTest,
private:
bool sent_gesture_;
ElementId last_scrolled_element_id_;
gfx::Vector2dF last_scrolled_offset_;
gfx::PointF last_scrolled_offset_;
base::WeakPtrFactory<ViewportDeltasAppliedDuringPinch> weak_ptr_factory_{
this};
};

@ -780,7 +780,7 @@ class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated
scroll_layer_->SetScrollable(gfx::Size(100, 100));
scroll_layer_->SetBounds(gfx::Size(1000, 1000));
client_.set_bounds(scroll_layer_->bounds());
scroll_layer_->SetScrollOffset(gfx::Vector2dF(10, 20));
scroll_layer_->SetScrollOffset(gfx::PointF(10, 20));
layer_tree_host()->root_layer()->AddChild(scroll_layer_);
AttachAnimationsToTimeline();
@ -794,8 +794,7 @@ class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated
case 1: {
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::
CreateEaseInOutAnimationForTesting(
gfx::Vector2dF(500.f, 550.f)));
CreateEaseInOutAnimationForTesting(gfx::PointF(500.f, 550.f)));
std::unique_ptr<KeyframeModel> keyframe_model(KeyframeModel::Create(
std::move(curve), 1, 0,
KeyframeModel::TargetPropertyId(TargetProperty::SCROLL_OFFSET)));
@ -833,7 +832,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationTakeover
scroll_layer_ = FakePictureLayer::Create(&client_);
scroll_layer_->SetBounds(gfx::Size(10000, 10000));
client_.set_bounds(scroll_layer_->bounds());
scroll_layer_->SetScrollOffset(gfx::Vector2dF(10, 20));
scroll_layer_->SetScrollOffset(gfx::PointF(10, 20));
scroll_layer_->SetScrollable(gfx::Size(10, 10));
layer_tree_host()->root_layer()->AddChild(scroll_layer_);
@ -859,8 +858,8 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationTakeover
void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->sync_tree()->source_frame_number() == 0) {
GetImplAnimationHost(host_impl)->ImplOnlyScrollAnimationCreate(
scroll_layer_->element_id(), gfx::Vector2dF(650.f, 750.f),
gfx::Vector2dF(10, 20), base::TimeDelta(), base::TimeDelta());
scroll_layer_->element_id(), gfx::PointF(650.f, 750.f),
gfx::PointF(10, 20), base::TimeDelta(), base::TimeDelta());
}
}
@ -894,7 +893,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted
scroll_layer_ = FakePictureLayer::Create(&client_);
scroll_layer_->SetBounds(gfx::Size(10000, 10000));
client_.set_bounds(scroll_layer_->bounds());
scroll_layer_->SetScrollOffset(gfx::Vector2dF(10, 20));
scroll_layer_->SetScrollOffset(gfx::PointF(10, 20));
scroll_layer_->SetScrollable(gfx::Size(10, 10));
layer_tree_host()->root_layer()->AddChild(scroll_layer_);
@ -948,16 +947,16 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted
// Verifiy the initial and target position before the scroll offset
// update from MT.
EXPECT_EQ(gfx::Vector2dF(10.f, 20.f), curve->GetValue(base::TimeDelta()));
EXPECT_EQ(gfx::Vector2dF(650.f, 750.f), curve->target_value());
EXPECT_EQ(gfx::PointF(10.f, 20.f), curve->GetValue(base::TimeDelta()));
EXPECT_EQ(gfx::PointF(650.f, 750.f), curve->target_value());
}
}
void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->sync_tree()->source_frame_number() == 0) {
GetImplAnimationHost(host_impl)->ImplOnlyScrollAnimationCreate(
scroll_layer_->element_id(), gfx::Vector2dF(650.f, 750.f),
gfx::Vector2dF(10, 20), base::TimeDelta(), base::TimeDelta());
scroll_layer_->element_id(), gfx::PointF(650.f, 750.f),
gfx::PointF(10, 20), base::TimeDelta(), base::TimeDelta());
}
}
@ -973,9 +972,8 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted
// Verifiy the initial and target position after the scroll offset
// update from MT
EXPECT_EQ(KeyframeModel::RunState::STARTING, keyframe_model->run_state());
EXPECT_EQ(gfx::Vector2dF(110.f, 120.f),
curve->GetValue(base::TimeDelta()));
EXPECT_EQ(gfx::Vector2dF(750.f, 850.f), curve->target_value());
EXPECT_EQ(gfx::PointF(110.f, 120.f), curve->GetValue(base::TimeDelta()));
EXPECT_EQ(gfx::PointF(750.f, 850.f), curve->target_value());
EndTest();
}
@ -1001,12 +999,12 @@ class LayerTreeHostPresentationDuringAnimation
scroll_layer_->SetScrollable(gfx::Size(100, 100));
scroll_layer_->SetBounds(gfx::Size(10000, 10000));
client_.set_bounds(scroll_layer_->bounds());
scroll_layer_->SetScrollOffset(gfx::Vector2dF(100.0, 200.0));
scroll_layer_->SetScrollOffset(gfx::PointF(100.0, 200.0));
layer_tree_host()->root_layer()->AddChild(scroll_layer_);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
gfx::Vector2dF(6500.f, 7500.f)));
gfx::PointF(6500.f, 7500.f)));
std::unique_ptr<KeyframeModel> keyframe_model(KeyframeModel::Create(
std::move(curve), 1, 0,
KeyframeModel::TargetPropertyId(TargetProperty::SCROLL_OFFSET)));
@ -1092,12 +1090,12 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval
scroll_layer_->SetScrollable(gfx::Size(100, 100));
scroll_layer_->SetBounds(gfx::Size(10000, 10000));
client_.set_bounds(scroll_layer_->bounds());
scroll_layer_->SetScrollOffset(gfx::Vector2dF(100.0, 200.0));
scroll_layer_->SetScrollOffset(gfx::PointF(100.0, 200.0));
layer_tree_host()->root_layer()->AddChild(scroll_layer_);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
gfx::Vector2dF(6500.f, 7500.f)));
gfx::PointF(6500.f, 7500.f)));
std::unique_ptr<KeyframeModel> keyframe_model(KeyframeModel::Create(
std::move(curve), 1, 0,
KeyframeModel::TargetPropertyId(TargetProperty::SCROLL_OFFSET)));
@ -1196,7 +1194,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> scroll_layer_;
const gfx::Vector2dF final_postion_;
const gfx::PointF final_postion_;
};
MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationRemoval);
@ -1219,7 +1217,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationCompletion
scroll_layer_->SetScrollable(gfx::Size(100, 100));
scroll_layer_->SetBounds(gfx::Size(10000, 10000));
client_.set_bounds(scroll_layer_->bounds());
scroll_layer_->SetScrollOffset(gfx::Vector2dF(100.0, 200.0));
scroll_layer_->SetScrollOffset(gfx::PointF(100.0, 200.0));
layer_tree_host()->root_layer()->AddChild(scroll_layer_);
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
@ -1297,7 +1295,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationCompletion
private:
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> scroll_layer_;
const gfx::Vector2dF final_position_;
const gfx::PointF final_position_;
bool ran_animation_ = false;
};
@ -2176,13 +2174,13 @@ class ImplSideInvalidationWithoutCommitTestScroll
layer_->SetScrollable(gfx::Size(100, 100));
layer_->SetBounds(gfx::Size(1000, 1000));
client_.set_bounds(layer_->bounds());
layer_->SetScrollOffset(gfx::Vector2dF(10.f, 20.f));
layer_->SetScrollOffset(gfx::PointF(10.f, 20.f));
}
void BeginTest() override {
std::unique_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurveFactory::CreateEaseInOutAnimationForTesting(
gfx::Vector2dF(500.f, 550.f)));
gfx::PointF(500.f, 550.f)));
std::unique_ptr<KeyframeModel> keyframe_model(KeyframeModel::Create(
std::move(curve), 1, 0,
KeyframeModel::TargetPropertyId(TargetProperty::SCROLL_OFFSET)));
@ -2196,14 +2194,14 @@ class ImplSideInvalidationWithoutCommitTestScroll
return;
EXPECT_EQ(0, host_impl->active_tree()->source_frame_number());
LayerImpl* layer_impl = host_impl->active_tree()->LayerById(layer_->id());
EXPECT_EQ(gfx::Vector2dF(10.f, 20.f), CurrentScrollOffset(layer_impl));
EXPECT_EQ(gfx::PointF(10.f, 20.f), CurrentScrollOffset(layer_impl));
}
void DidInvalidateContentOnImplSide(LayerTreeHostImpl* host_impl) override {
ASSERT_TRUE(did_request_impl_side_invalidation_);
EXPECT_EQ(0, host_impl->sync_tree()->source_frame_number());
LayerImpl* layer_impl = host_impl->pending_tree()->LayerById(layer_->id());
EXPECT_EQ(gfx::Vector2dF(500.f, 550.f), CurrentScrollOffset(layer_impl));
EXPECT_EQ(gfx::PointF(500.f, 550.f), CurrentScrollOffset(layer_impl));
LayerTreeHostAnimationTestImplSideInvalidationWithoutCommit::
DidInvalidateContentOnImplSide(host_impl);
}

@ -341,7 +341,7 @@ class LayerTreeHostScrollbarDamageTest : public LayerTreeHostDamageTest {
// The size of the container in which scrolling contents are visible need
// to be smaller than the bounds of the layer itself.
content_layer_->SetScrollable(gfx::Size(80, 180));
content_layer_->SetScrollOffset(gfx::Vector2dF(10, 20));
content_layer_->SetScrollOffset(gfx::PointF(10, 20));
content_layer_->SetBounds(gfx::Size(100, 200));
content_layer_->SetIsDrawable(true);
root_layer->AddChild(content_layer_);

@ -68,7 +68,7 @@ class LayerTreeTestMaskLayerForSurfaceWithContentRectNotAtOrigin
scroll_layer->AddChild(content_layer);
client_.set_bounds(root->bounds());
scroll_layer->SetScrollOffset(gfx::Vector2dF(50, 50));
scroll_layer->SetScrollOffset(gfx::PointF(50, 50));
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
@ -132,7 +132,7 @@ class LayerTreeTestMaskLayerForSurfaceWithContentRectNotAtOriginWithLayerList
SetupViewport(root, gfx::Size(50, 50), layer_size);
auto* scroll = layer_tree_host()->OuterViewportScrollLayerForTesting();
SetScrollOffset(scroll, gfx::Vector2dF(50, 50));
SetScrollOffset(scroll, gfx::PointF(50, 50));
client_.set_bounds(root->bounds());
auto content_layer = FakePictureLayer::Create(&client_);

@ -89,7 +89,7 @@ class LayerTreeHostScrollTest : public LayerTreeTest, public ScrollCallbacks {
// ScrollCallbacks
void DidCompositorScroll(ElementId element_id,
const gfx::Vector2dF& scroll_offset,
const gfx::PointF& scroll_offset,
const absl::optional<TargetSnapAreaElementIds>&
snap_target_ids) override {
// Simulates cc client (e.g Blink) behavior when handling impl-side scrolls.
@ -111,7 +111,7 @@ class LayerTreeHostScrollTest : public LayerTreeTest, public ScrollCallbacks {
}
void DidChangeScrollbarsHidden(ElementId, bool) override {}
virtual void DidScrollOuterViewport(const gfx::Vector2dF& scroll_offset) {
virtual void DidScrollOuterViewport(const gfx::PointF& scroll_offset) {
num_outer_viewport_scrolls_++;
}
@ -136,11 +136,11 @@ class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest {
Layer* scroll_layer =
layer_tree_host()->OuterViewportScrollLayerForTesting();
if (!layer_tree_host()->SourceFrameNumber()) {
EXPECT_VECTOR2DF_EQ(initial_scroll_,
GetTransformNode(scroll_layer)->scroll_offset);
EXPECT_POINTF_EQ(initial_scroll_,
GetTransformNode(scroll_layer)->scroll_offset);
} else {
EXPECT_VECTOR2DF_EQ(initial_scroll_ + scroll_amount_,
GetTransformNode(scroll_layer)->scroll_offset);
EXPECT_POINTF_EQ(initial_scroll_ + scroll_amount_,
GetTransformNode(scroll_layer)->scroll_offset);
// Pretend like Javascript updated the scroll position itself.
SetScrollOffset(scroll_layer, second_scroll_);
@ -159,12 +159,12 @@ class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest {
switch (impl->active_tree()->source_frame_number()) {
case 0:
EXPECT_VECTOR2DF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(scroll_amount_, ScrollDelta(scroll_layer));
PostSetNeedsCommitToMainThread();
break;
case 1:
EXPECT_VECTOR2DF_EQ(second_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(second_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(scroll_amount_, ScrollDelta(scroll_layer));
EndTest();
break;
@ -174,8 +174,8 @@ class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest {
void AfterTest() override { EXPECT_EQ(1, num_outer_viewport_scrolls_); }
private:
gfx::Vector2dF initial_scroll_;
gfx::Vector2dF second_scroll_;
gfx::PointF initial_scroll_;
gfx::PointF second_scroll_;
gfx::Vector2dF scroll_amount_;
};
@ -196,13 +196,13 @@ class LayerTreeHostScrollTestScrollMultipleRedraw
void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
switch (impl->sync_tree()->source_frame_number()) {
case 0:
EXPECT_VECTOR2DF_EQ(initial_scroll_,
CurrentScrollOffset(scroll_layer_.get()));
EXPECT_POINTF_EQ(initial_scroll_,
CurrentScrollOffset(scroll_layer_.get()));
break;
case 1:
case 2:
EXPECT_VECTOR2DF_EQ(initial_scroll_ + scroll_amount_ + scroll_amount_,
CurrentScrollOffset(scroll_layer_.get()));
EXPECT_POINTF_EQ(initial_scroll_ + scroll_amount_ + scroll_amount_,
CurrentScrollOffset(scroll_layer_.get()));
break;
}
}
@ -217,7 +217,7 @@ class LayerTreeHostScrollTestScrollMultipleRedraw
scroll_layer->ScrollBy(scroll_amount_);
EXPECT_VECTOR2DF_EQ(scroll_amount_, ScrollDelta(scroll_layer));
EXPECT_VECTOR2DF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
PostSetNeedsRedrawToMainThread();
} else if (impl->active_tree()->source_frame_number() == 0 &&
impl->SourceAnimationFrameNumberForTesting() == 2) {
@ -227,14 +227,14 @@ class LayerTreeHostScrollTestScrollMultipleRedraw
EXPECT_VECTOR2DF_EQ(scroll_amount_ + scroll_amount_,
ScrollDelta(scroll_layer));
EXPECT_VECTOR2DF_EQ(initial_scroll_,
CurrentScrollOffset(scroll_layer_.get()));
EXPECT_POINTF_EQ(initial_scroll_,
CurrentScrollOffset(scroll_layer_.get()));
PostSetNeedsCommitToMainThread();
} else if (impl->active_tree()->source_frame_number() == 1) {
// Third or later draw after second commit.
EXPECT_GE(impl->SourceAnimationFrameNumberForTesting(), 3u);
EXPECT_VECTOR2DF_EQ(initial_scroll_ + scroll_amount_ + scroll_amount_,
CurrentScrollOffset(scroll_layer_.get()));
EXPECT_POINTF_EQ(initial_scroll_ + scroll_amount_ + scroll_amount_,
CurrentScrollOffset(scroll_layer_.get()));
EndTest();
}
}
@ -242,7 +242,7 @@ class LayerTreeHostScrollTestScrollMultipleRedraw
void AfterTest() override { EXPECT_EQ(1, num_outer_viewport_scrolls_); }
private:
gfx::Vector2dF initial_scroll_;
gfx::PointF initial_scroll_;
gfx::Vector2dF scroll_amount_;
scoped_refptr<Layer> scroll_layer_;
};
@ -287,8 +287,8 @@ class LayerTreeHostScrollTestScrollAbortedCommit
// This will not be aborted because of the initial prop changes.
EXPECT_EQ(0, num_outer_viewport_scrolls_);
EXPECT_EQ(0, layer_tree_host()->SourceFrameNumber());
EXPECT_VECTOR2DF_EQ(initial_scroll_,
CurrentScrollOffset(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_,
CurrentScrollOffset(root_scroll_layer));
EXPECT_EQ(1.f, layer_tree_host()->page_scale_factor());
break;
case 2:
@ -296,8 +296,8 @@ class LayerTreeHostScrollTestScrollAbortedCommit
// initiated from the redraw.
EXPECT_EQ(1, num_outer_viewport_scrolls_);
EXPECT_EQ(1, layer_tree_host()->SourceFrameNumber());
EXPECT_VECTOR2DF_EQ(initial_scroll_ + impl_scroll_,
CurrentScrollOffset(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + impl_scroll_,
CurrentScrollOffset(root_scroll_layer));
EXPECT_EQ(impl_scale_, layer_tree_host()->page_scale_factor());
PostSetNeedsRedrawToMainThread();
break;
@ -306,8 +306,8 @@ class LayerTreeHostScrollTestScrollAbortedCommit
EXPECT_EQ(2, num_outer_viewport_scrolls_);
// The source frame number still increases even with the abort.
EXPECT_EQ(2, layer_tree_host()->SourceFrameNumber());
EXPECT_VECTOR2DF_EQ(initial_scroll_ + impl_scroll_ + impl_scroll_,
CurrentScrollOffset(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + impl_scroll_ + impl_scroll_,
CurrentScrollOffset(root_scroll_layer));
EXPECT_EQ(impl_scale_ * impl_scale_,
layer_tree_host()->page_scale_factor());
SetScrollOffset(
@ -320,8 +320,8 @@ class LayerTreeHostScrollTestScrollAbortedCommit
EXPECT_EQ(3, layer_tree_host()->SourceFrameNumber());
gfx::Vector2dF delta =
impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_;
EXPECT_VECTOR2DF_EQ(initial_scroll_ + delta,
CurrentScrollOffset(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + delta,
CurrentScrollOffset(root_scroll_layer));
// End the test by drawing to verify this commit is also aborted.
PostSetNeedsRedrawToMainThread();
@ -349,7 +349,7 @@ class LayerTreeHostScrollTestScrollAbortedCommit
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(root_scroll_layer));
root_scroll_layer->ScrollBy(impl_scroll_);
EXPECT_VECTOR2DF_EQ(impl_scroll_, ScrollDelta(root_scroll_layer));
EXPECT_VECTOR2DF_EQ(initial_scroll_, ScrollOffsetBase(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_, ScrollOffsetBase(root_scroll_layer));
EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor());
@ -367,8 +367,8 @@ class LayerTreeHostScrollTestScrollAbortedCommit
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(root_scroll_layer));
root_scroll_layer->ScrollBy(impl_scroll_);
EXPECT_VECTOR2DF_EQ(impl_scroll_, ScrollDelta(root_scroll_layer));
EXPECT_VECTOR2DF_EQ(initial_scroll_ + impl_scroll_,
ScrollOffsetBase(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + impl_scroll_,
ScrollOffsetBase(root_scroll_layer));
EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
EXPECT_EQ(impl_scale_, impl->active_tree()->current_page_scale_factor());
@ -389,16 +389,16 @@ class LayerTreeHostScrollTestScrollAbortedCommit
impl->SetNeedsCommit();
EXPECT_VECTOR2DF_EQ(impl_scroll_, ScrollDelta(root_scroll_layer));
gfx::Vector2dF delta = impl_scroll_ + impl_scroll_ + second_main_scroll_;
EXPECT_VECTOR2DF_EQ(initial_scroll_ + delta,
ScrollOffsetBase(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + delta,
ScrollOffsetBase(root_scroll_layer));
} else if (impl->active_tree()->source_frame_number() == 2 &&
impl->SourceAnimationFrameNumberForTesting() == 4) {
// Final draw after the second aborted commit.
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(root_scroll_layer));
gfx::Vector2dF delta =
impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_;
EXPECT_VECTOR2DF_EQ(initial_scroll_ + delta,
ScrollOffsetBase(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + delta,
ScrollOffsetBase(root_scroll_layer));
EndTest();
} else {
// Commit for source frame 3 is aborted.
@ -418,7 +418,7 @@ class LayerTreeHostScrollTestScrollAbortedCommit
}
private:
gfx::Vector2dF initial_scroll_;
gfx::PointF initial_scroll_;
gfx::Vector2dF impl_scroll_;
gfx::Vector2dF second_main_scroll_;
float impl_scale_;
@ -450,23 +450,22 @@ class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest {
// multiple commits.
switch (impl->active_tree()->source_frame_number()) {
case 0:
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(gfx::PointF(), ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(scroll_layer));
PostSetNeedsCommitToMainThread();
break;
case 1:
EXPECT_VECTOR2DF_EQ(
gfx::Vector2dF(gfx::ToRoundedVector2d(scroll_amount_)),
ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(gfx::ToRoundedVector2d(scroll_amount_),
ScrollOffsetBase(scroll_layer).OffsetFromOrigin());
EXPECT_VECTOR2DF_EQ(
scroll_amount_ - gfx::ToRoundedVector2d(scroll_amount_),
ScrollDelta(scroll_layer));
PostSetNeedsCommitToMainThread();
break;
case 2:
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(gfx::ToRoundedVector2d(
scroll_amount_ + scroll_amount_)),
ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(
gfx::ToRoundedVector2d(scroll_amount_ + scroll_amount_),
ScrollOffsetBase(scroll_layer).OffsetFromOrigin());
EXPECT_VECTOR2DF_EQ(
scroll_amount_ + scroll_amount_ -
gfx::ToRoundedVector2d(scroll_amount_ + scroll_amount_),
@ -617,7 +616,7 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest {
}
void DidCompositorScroll(ElementId element_id,
const gfx::Vector2dF& offset,
const gfx::PointF& offset,
const absl::optional<TargetSnapAreaElementIds>&
snap_target_ids) override {
LayerTreeHostScrollTest::DidCompositorScroll(element_id, offset,
@ -627,29 +626,29 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest {
EXPECT_EQ(offset, final_scroll_offset_);
EXPECT_EQ(element_id, expected_scroll_layer_->element_id());
} else {
EXPECT_TRUE(offset.IsZero());
EXPECT_TRUE(offset.IsOrigin());
}
}
void UpdateLayerTreeHost() override {
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(),
CurrentScrollOffset(expected_no_scroll_layer_));
EXPECT_POINTF_EQ(gfx::PointF(),
CurrentScrollOffset(expected_no_scroll_layer_));
switch (layer_tree_host()->SourceFrameNumber()) {
case 0:
EXPECT_VECTOR2DF_EQ(initial_offset_,
CurrentScrollOffset(expected_scroll_layer_));
EXPECT_POINTF_EQ(initial_offset_,
CurrentScrollOffset(expected_scroll_layer_));
break;
case 1:
EXPECT_VECTOR2DF_EQ(initial_offset_ + scroll_amount_,
CurrentScrollOffset(expected_scroll_layer_));
EXPECT_POINTF_EQ(initial_offset_ + scroll_amount_,
CurrentScrollOffset(expected_scroll_layer_));
// Pretend like Javascript updated the scroll position itself.
SetScrollOffset(expected_scroll_layer_, javascript_scroll_);
break;
case 2:
EXPECT_VECTOR2DF_EQ(javascript_scroll_ + scroll_amount_,
CurrentScrollOffset(expected_scroll_layer_));
EXPECT_POINTF_EQ(javascript_scroll_ + scroll_amount_,
CurrentScrollOffset(expected_scroll_layer_));
break;
}
}
@ -700,8 +699,8 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest {
impl->active_tree()->LastScrolledScrollNodeIndex());
// Check the scroll is applied as a delta.
EXPECT_VECTOR2DF_EQ(initial_offset_,
ScrollOffsetBase(expected_scroll_layer_impl));
EXPECT_POINTF_EQ(initial_offset_,
ScrollOffsetBase(expected_scroll_layer_impl));
EXPECT_VECTOR2DF_EQ(scroll_amount_,
ScrollDelta(expected_scroll_layer_impl));
break;
@ -720,16 +719,16 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest {
impl->GetInputHandler().ScrollEnd();
// Check the scroll is applied as a delta.
EXPECT_VECTOR2DF_EQ(javascript_scroll_,
ScrollOffsetBase(expected_scroll_layer_impl));
EXPECT_POINTF_EQ(javascript_scroll_,
ScrollOffsetBase(expected_scroll_layer_impl));
EXPECT_VECTOR2DF_EQ(scroll_amount_,
ScrollDelta(expected_scroll_layer_impl));
break;
}
case 2:
EXPECT_VECTOR2DF_EQ(javascript_scroll_ + scroll_amount_,
ScrollOffsetBase(expected_scroll_layer_impl));
EXPECT_POINTF_EQ(javascript_scroll_ + scroll_amount_,
ScrollOffsetBase(expected_scroll_layer_impl));
EXPECT_VECTOR2DF_EQ(gfx::Vector2d(),
ScrollDelta(expected_scroll_layer_impl));
@ -740,18 +739,17 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest {
void AfterTest() override {
EXPECT_EQ(scroll_child_layer_ ? 0 : 2, num_outer_viewport_scrolls_);
EXPECT_VECTOR2DF_EQ(javascript_scroll_ + scroll_amount_,
final_scroll_offset_);
EXPECT_POINTF_EQ(javascript_scroll_ + scroll_amount_, final_scroll_offset_);
}
protected:
float device_scale_factor_;
bool scroll_child_layer_;
gfx::Vector2dF initial_offset_;
gfx::Vector2dF javascript_scroll_;
gfx::PointF initial_offset_;
gfx::PointF javascript_scroll_;
gfx::Vector2d scroll_amount_;
gfx::Vector2dF final_scroll_offset_;
gfx::PointF final_scroll_offset_;
scoped_refptr<Layer> child_layer_;
Layer* expected_scroll_layer_;
@ -820,10 +818,10 @@ class LayerTreeHostScrollTestSimple : public LayerTreeHostScrollTest {
Layer* scroll_layer =
layer_tree_host()->OuterViewportScrollLayerForTesting();
if (!layer_tree_host()->SourceFrameNumber()) {
EXPECT_VECTOR2DF_EQ(initial_scroll_, CurrentScrollOffset(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_, CurrentScrollOffset(scroll_layer));
} else {
EXPECT_VECTOR2DF_EQ(CurrentScrollOffset(scroll_layer),
initial_scroll_ + impl_thread_scroll1_);
EXPECT_POINTF_EQ(CurrentScrollOffset(scroll_layer),
initial_scroll_ + impl_thread_scroll1_);
// Pretend like Javascript updated the scroll position itself with a
// change of main_thread_scroll.
@ -856,7 +854,7 @@ class LayerTreeHostScrollTestSimple : public LayerTreeHostScrollTest {
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(scroll_layer));
scroll_layer->ScrollBy(impl_thread_scroll1_);
EXPECT_VECTOR2DF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(impl_thread_scroll1_, ScrollDelta(scroll_layer));
PostSetNeedsCommitToMainThread();
@ -868,13 +866,13 @@ class LayerTreeHostScrollTestSimple : public LayerTreeHostScrollTest {
EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1);
scroll_layer->ScrollBy(impl_thread_scroll2_);
EXPECT_VECTOR2DF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(impl_thread_scroll1_ + impl_thread_scroll2_,
ScrollDelta(scroll_layer));
LayerImpl* pending_scroll_layer =
impl->pending_tree()->OuterViewportScrollLayerForTesting();
EXPECT_VECTOR2DF_EQ(
EXPECT_POINTF_EQ(
initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_,
ScrollOffsetBase(pending_scroll_layer));
EXPECT_VECTOR2DF_EQ(impl_thread_scroll2_,
@ -883,7 +881,7 @@ class LayerTreeHostScrollTestSimple : public LayerTreeHostScrollTest {
break;
case 1:
EXPECT_FALSE(impl->pending_tree());
EXPECT_VECTOR2DF_EQ(
EXPECT_POINTF_EQ(
initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_,
ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(impl_thread_scroll2_, ScrollDelta(scroll_layer));
@ -895,7 +893,7 @@ class LayerTreeHostScrollTestSimple : public LayerTreeHostScrollTest {
void AfterTest() override { EXPECT_EQ(1, num_outer_viewport_scrolls_); }
private:
gfx::Vector2dF initial_scroll_;
gfx::PointF initial_scroll_;
gfx::Vector2dF main_thread_scroll_;
gfx::Vector2dF impl_thread_scroll1_;
gfx::Vector2dF impl_thread_scroll2_;
@ -970,8 +968,8 @@ class LayerTreeHostScrollTestImplOnlyScroll : public LayerTreeHostScrollTest {
ASSERT_TRUE(pending_scroll_layer);
switch (impl->pending_tree()->source_frame_number()) {
case 0:
EXPECT_VECTOR2DF_EQ(initial_scroll_,
ScrollOffsetBase(pending_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_,
ScrollOffsetBase(pending_scroll_layer));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(),
ScrollDelta(pending_scroll_layer));
EXPECT_FALSE(active_root);
@ -979,20 +977,20 @@ class LayerTreeHostScrollTestImplOnlyScroll : public LayerTreeHostScrollTest {
case 1:
// Even though the scroll happened during the commit, both layers
// should have the appropriate scroll delta.
EXPECT_VECTOR2DF_EQ(initial_scroll_,
ScrollOffsetBase(pending_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_,
ScrollOffsetBase(pending_scroll_layer));
EXPECT_VECTOR2DF_EQ(impl_thread_scroll_,
ScrollDelta(pending_scroll_layer));
ASSERT_TRUE(active_root);
EXPECT_VECTOR2DF_EQ(initial_scroll_,
ScrollOffsetBase(active_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_,
ScrollOffsetBase(active_scroll_layer));
EXPECT_VECTOR2DF_EQ(impl_thread_scroll_,
ScrollDelta(active_scroll_layer));
break;
case 2:
// On the next commit, this delta should have been sent and applied.
EXPECT_VECTOR2DF_EQ(initial_scroll_ + impl_thread_scroll_,
ScrollOffsetBase(pending_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + impl_thread_scroll_,
ScrollOffsetBase(pending_scroll_layer));
EXPECT_VECTOR2DF_EQ(gfx::Vector2d(), ScrollDelta(pending_scroll_layer));
break;
}
@ -1004,9 +1002,9 @@ class LayerTreeHostScrollTestImplOnlyScroll : public LayerTreeHostScrollTest {
LayerImpl* scroll_layer =
impl->pending_tree()->OuterViewportScrollLayerForTesting();
gfx::Vector2dF scroll_offset = CurrentScrollOffset(scroll_layer);
gfx::PointF scroll_offset = CurrentScrollOffset(scroll_layer);
int transform_index = scroll_layer->transform_tree_index();
gfx::Vector2dF transform_tree_scroll_offset =
gfx::PointF transform_tree_scroll_offset =
impl->pending_tree()
->property_trees()
->transform_tree.Node(transform_index)
@ -1023,14 +1021,14 @@ class LayerTreeHostScrollTestImplOnlyScroll : public LayerTreeHostScrollTest {
switch (impl->active_tree()->source_frame_number()) {
case 0:
EXPECT_VECTOR2DF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(scroll_layer));
EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor());
PostSetNeedsCommitToMainThread();
break;
case 1:
EXPECT_VECTOR2DF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(impl_thread_scroll_, ScrollDelta(scroll_layer));
EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta());
EXPECT_EQ(impl_scale_,
@ -1047,7 +1045,7 @@ class LayerTreeHostScrollTestImplOnlyScroll : public LayerTreeHostScrollTest {
}
private:
gfx::Vector2dF initial_scroll_;
gfx::PointF initial_scroll_;
gfx::Vector2dF impl_thread_scroll_;
float impl_scale_;
};
@ -1232,7 +1230,7 @@ class LayerTreeHostScrollTestImplOnlyScrollSnap
// Set up snap container data.
SnapContainerData snap_container_data(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 100, 100), gfx::Vector2dF(900, 900));
gfx::RectF(0, 0, 100, 100), gfx::PointF(900, 900));
snap_container_data.AddSnapAreaData(snap_area_data);
CreateScrollNode(scroller_.get(), container_->bounds())
.snap_container_data = snap_container_data;
@ -1277,8 +1275,7 @@ class LayerTreeHostScrollTestImplOnlyScrollSnap
// On the first BeginMainFrame scrolling has not happened yet.
// Check that the scroll offset and scroll snap targets are at the initial
// values on the main thread.
EXPECT_VECTOR2DF_EQ(initial_scroll_,
CurrentScrollOffset(scroller_.get()));
EXPECT_POINTF_EQ(initial_scroll_, CurrentScrollOffset(scroller_.get()));
}
if (snap_animation_finished_) {
// After a snap target is set on the impl thread, the snap targets should
@ -1300,7 +1297,7 @@ class LayerTreeHostScrollTestImplOnlyScrollSnap
scoped_refptr<Layer> scroller_;
scoped_refptr<Layer> snap_area_;
gfx::Vector2dF initial_scroll_;
gfx::PointF initial_scroll_;
gfx::Vector2dF impl_thread_scroll_;
ElementId snap_area_id_;
@ -1371,7 +1368,7 @@ class LayerTreeHostScrollTestImplOnlyMultipleScrollSnap
// Set up snap container data.
SnapContainerData snap_container_data_a(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 100, 100), gfx::Vector2dF(900, 900));
gfx::RectF(0, 0, 100, 100), gfx::PointF(900, 900));
snap_container_data_a.AddSnapAreaData(snap_area_data_a);
CreateScrollNode(scroller_a_.get(), container_->bounds())
.snap_container_data = snap_container_data_a;
@ -1379,7 +1376,7 @@ class LayerTreeHostScrollTestImplOnlyMultipleScrollSnap
// Set up snap container data.
SnapContainerData snap_container_data_b(
ScrollSnapType(false, SnapAxis::kBoth, SnapStrictness::kMandatory),
gfx::RectF(0, 0, 100, 100), gfx::Vector2dF(900, 900));
gfx::RectF(0, 0, 100, 100), gfx::PointF(900, 900));
snap_container_data_b.AddSnapAreaData(snap_area_data_b);
CreateScrollNode(scroller_b_.get(), container_->bounds())
.snap_container_data = snap_container_data_b;
@ -1411,10 +1408,8 @@ class LayerTreeHostScrollTestImplOnlyMultipleScrollSnap
// values on the main thread.
EXPECT_EQ(snap_target_ids_a, TargetSnapAreaElementIds());
EXPECT_EQ(snap_target_ids_b, TargetSnapAreaElementIds());
EXPECT_VECTOR2DF_EQ(initial_scroll_,
CurrentScrollOffset(scroller_a_.get()));
EXPECT_VECTOR2DF_EQ(initial_scroll_,
CurrentScrollOffset(scroller_b_.get()));
EXPECT_POINTF_EQ(initial_scroll_, CurrentScrollOffset(scroller_a_.get()));
EXPECT_POINTF_EQ(initial_scroll_, CurrentScrollOffset(scroller_b_.get()));
} else {
// When scrolling happens on the impl thread, the snap targets of the
// scrolled layers should be pushed to the main thread.
@ -1451,7 +1446,7 @@ class LayerTreeHostScrollTestImplOnlyMultipleScrollSnap
scoped_refptr<Layer> snap_area_a_;
scoped_refptr<Layer> snap_area_b_;
gfx::Vector2dF initial_scroll_;
gfx::PointF initial_scroll_;
gfx::Vector2dF impl_thread_scroll_a_;
gfx::Vector2dF impl_thread_scroll_b_;
@ -1591,7 +1586,7 @@ class LayerTreeHostScrollTestScrollNonDrawnLayer
layer_tree_host()->OuterViewportScrollLayerForTesting()->SetIsDrawable(
false);
SetScrollOffset(layer_tree_host()->OuterViewportScrollLayerForTesting(),
gfx::Vector2dF(20.f, 20.f));
gfx::PointF(20.f, 20.f));
layer_tree_host()
->OuterViewportScrollLayerForTesting()
->SetNonFastScrollableRegion(gfx::Rect(20, 20, 20, 20));
@ -1761,8 +1756,8 @@ class ThreadCheckingInputHandlerClient : public InputHandlerClient {
void SetPrefersReducedMotion(bool prefers_reduced_motion) override {}
void UpdateRootLayerStateForSynchronousInputHandler(
const gfx::Vector2dF& total_scroll_offset,
const gfx::Vector2dF& max_scroll_offset,
const gfx::PointF& total_scroll_offset,
const gfx::PointF& max_scroll_offset,
const gfx::SizeF& scrollable_size,
float page_scale_factor,
float min_page_scale_factor,
@ -1835,7 +1830,7 @@ class LayerTreeHostScrollTestLayerStructureChange
void DidCompositorScroll(
ElementId element_id,
const gfx::Vector2dF&,
const gfx::PointF&,
const absl::optional<TargetSnapAreaElementIds>&) override {
if (scroll_destroy_whole_tree_) {
layer_tree_host()->SetRootLayer(nullptr);
@ -1935,18 +1930,18 @@ class LayerTreeHostScrollTestScrollMFBA : public LayerTreeHostScrollTest {
layer_tree_host()->OuterViewportScrollLayerForTesting();
switch (layer_tree_host()->SourceFrameNumber()) {
case 0:
EXPECT_VECTOR2DF_EQ(initial_scroll_, CurrentScrollOffset(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_, CurrentScrollOffset(scroll_layer));
break;
case 1:
EXPECT_VECTOR2DF_EQ(initial_scroll_ + scroll_amount_,
CurrentScrollOffset(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + scroll_amount_,
CurrentScrollOffset(scroll_layer));
// Pretend like Javascript updated the scroll position itself.
SetScrollOffset(scroll_layer, second_scroll_);
break;
case 2:
// Third frame does not see a scroll delta because we only did one
// scroll for the second and third frames.
EXPECT_VECTOR2DF_EQ(second_scroll_, CurrentScrollOffset(scroll_layer));
EXPECT_POINTF_EQ(second_scroll_, CurrentScrollOffset(scroll_layer));
// Pretend like Javascript updated the scroll position itself.
SetScrollOffset(scroll_layer, third_scroll_);
break;
@ -1959,7 +1954,7 @@ class LayerTreeHostScrollTestScrollMFBA : public LayerTreeHostScrollTest {
switch (impl->active_tree()->source_frame_number()) {
case 0:
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(scroll_layer));
EXPECT_VECTOR2DF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
Scroll(impl);
EXPECT_VECTOR2DF_EQ(scroll_amount_, ScrollDelta(scroll_layer));
// Ask for commit after we've scrolled.
@ -1967,14 +1962,14 @@ class LayerTreeHostScrollTestScrollMFBA : public LayerTreeHostScrollTest {
break;
case 1:
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(scroll_layer));
EXPECT_VECTOR2DF_EQ(second_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(second_scroll_, ScrollOffsetBase(scroll_layer));
Scroll(impl);
EXPECT_VECTOR2DF_EQ(scroll_amount_, ScrollDelta(scroll_layer));
break;
case 2:
// The scroll hasn't been consumed by the main thread.
EXPECT_VECTOR2DF_EQ(scroll_amount_, ScrollDelta(scroll_layer));
EXPECT_VECTOR2DF_EQ(third_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(third_scroll_, ScrollOffsetBase(scroll_layer));
EndTest();
break;
}
@ -1996,9 +1991,9 @@ class LayerTreeHostScrollTestScrollMFBA : public LayerTreeHostScrollTest {
scroll_layer->ScrollBy(scroll_amount_);
}
gfx::Vector2dF initial_scroll_;
gfx::Vector2dF second_scroll_;
gfx::Vector2dF third_scroll_;
gfx::PointF initial_scroll_;
gfx::PointF second_scroll_;
gfx::PointF third_scroll_;
gfx::Vector2dF scroll_amount_;
int num_commits_;
};
@ -2049,15 +2044,15 @@ class LayerTreeHostScrollTestScrollAbortedCommitMFBA
// This will not be aborted because of the initial prop changes.
EXPECT_EQ(0, num_outer_viewport_scrolls_);
EXPECT_EQ(0, layer_tree_host()->SourceFrameNumber());
EXPECT_VECTOR2DF_EQ(initial_scroll_,
CurrentScrollOffset(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_,
CurrentScrollOffset(root_scroll_layer));
break;
case 2:
// This commit will not be aborted because of the scroll change.
EXPECT_EQ(1, num_outer_viewport_scrolls_);
EXPECT_EQ(1, layer_tree_host()->SourceFrameNumber());
EXPECT_VECTOR2DF_EQ(initial_scroll_ + impl_scroll_,
CurrentScrollOffset(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + impl_scroll_,
CurrentScrollOffset(root_scroll_layer));
SetScrollOffset(
root_scroll_layer,
CurrentScrollOffset(root_scroll_layer) + second_main_scroll_);
@ -2069,8 +2064,8 @@ class LayerTreeHostScrollTestScrollAbortedCommitMFBA
EXPECT_EQ(2, layer_tree_host()->SourceFrameNumber());
gfx::Vector2dF delta =
impl_scroll_ + impl_scroll_ + second_main_scroll_;
EXPECT_VECTOR2DF_EQ(initial_scroll_ + delta,
CurrentScrollOffset(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + delta,
CurrentScrollOffset(root_scroll_layer));
break;
}
case 4: {
@ -2079,8 +2074,8 @@ class LayerTreeHostScrollTestScrollAbortedCommitMFBA
EXPECT_EQ(3, layer_tree_host()->SourceFrameNumber());
gfx::Vector2dF delta =
impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_;
EXPECT_VECTOR2DF_EQ(initial_scroll_ + delta,
CurrentScrollOffset(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + delta,
CurrentScrollOffset(root_scroll_layer));
break;
}
}
@ -2135,8 +2130,8 @@ class LayerTreeHostScrollTestScrollAbortedCommitMFBA
ScrollDelta(root_scroll_layer));
root_scroll_layer->ScrollBy(impl_scroll_);
EXPECT_VECTOR2DF_EQ(impl_scroll_, ScrollDelta(root_scroll_layer));
EXPECT_VECTOR2DF_EQ(initial_scroll_,
ScrollOffsetBase(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_,
ScrollOffsetBase(root_scroll_layer));
impl->SetNeedsCommit();
break;
}
@ -2146,8 +2141,8 @@ class LayerTreeHostScrollTestScrollAbortedCommitMFBA
root_scroll_layer->ScrollBy(impl_scroll_);
EXPECT_VECTOR2DF_EQ(impl_scroll_ + impl_scroll_,
ScrollDelta(root_scroll_layer));
EXPECT_VECTOR2DF_EQ(initial_scroll_,
ScrollOffsetBase(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_,
ScrollOffsetBase(root_scroll_layer));
// Ask for another commit (which will abort).
impl->SetNeedsCommit();
break;
@ -2167,8 +2162,8 @@ class LayerTreeHostScrollTestScrollAbortedCommitMFBA
EXPECT_VECTOR2DF_EQ(impl_scroll_, ScrollDelta(root_scroll_layer));
gfx::Vector2dF prev_delta =
impl_scroll_ + impl_scroll_ + second_main_scroll_;
EXPECT_VECTOR2DF_EQ(initial_scroll_ + prev_delta,
ScrollOffsetBase(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + prev_delta,
ScrollOffsetBase(root_scroll_layer));
// Ask for another commit (which will abort).
impl->SetNeedsCommit();
break;
@ -2176,8 +2171,8 @@ class LayerTreeHostScrollTestScrollAbortedCommitMFBA
case 2: {
gfx::Vector2dF delta = impl_scroll_ + impl_scroll_ + impl_scroll_ +
second_main_scroll_;
EXPECT_VECTOR2DF_EQ(initial_scroll_ + delta,
ScrollOffsetBase(root_scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + delta,
ScrollOffsetBase(root_scroll_layer));
// End test after second aborted commit (fourth commit request).
EndTest();
break;
@ -2205,7 +2200,7 @@ class LayerTreeHostScrollTestScrollAbortedCommitMFBA
}
private:
gfx::Vector2dF initial_scroll_;
gfx::PointF initial_scroll_;
gfx::Vector2dF impl_scroll_;
gfx::Vector2dF second_main_scroll_;
int num_will_begin_main_frames_;
@ -2229,8 +2224,8 @@ class MockInputHandlerClient : public InputHandlerClient {
void Animate(base::TimeTicks) override {}
void SetPrefersReducedMotion(bool prefers_reduced_motion) override {}
void UpdateRootLayerStateForSynchronousInputHandler(
const gfx::Vector2dF& total_scroll_offset,
const gfx::Vector2dF& max_scroll_offset,
const gfx::PointF& total_scroll_offset,
const gfx::PointF& max_scroll_offset,
const gfx::SizeF& scrollable_size,
float page_scale_factor,
float min_page_scale_factor,
@ -2415,10 +2410,10 @@ class LayerTreeHostScrollTestPropertyTreeUpdate
Layer* scroll_layer =
layer_tree_host()->OuterViewportScrollLayerForTesting();
if (layer_tree_host()->SourceFrameNumber() == 0) {
EXPECT_VECTOR2DF_EQ(initial_scroll_, CurrentScrollOffset(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_, CurrentScrollOffset(scroll_layer));
} else {
EXPECT_VECTOR2DF_EQ(initial_scroll_ + scroll_amount_,
CurrentScrollOffset(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_ + scroll_amount_,
CurrentScrollOffset(scroll_layer));
SetScrollOffset(scroll_layer, second_scroll_);
SetOpacity(scroll_layer, 0.5f);
}
@ -2430,23 +2425,23 @@ class LayerTreeHostScrollTestPropertyTreeUpdate
switch (impl->active_tree()->source_frame_number()) {
case 0:
EXPECT_VECTOR2DF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(initial_scroll_,
GetTransformNode(scroll_layer)->scroll_offset);
EXPECT_POINTF_EQ(initial_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(initial_scroll_,
GetTransformNode(scroll_layer)->scroll_offset);
PostSetNeedsCommitToMainThread();
break;
case 1:
EXPECT_VECTOR2DF_EQ(second_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_VECTOR2DF_EQ(second_scroll_,
GetTransformNode(scroll_layer)->scroll_offset);
EXPECT_POINTF_EQ(second_scroll_, ScrollOffsetBase(scroll_layer));
EXPECT_POINTF_EQ(second_scroll_,
GetTransformNode(scroll_layer)->scroll_offset);
EndTest();
break;
}
}
private:
gfx::Vector2dF initial_scroll_;
gfx::Vector2dF second_scroll_;
gfx::PointF initial_scroll_;
gfx::PointF second_scroll_;
gfx::Vector2dF scroll_amount_;
};
@ -2456,7 +2451,7 @@ class LayerTreeHostScrollTestImplSideInvalidation
: public LayerTreeHostScrollTest {
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidScrollOuterViewport(const gfx::Vector2dF& offset) override {
void DidScrollOuterViewport(const gfx::PointF& offset) override {
LayerTreeHostScrollTest::DidScrollOuterViewport(offset);
// Defer responding to the main frame until an impl-side pending tree is
@ -2511,9 +2506,9 @@ class LayerTreeHostScrollTestImplSideInvalidation
LayerImpl* scroll_layer =
host_impl->pending_tree()->OuterViewportScrollLayerForTesting();
gfx::Vector2dF scroll_offset = CurrentScrollOffset(scroll_layer);
gfx::PointF scroll_offset = CurrentScrollOffset(scroll_layer);
int transform_index = scroll_layer->transform_tree_index();
gfx::Vector2dF transform_tree_scroll_offset =
gfx::PointF transform_tree_scroll_offset =
host_impl->pending_tree()
->property_trees()
->transform_tree.Node(transform_index)
@ -2619,8 +2614,8 @@ class LayerTreeHostScrollTestImplSideInvalidation
EXPECT_EQ(3, num_of_main_frames_);
}
const gfx::Vector2dF outer_viewport_offsets_[3] = {
gfx::Vector2dF(20, 20), gfx::Vector2dF(50, 50), gfx::Vector2dF(70, 70)};
const gfx::PointF outer_viewport_offsets_[3] = {
gfx::PointF(20, 20), gfx::PointF(50, 50), gfx::PointF(70, 70)};
// Impl thread.
int num_of_activations_ = 0;

@ -68,11 +68,15 @@ class ViewportAnchor {
LayerTreeImpl* tree_impl)
: inner_(inner_scroll), outer_(outer_scroll), tree_impl_(tree_impl) {
viewport_in_content_coordinates_ =
scroll_tree().current_scroll_offset(inner_->element_id);
scroll_tree()
.current_scroll_offset(inner_->element_id)
.OffsetFromOrigin();
if (outer_) {
viewport_in_content_coordinates_ +=
scroll_tree().current_scroll_offset(outer_->element_id);
scroll_tree()
.current_scroll_offset(outer_->element_id)
.OffsetFromOrigin();
}
}
@ -83,8 +87,12 @@ class ViewportAnchor {
scroll_tree().ClampScrollToMaxScrollOffset(*outer_, tree_impl_);
gfx::Vector2dF viewport_location =
scroll_tree().current_scroll_offset(inner_->element_id) +
scroll_tree().current_scroll_offset(outer_->element_id);
scroll_tree()
.current_scroll_offset(inner_->element_id)
.OffsetFromOrigin() +
scroll_tree()
.current_scroll_offset(outer_->element_id)
.OffsetFromOrigin();
gfx::Vector2dF delta = viewport_in_content_coordinates_ - viewport_location;
@ -273,7 +281,7 @@ void LayerTreeImpl::UpdateScrollbarGeometries() {
auto* scroll_node = scroll_tree.FindNodeFromElementId(scrolling_element_id);
if (!scroll_node)
continue;
gfx::Vector2dF current_offset =
gfx::PointF current_offset =
scroll_tree.current_scroll_offset(scrolling_element_id);
gfx::SizeF scrolling_size(scroll_node->bounds);
gfx::Size bounds_size(scroll_tree.container_bounds(scroll_node->id));
@ -289,7 +297,8 @@ void LayerTreeImpl::UpdateScrollbarGeometries() {
// Add offset and bounds contribution of outer viewport.
current_offset +=
scroll_tree.current_scroll_offset(outer_scroll_node->element_id);
scroll_tree.current_scroll_offset(outer_scroll_node->element_id)
.OffsetFromOrigin();
gfx::SizeF outer_viewport_bounds(
scroll_tree.container_bounds(outer_scroll_node->id));
viewport_bounds.SetToMin(outer_viewport_bounds);
@ -301,7 +310,8 @@ void LayerTreeImpl::UpdateScrollbarGeometries() {
DCHECK(inner_scroll_node);
// Add offset and bounds contribution of inner viewport.
current_offset +=
scroll_tree.current_scroll_offset(inner_scroll_node->element_id);
scroll_tree.current_scroll_offset(inner_scroll_node->element_id)
.OffsetFromOrigin();
gfx::SizeF inner_viewport_bounds(
scroll_tree.container_bounds(inner_scroll_node->id));
viewport_bounds.SetToMin(inner_viewport_bounds);
@ -468,31 +478,37 @@ bool LayerTreeImpl::IsRootLayer(const LayerImpl* layer) const {
return !layer_list_.empty() && layer_list_[0].get() == layer;
}
gfx::Vector2dF LayerTreeImpl::TotalScrollOffset() const {
gfx::PointF LayerTreeImpl::TotalScrollOffset() const {
gfx::Vector2dF offset;
const auto& scroll_tree = property_trees()->scroll_tree;
if (auto* inner_scroll = InnerViewportScrollNode()) {
offset += scroll_tree.current_scroll_offset(inner_scroll->element_id);
offset += scroll_tree.current_scroll_offset(inner_scroll->element_id)
.OffsetFromOrigin();
DCHECK(OuterViewportScrollNode());
offset += scroll_tree.current_scroll_offset(
OuterViewportScrollNode()->element_id);
offset +=
scroll_tree.current_scroll_offset(OuterViewportScrollNode()->element_id)
.OffsetFromOrigin();
}
return offset;
return gfx::PointAtOffsetFromOrigin(offset);
}
gfx::Vector2dF LayerTreeImpl::TotalMaxScrollOffset() const {
gfx::PointF LayerTreeImpl::TotalMaxScrollOffset() const {
gfx::Vector2dF offset;
const auto& scroll_tree = property_trees()->scroll_tree;
if (viewport_property_ids_.inner_scroll != ScrollTree::kInvalidNodeId)
offset += scroll_tree.MaxScrollOffset(viewport_property_ids_.inner_scroll);
if (viewport_property_ids_.inner_scroll != ScrollTree::kInvalidNodeId) {
offset += scroll_tree.MaxScrollOffset(viewport_property_ids_.inner_scroll)
.OffsetFromOrigin();
}
if (viewport_property_ids_.outer_scroll != ScrollTree::kInvalidNodeId)
offset += scroll_tree.MaxScrollOffset(viewport_property_ids_.outer_scroll);
if (viewport_property_ids_.outer_scroll != ScrollTree::kInvalidNodeId) {
offset += scroll_tree.MaxScrollOffset(viewport_property_ids_.outer_scroll)
.OffsetFromOrigin();
}
return offset;
return gfx::PointAtOffsetFromOrigin(offset);
}
OwnedLayerImplList LayerTreeImpl::DetachLayers() {

@ -281,8 +281,8 @@ class CC_EXPORT LayerTreeImpl {
hud_layer_ = layer_impl;
}
gfx::Vector2dF TotalScrollOffset() const;
gfx::Vector2dF TotalMaxScrollOffset() const;
gfx::PointF TotalScrollOffset() const;
gfx::PointF TotalMaxScrollOffset() const;
void AddPresentationCallbacks(
std::vector<PresentationTimeCallbackBuffer::MainCallback> callbacks);

@ -13,6 +13,7 @@
#include "cc/trees/layer_tree_mutator.h"
#include "cc/trees/mutator_host_client.h"
#include "ui/gfx/geometry/box_f.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
@ -125,20 +126,20 @@ class MutatorHost {
virtual void ImplOnlyAutoScrollAnimationCreate(
ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
float autoscroll_velocity,
base::TimeDelta animation_start_offset) = 0;
virtual void ImplOnlyScrollAnimationCreate(
ElementId element_id,
const gfx::Vector2dF& target_offset,
const gfx::Vector2dF& current_offset,
const gfx::PointF& target_offset,
const gfx::PointF& current_offset,
base::TimeDelta delayed_by,
base::TimeDelta animation_start_offset) = 0;
virtual bool ImplOnlyScrollAnimationUpdateTarget(
const gfx::Vector2dF& scroll_delta,
const gfx::Vector2dF& max_scroll_offset,
const gfx::PointF& max_scroll_offset,
base::TimeTicks frame_monotonic_time,
base::TimeDelta delayed_by) = 0;

@ -12,7 +12,7 @@
namespace gfx {
class Transform;
class Vector2dF;
class PointF;
}
namespace cc {
@ -52,7 +52,7 @@ class MutatorHostClient {
virtual void SetElementScrollOffsetMutated(
ElementId element_id,
ElementListType list_type,
const gfx::Vector2dF& scroll_offset) = 0;
const gfx::PointF& scroll_offset) = 0;
// Allows to change IsAnimating value for a set of properties.
virtual void ElementIsAnimatingChanged(
@ -66,7 +66,7 @@ class MutatorHostClient {
float maximum_scale) = 0;
virtual void ScrollOffsetAnimationFinished() = 0;
virtual gfx::Vector2dF GetScrollOffsetForAnimation(
virtual gfx::PointF GetScrollOffsetForAnimation(
ElementId element_id) const = 0;
virtual void NotifyAnimationWorkletStateChange(

@ -23,6 +23,7 @@
#include "cc/trees/scroll_node.h"
#include "cc/trees/transform_node.h"
#include "components/viz/common/frame_sinks/copy_output_request.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/transform_util.h"
#include "ui/gfx/geometry/vector2d_conversions.h"
@ -1291,12 +1292,12 @@ void ScrollTree::clear() {
#endif
}
gfx::Vector2dF ScrollTree::MaxScrollOffset(int scroll_node_id) const {
gfx::PointF ScrollTree::MaxScrollOffset(int scroll_node_id) const {
const ScrollNode* scroll_node = Node(scroll_node_id);
gfx::SizeF scroll_bounds = this->scroll_bounds(scroll_node_id);
if (!scroll_node->scrollable || scroll_bounds.IsEmpty())
return gfx::Vector2dF();
return gfx::PointF();
TransformTree& transform_tree = property_trees()->transform_tree;
float scale_factor = 1.f;
@ -1309,12 +1310,12 @@ gfx::Vector2dF ScrollTree::MaxScrollOffset(int scroll_node_id) const {
gfx::Size clip_layer_bounds = container_bounds(scroll_node->id);
gfx::Vector2dF max_offset(
gfx::PointF max_offset(
scaled_scroll_bounds.width() - clip_layer_bounds.width(),
scaled_scroll_bounds.height() - clip_layer_bounds.height());
max_offset.Scale(1 / scale_factor);
max_offset.SetToMax(gfx::Vector2dF());
max_offset.SetToMax(gfx::PointF());
return max_offset;
}
@ -1330,7 +1331,7 @@ gfx::SizeF ScrollTree::scroll_bounds(int scroll_node_id) const {
void ScrollTree::OnScrollOffsetAnimated(ElementId id,
int scroll_tree_index,
const gfx::Vector2dF& scroll_offset,
const gfx::PointF& scroll_offset,
LayerTreeImpl* layer_tree_impl) {
// Only active tree needs to be updated, pending tree will find out about
// these changes as a result of the shared SyncedProperty.
@ -1418,29 +1419,29 @@ const SyncedScrollOffset* ScrollTree::GetSyncedScrollOffset(
gfx::Vector2dF ScrollTree::ClampScrollToMaxScrollOffset(
const ScrollNode& node,
LayerTreeImpl* layer_tree_impl) {
gfx::Vector2dF old_offset = current_scroll_offset(node.element_id);
gfx::Vector2dF clamped_offset = ClampScrollOffsetToLimits(old_offset, node);
gfx::PointF old_offset = current_scroll_offset(node.element_id);
gfx::PointF clamped_offset = ClampScrollOffsetToLimits(old_offset, node);
gfx::Vector2dF delta = clamped_offset - old_offset;
if (!delta.IsZero())
ScrollBy(node, delta, layer_tree_impl);
return delta;
}
const gfx::Vector2dF ScrollTree::current_scroll_offset(ElementId id) const {
const gfx::PointF ScrollTree::current_scroll_offset(ElementId id) const {
if (property_trees()->is_main_thread) {
auto it = scroll_offset_map_.find(id);
return it != scroll_offset_map_.end() ? it->second : gfx::Vector2dF();
return it != scroll_offset_map_.end() ? it->second : gfx::PointF();
}
return GetSyncedScrollOffset(id)
? GetSyncedScrollOffset(id)->Current(property_trees()->is_active)
: gfx::Vector2dF();
if (const auto* synced_scroll_offset = GetSyncedScrollOffset(id))
return synced_scroll_offset->Current(property_trees()->is_active);
return gfx::PointF();
}
const gfx::Vector2dF ScrollTree::GetPixelSnappedScrollOffset(
const gfx::PointF ScrollTree::GetPixelSnappedScrollOffset(
int scroll_node_id) const {
const ScrollNode* scroll_node = Node(scroll_node_id);
DCHECK(scroll_node);
gfx::Vector2dF offset = current_scroll_offset(scroll_node->element_id);
gfx::PointF offset = current_scroll_offset(scroll_node->element_id);
const TransformNode* transform_node =
property_trees()->transform_tree.Node(scroll_node->transform_id);
@ -1484,14 +1485,14 @@ gfx::Vector2dF ScrollTree::PullDeltaForMainThread(
// TODO(flackr): We should ideally round the fractional scrolls in the same
// direction as the scroll will be snapped but for common cases this is
// equivalent to rounding to the nearest integer offset.
gfx::Vector2dF current_offset =
gfx::PointF current_offset =
scroll_offset->Current(/* is_active_tree */ true);
gfx::Vector2dF rounded_offset = gfx::ToRoundedVector2d(current_offset);
gfx::PointF rounded_offset(gfx::ToRoundedPoint(current_offset));
// The calculation of the difference from the rounded active base is to
// represent the integer delta that the main thread should know about.
gfx::Vector2dF active_base = scroll_offset->ActiveBase();
gfx::PointF active_base = scroll_offset->ActiveBase();
gfx::Vector2dF diff_active_base =
active_base - gfx::ToRoundedVector2d(active_base);
active_base - gfx::PointF(gfx::ToRoundedPoint(active_base));
scroll_offset->SetCurrent(rounded_offset + diff_active_base);
gfx::Vector2dF delta = scroll_offset->PullDeltaForMainThread();
scroll_offset->SetCurrent(current_offset);
@ -1577,8 +1578,8 @@ void ScrollTree::PushScrollUpdatesFromMainThread(
// PullDeltaForMainThread where only an integer delta is extracted and
// prevents unnecessary property change in this case.
if (!use_fractional_deltas) {
gfx::Vector2dF pending_offset = synced_scroll_offset->Current(false);
gfx::Vector2dF rounded_offset = gfx::ToRoundedVector2d(pending_offset);
gfx::PointF pending_offset = synced_scroll_offset->Current(false);
gfx::PointF rounded_offset(gfx::ToRoundedPoint(pending_offset));
needs_scroll_update = map_entry.second != rounded_offset;
}
@ -1622,7 +1623,7 @@ void ScrollTree::ApplySentScrollDeltasFromAbortedCommit() {
}
void ScrollTree::SetBaseScrollOffset(ElementId id,
const gfx::Vector2dF& scroll_offset) {
const gfx::PointF& scroll_offset) {
if (property_trees()->is_main_thread) {
scroll_offset_map_[id] = scroll_offset;
return;
@ -1635,7 +1636,7 @@ void ScrollTree::SetBaseScrollOffset(ElementId id,
}
bool ScrollTree::SetScrollOffset(ElementId id,
const gfx::Vector2dF& scroll_offset) {
const gfx::PointF& scroll_offset) {
// TODO(crbug.com/1087088): Remove TRACE_EVENT call when the bug is fixed
TRACE_EVENT2("cc", "ScrollTree::SetScrollOffset", "x", scroll_offset.x(), "y",
scroll_offset.y());
@ -1646,16 +1647,14 @@ bool ScrollTree::SetScrollOffset(ElementId id,
return true;
}
if (property_trees()->is_active) {
if (property_trees()->is_active)
return GetOrCreateSyncedScrollOffset(id)->SetCurrent(scroll_offset);
}
return false;
}
bool ScrollTree::UpdateScrollOffsetBaseForTesting(
ElementId id,
const gfx::Vector2dF& offset) {
bool ScrollTree::UpdateScrollOffsetBaseForTesting(ElementId id,
const gfx::PointF& offset) {
DCHECK(!property_trees()->is_main_thread);
SyncedScrollOffset* synced_scroll_offset = GetOrCreateSyncedScrollOffset(id);
bool changed = synced_scroll_offset->PushMainToPending(offset);
@ -1670,7 +1669,7 @@ bool ScrollTree::SetScrollOffsetDeltaForTesting(ElementId id,
GetOrCreateSyncedScrollOffset(id)->ActiveBase() + delta);
}
const gfx::Vector2dF ScrollTree::GetScrollOffsetBaseForTesting(
const gfx::PointF ScrollTree::GetScrollOffsetBaseForTesting(
ElementId id) const {
DCHECK(!property_trees()->is_main_thread);
if (GetSyncedScrollOffset(id)) {
@ -1678,7 +1677,7 @@ const gfx::Vector2dF ScrollTree::GetScrollOffsetBaseForTesting(
? GetSyncedScrollOffset(id)->ActiveBase()
: GetSyncedScrollOffset(id)->PendingBase();
}
return gfx::Vector2dF();
return gfx::PointF();
}
const gfx::Vector2dF ScrollTree::GetScrollOffsetDeltaForTesting(
@ -1701,8 +1700,8 @@ gfx::Vector2dF ScrollTree::ScrollBy(const ScrollNode& scroll_node,
if (!scroll_node.user_scrollable_vertical)
adjusted_scroll.set_y(0);
DCHECK(scroll_node.scrollable);
gfx::Vector2dF old_offset = current_scroll_offset(scroll_node.element_id);
gfx::Vector2dF new_offset =
gfx::PointF old_offset = current_scroll_offset(scroll_node.element_id);
gfx::PointF new_offset =
ClampScrollOffsetToLimits(old_offset + adjusted_scroll, scroll_node);
if (SetScrollOffset(scroll_node.element_id, new_offset))
layer_tree_impl->DidUpdateScrollOffset(scroll_node.element_id);
@ -1711,11 +1710,11 @@ gfx::Vector2dF ScrollTree::ScrollBy(const ScrollNode& scroll_node,
return old_offset + scroll - new_offset;
}
gfx::Vector2dF ScrollTree::ClampScrollOffsetToLimits(
gfx::Vector2dF offset,
gfx::PointF ScrollTree::ClampScrollOffsetToLimits(
gfx::PointF offset,
const ScrollNode& scroll_node) const {
offset.SetToMin(MaxScrollOffset(scroll_node.id));
offset.SetToMax(gfx::Vector2dF());
offset.SetToMax(gfx::PointF());
return offset;
}
@ -1726,7 +1725,7 @@ void ScrollTree::SetScrollCallbacks(base::WeakPtr<ScrollCallbacks> callbacks) {
void ScrollTree::NotifyDidCompositorScroll(
ElementId scroll_element_id,
const gfx::Vector2dF& scroll_offset,
const gfx::PointF& scroll_offset,
const absl::optional<TargetSnapAreaElementIds>& snap_target_ids) {
DCHECK(property_trees()->is_main_thread);
if (callbacks_) {

@ -24,6 +24,7 @@
#include "cc/trees/mutator_host.h"
#include "cc/trees/sticky_position_constraint.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/transform.h"
#include "ui/gfx/geometry/vector2d_f.h"
@ -49,7 +50,8 @@ struct ScrollNode;
struct TransformNode;
struct TransformCachedNodeData;
using SyncedScrollOffset = SyncedProperty<AdditionGroup<gfx::Vector2dF>>;
using SyncedScrollOffset =
SyncedProperty<AdditionGroup<gfx::PointF, gfx::Vector2dF>>;
class PropertyTrees;
@ -383,7 +385,7 @@ class ScrollCallbacks {
// Called after the composited scroll offset changed.
virtual void DidCompositorScroll(
ElementId scroll_element_id,
const gfx::Vector2dF&,
const gfx::PointF&,
const absl::optional<TargetSnapAreaElementIds>&) = 0;
// Called after the hidden status of composited scrollbars changed. Note that
// |scroll_element_id| is the element id of the scroll not of the scrollbars.
@ -407,10 +409,10 @@ class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> {
void clear();
gfx::Vector2dF MaxScrollOffset(int scroll_node_id) const;
gfx::PointF MaxScrollOffset(int scroll_node_id) const;
void OnScrollOffsetAnimated(ElementId id,
int scroll_tree_index,
const gfx::Vector2dF& scroll_offset,
const gfx::PointF& scroll_offset,
LayerTreeImpl* layer_tree_impl);
gfx::Size container_bounds(int scroll_node_id) const;
gfx::SizeF scroll_bounds(int scroll_node_id) const;
@ -429,7 +431,7 @@ class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> {
// Returns the current scroll offset. On the main thread this would return the
// value for the LayerTree while on the impl thread this is the current value
// on the active tree.
const gfx::Vector2dF current_scroll_offset(ElementId id) const;
const gfx::PointF current_scroll_offset(ElementId id) const;
// Returns the scroll offset taking into account any adjustments that may be
// included due to pixel snapping.
@ -441,7 +443,7 @@ class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> {
// simple cases but we really should update the whole transform tree otherwise
// we are ignoring any parent transform node that needs updating and thus our
// snap amount can be incorrect.
const gfx::Vector2dF GetPixelSnappedScrollOffset(int scroll_node_id) const;
const gfx::PointF GetPixelSnappedScrollOffset(int scroll_node_id) const;
// Collects deltas for scroll changes on the impl thread that need to be
// reported to the main thread during the main frame. As such, should only be
@ -468,25 +470,25 @@ class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> {
void PushScrollUpdatesFromPendingTree(PropertyTrees* pending_property_trees,
LayerTreeImpl* active_tree);
void SetBaseScrollOffset(ElementId id, const gfx::Vector2dF& scroll_offset);
void SetBaseScrollOffset(ElementId id, const gfx::PointF& scroll_offset);
// Returns true if the scroll offset is changed.
bool SetScrollOffset(ElementId id, const gfx::Vector2dF& scroll_offset);
bool SetScrollOffset(ElementId id, const gfx::PointF& scroll_offset);
void SetScrollOffsetClobberActiveValue(ElementId id) {
GetOrCreateSyncedScrollOffset(id)->set_clobber_active_value();
}
bool UpdateScrollOffsetBaseForTesting(ElementId id,
const gfx::Vector2dF& offset);
const gfx::PointF& offset);
bool SetScrollOffsetDeltaForTesting(ElementId id,
const gfx::Vector2dF& delta);
const gfx::Vector2dF GetScrollOffsetBaseForTesting(ElementId id) const;
const gfx::PointF GetScrollOffsetBaseForTesting(ElementId id) const;
const gfx::Vector2dF GetScrollOffsetDeltaForTesting(ElementId id) const;
void CollectScrollDeltasForTesting(bool use_fractional_deltas = false);
gfx::Vector2dF ScrollBy(const ScrollNode& scroll_node,
const gfx::Vector2dF& scroll,
LayerTreeImpl* layer_tree_impl);
gfx::Vector2dF ClampScrollOffsetToLimits(gfx::Vector2dF offset,
const ScrollNode& scroll_node) const;
gfx::PointF ClampScrollOffsetToLimits(gfx::PointF offset,
const ScrollNode& scroll_node) const;
const SyncedScrollOffset* GetSyncedScrollOffset(ElementId id) const;
@ -501,7 +503,7 @@ class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> {
void NotifyDidCompositorScroll(
ElementId scroll_element_id,
const gfx::Vector2dF& scroll_offset,
const gfx::PointF& scroll_offset,
const absl::optional<TargetSnapAreaElementIds>& snap_target_ids);
void NotifyDidChangeScrollbarsHidden(ElementId scroll_element_id,
bool hidden);
@ -516,7 +518,7 @@ class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> {
using PropertyTree::needs_update;
using PropertyTree::set_needs_update;
using ScrollOffsetMap = base::flat_map<ElementId, gfx::Vector2dF>;
using ScrollOffsetMap = base::flat_map<ElementId, gfx::PointF>;
using SyncedScrollOffsetMap =
base::flat_map<ElementId, scoped_refptr<SyncedScrollOffset>>;

@ -614,18 +614,16 @@ TEST(ScrollTreeTest, GetPixelSnappedScrollOffsetNegativeOffset) {
scroll_tree.Node(scroll_node_id)->element_id = element_id;
// Set a scroll value close to 0.
scroll_tree.SetScrollOffset(element_id, gfx::Vector2dF(0, 0.1));
scroll_tree.SetScrollOffset(element_id, gfx::PointF(0, 0.1));
transform_tree.Node(transform_node_id)->scrolls = true;
transform_tree.Node(transform_node_id)->scroll_offset =
gfx::Vector2dF(0, 0.1);
transform_tree.Node(transform_node_id)->scroll_offset = gfx::PointF(0, 0.1);
// Pretend that the snap amount was slightly larger than 0.1.
transform_tree.Node(transform_node_id)->snap_amount = gfx::Vector2dF(0, 0.2);
transform_tree.Node(transform_node_id)->needs_local_transform_update = false;
// The returned offset should be clamped at a minimum of 0.
gfx::Vector2dF offset =
scroll_tree.GetPixelSnappedScrollOffset(scroll_node_id);
gfx::PointF offset = scroll_tree.GetPixelSnappedScrollOffset(scroll_node_id);
EXPECT_EQ(offset.y(), 0);
}
@ -668,7 +666,7 @@ TEST(ScrollTreeTest, PushScrollUpdatesFromMainThreadIntegerDelta) {
scroll_node_id;
// Push main scroll to pending.
main_scroll_tree.SetScrollOffset(element_id, gfx::Vector2dF(0, 1));
main_scroll_tree.SetScrollOffset(element_id, gfx::PointF(0, 1));
pending_scroll_tree.PushScrollUpdatesFromMainThread(
&property_trees, host_impl.pending_tree(), use_fractional_deltas);
const SyncedScrollOffset* scroll_offset =
@ -680,7 +678,7 @@ TEST(ScrollTreeTest, PushScrollUpdatesFromMainThreadIntegerDelta) {
pending_scroll_tree.SetScrollOffsetDeltaForTesting(element_id,
gfx::Vector2dF(0, 0.25));
main_scroll_tree.CollectScrollDeltasForTesting(use_fractional_deltas);
EXPECT_EQ(gfx::Vector2dF(0, 1),
EXPECT_EQ(gfx::PointF(0, 1),
main_scroll_tree.current_scroll_offset(element_id));
// Rounding logic turned on should not cause property change on push.

@ -67,7 +67,7 @@ class CC_EXPORT RenderFrameMetadata {
SkColor root_background_color = SK_ColorWHITE;
// Scroll offset of the root layer.
absl::optional<gfx::Vector2dF> root_scroll_offset;
absl::optional<gfx::PointF> root_scroll_offset;
// Selection region relative to the current viewport. If the selection is
// empty or otherwise unused, the bound types will indicate such.

@ -116,7 +116,7 @@ struct CC_EXPORT TransformNode {
// Set to true, if the node or it's parent |will_change_transform| is true.
bool node_or_ancestors_will_change_transform : 1;
gfx::Vector2dF scroll_offset;
gfx::PointF scroll_offset;
// This value stores the snapped amount whenever we snap. If the snap is due
// to a scroll, we need it to calculate fixed-pos elements adjustment, even

@ -620,8 +620,8 @@ TEST_F(TreeSynchronizerTest, SynchronizeScrollTreeScrollOffsetMap) {
transient_scroll_layer->SetScrollable(gfx::Size(1, 1));
scroll_layer->SetScrollable(gfx::Size(1, 1));
transient_scroll_layer->SetScrollOffset(gfx::Vector2dF(1, 2));
scroll_layer->SetScrollOffset(gfx::Vector2dF(10, 20));
transient_scroll_layer->SetScrollOffset(gfx::PointF(1, 2));
scroll_layer->SetScrollOffset(gfx::PointF(10, 20));
host_->SetRootLayer(layer_tree_root);
host_->BuildPropertyTreesForTesting();
@ -657,13 +657,13 @@ TEST_F(TreeSynchronizerTest, SynchronizeScrollTreeScrollOffsetMap) {
->scroll_tree.GetSyncedScrollOffset(
transient_scroll_layer->element_id())));
// Set ScrollOffset active delta: gfx::Vector2dF(10, 10)
// Set ScrollOffset active delta: gfx::PointF(10, 10)
LayerImpl* scroll_layer_impl =
host_impl->active_tree()->LayerById(scroll_layer->id());
ScrollTree& scroll_tree =
host_impl->active_tree()->property_trees()->scroll_tree;
scroll_tree.SetScrollOffset(scroll_layer_impl->element_id(),
gfx::Vector2dF(20, 30));
gfx::PointF(20, 30));
// Pull ScrollOffset delta for main thread, and change offset on main thread
std::unique_ptr<CompositorCommitData> commit_data(new CompositorCommitData());
@ -672,12 +672,12 @@ TEST_F(TreeSynchronizerTest, SynchronizeScrollTreeScrollOffsetMap) {
base::flat_map<ElementId, TargetSnapAreaElementIds>());
host_->proxy()->SetNeedsCommit();
host_->ApplyCompositorChanges(commit_data.get());
EXPECT_EQ(gfx::Vector2dF(20, 30), scroll_layer->scroll_offset());
scroll_layer->SetScrollOffset(gfx::Vector2dF(100, 100));
EXPECT_EQ(gfx::PointF(20, 30), scroll_layer->scroll_offset());
scroll_layer->SetScrollOffset(gfx::PointF(100, 100));
// More update to ScrollOffset active delta: gfx::Vector2dF(20, 20)
scroll_tree.SetScrollOffset(scroll_layer_impl->element_id(),
gfx::Vector2dF(40, 50));
gfx::PointF(40, 50));
host_impl->active_tree()->SetCurrentlyScrollingNode(
scroll_tree.Node(scroll_layer_impl->scroll_tree_index()));
@ -692,10 +692,10 @@ TEST_F(TreeSynchronizerTest, SynchronizeScrollTreeScrollOffsetMap) {
EXPECT_EQ(scroll_layer->scroll_tree_index(),
host_impl->active_tree()->CurrentlyScrollingNode()->id);
scroll_layer_offset->SetCurrent(gfx::Vector2dF(20, 30));
scroll_layer_offset->SetCurrent(gfx::PointF(20, 30));
scroll_layer_offset->PullDeltaForMainThread();
scroll_layer_offset->SetCurrent(gfx::Vector2dF(40, 50));
scroll_layer_offset->PushMainToPending(gfx::Vector2dF(100, 100));
scroll_layer_offset->SetCurrent(gfx::PointF(40, 50));
scroll_layer_offset->PushMainToPending(gfx::PointF(100, 100));
scroll_layer_offset->PushPendingToActive();
EXPECT_TRUE(AreScrollOffsetsEqual(
scroll_layer_offset.get(),

@ -42,7 +42,7 @@ void OverscrollSceneLayer::Prepare(JNIEnv* env,
// |OverscrollGlow| activates glow effect only when content is bigger than
// viewport. Make it bigger by 1.f.
const gfx::SizeF content_size(width + 1.f, height);
const gfx::Vector2dF content_scroll_offset(1, 0);
const gfx::PointF content_scroll_offset(1, 0);
glow_effect_->OnFrameUpdated(viewport_size, content_size,
content_scroll_offset);
}

@ -4363,7 +4363,7 @@ IN_PROC_BROWSER_TEST_P(WebViewGuestScrollTest, TestGuestWheelScrollsBubble) {
embedder_rect.set_x(0);
embedder_rect.set_y(0);
gfx::Vector2dF default_offset;
gfx::PointF default_offset;
embedder_frame_observer.WaitForScrollOffset(default_offset);
// Send scroll gesture to embedder & verify.
@ -4377,7 +4377,7 @@ IN_PROC_BROWSER_TEST_P(WebViewGuestScrollTest, TestGuestWheelScrollsBubble) {
embedder_rect.x() + embedder_rect.width() / 2,
(embedder_rect.y() + guest_rect.y()) / 2);
gfx::Vector2dF expected_offset(0.f, scroll_magnitude);
gfx::PointF expected_offset(0.f, scroll_magnitude);
content::SimulateMouseEvent(embedder_contents,
blink::WebInputEvent::Type::kMouseMove,
@ -4433,7 +4433,7 @@ IN_PROC_BROWSER_TEST_P(WebViewGuestScrollTest,
content::RenderWidgetHostView* guest_host_view =
guest_contents->GetRenderWidgetHostView();
gfx::Vector2dF default_offset;
gfx::PointF default_offset;
guest_frame_observer.WaitForScrollOffset(default_offset);
embedder_frame_observer.WaitForScrollOffset(default_offset);
@ -4538,7 +4538,7 @@ IN_PROC_BROWSER_TEST_P(WebViewGuestScrollTouchTest,
embedder_rect.set_x(0);
embedder_rect.set_y(0);
gfx::Vector2dF default_offset;
gfx::PointF default_offset;
embedder_frame_observer.WaitForScrollOffset(default_offset);
// Send scroll gesture to embedder & verify.
@ -4550,7 +4550,7 @@ IN_PROC_BROWSER_TEST_P(WebViewGuestScrollTouchTest,
embedder_rect.x() + embedder_rect.width() / 2,
(embedder_rect.y() + guest_rect.y()) / 2);
gfx::Vector2dF expected_offset(0.f, gesture_distance);
gfx::PointF expected_offset(0.f, gesture_distance);
content::SimulateGestureScrollSequence(
embedder_contents, embedder_scroll_location,

@ -40,7 +40,7 @@ IN_PROC_BROWSER_TEST_F(MetricIntegrationTest, DISABLED_FirstScrollDelay) {
blink::WebMouseWheelEvent::kPhaseEnded);
// Wait for the scroll to complete and the display to be updated.
frame_observer.WaitForScrollOffset(gfx::Vector2d(0, scroll_distance));
frame_observer.WaitForScrollOffset(gfx::PointF(0, scroll_distance));
// Navigate away.
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), GURL("about:blank")));

Some files were not shown because too many files have changed in this diff Show More