OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ASH_COMMON_SYSTEM_TRAY_SIZE_RANGE_LAYOUT_H_ | |
6 #define ASH_COMMON_SYSTEM_TRAY_SIZE_RANGE_LAYOUT_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "base/macros.h" | |
12 #include "ui/gfx/geometry/size.h" | |
13 #include "ui/views/layout/layout_manager.h" | |
14 | |
15 namespace views { | |
16 class View; | |
17 } // namespace views | |
18 | |
19 namespace ash { | |
20 | |
21 // A LayoutManager adapter that allows clients to specify a minimum and/or a | |
22 // maximum preferred size. The actual layout will be delegated to the | |
23 // 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.
| |
24 // size returned by a View. | |
25 // | |
26 // By default the SizeRangeLayout is configured to own a FillLayout but this can | |
27 // be overridden with SetLayoutManager(). | |
28 // | |
29 // Example use case : | |
30 // | |
31 // Suppose you wanted a Label to take up a specific size of (50, 50) even | |
32 // though the label's preferred size was (25, 25). | |
33 // | |
34 // Example code: | |
35 // | |
36 // Label* label = new Label(kSomeDummyText); | |
37 // View* container = new View(); | |
38 // container->AddChildView(label); | |
39 // SizeRangeLayout* layout = new SizeRangeLayout(); | |
40 // layout->SetSize(gfx::Size(50, 50)); | |
41 // container->SetLayoutManager(layout); | |
42 // | |
43 class ASH_EXPORT SizeRangeLayout : public views::LayoutManager { | |
44 public: | |
45 // The absolute minimum width/height. | |
46 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.
| |
47 | |
48 // The absolute maximum width/height. | |
49 static const int kMaxSize; | |
50 | |
51 // Returns the absolute minimum possible size. Use this with set_min_size() to | |
52 // effectively unset the minimum preferred size. | |
53 static gfx::Size MinSize(); | |
54 | |
55 // Returns the absolute maximum possible size. Use this with set_max_size() to | |
56 // effectively unset the maximum preferred size. | |
57 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.
| |
58 | |
59 // Create a layout with no minimum or maximum preferred size. | |
60 SizeRangeLayout(); | |
61 | |
62 // Create a layout with the given minimum and maximum preferred sizes. | |
63 SizeRangeLayout(const gfx::Size& min_size, const gfx::Size& max_size); | |
64 | |
65 ~SizeRangeLayout() override; | |
66 | |
67 // Sets both the minimum and maximum preferred size. | |
68 void SetSize(const gfx::Size& size); | |
69 | |
70 // Set the minimum preferred size that GetPreferredSize() will round up to. | |
71 void SetMinSize(const gfx::Size& size); | |
72 | |
73 // Set the minimum preferred size that GetPreferredSize() will round down to. | |
74 void SetMaxSize(const gfx::Size& size); | |
75 | |
76 // Sets the layout manager that actually performs the layout once the bounds | |
77 // have been defined. | |
78 void SetLayoutManager(std::unique_ptr<LayoutManager> layout_manager); | |
79 | |
80 // LayoutManager: | |
81 void Installed(views::View* host) override; | |
82 void Layout(views::View* host) override; | |
83 gfx::Size GetPreferredSize(const views::View* host) const override; | |
84 int GetPreferredHeightForWidth(const views::View* host, | |
85 int width) const override; | |
86 void ViewAdded(views::View* host, views::View* view) override; | |
87 void ViewRemoved(views::View* host, views::View* view) override; | |
88 | |
89 private: | |
90 friend class SizeRangeLayoutTest; | |
91 | |
92 // Clamps |size| to be within the minimum and maximum preferred sizes. | |
93 void ClampSizeToRange(gfx::Size* size) const; | |
94 | |
95 // The host View that this has been installed on. | |
96 views::View* host_ = nullptr; | |
97 | |
98 // The layout manager that actually performs the layout. | |
99 std::unique_ptr<views::LayoutManager> layout_manager_; | |
100 | |
101 // The minimum preferred size. | |
102 gfx::Size min_size_; | |
103 | |
104 // The maximum preferred size. | |
105 gfx::Size max_size_; | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(SizeRangeLayout); | |
108 }; | |
109 | |
110 } // namespace ash | |
111 | |
112 #endif // ASH_COMMON_SYSTEM_TRAY_SIZE_RANGE_LAYOUT_H_ | |
OLD | NEW |