Skip to content

Commit

Permalink
Make cc::Layer's scroll offset for layer tree mode only
Browse files Browse the repository at this point in the history
cc::Layer's scroll offset should just for layer tree mode as the input
of cc::PropertyTreeBuilder. In layer list mode, blink generates all
paint properties, and cc should use the paint properties instead of
the layer properties.

(TBR for a trivial change under compositor/ui/layer.cc due to rename
 of cc::Layer::paint_offset)
TBR=wangxianzhu@chromium.org

Change-Id: I5865e4a98f0c4c6957ed117b9de189fd7bd84a00
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2020554
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: Philip Rogers <pdr@chromium.org>
Reviewed-by: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737560}
  • Loading branch information
wangxianzhu authored and Commit Bot committed Feb 1, 2020
1 parent 42ca349 commit bfad4b4
Show file tree
Hide file tree
Showing 42 changed files with 868 additions and 1,053 deletions.
22 changes: 10 additions & 12 deletions cc/input/scrollbar_animation_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ class ScrollbarAnimationControllerAuraOverlayTest
clip_layer_ = root_layer();
clip_layer_->SetBounds(gfx::Size(100, 100));

scroll_layer_->SetScrollable(gfx::Size(100, 100));
scroll_layer_->SetBounds(gfx::Size(200, 200));
CopyProperties(clip_layer_, scroll_layer_);
CreateTransformNode(scroll_layer_);
CreateScrollNode(scroll_layer_);
CreateScrollNode(scroll_layer_, gfx::Size(100, 100));

v_scrollbar_layer_->SetBounds(gfx::Size(kThumbThickness, kTrackLength));
v_scrollbar_layer_->SetScrollElementId(scroll_layer_->element_id());
Expand Down Expand Up @@ -171,16 +170,16 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, AppearOnResize) {

// Make the Layer non-scrollable, scrollbar disappears.
clip_layer_->SetBounds(gfx::Size(200, 200));
scroll_layer_->SetScrollable(gfx::Size(200, 200));
GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(200, 200);
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();
scrollbar_controller_->DidScrollUpdate();
ExpectScrollbarsOpacity(0);

// Make the layer scrollable, scrollbar appears again.
clip_layer_->SetBounds(gfx::Size(100, 100));
scroll_layer_->SetScrollable(gfx::Size(100, 100));
GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(100, 100);
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();
scrollbar_controller_->DidScrollUpdate();
ExpectScrollbarsOpacity(1);
Expand All @@ -196,8 +195,8 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, HideOnResize) {
// Shrink along X axis, horizontal scrollbar should appear.
clip_layer_->SetBounds(gfx::Size(100, 200));
EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds());
scroll_layer_->SetScrollable(gfx::Size(100, 200));
GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(100, 200);
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();

scrollbar_controller_->DidScrollBegin();
Expand All @@ -211,8 +210,8 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, HideOnResize) {
// should disappear.
clip_layer_->SetBounds(gfx::Size(200, 100));
EXPECT_EQ(gfx::Size(200, 100), clip_layer_->bounds());
scroll_layer_->SetScrollable(gfx::Size(200, 100));
GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(200, 100);
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();

scrollbar_controller_->DidScrollBegin();
Expand Down Expand Up @@ -1386,10 +1385,9 @@ class ScrollbarAnimationControllerAndroidTest
SetElementIdsForTesting();

scroll_layer_->SetBounds(gfx::Size(200, 200));
scroll_layer_->SetScrollable(gfx::Size(100, 100));
CopyProperties(root, scroll_layer_);
CreateTransformNode(scroll_layer_);
CreateScrollNode(scroll_layer_);
CreateScrollNode(scroll_layer_, gfx::Size(100, 100));

scrollbar_layer_->SetScrollElementId(scroll_layer_->element_id());
CopyProperties(scroll_layer_, scrollbar_layer_);
Expand Down Expand Up @@ -1472,8 +1470,8 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnResize) {
EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation());

// Shrink along X axis, horizontal scrollbar should appear.
scroll_layer_->SetScrollable(gfx::Size(100, 200));
GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(100, 200);
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();
scrollbar_controller_->DidScrollBegin();

Expand All @@ -1483,8 +1481,8 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnResize) {

// Shrink along Y axis and expand along X, horizontal scrollbar
// should disappear.
scroll_layer_->SetScrollable(gfx::Size(200, 100));
GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(200, 100);
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();

scrollbar_controller_->DidScrollBegin();
Expand All @@ -1501,8 +1499,8 @@ TEST_F(VerticalScrollbarAnimationControllerAndroidTest, HideOnResize) {
EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation());

// Shrink along X axis, vertical scrollbar should remain invisible.
scroll_layer_->SetScrollable(gfx::Size(100, 200));
GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(100, 200);
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();
scrollbar_controller_->DidScrollBegin();

Expand All @@ -1511,8 +1509,8 @@ TEST_F(VerticalScrollbarAnimationControllerAndroidTest, HideOnResize) {
scrollbar_controller_->DidScrollEnd();

// Shrink along Y axis and expand along X, vertical scrollbar should appear.
scroll_layer_->SetScrollable(gfx::Size(200, 100));
GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(200, 100);
scroll_layer_->UpdateScrollable();
UpdateActiveTreeDrawProperties();

scrollbar_controller_->DidScrollBegin();
Expand Down
40 changes: 19 additions & 21 deletions cc/input/scrollbar_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,17 +403,10 @@ float ScrollbarController::GetScrollerToScrollbarRatio(
scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? thumb_rect.height()
: thumb_rect.width();
int viewport_length = GetViewportLength(scrollbar);

const LayerImpl* owner_scroll_layer =
layer_tree_host_impl_->active_tree()->ScrollableLayerByElementId(
scrollbar->scroll_element_id());
const float viewport_length =
scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? owner_scroll_layer->scroll_container_bounds().height()
: (owner_scroll_layer->scroll_container_bounds().width());

return ((scroll_layer_length - viewport_length) /
(scrollbar_track_length - scrollbar_thumb_length));
return (scroll_layer_length - viewport_length) /
(scrollbar_track_length - scrollbar_thumb_length);
}

void ScrollbarController::ResetState() {
Expand Down Expand Up @@ -597,34 +590,39 @@ LayerImpl* ScrollbarController::GetLayerHitByPoint(
return layer_impl;
}

int ScrollbarController::GetViewportLength(
const ScrollbarLayerImplBase* scrollbar) const {
const ScrollNode* scroll_node =
layer_tree_host_impl_->active_tree()
->property_trees()
->scroll_tree.FindNodeFromElementId(scrollbar->scroll_element_id());
DCHECK(scroll_node);
return scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? scroll_node->container_bounds.height()
: scroll_node->container_bounds.width();
}

int ScrollbarController::GetScrollDeltaForScrollbarPart(
const ScrollbarLayerImplBase* scrollbar,
const ScrollbarPart scrollbar_part,
const bool shift_modifier) {
int scroll_delta = 0;
int viewport_length = 0;
LayerImpl* owner_scroll_layer = nullptr;

switch (scrollbar_part) {
case ScrollbarPart::BACK_BUTTON:
case ScrollbarPart::FORWARD_BUTTON:
scroll_delta = kPixelsPerLineStep * ScreenSpaceScaleFactor();
break;
case ScrollbarPart::BACK_TRACK:
case ScrollbarPart::FORWARD_TRACK:
case ScrollbarPart::FORWARD_TRACK: {
if (shift_modifier) {
scroll_delta = GetScrollDeltaForAbsoluteJump(scrollbar);
break;
}
owner_scroll_layer =
layer_tree_host_impl_->active_tree()->ScrollableLayerByElementId(
scrollbar->scroll_element_id());
viewport_length =
scrollbar->orientation() == ScrollbarOrientation::VERTICAL
? owner_scroll_layer->scroll_container_bounds().height()
: (owner_scroll_layer->scroll_container_bounds().width());
scroll_delta = viewport_length * kMinFractionToStepWhenPaging;
scroll_delta =
GetViewportLength(scrollbar) * kMinFractionToStepWhenPaging;
break;
}
default:
scroll_delta = 0;
}
Expand Down
3 changes: 3 additions & 0 deletions cc/input/scrollbar_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ class CC_EXPORT ScrollbarController {
// Returns the ratio of the scroller length to the scrollbar length. This is
// needed to scale the scroll delta for thumb drag.
float GetScrollerToScrollbarRatio(const ScrollbarLayerImplBase* scrollbar);

int GetViewportLength(const ScrollbarLayerImplBase* scrollbar) const;

LayerTreeHostImpl* layer_tree_host_impl_;

// Used to safeguard against firing GSE without firing GSB and GSU. For
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class SingleScrollbarAnimationControllerThinningTest
root_layer()->SetBounds(gfx::Size(100, 100));
auto* scroll_layer = AddLayer<LayerImpl>();
scroll_layer->SetBounds(gfx::Size(200, 200));
scroll_layer->SetScrollable(gfx::Size(100, 100));
scroll_layer->SetElementId(
LayerIdToElementIdForTesting(scroll_layer->id()));

Expand All @@ -79,7 +78,7 @@ class SingleScrollbarAnimationControllerThinningTest

CopyProperties(root_layer(), scroll_layer);
CreateTransformNode(scroll_layer);
CreateScrollNode(scroll_layer);
CreateScrollNode(scroll_layer, gfx::Size(100, 100));
CopyProperties(scroll_layer, scrollbar_layer_);
scrollbar_layer_->SetOffsetToTransformParent(gfx::Vector2dF(90, 0));
CreateEffectNode(scrollbar_layer_).has_potential_opacity_animation = true;
Expand Down
Loading

0 comments on commit bfad4b4

Please sign in to comment.