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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6eaf8aa8612a5ba0b6593c6ea5d5500c8e757e67
--- /dev/null
+++ b/ash/common/system/tray/size_range_layout.cc
@@ -0,0 +1,103 @@
+// 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
+
+gfx::Size SizeRangeLayout::AbsoluteMinSize() {
+ const int kMinSize = 0;
+ return gfx::Size(kMinSize, kMinSize);
+}
+
+gfx::Size SizeRangeLayout::AbsoluteMaxSize() {
+ const int kMaxSize = std::numeric_limits<int>::max();
+ return gfx::Size(kMaxSize, kMaxSize);
+}
+
+// Non static
+
+SizeRangeLayout::SizeRangeLayout()
+ : SizeRangeLayout(AbsoluteMinSize(), AbsoluteMaxSize()) {}
+
+SizeRangeLayout::SizeRangeLayout(const gfx::Size& min_size,
+ const gfx::Size& max_size)
+ : layout_manager_(new views::FillLayout()),
+ min_size_(AbsoluteMinSize()),
+ max_size_(AbsoluteMaxSize()) {
+ 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());
+ max_size_.SetToMax(min_size_);
+}
+
+void SizeRangeLayout::SetMaxSize(const gfx::Size& size) {
+ max_size_ = size;
+ max_size_.SetToMax(gfx::Size());
+ min_size_.SetToMin(max_size_);
+}
+
+void SizeRangeLayout::SetLayoutManager(
+ std::unique_ptr<LayoutManager> layout_manager) {
+ DCHECK(layout_manager_);
+ layout_manager_ = std::move(layout_manager);
+ layout_manager_->Installed(host_);
+}
+
+void SizeRangeLayout::Installed(views::View* host) {
+ DCHECK(!host_);
+ host_ = host;
+ layout_manager_->Installed(host);
+}
+
+void SizeRangeLayout::Layout(views::View* host) {
+ layout_manager_->Layout(host);
+}
+
+gfx::Size SizeRangeLayout::GetPreferredSize(const views::View* host) const {
+ gfx::Size preferred_size = layout_manager_->GetPreferredSize(host);
+ ClampSizeToRange(&preferred_size);
+ return preferred_size;
+}
+
+int SizeRangeLayout::GetPreferredHeightForWidth(const views::View* host,
+ int width) const {
+ const int height = layout_manager_->GetPreferredHeightForWidth(host, width);
+ gfx::Size size(0, height);
+ ClampSizeToRange(&size);
+ return size.height();
+}
+
+void SizeRangeLayout::ViewAdded(views::View* host, views::View* view) {
+ layout_manager_->ViewAdded(host, view);
+}
+
+void SizeRangeLayout::ViewRemoved(views::View* host, views::View* view) {
+ layout_manager_->ViewRemoved(host, view);
+}
+
+void SizeRangeLayout::ClampSizeToRange(gfx::Size* size) const {
+ size->SetToMax(min_size_);
+ size->SetToMin(max_size_);
+}
+
+} // namespace ash
« 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