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 #include "ash/common/system/tray/three_view_layout.h" | |
| 6 | |
| 7 #include "ash/common/system/tray/size_range_layout.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "ui/views/border.h" | |
| 10 #include "ui/views/layout/box_layout.h" | |
| 11 #include "ui/views/layout/fill_layout.h" | |
| 12 | |
| 13 namespace ash { | |
| 14 namespace { | |
| 15 | |
| 16 // Converts ThreeViewLayout::Orientation values to | |
| 17 // views::BoxLayout::Orientation values. | |
| 18 views::BoxLayout::Orientation GetOrientation( | |
| 19 ThreeViewLayout::Orientation orientation) { | |
| 20 switch (orientation) { | |
| 21 case ThreeViewLayout::HORIZONTAL: | |
| 22 return views::BoxLayout::kHorizontal; | |
| 23 case ThreeViewLayout::VERTICAL: | |
| 24 return views::BoxLayout::kVertical; | |
|
tdanderson
2016/10/19 18:30:59
A possible future consideration is to have both la
bruthig
2016/10/20 04:40:12
Acknowledged.
| |
| 25 } | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 ThreeViewLayout::ThreeViewLayout() : ThreeViewLayout(0) {} | |
| 31 | |
| 32 ThreeViewLayout::ThreeViewLayout(int padding_between_containers) | |
| 33 : ThreeViewLayout(HORIZONTAL, padding_between_containers) {} | |
| 34 | |
| 35 ThreeViewLayout::ThreeViewLayout(Orientation orientation) | |
| 36 : ThreeViewLayout(orientation, 0) {} | |
| 37 | |
| 38 ThreeViewLayout::ThreeViewLayout(Orientation orientation, | |
| 39 int padding_between_containers) | |
| 40 : box_layout_(new views::BoxLayout(GetOrientation(orientation), | |
| 41 0, | |
| 42 0, | |
| 43 padding_between_containers)), | |
| 44 start_container_(new views::View), | |
| 45 start_container_layout_manager_(new SizeRangeLayout), | |
| 46 center_container_(new views::View), | |
| 47 center_container_layout_manager_(new SizeRangeLayout), | |
| 48 end_container_(new views::View), | |
| 49 end_container_layout_manager_(new SizeRangeLayout) { | |
| 50 start_container_->SetLayoutManager(GetLayoutManager(START)); | |
| 51 center_container_->SetLayoutManager(GetLayoutManager(CENTER)); | |
| 52 end_container_->SetLayoutManager(GetLayoutManager(END)); | |
| 53 GetLayoutManager(START)->SetLayoutManager( | |
| 54 CreateDefaultLayoutManager(orientation)); | |
| 55 GetLayoutManager(CENTER)->SetLayoutManager( | |
| 56 CreateDefaultLayoutManager(orientation)); | |
| 57 GetLayoutManager(END)->SetLayoutManager( | |
| 58 CreateDefaultLayoutManager(orientation)); | |
| 59 } | |
| 60 | |
| 61 ThreeViewLayout::~ThreeViewLayout() { | |
| 62 if (host_) { | |
| 63 host_->RemoveChildView(GetContainer(START)); | |
| 64 host_->RemoveChildView(GetContainer(CENTER)); | |
| 65 host_->RemoveChildView(GetContainer(END)); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void ThreeViewLayout::SetMinCrossAxisSize(int min_size) { | |
| 70 box_layout_->set_minimum_cross_axis_size(min_size); | |
| 71 } | |
| 72 | |
| 73 void ThreeViewLayout::SetMinSize(Container container, const gfx::Size& size) { | |
| 74 GetLayoutManager(container)->SetMinSize(size); | |
| 75 } | |
| 76 | |
| 77 void ThreeViewLayout::SetMaxSize(Container container, const gfx::Size& size) { | |
| 78 GetLayoutManager(container)->SetMaxSize(size); | |
| 79 } | |
| 80 | |
| 81 void ThreeViewLayout::AddView(Container container, views::View* view) { | |
| 82 views::View* container_view = GetContainer(container); | |
|
tdanderson
2016/10/19 18:30:59
nit: condense to one line?
bruthig
2016/10/20 04:40:12
Done.
| |
| 83 container_view->AddChildView(view); | |
| 84 } | |
| 85 | |
| 86 void ThreeViewLayout::SetView(Container container, views::View* view) { | |
| 87 views::View* container_view = GetContainer(container); | |
| 88 container_view->RemoveAllChildViews(true); | |
| 89 container_view->AddChildView(view); | |
| 90 } | |
| 91 | |
| 92 void ThreeViewLayout::SetInsets(const gfx::Insets& insets) { | |
| 93 box_layout_->set_inside_border_insets(insets); | |
| 94 } | |
| 95 | |
| 96 void ThreeViewLayout::SetBorder(Container container, | |
| 97 std::unique_ptr<views::Border> border) { | |
| 98 GetContainer(container)->SetBorder(std::move(border)); | |
| 99 } | |
| 100 | |
| 101 void ThreeViewLayout::SetContainerVisible(Container container, bool visible) { | |
| 102 GetContainer(container)->SetVisible(visible); | |
| 103 } | |
| 104 | |
| 105 void ThreeViewLayout::SetFlexForContainer(Container container, int flex) { | |
| 106 box_layout_->SetFlexForView(GetContainer(container), flex); | |
| 107 } | |
| 108 | |
| 109 void ThreeViewLayout::SetLayoutManager( | |
| 110 Container container, | |
| 111 std::unique_ptr<LayoutManager> layout_manager) { | |
| 112 GetLayoutManager(container)->SetLayoutManager(std::move(layout_manager)); | |
| 113 if (GetLayoutManager(container)) | |
| 114 GetLayoutManager(container)->Installed(GetContainer(container)); | |
| 115 } | |
| 116 | |
| 117 void ThreeViewLayout::Installed(views::View* host) { | |
| 118 DCHECK(!host_); | |
| 119 host_ = host; | |
| 120 if (host_) { | |
| 121 host_->AddChildView(GetContainer(START)); | |
| 122 host_->AddChildView(GetContainer(CENTER)); | |
| 123 host_->AddChildView(GetContainer(END)); | |
| 124 } | |
| 125 box_layout_->Installed(host_); | |
| 126 } | |
| 127 | |
| 128 void ThreeViewLayout::Layout(views::View* host) { | |
| 129 box_layout_->Layout(host); | |
| 130 } | |
| 131 | |
| 132 gfx::Size ThreeViewLayout::GetPreferredSize(const views::View* host) const { | |
| 133 return box_layout_->GetPreferredSize(host); | |
| 134 } | |
| 135 | |
| 136 int ThreeViewLayout::GetPreferredHeightForWidth(const views::View* host, | |
| 137 int width) const { | |
| 138 return box_layout_->GetPreferredHeightForWidth(host, width); | |
| 139 } | |
| 140 | |
| 141 void ThreeViewLayout::ViewAdded(views::View* host, views::View* view) { | |
| 142 box_layout_->ViewAdded(host, view); | |
| 143 } | |
| 144 | |
| 145 void ThreeViewLayout::ViewRemoved(views::View* host, views::View* view) { | |
| 146 box_layout_->ViewRemoved(host, view); | |
| 147 } | |
| 148 | |
| 149 std::unique_ptr<views::LayoutManager> | |
| 150 ThreeViewLayout::CreateDefaultLayoutManager(Orientation orientation) const { | |
| 151 views::BoxLayout* box_layout = | |
| 152 new views::BoxLayout(GetOrientation(orientation), 0, 0, 0); | |
| 153 box_layout->set_main_axis_alignment( | |
| 154 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
| 155 box_layout->set_cross_axis_alignment( | |
| 156 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 157 return std::unique_ptr<views::LayoutManager>(box_layout); | |
| 158 } | |
| 159 | |
| 160 views::View* ThreeViewLayout::GetContainer(Container container) const { | |
| 161 switch (container) { | |
| 162 case START: | |
| 163 return start_container_; | |
| 164 case CENTER: | |
| 165 return center_container_; | |
| 166 case END: | |
| 167 return end_container_; | |
| 168 } | |
| 169 } | |
| 170 | |
| 171 SizeRangeLayout* ThreeViewLayout::GetLayoutManager(Container container) const { | |
| 172 switch (container) { | |
| 173 case START: | |
| 174 return start_container_layout_manager_; | |
| 175 case CENTER: | |
| 176 return center_container_layout_manager_; | |
| 177 case END: | |
| 178 return end_container_layout_manager_; | |
| 179 } | |
| 180 } | |
| 181 | |
| 182 } // namespace ash | |
| OLD | NEW |