OLD | NEW |
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/common/shelf/wm_shelf_util.h" |
8 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
9 #include "ash/common/wm/shelf/wm_shelf_util.h" | |
10 #include "ash/metrics/user_metrics_recorder.h" | 10 #include "ash/metrics/user_metrics_recorder.h" |
11 #include "ash/shelf/shelf_layout_manager.h" | 11 #include "ash/shelf/shelf_layout_manager.h" |
12 #include "ash/shelf/shelf_util.h" | 12 #include "ash/shelf/shelf_util.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/system/audio/tray_audio.h" | 14 #include "ash/system/audio/tray_audio.h" |
15 #include "ash/system/cast/tray_cast.h" | 15 #include "ash/system/cast/tray_cast.h" |
16 #include "ash/system/date/tray_date.h" | 16 #include "ash/system/date/tray_date.h" |
17 #include "ash/system/status_area_widget.h" | 17 #include "ash/system/status_area_widget.h" |
18 #include "ash/system/tray/system_tray_delegate.h" | 18 #include "ash/system/tray/system_tray_delegate.h" |
19 #include "ash/system/tray/system_tray_item.h" | 19 #include "ash/system/tray/system_tray_item.h" |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 308 |
309 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) { | 309 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) { |
310 DestroySystemBubble(); | 310 DestroySystemBubble(); |
311 UpdateNotificationBubble(); | 311 UpdateNotificationBubble(); |
312 | 312 |
313 for (SystemTrayItem* item : items_) | 313 for (SystemTrayItem* item : items_) |
314 item->UpdateAfterLoginStatusChange(login_status); | 314 item->UpdateAfterLoginStatusChange(login_status); |
315 | 315 |
316 // Items default to SHELF_ALIGNMENT_BOTTOM. Update them if the initial | 316 // Items default to SHELF_ALIGNMENT_BOTTOM. Update them if the initial |
317 // position of the shelf differs. | 317 // position of the shelf differs. |
318 if (!wm::IsHorizontalAlignment(shelf_alignment())) | 318 if (!IsHorizontalAlignment(shelf_alignment())) |
319 UpdateAfterShelfAlignmentChange(shelf_alignment()); | 319 UpdateAfterShelfAlignmentChange(shelf_alignment()); |
320 | 320 |
321 SetVisible(true); | 321 SetVisible(true); |
322 PreferredSizeChanged(); | 322 PreferredSizeChanged(); |
323 } | 323 } |
324 | 324 |
325 void SystemTray::UpdateAfterShelfAlignmentChange(wm::ShelfAlignment alignment) { | 325 void SystemTray::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
326 for (SystemTrayItem* item : items_) | 326 for (SystemTrayItem* item : items_) |
327 item->UpdateAfterShelfAlignmentChange(alignment); | 327 item->UpdateAfterShelfAlignmentChange(alignment); |
328 } | 328 } |
329 | 329 |
330 void SystemTray::SetHideNotifications(bool hide_notifications) { | 330 void SystemTray::SetHideNotifications(bool hide_notifications) { |
331 if (notification_bubble_) | 331 if (notification_bubble_) |
332 notification_bubble_->bubble()->SetVisible(!hide_notifications); | 332 notification_bubble_->bubble()->SetVisible(!hide_notifications); |
333 hide_notifications_ = hide_notifications; | 333 hide_notifications_ = hide_notifications; |
334 } | 334 } |
335 | 335 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 base::string16 battery = base::ASCIIToUTF16(""); | 408 base::string16 battery = base::ASCIIToUTF16(""); |
409 #if defined(OS_CHROMEOS) | 409 #if defined(OS_CHROMEOS) |
410 battery = PowerStatus::Get()->GetAccessibleNameString(false); | 410 battery = PowerStatus::Get()->GetAccessibleNameString(false); |
411 #endif | 411 #endif |
412 return l10n_util::GetStringFUTF16( | 412 return l10n_util::GetStringFUTF16( |
413 IDS_ASH_STATUS_TRAY_ACCESSIBLE_DESCRIPTION, time, battery); | 413 IDS_ASH_STATUS_TRAY_ACCESSIBLE_DESCRIPTION, time, battery); |
414 } | 414 } |
415 | 415 |
416 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { | 416 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { |
417 // Don't attempt to align the arrow if the shelf is on the left or right. | 417 // Don't attempt to align the arrow if the shelf is on the left or right. |
418 if (!wm::IsHorizontalAlignment(shelf_alignment())) | 418 if (!IsHorizontalAlignment(shelf_alignment())) |
419 return TrayBubbleView::InitParams::kArrowDefaultOffset; | 419 return TrayBubbleView::InitParams::kArrowDefaultOffset; |
420 | 420 |
421 std::map<SystemTrayItem*, views::View*>::const_iterator it = | 421 std::map<SystemTrayItem*, views::View*>::const_iterator it = |
422 tray_item_map_.find(item); | 422 tray_item_map_.find(item); |
423 if (it == tray_item_map_.end()) | 423 if (it == tray_item_map_.end()) |
424 return TrayBubbleView::InitParams::kArrowDefaultOffset; | 424 return TrayBubbleView::InitParams::kArrowDefaultOffset; |
425 | 425 |
426 const views::View* item_view = it->second; | 426 const views::View* item_view = it->second; |
427 if (item_view->bounds().IsEmpty()) { | 427 if (item_view->bounds().IsEmpty()) { |
428 // The bounds of item could be still empty if it does not have a visible | 428 // The bounds of item could be still empty if it does not have a visible |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 } | 606 } |
607 | 607 |
608 base::string16 SystemTray::GetAccessibleTimeString( | 608 base::string16 SystemTray::GetAccessibleTimeString( |
609 const base::Time& now) const { | 609 const base::Time& now) const { |
610 base::HourClockType hour_type = | 610 base::HourClockType hour_type = |
611 ash::Shell::GetInstance()->system_tray_delegate()->GetHourClockType(); | 611 ash::Shell::GetInstance()->system_tray_delegate()->GetHourClockType(); |
612 return base::TimeFormatTimeOfDayWithHourClockType( | 612 return base::TimeFormatTimeOfDayWithHourClockType( |
613 now, hour_type, base::kKeepAmPm); | 613 now, hour_type, base::kKeepAmPm); |
614 } | 614 } |
615 | 615 |
616 void SystemTray::SetShelfAlignment(wm::ShelfAlignment alignment) { | 616 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { |
617 if (alignment == shelf_alignment()) | 617 if (alignment == shelf_alignment()) |
618 return; | 618 return; |
619 TrayBackgroundView::SetShelfAlignment(alignment); | 619 TrayBackgroundView::SetShelfAlignment(alignment); |
620 UpdateAfterShelfAlignmentChange(alignment); | 620 UpdateAfterShelfAlignmentChange(alignment); |
621 // Destroy any existing bubble so that it is rebuilt correctly. | 621 // Destroy any existing bubble so that it is rebuilt correctly. |
622 CloseSystemBubbleAndDeactivateSystemTray(); | 622 CloseSystemBubbleAndDeactivateSystemTray(); |
623 // Rebuild any notification bubble. | 623 // Rebuild any notification bubble. |
624 if (notification_bubble_) { | 624 if (notification_bubble_) { |
625 notification_bubble_.reset(); | 625 notification_bubble_.reset(); |
626 UpdateNotificationBubble(); | 626 UpdateNotificationBubble(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 bool SystemTray::PerformAction(const ui::Event& event) { | 709 bool SystemTray::PerformAction(const ui::Event& event) { |
710 // If we're already showing the default view, hide it; otherwise, show it | 710 // If we're already showing the default view, hide it; otherwise, show it |
711 // (and hide any popup that's currently shown). | 711 // (and hide any popup that's currently shown). |
712 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { | 712 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { |
713 system_bubble_->bubble()->Close(); | 713 system_bubble_->bubble()->Close(); |
714 } else { | 714 } else { |
715 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; | 715 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; |
716 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { | 716 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { |
717 const ui::LocatedEvent& located_event = | 717 const ui::LocatedEvent& located_event = |
718 static_cast<const ui::LocatedEvent&>(event); | 718 static_cast<const ui::LocatedEvent&>(event); |
719 if (wm::IsHorizontalAlignment(shelf_alignment())) { | 719 if (IsHorizontalAlignment(shelf_alignment())) { |
720 gfx::Point point(located_event.x(), 0); | 720 gfx::Point point(located_event.x(), 0); |
721 ConvertPointToWidget(this, &point); | 721 ConvertPointToWidget(this, &point); |
722 arrow_offset = point.x(); | 722 arrow_offset = point.x(); |
723 } | 723 } |
724 } | 724 } |
725 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset, false); | 725 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset, false); |
726 } | 726 } |
727 return true; | 727 return true; |
728 } | 728 } |
729 | 729 |
(...skipping 26 matching lines...) Expand all Loading... |
756 .work_area() | 756 .work_area() |
757 .height(); | 757 .height(); |
758 if (work_area_height > 0) { | 758 if (work_area_height > 0) { |
759 UMA_HISTOGRAM_CUSTOM_COUNTS( | 759 UMA_HISTOGRAM_CUSTOM_COUNTS( |
760 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 760 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
761 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 761 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
762 } | 762 } |
763 } | 763 } |
764 | 764 |
765 } // namespace ash | 765 } // namespace ash |
OLD | NEW |