| 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" |
| 11 #include "base/tuple.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/views/border.h" | 13 #include "ui/views/border.h" |
| 13 #include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h" | 14 #include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h" |
| 14 #include "ui/views/controls/scrollbar/native_scroll_bar.h" | 15 #include "ui/views/controls/scrollbar/native_scroll_bar.h" |
| 15 #include "ui/views/controls/scrollbar/native_scroll_bar_views.h" | 16 #include "ui/views/controls/scrollbar/native_scroll_bar_views.h" |
| 16 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" | 17 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" |
| 17 #include "ui/views/test/test_views.h" | 18 #include "ui/views/test/test_views.h" |
| 18 #include "ui/views/test/widget_test.h" | 19 #include "ui/views/test/widget_test.h" |
| 19 | 20 |
| 20 #if defined(OS_MACOSX) | 21 #if defined(OS_MACOSX) |
| 21 #include "ui/base/test/scoped_preferred_scroller_style_mac.h" | 22 #include "ui/base/test/scoped_preferred_scroller_style_mac.h" |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 25 namespace base { |
| 26 namespace internal { |
| 27 |
| 28 template <typename... Args> |
| 29 struct EmplaceUniqueResult { |
| 30 using Tuple = std::tuple<Args...>; |
| 31 Tuple params; |
| 32 |
| 33 EmplaceUniqueResult(Args&&... args) |
| 34 : params(std::forward<Args...>(args...)) {} |
| 35 |
| 36 template <class T, std::size_t... I> |
| 37 T* CreateNewT(IndexSequence<I...>) { |
| 38 return new T(std::get<I>(params)...); |
| 39 } |
| 40 |
| 41 template <class T> |
| 42 using UniquePtr = std::unique_ptr<T>; // Avoids a presumbmit error. |
| 43 |
| 44 template <class T> |
| 45 operator UniquePtr<T>() { |
| 46 return UniquePtr<T>(CreateNewT<T>(MakeIndexSequenceForTuple<Tuple>())); |
| 47 } |
| 48 }; |
| 49 |
| 50 } // namespace internal |
| 51 |
| 52 template <typename... Args> |
| 53 typename internal::EmplaceUniqueResult<Args...> EmplaceUnique(Args&&... args) { |
| 54 return internal::EmplaceUniqueResult<Args...>(std::forward<Args...>(args...)); |
| 55 } |
| 56 |
| 57 } // namespace base |
| 58 |
| 24 enum ScrollBarOrientation { HORIZONTAL, VERTICAL }; | 59 enum ScrollBarOrientation { HORIZONTAL, VERTICAL }; |
| 25 | 60 |
| 26 namespace views { | 61 namespace views { |
| 27 namespace test { | 62 namespace test { |
| 28 | 63 |
| 29 class ScrollViewTestApi { | 64 class ScrollViewTestApi { |
| 30 public: | 65 public: |
| 31 explicit ScrollViewTestApi(ScrollView* scroll_view) | 66 explicit ScrollViewTestApi(ScrollView* scroll_view) |
| 32 : scroll_view_(scroll_view) {} | 67 : scroll_view_(scroll_view) {} |
| 33 | 68 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 scroll_view_.SetBoundsRect(default_outer_bounds); | 179 scroll_view_.SetBoundsRect(default_outer_bounds); |
| 145 return contents; | 180 return contents; |
| 146 } | 181 } |
| 147 | 182 |
| 148 protected: | 183 protected: |
| 149 #if defined(OS_MACOSX) | 184 #if defined(OS_MACOSX) |
| 150 void SetOverlayScrollersEnabled(bool enabled) { | 185 void SetOverlayScrollersEnabled(bool enabled) { |
| 151 // Ensure the old scroller override is destroyed before creating a new one. | 186 // Ensure the old scroller override is destroyed before creating a new one. |
| 152 // Otherwise, the swizzlers are interleaved and restore incorrect methods. | 187 // Otherwise, the swizzlers are interleaved and restore incorrect methods. |
| 153 scroller_style_.reset(); | 188 scroller_style_.reset(); |
| 154 scroller_style_ = | 189 scroller_style_ = base::EmplaceUnique(enabled); |
| 155 base::MakeUnique<ui::test::ScopedPreferredScrollerStyle>(enabled); | |
| 156 } | 190 } |
| 157 | 191 |
| 158 private: | 192 private: |
| 159 // Disable overlay scrollers by default. This needs to be set before | 193 // Disable overlay scrollers by default. This needs to be set before |
| 160 // |scroll_view_| is initialized, otherwise scrollers will try to animate to | 194 // |scroll_view_| is initialized, otherwise scrollers will try to animate to |
| 161 // change modes, which requires a MessageLoop to exist. Tests should only | 195 // change modes, which requires a MessageLoop to exist. Tests should only |
| 162 // modify this via SetOverlayScrollersEnabled(). | 196 // modify this via SetOverlayScrollersEnabled(). |
| 163 std::unique_ptr<ui::test::ScopedPreferredScrollerStyle> scroller_style_ = | 197 std::unique_ptr<ui::test::ScopedPreferredScrollerStyle> scroller_style_ = |
| 164 base::MakeUnique<ui::test::ScopedPreferredScrollerStyle>(false); | 198 base::MakeUnique<ui::test::ScopedPreferredScrollerStyle>(false); |
| 165 | 199 |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 // Scroll via ScrollView API. Should be reflected on the impl side. | 928 // Scroll via ScrollView API. Should be reflected on the impl side. |
| 895 offset.set_y(kDefaultHeight * 4); | 929 offset.set_y(kDefaultHeight * 4); |
| 896 scroll_view->contents()->ScrollRectToVisible(offset); | 930 scroll_view->contents()->ScrollRectToVisible(offset); |
| 897 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); | 931 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); |
| 898 | 932 |
| 899 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); | 933 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); |
| 900 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); | 934 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); |
| 901 } | 935 } |
| 902 | 936 |
| 903 } // namespace views | 937 } // namespace views |
| OLD | NEW |