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 #ifndef UI_VIEWS_CONTROLS_SCROLL_VIEW_H_ | 5 #ifndef UI_VIEWS_CONTROLS_SCROLL_VIEW_H_ |
6 #define UI_VIEWS_CONTROLS_SCROLL_VIEW_H_ | 6 #define UI_VIEWS_CONTROLS_SCROLL_VIEW_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "ui/views/controls/scrollbar/scroll_bar.h" | 13 #include "ui/views/controls/scrollbar/scroll_bar.h" |
14 | 14 |
15 namespace gfx { | 15 namespace gfx { |
16 class ScrollOffset; | 16 class ScrollOffset; |
17 } | 17 } |
18 | 18 |
19 namespace views { | 19 namespace views { |
| 20 class ViewObserverTest; |
| 21 |
20 namespace test { | 22 namespace test { |
21 class ScrollViewTestApi; | 23 class ScrollViewTestApi; |
22 } | 24 } |
23 | 25 |
24 ///////////////////////////////////////////////////////////////////////////// | 26 ///////////////////////////////////////////////////////////////////////////// |
25 // | 27 // |
26 // ScrollView class | 28 // ScrollView class |
27 // | 29 // |
28 // A ScrollView is used to make any View scrollable. The view is added to | 30 // A ScrollView is used to make any View scrollable. The view is added to |
29 // a viewport which takes care of clipping. | 31 // a viewport which takes care of clipping. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // View overrides: | 100 // View overrides: |
99 gfx::Size GetPreferredSize() const override; | 101 gfx::Size GetPreferredSize() const override; |
100 int GetHeightForWidth(int width) const override; | 102 int GetHeightForWidth(int width) const override; |
101 void Layout() override; | 103 void Layout() override; |
102 bool OnKeyPressed(const ui::KeyEvent& event) override; | 104 bool OnKeyPressed(const ui::KeyEvent& event) override; |
103 bool OnMouseWheel(const ui::MouseWheelEvent& e) override; | 105 bool OnMouseWheel(const ui::MouseWheelEvent& e) override; |
104 void OnScrollEvent(ui::ScrollEvent* event) override; | 106 void OnScrollEvent(ui::ScrollEvent* event) override; |
105 void OnGestureEvent(ui::GestureEvent* event) override; | 107 void OnGestureEvent(ui::GestureEvent* event) override; |
106 const char* GetClassName() const override; | 108 const char* GetClassName() const override; |
107 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 109 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 110 void ViewHierarchyChanged( |
| 111 const ViewHierarchyChangedDetails& details) override; |
| 112 void OnChildLayerChanged(View* child) override; |
108 | 113 |
109 // ScrollBarController overrides: | 114 // ScrollBarController overrides: |
110 void ScrollToPosition(ScrollBar* source, int position) override; | 115 void ScrollToPosition(ScrollBar* source, int position) override; |
111 int GetScrollIncrement(ScrollBar* source, | 116 int GetScrollIncrement(ScrollBar* source, |
112 bool is_page, | 117 bool is_page, |
113 bool is_positive) override; | 118 bool is_positive) override; |
114 | 119 |
115 // TODO(djacobo): Remove this method when http://crbug.com/656198 is closed. | 120 // TODO(djacobo): Remove this method when http://crbug.com/656198 is closed. |
116 // Force |contents_viewport_| to enable a Layer(). | 121 // Force |contents_viewport_| to enable a Layer(). |
117 void EnableViewPortLayer(); | 122 void EnableViewPortLayer(); |
118 | 123 |
119 private: | 124 private: |
120 friend class test::ScrollViewTestApi; | 125 friend class test::ScrollViewTestApi; |
| 126 FRIEND_TEST_ALL_PREFIXES(ViewObserverTest, ScrollViewChildAddLayerTest); |
121 | 127 |
122 class Viewport; | 128 class Viewport; |
123 | 129 |
124 // Used internally by SetHeader() and SetContents() to reset the view. Sets | 130 // Used internally by SetHeader() and SetContents() to reset the view. Sets |
125 // |member| to |new_view|. If |new_view| is non-null it is added to |parent|. | 131 // |member| to |new_view|. If |new_view| is non-null it is added to |parent|. |
126 void SetHeaderOrContents(View* parent, View* new_view, View** member); | 132 void SetHeaderOrContents(View* parent, View* new_view, View** member); |
127 | 133 |
128 // Scrolls the minimum amount necessary to make the specified rectangle | 134 // Scrolls the minimum amount necessary to make the specified rectangle |
129 // visible, in the coordinates of the contents view. The specified rectangle | 135 // visible, in the coordinates of the contents view. The specified rectangle |
130 // is constrained by the bounds of the contents view. This has no effect if | 136 // is constrained by the bounds of the contents view. This has no effect if |
(...skipping 24 matching lines...) Expand all Loading... |
155 | 161 |
156 // Callback entrypoint when hosted Layers are scrolled by the Compositor. | 162 // Callback entrypoint when hosted Layers are scrolled by the Compositor. |
157 void OnLayerScrolled(const gfx::ScrollOffset& offset); | 163 void OnLayerScrolled(const gfx::ScrollOffset& offset); |
158 | 164 |
159 // Horizontally scrolls the header (if any) to match the contents. | 165 // Horizontally scrolls the header (if any) to match the contents. |
160 void ScrollHeader(); | 166 void ScrollHeader(); |
161 | 167 |
162 void AddBorder(); | 168 void AddBorder(); |
163 void UpdateBorder(); | 169 void UpdateBorder(); |
164 | 170 |
| 171 // Enables view port layering if |child| or any of its descendants has a |
| 172 // layer. Returns true if yes. We short circuit the recursion if we enabled |
| 173 // layering. |
| 174 bool EnableLayeringRecursivelyForChild(View* child); |
| 175 |
165 // The current contents and its viewport. |contents_| is contained in | 176 // The current contents and its viewport. |contents_| is contained in |
166 // |contents_viewport_|. | 177 // |contents_viewport_|. |
167 View* contents_; | 178 View* contents_; |
168 View* contents_viewport_; | 179 View* contents_viewport_; |
169 | 180 |
170 // The current header and its viewport. |header_| is contained in | 181 // The current header and its viewport. |header_| is contained in |
171 // |header_viewport_|. | 182 // |header_viewport_|. |
172 View* header_; | 183 View* header_; |
173 View* header_viewport_; | 184 View* header_viewport_; |
174 | 185 |
(...skipping 22 matching lines...) Expand all Loading... |
197 // In Harmony, the indicator is a focus ring. Pre-Harmony, the indicator is a | 208 // In Harmony, the indicator is a focus ring. Pre-Harmony, the indicator is a |
198 // different border painter. | 209 // different border painter. |
199 bool draw_focus_indicator_ = false; | 210 bool draw_focus_indicator_ = false; |
200 | 211 |
201 // Only needed for pre-Harmony. Remove when Harmony is default. | 212 // Only needed for pre-Harmony. Remove when Harmony is default. |
202 bool draw_border_ = false; | 213 bool draw_border_ = false; |
203 | 214 |
204 // Focus ring, if one is installed. | 215 // Focus ring, if one is installed. |
205 View* focus_ring_ = nullptr; | 216 View* focus_ring_ = nullptr; |
206 | 217 |
| 218 // Set to true if we enabled layering for the viewport. |
| 219 bool viewport_layer_enabled_ = false; |
| 220 |
| 221 // Set to true if the scroll with layers feature is enabled. |
| 222 const bool scroll_with_layers_enabled_; |
| 223 |
207 DISALLOW_COPY_AND_ASSIGN(ScrollView); | 224 DISALLOW_COPY_AND_ASSIGN(ScrollView); |
208 }; | 225 }; |
209 | 226 |
210 // VariableRowHeightScrollHelper is intended for views that contain rows of | 227 // VariableRowHeightScrollHelper is intended for views that contain rows of |
211 // varying height. To use a VariableRowHeightScrollHelper create one supplying | 228 // varying height. To use a VariableRowHeightScrollHelper create one supplying |
212 // a Controller and delegate GetPageScrollIncrement and GetLineScrollIncrement | 229 // a Controller and delegate GetPageScrollIncrement and GetLineScrollIncrement |
213 // to the helper. VariableRowHeightScrollHelper calls back to the | 230 // to the helper. VariableRowHeightScrollHelper calls back to the |
214 // Controller to determine row boundaries. | 231 // Controller to determine row boundaries. |
215 class VariableRowHeightScrollHelper { | 232 class VariableRowHeightScrollHelper { |
216 public: | 233 public: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 private: | 290 private: |
274 int top_margin_; | 291 int top_margin_; |
275 int row_height_; | 292 int row_height_; |
276 | 293 |
277 DISALLOW_COPY_AND_ASSIGN(FixedRowHeightScrollHelper); | 294 DISALLOW_COPY_AND_ASSIGN(FixedRowHeightScrollHelper); |
278 }; | 295 }; |
279 | 296 |
280 } // namespace views | 297 } // namespace views |
281 | 298 |
282 #endif // UI_VIEWS_CONTROLS_SCROLL_VIEW_H_ | 299 #endif // UI_VIEWS_CONTROLS_SCROLL_VIEW_H_ |
OLD | NEW |