Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: ui/views/controls/scroll_view.cc

Issue 462373002: Allow the native theme to paint the corner between scrollbars (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/logging.h" 7 #include "base/logging.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/gfx/canvas.h"
9 #include "ui/native_theme/native_theme.h" 10 #include "ui/native_theme/native_theme.h"
10 #include "ui/views/border.h" 11 #include "ui/views/border.h"
11 #include "ui/views/controls/scrollbar/native_scroll_bar.h" 12 #include "ui/views/controls/scrollbar/native_scroll_bar.h"
12 #include "ui/views/widget/root_view.h" 13 #include "ui/views/widget/root_view.h"
13 14
14 namespace views { 15 namespace views {
15 16
16 const char ScrollView::kViewClassName[] = "ScrollView"; 17 const char ScrollView::kViewClassName[] = "ScrollView";
17 18
18 namespace { 19 namespace {
19 20
20 // Subclass of ScrollView that resets the border when the theme changes. 21 // Subclass of ScrollView that resets the border when the theme changes.
21 class ScrollViewWithBorder : public views::ScrollView { 22 class ScrollViewWithBorder : public views::ScrollView {
22 public: 23 public:
23 ScrollViewWithBorder() {} 24 ScrollViewWithBorder() {}
24 25
25 // View overrides; 26 // View overrides;
26 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE { 27 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE {
27 SetBorder(Border::CreateSolidBorder( 28 SetBorder(Border::CreateSolidBorder(
28 1, 29 1,
29 theme->GetSystemColor(ui::NativeTheme::kColorId_UnfocusedBorderColor))); 30 theme->GetSystemColor(ui::NativeTheme::kColorId_UnfocusedBorderColor)));
30 } 31 }
31 32
32 private: 33 private:
33 DISALLOW_COPY_AND_ASSIGN(ScrollViewWithBorder); 34 DISALLOW_COPY_AND_ASSIGN(ScrollViewWithBorder);
34 }; 35 };
35 36
37 class ScrollCornerView : public views::View {
38 public:
39 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
40 ui::NativeTheme::ExtraParams ignored;
41 GetNativeTheme()->Paint(canvas->sk_canvas(),
42 ui::NativeTheme::kScrollbarCorner,
43 ui::NativeTheme::kNormal,
44 GetLocalBounds(),
45 ignored);
46 }
47 };
sky 2014/08/13 03:33:11 private: DISALLOW...
Andre 2014/08/13 17:53:35 Done.
48
36 // Returns the position for the view so that it isn't scrolled off the visible 49 // Returns the position for the view so that it isn't scrolled off the visible
37 // region. 50 // region.
38 int CheckScrollBounds(int viewport_size, int content_size, int current_pos) { 51 int CheckScrollBounds(int viewport_size, int content_size, int current_pos) {
39 int max = std::max(content_size - viewport_size, 0); 52 int max = std::max(content_size - viewport_size, 0);
40 if (current_pos < 0) 53 if (current_pos < 0)
41 return 0; 54 return 0;
42 if (current_pos > max) 55 if (current_pos > max)
43 return max; 56 return max;
44 return current_pos; 57 return current_pos;
45 } 58 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 DISALLOW_COPY_AND_ASSIGN(Viewport); 115 DISALLOW_COPY_AND_ASSIGN(Viewport);
103 }; 116 };
104 117
105 ScrollView::ScrollView() 118 ScrollView::ScrollView()
106 : contents_(NULL), 119 : contents_(NULL),
107 contents_viewport_(new Viewport()), 120 contents_viewport_(new Viewport()),
108 header_(NULL), 121 header_(NULL),
109 header_viewport_(new Viewport()), 122 header_viewport_(new Viewport()),
110 horiz_sb_(new NativeScrollBar(true)), 123 horiz_sb_(new NativeScrollBar(true)),
111 vert_sb_(new NativeScrollBar(false)), 124 vert_sb_(new NativeScrollBar(false)),
112 resize_corner_(NULL), 125 corner_view_(new ScrollCornerView()),
113 min_height_(-1), 126 min_height_(-1),
114 max_height_(-1), 127 max_height_(-1),
115 hide_horizontal_scrollbar_(false) { 128 hide_horizontal_scrollbar_(false) {
116 set_notify_enter_exit_on_child(true); 129 set_notify_enter_exit_on_child(true);
117 130
118 AddChildView(contents_viewport_); 131 AddChildView(contents_viewport_);
119 AddChildView(header_viewport_); 132 AddChildView(header_viewport_);
120 133
121 // Don't add the scrollbars as children until we discover we need them 134 // Don't add the scrollbars as children until we discover we need them
122 // (ShowOrHideScrollBar). 135 // (ShowOrHideScrollBar).
123 horiz_sb_->SetVisible(false); 136 horiz_sb_->SetVisible(false);
124 horiz_sb_->set_controller(this); 137 horiz_sb_->set_controller(this);
125 vert_sb_->SetVisible(false); 138 vert_sb_->SetVisible(false);
126 vert_sb_->set_controller(this); 139 vert_sb_->set_controller(this);
127 if (resize_corner_) 140 corner_view_->SetVisible(false);
128 resize_corner_->SetVisible(false);
129 } 141 }
130 142
131 ScrollView::~ScrollView() { 143 ScrollView::~ScrollView() {
132 // The scrollbars may not have been added, delete them to ensure they get 144 // The scrollbars may not have been added, delete them to ensure they get
133 // deleted. 145 // deleted.
134 delete horiz_sb_; 146 delete horiz_sb_;
135 delete vert_sb_; 147 delete vert_sb_;
136 148 delete corner_view_;
137 if (resize_corner_ && !resize_corner_->parent())
138 delete resize_corner_;
139 } 149 }
140 150
141 // static 151 // static
142 ScrollView* ScrollView::CreateScrollViewWithBorder() { 152 ScrollView* ScrollView::CreateScrollViewWithBorder() {
143 return new ScrollViewWithBorder(); 153 return new ScrollViewWithBorder();
144 } 154 }
145 155
146 void ScrollView::SetContents(View* a_view) { 156 void ScrollView::SetContents(View* a_view) {
147 SetHeaderOrContents(contents_viewport_, a_view, &contents_); 157 SetHeaderOrContents(contents_viewport_, a_view, &contents_);
148 } 158 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 bool should_layout_contents = false; 271 bool should_layout_contents = false;
262 bool horiz_sb_required = false; 272 bool horiz_sb_required = false;
263 bool vert_sb_required = false; 273 bool vert_sb_required = false;
264 if (contents_) { 274 if (contents_) {
265 gfx::Size content_size = contents_->size(); 275 gfx::Size content_size = contents_->size();
266 ComputeScrollBarsVisibility(viewport_size, 276 ComputeScrollBarsVisibility(viewport_size,
267 content_size, 277 content_size,
268 &horiz_sb_required, 278 &horiz_sb_required,
269 &vert_sb_required); 279 &vert_sb_required);
270 } 280 }
271 bool resize_corner_required = resize_corner_ && horiz_sb_required && 281 bool corner_view_required = horiz_sb_required && vert_sb_required;
272 vert_sb_required;
273 // Take action. 282 // Take action.
274 SetControlVisibility(horiz_sb_, horiz_sb_required); 283 SetControlVisibility(horiz_sb_, horiz_sb_required);
275 SetControlVisibility(vert_sb_, vert_sb_required); 284 SetControlVisibility(vert_sb_, vert_sb_required);
276 SetControlVisibility(resize_corner_, resize_corner_required); 285 SetControlVisibility(corner_view_, corner_view_required);
277 286
278 // Non-default. 287 // Non-default.
279 if (horiz_sb_required) { 288 if (horiz_sb_required) {
280 viewport_bounds.set_height( 289 viewport_bounds.set_height(
281 std::max(0, viewport_bounds.height() - horiz_sb_height)); 290 std::max(0, viewport_bounds.height() - horiz_sb_height));
282 should_layout_contents = true; 291 should_layout_contents = true;
283 } 292 }
284 // Default. 293 // Default.
285 if (!vert_sb_required) { 294 if (!vert_sb_required) {
286 viewport_bounds.set_width(viewport_bounds.width() + vert_sb_width); 295 viewport_bounds.set_width(viewport_bounds.width() + vert_sb_width);
287 should_layout_contents = true; 296 should_layout_contents = true;
288 } 297 }
289 298
290 if (horiz_sb_required) { 299 if (horiz_sb_required) {
291 int height_offset = horiz_sb_->GetContentOverlapSize(); 300 int height_offset = horiz_sb_->GetContentOverlapSize();
292 horiz_sb_->SetBounds(0, 301 horiz_sb_->SetBounds(0,
293 viewport_bounds.bottom() - height_offset, 302 viewport_bounds.bottom() - height_offset,
294 viewport_bounds.right(), 303 viewport_bounds.right(),
295 horiz_sb_height + height_offset); 304 horiz_sb_height + height_offset);
296 } 305 }
297 if (vert_sb_required) { 306 if (vert_sb_required) {
298 int width_offset = vert_sb_->GetContentOverlapSize(); 307 int width_offset = vert_sb_->GetContentOverlapSize();
299 vert_sb_->SetBounds(viewport_bounds.right() - width_offset, 308 vert_sb_->SetBounds(viewport_bounds.right() - width_offset,
300 0, 309 0,
301 vert_sb_width + width_offset, 310 vert_sb_width + width_offset,
302 viewport_bounds.bottom()); 311 viewport_bounds.bottom());
303 } 312 }
304 if (resize_corner_required) { 313 if (corner_view_required) {
305 // Show the resize corner. 314 // Show the resize corner.
306 resize_corner_->SetBounds(viewport_bounds.right(), 315 corner_view_->SetBounds(viewport_bounds.right(),
307 viewport_bounds.bottom(), 316 viewport_bounds.bottom(),
308 vert_sb_width, 317 vert_sb_width,
309 horiz_sb_height); 318 horiz_sb_height);
310 } 319 }
311 320
312 // Update to the real client size with the visible scrollbars. 321 // Update to the real client size with the visible scrollbars.
313 contents_viewport_->SetBoundsRect(viewport_bounds); 322 contents_viewport_->SetBoundsRect(viewport_bounds);
314 if (should_layout_contents && contents_) 323 if (should_layout_contents && contents_)
315 contents_->Layout(); 324 contents_->Layout();
316 325
317 header_viewport_->SetBounds(contents_x, contents_y, 326 header_viewport_->SetBounds(contents_x, contents_y,
318 viewport_bounds.width(), header_height); 327 viewport_bounds.width(), header_height);
319 if (header_) 328 if (header_)
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 630
622 VariableRowHeightScrollHelper::RowInfo 631 VariableRowHeightScrollHelper::RowInfo
623 FixedRowHeightScrollHelper::GetRowInfo(int y) { 632 FixedRowHeightScrollHelper::GetRowInfo(int y) {
624 if (y < top_margin_) 633 if (y < top_margin_)
625 return RowInfo(0, top_margin_); 634 return RowInfo(0, top_margin_);
626 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, 635 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_,
627 row_height_); 636 row_height_);
628 } 637 }
629 638
630 } // namespace views 639 } // namespace views
OLDNEW
« ui/views/controls/scroll_view.h ('K') | « ui/views/controls/scroll_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698