| 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/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/shelf/shelf_util.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "ash/system/audio/tray_audio.h" | 13 #include "ash/system/audio/tray_audio.h" |
| 14 #include "ash/system/bluetooth/tray_bluetooth.h" | 14 #include "ash/system/bluetooth/tray_bluetooth.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" |
| 20 #include "ash/system/tray/tray_bubble_wrapper.h" | 20 #include "ash/system/tray/tray_bubble_wrapper.h" |
| 21 #include "ash/system/tray/tray_constants.h" | 21 #include "ash/system/tray/tray_constants.h" |
| 22 #include "ash/system/tray_accessibility.h" | 22 #include "ash/system/tray_accessibility.h" |
| 23 #include "ash/system/tray_update.h" | 23 #include "ash/system/tray_update.h" |
| 24 #include "ash/system/user/login_status.h" | 24 #include "ash/system/user/login_status.h" |
| 25 #include "ash/system/user/tray_user.h" | 25 #include "ash/system/user/tray_user.h" |
| 26 #include "ash/system/user/tray_user_separator.h" | 26 #include "ash/system/user/tray_user_separator.h" |
| 27 #include "ash/system/web_notification/web_notification_tray.h" | 27 #include "ash/system/web_notification/web_notification_tray.h" |
| 28 #include "ash/wm/common/shelf/wm_shelf_util.h" |
| 28 #include "base/logging.h" | 29 #include "base/logging.h" |
| 29 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
| 30 #include "base/timer/timer.h" | 31 #include "base/timer/timer.h" |
| 31 #include "grit/ash_strings.h" | 32 #include "grit/ash_strings.h" |
| 32 #include "ui/aura/window_event_dispatcher.h" | 33 #include "ui/aura/window_event_dispatcher.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/compositor/layer.h" | 35 #include "ui/compositor/layer.h" |
| 35 #include "ui/display/screen.h" | 36 #include "ui/display/screen.h" |
| 36 #include "ui/events/event_constants.h" | 37 #include "ui/events/event_constants.h" |
| 37 #include "ui/gfx/canvas.h" | 38 #include "ui/gfx/canvas.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 311 |
| 311 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) { | 312 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) { |
| 312 DestroySystemBubble(); | 313 DestroySystemBubble(); |
| 313 UpdateNotificationBubble(); | 314 UpdateNotificationBubble(); |
| 314 | 315 |
| 315 for (SystemTrayItem* item : items_) | 316 for (SystemTrayItem* item : items_) |
| 316 item->UpdateAfterLoginStatusChange(login_status); | 317 item->UpdateAfterLoginStatusChange(login_status); |
| 317 | 318 |
| 318 // Items default to SHELF_ALIGNMENT_BOTTOM. Update them if the initial | 319 // Items default to SHELF_ALIGNMENT_BOTTOM. Update them if the initial |
| 319 // position of the shelf differs. | 320 // position of the shelf differs. |
| 320 if (!IsHorizontalAlignment(shelf_alignment())) | 321 if (!wm::IsHorizontalAlignment(shelf_alignment())) |
| 321 UpdateAfterShelfAlignmentChange(shelf_alignment()); | 322 UpdateAfterShelfAlignmentChange(shelf_alignment()); |
| 322 | 323 |
| 323 SetVisible(true); | 324 SetVisible(true); |
| 324 PreferredSizeChanged(); | 325 PreferredSizeChanged(); |
| 325 } | 326 } |
| 326 | 327 |
| 327 void SystemTray::UpdateAfterShelfAlignmentChange(wm::ShelfAlignment alignment) { | 328 void SystemTray::UpdateAfterShelfAlignmentChange(wm::ShelfAlignment alignment) { |
| 328 for (SystemTrayItem* item : items_) | 329 for (SystemTrayItem* item : items_) |
| 329 item->UpdateAfterShelfAlignmentChange(alignment); | 330 item->UpdateAfterShelfAlignmentChange(alignment); |
| 330 } | 331 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 base::string16 battery = base::ASCIIToUTF16(""); | 411 base::string16 battery = base::ASCIIToUTF16(""); |
| 411 #if defined(OS_CHROMEOS) | 412 #if defined(OS_CHROMEOS) |
| 412 battery = PowerStatus::Get()->GetAccessibleNameString(false); | 413 battery = PowerStatus::Get()->GetAccessibleNameString(false); |
| 413 #endif | 414 #endif |
| 414 return l10n_util::GetStringFUTF16( | 415 return l10n_util::GetStringFUTF16( |
| 415 IDS_ASH_STATUS_TRAY_ACCESSIBLE_DESCRIPTION, time, battery); | 416 IDS_ASH_STATUS_TRAY_ACCESSIBLE_DESCRIPTION, time, battery); |
| 416 } | 417 } |
| 417 | 418 |
| 418 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { | 419 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { |
| 419 // Don't attempt to align the arrow if the shelf is on the left or right. | 420 // Don't attempt to align the arrow if the shelf is on the left or right. |
| 420 if (!IsHorizontalAlignment(shelf_alignment())) | 421 if (!wm::IsHorizontalAlignment(shelf_alignment())) |
| 421 return TrayBubbleView::InitParams::kArrowDefaultOffset; | 422 return TrayBubbleView::InitParams::kArrowDefaultOffset; |
| 422 | 423 |
| 423 std::map<SystemTrayItem*, views::View*>::const_iterator it = | 424 std::map<SystemTrayItem*, views::View*>::const_iterator it = |
| 424 tray_item_map_.find(item); | 425 tray_item_map_.find(item); |
| 425 if (it == tray_item_map_.end()) | 426 if (it == tray_item_map_.end()) |
| 426 return TrayBubbleView::InitParams::kArrowDefaultOffset; | 427 return TrayBubbleView::InitParams::kArrowDefaultOffset; |
| 427 | 428 |
| 428 const views::View* item_view = it->second; | 429 const views::View* item_view = it->second; |
| 429 if (item_view->bounds().IsEmpty()) { | 430 if (item_view->bounds().IsEmpty()) { |
| 430 // The bounds of item could be still empty if it does not have a visible | 431 // The bounds of item could be still empty if it does not have a visible |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 bool SystemTray::PerformAction(const ui::Event& event) { | 705 bool SystemTray::PerformAction(const ui::Event& event) { |
| 705 // 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 |
| 706 // (and hide any popup that's currently shown). | 707 // (and hide any popup that's currently shown). |
| 707 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { | 708 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { |
| 708 system_bubble_->bubble()->Close(); | 709 system_bubble_->bubble()->Close(); |
| 709 } else { | 710 } else { |
| 710 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; | 711 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; |
| 711 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { | 712 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { |
| 712 const ui::LocatedEvent& located_event = | 713 const ui::LocatedEvent& located_event = |
| 713 static_cast<const ui::LocatedEvent&>(event); | 714 static_cast<const ui::LocatedEvent&>(event); |
| 714 if (IsHorizontalAlignment(shelf_alignment())) { | 715 if (wm::IsHorizontalAlignment(shelf_alignment())) { |
| 715 gfx::Point point(located_event.x(), 0); | 716 gfx::Point point(located_event.x(), 0); |
| 716 ConvertPointToWidget(this, &point); | 717 ConvertPointToWidget(this, &point); |
| 717 arrow_offset = point.x(); | 718 arrow_offset = point.x(); |
| 718 } | 719 } |
| 719 } | 720 } |
| 720 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset, false); | 721 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset, false); |
| 721 } | 722 } |
| 722 return true; | 723 return true; |
| 723 } | 724 } |
| 724 | 725 |
| 725 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { | 726 void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { |
| 726 system_bubble_.reset(); | 727 system_bubble_.reset(); |
| 727 // 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 |
| 728 // turn off the active tinting of the shelf. | 729 // turn off the active tinting of the shelf. |
| 729 if (full_system_tray_menu_) { | 730 if (full_system_tray_menu_) { |
| 730 SetDrawBackgroundAsActive(false); | 731 SetDrawBackgroundAsActive(false); |
| 731 full_system_tray_menu_ = false; | 732 full_system_tray_menu_ = false; |
| 732 } | 733 } |
| 733 } | 734 } |
| 734 | 735 |
| 735 } // namespace ash | 736 } // namespace ash |
| OLD | NEW |