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

Side by Side Diff: ash/system/tray/system_tray.cc

Issue 1907363004: (Merge to M-51) Revise the shelf alignment locking mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 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 | « ash/system/status_area_widget_delegate.cc ('k') | ash/system/tray/system_tray_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 (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/system/tray/system_tray.h" 5 #include "ash/system/tray/system_tray.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/metrics/user_metrics_recorder.h" 8 #include "ash/metrics/user_metrics_recorder.h"
9 #include "ash/shelf/shelf_layout_manager.h" 9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_util.h"
10 #include "ash/shell.h" 11 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h" 12 #include "ash/shell_window_ids.h"
12 #include "ash/system/audio/tray_audio.h" 13 #include "ash/system/audio/tray_audio.h"
13 #include "ash/system/bluetooth/tray_bluetooth.h" 14 #include "ash/system/bluetooth/tray_bluetooth.h"
14 #include "ash/system/cast/tray_cast.h" 15 #include "ash/system/cast/tray_cast.h"
15 #include "ash/system/date/tray_date.h" 16 #include "ash/system/date/tray_date.h"
16 #include "ash/system/status_area_widget.h" 17 #include "ash/system/status_area_widget.h"
17 #include "ash/system/tray/system_tray_delegate.h" 18 #include "ash/system/tray/system_tray_delegate.h"
18 #include "ash/system/tray/system_tray_item.h" 19 #include "ash/system/tray/system_tray_item.h"
19 #include "ash/system/tray/tray_bubble_wrapper.h" 20 #include "ash/system/tray/tray_bubble_wrapper.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 notification_items_.erase(found_iter); 305 notification_items_.erase(found_iter);
305 // Only update the notification bubble if visible (i.e. don't create one). 306 // Only update the notification bubble if visible (i.e. don't create one).
306 if (notification_bubble_) 307 if (notification_bubble_)
307 UpdateNotificationBubble(); 308 UpdateNotificationBubble();
308 } 309 }
309 310
310 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) { 311 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) {
311 DestroySystemBubble(); 312 DestroySystemBubble();
312 UpdateNotificationBubble(); 313 UpdateNotificationBubble();
313 314
314 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); 315 for (SystemTrayItem* item : items_)
315 it != items_.end(); 316 item->UpdateAfterLoginStatusChange(login_status);
316 ++it) {
317 (*it)->UpdateAfterLoginStatusChange(login_status);
318 }
319 317
320 // Items default to SHELF_ALIGNMENT_BOTTOM. Update them if the initial 318 // Items default to SHELF_ALIGNMENT_BOTTOM. Update them if the initial
321 // position of the shelf differs. 319 // position of the shelf differs.
322 if (shelf_alignment() != SHELF_ALIGNMENT_BOTTOM) 320 if (!IsHorizontalAlignment(shelf_alignment()))
323 UpdateAfterShelfAlignmentChange(shelf_alignment()); 321 UpdateAfterShelfAlignmentChange(shelf_alignment());
324 322
325 SetVisible(true); 323 SetVisible(true);
326 PreferredSizeChanged(); 324 PreferredSizeChanged();
327 } 325 }
328 326
329 void SystemTray::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 327 void SystemTray::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
330 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); 328 for (SystemTrayItem* item : items_)
331 it != items_.end(); 329 item->UpdateAfterShelfAlignmentChange(alignment);
332 ++it) {
333 (*it)->UpdateAfterShelfAlignmentChange(alignment);
334 }
335 } 330 }
336 331
337 void SystemTray::SetHideNotifications(bool hide_notifications) { 332 void SystemTray::SetHideNotifications(bool hide_notifications) {
338 if (notification_bubble_) 333 if (notification_bubble_)
339 notification_bubble_->bubble()->SetVisible(!hide_notifications); 334 notification_bubble_->bubble()->SetVisible(!hide_notifications);
340 hide_notifications_ = hide_notifications; 335 hide_notifications_ = hide_notifications;
341 } 336 }
342 337
343 bool SystemTray::ShouldShowShelf() const { 338 bool SystemTray::ShouldShowShelf() const {
344 return system_bubble_.get() && system_bubble_->bubble()->ShouldShowShelf(); 339 return system_bubble_.get() && system_bubble_->bubble()->ShouldShowShelf();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 base::string16 battery = base::ASCIIToUTF16(""); 410 base::string16 battery = base::ASCIIToUTF16("");
416 #if defined(OS_CHROMEOS) 411 #if defined(OS_CHROMEOS)
417 battery = PowerStatus::Get()->GetAccessibleNameString(false); 412 battery = PowerStatus::Get()->GetAccessibleNameString(false);
418 #endif 413 #endif
419 return l10n_util::GetStringFUTF16( 414 return l10n_util::GetStringFUTF16(
420 IDS_ASH_STATUS_TRAY_ACCESSIBLE_DESCRIPTION, time, battery); 415 IDS_ASH_STATUS_TRAY_ACCESSIBLE_DESCRIPTION, time, battery);
421 } 416 }
422 417
423 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { 418 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const {
424 // Don't attempt to align the arrow if the shelf is on the left or right. 419 // Don't attempt to align the arrow if the shelf is on the left or right.
425 if (shelf_alignment() != SHELF_ALIGNMENT_BOTTOM) 420 if (!IsHorizontalAlignment(shelf_alignment()))
426 return TrayBubbleView::InitParams::kArrowDefaultOffset; 421 return TrayBubbleView::InitParams::kArrowDefaultOffset;
427 422
428 std::map<SystemTrayItem*, views::View*>::const_iterator it = 423 std::map<SystemTrayItem*, views::View*>::const_iterator it =
429 tray_item_map_.find(item); 424 tray_item_map_.find(item);
430 if (it == tray_item_map_.end()) 425 if (it == tray_item_map_.end())
431 return TrayBubbleView::InitParams::kArrowDefaultOffset; 426 return TrayBubbleView::InitParams::kArrowDefaultOffset;
432 427
433 const views::View* item_view = it->second; 428 const views::View* item_view = it->second;
434 if (item_view->bounds().IsEmpty()) { 429 if (item_view->bounds().IsEmpty()) {
435 // The bounds of item could be still empty if it does not have a visible 430 // The bounds of item could be still empty if it does not have a visible
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 bool SystemTray::PerformAction(const ui::Event& event) { 705 bool SystemTray::PerformAction(const ui::Event& event) {
711 // If we're already showing the default view, hide it; otherwise, show it 706 // If we're already showing the default view, hide it; otherwise, show it
712 // (and hide any popup that's currently shown). 707 // (and hide any popup that's currently shown).
713 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { 708 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) {
714 system_bubble_->bubble()->Close(); 709 system_bubble_->bubble()->Close();
715 } else { 710 } else {
716 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; 711 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset;
717 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { 712 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) {
718 const ui::LocatedEvent& located_event = 713 const ui::LocatedEvent& located_event =
719 static_cast<const ui::LocatedEvent&>(event); 714 static_cast<const ui::LocatedEvent&>(event);
720 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { 715 if (IsHorizontalAlignment(shelf_alignment())) {
721 gfx::Point point(located_event.x(), 0); 716 gfx::Point point(located_event.x(), 0);
722 ConvertPointToWidget(this, &point); 717 ConvertPointToWidget(this, &point);
723 arrow_offset = point.x(); 718 arrow_offset = point.x();
724 } 719 }
725 } 720 }
726 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset, false); 721 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset, false);
727 } 722 }
728 return true; 723 return true;
729 } 724 }
730 725
731 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { 726 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() {
732 system_bubble_.reset(); 727 system_bubble_.reset();
733 // When closing a system bubble with the alternate shelf layout, we need to 728 // When closing a system bubble with the alternate shelf layout, we need to
734 // turn off the active tinting of the shelf. 729 // turn off the active tinting of the shelf.
735 if (full_system_tray_menu_) { 730 if (full_system_tray_menu_) {
736 SetDrawBackgroundAsActive(false); 731 SetDrawBackgroundAsActive(false);
737 full_system_tray_menu_ = false; 732 full_system_tray_menu_ = false;
738 } 733 }
739 } 734 }
740 735
741 } // namespace ash 736 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/status_area_widget_delegate.cc ('k') | ash/system/tray/system_tray_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698