Commit 0711bbac authored by Sandra Sun's avatar Sandra Sun Committed by Commit Bot

Share SnapPoints data between cc and blink

This patch does the following:
1. Moves the data structure of SnapPoints from blink to cc and shares it back with blink.
2. Use the coordinate of ScrollPosition and the type of FloatPoint to do calculations in
   SnapCoordinator instead of ScrollOffset, as gfx::ScrollOffset uses ScrollPosition.
3. Update the logic in SnapCoordinator to work with vertical-rl writing-mode.
4. Use LocalToAncestorQuad() for the snap_area to ensure transforms are properly dealt with.


Bug: 795404
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: I538327e169ebee4d3e03ec2ddd0d5b282e36f5de
Reviewed-on: https://chromium-review.googlesource.com/825994Reviewed-by: default avatarAli Juma <ajuma@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarMajid Valipour <majidvp@chromium.org>
Commit-Queue: Sandra Sun <sunyunjia@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525271}
parent 715a1c5f
...@@ -39,6 +39,8 @@ cc_component("cc") { ...@@ -39,6 +39,8 @@ cc_component("cc") {
"input/page_scale_animation.h", "input/page_scale_animation.h",
"input/scroll_elasticity_helper.cc", "input/scroll_elasticity_helper.cc",
"input/scroll_elasticity_helper.h", "input/scroll_elasticity_helper.h",
"input/scroll_snap_data.cc",
"input/scroll_snap_data.h",
"input/scroll_state.cc", "input/scroll_state.cc",
"input/scroll_state.h", "input/scroll_state.h",
"input/scroll_state_data.cc", "input/scroll_state_data.cc",
......
...@@ -2,13 +2,32 @@ ...@@ -2,13 +2,32 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "platform/scroll/ScrollSnapData.h" #include "cc/input/scroll_snap_data.h"
namespace blink { namespace cc {
SnapContainerData::SnapContainerData() : SnapContainerData(ScrollSnapType()) {}
SnapContainerData::SnapContainerData(ScrollSnapType type)
: scroll_snap_type(type) {}
SnapContainerData::SnapContainerData(ScrollSnapType type, gfx::ScrollOffset max)
: scroll_snap_type(type), max_position(max) {}
SnapContainerData::SnapContainerData(const SnapContainerData& other)
: scroll_snap_type(other.scroll_snap_type),
max_position(other.max_position),
snap_area_list(other.snap_area_list) {}
SnapContainerData::~SnapContainerData() {}
void SnapContainerData::AddSnapAreaData(SnapAreaData snap_area_data) {
snap_area_list.push_back(snap_area_data);
}
std::ostream& operator<<(std::ostream& ostream, const SnapAreaData& area_data) { std::ostream& operator<<(std::ostream& ostream, const SnapAreaData& area_data) {
return ostream << area_data.snap_offset.Width() << ", " return ostream << area_data.snap_position.x() << ", "
<< area_data.snap_offset.Height(); << area_data.snap_position.y();
} }
std::ostream& operator<<(std::ostream& ostream, std::ostream& operator<<(std::ostream& ostream,
...@@ -19,4 +38,4 @@ std::ostream& operator<<(std::ostream& ostream, ...@@ -19,4 +38,4 @@ std::ostream& operator<<(std::ostream& ostream,
return ostream; return ostream;
} }
} // namespace blink } // namespace cc
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_INPUT_SCROLL_SNAP_DATA_H_
#define CC_INPUT_SCROLL_SNAP_DATA_H_
#include <vector>
#include "cc/cc_export.h"
#include "ui/gfx/geometry/scroll_offset.h"
namespace cc {
// See https://www.w3.org/TR/css-scroll-snap-1/#snap-axis
enum class SnapAxis : unsigned {
kBoth,
kX,
kY,
kBlock,
kInline,
};
// See https://www.w3.org/TR/css-scroll-snap-1/#snap-strictness
// TODO(sunyunjia): Add kNone for SnapStrictness to match the spec.
// crbug.com/791663
enum class SnapStrictness : unsigned { kProximity, kMandatory };
// See https://www.w3.org/TR/css-scroll-snap-1/#scroll-snap-align
enum class SnapAlignment : unsigned { kNone, kStart, kEnd, kCenter };
struct ScrollSnapType {
ScrollSnapType()
: is_none(true),
axis(SnapAxis::kBoth),
strictness(SnapStrictness::kProximity) {}
ScrollSnapType(bool snap_type_none, SnapAxis axis, SnapStrictness strictness)
: is_none(snap_type_none), axis(axis), strictness(strictness) {}
bool operator==(const ScrollSnapType& other) const {
return is_none == other.is_none && axis == other.axis &&
strictness == other.strictness;
}
bool operator!=(const ScrollSnapType& other) const {
return !(*this == other);
}
// Whether the scroll-snap-type is none or the snap-strictness field has the
// value None.
// TODO(sunyunjia): Consider combining is_none with SnapStrictness.
bool is_none;
SnapAxis axis;
SnapStrictness strictness;
};
struct ScrollSnapAlign {
ScrollSnapAlign()
: alignmentX(SnapAlignment::kNone), alignmentY(SnapAlignment::kNone) {}
explicit ScrollSnapAlign(SnapAlignment alignment)
: alignmentX(alignment), alignmentY(alignment) {}
ScrollSnapAlign(SnapAlignment x, SnapAlignment y)
: alignmentX(x), alignmentY(y) {}
bool operator==(const ScrollSnapAlign& other) const {
return alignmentX == other.alignmentX && alignmentY == other.alignmentY;
}
bool operator!=(const ScrollSnapAlign& other) const {
return !(*this == other);
}
SnapAlignment alignmentX;
SnapAlignment alignmentY;
};
// Snap area is a bounding box that could be snapped to when a scroll happens in
// its scroll container.
// This data structure describes the data needed for SnapCoordinator if we want
// to snap to this snap area.
struct SnapAreaData {
// kInvalidScrollOffset is used to mark that the snap_position on a specific
// axis is not applicable, thus should not be considered when snapping on that
// axis. This is because the snap area has SnapAlignmentNone on that axis.
static const int kInvalidScrollPosition = -1;
SnapAreaData() {}
SnapAreaData(SnapAxis axis, gfx::ScrollOffset position, bool msnap)
: snap_axis(axis), snap_position(position), must_snap(msnap) {}
// The axes along which the area has specified snap positions.
SnapAxis snap_axis;
// The scroll_position to snap the area at the specified alignment in that
// axis.
// This is in the same coordinate with blink's scroll position, which is the
// location of the top/left of the scroll viewport in the top/left of the
// overflow rect.
gfx::ScrollOffset snap_position;
// Whether this area has scroll-snap-stop: always.
// See https://www.w3.org/TR/css-scroll-snap-1/#scroll-snap-stop
bool must_snap;
// TODO(sunyunjia): Add fields for visibility requirement and large area
// snapping.
};
// Snap container is a scroll container that has non-'none' value for
// scroll-snap-type. It can be snapped to one of its snap areas when a scroll
// happens.
// This data structure describes the data needed for SnapCoordinator to perform
// snapping in the snap container.
struct CC_EXPORT SnapContainerData {
SnapContainerData();
explicit SnapContainerData(ScrollSnapType type);
SnapContainerData(ScrollSnapType type, gfx::ScrollOffset max);
SnapContainerData(const SnapContainerData& other);
~SnapContainerData();
void AddSnapAreaData(SnapAreaData snap_area_data);
// Specifies whether a scroll container is a scroll snap container, how
// strictly it snaps, and which axes are considered.
// See https://www.w3.org/TR/css-scroll-snap-1/#scroll-snap-type for details.
ScrollSnapType scroll_snap_type;
// The maximal scroll position of the SnapContainer, in the same coordinate
// with blink's scroll position.
gfx::ScrollOffset max_position;
// 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
// position.
std::vector<SnapAreaData> snap_area_list;
};
CC_EXPORT std::ostream& operator<<(std::ostream&, const SnapAreaData&);
CC_EXPORT std::ostream& operator<<(std::ostream&, const SnapContainerData&);
} // namespace cc
#endif // CC_INPUT_SCROLL_SNAP_DATA_H_
...@@ -13,10 +13,6 @@ ...@@ -13,10 +13,6 @@
namespace blink { namespace blink {
class LayoutBox; class LayoutBox;
struct ScrollSnapType;
struct ScrollSnapAlign;
struct SnapAreaData;
struct SnapContainerData;
// Snap Coordinator keeps track of snap containers and all of their associated // Snap Coordinator keeps track of snap containers and all of their associated
// snap areas. It also contains the logic to generate the list of valid snap // snap areas. It also contains the logic to generate the list of valid snap
...@@ -48,8 +44,7 @@ class CORE_EXPORT SnapCoordinator final ...@@ -48,8 +44,7 @@ class CORE_EXPORT SnapCoordinator final
// container. // container.
SnapAreaData CalculateSnapAreaData(const LayoutBox& snap_area, SnapAreaData CalculateSnapAreaData(const LayoutBox& snap_area,
const LayoutBox& snap_container, const LayoutBox& snap_container,
const ScrollOffset& min_offset, const FloatPoint& max_position);
const ScrollOffset& max_offset);
// Called by LocalFrameView::PerformPostLayoutTasks(), so that the snap data // Called by LocalFrameView::PerformPostLayoutTasks(), so that the snap data
// are updated whenever a layout happens. // are updated whenever a layout happens.
...@@ -65,8 +60,8 @@ class CORE_EXPORT SnapCoordinator final ...@@ -65,8 +60,8 @@ class CORE_EXPORT SnapCoordinator final
bool GetSnapPosition(const LayoutBox& snap_container, bool GetSnapPosition(const LayoutBox& snap_container,
bool did_scroll_x, bool did_scroll_x,
bool did_scroll_y, bool did_scroll_y,
ScrollOffset* snap_offset); FloatPoint* snap_position);
static ScrollOffset FindSnapOffset(const ScrollOffset& current_offset, static FloatPoint FindSnapPosition(const FloatPoint& current_position,
const SnapContainerData&, const SnapContainerData&,
bool should_snap_on_x, bool should_snap_on_x,
bool should_snap_on_y); bool should_snap_on_y);
......
...@@ -1331,7 +1331,6 @@ jumbo_component("platform") { ...@@ -1331,7 +1331,6 @@ jumbo_component("platform") {
"scroll/ScrollAnimatorBase.h", "scroll/ScrollAnimatorBase.h",
"scroll/ScrollAnimatorCompositorCoordinator.cpp", "scroll/ScrollAnimatorCompositorCoordinator.cpp",
"scroll/ScrollAnimatorCompositorCoordinator.h", "scroll/ScrollAnimatorCompositorCoordinator.h",
"scroll/ScrollSnapData.cpp",
"scroll/ScrollSnapData.h", "scroll/ScrollSnapData.h",
"scroll/ScrollStateData.h", "scroll/ScrollStateData.h",
"scroll/ScrollTypes.h", "scroll/ScrollTypes.h",
......
...@@ -5,146 +5,19 @@ ...@@ -5,146 +5,19 @@
#ifndef ScrollSnapData_h #ifndef ScrollSnapData_h
#define ScrollSnapData_h #define ScrollSnapData_h
#include "platform/scroll/ScrollTypes.h" #include "cc/input/scroll_snap_data.h"
#include "platform/wtf/Vector.h"
// This file defines classes and structs used in SnapCoordinator.h // This file defines classes and structs used in SnapCoordinator.h
namespace blink { namespace blink {
// See https://www.w3.org/TR/css-scroll-snap-1/#snap-axis using SnapAxis = cc::SnapAxis;
enum class SnapAxis : unsigned { using SnapStrictness = cc::SnapStrictness;
kBoth, using SnapAlignment = cc::SnapAlignment;
kX, using ScrollSnapType = cc::ScrollSnapType;
kY, using ScrollSnapAlign = cc::ScrollSnapAlign;
kBlock, using SnapAreaData = cc::SnapAreaData;
kInline, using SnapContainerData = cc::SnapContainerData;
};
// See https://www.w3.org/TR/css-scroll-snap-1/#snap-strictness
// TODO(sunyunjia): Add kNone for SnapStrictness to match the spec.
// crbug.com/791663
enum class SnapStrictness : unsigned { kProximity, kMandatory };
// See https://www.w3.org/TR/css-scroll-snap-1/#scroll-snap-align
enum class SnapAlignment : unsigned { kNone, kStart, kEnd, kCenter };
struct ScrollSnapType {
DISALLOW_NEW();
ScrollSnapType()
: is_none(true),
axis(SnapAxis::kBoth),
strictness(SnapStrictness::kProximity) {}
ScrollSnapType(bool snap_type_none, SnapAxis axis, SnapStrictness strictness)
: is_none(snap_type_none), axis(axis), strictness(strictness) {}
bool operator==(const ScrollSnapType& other) const {
return is_none == other.is_none && axis == other.axis &&
strictness == other.strictness;
}
bool operator!=(const ScrollSnapType& other) const {
return !(*this == other);
}
// Whether the scroll-snap-type is none or the snap-strictness field has the
// value None.
// TODO(sunyunjia): Consider combining is_none with SnapStrictness.
bool is_none;
SnapAxis axis;
SnapStrictness strictness;
};
struct ScrollSnapAlign {
DISALLOW_NEW();
ScrollSnapAlign()
: alignmentX(SnapAlignment::kNone), alignmentY(SnapAlignment::kNone) {}
explicit ScrollSnapAlign(SnapAlignment alignment)
: alignmentX(alignment), alignmentY(alignment) {}
ScrollSnapAlign(SnapAlignment x, SnapAlignment y)
: alignmentX(x), alignmentY(y) {}
bool operator==(const ScrollSnapAlign& other) const {
return alignmentX == other.alignmentX && alignmentY == other.alignmentY;
}
bool operator!=(const ScrollSnapAlign& other) const {
return !(*this == other);
}
SnapAlignment alignmentX;
SnapAlignment alignmentY;
};
// Snap area is a bounding box that could be snapped to when a scroll happens in
// its scroll container.
// This data structure describes the data needed for SnapCoordinator if we want
// to snap to this snap area.
struct SnapAreaData {
// kInvalidScrollOffset is used to mark that the snap_offset on a specific
// axis is not applicable, thus should not be considered when snapping on that
// axis. This is because the snap area has SnapAlignmentNone on that axis.
static const int kInvalidScrollOffset = -1;
SnapAreaData() {}
SnapAreaData(SnapAxis axis, ScrollOffset offset, bool msnap)
: snap_axis(axis), snap_offset(offset), must_snap(msnap) {}
// The axes along which the area has specified snap positions.
SnapAxis snap_axis;
// The scroll_offset to snap the area at the specified alignment in that axis.
ScrollOffset snap_offset;
// Whether this area has scroll-snap-stop: always.
// See https://www.w3.org/TR/css-scroll-snap-1/#scroll-snap-stop
bool must_snap;
// TODO(sunyunjia): Add fields for visibility requirement and large area
// snapping.
};
// Snap container is a scroll container that has non-'none' value for
// scroll-snap-type. It can be snapped to one of its snap areas when a scroll
// happens.
// This data structure describes the data needed for SnapCoordinator to perform
// snapping in the snap container.
struct SnapContainerData {
SnapContainerData() : SnapContainerData(ScrollSnapType()) {}
explicit SnapContainerData(ScrollSnapType type) : scroll_snap_type(type) {}
SnapContainerData(ScrollSnapType type, ScrollOffset min, ScrollOffset max)
: scroll_snap_type(type), min_offset(min), max_offset(max) {}
void AddSnapAreaData(SnapAreaData snap_area_data) {
snap_area_list.push_back(snap_area_data);
}
// Specifies whether a scroll container is a scroll snap container, how
// strictly it snaps, and which axes are considered.
// See https://www.w3.org/TR/css-scroll-snap-1/#scroll-snap-type for details.
ScrollSnapType scroll_snap_type;
// The minimal scrollable offset of the SnapContainer.
ScrollOffset min_offset;
// The maximal scrollable offset of the SnapContainer.
ScrollOffset max_offset;
// 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
// position.
Vector<SnapAreaData> snap_area_list;
};
PLATFORM_EXPORT std::ostream& operator<<(std::ostream&, const SnapAreaData&);
PLATFORM_EXPORT std::ostream& operator<<(std::ostream&,
const SnapContainerData&);
} // namespace blink } // namespace blink
......
...@@ -282,6 +282,16 @@ inline ScrollGranularity ToPlatformScrollGranularity( ...@@ -282,6 +282,16 @@ inline ScrollGranularity ToPlatformScrollGranularity(
} }
} }
inline ScrollOffset ScrollPositionToOffset(FloatPoint position,
FloatPoint origin) {
return position - origin;
}
inline FloatPoint ScrollOffsetToPosition(ScrollOffset offset,
FloatPoint origin) {
return origin + offset;
}
typedef unsigned ScrollbarControlPartMask; typedef unsigned ScrollbarControlPartMask;
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment