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

Side by Side Diff: ash/common/system/chromeos/screen_security/screen_tray_item.cc

Issue 2463163002: Update chromeos system menu buttons for MD. (Closed)
Patch Set: boxlayout has some annoying dchecks 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chromeos/screen_security/screen_tray_item.h" 5 #include "ash/common/system/chromeos/screen_security/screen_tray_item.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/shelf/wm_shelf_util.h" 8 #include "ash/common/shelf/wm_shelf_util.h"
9 #include "ash/common/system/tray/fixed_sized_image_view.h" 9 #include "ash/common/system/tray/fixed_sized_image_view.h"
10 #include "ash/common/system/tray/tray_constants.h" 10 #include "ash/common/system/tray/tray_constants.h"
11 #include "ash/common/system/tray/tray_utils.h"
11 #include "ash/resources/vector_icons/vector_icons.h" 12 #include "ash/resources/vector_icons/vector_icons.h"
12 #include "grit/ash_resources.h" 13 #include "grit/ash_resources.h"
13 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/paint_vector_icon.h" 15 #include "ui/gfx/paint_vector_icon.h"
15 #include "ui/message_center/message_center.h" 16 #include "ui/message_center/message_center.h"
17 #include "ui/views/controls/button/label_button.h"
16 #include "ui/views/controls/label.h" 18 #include "ui/views/controls/label.h"
17 #include "ui/views/layout/box_layout.h" 19 #include "ui/views/layout/box_layout.h"
18 20
19 namespace { 21 namespace {
20 const int kStopButtonRightPadding = 18; 22 const int kStopButtonRightPadding = 18;
21 } // namespace 23 } // namespace
22 24
23 namespace ash { 25 namespace ash {
24 namespace tray { 26 namespace tray {
25 27
(...skipping 16 matching lines...) Expand all
42 44
43 void ScreenTrayView::Update() { 45 void ScreenTrayView::Update() {
44 SetVisible(screen_tray_item_->is_started()); 46 SetVisible(screen_tray_item_->is_started());
45 } 47 }
46 48
47 // ScreenStatusView implementations. 49 // ScreenStatusView implementations.
48 ScreenStatusView::ScreenStatusView(ScreenTrayItem* screen_tray_item, 50 ScreenStatusView::ScreenStatusView(ScreenTrayItem* screen_tray_item,
49 const base::string16& label_text, 51 const base::string16& label_text,
50 const base::string16& stop_button_text) 52 const base::string16& stop_button_text)
51 : screen_tray_item_(screen_tray_item), 53 : screen_tray_item_(screen_tray_item),
52 icon_(NULL), 54 icon_(nullptr),
53 label_(NULL), 55 label_(nullptr),
54 stop_button_(NULL), 56 stop_button_(nullptr),
55 label_text_(label_text), 57 label_text_(label_text),
56 stop_button_text_(stop_button_text) { 58 stop_button_text_(stop_button_text) {
57 CreateItems(); 59 CreateItems();
58 Update(); 60 if (screen_tray_item_)
61 UpdateFromScreenTrayItem();
59 } 62 }
60 63
61 ScreenStatusView::~ScreenStatusView() {} 64 ScreenStatusView::~ScreenStatusView() {}
62 65
63 void ScreenStatusView::Layout() {
64 views::View::Layout();
65
66 // Give the stop button the space it requests.
67 gfx::Size stop_size = stop_button_->GetPreferredSize();
68 gfx::Rect stop_bounds(stop_size);
69 stop_bounds.set_x(width() - stop_size.width() - kStopButtonRightPadding);
70 stop_bounds.set_y((height() - stop_size.height()) / 2);
71 stop_button_->SetBoundsRect(stop_bounds);
72
73 // Adjust the label's bounds in case it got cut off by |stop_button_|.
74 if (label_->bounds().Intersects(stop_button_->bounds())) {
75 gfx::Rect label_bounds = label_->bounds();
76 label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems -
77 label_->x());
78 label_->SetBoundsRect(label_bounds);
79 }
80 }
81
82 void ScreenStatusView::ButtonPressed(views::Button* sender, 66 void ScreenStatusView::ButtonPressed(views::Button* sender,
83 const ui::Event& event) { 67 const ui::Event& event) {
84 DCHECK(sender == stop_button_); 68 DCHECK(sender == stop_button_);
85 screen_tray_item_->Stop(); 69 screen_tray_item_->Stop();
86 screen_tray_item_->RecordStoppedFromDefaultViewMetric(); 70 screen_tray_item_->RecordStoppedFromDefaultViewMetric();
87 } 71 }
88 72
89 void ScreenStatusView::CreateItems() { 73 void ScreenStatusView::CreateItems() {
90 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 74 const bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial();
91 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 75 if (!use_md)
92 kTrayPopupPaddingHorizontal, 0, 76 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
93 kTrayPopupPaddingBetweenItems)); 77
78 auto layout =
79 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0,
80 use_md ? kTrayPopupPaddingBetweenItems : 0);
81 layout->set_cross_axis_alignment(
82 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
83 SetLayoutManager(layout);
84 SetBorder(views::Border::CreateEmptyBorder(
85 0, kTrayPopupPaddingHorizontal, 0,
86 use_md ? kTrayPopupButtonEndMargin : kStopButtonRightPadding));
94 87
95 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); 88 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
96 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 89 if (use_md) {
97 icon_->SetImage( 90 icon_->SetImage(
98 gfx::CreateVectorIcon(kSystemMenuScreenShareIcon, kMenuIconColor)); 91 gfx::CreateVectorIcon(kSystemMenuScreenShareIcon, kMenuIconColor));
99 } else { 92 } else {
100 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 93 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
101 icon_->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK) 94 icon_->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK)
102 .ToImageSkia()); 95 .ToImageSkia());
103 } 96 }
104 AddChildView(icon_); 97 AddChildView(icon_);
105 98
106 label_ = new views::Label; 99 label_ = new views::Label;
107 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 100 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
108 label_->SetMultiLine(true); 101 label_->SetMultiLine(true);
109 label_->SetText(label_text_); 102 label_->SetText(label_text_);
103 if (!use_md) {
104 label_->SetBorder(views::Border::CreateEmptyBorder(
105 0, kTrayPopupPaddingBetweenItems, 0, 0));
106 }
110 AddChildView(label_); 107 AddChildView(label_);
108 layout->SetFlexForView(label_, 1);
111 109
112 stop_button_ = new TrayPopupLabelButton(this, stop_button_text_); 110 stop_button_ = CreateTrayPopupButton(this, stop_button_text_);
113 AddChildView(stop_button_); 111 AddChildView(stop_button_);
114 } 112 }
115 113
116 void ScreenStatusView::Update() { 114 void ScreenStatusView::UpdateFromScreenTrayItem() {
117 // Hide the notification bubble when the ash tray bubble opens. 115 // Hide the notification bubble when the ash tray bubble opens.
118 screen_tray_item_->HideNotificationView(); 116 screen_tray_item_->HideNotificationView();
119 SetVisible(screen_tray_item_->is_started()); 117 SetVisible(screen_tray_item_->is_started());
120 } 118 }
121 119
122 ScreenNotificationDelegate::ScreenNotificationDelegate( 120 ScreenNotificationDelegate::ScreenNotificationDelegate(
123 ScreenTrayItem* screen_tray) 121 ScreenTrayItem* screen_tray)
124 : screen_tray_(screen_tray) {} 122 : screen_tray_(screen_tray) {}
125 123
126 ScreenNotificationDelegate::~ScreenNotificationDelegate() {} 124 ScreenNotificationDelegate::~ScreenNotificationDelegate() {}
127 125
128 void ScreenNotificationDelegate::ButtonClick(int button_index) { 126 void ScreenNotificationDelegate::ButtonClick(int button_index) {
129 DCHECK_EQ(0, button_index); 127 DCHECK_EQ(0, button_index);
130 screen_tray_->Stop(); 128 screen_tray_->Stop();
131 screen_tray_->RecordStoppedFromNotificationViewMetric(); 129 screen_tray_->RecordStoppedFromNotificationViewMetric();
132 } 130 }
133 131
134 } // namespace tray 132 } // namespace tray
135 133
136 ScreenTrayItem::ScreenTrayItem(SystemTray* system_tray, UmaType uma_type) 134 ScreenTrayItem::ScreenTrayItem(SystemTray* system_tray, UmaType uma_type)
137 : SystemTrayItem(system_tray, uma_type), 135 : SystemTrayItem(system_tray, uma_type),
138 tray_view_(NULL), 136 tray_view_(nullptr),
139 default_view_(NULL), 137 default_view_(nullptr),
140 is_started_(false), 138 is_started_(false),
141 stop_callback_(base::Bind(&base::DoNothing)) {} 139 stop_callback_(base::Bind(&base::DoNothing)) {}
142 140
143 ScreenTrayItem::~ScreenTrayItem() {} 141 ScreenTrayItem::~ScreenTrayItem() {}
144 142
145 void ScreenTrayItem::Update() { 143 void ScreenTrayItem::Update() {
146 if (tray_view_) 144 if (tray_view_)
147 tray_view_->Update(); 145 tray_view_->Update();
148 if (default_view_) 146 if (default_view_)
149 default_view_->Update(); 147 default_view_->UpdateFromScreenTrayItem();
150 if (is_started_) { 148 if (is_started_) {
151 CreateOrUpdateNotification(); 149 CreateOrUpdateNotification();
152 } else { 150 } else {
153 message_center::MessageCenter::Get()->RemoveNotification( 151 message_center::MessageCenter::Get()->RemoveNotification(
154 GetNotificationId(), false /* by_user */); 152 GetNotificationId(), false /* by_user */);
155 } 153 }
156 } 154 }
157 155
158 void ScreenTrayItem::Start(const base::Closure& stop_callback) { 156 void ScreenTrayItem::Start(const base::Closure& stop_callback) {
159 stop_callback_ = stop_callback; 157 stop_callback_ = stop_callback;
160 is_started_ = true; 158 is_started_ = true;
161 159
162 if (tray_view_) 160 if (tray_view_)
163 tray_view_->Update(); 161 tray_view_->Update();
164 162
165 if (default_view_) 163 if (default_view_)
166 default_view_->Update(); 164 default_view_->UpdateFromScreenTrayItem();
167 165
168 if (!system_tray()->HasSystemBubbleType( 166 if (!system_tray()->HasSystemBubbleType(
169 SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { 167 SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) {
170 CreateOrUpdateNotification(); 168 CreateOrUpdateNotification();
171 } 169 }
172 } 170 }
173 171
174 void ScreenTrayItem::Stop() { 172 void ScreenTrayItem::Stop() {
175 is_started_ = false; 173 is_started_ = false;
176 Update(); 174 Update();
177 175
178 if (stop_callback_.is_null()) 176 if (stop_callback_.is_null())
179 return; 177 return;
180 178
181 base::Closure callback = stop_callback_; 179 base::Closure callback = stop_callback_;
182 stop_callback_.Reset(); 180 stop_callback_.Reset();
183 callback.Run(); 181 callback.Run();
184 } 182 }
185 183
186 views::View* ScreenTrayItem::CreateTrayView(LoginStatus status) { 184 views::View* ScreenTrayItem::CreateTrayView(LoginStatus status) {
187 tray_view_ = new tray::ScreenTrayView(this); 185 tray_view_ = new tray::ScreenTrayView(this);
188 return tray_view_; 186 return tray_view_;
189 } 187 }
190 188
191 void ScreenTrayItem::RecordStoppedFromDefaultViewMetric() {} 189 void ScreenTrayItem::RecordStoppedFromDefaultViewMetric() {}
192 190
193 void ScreenTrayItem::RecordStoppedFromNotificationViewMetric() {} 191 void ScreenTrayItem::RecordStoppedFromNotificationViewMetric() {}
194 192
195 void ScreenTrayItem::DestroyTrayView() { 193 void ScreenTrayItem::DestroyTrayView() {
196 tray_view_ = NULL; 194 tray_view_ = nullptr;
197 } 195 }
198 196
199 void ScreenTrayItem::DestroyDefaultView() { 197 void ScreenTrayItem::DestroyDefaultView() {
200 default_view_ = NULL; 198 default_view_ = nullptr;
201 } 199 }
202 200
203 } // namespace ash 201 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/screen_security/screen_tray_item.h ('k') | ash/common/system/tray/system_tray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698