Commit 68d7d9b4 authored by sataya.m's avatar sataya.m Committed by Commit bot

[Android]Optimization of scrollbar animation.

Scrollbar animation is required if scrollbar parameters are changed.
If any of the scrollbar parameters are changed that should trigger the
scrollbar animation. If any of the scrollbar parameter is not changed,
that doesn't require scrollbar animation. Current Patch ensures that
scrollbar is animated only when any of the scrollbar parameter is
changed.

BUG=414238

Review URL: https://codereview.chromium.org/571873003

Cr-Commit-Position: refs/heads/master@{#295978}
parent d69572c0
......@@ -1275,17 +1275,25 @@ void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
current_offset.Scale(layer_tree_impl()->total_page_scale_factor());
}
scrollbar_layer->SetVerticalAdjust(scrollbar_clip_layer->bounds_delta().y());
bool scrollbar_needs_animation = false;
scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust(
scrollbar_clip_layer->bounds_delta().y());
if (scrollbar_layer->orientation() == HORIZONTAL) {
float visible_ratio = clip_rect.width() / scroll_rect.width();
scrollbar_layer->SetCurrentPos(current_offset.x());
scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width());
scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
scrollbar_needs_animation |=
scrollbar_layer->SetCurrentPos(current_offset.x());
scrollbar_needs_animation |=
scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width());
scrollbar_needs_animation |=
scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
} else {
float visible_ratio = clip_rect.height() / scroll_rect.height();
scrollbar_layer->SetCurrentPos(current_offset.y());
scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height());
scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
scrollbar_needs_animation |=
scrollbar_layer->SetCurrentPos(current_offset.y());
scrollbar_needs_animation |=
scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height());
scrollbar_needs_animation |=
scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
}
layer_tree_impl()->set_needs_update_draw_properties();
......@@ -1293,7 +1301,7 @@ void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
// activate for every scroll on the main frame, not just the scrolls that move
// the pinch virtual viewport (i.e. trigger from either inner or outer
// viewport).
if (scrollbar_animation_controller_) {
if (scrollbar_animation_controller_ && scrollbar_needs_animation) {
// When both non-overlay and overlay scrollbars are both present, don't
// animate the overlay scrollbars when page scale factor is at the min.
// Non-overlay scrollbars also shouldn't trigger animations.
......
......@@ -105,42 +105,47 @@ gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect(
return gfx::ToEnclosingRect(content_rect);
}
void ScrollbarLayerImplBase::SetCurrentPos(float current_pos) {
bool ScrollbarLayerImplBase::SetCurrentPos(float current_pos) {
if (current_pos_ == current_pos)
return;
return false;
current_pos_ = current_pos;
NoteLayerPropertyChanged();
return true;
}
void ScrollbarLayerImplBase::SetMaximum(int maximum) {
bool ScrollbarLayerImplBase::SetMaximum(int maximum) {
if (maximum_ == maximum)
return;
return false;
maximum_ = maximum;
NoteLayerPropertyChanged();
return true;
}
void ScrollbarLayerImplBase::SetVerticalAdjust(float vertical_adjust) {
bool ScrollbarLayerImplBase::SetVerticalAdjust(float vertical_adjust) {
if (vertical_adjust_ == vertical_adjust)
return;
return false;
vertical_adjust_ = vertical_adjust;
NoteLayerPropertyChanged();
return true;
}
void ScrollbarLayerImplBase::SetVisibleToTotalLengthRatio(float ratio) {
bool ScrollbarLayerImplBase::SetVisibleToTotalLengthRatio(float ratio) {
if (!IsThumbResizable())
return;
return false;
if (visible_to_total_length_ratio_ == ratio)
return;
return false;
visible_to_total_length_ratio_ = ratio;
NoteLayerPropertyChanged();
return true;
}
void ScrollbarLayerImplBase::SetThumbThicknessScaleFactor(float factor) {
bool ScrollbarLayerImplBase::SetThumbThicknessScaleFactor(float factor) {
if (thumb_thickness_scale_factor_ == factor)
return;
return false;
thumb_thickness_scale_factor_ = factor;
NoteLayerPropertyChanged();
return true;
}
gfx::Rect ScrollbarLayerImplBase::ComputeThumbQuadRect() const {
......
......@@ -28,11 +28,11 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl {
void ClearClipLayer() { clip_layer_ = NULL; }
float current_pos() const { return current_pos_; }
void SetCurrentPos(float current_pos);
bool SetCurrentPos(float current_pos);
int maximum() const { return maximum_; }
void SetMaximum(int maximum);
bool SetMaximum(int maximum);
void SetVerticalAdjust(float vertical_adjust);
bool SetVerticalAdjust(float vertical_adjust);
bool is_overlay_scrollbar() const { return is_overlay_scrollbar_; }
void set_is_overlay_scrollbar(bool is_overlay) {
......@@ -48,13 +48,13 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl {
virtual ScrollbarLayerImplBase* ToScrollbarLayer() OVERRIDE;
void PushScrollClipPropertiesTo(LayerImpl* layer);
void SetVisibleToTotalLengthRatio(float ratio);
bool SetVisibleToTotalLengthRatio(float ratio);
virtual gfx::Rect ComputeThumbQuadRect() const;
float thumb_thickness_scale_factor() {
return thumb_thickness_scale_factor_;
}
void SetThumbThicknessScaleFactor(float thumb_thickness_scale_factor);
bool SetThumbThicknessScaleFactor(float thumb_thickness_scale_factor);
void ScrollbarParametersDidChange();
......
......@@ -1359,7 +1359,7 @@ TEST_F(LayerTreeHostImplTest, ScrollbarLinearFadeScheduling) {
// After a scroll, a fade animation should be scheduled about 20ms from now.
host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0, 5));
host_impl_->ScrollEnd();
did_request_redraw_ = false;
did_request_animate_ = false;
......@@ -1386,6 +1386,12 @@ TEST_F(LayerTreeHostImplTest, ScrollbarLinearFadeScheduling) {
EXPECT_FALSE(did_request_redraw_);
EXPECT_FALSE(did_request_animate_);
requested_scrollbar_animation_delay_ = base::TimeDelta();
// Unnecessarily Fade animation of solid color scrollbar is not triggered.
host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
host_impl_->ScrollEnd();
EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
}
TEST_F(LayerTreeHostImplTest, ScrollbarFadePinchZoomScrollbars) {
......
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