Chromium Code Reviews| 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 #ifndef ASH_COMMON_SYSTEM_TRAY_THREE_VIEW_LAYOUT_H_ | |
| 6 #define ASH_COMMON_SYSTEM_TRAY_THREE_VIEW_LAYOUT_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "ui/gfx/geometry/insets.h" | |
| 12 #include "ui/gfx/geometry/size.h" | |
| 13 #include "ui/views/layout/layout_manager.h" | |
| 14 | |
| 15 namespace views { | |
| 16 class BoxLayout; | |
| 17 class View; | |
| 18 } // namespace views | |
| 19 | |
| 20 namespace ash { | |
| 21 class SizeRangeLayout; | |
| 22 | |
| 23 // A layout manager that has 3 child containers (START, CENTER, END) which can | |
| 24 // be arranged vertically or horizontally. The child containers can have | |
| 25 // minimum and/or maximum preferred size defined as well as a flex weight that | |
| 26 // is used to distribute excess space across the main axis, i.e. flexible width | |
| 27 // for the horizontal orientation. By default all the containers have a flex | |
| 28 // weight of 0, meaning no flexibility, and no minimum or maximum size. | |
| 29 // | |
| 30 // Views are laid out within each container as per the LayoutManager that has | |
| 31 // been installed on that container. By default a BoxLayout manager is installed | |
| 32 // on each container with the same orientation as this has been created with. | |
| 33 // The default BoxLayout will use a center alignment for both the main axis and | |
| 34 // cross axis alignment. | |
| 35 class ThreeViewLayout : public views::LayoutManager { | |
|
sky
2016/10/14 22:11:12
How is this different than BoxLayout? I get that i
bruthig
2016/10/17 15:53:12
It's different in that each of the Container views
| |
| 36 public: | |
| 37 enum Orientation { | |
| 38 HORIZONTAL, | |
| 39 VERTICAL, | |
| 40 }; | |
| 41 | |
| 42 // The different containers that child Views can be added to. | |
| 43 enum Container { START, CENTER, END }; | |
| 44 | |
| 45 // Constructs a layout with Horizontal orientation. | |
| 46 // | |
| 47 // TODO(bruthig): The |padding_between_items| can only be set on BoxLayouts | |
| 48 // during construction. Investigate whether this can be a mutable property of | |
| 49 // BoxLayouts and if so consider dropping it as a constructor parameter here. | |
| 50 explicit ThreeViewLayout(int padding_between_items); | |
| 51 | |
| 52 // Constructs a layout with the specified orientation and padding between | |
| 53 // child Views. | |
| 54 ThreeViewLayout(Orientation orientation, int padding_between_items); | |
| 55 | |
| 56 ~ThreeViewLayout() override; | |
| 57 | |
| 58 // Set the minimum cross axis size for the layout, i.e. the minimum height for | |
| 59 // a horizontal orientation. | |
| 60 void SetMinCrossAxisSize(int min_size); | |
| 61 | |
| 62 // Set the minimum size for the given |container|. | |
| 63 void SetMinSize(Container container, const gfx::Size& size); | |
| 64 | |
| 65 // Set the maximum size for the given |container|. | |
| 66 void SetMaxSize(Container container, const gfx::Size& size); | |
| 67 | |
| 68 // Adds the child |view| to the specified |container|. | |
| 69 void AddView(Container container, views::View* view); | |
| 70 | |
| 71 // Removes all current children from the specified |container| and adds the | |
| 72 // child |view| to it. | |
| 73 void SetView(Container container, views::View* view); | |
| 74 | |
| 75 // Sets the |insets| that union of the Container spaces will be laied out | |
| 76 // within. | |
| 77 void SetInsets(const gfx::Insets& insets); | |
| 78 | |
| 79 // Sets the |insets| within the given |container|. | |
| 80 void SetInsets(Container container, const gfx::Insets& insets); | |
| 81 | |
| 82 // Sets wither the |container| is visible. When a container is set to | |
| 83 // not-visible its space will be distributed to the other visible containers. | |
| 84 void SetContainerVisible(Container container, bool visible); | |
| 85 | |
| 86 // Sets the flex weight for the given |container|. Using the preferred size as | |
| 87 // the basis, free space along the main axis is distributed to views in the | |
| 88 // ratio of their flex weights. Similarly, if the views will overflow the | |
| 89 // parent, space is subtracted in these ratios. | |
| 90 // | |
| 91 // A flex of 0 means this view is not resized. Flex values must not be | |
| 92 // negative. | |
| 93 void SetFlexForView(Container container, int flex); | |
| 94 | |
| 95 // Sets the |layout_manager| used by the given |container|. | |
| 96 void SetLayoutManager(Container container, | |
| 97 std::unique_ptr<LayoutManager> layout_manager); | |
| 98 | |
| 99 // LayoutManager: | |
| 100 void Installed(views::View* host) override; | |
| 101 void Uninstalled(views::View* host) override; | |
| 102 void Layout(views::View* host) override; | |
| 103 gfx::Size GetPreferredSize(const views::View* host) const override; | |
| 104 int GetPreferredHeightForWidth(const views::View* host, | |
| 105 int width) const override; | |
| 106 void ViewAdded(views::View* host, views::View* view) override; | |
| 107 void ViewRemoved(views::View* host, views::View* view) override; | |
| 108 | |
| 109 private: | |
| 110 // Creates a default LayoutManager for the given |orientation|. | |
| 111 std::unique_ptr<views::LayoutManager> CreateDefaultLayoutManager( | |
| 112 Orientation orientation) const; | |
| 113 | |
| 114 // Returns the View for the given |container|. | |
| 115 views::View* GetContainer(Container container) const; | |
| 116 | |
| 117 // Returns the layout manager for the given |container|. | |
| 118 SizeRangeLayout* GetLayoutManager(Container container) const; | |
| 119 | |
| 120 // The layout manager that lays out the different Container Views. | |
| 121 std::unique_ptr<views::BoxLayout> box_layout_; | |
| 122 | |
| 123 // The host View that this layout manager has been installed on. | |
| 124 views::View* host_ = nullptr; | |
| 125 | |
| 126 views::View* start_container_ = nullptr; | |
| 127 SizeRangeLayout* start_container_layout_manager_ = nullptr; | |
| 128 | |
| 129 views::View* center_container_ = nullptr; | |
| 130 SizeRangeLayout* center_container_layout_manager_ = nullptr; | |
| 131 | |
| 132 views::View* end_container_ = nullptr; | |
| 133 SizeRangeLayout* end_container_layout_manager_ = nullptr; | |
| 134 | |
| 135 DISALLOW_COPY_AND_ASSIGN(ThreeViewLayout); | |
| 136 }; | |
| 137 | |
| 138 } // namespace ash | |
| 139 | |
| 140 #endif // ASH_COMMON_SYSTEM_TRAY_THREE_VIEW_LAYOUT_H_ | |
| OLD | NEW |