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

Side by Side Diff: ash/common/system/chromeos/bluetooth/tray_bluetooth.cc

Issue 2684293002: Remove non-MD code from Bluetooth tray. (Closed)
Patch Set: Created 3 years, 10 months 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 | « no previous file | ash/resources/ash_resources.grd » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bluetooth/tray_bluetooth.h" 5 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/session/session_state_delegate.h" 7 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/system/tray/hover_highlight_view.h" 8 #include "ash/common/system/tray/hover_highlight_view.h"
10 #include "ash/common/system/tray/system_tray.h" 9 #include "ash/common/system/tray/system_tray.h"
11 #include "ash/common/system/tray/system_tray_delegate.h" 10 #include "ash/common/system/tray/system_tray_delegate.h"
12 #include "ash/common/system/tray/system_tray_notifier.h" 11 #include "ash/common/system/tray/system_tray_notifier.h"
13 #include "ash/common/system/tray/throbber_view.h" 12 #include "ash/common/system/tray/throbber_view.h"
tdanderson 2017/02/10 15:51:01 I think this can be removed too
fukino 2017/02/11 00:25:01 ThrobberView is still in use for connecting rows.
tdanderson 2017/02/13 17:14:59 Acknowledged.
14 #include "ash/common/system/tray/tray_constants.h" 13 #include "ash/common/system/tray/tray_constants.h"
15 #include "ash/common/system/tray/tray_details_view.h" 14 #include "ash/common/system/tray/tray_details_view.h"
16 #include "ash/common/system/tray/tray_item_more.h" 15 #include "ash/common/system/tray/tray_item_more.h"
17 #include "ash/common/system/tray/tray_popup_header_button.h" 16 #include "ash/common/system/tray/tray_popup_header_button.h"
tdanderson 2017/02/10 15:51:01 Can also be removed
fukino 2017/02/11 00:25:01 Done.
18 #include "ash/common/system/tray/tray_popup_item_style.h" 17 #include "ash/common/system/tray/tray_popup_item_style.h"
19 #include "ash/common/system/tray/tray_popup_utils.h" 18 #include "ash/common/system/tray/tray_popup_utils.h"
20 #include "ash/common/system/tray/tri_view.h" 19 #include "ash/common/system/tray/tri_view.h"
21 #include "ash/common/wm_shell.h" 20 #include "ash/common/wm_shell.h"
22 #include "ash/resources/vector_icons/vector_icons.h" 21 #include "ash/resources/vector_icons/vector_icons.h"
23 #include "device/bluetooth/bluetooth_common.h" 22 #include "device/bluetooth/bluetooth_common.h"
24 #include "grit/ash_resources.h" 23 #include "grit/ash_resources.h"
25 #include "grit/ash_strings.h" 24 #include "grit/ash_strings.h"
26 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/color_palette.h" 27 #include "ui/gfx/color_palette.h"
29 #include "ui/gfx/image/image.h" 28 #include "ui/gfx/image/image.h"
30 #include "ui/gfx/paint_vector_icon.h" 29 #include "ui/gfx/paint_vector_icon.h"
31 #include "ui/gfx/vector_icons_public.h" 30 #include "ui/gfx/vector_icons_public.h"
32 #include "ui/views/controls/button/toggle_button.h" 31 #include "ui/views/controls/button/toggle_button.h"
33 #include "ui/views/controls/image_view.h" 32 #include "ui/views/controls/image_view.h"
34 #include "ui/views/controls/label.h" 33 #include "ui/views/controls/label.h"
35 #include "ui/views/controls/progress_bar.h" 34 #include "ui/views/controls/progress_bar.h"
36 #include "ui/views/controls/scroll_view.h" 35 #include "ui/views/controls/scroll_view.h"
37 #include "ui/views/controls/separator.h" 36 #include "ui/views/controls/separator.h"
38 #include "ui/views/layout/box_layout.h" 37 #include "ui/views/layout/box_layout.h"
39 38
40 namespace ash { 39 namespace ash {
41 namespace tray { 40 namespace tray {
42 namespace { 41 namespace {
43 42
44 bool UseMd() {
45 return MaterialDesignController::IsSystemTrayMenuMaterial();
46 }
47
48 // Updates bluetooth device |device| in the |list|. If it is new, append to the 43 // Updates bluetooth device |device| in the |list|. If it is new, append to the
49 // end of the |list|; otherwise, keep it at the same place, but update the data 44 // end of the |list|; otherwise, keep it at the same place, but update the data
50 // with new device info provided by |device|. 45 // with new device info provided by |device|.
51 void UpdateBluetoothDeviceListHelper(BluetoothDeviceList* list, 46 void UpdateBluetoothDeviceListHelper(BluetoothDeviceList* list,
52 const BluetoothDeviceInfo& device) { 47 const BluetoothDeviceInfo& device) {
53 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); 48 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end();
54 ++it) { 49 ++it) {
55 if ((*it).address == device.address) { 50 if ((*it).address == device.address) {
56 *it = device; 51 *it = device;
57 return; 52 return;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 : ash::kSystemMenuBluetoothIcon; 107 : ash::kSystemMenuBluetoothIcon;
113 } 108 }
114 109
115 const int kDisabledPanelLabelBaselineY = 20; 110 const int kDisabledPanelLabelBaselineY = 20;
116 111
117 } // namespace 112 } // namespace
118 113
119 class BluetoothDefaultView : public TrayItemMore { 114 class BluetoothDefaultView : public TrayItemMore {
120 public: 115 public:
121 BluetoothDefaultView(SystemTrayItem* owner, bool show_more) 116 BluetoothDefaultView(SystemTrayItem* owner, bool show_more)
122 : TrayItemMore(owner, show_more) { 117 : TrayItemMore(owner, show_more) {}
123 if (!UseMd()) {
124 // The icon doesn't change in non-md.
125 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
126 SetImage(
127 *bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia());
128 }
129 }
130 118
131 ~BluetoothDefaultView() override {} 119 ~BluetoothDefaultView() override {}
132 120
133 void Update() { 121 void Update() {
134 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 122 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
135 const bool enabled = delegate->GetBluetoothEnabled(); 123 const bool enabled = delegate->GetBluetoothEnabled();
136 if (delegate->GetBluetoothAvailable()) { 124 if (delegate->GetBluetoothAvailable()) {
137 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 125 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
138 const base::string16 label = rb.GetLocalizedString( 126 const base::string16 label = rb.GetLocalizedString(
139 enabled ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED 127 enabled ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED
(...skipping 17 matching lines...) Expand all
157 ? TrayPopupItemStyle::ColorStyle::ACTIVE 145 ? TrayPopupItemStyle::ColorStyle::ACTIVE
158 : delegate->GetBluetoothAvailable() 146 : delegate->GetBluetoothAvailable()
159 ? TrayPopupItemStyle::ColorStyle::INACTIVE 147 ? TrayPopupItemStyle::ColorStyle::INACTIVE
160 : TrayPopupItemStyle::ColorStyle::DISABLED); 148 : TrayPopupItemStyle::ColorStyle::DISABLED);
161 149
162 return style; 150 return style;
163 } 151 }
164 152
165 void UpdateStyle() override { 153 void UpdateStyle() override {
166 TrayItemMore::UpdateStyle(); 154 TrayItemMore::UpdateStyle();
167
168 if (!UseMd())
169 return;
170
171 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); 155 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle();
172 SetImage(gfx::CreateVectorIcon(GetCurrentIcon(), style->GetIconColor())); 156 SetImage(gfx::CreateVectorIcon(GetCurrentIcon(), style->GetIconColor()));
173 } 157 }
174 158
175 private: 159 private:
176 const gfx::VectorIcon& GetCurrentIcon() { 160 const gfx::VectorIcon& GetCurrentIcon() {
177 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 161 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
178 if (!delegate->GetBluetoothEnabled()) 162 if (!delegate->GetBluetoothEnabled())
179 return kSystemMenuBluetoothDisabledIcon; 163 return kSystemMenuBluetoothDisabledIcon;
180 164
(...skipping 11 matching lines...) Expand all
192 } 176 }
193 177
194 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); 178 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView);
195 }; 179 };
196 180
197 class BluetoothDetailedView : public TrayDetailsView { 181 class BluetoothDetailedView : public TrayDetailsView {
198 public: 182 public:
199 BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login) 183 BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login)
200 : TrayDetailsView(owner), 184 : TrayDetailsView(owner),
201 login_(login), 185 login_(login),
202 manage_devices_(nullptr),
203 throbber_(nullptr),
204 toggle_bluetooth_(nullptr),
205 enable_bluetooth_(nullptr), 186 enable_bluetooth_(nullptr),
206 toggle_(nullptr), 187 toggle_(nullptr),
207 settings_(nullptr), 188 settings_(nullptr),
208 disabled_panel_(nullptr) { 189 disabled_panel_(nullptr) {
209 CreateItems(); 190 CreateItems();
210 } 191 }
211 192
212 ~BluetoothDetailedView() override { 193 ~BluetoothDetailedView() override {
213 // Stop discovering bluetooth devices when exiting BT detailed view. 194 // Stop discovering bluetooth devices when exiting BT detailed view.
214 BluetoothStopDiscovering(); 195 BluetoothStopDiscovering();
215 } 196 }
216 197
217 void Update() { 198 void Update() {
218 BluetoothStartDiscovering(); 199 BluetoothStartDiscovering();
219 UpdateBluetoothDeviceList(); 200 UpdateBluetoothDeviceList();
220 201
221 // Update UI. 202 // Update UI.
222 UpdateDeviceScrollList(); 203 UpdateDeviceScrollList();
223 UpdateHeaderEntry(); 204 UpdateHeaderEntry();
224 Layout(); 205 Layout();
225 } 206 }
226 207
227 private: 208 private:
228 void CreateItems() { 209 void CreateItems() {
229 CreateScrollableList(); 210 CreateScrollableList();
230 AppendSettingsEntries();
231 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH); 211 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH);
232 } 212 }
233 213
234 void BluetoothStartDiscovering() { 214 void BluetoothStartDiscovering() {
235 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 215 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
236 if (delegate->GetBluetoothDiscovering()) { 216 if (delegate->GetBluetoothDiscovering()) {
237 ShowLoadingIndicator(); 217 ShowLoadingIndicator();
238 return; 218 return;
239 } 219 }
240 HideLoadingIndicator(); 220 HideLoadingIndicator();
(...skipping 12 matching lines...) Expand all
253 void UpdateBluetoothDeviceList() { 233 void UpdateBluetoothDeviceList() {
254 std::set<std::string> new_connecting_devices; 234 std::set<std::string> new_connecting_devices;
255 std::set<std::string> new_connected_devices; 235 std::set<std::string> new_connected_devices;
256 std::set<std::string> new_paired_not_connected_devices; 236 std::set<std::string> new_paired_not_connected_devices;
257 std::set<std::string> new_discovered_not_paired_devices; 237 std::set<std::string> new_discovered_not_paired_devices;
258 238
259 BluetoothDeviceList list; 239 BluetoothDeviceList list;
260 WmShell::Get()->system_tray_delegate()->GetAvailableBluetoothDevices(&list); 240 WmShell::Get()->system_tray_delegate()->GetAvailableBluetoothDevices(&list);
261 for (size_t i = 0; i < list.size(); ++i) { 241 for (size_t i = 0; i < list.size(); ++i) {
262 if (list[i].connecting) { 242 if (list[i].connecting) {
263 if (!UseMd()) {
264 list[i].display_name = l10n_util::GetStringFUTF16(
265 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, list[i].display_name);
tdanderson 2017/02/10 15:51:01 I think you can remove this string resource too si
fukino 2017/02/11 00:25:01 You are right. Thank you for pointing this out! Do
266 }
267 new_connecting_devices.insert(list[i].address); 243 new_connecting_devices.insert(list[i].address);
268 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]); 244 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]);
269 } else if (list[i].connected && list[i].paired) { 245 } else if (list[i].connected && list[i].paired) {
270 new_connected_devices.insert(list[i].address); 246 new_connected_devices.insert(list[i].address);
271 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]); 247 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]);
272 } else if (list[i].paired) { 248 } else if (list[i].paired) {
273 new_paired_not_connected_devices.insert(list[i].address); 249 new_paired_not_connected_devices.insert(list[i].address);
274 UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_, 250 UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_,
275 list[i]); 251 list[i]);
276 } else { 252 } else {
(...skipping 10 matching lines...) Expand all
287 new_paired_not_connected_devices); 263 new_paired_not_connected_devices);
288 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, 264 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_,
289 new_discovered_not_paired_devices); 265 new_discovered_not_paired_devices);
290 } 266 }
291 267
292 void UpdateHeaderEntry() { 268 void UpdateHeaderEntry() {
293 bool is_bluetooth_enabled = 269 bool is_bluetooth_enabled =
294 WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled(); 270 WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled();
295 if (toggle_) 271 if (toggle_)
296 toggle_->SetIsOn(is_bluetooth_enabled, false); 272 toggle_->SetIsOn(is_bluetooth_enabled, false);
297 else if (toggle_bluetooth_)
298 toggle_bluetooth_->SetToggled(!is_bluetooth_enabled);
299 } 273 }
300 274
301 void UpdateDeviceScrollList() { 275 void UpdateDeviceScrollList() {
302 device_map_.clear(); 276 device_map_.clear();
303 scroll_content()->RemoveAllChildViews(true); 277 scroll_content()->RemoveAllChildViews(true);
304 enable_bluetooth_ = nullptr; 278 enable_bluetooth_ = nullptr;
305 279
306 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 280 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
307 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); 281 bool bluetooth_enabled = delegate->GetBluetoothEnabled();
308 bool bluetooth_available = delegate->GetBluetoothAvailable(); 282 bool bluetooth_available = delegate->GetBluetoothAvailable();
309 if (bluetooth_available && !bluetooth_enabled && toggle_bluetooth_) {
310 enable_bluetooth_ = AddScrollListItem(
311 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH),
tdanderson 2017/02/10 15:51:01 This string also looks like it's no longer used
fukino 2017/02/11 00:25:01 DONE. I removed IDS_ASH_STATUS_TRAY_DISABLE_BLUETO
tdanderson 2017/02/13 17:14:59 Great, thanks for catching those other two strings
fukino 2017/02/13 19:56:17 I should have noticed earlier. Thank you for catch
312 false /* highlight */, false /* checked */, true /* enabled */);
313 }
314 283
315 // If Bluetooth is disabled, show a panel which only indicates that it is 284 // If Bluetooth is disabled, show a panel which only indicates that it is
316 // disabled, instead of the scroller with Bluetooth devices. 285 // disabled, instead of the scroller with Bluetooth devices.
317 if (UseMd()) { 286 if (bluetooth_enabled) {
318 if (bluetooth_enabled) { 287 HideDisabledPanel();
319 HideDisabledPanel(); 288 } else {
320 } else { 289 ShowDisabledPanel();
321 ShowDisabledPanel(); 290 return;
322 return;
323 }
324 } 291 }
325 292
326 // Add paired devices (and their section header in MD) in the list. 293 // Add paired devices (and their section header in MD) in the list.
327 size_t num_paired_devices = connected_devices_.size() + 294 size_t num_paired_devices = connected_devices_.size() +
328 connecting_devices_.size() + 295 connecting_devices_.size() +
329 paired_not_connected_devices_.size(); 296 paired_not_connected_devices_.size();
330 if (num_paired_devices > 0) { 297 if (num_paired_devices > 0) {
331 if (UseMd()) 298 AddSubHeader(IDS_ASH_STATUS_TRAY_BLUETOOTH_PAIRED_DEVICES);
332 AddSubHeader(IDS_ASH_STATUS_TRAY_BLUETOOTH_PAIRED_DEVICES);
333 AppendSameTypeDevicesToScrollList(connected_devices_, true, true, 299 AppendSameTypeDevicesToScrollList(connected_devices_, true, true,
334 bluetooth_enabled); 300 bluetooth_enabled);
335 AppendSameTypeDevicesToScrollList(connecting_devices_, true, false, 301 AppendSameTypeDevicesToScrollList(connecting_devices_, true, false,
336 bluetooth_enabled); 302 bluetooth_enabled);
337 AppendSameTypeDevicesToScrollList(paired_not_connected_devices_, false, 303 AppendSameTypeDevicesToScrollList(paired_not_connected_devices_, false,
338 false, bluetooth_enabled); 304 false, bluetooth_enabled);
339 } 305 }
340 306
341 // Add paired devices (and their section header in MD) in the list. 307 // Add paired devices (and their section header in MD) in the list.
342 if (discovered_not_paired_devices_.size() > 0) { 308 if (discovered_not_paired_devices_.size() > 0) {
343 if (UseMd()) { 309 if (num_paired_devices > 0)
344 if (num_paired_devices > 0) 310 AddSubHeader(IDS_ASH_STATUS_TRAY_BLUETOOTH_UNPAIRED_DEVICES);
345 AddSubHeader(IDS_ASH_STATUS_TRAY_BLUETOOTH_UNPAIRED_DEVICES);
346 } else {
347 AddScrollSeparator();
348 }
349 AppendSameTypeDevicesToScrollList(discovered_not_paired_devices_, false, 311 AppendSameTypeDevicesToScrollList(discovered_not_paired_devices_, false,
350 false, bluetooth_enabled); 312 false, bluetooth_enabled);
351 } 313 }
352 314
353 // Show user Bluetooth state if there is no bluetooth devices in list. 315 // Show user Bluetooth state if there is no bluetooth devices in list.
354 if (device_map_.size() == 0) { 316 if (device_map_.size() == 0) {
355 if (bluetooth_available && bluetooth_enabled) { 317 if (bluetooth_available && bluetooth_enabled) {
356 AddScrollListItem(l10n_util::GetStringUTF16( 318 HoverHighlightView* container = new HoverHighlightView(this);
tdanderson 2017/02/10 15:51:01 If I understand correctly, is this just displaying
fukino 2017/02/11 00:25:01 I filed crbug.com/691138 and attached a screenshot
tdanderson 2017/02/13 17:14:59 Thank you!
357 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING), 319 container->AddLabel(l10n_util::GetStringUTF16(
358 false /* highlight */, false /* checked */, 320 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING),
359 true /* enabled */); 321 gfx::ALIGN_LEFT, false);
322 scroll_content()->AddChildView(container);
360 } 323 }
361 } 324 }
362 325
363 scroll_content()->InvalidateLayout(); 326 scroll_content()->InvalidateLayout();
364 } 327 }
365 328
366 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, 329 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list,
367 bool highlight, 330 bool highlight,
368 bool checked, 331 bool checked,
369 bool enabled) { 332 bool enabled) {
370 for (size_t i = 0; i < list.size(); ++i) { 333 for (size_t i = 0; i < list.size(); ++i) {
371 HoverHighlightView* container = nullptr; 334 HoverHighlightView* container = nullptr;
372 if (UseMd()) { 335 gfx::ImageSkia icon_image = CreateVectorIcon(
373 gfx::ImageSkia icon_image = CreateVectorIcon( 336 GetBluetoothDeviceIcon(list[i].device_type, list[i].connected),
374 GetBluetoothDeviceIcon(list[i].device_type, list[i].connected), 337 kMenuIconColor);
375 kMenuIconColor); 338 container = AddScrollListItem(list[i].display_name, icon_image,
376 container = AddScrollListItemMd(list[i].display_name, icon_image, 339 list[i].connected, list[i].connecting);
377 list[i].connected, list[i].connecting);
378 } else {
379 container = AddScrollListItem(list[i].display_name, highlight, checked,
380 enabled);
381 }
382 device_map_[container] = list[i].address; 340 device_map_[container] = list[i].address;
383 } 341 }
384 } 342 }
385 343
386 // TODO(fukino): Remove this code when material design is enabled by default,
387 // since AddScrollListItem should be used only in the old design.
388 // See crbug.com/614453".
389 HoverHighlightView* AddScrollListItem(const base::string16& text, 344 HoverHighlightView* AddScrollListItem(const base::string16& text,
390 bool highlight, 345 const gfx::ImageSkia& image,
391 bool checked, 346 bool connected,
392 bool enabled) { 347 bool connecting) {
393 HoverHighlightView* container = new HoverHighlightView(this);
394 views::Label* label =
395 container->AddCheckableLabel(text, highlight, checked);
396 label->SetEnabled(enabled);
397 scroll_content()->AddChildView(container);
398 return container;
399 }
400
401 HoverHighlightView* AddScrollListItemMd(const base::string16& text,
402 const gfx::ImageSkia& image,
403 bool connected,
404 bool connecting) {
405 DCHECK(UseMd());
406 HoverHighlightView* container = new HoverHighlightView(this); 348 HoverHighlightView* container = new HoverHighlightView(this);
407 if (connected) { 349 if (connected) {
408 SetupConnectedItemMd(container, text, image); 350 SetupConnectedItem(container, text, image);
409 } else if (connecting) { 351 } else if (connecting) {
410 SetupConnectingItemMd(container, text, image); 352 SetupConnectingItem(container, text, image);
411 } else { 353 } else {
412 container->AddIconAndLabel(image, text, false); 354 container->AddIconAndLabel(image, text, false);
413 } 355 }
414 scroll_content()->AddChildView(container); 356 scroll_content()->AddChildView(container);
415 return container; 357 return container;
416 } 358 }
417 359
418 void AddSubHeader(int message_id) { 360 void AddSubHeader(int message_id) {
419 TriView* header = TrayPopupUtils::CreateSubHeaderRowView(); 361 TriView* header = TrayPopupUtils::CreateSubHeaderRowView();
420 TrayPopupUtils::ConfigureAsStickyHeader(header); 362 TrayPopupUtils::ConfigureAsStickyHeader(header);
421 363
422 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); 364 views::Label* label = TrayPopupUtils::CreateDefaultLabel();
423 label->SetText(l10n_util::GetStringUTF16(message_id)); 365 label->SetText(l10n_util::GetStringUTF16(message_id));
424 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); 366 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER);
425 style.SetupLabel(label); 367 style.SetupLabel(label);
426 header->AddView(TriView::Container::CENTER, label); 368 header->AddView(TriView::Container::CENTER, label);
427 369
428 scroll_content()->AddChildView(header); 370 scroll_content()->AddChildView(header);
429 } 371 }
430 372
431 void SetupConnectedItemMd(HoverHighlightView* container, 373 void SetupConnectedItem(HoverHighlightView* container,
432 const base::string16& text, 374 const base::string16& text,
433 const gfx::ImageSkia& image) { 375 const gfx::ImageSkia& image) {
434 container->AddIconAndLabels( 376 container->AddIconAndLabels(
435 image, text, l10n_util::GetStringUTF16( 377 image, text, l10n_util::GetStringUTF16(
436 IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); 378 IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED));
437 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION); 379 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION);
438 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED); 380 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED);
439 style.SetupLabel(container->sub_text_label()); 381 style.SetupLabel(container->sub_text_label());
440 } 382 }
441 383
442 void SetupConnectingItemMd(HoverHighlightView* container, 384 void SetupConnectingItem(HoverHighlightView* container,
443 const base::string16& text, 385 const base::string16& text,
444 const gfx::ImageSkia& image) { 386 const gfx::ImageSkia& image) {
445 container->AddIconAndLabels( 387 container->AddIconAndLabels(
446 image, text, l10n_util::GetStringUTF16( 388 image, text, l10n_util::GetStringUTF16(
447 IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); 389 IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING));
448 ThrobberView* throbber = new ThrobberView; 390 ThrobberView* throbber = new ThrobberView;
449 throbber->Start(); 391 throbber->Start();
450 container->AddRightView(throbber); 392 container->AddRightView(throbber);
451 } 393 }
452 394
453 // Add settings entries.
454 void AppendSettingsEntries() {
455 // Do not append the bottom button row in material design; this is replaced
456 // by the settings button in the header row.
457 if (UseMd())
458 return;
459
460 if (!WmShell::Get()->system_tray_delegate()->ShouldShowSettings())
461 return;
462
463 // Add bluetooth device requires a browser window, hide it for non logged in
464 // user.
465 if (!TrayPopupUtils::CanOpenWebUISettings(login_))
466 return;
467
468 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
469 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
470 HoverHighlightView* container = new HoverHighlightView(this);
471 container->AddLabel(
472 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_MANAGE_DEVICES),
473 gfx::ALIGN_LEFT, false /* highlight */);
474 container->SetEnabled(delegate->GetBluetoothAvailable());
475 AddChildView(container);
476 manage_devices_ = container;
477 }
478
479 // Returns true if the device with |device_id| is found in |device_list|, 395 // Returns true if the device with |device_id| is found in |device_list|,
480 // and the display_name of the device will be returned in |display_name| if 396 // and the display_name of the device will be returned in |display_name| if
481 // it's not NULL. 397 // it's not NULL.
482 bool FoundDevice(const std::string& device_id, 398 bool FoundDevice(const std::string& device_id,
483 const BluetoothDeviceList& device_list, 399 const BluetoothDeviceList& device_list,
484 base::string16* display_name, 400 base::string16* display_name,
485 device::BluetoothDeviceType* device_type) { 401 device::BluetoothDeviceType* device_type) {
486 for (size_t i = 0; i < device_list.size(); ++i) { 402 for (size_t i = 0; i < device_list.size(); ++i) {
487 if (device_list[i].address == device_id) { 403 if (device_list[i].address == device_id) {
488 if (display_name) 404 if (display_name)
(...skipping 10 matching lines...) Expand all
499 // or disconnected if such an operation is going to be performed underway. 415 // or disconnected if such an operation is going to be performed underway.
500 void UpdateClickedDevice(const std::string& device_id, 416 void UpdateClickedDevice(const std::string& device_id,
501 views::View* item_container) { 417 views::View* item_container) {
502 base::string16 display_name; 418 base::string16 display_name;
503 device::BluetoothDeviceType device_type; 419 device::BluetoothDeviceType device_type;
504 if (FoundDevice(device_id, paired_not_connected_devices_, &display_name, 420 if (FoundDevice(device_id, paired_not_connected_devices_, &display_name,
505 &device_type)) { 421 &device_type)) {
506 item_container->RemoveAllChildViews(true); 422 item_container->RemoveAllChildViews(true);
507 HoverHighlightView* container = 423 HoverHighlightView* container =
508 static_cast<HoverHighlightView*>(item_container); 424 static_cast<HoverHighlightView*>(item_container);
509 if (UseMd()) { 425 TrayPopupItemStyle style(
510 TrayPopupItemStyle style( 426 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
511 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); 427 gfx::ImageSkia icon_image = CreateVectorIcon(
512 gfx::ImageSkia icon_image = CreateVectorIcon( 428 GetBluetoothDeviceIcon(device_type, false), style.GetIconColor());
513 GetBluetoothDeviceIcon(device_type, false), style.GetIconColor()); 429 SetupConnectingItem(container, display_name, icon_image);
514 SetupConnectingItemMd(container, display_name, icon_image);
515 } else {
516 display_name = l10n_util::GetStringFUTF16(
517 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, display_name);
518 container->AddCheckableLabel(display_name, true /* highlight */, false);
519 }
520 scroll_content()->SizeToPreferredSize(); 430 scroll_content()->SizeToPreferredSize();
521 scroller()->Layout(); 431 scroller()->Layout();
522 } 432 }
523 } 433 }
524 434
525 // TrayDetailsView: 435 // TrayDetailsView:
526 void HandleViewClicked(views::View* view) override { 436 void HandleViewClicked(views::View* view) override {
527 if (view == manage_devices_) {
528 ShowSettings();
529 return;
530 }
531
532 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 437 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
533 if (view == enable_bluetooth_) { 438 if (view == enable_bluetooth_) {
tdanderson 2017/02/10 15:51:01 On line 310 you are removing the instantiation of
fukino 2017/02/11 00:25:01 Removed |enable_bluetooth_| and its related code.
tdanderson 2017/02/13 17:14:59 Acknowledged, thanks.
534 WmShell::Get()->RecordUserMetricsAction( 439 WmShell::Get()->RecordUserMetricsAction(
535 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED 440 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED
536 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); 441 : UMA_STATUS_AREA_BLUETOOTH_ENABLED);
537 delegate->ToggleBluetooth(); 442 delegate->ToggleBluetooth();
538 return; 443 return;
539 } 444 }
540 445
541 if (!delegate->GetBluetoothEnabled()) 446 if (!delegate->GetBluetoothEnabled())
542 return; 447 return;
543 448
544 std::map<views::View*, std::string>::iterator find; 449 std::map<views::View*, std::string>::iterator find;
545 find = device_map_.find(view); 450 find = device_map_.find(view);
546 if (find == device_map_.end()) 451 if (find == device_map_.end())
547 return; 452 return;
548 453
549 const std::string device_id = find->second; 454 const std::string device_id = find->second;
550 if (FoundDevice(device_id, connecting_devices_, nullptr, nullptr)) 455 if (FoundDevice(device_id, connecting_devices_, nullptr, nullptr))
551 return; 456 return;
552 457
553 UpdateClickedDevice(device_id, view); 458 UpdateClickedDevice(device_id, view);
554 delegate->ConnectToBluetoothDevice(device_id); 459 delegate->ConnectToBluetoothDevice(device_id);
555 } 460 }
556 461
557 void HandleButtonPressed(views::Button* sender, 462 void HandleButtonPressed(views::Button* sender,
558 const ui::Event& event) override { 463 const ui::Event& event) override {
559 if (UseMd()) { 464 if (sender == toggle_)
560 if (sender == toggle_) 465 WmShell::Get()->system_tray_delegate()->ToggleBluetooth();
561 WmShell::Get()->system_tray_delegate()->ToggleBluetooth(); 466 else if (sender == settings_)
562 else if (sender == settings_) 467 ShowSettings();
563 ShowSettings();
564 else
565 NOTREACHED();
566 return;
567 }
568 468
569 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 469 NOTREACHED();
570 if (sender == toggle_bluetooth_)
571 delegate->ToggleBluetooth();
572 else
573 NOTREACHED();
574 } 470 }
575 471
576 void CreateExtraTitleRowButtons() override { 472 void CreateExtraTitleRowButtons() override {
577 if (login_ == LoginStatus::LOCKED) 473 if (login_ == LoginStatus::LOCKED)
578 return; 474 return;
579 475
580 if (UseMd()) { 476 DCHECK(!toggle_);
581 DCHECK(!toggle_); 477 DCHECK(!settings_);
582 DCHECK(!settings_);
583 478
584 tri_view()->SetContainerVisible(TriView::Container::END, true); 479 tri_view()->SetContainerVisible(TriView::Container::END, true);
585 480
586 toggle_ = TrayPopupUtils::CreateToggleButton( 481 toggle_ =
587 this, IDS_ASH_STATUS_TRAY_BLUETOOTH); 482 TrayPopupUtils::CreateToggleButton(this, IDS_ASH_STATUS_TRAY_BLUETOOTH);
588 tri_view()->AddView(TriView::Container::END, toggle_); 483 tri_view()->AddView(TriView::Container::END, toggle_);
589 484
590 settings_ = CreateSettingsButton(login_); 485 settings_ = CreateSettingsButton(login_);
591 tri_view()->AddView(TriView::Container::END, settings_); 486 tri_view()->AddView(TriView::Container::END, settings_);
592 return;
593 }
594
595 throbber_ = new ThrobberView;
596 throbber_->SetTooltipText(
597 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING));
598 title_row()->AddViewToRowNonMd(throbber_, false);
599
600 // Do not allow toggling bluetooth in the lock screen.
601 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
602 toggle_bluetooth_ =
603 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED,
604 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED,
605 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER,
606 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER,
607 IDS_ASH_STATUS_TRAY_BLUETOOTH);
608 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled());
609 toggle_bluetooth_->SetTooltipText(
610 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH));
611 toggle_bluetooth_->SetToggledTooltipText(
612 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH));
613 toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false);
614 title_row()->AddViewToRowNonMd(toggle_bluetooth_, true);
615 } 487 }
616 488
617 void ShowSettings() { 489 void ShowSettings() {
618 if (TrayPopupUtils::CanOpenWebUISettings(login_)) { 490 if (TrayPopupUtils::CanOpenWebUISettings(login_)) {
619 WmShell::Get()->system_tray_delegate()->ManageBluetoothDevices(); 491 WmShell::Get()->system_tray_delegate()->ManageBluetoothDevices();
620 owner()->system_tray()->CloseSystemBubble(); 492 owner()->system_tray()->CloseSystemBubble();
621 } 493 }
622 } 494 }
623 495
624 void ShowLoadingIndicator() { 496 void ShowLoadingIndicator() {
625 if (throbber_) { 497 // Setting a value of -1 gives progress_bar an infinite-loading behavior.
626 throbber_->Start(); 498 ShowProgress(-1, true);
627 } else if (UseMd()) {
628 // Setting a value of -1 gives progress_bar an infinite-loading behavior.
629 ShowProgress(-1, true);
630 }
631 } 499 }
632 500
633 void HideLoadingIndicator() { 501 void HideLoadingIndicator() { ShowProgress(0, false); }
tdanderson 2017/02/10 15:51:01 Please format as void ...() { ... }
fukino 2017/02/11 00:25:01 Done, but I had to ignore presubmit warning "Pleas
tdanderson 2017/02/13 17:14:59 Oh, that's strange. In this case just go with what
fukino 2017/02/13 19:56:18 Got it. I did git cl format for PS3.
634 if (throbber_)
635 throbber_->Stop();
636 else if (UseMd())
637 ShowProgress(0, false);
638 }
639 502
640 void ShowDisabledPanel() { 503 void ShowDisabledPanel() {
641 DCHECK(UseMd());
642 DCHECK(scroller()); 504 DCHECK(scroller());
643 if (!disabled_panel_) { 505 if (!disabled_panel_) {
644 disabled_panel_ = CreateDisabledPanel(); 506 disabled_panel_ = CreateDisabledPanel();
645 // Insert |disabled_panel_| before the scroller, since the scroller will 507 // Insert |disabled_panel_| before the scroller, since the scroller will
646 // have unnecessary bottom border when it is not the last child. 508 // have unnecessary bottom border when it is not the last child.
647 AddChildViewAt(disabled_panel_, GetIndexOf(scroller())); 509 AddChildViewAt(disabled_panel_, GetIndexOf(scroller()));
648 // |disabled_panel_| need to fill the remaining space below the title row 510 // |disabled_panel_| need to fill the remaining space below the title row
649 // so that the inner contents of |disabled_panel_| are placed properly. 511 // so that the inner contents of |disabled_panel_| are placed properly.
650 box_layout()->SetFlexForView(disabled_panel_, 1); 512 box_layout()->SetFlexForView(disabled_panel_, 1);
651 } 513 }
652 disabled_panel_->SetVisible(true); 514 disabled_panel_->SetVisible(true);
653 scroller()->SetVisible(false); 515 scroller()->SetVisible(false);
654 } 516 }
655 517
656 void HideDisabledPanel() { 518 void HideDisabledPanel() {
657 DCHECK(UseMd());
658 DCHECK(scroller()); 519 DCHECK(scroller());
659 if (disabled_panel_) 520 if (disabled_panel_)
660 disabled_panel_->SetVisible(false); 521 disabled_panel_->SetVisible(false);
661 scroller()->SetVisible(true); 522 scroller()->SetVisible(true);
662 } 523 }
663 524
664 views::View* CreateDisabledPanel() { 525 views::View* CreateDisabledPanel() {
665 views::View* container = new views::View; 526 views::View* container = new views::View;
666 views::BoxLayout* box_layout = 527 views::BoxLayout* box_layout =
667 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); 528 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
(...skipping 23 matching lines...) Expand all
691 // icon is vertically aligned to center of the container. 552 // icon is vertically aligned to center of the container.
692 image_view->SetBorder( 553 image_view->SetBorder(
693 views::CreateEmptyBorder(label->GetPreferredSize().height(), 0, 0, 0)); 554 views::CreateEmptyBorder(label->GetPreferredSize().height(), 0, 0, 0));
694 return container; 555 return container;
695 } 556 }
696 557
697 LoginStatus login_; 558 LoginStatus login_;
698 559
699 std::map<views::View*, std::string> device_map_; 560 std::map<views::View*, std::string> device_map_;
700 561
701 // Not used in material design.
702 views::View* manage_devices_;
703
704 // Not used in material design.
705 ThrobberView* throbber_;
706
707 // Not used in material design.
708 TrayPopupHeaderButton* toggle_bluetooth_;
709
710 HoverHighlightView* enable_bluetooth_; 562 HoverHighlightView* enable_bluetooth_;
711 BluetoothDeviceList connected_devices_; 563 BluetoothDeviceList connected_devices_;
712 BluetoothDeviceList connecting_devices_; 564 BluetoothDeviceList connecting_devices_;
713 BluetoothDeviceList paired_not_connected_devices_; 565 BluetoothDeviceList paired_not_connected_devices_;
714 BluetoothDeviceList discovered_not_paired_devices_; 566 BluetoothDeviceList discovered_not_paired_devices_;
715 567
716 // The on/off toggle button used in material design.
717 views::ToggleButton* toggle_; 568 views::ToggleButton* toggle_;
718
719 // Only used in material design.
720 views::Button* settings_; 569 views::Button* settings_;
721 570
722 // Only used in material design.
723 // The container of the message "Bluetooth is disabled" and an icon. It should 571 // The container of the message "Bluetooth is disabled" and an icon. It should
724 // be shown instead of Bluetooth device list when Bluetooth is disabled. 572 // be shown instead of Bluetooth device list when Bluetooth is disabled.
725 views::View* disabled_panel_; 573 views::View* disabled_panel_;
726 574
727 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); 575 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView);
728 }; 576 };
729 577
730 } // namespace tray 578 } // namespace tray
731 579
732 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) 580 TrayBluetooth::TrayBluetooth(SystemTray* system_tray)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 detailed_->Update(); 630 detailed_->Update();
783 } 631 }
784 632
785 void TrayBluetooth::OnBluetoothDiscoveringChanged() { 633 void TrayBluetooth::OnBluetoothDiscoveringChanged() {
786 if (!detailed_) 634 if (!detailed_)
787 return; 635 return;
788 detailed_->Update(); 636 detailed_->Update();
789 } 637 }
790 638
791 } // namespace ash 639 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/resources/ash_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698