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

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

Issue 2414103003: Added common layout framework for system menu rows. (Closed)
Patch Set: Merge branch 'master' into md_system_menu_layout_mgr Created 4 years, 2 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <limits>
6
7 #include "ash/common/system/tray/size_range_layout.h"
8
9 #include "base/logging.h"
10 #include "ui/views/layout/fill_layout.h"
11
12 namespace ash {
13
14 // static
15
16 const int SizeRangeLayout::kMinSize = 0;
17
18 const int SizeRangeLayout::kMaxSize = std::numeric_limits<int>::max();
19
20 gfx::Size SizeRangeLayout::MinSize() {
21 return gfx::Size(kMinSize, kMinSize);
22 }
23
24 gfx::Size SizeRangeLayout::MaxSize() {
25 return gfx::Size(kMaxSize, kMaxSize);
26 }
27
28 // Non static
29
30 SizeRangeLayout::SizeRangeLayout() : SizeRangeLayout(MinSize(), MaxSize()) {}
31
32 SizeRangeLayout::SizeRangeLayout(const gfx::Size& min_size,
33 const gfx::Size& max_size)
34 : layout_manager_(new views::FillLayout()) {
35 SetMinSize(min_size);
36 SetMaxSize(max_size);
37 }
38
39 SizeRangeLayout::~SizeRangeLayout() {}
40
41 void SizeRangeLayout::SetSize(const gfx::Size& size) {
42 SetMinSize(size);
43 SetMaxSize(size);
44 }
45
46 void SizeRangeLayout::SetMinSize(const gfx::Size& size) {
47 min_size_ = size;
48 min_size_.SetToMax(gfx::Size());
49 }
50
51 void SizeRangeLayout::SetMaxSize(const gfx::Size& size) {
52 max_size_ = size;
53 min_size_.SetToMax(gfx::Size());
tdanderson 2016/10/19 18:30:59 You probably wanted this to be |max_size_|
bruthig 2016/10/20 04:40:12 D'oh, done!
54 }
55
56 void SizeRangeLayout::SetLayoutManager(
57 std::unique_ptr<LayoutManager> layout_manager) {
58 layout_manager_ = std::move(layout_manager);
59 if (layout_manager_)
60 layout_manager_->Installed(host_);
61 }
62
63 void SizeRangeLayout::Installed(views::View* host) {
64 DCHECK(!host_);
65 host_ = host;
66 if (layout_manager_)
67 layout_manager_->Installed(host);
68 }
69
70 void SizeRangeLayout::Layout(views::View* host) {
71 if (layout_manager_)
72 layout_manager_->Layout(host);
73 }
74
75 gfx::Size SizeRangeLayout::GetPreferredSize(const views::View* host) const {
76 // TODO(bruthig): Handle Views that override GetPreferredSize().
tdanderson 2016/10/19 18:30:59 As discussed in person, can you append something l
bruthig 2016/10/20 04:40:12 Removed.
77 gfx::Size preferred_size =
78 layout_manager_ ? layout_manager_->GetPreferredSize(host) : gfx::Size();
79 ClampSizeToRange(&preferred_size);
80 return preferred_size;
81 }
82
83 int SizeRangeLayout::GetPreferredHeightForWidth(const views::View* host,
84 int width) const {
85 // TODO(bruthig): Handle Views that override GetPreferredSize().
86 const int height =
87 layout_manager_ ? layout_manager_->GetPreferredHeightForWidth(host, width)
88 : 0;
89 gfx::Size size(0, height);
90 ClampSizeToRange(&size);
91 return size.height();
92 }
93
94 void SizeRangeLayout::ViewAdded(views::View* host, views::View* view) {
95 if (layout_manager_)
tdanderson 2016/10/19 18:30:59 Regarding your 'if (layout_manager_)' checks in th
bruthig 2016/10/20 04:40:12 I've changed it to a DCHECK(). Do you think it's
tdanderson 2016/10/20 18:16:48 A DCHECK should be fine.
96 layout_manager_->ViewAdded(host, view);
97 }
98
99 void SizeRangeLayout::ViewRemoved(views::View* host, views::View* view) {
100 if (layout_manager_)
101 layout_manager_->ViewRemoved(host, view);
102 }
103
104 void SizeRangeLayout::ClampSizeToRange(gfx::Size* size) const {
105 size->SetToMax(min_size_);
106 size->SetToMin(max_size_);
107 }
108
109 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698