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