OLD | NEW |
| (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::kAbsoluteMinSize = 0; | |
17 const int SizeRangeLayout::kAbsoluteMaxSize = std::numeric_limits<int>::max(); | |
18 | |
19 // Non static | |
20 | |
21 SizeRangeLayout::SizeRangeLayout() | |
22 : SizeRangeLayout(gfx::Size(kAbsoluteMinSize, kAbsoluteMinSize), | |
23 gfx::Size(kAbsoluteMaxSize, kAbsoluteMaxSize)) {} | |
24 | |
25 SizeRangeLayout::SizeRangeLayout(const gfx::Size& min_size, | |
26 const gfx::Size& max_size) | |
27 : layout_manager_(new views::FillLayout()), | |
28 min_size_(gfx::Size(kAbsoluteMinSize, kAbsoluteMinSize)), | |
29 max_size_(gfx::Size(kAbsoluteMaxSize, kAbsoluteMaxSize)) { | |
30 SetMinSize(min_size); | |
31 SetMaxSize(max_size); | |
32 } | |
33 | |
34 SizeRangeLayout::~SizeRangeLayout() {} | |
35 | |
36 void SizeRangeLayout::SetSize(const gfx::Size& size) { | |
37 SetMinSize(size); | |
38 SetMaxSize(size); | |
39 } | |
40 | |
41 void SizeRangeLayout::SetMinSize(const gfx::Size& size) { | |
42 min_size_ = size; | |
43 min_size_.SetToMax(gfx::Size()); | |
44 max_size_.SetToMax(min_size_); | |
45 } | |
46 | |
47 void SizeRangeLayout::SetMaxSize(const gfx::Size& size) { | |
48 max_size_ = size; | |
49 max_size_.SetToMax(gfx::Size()); | |
50 min_size_.SetToMin(max_size_); | |
51 } | |
52 | |
53 void SizeRangeLayout::SetLayoutManager( | |
54 std::unique_ptr<LayoutManager> layout_manager) { | |
55 DCHECK(layout_manager_); | |
56 layout_manager_ = std::move(layout_manager); | |
57 layout_manager_->Installed(host_); | |
58 } | |
59 | |
60 void SizeRangeLayout::Installed(views::View* host) { | |
61 DCHECK(!host_); | |
62 host_ = host; | |
63 layout_manager_->Installed(host); | |
64 } | |
65 | |
66 void SizeRangeLayout::Layout(views::View* host) { | |
67 layout_manager_->Layout(host); | |
68 } | |
69 | |
70 gfx::Size SizeRangeLayout::GetPreferredSize(const views::View* host) const { | |
71 gfx::Size preferred_size = layout_manager_->GetPreferredSize(host); | |
72 ClampSizeToRange(&preferred_size); | |
73 return preferred_size; | |
74 } | |
75 | |
76 int SizeRangeLayout::GetPreferredHeightForWidth(const views::View* host, | |
77 int width) const { | |
78 const int height = layout_manager_->GetPreferredHeightForWidth(host, width); | |
79 gfx::Size size(0, height); | |
80 ClampSizeToRange(&size); | |
81 return size.height(); | |
82 } | |
83 | |
84 void SizeRangeLayout::ViewAdded(views::View* host, views::View* view) { | |
85 layout_manager_->ViewAdded(host, view); | |
86 } | |
87 | |
88 void SizeRangeLayout::ViewRemoved(views::View* host, views::View* view) { | |
89 layout_manager_->ViewRemoved(host, view); | |
90 } | |
91 | |
92 void SizeRangeLayout::ClampSizeToRange(gfx::Size* size) const { | |
93 size->SetToMax(min_size_); | |
94 size->SetToMin(max_size_); | |
95 } | |
96 | |
97 } // namespace ash | |
OLD | NEW |