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

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

Issue 2439093002: Reland of "Added common layout framework for system menu rows." (Closed)
Patch Set: Addressed review comments. 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
(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 gfx::Size SizeRangeLayout::AbsoluteMinSize() {
17 const int kMinSize = 0;
18 return gfx::Size(kMinSize, kMinSize);
19 }
20
21 gfx::Size SizeRangeLayout::AbsoluteMaxSize() {
22 const int kMaxSize = std::numeric_limits<int>::max();
23 return gfx::Size(kMaxSize, kMaxSize);
24 }
25
26 // Non static
27
28 SizeRangeLayout::SizeRangeLayout()
29 : SizeRangeLayout(AbsoluteMinSize(), AbsoluteMaxSize()) {}
30
31 SizeRangeLayout::SizeRangeLayout(const gfx::Size& min_size,
32 const gfx::Size& max_size)
33 : layout_manager_(new views::FillLayout()),
34 min_size_(AbsoluteMinSize()),
35 max_size_(AbsoluteMaxSize()) {
36 SetMinSize(min_size);
37 SetMaxSize(max_size);
38 }
39
40 SizeRangeLayout::~SizeRangeLayout() {}
41
42 void SizeRangeLayout::SetSize(const gfx::Size& size) {
43 SetMinSize(size);
44 SetMaxSize(size);
45 }
46
47 void SizeRangeLayout::SetMinSize(const gfx::Size& size) {
48 min_size_ = size;
49 min_size_.SetToMax(gfx::Size());
50 max_size_.SetToMax(min_size_);
51 }
52
53 void SizeRangeLayout::SetMaxSize(const gfx::Size& size) {
54 max_size_ = size;
55 max_size_.SetToMax(gfx::Size());
56 min_size_.SetToMin(max_size_);
57 }
58
59 void SizeRangeLayout::SetLayoutManager(
60 std::unique_ptr<LayoutManager> layout_manager) {
61 DCHECK(layout_manager_);
62 layout_manager_ = std::move(layout_manager);
63 layout_manager_->Installed(host_);
64 }
65
66 void SizeRangeLayout::Installed(views::View* host) {
67 DCHECK(!host_);
68 host_ = host;
69 layout_manager_->Installed(host);
70 }
71
72 void SizeRangeLayout::Layout(views::View* host) {
73 layout_manager_->Layout(host);
74 }
75
76 gfx::Size SizeRangeLayout::GetPreferredSize(const views::View* host) const {
77 gfx::Size preferred_size = layout_manager_->GetPreferredSize(host);
78 ClampSizeToRange(&preferred_size);
79 return preferred_size;
80 }
81
82 int SizeRangeLayout::GetPreferredHeightForWidth(const views::View* host,
83 int width) const {
84 const int height = layout_manager_->GetPreferredHeightForWidth(host, width);
85 gfx::Size size(0, height);
86 ClampSizeToRange(&size);
87 return size.height();
88 }
89
90 void SizeRangeLayout::ViewAdded(views::View* host, views::View* view) {
91 layout_manager_->ViewAdded(host, view);
92 }
93
94 void SizeRangeLayout::ViewRemoved(views::View* host, views::View* view) {
95 layout_manager_->ViewRemoved(host, view);
96 }
97
98 void SizeRangeLayout::ClampSizeToRange(gfx::Size* size) const {
99 size->SetToMax(min_size_);
100 size->SetToMin(max_size_);
101 }
102
103 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/size_range_layout.h ('k') | ash/common/system/tray/size_range_layout_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698