Index: ash/common/system/tray/size_range_layout.cc |
diff --git a/ash/common/system/tray/size_range_layout.cc b/ash/common/system/tray/size_range_layout.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ddb5b5bedda2401fbb5380315e8543a36e74d683 |
--- /dev/null |
+++ b/ash/common/system/tray/size_range_layout.cc |
@@ -0,0 +1,109 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <limits> |
+ |
+#include "ash/common/system/tray/size_range_layout.h" |
+ |
+#include "base/logging.h" |
+#include "ui/views/layout/fill_layout.h" |
+ |
+namespace ash { |
+ |
+// static |
+ |
+const int SizeRangeLayout::kMinSize = 0; |
+ |
+const int SizeRangeLayout::kMaxSize = std::numeric_limits<int>::max(); |
+ |
+gfx::Size SizeRangeLayout::MinSize() { |
+ return gfx::Size(kMinSize, kMinSize); |
+} |
+ |
+gfx::Size SizeRangeLayout::MaxSize() { |
+ return gfx::Size(kMaxSize, kMaxSize); |
+} |
+ |
+// Non static |
+ |
+SizeRangeLayout::SizeRangeLayout() : SizeRangeLayout(MinSize(), MaxSize()) {} |
+ |
+SizeRangeLayout::SizeRangeLayout(const gfx::Size& min_size, |
+ const gfx::Size& max_size) |
+ : layout_manager_(new views::FillLayout()) { |
+ SetMinSize(min_size); |
+ SetMaxSize(max_size); |
+} |
+ |
+SizeRangeLayout::~SizeRangeLayout() {} |
+ |
+void SizeRangeLayout::SetSize(const gfx::Size& size) { |
+ SetMinSize(size); |
+ SetMaxSize(size); |
+} |
+ |
+void SizeRangeLayout::SetMinSize(const gfx::Size& size) { |
+ min_size_ = size; |
+ min_size_.SetToMax(gfx::Size()); |
+} |
+ |
+void SizeRangeLayout::SetMaxSize(const gfx::Size& size) { |
+ max_size_ = size; |
+ 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!
|
+} |
+ |
+void SizeRangeLayout::SetLayoutManager( |
+ std::unique_ptr<LayoutManager> layout_manager) { |
+ layout_manager_ = std::move(layout_manager); |
+ if (layout_manager_) |
+ layout_manager_->Installed(host_); |
+} |
+ |
+void SizeRangeLayout::Installed(views::View* host) { |
+ DCHECK(!host_); |
+ host_ = host; |
+ if (layout_manager_) |
+ layout_manager_->Installed(host); |
+} |
+ |
+void SizeRangeLayout::Layout(views::View* host) { |
+ if (layout_manager_) |
+ layout_manager_->Layout(host); |
+} |
+ |
+gfx::Size SizeRangeLayout::GetPreferredSize(const views::View* host) const { |
+ // 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.
|
+ gfx::Size preferred_size = |
+ layout_manager_ ? layout_manager_->GetPreferredSize(host) : gfx::Size(); |
+ ClampSizeToRange(&preferred_size); |
+ return preferred_size; |
+} |
+ |
+int SizeRangeLayout::GetPreferredHeightForWidth(const views::View* host, |
+ int width) const { |
+ // TODO(bruthig): Handle Views that override GetPreferredSize(). |
+ const int height = |
+ layout_manager_ ? layout_manager_->GetPreferredHeightForWidth(host, width) |
+ : 0; |
+ gfx::Size size(0, height); |
+ ClampSizeToRange(&size); |
+ return size.height(); |
+} |
+ |
+void SizeRangeLayout::ViewAdded(views::View* host, views::View* view) { |
+ 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.
|
+ layout_manager_->ViewAdded(host, view); |
+} |
+ |
+void SizeRangeLayout::ViewRemoved(views::View* host, views::View* view) { |
+ if (layout_manager_) |
+ layout_manager_->ViewRemoved(host, view); |
+} |
+ |
+void SizeRangeLayout::ClampSizeToRange(gfx::Size* size) const { |
+ size->SetToMax(min_size_); |
+ size->SetToMin(max_size_); |
+} |
+ |
+} // namespace ash |