OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/scroll_view.h" | 5 #include "ui/views/controls/scroll_view.h" |
6 | 6 |
7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 } | 692 } |
693 | 693 |
694 void ScrollView::ScrollToOffset(const gfx::ScrollOffset& offset) { | 694 void ScrollView::ScrollToOffset(const gfx::ScrollOffset& offset) { |
695 if (ScrollsWithLayers()) { | 695 if (ScrollsWithLayers()) { |
696 contents_->layer()->SetScrollOffset(offset); | 696 contents_->layer()->SetScrollOffset(offset); |
697 | 697 |
698 // TODO(tapted): Remove this call to OnLayerScrolled(). It's unnecessary, | 698 // TODO(tapted): Remove this call to OnLayerScrolled(). It's unnecessary, |
699 // but will only be invoked (asynchronously) when a Compositor is present | 699 // but will only be invoked (asynchronously) when a Compositor is present |
700 // and commits a frame, which isn't true in some tests. | 700 // and commits a frame, which isn't true in some tests. |
701 // See http://crbug.com/637521. | 701 // See http://crbug.com/637521. |
702 OnLayerScrolled(); | 702 OnLayerScrolled(offset); |
703 } else { | 703 } else { |
704 contents_->SetPosition(gfx::Point(-offset.x(), -offset.y())); | 704 contents_->SetPosition(gfx::Point(-offset.x(), -offset.y())); |
705 ScrollHeader(); | 705 ScrollHeader(); |
706 } | 706 } |
707 } | 707 } |
708 | 708 |
709 bool ScrollView::ScrollsWithLayers() const { | 709 bool ScrollView::ScrollsWithLayers() const { |
710 // Just check for the presence of a layer since it's cheaper than querying the | 710 // Just check for the presence of a layer since it's cheaper than querying the |
711 // Feature flag each time. | 711 // Feature flag each time. |
712 return contents_viewport_->layer() != nullptr; | 712 return contents_viewport_->layer() != nullptr; |
713 } | 713 } |
714 | 714 |
715 void ScrollView::EnableViewPortLayer() { | 715 void ScrollView::EnableViewPortLayer() { |
716 background_color_ = SK_ColorWHITE; | 716 background_color_ = SK_ColorWHITE; |
717 contents_viewport_->set_background( | 717 contents_viewport_->set_background( |
718 Background::CreateSolidBackground(background_color_)); | 718 Background::CreateSolidBackground(background_color_)); |
719 contents_viewport_->SetPaintToLayer(); | 719 contents_viewport_->SetPaintToLayer(); |
720 contents_viewport_->layer()->SetMasksToBounds(true); | 720 contents_viewport_->layer()->SetMasksToBounds(true); |
721 } | 721 } |
722 | 722 |
723 void ScrollView::OnLayerScrolled() { | 723 void ScrollView::OnLayerScrolled(const gfx::ScrollOffset&) { |
724 UpdateScrollBarPositions(); | 724 UpdateScrollBarPositions(); |
725 ScrollHeader(); | 725 ScrollHeader(); |
726 } | 726 } |
727 | 727 |
728 void ScrollView::ScrollHeader() { | 728 void ScrollView::ScrollHeader() { |
729 if (!header_) | 729 if (!header_) |
730 return; | 730 return; |
731 | 731 |
732 int x_offset = CurrentOffset().x(); | 732 int x_offset = CurrentOffset().x(); |
733 if (header_->x() != -x_offset) { | 733 if (header_->x() != -x_offset) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 | 803 |
804 VariableRowHeightScrollHelper::RowInfo | 804 VariableRowHeightScrollHelper::RowInfo |
805 FixedRowHeightScrollHelper::GetRowInfo(int y) { | 805 FixedRowHeightScrollHelper::GetRowInfo(int y) { |
806 if (y < top_margin_) | 806 if (y < top_margin_) |
807 return RowInfo(0, top_margin_); | 807 return RowInfo(0, top_margin_); |
808 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, | 808 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, |
809 row_height_); | 809 row_height_); |
810 } | 810 } |
811 | 811 |
812 } // namespace views | 812 } // namespace views |
OLD | NEW |