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

Unified Diff: ash/common/system/tray/size_range_layout.h

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 side-by-side diff with in-line comments
Download patch
Index: ash/common/system/tray/size_range_layout.h
diff --git a/ash/common/system/tray/size_range_layout.h b/ash/common/system/tray/size_range_layout.h
new file mode 100644
index 0000000000000000000000000000000000000000..f59b25e25257b13cfad388e8ded62ba150dd1649
--- /dev/null
+++ b/ash/common/system/tray/size_range_layout.h
@@ -0,0 +1,112 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
tdanderson 2016/10/19 18:30:59 Can you include a bug number in the CL description
bruthig 2016/10/20 04:40:12 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_COMMON_SYSTEM_TRAY_SIZE_RANGE_LAYOUT_H_
+#define ASH_COMMON_SYSTEM_TRAY_SIZE_RANGE_LAYOUT_H_
+
+#include <memory>
+
+#include "ash/ash_export.h"
+#include "base/macros.h"
+#include "ui/gfx/geometry/size.h"
+#include "ui/views/layout/layout_manager.h"
+
+namespace views {
+class View;
+} // namespace views
+
+namespace ash {
+
+// A LayoutManager adapter that allows clients to specify a minimum and/or a
+// maximum preferred size. The actual layout will be delegated to the
+// LayoutManager owned by this. i.e. this can be used to override the preferred
tdanderson 2016/10/19 18:30:59 nit: |this| instead of 'this'.
bruthig 2016/10/20 04:40:12 Done.
+// size returned by a View.
+//
+// By default the SizeRangeLayout is configured to own a FillLayout but this can
+// be overridden with SetLayoutManager().
+//
+// Example use case :
+//
+// Suppose you wanted a Label to take up a specific size of (50, 50) even
+// though the label's preferred size was (25, 25).
+//
+// Example code:
+//
+// Label* label = new Label(kSomeDummyText);
+// View* container = new View();
+// container->AddChildView(label);
+// SizeRangeLayout* layout = new SizeRangeLayout();
+// layout->SetSize(gfx::Size(50, 50));
+// container->SetLayoutManager(layout);
+//
+class ASH_EXPORT SizeRangeLayout : public views::LayoutManager {
+ public:
+ // The absolute minimum width/height.
+ static const int kMinSize;
tdanderson 2016/10/19 18:30:59 I don't think that |kMinSize| and |kMaxSize| need
bruthig 2016/10/20 04:40:12 Done.
+
+ // The absolute maximum width/height.
+ static const int kMaxSize;
+
+ // Returns the absolute minimum possible size. Use this with set_min_size() to
+ // effectively unset the minimum preferred size.
+ static gfx::Size MinSize();
+
+ // Returns the absolute maximum possible size. Use this with set_max_size() to
+ // effectively unset the maximum preferred size.
+ static gfx::Size MaxSize();
tdanderson 2016/10/19 18:30:59 I'm also not sure whether MinSize() and MaxSize()
bruthig 2016/10/20 04:40:12 I don't want to move them to private because I env
tdanderson 2016/10/20 18:16:48 OK, sounds reasonable and the new names lg.
+
+ // Create a layout with no minimum or maximum preferred size.
+ SizeRangeLayout();
+
+ // Create a layout with the given minimum and maximum preferred sizes.
+ SizeRangeLayout(const gfx::Size& min_size, const gfx::Size& max_size);
+
+ ~SizeRangeLayout() override;
+
+ // Sets both the minimum and maximum preferred size.
+ void SetSize(const gfx::Size& size);
+
+ // Set the minimum preferred size that GetPreferredSize() will round up to.
+ void SetMinSize(const gfx::Size& size);
+
+ // Set the minimum preferred size that GetPreferredSize() will round down to.
+ void SetMaxSize(const gfx::Size& size);
+
+ // Sets the layout manager that actually performs the layout once the bounds
+ // have been defined.
+ void SetLayoutManager(std::unique_ptr<LayoutManager> layout_manager);
+
+ // LayoutManager:
+ void Installed(views::View* host) override;
+ void Layout(views::View* host) override;
+ gfx::Size GetPreferredSize(const views::View* host) const override;
+ int GetPreferredHeightForWidth(const views::View* host,
+ int width) const override;
+ void ViewAdded(views::View* host, views::View* view) override;
+ void ViewRemoved(views::View* host, views::View* view) override;
+
+ private:
+ friend class SizeRangeLayoutTest;
+
+ // Clamps |size| to be within the minimum and maximum preferred sizes.
+ void ClampSizeToRange(gfx::Size* size) const;
+
+ // The host View that this has been installed on.
+ views::View* host_ = nullptr;
+
+ // The layout manager that actually performs the layout.
+ std::unique_ptr<views::LayoutManager> layout_manager_;
+
+ // The minimum preferred size.
+ gfx::Size min_size_;
+
+ // The maximum preferred size.
+ gfx::Size max_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(SizeRangeLayout);
+};
+
+} // namespace ash
+
+#endif // ASH_COMMON_SYSTEM_TRAY_SIZE_RANGE_LAYOUT_H_

Powered by Google App Engine
This is Rietveld 408576698