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

Side by Side Diff: ash/common/system/tray/tray_popup_utils.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/tray_popup_utils.h ('k') | ash/common/system/tray/tri_view.h » ('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/tray_popup_utils.h" 5 #include "ash/common/system/tray/tray_popup_utils.h"
6 6
7 #include "ash/common/ash_constants.h" 7 #include "ash/common/ash_constants.h"
8 #include "ash/common/material_design/material_design_controller.h" 8 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/session/session_state_delegate.h" 9 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/system/tray/fixed_sized_image_view.h" 10 #include "ash/common/system/tray/fixed_sized_image_view.h"
(...skipping 14 matching lines...) Expand all
25 #include "ui/views/layout/fill_layout.h" 25 #include "ui/views/layout/fill_layout.h"
26 26
27 namespace ash { 27 namespace ash {
28 28
29 namespace { 29 namespace {
30 30
31 // Creates a layout manager that positions Views vertically. The Views will be 31 // Creates a layout manager that positions Views vertically. The Views will be
32 // stretched horizontally and centered vertically. 32 // stretched horizontally and centered vertically.
33 std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() { 33 std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() {
34 // TODO(bruthig): Use constants instead of magic numbers. 34 // TODO(bruthig): Use constants instead of magic numbers.
35 views::BoxLayout* box_layout = 35 auto box_layout =
36 new views::BoxLayout(views::BoxLayout::kVertical, 4, 8, 4); 36 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 4, 8, 4);
37 box_layout->set_main_axis_alignment( 37 box_layout->set_main_axis_alignment(
38 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); 38 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
39 box_layout->set_cross_axis_alignment( 39 box_layout->set_cross_axis_alignment(
40 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); 40 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
41 return std::unique_ptr<views::LayoutManager>(box_layout); 41 return std::move(box_layout);
42 } 42 }
43 43
44 // Creates a layout manager that positions Views horizontally. The Views will be 44 // Creates a layout manager that positions Views horizontally. The Views will be
45 // centered along the horizontal and vertical axis. 45 // centered along the horizontal and vertical axis.
46 std::unique_ptr<views::LayoutManager> CreateDefaultEndsLayoutManager() { 46 std::unique_ptr<views::LayoutManager> CreateDefaultEndsLayoutManager() {
47 views::BoxLayout* box_layout = 47 auto box_layout = base::MakeUnique<views::BoxLayout>(
48 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); 48 views::BoxLayout::kHorizontal, 0, 0, 0);
49 box_layout->set_main_axis_alignment( 49 box_layout->set_main_axis_alignment(
50 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); 50 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
51 box_layout->set_cross_axis_alignment( 51 box_layout->set_cross_axis_alignment(
52 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); 52 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
53 return std::unique_ptr<views::LayoutManager>(box_layout); 53 return std::move(box_layout);
54 }
55
56 std::unique_ptr<views::LayoutManager> CreateDefaultLayoutManager(
57 TriView::Container container) {
58 switch (container) {
59 case TriView::Container::START:
60 case TriView::Container::END:
61 return CreateDefaultEndsLayoutManager();
62 case TriView::Container::CENTER:
63 return CreateDefaultCenterLayoutManager();
64 }
65 // Required by some compilers.
66 NOTREACHED();
67 return nullptr;
68 }
69
70 // Configures the default size and flex value for the specified |container|
71 // of the given |tri_view|. Used by CreateDefaultRowView().
72 void ConfigureDefaultSizeAndFlex(TriView* tri_view,
73 TriView::Container container) {
74 int min_width = 0;
75 switch (container) {
76 case TriView::Container::START:
77 min_width = GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH);
78 break;
79 case TriView::Container::CENTER:
80 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f);
81 break;
82 case TriView::Container::END:
83 min_width = GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH);
84 break;
85 }
86
87 tri_view->SetMinSize(
88 container, gfx::Size(min_width, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)));
54 } 89 }
55 90
56 class BorderlessLabelButton : public views::LabelButton { 91 class BorderlessLabelButton : public views::LabelButton {
57 public: 92 public:
58 BorderlessLabelButton(views::ButtonListener* listener, 93 BorderlessLabelButton(views::ButtonListener* listener,
59 const base::string16& text) 94 const base::string16& text)
60 : LabelButton(listener, text) { 95 : LabelButton(listener, text) {
61 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 96 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
62 SetInkDropMode(views::InkDropHostView::InkDropMode::ON); 97 SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
63 set_has_ink_drop_action_on_click(true); 98 set_has_ink_drop_action_on_click(true);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 156
122 return tri_view; 157 return tri_view;
123 } 158 }
124 159
125 TriView* TrayPopupUtils::CreateMultiTargetRowView() { 160 TriView* TrayPopupUtils::CreateMultiTargetRowView() {
126 TriView* tri_view = new TriView(0 /* padding_between_items */); 161 TriView* tri_view = new TriView(0 /* padding_between_items */);
127 162
128 tri_view->SetInsets( 163 tri_view->SetInsets(
129 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0, 164 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0,
130 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); 165 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET)));
131 tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
132 166
133 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::START); 167 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::START);
134 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::CENTER); 168 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::CENTER);
135 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::END); 169 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::END);
136 170
137 tri_view->SetContainerLayout(TriView::Container::START, 171 tri_view->SetContainerLayout(TriView::Container::START,
138 base::MakeUnique<views::FillLayout>()); 172 base::MakeUnique<views::FillLayout>());
139 tri_view->SetContainerLayout(TriView::Container::CENTER, 173 tri_view->SetContainerLayout(TriView::Container::CENTER,
140 base::MakeUnique<views::FillLayout>()); 174 base::MakeUnique<views::FillLayout>());
141 tri_view->SetContainerLayout(TriView::Container::END, 175 tri_view->SetContainerLayout(TriView::Container::END,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 return slider; 224 return slider;
191 } 225 }
192 226
193 void TrayPopupUtils::ConfigureContainer(TriView::Container container, 227 void TrayPopupUtils::ConfigureContainer(TriView::Container container,
194 views::View* container_view) { 228 views::View* container_view) {
195 container_view->SetBorder(CreateDefaultBorder(container)); 229 container_view->SetBorder(CreateDefaultBorder(container));
196 container_view->SetLayoutManager( 230 container_view->SetLayoutManager(
197 CreateDefaultLayoutManager(container).release()); 231 CreateDefaultLayoutManager(container).release());
198 } 232 }
199 233
200 void TrayPopupUtils::ConfigureDefaultSizeAndFlex(TriView* tri_view,
201 TriView::Container container) {
202 switch (container) {
203 case TriView::Container::START:
204 tri_view->SetMinSize(
205 TriView::Container::START,
206 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0));
207 break;
208 case TriView::Container::CENTER:
209 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f);
210 break;
211 case TriView::Container::END:
212 tri_view->SetMinSize(
213 TriView::Container::END,
214 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0));
215 break;
216 }
217 }
218
219 views::LabelButton* TrayPopupUtils::CreateTrayPopupBorderlessButton( 234 views::LabelButton* TrayPopupUtils::CreateTrayPopupBorderlessButton(
220 views::ButtonListener* listener, 235 views::ButtonListener* listener,
221 const base::string16& text) { 236 const base::string16& text) {
222 return new BorderlessLabelButton(listener, text); 237 return new BorderlessLabelButton(listener, text);
223 } 238 }
224 239
225 views::LabelButton* TrayPopupUtils::CreateTrayPopupButton( 240 views::LabelButton* TrayPopupUtils::CreateTrayPopupButton(
226 views::ButtonListener* listener, 241 views::ButtonListener* listener,
227 const base::string16& text) { 242 const base::string16& text) {
228 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) 243 if (!MaterialDesignController::IsSystemTrayMenuMaterial())
(...skipping 14 matching lines...) Expand all
243 258
244 bool TrayPopupUtils::CanOpenWebUISettings(LoginStatus status) { 259 bool TrayPopupUtils::CanOpenWebUISettings(LoginStatus status) {
245 // TODO(tdanderson): Consider moving this into WmShell, or introduce a 260 // TODO(tdanderson): Consider moving this into WmShell, or introduce a
246 // CanShowSettings() method in each delegate type that has a 261 // CanShowSettings() method in each delegate type that has a
247 // ShowSettings() method. 262 // ShowSettings() method.
248 return status != LoginStatus::NOT_LOGGED_IN && 263 return status != LoginStatus::NOT_LOGGED_IN &&
249 status != LoginStatus::LOCKED && 264 status != LoginStatus::LOCKED &&
250 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); 265 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen();
251 } 266 }
252 267
253 std::unique_ptr<views::LayoutManager>
254 TrayPopupUtils::CreateDefaultLayoutManager(TriView::Container container) {
255 switch (container) {
256 case TriView::Container::START:
257 case TriView::Container::END:
258 return CreateDefaultEndsLayoutManager();
259 case TriView::Container::CENTER:
260 return CreateDefaultCenterLayoutManager();
261 }
262 // Required by some compilers.
263 NOTREACHED();
264 return nullptr;
265 }
266
267 std::unique_ptr<views::Border> TrayPopupUtils::CreateDefaultBorder( 268 std::unique_ptr<views::Border> TrayPopupUtils::CreateDefaultBorder(
268 TriView::Container container) { 269 TriView::Container container) {
269 switch (container) { 270 switch (container) {
270 case TriView::Container::START: 271 case TriView::Container::START:
271 // TODO(bruthig): Update the 'Main' images to have a fixed size that is 272 // TODO(bruthig): Update the 'Main' images to have a fixed size that is
272 // just the painted size and add a border. 273 // just the painted size and add a border.
273 return nullptr; 274 return nullptr;
274 break; 275 break;
275 case TriView::Container::CENTER: 276 case TriView::Container::CENTER:
276 return nullptr; 277 return nullptr;
277 break; 278 break;
278 case TriView::Container::END: 279 case TriView::Container::END:
279 return views::CreateEmptyBorder( 280 return views::CreateEmptyBorder(
280 0, GetTrayConstant(TRAY_POPUP_ITEM_MORE_REGION_HORIZONTAL_INSET), 0, 281 0, GetTrayConstant(TRAY_POPUP_ITEM_MORE_REGION_HORIZONTAL_INSET), 0,
281 GetTrayConstant(TRAY_POPUP_ITEM_MORE_REGION_HORIZONTAL_INSET)); 282 GetTrayConstant(TRAY_POPUP_ITEM_MORE_REGION_HORIZONTAL_INSET));
282 break; 283 break;
283 } 284 }
284 // Required by some compilers. 285 // Required by some compilers.
285 NOTREACHED(); 286 NOTREACHED();
286 return nullptr; 287 return nullptr;
287 } 288 }
288 289
289 } // namespace ash 290 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/tray_popup_utils.h ('k') | ash/common/system/tray/tri_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698