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

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

Issue 2468533002: [ash-md] Applied Material Design layout to TrayItemMore system menu rows. (Closed)
Patch Set: Merge branch 'master' into md_system_menu_tray_item_more_layout 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
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_layout_factory.h" 5 #include "ash/common/system/tray/tray_popup_utils.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/system/tray/fixed_sized_image_view.h"
8 #include "ash/common/system/tray/tray_constants.h" 9 #include "ash/common/system/tray/tray_constants.h"
9 #include "ash/common/system/tray/tri_view.h" 10 #include "ash/common/system/tray/tray_popup_label_button.h"
11 #include "ui/views/border.h"
10 #include "ui/views/controls/button/label_button.h" 12 #include "ui/views/controls/button/label_button.h"
13 #include "ui/views/controls/image_view.h"
14 #include "ui/views/controls/label.h"
15 #include "ui/views/controls/slider.h"
tdanderson 2016/11/01 18:59:44 Is this include needed?
bruthig 2016/11/01 23:00:43 Removed.
11 #include "ui/views/layout/box_layout.h" 16 #include "ui/views/layout/box_layout.h"
12 17
13 namespace ash { 18 namespace ash {
14 19
15 namespace { 20 namespace {
16 21
17 // Creates a layout manager that positions Views vertically. The Views will be 22 // Creates a layout manager that positions Views vertically. The Views will be
18 // stretched horizontally and centered vertically. 23 // stretched horizontally and centered vertically.
19 std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() { 24 std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() {
20 // TODO(bruthig): Use constants instead of magic numbers. 25 // TODO(bruthig): Use constants instead of magic numbers.
21 views::BoxLayout* box_layout = 26 views::BoxLayout* box_layout =
22 new views::BoxLayout(views::BoxLayout::kVertical, 4, 8, 4); 27 new views::BoxLayout(views::BoxLayout::kVertical, 4, 8, 4);
23 box_layout->set_main_axis_alignment( 28 box_layout->set_main_axis_alignment(
24 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); 29 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
25 box_layout->set_cross_axis_alignment( 30 box_layout->set_cross_axis_alignment(
26 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); 31 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
27 return std::unique_ptr<views::LayoutManager>(box_layout); 32 return std::unique_ptr<views::LayoutManager>(box_layout);
28 } 33 }
29 34
30 // Creates a layout manager that positions Views horizontally. The Views will be 35 // Creates a layout manager that positions Views horizontally. The Views will be
31 // centered along the horizontal and vertical axis. 36 // centered along the horizontal and vertical axis.
32 std::unique_ptr<views::LayoutManager> CreateDefaultEndsLayoutManager() { 37 std::unique_ptr<views::LayoutManager> CreateDefaultEndsLayoutManager() {
33 views::BoxLayout* box_layout = 38 views::BoxLayout* box_layout =
34 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); 39 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
35 box_layout->set_main_axis_alignment( 40 box_layout->set_main_axis_alignment(
36 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); 41 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
37 box_layout->set_cross_axis_alignment( 42 box_layout->set_cross_axis_alignment(
38 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 43 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
tdanderson 2016/11/01 18:59:44 It seems CENTER is what you want here instead of S
bruthig 2016/11/01 23:00:43 Actually this should be START if we are trying to
39 return std::unique_ptr<views::LayoutManager>(box_layout); 44 return std::unique_ptr<views::LayoutManager>(box_layout);
40 } 45 }
41 46
42 } // namespace 47 } // namespace
43 48
44 TriView* TrayPopupLayoutFactory::CreateDefaultRowView() { 49 TriView* TrayPopupUtils::CreateDefaultRowView() {
45 TriView* tri_view = new TriView(0 /* padding_between_items */); 50 TriView* tri_view = new TriView(0 /* padding_between_items */);
46 51
47 tri_view->SetInsets( 52 tri_view->SetInsets(
48 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0, 53 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0,
49 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); 54 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET)));
50 tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); 55 tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
51 56
52 ConfigureDefaultLayout(tri_view, TriView::Container::START); 57 ConfigureDefaultLayout(tri_view, TriView::Container::START);
53 ConfigureDefaultLayout(tri_view, TriView::Container::CENTER); 58 ConfigureDefaultLayout(tri_view, TriView::Container::CENTER);
54 ConfigureDefaultLayout(tri_view, TriView::Container::END); 59 ConfigureDefaultLayout(tri_view, TriView::Container::END);
55 60
56 return tri_view; 61 return tri_view;
57 } 62 }
58 63
59 void TrayPopupLayoutFactory::ConfigureDefaultLayout( 64 std::unique_ptr<views::LayoutManager> TrayPopupUtils::CreateLayoutManager(
60 TriView* tri_view,
61 TriView::Container container) { 65 TriView::Container container) {
62 switch (container) { 66 switch (container) {
63 case TriView::Container::START: 67 case TriView::Container::START:
64 tri_view->SetContainerLayout(TriView::Container::START, 68 case TriView::Container::END:
65 CreateDefaultEndsLayoutManager()); 69 return CreateDefaultEndsLayoutManager();
70 case TriView::Container::CENTER:
71 return CreateDefaultCenterLayoutManager();
72 }
73 // Required by some compilers.
74 NOTREACHED();
75 return nullptr;
76 }
77
78 views::Label* TrayPopupUtils::CreateDefaultLabel() {
79 views::Label* label = new views::Label();
80 label->SetBorder(
81 views::Border::CreateEmptyBorder(0, kTrayPopupLabelHorizontalPadding, 0,
82 kTrayPopupLabelHorizontalPadding));
83 return label;
84 }
85
86 views::ImageView* TrayPopupUtils::CreateMainImageView() {
87 return new FixedSizedImageView(
88 GetTrayConstant(TRAY_POPUP_ITEM_MAIN_IMAGE_CONTAINER_WIDTH),
89 GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
90 }
91
92 views::ImageView* TrayPopupUtils::CreateMoreImageView() {
93 return new FixedSizedImageView(
94 GetTrayConstant(TRAY_POPUP_ITEM_MORE_IMAGE_CONTAINER_WIDTH),
95 GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
96 }
97
98 void TrayPopupUtils::ConfigureDefaultLayout(TriView* tri_view,
99 TriView::Container container) {
100 switch (container) {
101 case TriView::Container::START:
66 tri_view->SetMinSize( 102 tri_view->SetMinSize(
67 TriView::Container::START, 103 TriView::Container::START,
68 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0)); 104 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0));
69 break; 105 break;
70 case TriView::Container::CENTER: 106 case TriView::Container::CENTER:
71 tri_view->SetContainerLayout(TriView::Container::CENTER,
72 CreateDefaultCenterLayoutManager());
73 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f); 107 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f);
74 break; 108 break;
75 case TriView::Container::END: 109 case TriView::Container::END:
76 tri_view->SetContainerLayout(TriView::Container::END,
77 CreateDefaultEndsLayoutManager());
78 tri_view->SetMinSize( 110 tri_view->SetMinSize(
79 TriView::Container::END, 111 TriView::Container::END,
80 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0)); 112 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0));
81 break; 113 break;
82 } 114 }
115
116 tri_view->SetContainerLayout(container, CreateLayoutManager(container));
83 } 117 }
84 118
85 } // namespace ash 119 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698