Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: ash/common/system/tray/tri_view.cc

Issue 2487603005: Adjust TriView. (Closed)
Patch Set: merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/system/tray/tri_view.h ('k') | ash/common/system/tray/tri_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 AddChildView(new views::View); 48 AddChildView(new views::View);
49 AddChildView(new views::View); 49 AddChildView(new views::View);
50 50
51 GetContainer(Container::START) 51 GetContainer(Container::START)
52 ->SetLayoutManager(GetLayoutManager(Container::START)); 52 ->SetLayoutManager(GetLayoutManager(Container::START));
53 GetContainer(Container::CENTER) 53 GetContainer(Container::CENTER)
54 ->SetLayoutManager(GetLayoutManager(Container::CENTER)); 54 ->SetLayoutManager(GetLayoutManager(Container::CENTER));
55 GetContainer(Container::END) 55 GetContainer(Container::END)
56 ->SetLayoutManager(GetLayoutManager(Container::END)); 56 ->SetLayoutManager(GetLayoutManager(Container::END));
57 57
58 GetLayoutManager(Container::START) 58 box_layout_->set_cross_axis_alignment(
59 ->SetLayoutManager(CreateDefaultLayoutManager(orientation)); 59 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
60 GetLayoutManager(Container::CENTER)
61 ->SetLayoutManager(CreateDefaultLayoutManager(orientation));
62 GetLayoutManager(Container::END)
63 ->SetLayoutManager(CreateDefaultLayoutManager(orientation));
64
65 SetLayoutManager(box_layout_); 60 SetLayoutManager(box_layout_);
66 61
67 enable_hierarchy_changed_dcheck_ = true; 62 enable_hierarchy_changed_dcheck_ = true;
68 } 63 }
69 64
70 TriView::~TriView() { 65 TriView::~TriView() {
71 enable_hierarchy_changed_dcheck_ = false; 66 enable_hierarchy_changed_dcheck_ = false;
72 } 67 }
73 68
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) { 69 void TriView::SetMinSize(Container container, const gfx::Size& size) {
79 GetLayoutManager(container)->SetMinSize(size); 70 GetLayoutManager(container)->SetMinSize(size);
80 } 71 }
81 72
82 void TriView::SetMaxSize(Container container, const gfx::Size& size) { 73 void TriView::SetMaxSize(Container container, const gfx::Size& size) {
83 GetLayoutManager(container)->SetMaxSize(size); 74 GetLayoutManager(container)->SetMaxSize(size);
84 } 75 }
85 76
86 void TriView::AddView(Container container, views::View* view) { 77 void TriView::AddView(Container container, views::View* view) {
87 GetContainer(container)->AddChildView(view); 78 GetContainer(container)->AddChildView(view);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 if (details.is_add) { 115 if (details.is_add) {
125 DCHECK(false) 116 DCHECK(false)
126 << "Child views should not be added directly. They should be added " 117 << "Child views should not be added directly. They should be added "
127 "using TriView::AddView()."; 118 "using TriView::AddView().";
128 } else { 119 } else {
129 DCHECK(false) << "Container views should not be removed."; 120 DCHECK(false) << "Container views should not be removed.";
130 } 121 }
131 } 122 }
132 } 123 }
133 124
134 std::unique_ptr<views::LayoutManager> TriView::CreateDefaultLayoutManager( 125 views::View* TriView::GetContainer(Container container) {
135 Orientation orientation) const { 126 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 } 127 }
144 128
145 views::View* TriView::GetContainer(Container container) const { 129 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) { 130 switch (container) {
151 case Container::START: 131 case Container::START:
152 return start_container_layout_manager_; 132 return start_container_layout_manager_;
153 case Container::CENTER: 133 case Container::CENTER:
154 return center_container_layout_manager_; 134 return center_container_layout_manager_;
155 case Container::END: 135 case Container::END:
156 return end_container_layout_manager_; 136 return end_container_layout_manager_;
157 } 137 }
158 // Required for some compilers. 138 // Required for some compilers.
159 NOTREACHED(); 139 NOTREACHED();
160 return nullptr; 140 return nullptr;
161 } 141 }
162 142
163 } // namespace ash 143 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/tri_view.h ('k') | ash/common/system/tray/tri_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698