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 std::unique_ptr<views::LayoutManager> CreateDefaultLayoutManager( | |
| 31 TriView::Orientation orientation) { | |
| 32 auto box_layout = | |
| 33 base::MakeUnique<views::BoxLayout>(GetOrientation(orientation), 0, 0, 0); | |
| 34 box_layout->set_main_axis_alignment( | |
| 35 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
| 36 box_layout->set_cross_axis_alignment( | |
| 37 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 38 return box_layout; | |
| 39 } | |
| 40 | |
| 30 } // namespace | 41 } // namespace |
| 31 | 42 |
| 32 TriView::TriView() : TriView(0) {} | 43 TriView::TriView() : TriView(0) {} |
| 33 | 44 |
| 34 TriView::TriView(int padding_between_containers) | 45 TriView::TriView(int padding_between_containers) |
| 35 : TriView(Orientation::HORIZONTAL, padding_between_containers) {} | 46 : TriView(Orientation::HORIZONTAL, padding_between_containers) {} |
| 36 | 47 |
| 37 TriView::TriView(Orientation orientation) : TriView(orientation, 0) {} | 48 TriView::TriView(Orientation orientation) : TriView(orientation, 0) {} |
| 38 | 49 |
| 39 TriView::TriView(Orientation orientation, int padding_between_containers) | 50 TriView::TriView(Orientation orientation, int padding_between_containers) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 55 GetContainer(Container::END) | 66 GetContainer(Container::END) |
| 56 ->SetLayoutManager(GetLayoutManager(Container::END)); | 67 ->SetLayoutManager(GetLayoutManager(Container::END)); |
| 57 | 68 |
| 58 GetLayoutManager(Container::START) | 69 GetLayoutManager(Container::START) |
| 59 ->SetLayoutManager(CreateDefaultLayoutManager(orientation)); | 70 ->SetLayoutManager(CreateDefaultLayoutManager(orientation)); |
| 60 GetLayoutManager(Container::CENTER) | 71 GetLayoutManager(Container::CENTER) |
| 61 ->SetLayoutManager(CreateDefaultLayoutManager(orientation)); | 72 ->SetLayoutManager(CreateDefaultLayoutManager(orientation)); |
| 62 GetLayoutManager(Container::END) | 73 GetLayoutManager(Container::END) |
| 63 ->SetLayoutManager(CreateDefaultLayoutManager(orientation)); | 74 ->SetLayoutManager(CreateDefaultLayoutManager(orientation)); |
| 64 | 75 |
| 76 box_layout_->set_cross_axis_alignment( | |
| 77 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | |
|
bruthig
2016/11/10 18:33:40
Just looking for confirmation, in your comment her
Evan Stade
2016/11/10 19:18:05
no, all we needed to do to fix the toggle was chan
bruthig
2016/11/10 20:51:16
Acknowledged.
| |
| 65 SetLayoutManager(box_layout_); | 78 SetLayoutManager(box_layout_); |
| 66 | 79 |
| 67 enable_hierarchy_changed_dcheck_ = true; | 80 enable_hierarchy_changed_dcheck_ = true; |
| 68 } | 81 } |
| 69 | 82 |
| 70 TriView::~TriView() { | 83 TriView::~TriView() { |
| 71 enable_hierarchy_changed_dcheck_ = false; | 84 enable_hierarchy_changed_dcheck_ = false; |
| 72 } | 85 } |
| 73 | 86 |
| 74 void TriView::SetMinCrossAxisSize(int min_size) { | |
| 75 box_layout_->set_minimum_cross_axis_size(min_size); | |
| 76 } | |
| 77 | |
| 78 void TriView::SetMinSize(Container container, const gfx::Size& size) { | 87 void TriView::SetMinSize(Container container, const gfx::Size& size) { |
| 79 GetLayoutManager(container)->SetMinSize(size); | 88 GetLayoutManager(container)->SetMinSize(size); |
| 80 } | 89 } |
| 81 | 90 |
| 82 void TriView::SetMaxSize(Container container, const gfx::Size& size) { | 91 void TriView::SetMaxSize(Container container, const gfx::Size& size) { |
| 83 GetLayoutManager(container)->SetMaxSize(size); | 92 GetLayoutManager(container)->SetMaxSize(size); |
| 84 } | 93 } |
| 85 | 94 |
| 86 void TriView::AddView(Container container, views::View* view) { | 95 void TriView::AddView(Container container, views::View* view) { |
| 87 GetContainer(container)->AddChildView(view); | 96 GetContainer(container)->AddChildView(view); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 if (details.is_add) { | 133 if (details.is_add) { |
| 125 DCHECK(false) | 134 DCHECK(false) |
| 126 << "Child views should not be added directly. They should be added " | 135 << "Child views should not be added directly. They should be added " |
| 127 "using TriView::AddView()."; | 136 "using TriView::AddView()."; |
| 128 } else { | 137 } else { |
| 129 DCHECK(false) << "Container views should not be removed."; | 138 DCHECK(false) << "Container views should not be removed."; |
| 130 } | 139 } |
| 131 } | 140 } |
| 132 } | 141 } |
| 133 | 142 |
| 134 std::unique_ptr<views::LayoutManager> TriView::CreateDefaultLayoutManager( | 143 views::View* TriView::GetContainer(Container container) { |
| 135 Orientation orientation) const { | 144 return child_at(static_cast<int>(container)); |
| 136 views::BoxLayout* box_layout = | |
| 137 new views::BoxLayout(GetOrientation(orientation), 0, 0, 0); | |
| 138 box_layout->set_main_axis_alignment( | |
| 139 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
| 140 box_layout->set_cross_axis_alignment( | |
| 141 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 142 return std::unique_ptr<views::LayoutManager>(box_layout); | |
| 143 } | 145 } |
| 144 | 146 |
| 145 views::View* TriView::GetContainer(Container container) const { | 147 SizeRangeLayout* TriView::GetLayoutManager(Container container) { |
| 146 return const_cast<views::View*>(child_at(static_cast<int>(container))); | |
| 147 } | |
| 148 | |
| 149 SizeRangeLayout* TriView::GetLayoutManager(Container container) const { | |
| 150 switch (container) { | 148 switch (container) { |
| 151 case Container::START: | 149 case Container::START: |
| 152 return start_container_layout_manager_; | 150 return start_container_layout_manager_; |
| 153 case Container::CENTER: | 151 case Container::CENTER: |
| 154 return center_container_layout_manager_; | 152 return center_container_layout_manager_; |
| 155 case Container::END: | 153 case Container::END: |
| 156 return end_container_layout_manager_; | 154 return end_container_layout_manager_; |
| 157 } | 155 } |
| 158 // Required for some compilers. | 156 // Required for some compilers. |
| 159 NOTREACHED(); | 157 NOTREACHED(); |
| 160 return nullptr; | 158 return nullptr; |
| 161 } | 159 } |
| 162 | 160 |
| 163 } // namespace ash | 161 } // namespace ash |
| OLD | NEW |