Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/system/tray/tri_view.h" | 5 #include "ash/common/system/tray/tri_view.h" |
| 6 | 6 |
| 7 #include "ash/common/system/tray/size_range_layout.h" | 7 #include "ash/common/system/tray/size_range_layout.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ui/views/border.h" | 9 #include "ui/views/border.h" |
| 10 #include "ui/views/layout/box_layout.h" | 10 #include "ui/views/layout/box_layout.h" |
| 11 #include "ui/views/layout/fill_layout.h" | 11 #include "ui/views/layout/fill_layout.h" |
| 12 #include "ui/views/layout/layout_manager.h" | 12 #include "ui/views/layout/layout_manager.h" |
| 13 | 13 |
| 14 namespace ash { | 14 namespace ash { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // Converts TriView::Orientation values to views::BoxLayout::Orientation values. | 17 // Converts TriView::Orientation values to views::BoxLayout::Orientation values. |
| 18 views::BoxLayout::Orientation GetOrientation(TriView::Orientation orientation) { | 18 views::BoxLayout::Orientation GetOrientation(TriView::Orientation orientation) { |
| 19 switch (orientation) { | 19 switch (orientation) { |
| 20 case TriView::Orientation::HORIZONTAL: | 20 case TriView::Orientation::HORIZONTAL: |
| 21 return views::BoxLayout::kHorizontal; | 21 return views::BoxLayout::kHorizontal; |
| 22 case TriView::Orientation::VERTICAL: | 22 case TriView::Orientation::VERTICAL: |
| 23 return views::BoxLayout::kVertical; | 23 return views::BoxLayout::kVertical; |
| 24 } | 24 } |
| 25 // Required for some compilers. | 25 // Required for some compilers. |
| 26 NOTREACHED(); | 26 NOTREACHED(); |
| 27 return views::BoxLayout::kHorizontal; | 27 return views::BoxLayout::kHorizontal; |
| 28 } | 28 } |
| 29 | 29 |
| 30 // A View that will perform a layout if a child view's preferred size changes. | |
| 31 class RelayoutView : public views::View { | |
|
tdanderson
2016/11/28 21:47:37
Hm, I'm a bit surprised there isn't something like
| |
| 32 public: | |
| 33 RelayoutView() {} | |
| 34 | |
| 35 // views::View: | |
| 36 void ChildPreferredSizeChanged(View* child) override { Layout(); } | |
| 37 | |
| 38 private: | |
| 39 DISALLOW_COPY_AND_ASSIGN(RelayoutView); | |
| 40 }; | |
| 41 | |
| 30 } // namespace | 42 } // namespace |
| 31 | 43 |
| 32 TriView::TriView() : TriView(0) {} | 44 TriView::TriView() : TriView(0) {} |
| 33 | 45 |
| 34 TriView::TriView(int padding_between_containers) | 46 TriView::TriView(int padding_between_containers) |
| 35 : TriView(Orientation::HORIZONTAL, padding_between_containers) {} | 47 : TriView(Orientation::HORIZONTAL, padding_between_containers) {} |
| 36 | 48 |
| 37 TriView::TriView(Orientation orientation) : TriView(orientation, 0) {} | 49 TriView::TriView(Orientation orientation) : TriView(orientation, 0) {} |
| 38 | 50 |
| 39 TriView::TriView(Orientation orientation, int padding_between_containers) | 51 TriView::TriView(Orientation orientation, int padding_between_containers) |
| 40 : box_layout_(new views::BoxLayout(GetOrientation(orientation), | 52 : box_layout_(new views::BoxLayout(GetOrientation(orientation), |
| 41 0, | 53 0, |
| 42 0, | 54 0, |
| 43 padding_between_containers)), | 55 padding_between_containers)), |
| 44 start_container_layout_manager_(new SizeRangeLayout), | 56 start_container_layout_manager_(new SizeRangeLayout), |
| 45 center_container_layout_manager_(new SizeRangeLayout), | 57 center_container_layout_manager_(new SizeRangeLayout), |
| 46 end_container_layout_manager_(new SizeRangeLayout) { | 58 end_container_layout_manager_(new SizeRangeLayout) { |
| 47 AddChildView(new views::View); | 59 AddChildView(new RelayoutView); |
| 48 AddChildView(new views::View); | 60 AddChildView(new RelayoutView); |
| 49 AddChildView(new views::View); | 61 AddChildView(new RelayoutView); |
| 50 | 62 |
| 51 GetContainer(Container::START) | 63 GetContainer(Container::START) |
| 52 ->SetLayoutManager(GetLayoutManager(Container::START)); | 64 ->SetLayoutManager(GetLayoutManager(Container::START)); |
| 53 GetContainer(Container::CENTER) | 65 GetContainer(Container::CENTER) |
| 54 ->SetLayoutManager(GetLayoutManager(Container::CENTER)); | 66 ->SetLayoutManager(GetLayoutManager(Container::CENTER)); |
| 55 GetContainer(Container::END) | 67 GetContainer(Container::END) |
| 56 ->SetLayoutManager(GetLayoutManager(Container::END)); | 68 ->SetLayoutManager(GetLayoutManager(Container::END)); |
| 57 | 69 |
| 58 box_layout_->set_cross_axis_alignment( | 70 box_layout_->set_cross_axis_alignment( |
| 59 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | 71 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 return center_container_layout_manager_; | 150 return center_container_layout_manager_; |
| 139 case Container::END: | 151 case Container::END: |
| 140 return end_container_layout_manager_; | 152 return end_container_layout_manager_; |
| 141 } | 153 } |
| 142 // Required for some compilers. | 154 // Required for some compilers. |
| 143 NOTREACHED(); | 155 NOTREACHED(); |
| 144 return nullptr; | 156 return nullptr; |
| 145 } | 157 } |
| 146 | 158 |
| 147 } // namespace ash | 159 } // namespace ash |
| OLD | NEW |