| 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/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 EXPECT_EQ(fully_scrolled.x(), test_api.CurrentOffset().x()); | 862 EXPECT_EQ(fully_scrolled.x(), test_api.CurrentOffset().x()); |
| 863 | 863 |
| 864 // And 77 pixels wider should scroll left. Also make it short again: the y- | 864 // And 77 pixels wider should scroll left. Also make it short again: the y- |
| 865 // offset from the last change should remain. | 865 // offset from the last change should remain. |
| 866 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 177, 100)); | 866 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 177, 100)); |
| 867 scroll_view_.Layout(); | 867 scroll_view_.Layout(); |
| 868 EXPECT_EQ(fully_scrolled.y() - 55, test_api.CurrentOffset().y()); | 868 EXPECT_EQ(fully_scrolled.y() - 55, test_api.CurrentOffset().y()); |
| 869 EXPECT_EQ(fully_scrolled.x() - 77, test_api.CurrentOffset().x()); | 869 EXPECT_EQ(fully_scrolled.x() - 77, test_api.CurrentOffset().x()); |
| 870 } | 870 } |
| 871 | 871 |
| 872 // Calling Layout on ScrollView should not reset the scroll location. | |
| 873 TEST_F(ScrollViewTest, ContentScrollNotResetOnLayout) { | |
| 874 ScrollViewTestApi test_api(&scroll_view_); | |
| 875 | |
| 876 CustomView* contents = new CustomView; | |
| 877 contents->SetPreferredSize(gfx::Size(300, 300)); | |
| 878 scroll_view_.SetContents(contents); | |
| 879 scroll_view_.ClipHeightTo(0, 150); | |
| 880 scroll_view_.SizeToPreferredSize(); | |
| 881 // ScrollView preferred width matches that of |contents|, with the height | |
| 882 // capped at the value we clipped to. | |
| 883 EXPECT_EQ(gfx::Size(300, 150), scroll_view_.size()); | |
| 884 | |
| 885 // Scroll down. | |
| 886 scroll_view_.ScrollToPosition( | |
| 887 const_cast<ScrollBar*>(scroll_view_.vertical_scroll_bar()), 25); | |
| 888 EXPECT_EQ(25, test_api.CurrentOffset().y()); | |
| 889 // Call Layout; no change to scroll position. | |
| 890 scroll_view_.Layout(); | |
| 891 EXPECT_EQ(25, test_api.CurrentOffset().y()); | |
| 892 // Change contents of |contents|, call Layout; still no change to scroll | |
| 893 // position. | |
| 894 contents->SetPreferredSize(gfx::Size(300, 500)); | |
| 895 contents->InvalidateLayout(); | |
| 896 scroll_view_.Layout(); | |
| 897 EXPECT_EQ(25, test_api.CurrentOffset().y()); | |
| 898 | |
| 899 // Change |contents| to be shorter than the ScrollView's clipped height. | |
| 900 // This /will/ change the scroll location due to ConstrainScrollToBounds. | |
| 901 contents->SetPreferredSize(gfx::Size(300, 50)); | |
| 902 scroll_view_.Layout(); | |
| 903 EXPECT_EQ(0, test_api.CurrentOffset().y()); | |
| 904 } | |
| 905 | |
| 906 // Test scrolling behavior when clicking on the scroll track. | 872 // Test scrolling behavior when clicking on the scroll track. |
| 907 TEST_F(WidgetScrollViewTest, ScrollTrackScrolling) { | 873 TEST_F(WidgetScrollViewTest, ScrollTrackScrolling) { |
| 908 // Set up with a vertical scroller. | 874 // Set up with a vertical scroller. |
| 909 ScrollView* scroll_view = | 875 ScrollView* scroll_view = |
| 910 AddScrollViewWithContentSize(gfx::Size(10, kDefaultHeight * 5)); | 876 AddScrollViewWithContentSize(gfx::Size(10, kDefaultHeight * 5)); |
| 911 ScrollViewTestApi test_api(scroll_view); | 877 ScrollViewTestApi test_api(scroll_view); |
| 912 BaseScrollBar* scroll_bar = test_api.GetBaseScrollBar(VERTICAL); | 878 BaseScrollBar* scroll_bar = test_api.GetBaseScrollBar(VERTICAL); |
| 913 View* thumb = test_api.GetScrollBarThumb(VERTICAL); | 879 View* thumb = test_api.GetScrollBarThumb(VERTICAL); |
| 914 | 880 |
| 915 // Click in the middle of the track, ensuring it's below the thumb. | 881 // Click in the middle of the track, ensuring it's below the thumb. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 // Scroll via ScrollView API. Should be reflected on the impl side. | 987 // Scroll via ScrollView API. Should be reflected on the impl side. |
| 1022 offset.set_y(kDefaultHeight * 4); | 988 offset.set_y(kDefaultHeight * 4); |
| 1023 scroll_view->contents()->ScrollRectToVisible(offset); | 989 scroll_view->contents()->ScrollRectToVisible(offset); |
| 1024 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); | 990 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); |
| 1025 | 991 |
| 1026 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); | 992 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); |
| 1027 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); | 993 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); |
| 1028 } | 994 } |
| 1029 | 995 |
| 1030 } // namespace views | 996 } // namespace views |
| OLD | NEW |