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

Side by Side Diff: ash/common/system/tray/fixed_sized_scroll_view.cc

Issue 2478273003: Use overlay scrollbars for the cros system menu. (Closed)
Patch Set: rebase Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/common/system/tray/fixed_sized_scroll_view.h" 5 #include "ash/common/system/tray/fixed_sized_scroll_view.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ui/views/background.h"
9 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
10
7 namespace ash { 11 namespace ash {
8 12
13 namespace {
14
15 bool UseMd() {
16 return MaterialDesignController::IsSystemTrayMenuMaterial();
17 }
18
19 } // namespace
20
9 FixedSizedScrollView::FixedSizedScrollView() { 21 FixedSizedScrollView::FixedSizedScrollView() {
10 set_notify_enter_exit_on_child(true); 22 set_notify_enter_exit_on_child(true);
23 if (UseMd())
24 SetVerticalScrollBar(new views::OverlayScrollBar(false));
11 } 25 }
12 26
13 FixedSizedScrollView::~FixedSizedScrollView() {} 27 FixedSizedScrollView::~FixedSizedScrollView() {}
14 28
15 void FixedSizedScrollView::SetContentsView(views::View* view) { 29 void FixedSizedScrollView::SetContentsView(views::View* view) {
16 SetContents(view); 30 SetContents(view);
17 view->SetBoundsRect(gfx::Rect(view->GetPreferredSize())); 31 view->SetBoundsRect(gfx::Rect(view->GetPreferredSize()));
18 } 32 }
19 33
20 void FixedSizedScrollView::SetFixedSize(const gfx::Size& size) { 34 void FixedSizedScrollView::SetFixedSize(const gfx::Size& size) {
35 DCHECK(!UseMd());
21 if (fixed_size_ == size) 36 if (fixed_size_ == size)
22 return; 37 return;
23 fixed_size_ = size; 38 fixed_size_ = size;
24 PreferredSizeChanged(); 39 PreferredSizeChanged();
25 } 40 }
26 41
42 void FixedSizedScrollView::set_fixed_size(const gfx::Size& size) {
43 DCHECK(!UseMd());
44 fixed_size_ = size;
45 }
46
27 gfx::Size FixedSizedScrollView::GetPreferredSize() const { 47 gfx::Size FixedSizedScrollView::GetPreferredSize() const {
28 gfx::Size size = 48 gfx::Size size =
29 fixed_size_.IsEmpty() ? contents()->GetPreferredSize() : fixed_size_; 49 fixed_size_.IsEmpty() ? contents()->GetPreferredSize() : fixed_size_;
30 gfx::Insets insets = GetInsets(); 50 gfx::Insets insets = GetInsets();
31 size.Enlarge(insets.width(), insets.height()); 51 size.Enlarge(insets.width(), insets.height());
32 return size; 52 return size;
33 } 53 }
34 54
35 void FixedSizedScrollView::Layout() { 55 void FixedSizedScrollView::Layout() {
56 if (UseMd()) {
57 views::ScrollView::Layout();
58 return;
59 }
60
36 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); 61 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize());
37 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); 62 bounds.set_width(std::max(0, width() - GetScrollBarWidth()));
38 // Keep the origin of the contents unchanged so that the list will not scroll 63 // Keep the origin of the contents unchanged so that the list will not scroll
39 // away from the current visible region user is viewing. ScrollView::Layout() 64 // away from the current visible region user is viewing. ScrollView::Layout()
40 // will make sure the contents line up with its viewport properly if 65 // will make sure the contents line up with its viewport properly if
41 // the contents moves out of the viewport region. 66 // the contents moves out of the viewport region.
42 bounds.set_origin(contents()->bounds().origin()); 67 bounds.set_origin(contents()->bounds().origin());
43 contents()->SetBoundsRect(bounds); 68 contents()->SetBoundsRect(bounds);
44 69
45 views::ScrollView::Layout(); 70 views::ScrollView::Layout();
46 if (!vertical_scroll_bar()->visible()) { 71 if (!vertical_scroll_bar()->visible()) {
47 gfx::Rect bounds = contents()->bounds(); 72 gfx::Rect bounds = contents()->bounds();
48 bounds.set_width(bounds.width() + GetScrollBarWidth()); 73 bounds.set_width(bounds.width() + GetScrollBarWidth());
49 contents()->SetBoundsRect(bounds); 74 contents()->SetBoundsRect(bounds);
50 } 75 }
51 } 76 }
52 77
53 void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 78 void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
79 if (UseMd())
80 return;
81
54 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); 82 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize());
55 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); 83 bounds.set_width(std::max(0, width() - GetScrollBarWidth()));
56 contents()->SetBoundsRect(bounds); 84 contents()->SetBoundsRect(bounds);
57 } 85 }
58 86
59 } // namespace ash 87 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/fixed_sized_scroll_view.h ('k') | ash/common/system/tray/tray_details_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698