diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-08-08 14:30:41 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-08-12 13:49:54 +0200 |
commit | ab0a50979b9eb4dfa3320eff7e187e41efedf7a9 (patch) | |
tree | 498dfb8a97ff3361a9f7486863a52bb4e26bb898 /chromium/ash/system | |
parent | 4ce69f7403811819800e7c5ae1318b2647e778d1 (diff) |
Update Chromium to beta version 37.0.2062.68
Change-Id: I188e3b5aff1bec75566014291b654eb19f5bc8ca
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'chromium/ash/system')
184 files changed, 0 insertions, 26924 deletions
diff --git a/chromium/ash/system/DEPS b/chromium/ash/system/DEPS deleted file mode 100644 index abf5b5f48c4..00000000000 --- a/chromium/ash/system/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "-chromeos", -] diff --git a/chromium/ash/system/OWNERS b/chromium/ash/system/OWNERS deleted file mode 100644 index de76ad8ce46..00000000000 --- a/chromium/ash/system/OWNERS +++ /dev/null @@ -1,3 +0,0 @@ -sadrul@chromium.org -stevenjb@chromium.org -jennyz@chromium.org diff --git a/chromium/ash/system/bluetooth/bluetooth_observer.h b/chromium/ash/system/bluetooth/bluetooth_observer.h deleted file mode 100644 index 1c1bf4fa4d0..00000000000 --- a/chromium/ash/system/bluetooth/bluetooth_observer.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_BLUETOOTH_BLUETOOTH_OBSERVER_H_ -#define ASH_SYSTEM_BLUETOOTH_BLUETOOTH_OBSERVER_H_ - -namespace ash { - -class BluetoothObserver { - public: - virtual ~BluetoothObserver() {} - - virtual void OnBluetoothRefresh() = 0; - virtual void OnBluetoothDiscoveringChanged() = 0; -}; - -} // namespace ash - -#endif // ASH_SYSTEM_BLUETOOTH_BLUETOOTH_OBSERVER_H_ diff --git a/chromium/ash/system/bluetooth/tray_bluetooth.cc b/chromium/ash/system/bluetooth/tray_bluetooth.cc deleted file mode 100644 index 9114118df83..00000000000 --- a/chromium/ash/system/bluetooth/tray_bluetooth.cc +++ /dev/null @@ -1,469 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/bluetooth/tray_bluetooth.h" - -#include "ash/shell.h" -#include "ash/system/tray/fixed_sized_scroll_view.h" -#include "ash/system/tray/hover_highlight_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/throbber_view.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_details_view.h" -#include "ash/system/tray/tray_item_more.h" -#include "ash/system/tray/tray_popup_header_button.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" - -namespace ash { -namespace internal { - -namespace tray { - -namespace { - -// Updates bluetooth device |device| in the |list|. If it is new, append to the -// end of the |list|; otherwise, keep it at the same place, but update the data -// with new device info provided by |device|. -void UpdateBluetoothDeviceList(BluetoothDeviceList* list, - const BluetoothDeviceInfo& device) { - for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); - ++it) { - if ((*it).address == device.address) { - *it = device; - return; - } - } - - list->push_back(device); -} - -// Removes the obsolete BluetoothDevices from |list|, if they are not in the -// |new_list|. -void RemoveObsoleteBluetoothDevicesFromList( - BluetoothDeviceList* list, - const std::set<std::string>& new_list) { - for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); - ++it) { - if (new_list.find((*it).address) == new_list.end()) { - it = list->erase(it); - if (it == list->end()) - return; - } - } -} - -} // namespace - -class BluetoothDefaultView : public TrayItemMore { - public: - BluetoothDefaultView(SystemTrayItem* owner, bool show_more) - : TrayItemMore(owner, show_more) { - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia()); - UpdateLabel(); - } - - virtual ~BluetoothDefaultView() {} - - void UpdateLabel() { - ash::SystemTrayDelegate* delegate = - ash::Shell::GetInstance()->system_tray_delegate(); - if (delegate->GetBluetoothAvailable()) { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - const base::string16 label = - rb.GetLocalizedString(delegate->GetBluetoothEnabled() ? - IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED : - IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED); - SetLabel(label); - SetAccessibleName(label); - SetVisible(true); - } else { - SetVisible(false); - } - } - - private: - DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); -}; - -class BluetoothDetailedView : public TrayDetailsView, - public ViewClickListener, - public views::ButtonListener { - public: - BluetoothDetailedView(SystemTrayItem* owner, user::LoginStatus login) - : TrayDetailsView(owner), - login_(login), - manage_devices_(NULL), - toggle_bluetooth_(NULL), - enable_bluetooth_(NULL), - bluetooth_discovering_(false) { - CreateItems(); - Update(); - } - - virtual ~BluetoothDetailedView() { - // Stop discovering bluetooth devices when exiting BT detailed view. - BluetoothStopDiscovering(); - } - - void Update() { - BluetoothStartDiscovering(); - UpdateBlueToothDeviceList(); - - // Update UI. - UpdateDeviceScrollList(); - UpdateHeaderEntry(); - Layout(); - } - - private: - void CreateItems() { - CreateScrollableList(); - AppendSettingsEntries(); - AppendHeaderEntry(); - } - - void BluetoothStartDiscovering() { - ash::SystemTrayDelegate* delegate = - ash::Shell::GetInstance()->system_tray_delegate(); - bool bluetooth_enabled = delegate->GetBluetoothEnabled(); - if (!bluetooth_discovering_ && bluetooth_enabled) { - bluetooth_discovering_ = true; - delegate->BluetoothStartDiscovering(); - throbber_->Start(); - } else if(!bluetooth_enabled) { - bluetooth_discovering_ = false; - throbber_->Stop(); - } - } - - void BluetoothStopDiscovering() { - ash::SystemTrayDelegate* delegate = - ash::Shell::GetInstance()->system_tray_delegate(); - if (delegate && bluetooth_discovering_) { - bluetooth_discovering_ = false; - delegate->BluetoothStopDiscovering(); - throbber_->Stop(); - } - } - - void UpdateBlueToothDeviceList() { - std::set<std::string> new_connecting_devices; - std::set<std::string> new_connected_devices; - std::set<std::string> new_paired_not_connected_devices; - std::set<std::string> new_discovered_not_paired_devices; - - BluetoothDeviceList list; - Shell::GetInstance()->system_tray_delegate()-> - GetAvailableBluetoothDevices(&list); - for (size_t i = 0; i < list.size(); ++i) { - if (list[i].connecting) { - list[i].display_name = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, list[i].display_name); - new_connecting_devices.insert(list[i].address); - UpdateBluetoothDeviceList(&connecting_devices_, list[i]); - } else if (list[i].connected && list[i].paired) { - new_connected_devices.insert(list[i].address); - UpdateBluetoothDeviceList(&connected_devices_, list[i]); - } else if (list[i].paired) { - new_paired_not_connected_devices.insert(list[i].address); - UpdateBluetoothDeviceList(&paired_not_connected_devices_, list[i]); - } else { - new_discovered_not_paired_devices.insert(list[i].address); - UpdateBluetoothDeviceList(&discovered_not_paired_devices_, list[i]); - } - } - RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_, - new_connecting_devices); - RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, - new_connected_devices); - RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, - new_paired_not_connected_devices); - RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, - new_discovered_not_paired_devices); - } - - void AppendHeaderEntry() { - CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); - - if (login_ == user::LOGGED_IN_LOCKED) - return; - - throbber_ = new ThrobberView; - throbber_->SetTooltipText( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING)); - footer()->AddThrobber(throbber_); - - // Do not allow toggling bluetooth in the lock screen. - ash::SystemTrayDelegate* delegate = - ash::Shell::GetInstance()->system_tray_delegate(); - toggle_bluetooth_ = new TrayPopupHeaderButton(this, - IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, - IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, - IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, - IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, - IDS_ASH_STATUS_TRAY_BLUETOOTH); - toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); - toggle_bluetooth_->SetTooltipText( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); - toggle_bluetooth_->SetToggledTooltipText( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); - footer()->AddButton(toggle_bluetooth_); - } - - void UpdateHeaderEntry() { - if (toggle_bluetooth_) { - toggle_bluetooth_->SetToggled( - !ash::Shell::GetInstance()->system_tray_delegate()-> - GetBluetoothEnabled()); - } - } - - void UpdateDeviceScrollList() { - device_map_.clear(); - scroll_content()->RemoveAllChildViews(true); - enable_bluetooth_ = NULL; - - ash::SystemTrayDelegate* delegate = - ash::Shell::GetInstance()->system_tray_delegate(); - bool bluetooth_enabled = delegate->GetBluetoothEnabled(); - bool blueooth_available = delegate->GetBluetoothAvailable(); - if (blueooth_available && !bluetooth_enabled && - toggle_bluetooth_) { - enable_bluetooth_ = - AddScrollListItem( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), - gfx::Font::NORMAL, false, true); - } - - AppendSameTypeDevicesToScrollList( - connected_devices_, true, true, bluetooth_enabled); - AppendSameTypeDevicesToScrollList( - connecting_devices_, true, false, bluetooth_enabled); - AppendSameTypeDevicesToScrollList( - paired_not_connected_devices_, false, false, bluetooth_enabled); - if (discovered_not_paired_devices_.size() > 0) - AddScrollSeparator(); - AppendSameTypeDevicesToScrollList( - discovered_not_paired_devices_, false, false, bluetooth_enabled); - - // Show user Bluetooth state if there is no bluetooth devices in list. - if (device_map_.size() == 0) { - if (blueooth_available && bluetooth_enabled) { - AddScrollListItem( - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING), - gfx::Font::NORMAL, false, true); - } - } - - scroll_content()->SizeToPreferredSize(); - static_cast<views::View*>(scroller())->Layout(); - } - - void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, - bool bold, - bool checked, - bool enabled) { - for (size_t i = 0; i < list.size(); ++i) { - HoverHighlightView* container = AddScrollListItem( - list[i].display_name, - bold? gfx::Font::BOLD : gfx::Font::NORMAL, - checked, enabled); - device_map_[container] = list[i].address; - } - } - - HoverHighlightView* AddScrollListItem(const base::string16& text, - gfx::Font::FontStyle style, - bool checked, - bool enabled) { - HoverHighlightView* container = new HoverHighlightView(this); - views::Label* label = container->AddCheckableLabel(text, style, checked); - label->SetEnabled(enabled); - scroll_content()->AddChildView(container); - return container; - } - - // Add settings entries. - void AppendSettingsEntries() { - // Add bluetooth device requires a browser window, hide it for non logged in - // user. - if (login_ == user::LOGGED_IN_NONE || - login_ == user::LOGGED_IN_LOCKED) - return; - - ash::SystemTrayDelegate* delegate = - ash::Shell::GetInstance()->system_tray_delegate(); - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - HoverHighlightView* container = new HoverHighlightView(this); - container->AddLabel( - rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_MANAGE_DEVICES), - gfx::Font::NORMAL); - container->SetEnabled(delegate->GetBluetoothAvailable()); - AddChildView(container); - manage_devices_ = container; - } - - // Returns true if the device with |device_id| is found in |device_list|, - // and the display_name of the device will be returned in |display_name| if - // it's not NULL. - bool FoundDevice(const std::string& device_id, - const BluetoothDeviceList& device_list, - base::string16* display_name) { - for (size_t i = 0; i < device_list.size(); ++i) { - if (device_list[i].address == device_id) { - if (display_name) - *display_name = device_list[i].display_name; - return true; - } - } - return false; - } - - // Updates UI of the clicked bluetooth device to show it is being connected - // or disconnected if such an operation is going to be performed underway. - void UpdateClickedDevice(std::string device_id, views::View* item_container) { - base::string16 display_name; - if (FoundDevice(device_id, paired_not_connected_devices_, - &display_name)) { - display_name = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, display_name); - - item_container->RemoveAllChildViews(true); - static_cast<HoverHighlightView*>(item_container)-> - AddCheckableLabel(display_name, gfx::Font::BOLD, false); - scroll_content()->SizeToPreferredSize(); - static_cast<views::View*>(scroller())->Layout(); - } - } - - // Overridden from ViewClickListener. - virtual void OnViewClicked(views::View* sender) OVERRIDE { - ash::SystemTrayDelegate* delegate = - ash::Shell::GetInstance()->system_tray_delegate(); - if (sender == footer()->content()) { - TransitionToDefaultView(); - } else if (sender == manage_devices_) { - delegate->ManageBluetoothDevices(); - } else if (sender == enable_bluetooth_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - delegate->GetBluetoothEnabled() ? - ash::UMA_STATUS_AREA_BLUETOOTH_DISABLED : - ash::UMA_STATUS_AREA_BLUETOOTH_ENABLED); - delegate->ToggleBluetooth(); - } else { - if (!delegate->GetBluetoothEnabled()) - return; - std::map<views::View*, std::string>::iterator find; - find = device_map_.find(sender); - if (find == device_map_.end()) - return; - std::string device_id = find->second; - if (FoundDevice(device_id, connecting_devices_, NULL)) - return; - UpdateClickedDevice(device_id, sender); - delegate->ConnectToBluetoothDevice(device_id); - } - } - - // Overridden from ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE { - ash::SystemTrayDelegate* delegate = - ash::Shell::GetInstance()->system_tray_delegate(); - if (sender == toggle_bluetooth_) - delegate->ToggleBluetooth(); - else - NOTREACHED(); - } - - user::LoginStatus login_; - - std::map<views::View*, std::string> device_map_; - views::View* manage_devices_; - ThrobberView* throbber_; - TrayPopupHeaderButton* toggle_bluetooth_; - HoverHighlightView* enable_bluetooth_; - BluetoothDeviceList connected_devices_; - BluetoothDeviceList connecting_devices_; - BluetoothDeviceList paired_not_connected_devices_; - BluetoothDeviceList discovered_not_paired_devices_; - bool bluetooth_discovering_; - - DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); -}; - -} // namespace tray - -TrayBluetooth::TrayBluetooth(SystemTray* system_tray) - : SystemTrayItem(system_tray), - default_(NULL), - detailed_(NULL) { - Shell::GetInstance()->system_tray_notifier()->AddBluetoothObserver(this); -} - -TrayBluetooth::~TrayBluetooth() { - Shell::GetInstance()->system_tray_notifier()->RemoveBluetoothObserver(this); -} - -views::View* TrayBluetooth::CreateTrayView(user::LoginStatus status) { - return NULL; -} - -views::View* TrayBluetooth::CreateDefaultView(user::LoginStatus status) { - CHECK(default_ == NULL); - default_ = new tray::BluetoothDefaultView( - this, status != user::LOGGED_IN_LOCKED); - return default_; -} - -views::View* TrayBluetooth::CreateDetailedView(user::LoginStatus status) { - if (!Shell::GetInstance()->system_tray_delegate()->GetBluetoothAvailable()) - return NULL; - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW); - CHECK(detailed_ == NULL); - detailed_ = new tray::BluetoothDetailedView(this, status); - return detailed_; -} - -void TrayBluetooth::DestroyTrayView() { -} - -void TrayBluetooth::DestroyDefaultView() { - default_ = NULL; -} - -void TrayBluetooth::DestroyDetailedView() { - detailed_ = NULL; -} - -void TrayBluetooth::UpdateAfterLoginStatusChange(user::LoginStatus status) { -} - -void TrayBluetooth::OnBluetoothRefresh() { - if (default_) - default_->UpdateLabel(); - else if (detailed_) - detailed_->Update(); -} - -void TrayBluetooth::OnBluetoothDiscoveringChanged() { - if (!detailed_) - return; - detailed_->Update(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/bluetooth/tray_bluetooth.h b/chromium/ash/system/bluetooth/tray_bluetooth.h deleted file mode 100644 index 2e452c643d9..00000000000 --- a/chromium/ash/system/bluetooth/tray_bluetooth.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_BLUETOOTH_TRAY_BLUETOOTH_H_ -#define ASH_SYSTEM_BLUETOOTH_TRAY_BLUETOOTH_H_ - -#include "ash/system/bluetooth/bluetooth_observer.h" -#include "ash/system/tray/system_tray_item.h" - -namespace ash { -namespace internal { - -namespace tray { -class BluetoothDefaultView; -class BluetoothDetailedView; -} - -class TrayBluetooth : public SystemTrayItem, - public BluetoothObserver { - public: - explicit TrayBluetooth(SystemTray* system_tray); - virtual ~TrayBluetooth(); - - private: - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - - // Overridden from BluetoothObserver. - virtual void OnBluetoothRefresh() OVERRIDE; - virtual void OnBluetoothDiscoveringChanged() OVERRIDE; - - tray::BluetoothDefaultView* default_; - tray::BluetoothDetailedView* detailed_; - - DISALLOW_COPY_AND_ASSIGN(TrayBluetooth); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_BLUETOOTH_TRAY_BLUETOOTH_H_ diff --git a/chromium/ash/system/brightness_control_delegate.h b/chromium/ash/system/brightness_control_delegate.h deleted file mode 100644 index 55791ac6bb6..00000000000 --- a/chromium/ash/system/brightness_control_delegate.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_BRIGHTNESS_CONTROL_DELEGATE_H_ -#define ASH_SYSTEM_BRIGHTNESS_CONTROL_DELEGATE_H_ - -#include "base/callback.h" - -namespace ui { -class Accelerator; -} // namespace ui - -namespace ash { - -// Delegate for controlling the brightness. -class BrightnessControlDelegate { - public: - virtual ~BrightnessControlDelegate() {} - - // Handles an accelerator-driven request to decrease or increase the screen - // brightness. - virtual bool HandleBrightnessDown(const ui::Accelerator& accelerator) = 0; - virtual bool HandleBrightnessUp(const ui::Accelerator& accelerator) = 0; - - // Requests that the brightness be set to |percent|, in the range - // [0.0, 100.0]. |gradual| specifies whether the transition to the new - // brightness should be animated or instantaneous. - virtual void SetBrightnessPercent(double percent, bool gradual) = 0; - - // Asynchronously invokes |callback| with the current brightness, in the range - // [0.0, 100.0]. - virtual void GetBrightnessPercent( - const base::Callback<void(double)>& callback) = 0; -}; - -} // namespace ash - -#endif // ASH_SYSTEM_BRIGHTNESS_CONTROL_DELEGATE_H_ diff --git a/chromium/ash/system/chromeos/DEPS b/chromium/ash/system/chromeos/DEPS deleted file mode 100644 index 79b8e8ba13b..00000000000 --- a/chromium/ash/system/chromeos/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+chromeos", -] diff --git a/chromium/ash/system/chromeos/audio/tray_audio.cc b/chromium/ash/system/chromeos/audio/tray_audio.cc deleted file mode 100644 index 7d26fc6b9e9..00000000000 --- a/chromium/ash/system/chromeos/audio/tray_audio.cc +++ /dev/null @@ -1,660 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/audio/tray_audio.h" - -#include <cmath> - -#include "ash/ash_constants.h" -#include "ash/ash_switches.h" -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/shell.h" -#include "ash/system/tray/actionable_view.h" -#include "ash/system/tray/fixed_sized_scroll_view.h" -#include "ash/system/tray/hover_highlight_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/volume_control_delegate.h" -#include "base/strings/utf_string_conversions.h" -#include "chromeos/audio/cras_audio_handler.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkPaint.h" -#include "third_party/skia/include/core/SkRect.h" -#include "third_party/skia/include/effects/SkGradientShader.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/image/image.h" -#include "ui/gfx/image/image_skia_operations.h" -#include "ui/views/controls/button/image_button.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/controls/slider.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/view.h" - -using chromeos::CrasAudioHandler; - -namespace ash { -namespace internal { - -namespace { -const int kVolumeImageWidth = 25; -const int kVolumeImageHeight = 25; -const int kBarSeparatorWidth = 25; -const int kBarSeparatorHeight = 30; -const int kSliderRightPaddingToVolumeViewEdge = 17; -const int kExtraPaddingBetweenBarAndMore = 10; - -const int kNoAudioDeviceIcon = -1; - -// IDR_AURA_UBER_TRAY_VOLUME_LEVELS contains 5 images, -// The one for mute is at the 0 index and the other -// four are used for ascending volume levels. -const int kVolumeLevels = 4; - -bool IsAudioMuted() { - return CrasAudioHandler::Get()->IsOutputMuted(); -} - -float GetVolumeLevel() { - return CrasAudioHandler::Get()->GetOutputVolumePercent() / 100.0f; -} - -int GetAudioDeviceIconId(chromeos::AudioDeviceType type) { - if (type == chromeos::AUDIO_TYPE_HEADPHONE) - return IDR_AURA_UBER_TRAY_AUDIO_HEADPHONE; - else if (type == chromeos::AUDIO_TYPE_USB) - return IDR_AURA_UBER_TRAY_AUDIO_USB; - else if (type == chromeos::AUDIO_TYPE_BLUETOOTH) - return IDR_AURA_UBER_TRAY_AUDIO_BLUETOOTH; - else if (type == chromeos::AUDIO_TYPE_HDMI) - return IDR_AURA_UBER_TRAY_AUDIO_HDMI; - else - return kNoAudioDeviceIcon; -} - -base::string16 GetAudioDeviceName(const chromeos::AudioDevice& device) { - switch(device.type) { - case chromeos::AUDIO_TYPE_HEADPHONE: - return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_HEADPHONE); - case chromeos::AUDIO_TYPE_INTERNAL_SPEAKER: - return l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_AUDIO_INTERNAL_SPEAKER); - case chromeos::AUDIO_TYPE_INTERNAL_MIC: - return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_INTERNAL_MIC); - case chromeos::AUDIO_TYPE_USB: - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_AUDIO_USB_DEVICE, - UTF8ToUTF16(device.display_name)); - case chromeos::AUDIO_TYPE_BLUETOOTH: - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_AUDIO_BLUETOOTH_DEVICE, - UTF8ToUTF16(device.display_name)); - case chromeos::AUDIO_TYPE_HDMI: - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_AUDIO_HDMI_DEVICE, - UTF8ToUTF16(device.display_name)); - default: - return UTF8ToUTF16(device.display_name); - } -} - -} // namespace - -namespace tray { - -class VolumeButton : public views::ToggleImageButton { - public: - explicit VolumeButton(views::ButtonListener* listener) - : views::ToggleImageButton(listener), - image_index_(-1) { - SetImageAlignment(ALIGN_CENTER, ALIGN_MIDDLE); - image_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed( - IDR_AURA_UBER_TRAY_VOLUME_LEVELS); - SetPreferredSize(gfx::Size(kTrayPopupItemHeight, kTrayPopupItemHeight)); - Update(); - } - - virtual ~VolumeButton() {} - - void Update() { - float level = GetVolumeLevel(); - int image_index = IsAudioMuted() ? - 0 : (level == 1.0 ? - kVolumeLevels : - std::max(1, int(std::ceil(level * (kVolumeLevels - 1))))); - if (image_index != image_index_) { - gfx::Rect region(0, image_index * kVolumeImageHeight, - kVolumeImageWidth, kVolumeImageHeight); - gfx::ImageSkia image_skia = gfx::ImageSkiaOperations::ExtractSubset( - *(image_.ToImageSkia()), region); - SetImage(views::CustomButton::STATE_NORMAL, &image_skia); - image_index_ = image_index; - } - SchedulePaint(); - } - - private: - // Overridden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE { - gfx::Size size = views::ToggleImageButton::GetPreferredSize(); - size.set_height(kTrayPopupItemHeight); - return size; - } - - gfx::Image image_; - int image_index_; - - DISALLOW_COPY_AND_ASSIGN(VolumeButton); -}; - -class VolumeSlider : public views::Slider { - public: - explicit VolumeSlider(views::SliderListener* listener) - : views::Slider(listener, views::Slider::HORIZONTAL) { - set_focus_border_color(kFocusBorderColor); - SetValue(GetVolumeLevel()); - SetAccessibleName( - ui::ResourceBundle::GetSharedInstance().GetLocalizedString( - IDS_ASH_STATUS_TRAY_VOLUME)); - Update(); - } - virtual ~VolumeSlider() {} - - void Update() { - UpdateState(!IsAudioMuted()); - } - - DISALLOW_COPY_AND_ASSIGN(VolumeSlider); -}; - -// Vertical bar separator that can be placed on the VolumeView. -class BarSeparator : public views::View { - public: - BarSeparator() {} - virtual ~BarSeparator() {} - - // Overriden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE { - return gfx::Size(kBarSeparatorWidth, kBarSeparatorHeight); - } - - private: - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { - canvas->FillRect(gfx::Rect(width() / 2, 0, 1, height()), - kButtonStrokeColor); - } - - DISALLOW_COPY_AND_ASSIGN(BarSeparator); -}; - -class VolumeView : public ActionableView, - public views::ButtonListener, - public views::SliderListener { - public: - VolumeView(SystemTrayItem* owner, bool is_default_view) - : owner_(owner), - icon_(NULL), - slider_(NULL), - bar_(NULL), - device_type_(NULL), - more_(NULL), - is_default_view_(is_default_view) { - SetFocusable(false); - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, - kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems)); - - icon_ = new VolumeButton(this); - AddChildView(icon_); - - slider_ = new VolumeSlider(this); - AddChildView(slider_); - - bar_ = new BarSeparator; - AddChildView(bar_); - - device_type_ = new views::ImageView; - AddChildView(device_type_); - - more_ = new views::ImageView; - more_->EnableCanvasFlippingForRTLUI(true); - more_->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageNamed( - IDR_AURA_UBER_TRAY_MORE).ToImageSkia()); - AddChildView(more_); - - Update(); - } - - virtual ~VolumeView() {} - - void Update() { - icon_->Update(); - slider_->Update(); - UpdateDeviceTypeAndMore(); - Layout(); - } - - // Sets volume level on slider_, |percent| is ranged from [0.00] to [1.00]. - void SetVolumeLevel(float percent) { - // Slider's value is in finer granularity than audio volume level(0.01), - // there will be a small discrepancy between slider's value and volume level - // on audio side. To avoid the jittering in slider UI, do not set change - // slider value if the change is less than 1%. - if (std::abs(percent-slider_->value()) < 0.01) - return; - // The change in volume will be reflected via accessibility system events, - // so we prevent the UI event from being sent here. - slider_->set_enable_accessibility_events(false); - slider_->SetValue(percent); - // It is possible that the volume was (un)muted, but the actual volume level - // did not change. In that case, setting the value of the slider won't - // trigger an update. So explicitly trigger an update. - Update(); - slider_->set_enable_accessibility_events(true); - } - - private: - // Updates bar_, device_type_ icon, and more_ buttons. - void UpdateDeviceTypeAndMore() { - if (!ash::switches::ShowAudioDeviceMenu() || !is_default_view_) { - more_->SetVisible(false); - bar_->SetVisible(false); - device_type_->SetVisible(false); - return; - } - - CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); - bool show_more = audio_handler->has_alternative_output() || - audio_handler->has_alternative_input(); - more_->SetVisible(show_more); - - // Show output device icon if necessary. - chromeos::AudioDevice device; - if (!audio_handler->GetActiveOutputDevice(&device)) - return; - int device_icon = GetAudioDeviceIconId(device.type); - bar_->SetVisible(show_more); - if (device_icon != kNoAudioDeviceIcon) { - device_type_->SetVisible(true); - device_type_->SetImage( - ui::ResourceBundle::GetSharedInstance().GetImageNamed( - device_icon).ToImageSkia()); - } else { - device_type_->SetVisible(false); - } - } - - void HandleVolumeUp(int volume) { - CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); - audio_handler->SetOutputVolumePercent(volume); - if (audio_handler->IsOutputMuted() && - !audio_handler->IsOutputVolumeBelowDefaultMuteLvel()) - audio_handler->SetOutputMute(false); - } - - void HandleVolumeDown(int volume) { - CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); - audio_handler->SetOutputVolumePercent(volume); - if (audio_handler->IsOutputVolumeBelowDefaultMuteLvel() && - !audio_handler->IsOutputMuted()) { - audio_handler->SetOutputMute(true); - } else if (!audio_handler->IsOutputVolumeBelowDefaultMuteLvel() && - audio_handler->IsOutputMuted()) { - audio_handler->SetOutputMute(false); - } - } - - // Overridden from views::View. - virtual void Layout() OVERRIDE { - views::View::Layout(); - - if (!more_->visible()) { - int w = width() - slider_->bounds().x() - - kSliderRightPaddingToVolumeViewEdge; - slider_->SetSize(gfx::Size(w, slider_->height())); - return; - } - - // Make sure the chevron always has the full size. - gfx::Size size = more_->GetPreferredSize(); - gfx::Rect bounds(size); - bounds.set_x(width() - size.width() - kTrayPopupPaddingBetweenItems); - bounds.set_y((height() - size.height()) / 2); - more_->SetBoundsRect(bounds); - - // Layout either bar_ or device_type_ at the left of the more_ button. - views::View* view_left_to_more; - if (device_type_->visible()) - view_left_to_more = device_type_; - else - view_left_to_more = bar_; - gfx::Size view_size = view_left_to_more->GetPreferredSize(); - gfx::Rect view_bounds(view_size); - view_bounds.set_x(more_->bounds().x() - view_size.width() - - kExtraPaddingBetweenBarAndMore); - view_bounds.set_y((height() - view_size.height()) / 2); - view_left_to_more->SetBoundsRect(view_bounds); - - // Layout vertical bar next to view_left_to_more if device_type_ is visible. - if (device_type_->visible()) { - gfx::Size bar_size = bar_->GetPreferredSize(); - gfx::Rect bar_bounds(bar_size); - bar_bounds.set_x(view_left_to_more->bounds().x() - bar_size.width()); - bar_bounds.set_y((height() - bar_size.height()) / 2); - bar_->SetBoundsRect(bar_bounds); - } - - // Layout slider, calculate slider width. - gfx::Rect slider_bounds = slider_->bounds(); - slider_bounds.set_width( - bar_->bounds().x() - - (device_type_->visible() ? 0 : kTrayPopupPaddingBetweenItems) - - slider_bounds.x()); - slider_->SetBoundsRect(slider_bounds); - } - - // Overridden from views::ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE { - CHECK(sender == icon_); - bool mute_on = !IsAudioMuted(); - CrasAudioHandler::Get()->SetOutputMute(mute_on); - if (!mute_on) - CrasAudioHandler::Get()->AdjustOutputVolumeToAudibleLevel(); - } - - // Overridden from views:SliderListener. - virtual void SliderValueChanged(views::Slider* sender, - float value, - float old_value, - views::SliderChangeReason reason) OVERRIDE { - if (reason == views::VALUE_CHANGED_BY_USER) { - int volume = value * 100.0f; - int old_volume = CrasAudioHandler::Get()->GetOutputVolumePercent(); - // Do not call change audio volume if the difference is less than - // 1%, which is beyond cras audio api's granularity for output volume. - if (std::abs(volume - old_volume) < 1) - return; - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - is_default_view_ ? - ash::UMA_STATUS_AREA_CHANGED_VOLUME_MENU : - ash::UMA_STATUS_AREA_CHANGED_VOLUME_POPUP); - if (volume > old_volume) - HandleVolumeUp(volume); - else - HandleVolumeDown(volume); - } - icon_->Update(); - } - - // Overriden from ActionableView. - virtual bool PerformAction(const ui::Event& event) OVERRIDE { - if (!more_->visible()) - return false; - owner_->TransitionDetailedView(); - return true; - } - - SystemTrayItem* owner_; - VolumeButton* icon_; - VolumeSlider* slider_; - BarSeparator* bar_; - views::ImageView* device_type_; - views::ImageView* more_; - bool is_default_view_; - - DISALLOW_COPY_AND_ASSIGN(VolumeView); -}; - -class AudioDetailedView : public TrayDetailsView, - public ViewClickListener { - public: - AudioDetailedView(SystemTrayItem* owner, user::LoginStatus login) - : TrayDetailsView(owner), - login_(login) { - CreateItems(); - Update(); - } - - virtual ~AudioDetailedView() { - } - - void Update() { - UpdateAudioDevices(); - Layout(); - } - - private: - void CreateItems() { - CreateScrollableList(); - CreateHeaderEntry(); - } - - void CreateHeaderEntry() { - CreateSpecialRow(IDS_ASH_STATUS_TRAY_AUDIO, this); - } - - void UpdateAudioDevices() { - output_devices_.clear(); - input_devices_.clear(); - chromeos::AudioDeviceList devices; - CrasAudioHandler::Get()->GetAudioDevices(&devices); - for (size_t i = 0; i < devices.size(); ++i) { - if (devices[i].is_input) - input_devices_.push_back(devices[i]); - else - output_devices_.push_back(devices[i]); - } - UpdateScrollableList(); - } - - void UpdateScrollableList() { - scroll_content()->RemoveAllChildViews(true); - device_map_.clear(); - - // Add audio output devices. - AddScrollListInfoItem( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_OUTPUT)); - for (size_t i = 0; i < output_devices_.size(); ++i) { - HoverHighlightView* container = AddScrollListItem( - GetAudioDeviceName(output_devices_[i]), - gfx::Font::NORMAL, - output_devices_[i].active); /* checkmark if active */ - device_map_[container] = output_devices_[i]; - } - - AddScrollSeparator(); - - // Add audio input devices. - AddScrollListInfoItem( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_INPUT)); - for (size_t i = 0; i < input_devices_.size(); ++i) { - HoverHighlightView* container = AddScrollListItem( - GetAudioDeviceName(input_devices_[i]), - gfx::Font::NORMAL, - input_devices_[i].active); /* checkmark if active */ - device_map_[container] = input_devices_[i]; - } - - scroll_content()->SizeToPreferredSize(); - scroller()->Layout(); - } - - void AddScrollListInfoItem(const string16& text) { - views::Label* label = new views::Label(text); - - // Align info item with checkbox items - int margin = kTrayPopupPaddingHorizontal + - kTrayPopupDetailsLabelExtraLeftMargin; - int left_margin = 0; - int right_margin = 0; - if (base::i18n::IsRTL()) - right_margin = margin; - else - left_margin = margin; - - label->set_border(views::Border::CreateEmptyBorder( - ash::kTrayPopupPaddingBetweenItems, - left_margin, - ash::kTrayPopupPaddingBetweenItems, - right_margin)); - label->SetHorizontalAlignment(gfx::ALIGN_LEFT); - label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0)); - label->SetFont(label->font().DeriveFont(0, gfx::Font::BOLD)); - - scroll_content()->AddChildView(label); - } - - HoverHighlightView* AddScrollListItem(const string16& text, - gfx::Font::FontStyle style, - bool checked) { - HoverHighlightView* container = new HoverHighlightView(this); - container->AddCheckableLabel(text, style, checked); - scroll_content()->AddChildView(container); - return container; - } - - // Overridden from ViewClickListener. - virtual void OnViewClicked(views::View* sender) OVERRIDE { - if (sender == footer()->content()) { - TransitionToDefaultView(); - } else { - AudioDeviceMap::iterator iter = device_map_.find(sender); - if (iter == device_map_.end()) - return; - chromeos::AudioDevice& device = iter->second; - CrasAudioHandler::Get()->SwitchToDevice(device); - } - } - - typedef std::map<views::View*, chromeos::AudioDevice> AudioDeviceMap; - - user::LoginStatus login_; - chromeos::AudioDeviceList output_devices_; - chromeos::AudioDeviceList input_devices_; - AudioDeviceMap device_map_; - - DISALLOW_COPY_AND_ASSIGN(AudioDetailedView); -}; - -} // namespace tray - -TrayAudio::TrayAudio(SystemTray* system_tray) - : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_VOLUME_MUTE), - volume_view_(NULL), - audio_detail_(NULL), - pop_up_volume_view_(false) { - CrasAudioHandler::Get()->AddAudioObserver(this); -} - -TrayAudio::~TrayAudio() { - if (CrasAudioHandler::IsInitialized()) - CrasAudioHandler::Get()->RemoveAudioObserver(this); -} - -bool TrayAudio::GetInitialVisibility() { - return IsAudioMuted(); -} - -views::View* TrayAudio::CreateDefaultView(user::LoginStatus status) { - volume_view_ = new tray::VolumeView(this, true); - return volume_view_; -} - -views::View* TrayAudio::CreateDetailedView(user::LoginStatus status) { - if (!ash::switches::ShowAudioDeviceMenu() || pop_up_volume_view_) { - volume_view_ = new tray::VolumeView(this, false); - return volume_view_; - } else { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_DETAILED_AUDIO_VIEW); - audio_detail_ = new tray::AudioDetailedView(this, status); - return audio_detail_; - } -} - -void TrayAudio::DestroyDefaultView() { - volume_view_ = NULL; -} - -void TrayAudio::DestroyDetailedView() { - if (audio_detail_) { - audio_detail_ = NULL; - } else if (volume_view_) { - volume_view_ = NULL; - pop_up_volume_view_ = false; - } -} - -bool TrayAudio::ShouldHideArrow() const { - return true; -} - -bool TrayAudio::ShouldShowLauncher() const { - return ash::switches::ShowAudioDeviceMenu() && !pop_up_volume_view_; -} - -void TrayAudio::OnOutputVolumeChanged() { - float percent = GetVolumeLevel(); - if (tray_view()) - tray_view()->SetVisible(GetInitialVisibility()); - - if (volume_view_) { - volume_view_->SetVolumeLevel(percent); - SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); - return; - } - pop_up_volume_view_ = true; - PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); -} - -void TrayAudio::OnOutputMuteChanged() { - if (tray_view()) - tray_view()->SetVisible(GetInitialVisibility()); - - if (volume_view_) { - volume_view_->Update(); - SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); - } else { - pop_up_volume_view_ = true; - PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); - } -} - -void TrayAudio::OnInputGainChanged() { -} - -void TrayAudio::OnInputMuteChanged() { -} - -void TrayAudio::OnAudioNodesChanged() { - Update(); -} - -void TrayAudio::OnActiveOutputNodeChanged() { - Update(); -} - -void TrayAudio::OnActiveInputNodeChanged() { - Update(); -} - -void TrayAudio::Update() { - if (tray_view()) - tray_view()->SetVisible(GetInitialVisibility()); - if (audio_detail_) - audio_detail_->Update(); - if (volume_view_) { - volume_view_->SetVolumeLevel(GetVolumeLevel()); - volume_view_->Update(); - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/audio/tray_audio.h b/chromium/ash/system/chromeos/audio/tray_audio.h deleted file mode 100644 index d055a54b037..00000000000 --- a/chromium/ash/system/chromeos/audio/tray_audio.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_AUDIO_TRAY_AUDIO_H_ -#define ASH_SYSTEM_CHROMEOS_AUDIO_TRAY_AUDIO_H_ - -#include "ash/system/tray/tray_image_item.h" -#include "chromeos/audio/cras_audio_handler.h" - -namespace ash { -namespace internal { - -namespace tray { -class VolumeView; -class AudioDetailedView; -} - -class TrayAudio : public TrayImageItem, - public chromeos::CrasAudioHandler::AudioObserver { - public: - explicit TrayAudio(SystemTray* system_tray); - virtual ~TrayAudio(); - - private: - // Overridden from TrayImageItem. - virtual bool GetInitialVisibility() OVERRIDE; - - // Overridden from SystemTrayItem. - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual bool ShouldHideArrow() const OVERRIDE; - virtual bool ShouldShowLauncher() const OVERRIDE; - - // Overridden from chromeos::CrasAudioHandler::AudioObserver. - virtual void OnOutputVolumeChanged() OVERRIDE; - virtual void OnOutputMuteChanged() OVERRIDE; - virtual void OnInputGainChanged() OVERRIDE; - virtual void OnInputMuteChanged() OVERRIDE; - virtual void OnAudioNodesChanged() OVERRIDE; - virtual void OnActiveOutputNodeChanged() OVERRIDE; - virtual void OnActiveInputNodeChanged() OVERRIDE; - - void Update(); - - tray::VolumeView* volume_view_; - tray::AudioDetailedView* audio_detail_; - - // True if VolumeView should be created for accelerator pop up; - // Otherwise, it should be created for detailed view in ash tray bubble. - bool pop_up_volume_view_; - - DISALLOW_COPY_AND_ASSIGN(TrayAudio); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_AUDIO_TRAY_AUDIO_H_ diff --git a/chromium/ash/system/chromeos/brightness/brightness_controller_chromeos.cc b/chromium/ash/system/chromeos/brightness/brightness_controller_chromeos.cc deleted file mode 100644 index 78d35df4bc7..00000000000 --- a/chromium/ash/system/chromeos/brightness/brightness_controller_chromeos.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/brightness/brightness_controller_chromeos.h" - -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/power_manager_client.h" -#include "content/public/browser/user_metrics.h" -#include "ui/base/accelerators/accelerator.h" - -namespace ash { -namespace system { - -bool BrightnessControllerChromeos::HandleBrightnessDown( - const ui::Accelerator& accelerator) { - if (accelerator.key_code() == ui::VKEY_BRIGHTNESS_DOWN) - content::RecordAction( - content::UserMetricsAction("Accel_BrightnessDown_F6")); - - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - DecreaseScreenBrightness(true); - return true; -} - -bool BrightnessControllerChromeos::HandleBrightnessUp( - const ui::Accelerator& accelerator) { - if (accelerator.key_code() == ui::VKEY_BRIGHTNESS_UP) - content::RecordAction(content::UserMetricsAction("Accel_BrightnessUp_F7")); - - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - IncreaseScreenBrightness(); - return true; -} - -void BrightnessControllerChromeos::SetBrightnessPercent(double percent, - bool gradual) { - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - SetScreenBrightnessPercent(percent, gradual); -} - -void BrightnessControllerChromeos::GetBrightnessPercent( - const base::Callback<void(double)>& callback) { - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - GetScreenBrightnessPercent(callback); -} - -} // namespace system -} // namespace ash diff --git a/chromium/ash/system/chromeos/brightness/brightness_controller_chromeos.h b/chromium/ash/system/chromeos/brightness/brightness_controller_chromeos.h deleted file mode 100644 index 111daf396b1..00000000000 --- a/chromium/ash/system/chromeos/brightness/brightness_controller_chromeos.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_BRIGHTNESS_BRIGHTNESS_CONTROLLER_CHROMEOS_H_ -#define ASH_SYSTEM_CHROMEOS_BRIGHTNESS_BRIGHTNESS_CONTROLLER_CHROMEOS_H_ - -#include "ash/ash_export.h" -#include "ash/system/brightness_control_delegate.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" - -namespace ash { -namespace system { - -// A class which controls brightness when F6, F7 or a multimedia key for -// brightness is pressed. -class ASH_EXPORT BrightnessControllerChromeos - : public ash::BrightnessControlDelegate { - public: - BrightnessControllerChromeos() {} - virtual ~BrightnessControllerChromeos() {} - - // Overridden from ash::BrightnessControlDelegate: - virtual bool HandleBrightnessDown( - const ui::Accelerator& accelerator) OVERRIDE; - virtual bool HandleBrightnessUp(const ui::Accelerator& accelerator) OVERRIDE; - virtual void SetBrightnessPercent(double percent, bool gradual) OVERRIDE; - virtual void GetBrightnessPercent( - const base::Callback<void(double)>& callback) OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(BrightnessControllerChromeos); -}; - -} // namespace system -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_BRIGHTNESS_BRIGHTNESS_CONTROLLER_CHROMEOS_H_ diff --git a/chromium/ash/system/chromeos/brightness/tray_brightness.cc b/chromium/ash/system/chromeos/brightness/tray_brightness.cc deleted file mode 100644 index 98cace08577..00000000000 --- a/chromium/ash/system/chromeos/brightness/tray_brightness.cc +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/brightness/tray_brightness.h" - -#include "ash/accelerators/accelerator_controller.h" -#include "ash/ash_constants.h" -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/shell.h" -#include "ash/system/brightness_control_delegate.h" -#include "ash/system/tray/fixed_sized_image_view.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "base/bind.h" -#include "base/message_loop/message_loop.h" -#include "base/strings/utf_string_conversions.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/power_manager_client.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image.h" -#include "ui/views/controls/button/image_button.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/controls/slider.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/view.h" - -namespace ash { -namespace internal { - -namespace tray { - -namespace { - -// We don't let the screen brightness go lower than this when it's being -// adjusted via the slider. Otherwise, if the user doesn't know about the -// brightness keys, they may turn the backlight off and not know how to turn it -// back on. -const double kMinBrightnessPercent = 5.0; - -} // namespace - -class BrightnessView : public views::View, - public views::SliderListener { - public: - explicit BrightnessView(double initial_percent) - : dragging_(false), - last_percent_(initial_percent) { - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, - kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems)); - - views::ImageView* icon = new FixedSizedImageView(0, kTrayPopupItemHeight); - gfx::Image image = ui::ResourceBundle::GetSharedInstance().GetImageNamed( - IDR_AURA_UBER_TRAY_BRIGHTNESS); - icon->SetImage(image.ToImageSkia()); - AddChildView(icon); - - slider_ = new views::Slider(this, views::Slider::HORIZONTAL); - slider_->set_focus_border_color(kFocusBorderColor); - slider_->SetValue(static_cast<float>(initial_percent / 100.0)); - slider_->SetAccessibleName( - ui::ResourceBundle::GetSharedInstance().GetLocalizedString( - IDS_ASH_STATUS_TRAY_BRIGHTNESS)); - AddChildView(slider_); - } - - virtual ~BrightnessView() {} - - // |percent| is in the range [0.0, 100.0]. - void SetBrightnessPercent(double percent) { - last_percent_ = percent; - if (!dragging_) - slider_->SetValue(static_cast<float>(percent / 100.0)); - } - - private: - // Overridden from views::View. - virtual void OnBoundsChanged(const gfx::Rect& old_bounds) OVERRIDE { - int w = width() - slider_->x(); - slider_->SetSize(gfx::Size(w, slider_->height())); - } - - // Overridden from views:SliderListener. - virtual void SliderValueChanged(views::Slider* sender, - float value, - float old_value, - views::SliderChangeReason reason) OVERRIDE { - DCHECK_EQ(sender, slider_); - if (reason != views::VALUE_CHANGED_BY_USER) - return; - AcceleratorController* ac = Shell::GetInstance()->accelerator_controller(); - if (ac->brightness_control_delegate()) { - double percent = std::max(value * 100.0, kMinBrightnessPercent); - ac->brightness_control_delegate()->SetBrightnessPercent(percent, true); - } - } - - // Overridden from views:SliderListener. - virtual void SliderDragStarted(views::Slider* slider) OVERRIDE { - DCHECK_EQ(slider, slider_); - dragging_ = true; - } - - // Overridden from views:SliderListener. - virtual void SliderDragEnded(views::Slider* slider) OVERRIDE { - DCHECK_EQ(slider, slider_); - dragging_ = false; - slider_->SetValue(static_cast<float>(last_percent_ / 100.0)); - } - - views::Slider* slider_; - - // Is |slider_| currently being dragged? - bool dragging_; - - // Last brightness level that we observed, in the range [0.0, 100.0]. - double last_percent_; - - DISALLOW_COPY_AND_ASSIGN(BrightnessView); -}; - -} // namespace tray - -TrayBrightness::TrayBrightness(SystemTray* system_tray) - : SystemTrayItem(system_tray), - weak_ptr_factory_(this), - brightness_view_(NULL), - is_default_view_(false), - current_percent_(100.0), - got_current_percent_(false) { - // Post a task to get the initial brightness; the BrightnessControlDelegate - // isn't created yet. - base::MessageLoopForUI::current()->PostTask( - FROM_HERE, - base::Bind(&TrayBrightness::GetInitialBrightness, - weak_ptr_factory_.GetWeakPtr())); - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - AddObserver(this); -} - -TrayBrightness::~TrayBrightness() { - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - RemoveObserver(this); -} - -void TrayBrightness::GetInitialBrightness() { - BrightnessControlDelegate* delegate = - Shell::GetInstance()->accelerator_controller()-> - brightness_control_delegate(); - // Worrisome, but happens in unit tests, so don't log anything. - if (!delegate) - return; - delegate->GetBrightnessPercent( - base::Bind(&TrayBrightness::HandleInitialBrightness, - weak_ptr_factory_.GetWeakPtr())); -} - -void TrayBrightness::HandleInitialBrightness(double percent) { - if (!got_current_percent_) - HandleBrightnessChanged(percent, false); -} - -views::View* TrayBrightness::CreateTrayView(user::LoginStatus status) { - return NULL; -} - -views::View* TrayBrightness::CreateDefaultView(user::LoginStatus status) { - return NULL; -} - -views::View* TrayBrightness::CreateDetailedView(user::LoginStatus status) { - CHECK(brightness_view_ == NULL); - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_DETAILED_BRIGHTNESS_VIEW); - brightness_view_ = new tray::BrightnessView(current_percent_); - is_default_view_ = false; - return brightness_view_; -} - -void TrayBrightness::DestroyTrayView() { -} - -void TrayBrightness::DestroyDefaultView() { - if (is_default_view_) - brightness_view_ = NULL; -} - -void TrayBrightness::DestroyDetailedView() { - if (!is_default_view_) - brightness_view_ = NULL; -} - -void TrayBrightness::UpdateAfterLoginStatusChange(user::LoginStatus status) { -} - -bool TrayBrightness::ShouldHideArrow() const { - return true; -} - -bool TrayBrightness::ShouldShowLauncher() const { - return false; -} - -void TrayBrightness::BrightnessChanged(int level, bool user_initiated) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_BRIGHTNESS_CHANGED); - double percent = static_cast<double>(level); - HandleBrightnessChanged(percent, user_initiated); -} - -void TrayBrightness::HandleBrightnessChanged(double percent, - bool user_initiated) { - current_percent_ = percent; - got_current_percent_ = true; - - if (brightness_view_) - brightness_view_->SetBrightnessPercent(percent); - if (!user_initiated) - return; - - if (brightness_view_) - SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); - else - PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/brightness/tray_brightness.h b/chromium/ash/system/chromeos/brightness/tray_brightness.h deleted file mode 100644 index adabbc55d82..00000000000 --- a/chromium/ash/system/chromeos/brightness/tray_brightness.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_BRIGHTNESS_TRAY_BRIGHTNESS_H_ -#define ASH_SYSTEM_CHROMEOS_BRIGHTNESS_TRAY_BRIGHTNESS_H_ - -#include "ash/system/tray/system_tray_item.h" -#include "base/compiler_specific.h" -#include "base/memory/weak_ptr.h" -#include "chromeos/dbus/power_manager_client.h" - -namespace ash { -namespace internal { - -namespace tray { -class BrightnessView; -} - -class TrayBrightness : public SystemTrayItem, - public chromeos::PowerManagerClient::Observer { - public: - explicit TrayBrightness(SystemTray* system_tray); - virtual ~TrayBrightness(); - - private: - // Sends a request to get the current screen brightness so |current_percent_| - // can be initialized. - void GetInitialBrightness(); - - // Updates |current_percent_| with the initial brightness requested by - // GetInitialBrightness(), if we haven't seen the brightness already in the - // meantime. - void HandleInitialBrightness(double percent); - - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - virtual bool ShouldHideArrow() const OVERRIDE; - virtual bool ShouldShowLauncher() const OVERRIDE; - - // Overriden from PowerManagerClient::Observer. - virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE; - - void HandleBrightnessChanged(double percent, bool user_initiated); - - base::WeakPtrFactory<TrayBrightness> weak_ptr_factory_; - - tray::BrightnessView* brightness_view_; - - // Was |brightness_view_| created for CreateDefaultView() rather than - // CreateDetailedView()? Used to avoid resetting |brightness_view_| - // inappropriately in DestroyDefaultView() or DestroyDetailedView(). - bool is_default_view_; - - // Brightness level in the range [0.0, 100.0] that we've heard about most - // recently. - double current_percent_; - - // Has |current_percent_| been initialized? - bool got_current_percent_; - - DISALLOW_COPY_AND_ASSIGN(TrayBrightness); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_BRIGHTNESS_TRAY_BRIGHTNESS_H_ diff --git a/chromium/ash/system/chromeos/enterprise/enterprise_domain_observer.h b/chromium/ash/system/chromeos/enterprise/enterprise_domain_observer.h deleted file mode 100644 index 5df8a4262d8..00000000000 --- a/chromium/ash/system/chromeos/enterprise/enterprise_domain_observer.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_ENTERPISE_ENTERPRISE_DOMAIN_OBSERVER_H_ -#define ASH_SYSTEM_CHROMEOS_ENTERPISE_ENTERPRISE_DOMAIN_OBSERVER_H_ - -namespace ash { - -class EnterpriseDomainObserver { - public: - virtual ~EnterpriseDomainObserver() {} - - virtual void OnEnterpriseDomainChanged() = 0; -}; - -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_ENTERPISE_ENTERPRISE_DOMAIN_OBSERVER_H_ - diff --git a/chromium/ash/system/chromeos/enterprise/tray_enterprise.cc b/chromium/ash/system/chromeos/enterprise/tray_enterprise.cc deleted file mode 100644 index 8fca1c6cb13..00000000000 --- a/chromium/ash/system/chromeos/enterprise/tray_enterprise.cc +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/enterprise/tray_enterprise.h" - -#include "ash/shell.h" -#include "ash/system/chromeos/label_tray_view.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/user/login_status.h" -#include "base/logging.h" -#include "grit/ash_resources.h" - -namespace ash { -namespace internal { - -TrayEnterprise::TrayEnterprise(SystemTray* system_tray) - : SystemTrayItem(system_tray), - tray_view_(NULL) { - Shell::GetInstance()->system_tray_notifier()-> - AddEnterpriseDomainObserver(this); -} - -TrayEnterprise::~TrayEnterprise() { - Shell::GetInstance()->system_tray_notifier()-> - RemoveEnterpriseDomainObserver(this); -} - -void TrayEnterprise::UpdateEnterpriseMessage() { - base::string16 message = Shell::GetInstance()->system_tray_delegate()-> - GetEnterpriseMessage(); - if (tray_view_) - tray_view_->SetMessage(message); -} - -views::View* TrayEnterprise::CreateDefaultView(user::LoginStatus status) { - CHECK(tray_view_ == NULL); - // For public accounts, enterprise ownership is indicated in the user details - // instead. - if (status == ash::user::LOGGED_IN_PUBLIC) - return NULL; - tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_ENTERPRISE_DARK); - UpdateEnterpriseMessage(); - return tray_view_; -} - -void TrayEnterprise::DestroyDefaultView() { - tray_view_ = NULL; -} - -void TrayEnterprise::OnEnterpriseDomainChanged() { - UpdateEnterpriseMessage(); -} - -void TrayEnterprise::OnViewClicked(views::View* sender) { - Shell::GetInstance()->system_tray_delegate()->ShowEnterpriseInfo(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/enterprise/tray_enterprise.h b/chromium/ash/system/chromeos/enterprise/tray_enterprise.h deleted file mode 100644 index 697dfcd61d5..00000000000 --- a/chromium/ash/system/chromeos/enterprise/tray_enterprise.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_ENTERPRISE_TRAY_ENTERPRISE_H -#define ASH_SYSTEM_CHROMEOS_ENTERPRISE_TRAY_ENTERPRISE_H - -#include "ash/system/chromeos/enterprise/enterprise_domain_observer.h" -#include "ash/system/tray/system_tray_item.h" -#include "ash/system/tray/view_click_listener.h" - -namespace ash { -class SystemTray; -} - -namespace ash { -namespace internal { - -class LabelTrayView; - -class TrayEnterprise : public SystemTrayItem, - public ViewClickListener, - public EnterpriseDomainObserver { - public: - explicit TrayEnterprise(SystemTray* system_tray); - virtual ~TrayEnterprise(); - - // If message is not empty updates content of default view, otherwise hides - // tray items. - void UpdateEnterpriseMessage(); - - // Overridden from SystemTrayItem. - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - - // Overridden from EnterpriseDomainObserver. - virtual void OnEnterpriseDomainChanged() OVERRIDE; - - // Overridden from ViewClickListener. - virtual void OnViewClicked(views::View* sender) OVERRIDE; - - private: - LabelTrayView* tray_view_; - - DISALLOW_COPY_AND_ASSIGN(TrayEnterprise); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_ENTERPRISE_TRAY_ENTERPRISE_H - diff --git a/chromium/ash/system/chromeos/keyboard_brightness_controller.cc b/chromium/ash/system/chromeos/keyboard_brightness_controller.cc deleted file mode 100644 index 15f91edccc0..00000000000 --- a/chromium/ash/system/chromeos/keyboard_brightness_controller.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/keyboard_brightness_controller.h" - -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/shell.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/power_manager_client.h" -#include "content/public/browser/user_metrics.h" -#include "ui/base/accelerators/accelerator.h" - -namespace ash { - -bool KeyboardBrightnessController::HandleKeyboardBrightnessDown( - const ui::Accelerator& accelerator) { - if (accelerator.key_code() == ui::VKEY_BRIGHTNESS_DOWN) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6); - } - - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - DecreaseKeyboardBrightness(); - return true; -} - -bool KeyboardBrightnessController::HandleKeyboardBrightnessUp( - const ui::Accelerator& accelerator) { - if (accelerator.key_code() == ui::VKEY_BRIGHTNESS_UP) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7); - } - - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - IncreaseKeyboardBrightness(); - return true; -} - -} // namespace ash diff --git a/chromium/ash/system/chromeos/keyboard_brightness_controller.h b/chromium/ash/system/chromeos/keyboard_brightness_controller.h deleted file mode 100644 index 1afc94b1f6b..00000000000 --- a/chromium/ash/system/chromeos/keyboard_brightness_controller.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_KEYBOARD_BRIGHTNESS_CONTROLLER_H_ -#define ASH_SYSTEM_CHROMEOS_KEYBOARD_BRIGHTNESS_CONTROLLER_H_ - -#include "ash/ash_export.h" -#include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" - -namespace ash { - -// A class which controls keyboard brightness when Alt+F6, Alt+F7 or a -// multimedia key for keyboard brightness is pressed. -class ASH_EXPORT KeyboardBrightnessController - : public KeyboardBrightnessControlDelegate { - public: - KeyboardBrightnessController() {} - virtual ~KeyboardBrightnessController() {} - - private: - // Overridden from KeyboardBrightnessControlDelegate: - virtual bool HandleKeyboardBrightnessDown( - const ui::Accelerator& accelerator) OVERRIDE; - virtual bool HandleKeyboardBrightnessUp( - const ui::Accelerator& accelerator) OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(KeyboardBrightnessController); -}; - -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_KEYBOARD_BRIGHTNESS_CONTROLLER_H_ diff --git a/chromium/ash/system/chromeos/label_tray_view.cc b/chromium/ash/system/chromeos/label_tray_view.cc deleted file mode 100644 index 0ae4604680e..00000000000 --- a/chromium/ash/system/chromeos/label_tray_view.cc +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/label_tray_view.h" - -#include "ash/system/tray/hover_highlight_view.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/view_click_listener.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/font.h" -#include "ui/views/border.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/fill_layout.h" - -namespace ash { -namespace internal { - -LabelTrayView::LabelTrayView(ViewClickListener* click_listener, - int icon_resource_id) - : click_listener_(click_listener), - icon_resource_id_(icon_resource_id) { - SetLayoutManager(new views::FillLayout()); - SetVisible(false); -} - -LabelTrayView::~LabelTrayView() { -} - -void LabelTrayView::SetMessage(const base::string16& message) { - if (message_ == message) - return; - - message_ = message; - RemoveAllChildViews(true); - if (!message_.empty()) { - AddChildView(CreateChildView(message_)); - SetVisible(true); - } else { - SetVisible(false); - } -} - -views::View* LabelTrayView::CreateChildView( - const base::string16& message) const { - HoverHighlightView* child = new HoverHighlightView(click_listener_); - if (icon_resource_id_) { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - const gfx::ImageSkia* icon = rb.GetImageSkiaNamed(icon_resource_id_); - child->AddIconAndLabel(*icon, message, gfx::Font::NORMAL); - child->set_border( - views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, - 0, kTrayPopupPaddingHorizontal)); - child->text_label()->SetMultiLine(true); - child->text_label()->SizeToFit(kTrayNotificationContentsWidth); - } else { - child->AddLabel(message, gfx::Font::NORMAL); - child->text_label()->SetMultiLine(true); - child->text_label()->SizeToFit(kTrayNotificationContentsWidth + - kNotificationIconWidth); - } - child->text_label()->SetAllowCharacterBreak(true); - child->SetExpandable(true); - child->SetVisible(true); - return child; -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/label_tray_view.h b/chromium/ash/system/chromeos/label_tray_view.h deleted file mode 100644 index b29c37bee56..00000000000 --- a/chromium/ash/system/chromeos/label_tray_view.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_LABEL_TRAY_VIEW_H_ -#define ASH_SYSTEM_CHROMEOS_LABEL_TRAY_VIEW_H_ - -#include "base/strings/string16.h" -#include "ui/views/view.h" - -namespace ash { -namespace internal { - -class ViewClickListener; - -// View for simple information in tray. Automatically hides when message is -// empty. Supports multiline messages. - -class LabelTrayView : public views::View { - public: - LabelTrayView(ViewClickListener* click_listener, int icon_resource_id); - virtual ~LabelTrayView(); - void SetMessage(const base::string16& message); - private: - views::View* CreateChildView(const base::string16& message) const; - - ViewClickListener* click_listener_; - int icon_resource_id_; - base::string16 message_; - - DISALLOW_COPY_AND_ASSIGN(LabelTrayView); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_LABEL_TRAY_VIEW_H_ diff --git a/chromium/ash/system/chromeos/managed/tray_locally_managed_user.cc b/chromium/ash/system/chromeos/managed/tray_locally_managed_user.cc deleted file mode 100644 index bd3e380b257..00000000000 --- a/chromium/ash/system/chromeos/managed/tray_locally_managed_user.cc +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/managed/tray_locally_managed_user.h" - -#include "ash/shell.h" -#include "ash/system/chromeos/label_tray_view.h" -#include "ash/system/system_notifier.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_notification_view.h" -#include "ash/system/user/login_status.h" -#include "base/callback.h" -#include "base/logging.h" -#include "grit/ash_resources.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" -#include "ui/message_center/notification_delegate.h" - -using message_center::Notification; - -namespace ash { -namespace internal { - -const char TrayLocallyManagedUser::kNotificationId[] = - "chrome://user/locally-managed"; - -TrayLocallyManagedUser::TrayLocallyManagedUser(SystemTray* system_tray) - : SystemTrayItem(system_tray), - tray_view_(NULL), - status_(ash::user::LOGGED_IN_NONE) { -} - -TrayLocallyManagedUser::~TrayLocallyManagedUser() { -} - -void TrayLocallyManagedUser::UpdateMessage() { - base::string16 message = Shell::GetInstance()->system_tray_delegate()-> - GetLocallyManagedUserMessage(); - if (tray_view_) - tray_view_->SetMessage(message); - if (message_center::MessageCenter::Get()->HasNotification(kNotificationId)) - CreateOrUpdateNotification(message); -} - -views::View* TrayLocallyManagedUser::CreateDefaultView( - user::LoginStatus status) { - CHECK(tray_view_ == NULL); - if (status != ash::user::LOGGED_IN_LOCALLY_MANAGED) - return NULL; - - tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_MANAGED_USER); - UpdateMessage(); - return tray_view_; -} - -void TrayLocallyManagedUser::DestroyDefaultView() { - tray_view_ = NULL; -} - -void TrayLocallyManagedUser::OnViewClicked(views::View* sender) { - Shell::GetInstance()->system_tray_delegate()->ShowLocallyManagedUserInfo(); -} - -void TrayLocallyManagedUser::UpdateAfterLoginStatusChange( - user::LoginStatus status) { - if (status == status_) - return; - if (status == ash::user::LOGGED_IN_LOCALLY_MANAGED && - status_ != ash::user::LOGGED_IN_LOCKED) { - SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); - CreateOrUpdateNotification(delegate->GetLocallyManagedUserMessage()); - } - status_ = status; -} - -void TrayLocallyManagedUser::CreateOrUpdateNotification( - const base::string16& new_message) { - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - scoped_ptr<Notification> notification( - message_center::Notification::CreateSystemNotification( - kNotificationId, - string16() /* no title */, - new_message, - bundle.GetImageNamed(IDR_AURA_UBER_TRAY_MANAGED_USER), - system_notifier::kNotifierLocallyManagedUser, - base::Closure() /* null callback */)); - message_center::MessageCenter::Get()->AddNotification(notification.Pass()); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/managed/tray_locally_managed_user.h b/chromium/ash/system/chromeos/managed/tray_locally_managed_user.h deleted file mode 100644 index a508ec39e66..00000000000 --- a/chromium/ash/system/chromeos/managed/tray_locally_managed_user.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_LOCALLY_MANAGED_TRAY_LOCALLY_MANAGED_USER_H -#define ASH_SYSTEM_CHROMEOS_LOCALLY_MANAGED_TRAY_LOCALLY_MANAGED_USER_H - -#include "ash/ash_export.h" -#include "ash/system/tray/system_tray_item.h" -#include "ash/system/tray/view_click_listener.h" -#include "base/strings/string16.h" - -namespace ash { -class SystemTray; - -namespace internal { - -class LabelTrayView; - -class ASH_EXPORT TrayLocallyManagedUser : public SystemTrayItem, - public ViewClickListener { - public: - explicit TrayLocallyManagedUser(SystemTray* system_tray); - virtual ~TrayLocallyManagedUser(); - - // If message is not empty updates content of default view, otherwise hides - // tray items. - void UpdateMessage(); - - // Overridden from SystemTrayItem. - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - - // Overridden from ViewClickListener. - virtual void OnViewClicked(views::View* sender) OVERRIDE; - - private: - friend class TrayLocallyManagedUserTest; - - static const char kNotificationId[]; - - void CreateOrUpdateNotification(const base::string16& new_message); - - LabelTrayView* tray_view_; - // Previous login status to avoid showing notification upon unlock. - user::LoginStatus status_; - - DISALLOW_COPY_AND_ASSIGN(TrayLocallyManagedUser); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_LOCALLY_MANAGED_TRAY_LOCALLY_MANAGED_USER_H diff --git a/chromium/ash/system/chromeos/managed/tray_locally_managed_user_unittest.cc b/chromium/ash/system/chromeos/managed/tray_locally_managed_user_unittest.cc deleted file mode 100644 index 46f60d13c93..00000000000 --- a/chromium/ash/system/chromeos/managed/tray_locally_managed_user_unittest.cc +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/managed/tray_locally_managed_user.h" - -#include "ash/shell.h" -#include "ash/system/user/login_status.h" -#include "ash/test/ash_test_base.h" -#include "ash/test/test_system_tray_delegate.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" -#include "ui/message_center/notification_list.h" -#include "ui/message_center/notification_types.h" - -using message_center::NotificationList; - -namespace ash { -namespace internal { - -class TrayLocallyManagedUserTest : public test::AshTestBase { - public: - TrayLocallyManagedUserTest() {} - virtual ~TrayLocallyManagedUserTest() {} - - protected: - message_center::Notification* GetPopup(); - - private: - DISALLOW_COPY_AND_ASSIGN(TrayLocallyManagedUserTest); -}; - -message_center::Notification* TrayLocallyManagedUserTest::GetPopup() { - NotificationList::PopupNotifications popups = - message_center::MessageCenter::Get()->GetPopupNotifications(); - for (NotificationList::PopupNotifications::const_iterator iter = - popups.begin(); iter != popups.end(); ++iter) { - if ((*iter)->id() == TrayLocallyManagedUser::kNotificationId) - return *iter; - } - return NULL; -} - -class TrayLocallyManagedUserInitialTest : public TrayLocallyManagedUserTest { - public: - TrayLocallyManagedUserInitialTest() {} - virtual ~TrayLocallyManagedUserInitialTest() {} - - virtual void SetUp() OVERRIDE; - virtual void TearDown() OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(TrayLocallyManagedUserInitialTest); -}; - -void TrayLocallyManagedUserInitialTest::SetUp() { - test::TestSystemTrayDelegate::SetInitialLoginStatus( - user::LOGGED_IN_LOCALLY_MANAGED); - test::AshTestBase::SetUp(); -} - -void TrayLocallyManagedUserInitialTest::TearDown() { - test::AshTestBase::TearDown(); - // SetInitialLoginStatus() is reset in AshTestHelper::TearDown(). -} - -TEST_F(TrayLocallyManagedUserTest, LocallyManagedUserHasNotification) { - test::TestSystemTrayDelegate* delegate = - static_cast<test::TestSystemTrayDelegate*>( - ash::Shell::GetInstance()->system_tray_delegate()); - delegate->SetLoginStatus(user::LOGGED_IN_LOCALLY_MANAGED); - - message_center::Notification* notification = GetPopup(); - ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); - EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), - notification->rich_notification_data().priority); -} - -TEST_F(TrayLocallyManagedUserInitialTest, LocallyManagedUserNoCrash) { - // Initial login status is already LOCALLY_MANAGED, which should create - // the notification and should not cause crashes. - message_center::Notification* notification = GetPopup(); - ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); - EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), - notification->rich_notification_data().priority); -} - -} // namespace test -} // namespace diff --git a/chromium/ash/system/chromeos/network/network_connect.cc b/chromium/ash/system/chromeos/network/network_connect.cc deleted file mode 100644 index d8f524aea43..00000000000 --- a/chromium/ash/system/chromeos/network/network_connect.cc +++ /dev/null @@ -1,579 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/network/network_connect.h" - -#include "ash/session_state_delegate.h" -#include "ash/shell.h" -#include "ash/system/chromeos/network/network_state_notifier.h" -#include "ash/system/system_notifier.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "base/bind.h" -#include "base/memory/scoped_ptr.h" -#include "base/strings/utf_string_conversions.h" -#include "base/values.h" -#include "chromeos/login/login_state.h" -#include "chromeos/network/device_state.h" -#include "chromeos/network/network_activation_handler.h" -#include "chromeos/network/network_configuration_handler.h" -#include "chromeos/network/network_connection_handler.h" -#include "chromeos/network/network_event_log.h" -#include "chromeos/network/network_handler_callbacks.h" -#include "chromeos/network/network_profile.h" -#include "chromeos/network/network_profile_handler.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" -#include "chromeos/network/shill_property_util.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "third_party/cros_system_api/dbus/service_constants.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" - -using chromeos::DeviceState; -using chromeos::NetworkConfigurationHandler; -using chromeos::NetworkConnectionHandler; -using chromeos::NetworkHandler; -using chromeos::NetworkProfile; -using chromeos::NetworkProfileHandler; -using chromeos::NetworkState; -using chromeos::NetworkStateHandler; -using chromeos::NetworkTypePattern; - -namespace ash { - -namespace { - -// TODO(stevenjb): This should be in service_constants.h -const char kErrorInProgress[] = "org.chromium.flimflam.Error.InProgress"; - -// Returns true for carriers that can be activated through Shill instead of -// through a WebUI dialog. -bool IsDirectActivatedCarrier(const std::string& carrier) { - if (carrier == shill::kCarrierSprint) - return true; - return false; -} - -void ShowErrorNotification(const std::string& error_name, - const std::string& shill_error, - const std::string& service_path) { - Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> - ShowNetworkConnectError(error_name, shill_error, service_path); -} - -void HandleUnconfiguredNetwork(const std::string& service_path, - gfx::NativeWindow parent_window) { - const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> - GetNetworkState(service_path); - if (!network) { - NET_LOG_ERROR("Configuring unknown network", service_path); - return; - } - - if (network->type() == shill::kTypeWifi) { - // Only show the config view for secure networks, otherwise do nothing. - if (network->security() != shill::kSecurityNone) { - ash::Shell::GetInstance()->system_tray_delegate()-> - ShowNetworkConfigure(service_path, parent_window); - } - return; - } - - if (network->type() == shill::kTypeWimax || - network->type() == shill::kTypeVPN) { - ash::Shell::GetInstance()->system_tray_delegate()-> - ShowNetworkConfigure(service_path, parent_window); - return; - } - - if (network->type() == shill::kTypeCellular) { - if (network->RequiresActivation()) { - ash::network_connect::ActivateCellular(service_path); - return; - } - if (network->cellular_out_of_credits()) { - ash::network_connect::ShowMobileSetup(service_path); - return; - } - // No special configure or setup for |network|, show the settings UI. - if (chromeos::LoginState::Get()->IsUserLoggedIn()) { - ash::Shell::GetInstance()->system_tray_delegate()-> - ShowNetworkSettings(service_path); - } - return; - } - NOTREACHED(); -} - -void OnConnectFailed(const std::string& service_path, - gfx::NativeWindow parent_window, - const std::string& error_name, - scoped_ptr<base::DictionaryValue> error_data) { - NET_LOG_ERROR("Connect Failed: " + error_name, service_path); - - if (!ash::Shell::HasInstance()) - return; - - // If a new connect attempt canceled this connect, no need to notify the user. - if (error_name == NetworkConnectionHandler::kErrorConnectCanceled) - return; - - if (error_name == shill::kErrorBadPassphrase || - error_name == NetworkConnectionHandler::kErrorPassphraseRequired || - error_name == NetworkConnectionHandler::kErrorConfigurationRequired || - error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { - HandleUnconfiguredNetwork(service_path, parent_window); - return; - } - - if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) { - if (!ash::Shell::GetInstance()->system_tray_delegate()->EnrollNetwork( - service_path, parent_window)) { - HandleUnconfiguredNetwork(service_path, parent_window); - } - return; - } - - if (error_name == NetworkConnectionHandler::kErrorActivationRequired) { - network_connect::ActivateCellular(service_path); - return; - } - - if (error_name == NetworkConnectionHandler::kErrorConnected || - error_name == NetworkConnectionHandler::kErrorConnecting) { - network_connect::ShowNetworkSettings(service_path); - return; - } - - // ConnectFailed or unknown error; show a notification. - std::string shill_error; - error_data.get()->GetString( - chromeos::network_handler::kErrorDetail, &shill_error); - ShowErrorNotification(error_name, shill_error, service_path); - - // Only show a configure dialog if there was a ConnectFailed error and the - // screen is not locked. - if (error_name != shill::kErrorConnectFailed || - Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) - return; - - // If Shill reports an InProgress error, don't try to configure the network. - std::string dbus_error_name; - error_data.get()->GetString( - chromeos::network_handler::kDbusErrorName, &dbus_error_name); - if (dbus_error_name == kErrorInProgress) - return; - - HandleUnconfiguredNetwork(service_path, parent_window); -} - -void OnConnectSucceeded(const std::string& service_path) { - NET_LOG_USER("Connect Succeeded", service_path); - if (!ash::Shell::HasInstance()) - return; - message_center::MessageCenter::Get()->RemoveNotification( - network_connect::kNetworkConnectNotificationId, false /* not by user */); -} - -// If |check_error_state| is true, error state for the network is checked, -// otherwise any current error state is ignored (e.g. for recently configured -// networks or repeat connect attempts). |parent_window| will be used to parent -// any configuration UI on failure and may be NULL (in which case the default -// window will be used). -void CallConnectToNetwork(const std::string& service_path, - bool check_error_state, - gfx::NativeWindow parent_window) { - if (!ash::Shell::HasInstance()) - return; - message_center::MessageCenter::Get()->RemoveNotification( - network_connect::kNetworkConnectNotificationId, false /* not by user */); - - NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( - service_path, - base::Bind(&OnConnectSucceeded, service_path), - base::Bind(&OnConnectFailed, service_path, parent_window), - check_error_state); -} - -void OnActivateFailed(const std::string& service_path, - const std::string& error_name, - scoped_ptr<base::DictionaryValue> error_data) { - NET_LOG_ERROR("Unable to activate network", service_path); - ShowErrorNotification( - network_connect::kErrorActivateFailed, "", service_path); -} - -void OnActivateSucceeded(const std::string& service_path) { - NET_LOG_USER("Activation Succeeded", service_path); -} - -void OnConfigureFailed(const std::string& error_name, - scoped_ptr<base::DictionaryValue> error_data) { - NET_LOG_ERROR("Unable to configure network", ""); - ShowErrorNotification( - NetworkConnectionHandler::kErrorConfigureFailed, "", ""); -} - -void OnConfigureSucceeded(const std::string& service_path) { - NET_LOG_USER("Configure Succeeded", service_path); - // After configuring a network, ignore any (possibly stale) error state. - const bool check_error_state = false; - const gfx::NativeWindow parent_window = NULL; - CallConnectToNetwork(service_path, check_error_state, parent_window); -} - -void SetPropertiesFailed(const std::string& desc, - const std::string& service_path, - const std::string& config_error_name, - scoped_ptr<base::DictionaryValue> error_data) { - NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path); - ShowErrorNotification( - NetworkConnectionHandler::kErrorConfigureFailed, "", service_path); -} - -void SetPropertiesToClear(base::DictionaryValue* properties_to_set, - std::vector<std::string>* properties_to_clear) { - // Move empty string properties to properties_to_clear. - for (base::DictionaryValue::Iterator iter(*properties_to_set); - !iter.IsAtEnd(); iter.Advance()) { - std::string value_str; - if (iter.value().GetAsString(&value_str) && value_str.empty()) - properties_to_clear->push_back(iter.key()); - } - // Remove cleared properties from properties_to_set. - for (std::vector<std::string>::iterator iter = properties_to_clear->begin(); - iter != properties_to_clear->end(); ++iter) { - properties_to_set->RemoveWithoutPathExpansion(*iter, NULL); - } -} - -void ClearPropertiesAndConnect( - const std::string& service_path, - const std::vector<std::string>& properties_to_clear) { - NET_LOG_USER("ClearPropertiesAndConnect", service_path); - // After configuring a network, ignore any (possibly stale) error state. - const bool check_error_state = false; - const gfx::NativeWindow parent_window = NULL; - NetworkHandler::Get()->network_configuration_handler()->ClearProperties( - service_path, - properties_to_clear, - base::Bind(&CallConnectToNetwork, - service_path, check_error_state, - parent_window), - base::Bind(&SetPropertiesFailed, "ClearProperties", service_path)); -} - -// Returns false if !shared and no valid profile is available, which will -// trigger an error and abort. -bool GetNetworkProfilePath(bool shared, std::string* profile_path) { - if (shared) { - *profile_path = NetworkProfileHandler::kSharedProfilePath; - return true; - } - - if (!chromeos::LoginState::Get()->IsUserAuthenticated()) { - NET_LOG_ERROR("User profile specified before login", ""); - return false; - } - - const NetworkProfile* profile = - NetworkHandler::Get()->network_profile_handler()-> - GetDefaultUserProfile(); - if (!profile) { - NET_LOG_ERROR("No user profile for unshared network configuration", ""); - return false; - } - - *profile_path = profile->path; - return true; -} - -void ConfigureSetProfileSucceeded( - const std::string& service_path, - scoped_ptr<base::DictionaryValue> properties_to_set) { - std::vector<std::string> properties_to_clear; - SetPropertiesToClear(properties_to_set.get(), &properties_to_clear); - NetworkHandler::Get()->network_configuration_handler()->SetProperties( - service_path, - *properties_to_set, - base::Bind(&ClearPropertiesAndConnect, - service_path, - properties_to_clear), - base::Bind(&SetPropertiesFailed, "SetProperties", service_path)); -} - -const NetworkState* GetNetworkState(const std::string& service_path) { - return NetworkHandler::Get()->network_state_handler()-> - GetNetworkState(service_path); -} - -} // namespace - -namespace network_connect { - -const char kNetworkConnectNotificationId[] = - "chrome://settings/internet/connect"; -const char kNetworkActivateNotificationId[] = - "chrome://settings/internet/activate"; - -const char kErrorActivateFailed[] = "activate-failed"; - -void ConnectToNetwork(const std::string& service_path, - gfx::NativeWindow parent_window) { - NET_LOG_USER("ConnectToNetwork", service_path); - const NetworkState* network = GetNetworkState(service_path); - if (network && !network->error().empty()) { - NET_LOG_USER("Configure: " + network->error(), service_path); - // If the network is in an error state, show the configuration UI directly - // to avoid a spurious notification. - HandleUnconfiguredNetwork(service_path, parent_window); - return; - } - const bool check_error_state = true; - CallConnectToNetwork(service_path, check_error_state, parent_window); -} - -void SetTechnologyEnabled(const NetworkTypePattern& technology, - bool enabled_state) { - std::string log_string = - base::StringPrintf("technology %s, target state: %s", - technology.ToDebugString().c_str(), - (enabled_state ? "ENABLED" : "DISABLED")); - NET_LOG_USER("SetTechnologyEnabled", log_string); - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - bool enabled = handler->IsTechnologyEnabled(technology); - if (enabled_state == enabled) { - NET_LOG_USER("Technology already in target state.", log_string); - return; - } - if (enabled) { - // User requested to disable the technology. - handler->SetTechnologyEnabled( - technology, false, chromeos::network_handler::ErrorCallback()); - return; - } - // If we're dealing with a mobile network, then handle SIM lock here. - // SIM locking only applies to cellular, so the code below won't execute - // if |technology| has been explicitly set to WiMAX. - if (technology.MatchesPattern(NetworkTypePattern::Mobile())) { - const DeviceState* mobile = handler->GetDeviceStateByType(technology); - if (!mobile) { - NET_LOG_ERROR("SetTechnologyEnabled with no device", log_string); - return; - } - // The following only applies to cellular. - if (mobile->type() == shill::kTypeCellular) { - if (mobile->IsSimAbsent()) { - // If this is true, then we have a cellular device with no SIM inserted. - // TODO(armansito): Chrome should display a notification here, prompting - // the user to insert a SIM card and restart the device to enable - // cellular. See crbug.com/125171. - NET_LOG_USER("Cannot enable cellular device without SIM.", log_string); - return; - } - if (!mobile->sim_lock_type().empty()) { - // A SIM has been inserted, but it is locked. Let the user unlock it - // via the dialog. - ash::Shell::GetInstance()->system_tray_delegate()-> - ShowMobileSimDialog(); - return; - } - } - } - handler->SetTechnologyEnabled( - technology, true, chromeos::network_handler::ErrorCallback()); -} - -void ActivateCellular(const std::string& service_path) { - NET_LOG_USER("ActivateCellular", service_path); - const NetworkState* cellular = GetNetworkState(service_path); - if (!cellular || cellular->type() != shill::kTypeCellular) { - NET_LOG_ERROR("ActivateCellular with no Service", service_path); - return; - } - const DeviceState* cellular_device = - NetworkHandler::Get()->network_state_handler()-> - GetDeviceState(cellular->device_path()); - if (!cellular_device) { - NET_LOG_ERROR("ActivateCellular with no Device", service_path); - return; - } - if (!IsDirectActivatedCarrier(cellular_device->carrier())) { - // For non direct activation, show the mobile setup dialog which can be - // used to activate the network. - ShowMobileSetup(service_path); - return; - } - if (cellular->activation_state() == shill::kActivationStateActivated) { - NET_LOG_ERROR("ActivateCellular for activated service", service_path); - return; - } - - NetworkHandler::Get()->network_activation_handler()->Activate( - service_path, - "", // carrier - base::Bind(&OnActivateSucceeded, service_path), - base::Bind(&OnActivateFailed, service_path)); -} - -void ShowMobileSetup(const std::string& service_path) { - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - const NetworkState* cellular = handler->GetNetworkState(service_path); - if (!cellular || cellular->type() != shill::kTypeCellular) { - NET_LOG_ERROR("ShowMobileSetup without Cellular network", service_path); - return; - } - if (cellular->activation_state() != shill::kActivationStateActivated && - cellular->activate_over_non_cellular_networks() && - !handler->DefaultNetwork()) { - message_center::MessageCenter::Get()->AddNotification( - message_center::Notification::CreateSystemNotification( - kNetworkActivateNotificationId, - l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE), - l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION, - UTF8ToUTF16(cellular->name())), - ui::ResourceBundle::GetSharedInstance().GetImageNamed( - IDR_AURA_UBER_TRAY_CELLULAR_NETWORK_FAILED), - ash::system_notifier::kNotifierNetwork, - base::Bind(&ash::network_connect::ShowNetworkSettings, - service_path))); - return; - } - ash::Shell::GetInstance()->system_tray_delegate()->ShowMobileSetupDialog( - service_path); -} - -void ConfigureNetworkAndConnect(const std::string& service_path, - const base::DictionaryValue& properties, - bool shared) { - NET_LOG_USER("ConfigureNetworkAndConnect", service_path); - - scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); - - std::string profile_path; - if (!GetNetworkProfilePath(shared, &profile_path)) { - ShowErrorNotification( - NetworkConnectionHandler::kErrorConfigureFailed, "", service_path); - return; - } - NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( - service_path, profile_path, - base::Bind(&ConfigureSetProfileSucceeded, - service_path, base::Passed(&properties_to_set)), - base::Bind(&SetPropertiesFailed, - "SetProfile: " + profile_path, service_path)); -} - -void CreateConfigurationAndConnect(base::DictionaryValue* properties, - bool shared) { - NET_LOG_USER("CreateConfigurationAndConnect", ""); - std::string profile_path; - if (!GetNetworkProfilePath(shared, &profile_path)) { - ShowErrorNotification( - NetworkConnectionHandler::kErrorConfigureFailed, "", ""); - return; - } - properties->SetStringWithoutPathExpansion( - shill::kProfileProperty, profile_path); - NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration( - *properties, - base::Bind(&OnConfigureSucceeded), - base::Bind(&OnConfigureFailed)); -} - -string16 ErrorString(const std::string& error, - const std::string& service_path) { - if (error.empty()) - return string16(); - if (error == shill::kErrorOutOfRange) - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE); - if (error == shill::kErrorPinMissing) - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING); - if (error == shill::kErrorDhcpFailed) - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_DHCP_FAILED); - if (error == shill::kErrorConnectFailed) - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED); - if (error == shill::kErrorBadPassphrase) - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_PASSPHRASE); - if (error == shill::kErrorBadWEPKey) - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_WEPKEY); - if (error == shill::kErrorActivationFailed) { - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED); - } - if (error == shill::kErrorNeedEvdo) - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_NEED_EVDO); - if (error == shill::kErrorNeedHomeNetwork) { - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_NEED_HOME_NETWORK); - } - if (error == shill::kErrorOtaspFailed) - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OTASP_FAILED); - if (error == shill::kErrorAaaFailed) - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_AAA_FAILED); - if (error == shill::kErrorInternal) - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_INTERNAL); - if (error == shill::kErrorDNSLookupFailed) { - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_DNS_LOOKUP_FAILED); - } - if (error == shill::kErrorHTTPGetFailed) { - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_HTTP_GET_FAILED); - } - if (error == shill::kErrorIpsecPskAuthFailed) { - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_IPSEC_PSK_AUTH_FAILED); - } - if (error == shill::kErrorIpsecCertAuthFailed) { - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED); - } - if (error == shill::kErrorEapAuthenticationFailed) { - const NetworkState* network = GetNetworkState(service_path); - // TLS always requires a client certificate, so show a cert auth - // failed message for TLS. Other EAP methods do not generally require - // a client certicate. - if (network && network->eap_method() == shill::kEapMethodTLS) { - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED); - } else { - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_EAP_AUTH_FAILED); - } - } - if (error == shill::kErrorEapLocalTlsFailed) { - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_EAP_LOCAL_TLS_FAILED); - } - if (error == shill::kErrorEapRemoteTlsFailed) { - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_EAP_REMOTE_TLS_FAILED); - } - if (error == shill::kErrorPppAuthFailed) { - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_PPP_AUTH_FAILED); - } - - if (StringToLowerASCII(error) == - StringToLowerASCII(std::string(shill::kUnknownString))) { - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); - } - return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR, - UTF8ToUTF16(error)); -} - -void ShowNetworkSettings(const std::string& service_path) { - if (!ash::Shell::HasInstance()) - return; - ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( - service_path); -} - -} // network_connect -} // ash diff --git a/chromium/ash/system/chromeos/network/network_connect.h b/chromium/ash/system/chromeos/network/network_connect.h deleted file mode 100644 index adf939de8b4..00000000000 --- a/chromium/ash/system/chromeos/network/network_connect.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_CONNECT_H -#define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_CONNECT_H - -#include <string> - -#include "ash/ash_export.h" -#include "base/strings/string16.h" -#include "ui/gfx/native_widget_types.h" // gfx::NativeWindow - -namespace base { -class DictionaryValue; -} - -namespace chromeos { -class NetworkTypePattern; -} - -namespace ash { -namespace network_connect { - -ASH_EXPORT extern const char kNetworkConnectNotificationId[]; -ASH_EXPORT extern const char kNetworkActivateNotificationId[]; - -ASH_EXPORT extern const char kErrorActivateFailed[]; - -// Requests a network connection and handles any errors and notifications. -// |parent_window| is used to parent any UI on failure (e.g. for certificate -// enrollment). If NULL, the default window will be used. -ASH_EXPORT void ConnectToNetwork(const std::string& service_path, - gfx::NativeWindow parent_window); - -// Enables or disables a network technology. If |technology| refers to cellular -// and the device cannot be enabled due to a SIM lock, this function will -// launch the SIM unlock dialog. -ASH_EXPORT void SetTechnologyEnabled( - const chromeos::NetworkTypePattern& technology, - bool enabled_state); - -// Requests network activation and handles any errors and notifications. -ASH_EXPORT void ActivateCellular(const std::string& service_path); - -// Determines whether or not a network requires a connection to activate or -// setup and either shows a notification or opens the mobile setup dialog. -ASH_EXPORT void ShowMobileSetup(const std::string& service_path); - -// Configures a network with a dictionary of Shill properties, then sends a -// connect request. The profile is set according to 'shared' if allowed. -ASH_EXPORT void ConfigureNetworkAndConnect( - const std::string& service_path, - const base::DictionaryValue& properties, - bool shared); - -// Requests a new network configuration to be created from a dictionary of -// Shill properties. The profile used is determined by |shared|. -ASH_EXPORT void CreateConfigurationAndConnect(base::DictionaryValue* properties, - bool shared); - -// Returns the localized string for shill error string |error|. -ASH_EXPORT base::string16 ErrorString(const std::string& error, - const std::string& service_path); - -// Shows the settings for the network specified by |service_path|. If empty, -// or no matching network exists, shows the general internet settings page. -ASH_EXPORT void ShowNetworkSettings(const std::string& service_path); - -} // network_connect -} // ash - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_CONNECT_H diff --git a/chromium/ash/system/chromeos/network/network_detailed_view.h b/chromium/ash/system/chromeos/network/network_detailed_view.h deleted file mode 100644 index fe7ac21db0e..00000000000 --- a/chromium/ash/system/chromeos/network/network_detailed_view.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_DETAILED_VIEW_H -#define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_DETAILED_VIEW_H - -#include "ash/system/tray/tray_details_view.h" -#include "chromeos/network/network_state_handler.h" - -namespace ash { -namespace internal { - -namespace tray { - -// Abstract base class for all NetworkDetailedView derived subclasses, -// which includes NetworkWifiDetailedView and NetworkStateListDetailedView. -class NetworkDetailedView : public TrayDetailsView { - public: - enum DetailedViewType { - LIST_VIEW, - STATE_LIST_VIEW, - WIFI_VIEW, - }; - - explicit NetworkDetailedView(SystemTrayItem* owner) - : TrayDetailsView(owner) { - } - - virtual void Init() = 0; - - virtual DetailedViewType GetViewType() const = 0; - - // Called when network manager state has changed. - // (Generic update for NetworkTray <> AshSystemTrayDelegate interface). - virtual void ManagerChanged() = 0; - - // Called when the contents of the network list have changed. - // (Called only from TrayNetworkStateObserver). - virtual void NetworkListChanged() = 0; - - // Called when a network service property has changed. - // (Called only from TrayNetworkStateObserver). - virtual void NetworkServiceChanged(const chromeos::NetworkState* network) = 0; - - protected: - virtual ~NetworkDetailedView() {} -}; - -} // namespace tray - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_DETAILED_VIEW_H diff --git a/chromium/ash/system/chromeos/network/network_icon.cc b/chromium/ash/system/chromeos/network/network_icon.cc deleted file mode 100644 index d3c489934a7..00000000000 --- a/chromium/ash/system/chromeos/network/network_icon.cc +++ /dev/null @@ -1,846 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/network/network_icon.h" - -#include "ash/shell.h" -#include "ash/system/chromeos/network/network_icon_animation.h" -#include "ash/system/chromeos/network/network_icon_animation_observer.h" -#include "base/strings/utf_string_conversions.h" -#include "chromeos/network/device_state.h" -#include "chromeos/network/network_connection_handler.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" -#include "chromeos/network/shill_property_util.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "third_party/cros_system_api/dbus/service_constants.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/image/image_skia_operations.h" -#include "ui/gfx/image/image_skia_source.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size_conversions.h" - -using chromeos::DeviceState; -using chromeos::NetworkConnectionHandler; -using chromeos::NetworkHandler; -using chromeos::NetworkState; -using chromeos::NetworkStateHandler; -using chromeos::NetworkTypePattern; - -namespace ash { -namespace network_icon { - -namespace { - -//------------------------------------------------------------------------------ -// Struct to pass icon badges to NetworkIconImageSource. -struct Badges { - Badges() - : top_left(NULL), - top_right(NULL), - bottom_left(NULL), - bottom_right(NULL) { - } - const gfx::ImageSkia* top_left; - const gfx::ImageSkia* top_right; - const gfx::ImageSkia* bottom_left; - const gfx::ImageSkia* bottom_right; -}; - -//------------------------------------------------------------------------------ -// class used for maintaining a map of network state and images. -class NetworkIconImpl { - public: - explicit NetworkIconImpl(IconType icon_type); - - // Determines whether or not the associated network might be dirty and if so - // updates and generates the icon. Does nothing if network no longer exists. - void Update(const chromeos::NetworkState* network); - - const gfx::ImageSkia& image() const { return image_; } - - private: - // Updates |strength_index_| for wireless networks. Returns true if changed. - bool UpdateWirelessStrengthIndex(const chromeos::NetworkState* network); - - // Updates the local state for cellular networks. Returns true if changed. - bool UpdateCellularState(const chromeos::NetworkState* network); - - // Updates the VPN badge. Returns true if changed. - bool UpdateVPNBadge(); - - // Gets |badges| based on |network| and the current state. - void GetBadges(const NetworkState* network, Badges* badges); - - // Gets the appropriate icon and badges and composites the image. - void GenerateImage(const chromeos::NetworkState* network); - - // Defines color theme and VPN badging - const IconType icon_type_; - - // Cached state of the network when the icon was last generated. - std::string state_; - - // Cached strength index of the network when the icon was last generated. - int strength_index_; - - // Cached technology badge for the network when the icon was last generated. - const gfx::ImageSkia* technology_badge_; - - // Cached vpn badge for the network when the icon was last generated. - const gfx::ImageSkia* vpn_badge_; - - // Cached roaming state of the network when the icon was last generated. - std::string roaming_state_; - - // Generated icon image. - gfx::ImageSkia image_; - - DISALLOW_COPY_AND_ASSIGN(NetworkIconImpl); -}; - -//------------------------------------------------------------------------------ -// Maintain a static (global) icon map. Note: Icons are never destroyed; -// it is assumed that a finite and reasonable number of network icons will be -// created during a session. - -typedef std::map<std::string, NetworkIconImpl*> NetworkIconMap; - -NetworkIconMap* GetIconMapInstance(IconType icon_type, bool create) { - typedef std::map<IconType, NetworkIconMap*> IconTypeMap; - static IconTypeMap* s_icon_map = NULL; - if (s_icon_map == NULL) { - if (!create) - return NULL; - s_icon_map = new IconTypeMap; - } - if (s_icon_map->count(icon_type) == 0) { - if (!create) - return NULL; - (*s_icon_map)[icon_type] = new NetworkIconMap; - } - return (*s_icon_map)[icon_type]; -} - -NetworkIconMap* GetIconMap(IconType icon_type) { - return GetIconMapInstance(icon_type, true); -} - -void PurgeIconMap(IconType icon_type, - const std::set<std::string>& network_paths) { - NetworkIconMap* icon_map = GetIconMapInstance(icon_type, false); - if (!icon_map) - return; - for (NetworkIconMap::iterator loop_iter = icon_map->begin(); - loop_iter != icon_map->end(); ) { - NetworkIconMap::iterator cur_iter = loop_iter++; - if (network_paths.count(cur_iter->first) == 0) { - delete cur_iter->second; - icon_map->erase(cur_iter); - } - } -} - -//------------------------------------------------------------------------------ -// Utilities for generating icon images. - -// 'NONE' will default to ARCS behavior where appropriate (e.g. no network or -// if a new type gets added). -enum ImageType { - ARCS, - BARS, - NONE -}; - -// Amount to fade icons while connecting. -const double kConnectingImageAlpha = 0.5; - -// Images for strength bars for wired networks. -const int kNumBarsImages = 5; - -// Imagaes for strength arcs for wireless networks. -const int kNumArcsImages = 5; - -// Number of discrete images to use for alpha fade animation -const int kNumFadeImages = 10; - -//------------------------------------------------------------------------------ -// Classes for generating scaled images. - -const SkBitmap GetEmptyBitmap(const gfx::Size pixel_size) { - typedef std::pair<int, int> SizeKey; - typedef std::map<SizeKey, SkBitmap> SizeBitmapMap; - static SizeBitmapMap* s_empty_bitmaps = new SizeBitmapMap; - - SizeKey key(pixel_size.width(), pixel_size.height()); - - SizeBitmapMap::iterator iter = s_empty_bitmaps->find(key); - if (iter != s_empty_bitmaps->end()) - return iter->second; - - SkBitmap empty; - empty.setConfig(SkBitmap::kARGB_8888_Config, key.first, key.second); - empty.allocPixels(); - empty.eraseARGB(0, 0, 0, 0); - (*s_empty_bitmaps)[key] = empty; - return empty; -} - -class EmptyImageSource: public gfx::ImageSkiaSource { - public: - explicit EmptyImageSource(const gfx::Size& size) - : size_(size) { - } - - virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { - gfx::Size pixel_size = gfx::ToFlooredSize(gfx::ScaleSize(size_, scale)); - SkBitmap empty_bitmap = GetEmptyBitmap(pixel_size); - return gfx::ImageSkiaRep(empty_bitmap, scale); - } - - private: - const gfx::Size size_; - - DISALLOW_COPY_AND_ASSIGN(EmptyImageSource); -}; - -// This defines how we assemble a network icon. -class NetworkIconImageSource : public gfx::ImageSkiaSource { - public: - NetworkIconImageSource(const gfx::ImageSkia& icon, const Badges& badges) - : icon_(icon), - badges_(badges) { - } - virtual ~NetworkIconImageSource() {} - - // TODO(pkotwicz): Figure out what to do when a new image resolution becomes - // available. - virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { - gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale); - if (icon_rep.is_null()) - return gfx::ImageSkiaRep(); - gfx::Canvas canvas(icon_rep, false); - if (badges_.top_left) - canvas.DrawImageInt(*badges_.top_left, 0, 0); - if (badges_.top_right) - canvas.DrawImageInt(*badges_.top_right, - icon_.width() - badges_.top_right->width(), 0); - if (badges_.bottom_left) { - canvas.DrawImageInt(*badges_.bottom_left, - 0, icon_.height() - badges_.bottom_left->height()); - } - if (badges_.bottom_right) { - canvas.DrawImageInt(*badges_.bottom_right, - icon_.width() - badges_.bottom_right->width(), - icon_.height() - badges_.bottom_right->height()); - } - return canvas.ExtractImageRep(); - } - - private: - const gfx::ImageSkia icon_; - const Badges badges_; - - DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSource); -}; - -//------------------------------------------------------------------------------ -// Utilities for extracting icon images. - -bool IconTypeIsDark(IconType icon_type) { - return (icon_type != ICON_TYPE_TRAY); -} - -bool IconTypeHasVPNBadge(IconType icon_type) { - return (icon_type != ICON_TYPE_LIST); -} - -int NumImagesForType(ImageType type) { - return (type == BARS) ? kNumBarsImages : kNumArcsImages; -} - -gfx::ImageSkia* BaseImageForType(ImageType image_type, IconType icon_type) { - gfx::ImageSkia* image; - if (image_type == BARS) { - image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IconTypeIsDark(icon_type) ? - IDR_AURA_UBER_TRAY_NETWORK_BARS_DARK : - IDR_AURA_UBER_TRAY_NETWORK_BARS_LIGHT); - } else { - image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IconTypeIsDark(icon_type) ? - IDR_AURA_UBER_TRAY_NETWORK_ARCS_DARK : - IDR_AURA_UBER_TRAY_NETWORK_ARCS_LIGHT); - } - return image; -} - -ImageType ImageTypeForNetworkType(const std::string& type) { - if (type == shill::kTypeWifi) - return ARCS; - else if (type == shill::kTypeCellular || type == shill::kTypeWimax) - return BARS; - return NONE; -} - -gfx::ImageSkia GetImageForIndex(ImageType image_type, - IconType icon_type, - int index) { - int num_images = NumImagesForType(image_type); - if (index < 0 || index >= num_images) - return gfx::ImageSkia(); - gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); - int width = images->width(); - int height = images->height() / num_images; - return gfx::ImageSkiaOperations::ExtractSubset(*images, - gfx::Rect(0, index * height, width, height)); -} - -const gfx::ImageSkia GetConnectedImage(const std::string& type, - IconType icon_type) { - if (type == shill::kTypeVPN) { - return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_NETWORK_VPN); - } - ImageType image_type = ImageTypeForNetworkType(type); - const int connected_index = NumImagesForType(image_type) - 1; - return GetImageForIndex(image_type, icon_type, connected_index); -} - -const gfx::ImageSkia GetDisconnectedImage(const std::string& type, - IconType icon_type) { - if (type == shill::kTypeVPN) { - // Note: same as connected image, shouldn't normally be seen. - return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_NETWORK_VPN); - } - ImageType image_type = ImageTypeForNetworkType(type); - const int disconnected_index = 0; - return GetImageForIndex(image_type, icon_type, disconnected_index); -} - -gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type, - IconType icon_type, - double animation) { - static gfx::ImageSkia* s_bars_images_dark[kNumBarsImages - 1]; - static gfx::ImageSkia* s_bars_images_light[kNumBarsImages - 1]; - static gfx::ImageSkia* s_arcs_images_dark[kNumArcsImages - 1]; - static gfx::ImageSkia* s_arcs_images_light[kNumArcsImages - 1]; - int image_count = NumImagesForType(image_type) - 1; - int index = animation * nextafter(static_cast<float>(image_count), 0); - index = std::max(std::min(index, image_count - 1), 0); - gfx::ImageSkia** images; - bool dark = IconTypeIsDark(icon_type); - if (image_type == BARS) - images = dark ? s_bars_images_dark : s_bars_images_light; - else - images = dark ? s_arcs_images_dark : s_arcs_images_light; - if (!images[index]) { - // Lazily cache images. - gfx::ImageSkia source = GetImageForIndex(image_type, icon_type, index + 1); - images[index] = new gfx::ImageSkia( - gfx::ImageSkiaOperations::CreateBlendedImage( - gfx::ImageSkia(new EmptyImageSource(source.size()), source.size()), - source, - kConnectingImageAlpha)); - } - return images[index]; -} - -gfx::ImageSkia* ConnectingVpnImage(double animation) { - int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); - static gfx::ImageSkia* s_vpn_images[kNumFadeImages]; - if (!s_vpn_images[index]) { - // Lazily cache images. - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); - s_vpn_images[index] = new gfx::ImageSkia( - gfx::ImageSkiaOperations::CreateBlendedImage( - gfx::ImageSkia(new EmptyImageSource(icon->size()), icon->size()), - *icon, - animation)); - } - return s_vpn_images[index]; -} - -gfx::ImageSkia* ConnectingVpnBadge(double animation) { - int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); - static gfx::ImageSkia* s_vpn_badges[kNumFadeImages]; - if (!s_vpn_badges[index]) { - // Lazily cache images. - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - gfx::ImageSkia* icon = - rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); // For size - gfx::ImageSkia* badge = - rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); - s_vpn_badges[index] = new gfx::ImageSkia( - gfx::ImageSkiaOperations::CreateBlendedImage( - gfx::ImageSkia(new EmptyImageSource(icon->size()), icon->size()), - *badge, - animation)); - } - return s_vpn_badges[index]; -} - -int StrengthIndex(int strength, int count) { - // Return an index in the range [1, count-1]. - const float findex = (static_cast<float>(strength) / 100.0f) * - nextafter(static_cast<float>(count - 1), 0); - int index = 1 + static_cast<int>(findex); - index = std::max(std::min(index, count - 1), 1); - return index; -} - -int GetStrengthIndex(const NetworkState* network) { - ImageType image_type = ImageTypeForNetworkType(network->type()); - if (image_type == ARCS) - return StrengthIndex(network->signal_strength(), kNumArcsImages); - else if (image_type == BARS) - return StrengthIndex(network->signal_strength(), kNumBarsImages); - return 0; -} - -const gfx::ImageSkia* BadgeForNetworkTechnology(const NetworkState* network, - IconType icon_type) { - const int kUnknownBadgeType = -1; - int id = kUnknownBadgeType; - const std::string& technology = network->network_technology(); - if (technology == shill::kNetworkTechnologyEvdo) { - id = IconTypeIsDark(icon_type) ? - IDR_AURA_UBER_TRAY_NETWORK_EVDO_DARK : - IDR_AURA_UBER_TRAY_NETWORK_EVDO_LIGHT; - } else if (technology == shill::kNetworkTechnology1Xrtt) { - id = IDR_AURA_UBER_TRAY_NETWORK_1X; - } else if (technology == shill::kNetworkTechnologyGprs) { - id = IconTypeIsDark(icon_type) ? - IDR_AURA_UBER_TRAY_NETWORK_GPRS_DARK : - IDR_AURA_UBER_TRAY_NETWORK_GPRS_LIGHT; - } else if (technology == shill::kNetworkTechnologyEdge) { - id = IconTypeIsDark(icon_type) ? - IDR_AURA_UBER_TRAY_NETWORK_EDGE_DARK : - IDR_AURA_UBER_TRAY_NETWORK_EDGE_LIGHT; - } else if (technology == shill::kNetworkTechnologyUmts) { - id = IconTypeIsDark(icon_type) ? - IDR_AURA_UBER_TRAY_NETWORK_3G_DARK : - IDR_AURA_UBER_TRAY_NETWORK_3G_LIGHT; - } else if (technology == shill::kNetworkTechnologyHspa) { - id = IconTypeIsDark(icon_type) ? - IDR_AURA_UBER_TRAY_NETWORK_HSPA_DARK : - IDR_AURA_UBER_TRAY_NETWORK_HSPA_LIGHT; - } else if (technology == shill::kNetworkTechnologyHspaPlus) { - id = IconTypeIsDark(icon_type) ? - IDR_AURA_UBER_TRAY_NETWORK_HSPA_PLUS_DARK : - IDR_AURA_UBER_TRAY_NETWORK_HSPA_PLUS_LIGHT; - } else if (technology == shill::kNetworkTechnologyLte) { - id = IconTypeIsDark(icon_type) ? - IDR_AURA_UBER_TRAY_NETWORK_LTE_DARK : - IDR_AURA_UBER_TRAY_NETWORK_LTE_LIGHT; - } else if (technology == shill::kNetworkTechnologyLteAdvanced) { - id = IconTypeIsDark(icon_type) ? - IDR_AURA_UBER_TRAY_NETWORK_LTE_ADVANCED_DARK : - IDR_AURA_UBER_TRAY_NETWORK_LTE_ADVANCED_LIGHT; - } else if (technology == shill::kNetworkTechnologyGsm) { - id = IconTypeIsDark(icon_type) ? - IDR_AURA_UBER_TRAY_NETWORK_GPRS_DARK : - IDR_AURA_UBER_TRAY_NETWORK_GPRS_LIGHT; - } - if (id == kUnknownBadgeType) - return NULL; - else - return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); -} - -const gfx::ImageSkia* BadgeForVPN(IconType icon_type) { - return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); -} - -gfx::ImageSkia GetIcon(const NetworkState* network, - IconType icon_type, - int strength_index) { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - if (network->Matches(NetworkTypePattern::Ethernet())) { - return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); - } else if (network->Matches(NetworkTypePattern::Wireless())) { - DCHECK(strength_index > 0); - return GetImageForIndex( - ImageTypeForNetworkType(network->type()), icon_type, strength_index); - } else if (network->Matches(NetworkTypePattern::VPN())) { - return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); - } else { - LOG(WARNING) << "Request for icon for unsupported type: " - << network->type(); - return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); - } -} - -//------------------------------------------------------------------------------ -// Get connecting images - -gfx::ImageSkia GetConnectingVpnImage(IconType icon_type) { - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - const NetworkState* connected_network = NULL; - if (icon_type == ICON_TYPE_TRAY) { - connected_network = - handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); - } - double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); - - if (connected_network) { - gfx::ImageSkia icon = GetImageForNetwork(connected_network, icon_type); - Badges badges; - badges.bottom_left = ConnectingVpnBadge(animation); - return gfx::ImageSkia( - new NetworkIconImageSource(icon, badges), icon.size()); - } else { - gfx::ImageSkia* icon = ConnectingVpnImage(animation); - return gfx::ImageSkia( - new NetworkIconImageSource(*icon, Badges()), icon->size()); - } -} - -gfx::ImageSkia GetConnectingImage(const std::string& network_type, - IconType icon_type) { - if (network_type == shill::kTypeVPN) - return GetConnectingVpnImage(icon_type); - - ImageType image_type = ImageTypeForNetworkType(network_type); - double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); - - gfx::ImageSkia* icon = ConnectingWirelessImage( - image_type, icon_type, animation); - return gfx::ImageSkia( - new NetworkIconImageSource(*icon, Badges()), icon->size()); -} - -} // namespace - -//------------------------------------------------------------------------------ -// NetworkIconImpl - -NetworkIconImpl::NetworkIconImpl(IconType icon_type) - : icon_type_(icon_type), - strength_index_(-1), - technology_badge_(NULL), - vpn_badge_(NULL) { - // Default image - image_ = GetDisconnectedImage(shill::kTypeWifi, icon_type); -} - -void NetworkIconImpl::Update(const NetworkState* network) { - DCHECK(network); - // Determine whether or not we need to update the icon. - bool dirty = image_.isNull(); - - // If the network state has changed, the icon needs updating. - if (state_ != network->connection_state()) { - state_ = network->connection_state(); - dirty = true; - } - - if (network->Matches(NetworkTypePattern::Wireless())) - dirty |= UpdateWirelessStrengthIndex(network); - - if (network->Matches(NetworkTypePattern::Cellular())) - dirty |= UpdateCellularState(network); - - if (IconTypeHasVPNBadge(icon_type_) && - network->Matches(NetworkTypePattern::NonVirtual())) { - dirty |= UpdateVPNBadge(); - } - - if (dirty) { - // Set the icon and badges based on the network and generate the image. - GenerateImage(network); - } -} - -bool NetworkIconImpl::UpdateWirelessStrengthIndex(const NetworkState* network) { - int index = GetStrengthIndex(network); - if (index != strength_index_) { - strength_index_ = index; - return true; - } - return false; -} - -bool NetworkIconImpl::UpdateCellularState(const NetworkState* network) { - bool dirty = false; - const gfx::ImageSkia* technology_badge = - BadgeForNetworkTechnology(network, icon_type_); - if (technology_badge != technology_badge_) { - technology_badge_ = technology_badge; - dirty = true; - } - std::string roaming_state = network->roaming(); - if (roaming_state != roaming_state_) { - roaming_state_ = roaming_state; - dirty = true; - } - return dirty; -} - -bool NetworkIconImpl::UpdateVPNBadge() { - const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> - ConnectedNetworkByType(NetworkTypePattern::VPN()); - if (vpn && vpn_badge_ == NULL) { - vpn_badge_ = BadgeForVPN(icon_type_); - return true; - } else if (!vpn && vpn_badge_ != NULL) { - vpn_badge_ = NULL; - return true; - } - return false; -} - -void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) { - DCHECK(network); - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - - const std::string& type = network->type(); - if (type == shill::kTypeWifi) { - if (network->security() != shill::kSecurityNone && - IconTypeIsDark(icon_type_)) { - badges->bottom_right = rb.GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_NETWORK_SECURE_DARK); - } - } else if (type == shill::kTypeWimax) { - technology_badge_ = rb.GetImageSkiaNamed( - IconTypeIsDark(icon_type_) ? - IDR_AURA_UBER_TRAY_NETWORK_4G_DARK : - IDR_AURA_UBER_TRAY_NETWORK_4G_LIGHT); - } else if (type == shill::kTypeCellular) { - if (network->roaming() == shill::kRoamingStateRoaming) { - // For networks that are always in roaming don't show roaming badge. - const DeviceState* device = - handler->GetDeviceState(network->device_path()); - LOG_IF(WARNING, !device) << "Could not find device state for " - << network->device_path(); - if (!device || !device->provider_requires_roaming()) { - badges->bottom_right = rb.GetImageSkiaNamed( - IconTypeIsDark(icon_type_) ? - IDR_AURA_UBER_TRAY_NETWORK_ROAMING_DARK : - IDR_AURA_UBER_TRAY_NETWORK_ROAMING_LIGHT); - } - } - } - if (!network->IsConnectingState()) { - badges->top_left = technology_badge_; - badges->bottom_left = vpn_badge_; - } -} - -void NetworkIconImpl::GenerateImage(const NetworkState* network) { - DCHECK(network); - gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_); - Badges badges; - GetBadges(network, &badges); - image_ = gfx::ImageSkia( - new NetworkIconImageSource(icon, badges), icon.size()); -} - -//------------------------------------------------------------------------------ -// Public interface - -gfx::ImageSkia GetImageForNetwork(const NetworkState* network, - IconType icon_type) { - DCHECK(network); - // Handle connecting icons. - if (network->IsConnectingState()) - return GetConnectingImage(network->type(), icon_type); - - // Find or add the icon. - NetworkIconMap* icon_map = GetIconMap(icon_type); - NetworkIconImpl* icon; - NetworkIconMap::iterator iter = icon_map->find(network->path()); - if (iter == icon_map->end()) { - icon = new NetworkIconImpl(icon_type); - icon_map->insert(std::make_pair(network->path(), icon)); - } else { - icon = iter->second; - } - - // Update and return the icon's image. - icon->Update(network); - return icon->image(); -} - -gfx::ImageSkia GetImageForConnectedNetwork(IconType icon_type, - const std::string& network_type) { - return GetConnectedImage(network_type, icon_type); -} - -gfx::ImageSkia GetImageForConnectingNetwork(IconType icon_type, - const std::string& network_type) { - return GetConnectingImage(network_type, icon_type); -} - -gfx::ImageSkia GetImageForDisconnectedNetwork(IconType icon_type, - const std::string& network_type) { - return GetDisconnectedImage(network_type, icon_type); -} - -base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, - IconType icon_type) { - DCHECK(network); - std::string activation_state = network->activation_state(); - if (icon_type == ICON_TYPE_LIST) { - // Show "<network>: [Connecting|Activating]..." - if (network->IsConnectingState()) { - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_NETWORK_LIST_CONNECTING, - UTF8ToUTF16(network->name())); - } - if (activation_state == shill::kActivationStateActivating) { - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_NETWORK_LIST_ACTIVATING, - UTF8ToUTF16(network->name())); - } - // Show "Activate <network>" in list view only. - if (activation_state == shill::kActivationStateNotActivated || - activation_state == shill::kActivationStatePartiallyActivated) { - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_NETWORK_LIST_ACTIVATE, - UTF8ToUTF16(network->name())); - } - } else { - // Show "[Connected to|Connecting to|Activating] <network>" (non-list view). - if (network->IsConnectedState()) { - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, UTF8ToUTF16(network->name())); - } - if (network->IsConnectingState()) { - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_NETWORK_CONNECTING, UTF8ToUTF16(network->name())); - } - if (activation_state == shill::kActivationStateActivating) { - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_NETWORK_ACTIVATING, UTF8ToUTF16(network->name())); - } - } - - // Otherwise just show the network name or 'Ethernet'. - if (network->Matches(NetworkTypePattern::Ethernet())) { - return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ETHERNET); - } else { - return UTF8ToUTF16(network->name()); - } -} - -int GetCellularUninitializedMsg() { - static base::Time s_uninitialized_state_time; - static int s_uninitialized_msg(0); - - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - if (handler->GetTechnologyState(NetworkTypePattern::Mobile()) - == NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) { - s_uninitialized_msg = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR; - s_uninitialized_state_time = base::Time::Now(); - return s_uninitialized_msg; - } else if (handler->GetScanningByType(NetworkTypePattern::Mobile())) { - s_uninitialized_msg = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING; - s_uninitialized_state_time = base::Time::Now(); - return s_uninitialized_msg; - } - // There can be a delay between leaving the Initializing state and when - // a Cellular device shows up, so keep showing the initializing - // animation for a bit to avoid flashing the disconnect icon. - const int kInitializingDelaySeconds = 1; - base::TimeDelta dtime = base::Time::Now() - s_uninitialized_state_time; - if (dtime.InSeconds() < kInitializingDelaySeconds) - return s_uninitialized_msg; - return 0; -} - -void GetDefaultNetworkImageAndLabel(IconType icon_type, - gfx::ImageSkia* image, - base::string16* label, - bool* animating) { - NetworkStateHandler* state_handler = - NetworkHandler::Get()->network_state_handler(); - NetworkConnectionHandler* connect_handler = - NetworkHandler::Get()->network_connection_handler(); - const NetworkState* connected_network = - state_handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); - const NetworkState* connecting_network = - state_handler->ConnectingNetworkByType(NetworkTypePattern::Wireless()); - if (!connecting_network && icon_type == ICON_TYPE_TRAY) { - connecting_network = - state_handler->ConnectingNetworkByType(NetworkTypePattern::VPN()); - } - - const NetworkState* network; - // If we are connecting to a network, and there is either no connected - // network, or the connection was user requested, use the connecting - // network. - if (connecting_network && - (!connected_network || - connect_handler->HasConnectingNetwork(connecting_network->path()))) { - network = connecting_network; - } else { - network = connected_network; - } - - // Don't show ethernet in the tray - if (icon_type == ICON_TYPE_TRAY && network && - network->Matches(NetworkTypePattern::Ethernet())) { - *image = gfx::ImageSkia(); - *animating = false; - return; - } - - if (!network) { - // If no connecting network, check if we are activating a network. - const NetworkState* mobile_network = - state_handler->FirstNetworkByType(NetworkTypePattern::Mobile()); - if (mobile_network && (mobile_network->activation_state() == - shill::kActivationStateActivating)) { - network = mobile_network; - } - } - if (!network) { - // If no connecting network, check for cellular initializing. - int uninitialized_msg = GetCellularUninitializedMsg(); - if (uninitialized_msg != 0) { - *image = GetImageForConnectingNetwork(icon_type, shill::kTypeCellular); - if (label) - *label = l10n_util::GetStringUTF16(uninitialized_msg); - *animating = true; - } else { - // Otherwise show the disconnected wifi icon. - *image = GetImageForDisconnectedNetwork(icon_type, shill::kTypeWifi); - if (label) { - *label = l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED); - } - *animating = false; - } - return; - } - *animating = network->IsConnectingState(); - // Get icon and label for connected or connecting network. - *image = GetImageForNetwork(network, icon_type); - if (label) - *label = GetLabelForNetwork(network, icon_type); -} - -void PurgeNetworkIconCache() { - NetworkStateHandler::NetworkStateList networks; - NetworkHandler::Get()->network_state_handler()->GetNetworkList(&networks); - std::set<std::string> network_paths; - for (NetworkStateHandler::NetworkStateList::iterator iter = networks.begin(); - iter != networks.end(); ++iter) { - network_paths.insert((*iter)->path()); - } - PurgeIconMap(ICON_TYPE_TRAY, network_paths); - PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); - PurgeIconMap(ICON_TYPE_LIST, network_paths); -} - -} // namespace network_icon -} // namespace ash diff --git a/chromium/ash/system/chromeos/network/network_icon.h b/chromium/ash/system/chromeos/network/network_icon.h deleted file mode 100644 index 1f9b2c7e387..00000000000 --- a/chromium/ash/system/chromeos/network/network_icon.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_ICON_H_ -#define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_ICON_H_ - -#include <string> - -#include "ash/ash_export.h" -#include "base/strings/string16.h" -#include "ui/gfx/image/image_skia.h" - -namespace chromeos { -class NetworkState; -} - -namespace ash { -namespace network_icon { - -class AnimationObserver; - -// Type of icon which dictates color theme and VPN badging -enum IconType { - ICON_TYPE_TRAY, // light icons with VPN badges - ICON_TYPE_DEFAULT_VIEW, // dark icons with VPN badges - ICON_TYPE_LIST, // dark icons without VPN badges -}; - -// Gets the image for the network associated with |service_path|. |network| must -// not be NULL. |icon_type| determines the color theme and whether or not to -// show the VPN badge. This caches badged icons per network per |icon_type|. -ASH_EXPORT gfx::ImageSkia GetImageForNetwork( - const chromeos::NetworkState* network, - IconType icon_type); - -// Gets the fulls strength image for a connected network type. -ASH_EXPORT gfx::ImageSkia GetImageForConnectedNetwork( - IconType icon_type, - const std::string& network_type); - -// Gets the image for a connecting network type. -ASH_EXPORT gfx::ImageSkia GetImageForConnectingNetwork( - IconType icon_type, - const std::string& network_type); - -// Gets the image for a disconnected network type. -ASH_EXPORT gfx::ImageSkia GetImageForDisconnectedNetwork( - IconType icon_type, - const std::string& network_type); - -// Returns the label for |network| based on |icon_type|. |network| can be NULL. -ASH_EXPORT base::string16 GetLabelForNetwork( - const chromeos::NetworkState* network, - IconType icon_type); - -// Updates and returns the appropriate message id if the cellular network -// is uninitialized. -ASH_EXPORT int GetCellularUninitializedMsg(); - -// Gets the correct icon and label for |icon_type|. Also sets |animating| -// based on whether or not the icon is animating (i.e. connecting). -ASH_EXPORT void GetDefaultNetworkImageAndLabel(IconType icon_type, - gfx::ImageSkia* image, - base::string16* label, - bool* animating); - -// Called when the list of networks changes. Retreives the list of networks -// from the global NetworkStateHandler instance and removes cached entries -// that are no longer in the list. -ASH_EXPORT void PurgeNetworkIconCache(); - -} // namespace network_icon -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_ICON_H_ diff --git a/chromium/ash/system/chromeos/network/network_icon_animation.cc b/chromium/ash/system/chromeos/network/network_icon_animation.cc deleted file mode 100644 index 5065745c849..00000000000 --- a/chromium/ash/system/chromeos/network/network_icon_animation.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/network/network_icon_animation.h" - -#include "ash/system/chromeos/network/network_icon_animation_observer.h" - -namespace { -const int kThrobDurationMs = 750; // Animation cycle length. -} - -namespace ash { -namespace network_icon { - -NetworkIconAnimation::NetworkIconAnimation() - : animation_(this) { - // Set up the animation throbber. - animation_.SetThrobDuration(kThrobDurationMs); - animation_.SetTweenType(gfx::Tween::LINEAR); -} - -NetworkIconAnimation::~NetworkIconAnimation() { -} - -void NetworkIconAnimation::AnimationProgressed( - const gfx::Animation* animation) { - if (animation != &animation_) - return; - FOR_EACH_OBSERVER(AnimationObserver, observers_, NetworkIconChanged()); -} - -double NetworkIconAnimation::GetAnimation() { - if (!animation_.is_animating()) { - animation_.Reset(); - animation_.StartThrobbing(-1 /*throb indefinitely*/); - return 0; - } - return animation_.GetCurrentValue(); -} - -void NetworkIconAnimation::AddObserver(AnimationObserver* observer) { - if (!observers_.HasObserver(observer)) - observers_.AddObserver(observer); -} - -void NetworkIconAnimation::RemoveObserver(AnimationObserver* observer) { - observers_.RemoveObserver(observer); - if (!observers_.might_have_observers()) - animation_.Reset(); // Stops the animation and resets the current value. -} - -// static -NetworkIconAnimation* NetworkIconAnimation::GetInstance() { - static NetworkIconAnimation* s_icon_animation = - new NetworkIconAnimation(); - return s_icon_animation; -} - -} // namespace network_icon -} // namespace ash diff --git a/chromium/ash/system/chromeos/network/network_icon_animation.h b/chromium/ash/system/chromeos/network/network_icon_animation.h deleted file mode 100644 index a34b80ed969..00000000000 --- a/chromium/ash/system/chromeos/network/network_icon_animation.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_ICON_ANIMATION_H_ -#define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_ICON_ANIMATION_H_ - -#include <set> -#include <string> - -#include "ash/ash_export.h" -#include "base/observer_list.h" -#include "ui/gfx/animation/animation_delegate.h" -#include "ui/gfx/animation/throb_animation.h" - -namespace ash { -namespace network_icon { - -class AnimationObserver; - -// Single instance class to handle icon animations and keep them in sync. -class ASH_EXPORT NetworkIconAnimation : public gfx::AnimationDelegate { - public: - NetworkIconAnimation(); - virtual ~NetworkIconAnimation(); - - // Returns the current animation value, [0-1]. - double GetAnimation(); - - // The animation stops when all observers have been removed. - // Be sure to remove observers when no associated icons are animating. - void AddObserver(AnimationObserver* observer); - void RemoveObserver(AnimationObserver* observer); - - // gfx::AnimationDelegate implementation. - virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; - - static NetworkIconAnimation* GetInstance(); - - private: - gfx::ThrobAnimation animation_; - ObserverList<AnimationObserver> observers_; -}; - -} // namespace network_icon -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_ICON_ANIMATION_H_ diff --git a/chromium/ash/system/chromeos/network/network_icon_animation_observer.h b/chromium/ash/system/chromeos/network/network_icon_animation_observer.h deleted file mode 100644 index 28a5c735d1b..00000000000 --- a/chromium/ash/system/chromeos/network/network_icon_animation_observer.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_ICON_ANIMATION_OBSERVER_H_ -#define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_ICON_ANIMATION_OBSERVER_H_ - -#include "ash/ash_export.h" - -namespace ash { -namespace network_icon { - -// Observer interface class for animating network icons. -class ASH_EXPORT AnimationObserver { - public: - // Called when the image has changed due to animation. The callback should - // trigger a call to GetImageForNetwork() to retrieve the image. - virtual void NetworkIconChanged() = 0; - - protected: - virtual ~AnimationObserver() {} -}; - -} // namespace network_icon -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_ICON_ANIMATION_OBSERVER_H_ diff --git a/chromium/ash/system/chromeos/network/network_observer.h b/chromium/ash/system/chromeos/network/network_observer.h deleted file mode 100644 index 20473c7786c..00000000000 --- a/chromium/ash/system/chromeos/network/network_observer.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_OBSERVER_H -#define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_OBSERVER_H - -#include <vector> - -#include "base/strings/string16.h" - -namespace ash { - -class NetworkObserver { - public: - virtual ~NetworkObserver() {} - - // Called to request toggling Wi-Fi enable/disable, e.g. from an accelerator. - // NOTE: Toggling is asynchronous and subsequent calls to query the current - // state may return the old value. - virtual void RequestToggleWifi() = 0; -}; - -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_OBSERVER_H diff --git a/chromium/ash/system/chromeos/network/network_state_list_detailed_view.cc b/chromium/ash/system/chromeos/network/network_state_list_detailed_view.cc deleted file mode 100644 index ed2d0382b63..00000000000 --- a/chromium/ash/system/chromeos/network/network_state_list_detailed_view.cc +++ /dev/null @@ -1,896 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/network/network_state_list_detailed_view.h" - -#include "ash/ash_switches.h" -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/root_window_controller.h" -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "ash/shell_window_ids.h" -#include "ash/system/chromeos/network/network_connect.h" -#include "ash/system/chromeos/network/network_icon.h" -#include "ash/system/chromeos/network/network_icon_animation.h" -#include "ash/system/chromeos/network/tray_network_state_observer.h" -#include "ash/system/tray/fixed_sized_scroll_view.h" -#include "ash/system/tray/hover_highlight_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_details_view.h" -#include "ash/system/tray/tray_popup_header_button.h" -#include "ash/system/tray/tray_popup_label_button.h" -#include "base/command_line.h" -#include "base/message_loop/message_loop.h" -#include "base/strings/utf_string_conversions.h" -#include "base/time/time.h" -#include "chromeos/chromeos_switches.h" -#include "chromeos/network/device_state.h" -#include "chromeos/network/favorite_state.h" -#include "chromeos/network/network_configuration_handler.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" -#include "chromeos/network/shill_property_util.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "third_party/cros_system_api/dbus/service_constants.h" -#include "ui/aura/window.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/views/bubble/bubble_delegate.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/widget/widget.h" - -using chromeos::DeviceState; -using chromeos::FavoriteState; -using chromeos::NetworkHandler; -using chromeos::NetworkState; -using chromeos::NetworkStateHandler; -using chromeos::NetworkTypePattern; - -namespace ash { -namespace internal { -namespace tray { - -namespace { - -// Delay between scan requests. -const int kRequestScanDelaySeconds = 10; - -// Create a label with the font size and color used in the network info bubble. -views::Label* CreateInfoBubbleLabel(const base::string16& text) { - views::Label* label = new views::Label(text); - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - label->SetFont(rb.GetFont(ui::ResourceBundle::SmallFont)); - label->SetEnabledColor(SkColorSetARGB(127, 0, 0, 0)); - return label; -} - -// Create a label formatted for info items in the menu -views::Label* CreateMenuInfoLabel(const base::string16& text) { - views::Label* label = new views::Label(text); - label->set_border(views::Border::CreateEmptyBorder( - ash::kTrayPopupPaddingBetweenItems, - ash::kTrayPopupPaddingHorizontal, - ash::kTrayPopupPaddingBetweenItems, 0)); - label->SetHorizontalAlignment(gfx::ALIGN_LEFT); - label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0)); - return label; -} - -// Create a row of labels for the network info bubble. -views::View* CreateInfoBubbleLine(const base::string16& text_label, - const std::string& text_string) { - views::View* view = new views::View; - view->SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 1)); - view->AddChildView(CreateInfoBubbleLabel(text_label)); - view->AddChildView(CreateInfoBubbleLabel(UTF8ToUTF16(": "))); - view->AddChildView(CreateInfoBubbleLabel(UTF8ToUTF16(text_string))); - return view; -} - -} // namespace - - -//------------------------------------------------------------------------------ - -struct NetworkInfo { - NetworkInfo(const std::string& path) - : service_path(path), - disable(false), - highlight(false) { - } - - std::string service_path; - base::string16 label; - gfx::ImageSkia image; - bool disable; - bool highlight; -}; - -//------------------------------------------------------------------------------ - -// A bubble which displays network info. -class NetworkStateListDetailedView::InfoBubble - : public views::BubbleDelegateView { - public: - InfoBubble(views::View* anchor, - views::View* content, - NetworkStateListDetailedView* detailed_view) - : views::BubbleDelegateView(anchor, views::BubbleBorder::TOP_RIGHT), - detailed_view_(detailed_view) { - set_use_focusless(true); - set_parent_window(ash::Shell::GetContainer( - anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), - ash::internal::kShellWindowId_SettingBubbleContainer)); - SetLayoutManager(new views::FillLayout()); - AddChildView(content); - } - - virtual ~InfoBubble() { - detailed_view_->OnInfoBubbleDestroyed(); - } - - virtual bool CanActivate() const OVERRIDE { return false; } - - private: - // Not owned. - NetworkStateListDetailedView* detailed_view_; - - DISALLOW_COPY_AND_ASSIGN(InfoBubble); -}; - -//------------------------------------------------------------------------------ -// NetworkStateListDetailedView - -NetworkStateListDetailedView::NetworkStateListDetailedView( - SystemTrayItem* owner, - ListType list_type, - user::LoginStatus login) - : NetworkDetailedView(owner), - list_type_(list_type), - login_(login), - info_icon_(NULL), - button_wifi_(NULL), - button_mobile_(NULL), - other_wifi_(NULL), - turn_on_wifi_(NULL), - other_mobile_(NULL), - other_vpn_(NULL), - toggle_debug_preferred_networks_(NULL), - settings_(NULL), - proxy_settings_(NULL), - scanning_view_(NULL), - no_wifi_networks_view_(NULL), - no_cellular_networks_view_(NULL), - info_bubble_(NULL) { -} - -NetworkStateListDetailedView::~NetworkStateListDetailedView() { - if (info_bubble_) - info_bubble_->GetWidget()->CloseNow(); - network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); -} - -void NetworkStateListDetailedView::ManagerChanged() { - UpdateNetworkList(); - UpdateHeaderButtons(); - UpdateNetworkExtra(); - Layout(); -} - -void NetworkStateListDetailedView::NetworkListChanged() { - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - if (list_type_ == LIST_TYPE_DEBUG_PREFERRED) { - NetworkStateHandler::FavoriteStateList favorite_list; - handler->GetFavoriteList(&favorite_list); - UpdatePreferred(favorite_list); - } else { - NetworkStateHandler::NetworkStateList network_list; - handler->GetNetworkList(&network_list); - UpdateNetworks(network_list); - } - UpdateNetworkList(); - UpdateHeaderButtons(); - UpdateNetworkExtra(); - Layout(); -} - -void NetworkStateListDetailedView::NetworkServiceChanged( - const NetworkState* network) { - UpdateNetworkList(); - Layout(); -} - -void NetworkStateListDetailedView::NetworkIconChanged() { - UpdateNetworkList(); - Layout(); -} - -// Overridden from NetworkDetailedView: - -void NetworkStateListDetailedView::Init() { - Reset(); - network_map_.clear(); - service_path_map_.clear(); - info_icon_ = NULL; - button_wifi_ = NULL; - button_mobile_ = NULL; - other_wifi_ = NULL; - turn_on_wifi_ = NULL; - other_mobile_ = NULL; - other_vpn_ = NULL; - toggle_debug_preferred_networks_ = NULL; - settings_ = NULL; - proxy_settings_ = NULL; - scanning_view_ = NULL; - no_wifi_networks_view_ = NULL; - no_cellular_networks_view_ = NULL; - - CreateScrollableList(); - CreateNetworkExtra(); - CreateHeaderEntry(); - CreateHeaderButtons(); - - NetworkListChanged(); - - CallRequestScan(); -} - -NetworkDetailedView::DetailedViewType -NetworkStateListDetailedView::GetViewType() const { - return STATE_LIST_VIEW; -} - -// Views overrides - -void NetworkStateListDetailedView::ButtonPressed(views::Button* sender, - const ui::Event& event) { - if (sender == info_icon_) { - ToggleInfoBubble(); - return; - } - - // If the info bubble was visible, close it when some other item is clicked. - ResetInfoBubble(); - - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - ash::SystemTrayDelegate* delegate = - ash::Shell::GetInstance()->system_tray_delegate(); - if (sender == button_wifi_) { - bool enabled = handler->IsTechnologyEnabled( - NetworkTypePattern::WiFi()); - handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), - !enabled, - chromeos::network_handler::ErrorCallback()); - } else if (sender == turn_on_wifi_) { - handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), - true, - chromeos::network_handler::ErrorCallback()); - } else if (sender == button_mobile_) { - ToggleMobile(); - } else if (sender == settings_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - list_type_ == LIST_TYPE_VPN ? - ash::UMA_STATUS_AREA_VPN_SETTINGS_CLICKED : - ash::UMA_STATUS_AREA_NETWORK_SETTINGS_CLICKED); - delegate->ShowNetworkSettings(""); - } else if (sender == proxy_settings_) { - delegate->ChangeProxySettings(); - } else if (sender == other_mobile_) { - delegate->ShowOtherNetworkDialog(shill::kTypeCellular); - } else if (sender == toggle_debug_preferred_networks_) { - list_type_ = (list_type_ == LIST_TYPE_NETWORK) - ? LIST_TYPE_DEBUG_PREFERRED : LIST_TYPE_NETWORK; - // Re-initialize this after processing the event. - base::MessageLoopForUI::current()->PostTask( - FROM_HERE, - base::Bind(&NetworkStateListDetailedView::Init, AsWeakPtr())); - } else if (sender == other_wifi_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED); - delegate->ShowOtherNetworkDialog(shill::kTypeWifi); - } else if (sender == other_vpn_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_VPN_JOIN_OTHER_CLICKED); - delegate->ShowOtherNetworkDialog(shill::kTypeVPN); - } else { - NOTREACHED(); - } -} - -void NetworkStateListDetailedView::OnViewClicked(views::View* sender) { - // If the info bubble was visible, close it when some other item is clicked. - ResetInfoBubble(); - - if (sender == footer()->content()) { - TransitionToDefaultView(); - return; - } - - if (login_ == user::LOGGED_IN_LOCKED) - return; - - std::map<views::View*, std::string>::iterator found = - network_map_.find(sender); - if (found == network_map_.end()) - return; - - const std::string& service_path = found->second; - if (list_type_ == LIST_TYPE_DEBUG_PREFERRED) { - NetworkHandler::Get()->network_configuration_handler()-> - RemoveConfiguration(service_path, - base::Bind(&base::DoNothing), - chromeos::network_handler::ErrorCallback()); - return; - } - - const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> - GetNetworkState(service_path); - if (!network || network->IsConnectedState() || network->IsConnectingState()) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - list_type_ == LIST_TYPE_VPN ? - ash::UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS : - ash::UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS); - Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( - service_path); - } else { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - list_type_ == LIST_TYPE_VPN ? - ash::UMA_STATUS_AREA_CONNECT_TO_VPN : - ash::UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK); - ash::network_connect::ConnectToNetwork(service_path, NULL); - } -} - -// Create UI components. - -void NetworkStateListDetailedView::CreateHeaderEntry() { - CreateSpecialRow(IDS_ASH_STATUS_TRAY_NETWORK, this); -} - -void NetworkStateListDetailedView::CreateHeaderButtons() { - if (list_type_ != LIST_TYPE_VPN) { - button_wifi_ = new TrayPopupHeaderButton( - this, - IDR_AURA_UBER_TRAY_WIFI_ENABLED, - IDR_AURA_UBER_TRAY_WIFI_DISABLED, - IDR_AURA_UBER_TRAY_WIFI_ENABLED_HOVER, - IDR_AURA_UBER_TRAY_WIFI_DISABLED_HOVER, - IDS_ASH_STATUS_TRAY_WIFI); - button_wifi_->SetTooltipText( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_WIFI)); - button_wifi_->SetToggledTooltipText( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_WIFI)); - footer()->AddButton(button_wifi_); - - button_mobile_ = new TrayPopupHeaderButton( - this, - IDR_AURA_UBER_TRAY_CELLULAR_ENABLED, - IDR_AURA_UBER_TRAY_CELLULAR_DISABLED, - IDR_AURA_UBER_TRAY_CELLULAR_ENABLED_HOVER, - IDR_AURA_UBER_TRAY_CELLULAR_DISABLED_HOVER, - IDS_ASH_STATUS_TRAY_CELLULAR); - button_mobile_->SetTooltipText( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_MOBILE)); - button_mobile_->SetToggledTooltipText( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_MOBILE)); - footer()->AddButton(button_mobile_); - } - - info_icon_ = new TrayPopupHeaderButton( - this, - IDR_AURA_UBER_TRAY_NETWORK_INFO, - IDR_AURA_UBER_TRAY_NETWORK_INFO, - IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER, - IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER, - IDS_ASH_STATUS_TRAY_NETWORK_INFO); - info_icon_->SetTooltipText( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_INFO)); - footer()->AddButton(info_icon_); -} - -void NetworkStateListDetailedView::CreateNetworkExtra() { - if (login_ == user::LOGGED_IN_LOCKED) - return; - - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - - views::View* bottom_row = new views::View(); - views::BoxLayout* layout = new views::BoxLayout( - views::BoxLayout::kHorizontal, - kTrayMenuBottomRowPadding, - kTrayMenuBottomRowPadding, - kTrayMenuBottomRowPaddingBetweenItems); - layout->set_spread_blank_space(true); - bottom_row->SetLayoutManager(layout); - - if (list_type_ != LIST_TYPE_VPN) { - other_wifi_ = new TrayPopupLabelButton( - this, rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_OTHER_WIFI)); - bottom_row->AddChildView(other_wifi_); - - turn_on_wifi_ = new TrayPopupLabelButton( - this, rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_TURN_ON_WIFI)); - bottom_row->AddChildView(turn_on_wifi_); - - other_mobile_ = new TrayPopupLabelButton( - this, rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_OTHER_MOBILE)); - bottom_row->AddChildView(other_mobile_); - - if (CommandLine::ForCurrentProcess()->HasSwitch( - ash::switches::kAshDebugShowPreferredNetworks)) { - // Debugging UI to view and remove favorites from the status area. - std::string toggle_debug_preferred_label = - (list_type_ == LIST_TYPE_DEBUG_PREFERRED) ? "Visible" : "Preferred"; - toggle_debug_preferred_networks_ = new TrayPopupLabelButton( - this, UTF8ToUTF16(toggle_debug_preferred_label)); - bottom_row->AddChildView(toggle_debug_preferred_networks_); - } - } else { - other_vpn_ = new TrayPopupLabelButton( - this, - ui::ResourceBundle::GetSharedInstance().GetLocalizedString( - IDS_ASH_STATUS_TRAY_OTHER_VPN)); - bottom_row->AddChildView(other_vpn_); - } - - CreateSettingsEntry(); - DCHECK(settings_ || proxy_settings_); - bottom_row->AddChildView(settings_ ? settings_ : proxy_settings_); - - AddChildView(bottom_row); -} - -// Update UI components. - -void NetworkStateListDetailedView::UpdateHeaderButtons() { - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - if (button_wifi_) - UpdateTechnologyButton(button_wifi_, NetworkTypePattern::WiFi()); - if (button_mobile_) { - UpdateTechnologyButton(button_mobile_, NetworkTypePattern::Mobile()); - } - if (proxy_settings_) - proxy_settings_->SetEnabled(handler->DefaultNetwork() != NULL); - - static_cast<views::View*>(footer())->Layout(); -} - -void NetworkStateListDetailedView::UpdateTechnologyButton( - TrayPopupHeaderButton* button, - const NetworkTypePattern& technology) { - NetworkStateHandler::TechnologyState state = - NetworkHandler::Get()->network_state_handler()->GetTechnologyState( - technology); - if (state == NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) { - button->SetVisible(false); - return; - } - button->SetVisible(true); - if (state == NetworkStateHandler::TECHNOLOGY_AVAILABLE) { - button->SetEnabled(true); - button->SetToggled(true); - } else if (state == NetworkStateHandler::TECHNOLOGY_ENABLED) { - button->SetEnabled(true); - button->SetToggled(false); - } else if (state == NetworkStateHandler::TECHNOLOGY_ENABLING) { - button->SetEnabled(false); - button->SetToggled(false); - } else { // Initializing - button->SetEnabled(false); - button->SetToggled(true); - } -} - -void NetworkStateListDetailedView::UpdateNetworks( - const NetworkStateHandler::NetworkStateList& networks) { - DCHECK(list_type_ != LIST_TYPE_DEBUG_PREFERRED); - network_list_.clear(); - for (NetworkStateHandler::NetworkStateList::const_iterator iter = - networks.begin(); iter != networks.end(); ++iter) { - const NetworkState* network = *iter; - if ((list_type_ == LIST_TYPE_NETWORK && - network->type() != shill::kTypeVPN) || - (list_type_ == LIST_TYPE_VPN && - network->type() == shill::kTypeVPN)) { - NetworkInfo* info = new NetworkInfo(network->path()); - network_list_.push_back(info); - } - } -} - -void NetworkStateListDetailedView::UpdatePreferred( - const NetworkStateHandler::FavoriteStateList& favorites) { - DCHECK(list_type_ == LIST_TYPE_DEBUG_PREFERRED); - network_list_.clear(); - for (NetworkStateHandler::FavoriteStateList::const_iterator iter = - favorites.begin(); iter != favorites.end(); ++iter) { - const FavoriteState* favorite = *iter; - NetworkInfo* info = new NetworkInfo(favorite->path()); - network_list_.push_back(info); - } -} - -void NetworkStateListDetailedView::UpdateNetworkList() { - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - - // First, update state for all networks - bool animating = false; - for (size_t i = 0; i < network_list_.size(); ++i) { - NetworkInfo* info = network_list_[i]; - const NetworkState* network = - handler->GetNetworkState(info->service_path); - if (network) { - info->image = network_icon::GetImageForNetwork( - network, network_icon::ICON_TYPE_LIST); - info->label = network_icon::GetLabelForNetwork( - network, network_icon::ICON_TYPE_LIST); - info->highlight = - network->IsConnectedState() || network->IsConnectingState(); - info->disable = - network->activation_state() == shill::kActivationStateActivating; - if (!animating && network->IsConnectingState()) - animating = true; - } else if (list_type_ == LIST_TYPE_DEBUG_PREFERRED) { - // Favorites that are visible will use the same display info as the - // visible network. Non visible favorites will show the disconnected - // icon and the name of the network. - const FavoriteState* favorite = - handler->GetFavoriteState(info->service_path); - if (favorite) { - info->image = network_icon::GetImageForDisconnectedNetwork( - network_icon::ICON_TYPE_LIST, favorite->type()); - info->label = UTF8ToUTF16(favorite->name()); - } - } - } - if (animating) - network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); - else - network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); - - // Get the updated list entries - network_map_.clear(); - std::set<std::string> new_service_paths; - bool needs_relayout = UpdateNetworkListEntries(&new_service_paths); - - // Remove old children - std::set<std::string> remove_service_paths; - for (ServicePathMap::const_iterator it = service_path_map_.begin(); - it != service_path_map_.end(); ++it) { - if (new_service_paths.find(it->first) == new_service_paths.end()) { - remove_service_paths.insert(it->first); - network_map_.erase(it->second); - scroll_content()->RemoveChildView(it->second); - needs_relayout = true; - } - } - - for (std::set<std::string>::const_iterator remove_it = - remove_service_paths.begin(); - remove_it != remove_service_paths.end(); ++remove_it) { - service_path_map_.erase(*remove_it); - } - - if (needs_relayout) { - views::View* selected_view = NULL; - for (ServicePathMap::const_iterator iter = service_path_map_.begin(); - iter != service_path_map_.end(); ++iter) { - if (iter->second->hover()) { - selected_view = iter->second; - break; - } - } - scroll_content()->SizeToPreferredSize(); - static_cast<views::View*>(scroller())->Layout(); - if (selected_view) - scroll_content()->ScrollRectToVisible(selected_view->bounds()); - } -} - -bool NetworkStateListDetailedView::CreateOrUpdateInfoLabel( - int index, const base::string16& text, views::Label** label) { - if (*label == NULL) { - *label = CreateMenuInfoLabel(text); - scroll_content()->AddChildViewAt(*label, index); - return true; - } else { - (*label)->SetText(text); - return OrderChild(*label, index); - } -} - -bool NetworkStateListDetailedView::UpdateNetworkChild(int index, - const NetworkInfo* info) { - bool needs_relayout = false; - HoverHighlightView* container = NULL; - ServicePathMap::const_iterator found = - service_path_map_.find(info->service_path); - gfx::Font::FontStyle font = - info->highlight ? gfx::Font::BOLD : gfx::Font::NORMAL; - if (found == service_path_map_.end()) { - container = new HoverHighlightView(this); - container->AddIconAndLabel(info->image, info->label, font); - scroll_content()->AddChildViewAt(container, index); - container->set_border(views::Border::CreateEmptyBorder( - 0, kTrayPopupPaddingHorizontal, 0, 0)); - needs_relayout = true; - } else { - container = found->second; - container->RemoveAllChildViews(true); - container->AddIconAndLabel(info->image, info->label, font); - container->Layout(); - container->SchedulePaint(); - needs_relayout = OrderChild(container, index); - } - if (info->disable) - container->SetEnabled(false); - network_map_[container] = info->service_path; - service_path_map_[info->service_path] = container; - return needs_relayout; -} - -bool NetworkStateListDetailedView::OrderChild(views::View* view, int index) { - if (scroll_content()->child_at(index) != view) { - scroll_content()->ReorderChildView(view, index); - return true; - } - return false; -} - -bool NetworkStateListDetailedView::UpdateNetworkListEntries( - std::set<std::string>* new_service_paths) { - bool needs_relayout = false; - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - - // Insert child views - int index = 0; - - // Highlighted networks - for (size_t i = 0; i < network_list_.size(); ++i) { - const NetworkInfo* info = network_list_[i]; - if (info->highlight) { - if (UpdateNetworkChild(index++, info)) - needs_relayout = true; - new_service_paths->insert(info->service_path); - } - } - - if (list_type_ == LIST_TYPE_NETWORK) { - // Cellular initializing - int status_message_id = network_icon::GetCellularUninitializedMsg(); - if (!status_message_id && - handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && - !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { - status_message_id = IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS; - } - if (status_message_id) { - base::string16 text = rb.GetLocalizedString(status_message_id); - if (CreateOrUpdateInfoLabel(index++, text, &no_cellular_networks_view_)) - needs_relayout = true; - } else if (no_cellular_networks_view_) { - scroll_content()->RemoveChildView(no_cellular_networks_view_); - no_cellular_networks_view_ = NULL; - needs_relayout = true; - } - - // "Wifi Enabled / Disabled" - if (network_list_.empty()) { - int message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) - ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED - : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; - base::string16 text = rb.GetLocalizedString(message_id); - if (CreateOrUpdateInfoLabel(index++, text, &no_wifi_networks_view_)) - needs_relayout = true; - } else if (no_wifi_networks_view_) { - scroll_content()->RemoveChildView(no_wifi_networks_view_); - no_wifi_networks_view_ = NULL; - needs_relayout = true; - } - - // "Wifi Scanning" - if (handler->GetScanningByType(NetworkTypePattern::WiFi())) { - base::string16 text = - rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_WIFI_SCANNING_MESSAGE); - if (CreateOrUpdateInfoLabel(index++, text, &scanning_view_)) - needs_relayout = true; - } else if (scanning_view_ != NULL) { - scroll_content()->RemoveChildView(scanning_view_); - scanning_view_ = NULL; - needs_relayout = true; - } - } - - // Un-highlighted networks - for (size_t i = 0; i < network_list_.size(); ++i) { - const NetworkInfo* info = network_list_[i]; - if (!info->highlight) { - if (UpdateNetworkChild(index++, info)) - needs_relayout = true; - new_service_paths->insert(info->service_path); - } - } - - // No networks or other messages (fallback) - if (index == 0) { - base::string16 text; - if (list_type_ == LIST_TYPE_VPN) - text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_NETWORK_NO_VPN); - else - text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_NO_NETWORKS); - if (CreateOrUpdateInfoLabel(index++, text, &scanning_view_)) - needs_relayout = true; - } - - return needs_relayout; -} - -void NetworkStateListDetailedView::UpdateNetworkExtra() { - if (login_ == user::LOGGED_IN_LOCKED) - return; - - View* layout_parent = NULL; // All these buttons have the same parent. - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - if (other_wifi_) { - DCHECK(turn_on_wifi_); - NetworkStateHandler::TechnologyState state = - handler->GetTechnologyState(NetworkTypePattern::WiFi()); - if (state == NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) { - turn_on_wifi_->SetVisible(false); - other_wifi_->SetVisible(false); - } else { - if (state == NetworkStateHandler::TECHNOLOGY_AVAILABLE) { - turn_on_wifi_->SetVisible(true); - turn_on_wifi_->SetEnabled(true); - other_wifi_->SetVisible(false); - } else if (state == NetworkStateHandler::TECHNOLOGY_ENABLED) { - turn_on_wifi_->SetVisible(false); - other_wifi_->SetVisible(true); - } else { - // Initializing or Enabling - turn_on_wifi_->SetVisible(true); - turn_on_wifi_->SetEnabled(false); - other_wifi_->SetVisible(false); - } - } - layout_parent = other_wifi_->parent(); - } - - if (other_mobile_) { - bool show_other_mobile = false; - NetworkStateHandler::TechnologyState state = - handler->GetTechnologyState(NetworkTypePattern::Mobile()); - if (state != NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) { - const chromeos::DeviceState* device = - handler->GetDeviceStateByType(NetworkTypePattern::Mobile()); - show_other_mobile = (device && device->support_network_scan()); - } - if (show_other_mobile) { - other_mobile_->SetVisible(true); - other_mobile_->SetEnabled( - state == NetworkStateHandler::TECHNOLOGY_ENABLED); - } else { - other_mobile_->SetVisible(false); - } - if (!layout_parent) - layout_parent = other_wifi_->parent(); - } - - if (layout_parent) - layout_parent->Layout(); -} - -void NetworkStateListDetailedView::CreateSettingsEntry() { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - if (login_ != user::LOGGED_IN_NONE) { - // Settings, only if logged in. - settings_ = new TrayPopupLabelButton( - this, rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_NETWORK_SETTINGS)); - } else { - proxy_settings_ = new TrayPopupLabelButton( - this, - rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_NETWORK_PROXY_SETTINGS)); - } -} - -void NetworkStateListDetailedView::ToggleInfoBubble() { - if (ResetInfoBubble()) - return; - - info_bubble_ = new InfoBubble( - info_icon_, CreateNetworkInfoView(), this); - views::BubbleDelegateView::CreateBubble(info_bubble_)->Show(); -} - -bool NetworkStateListDetailedView::ResetInfoBubble() { - if (!info_bubble_) - return false; - info_bubble_->GetWidget()->Close(); - info_bubble_ = NULL; - return true; -} - -void NetworkStateListDetailedView::OnInfoBubbleDestroyed() { - info_bubble_ = NULL; -} - -views::View* NetworkStateListDetailedView::CreateNetworkInfoView() { - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - - std::string ip_address("0.0.0.0"); - const NetworkState* network = handler->DefaultNetwork(); - if (network) - ip_address = network->ip_address(); - - views::View* container = new views::View; - container->SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); - container->set_border(views::Border::CreateEmptyBorder(0, 5, 0, 5)); - - std::string ethernet_address, wifi_address, vpn_address; - if (list_type_ != LIST_TYPE_VPN) { - ethernet_address = handler->FormattedHardwareAddressForType( - NetworkTypePattern::Ethernet()); - wifi_address = - handler->FormattedHardwareAddressForType(NetworkTypePattern::WiFi()); - } else { - vpn_address = - handler->FormattedHardwareAddressForType(NetworkTypePattern::VPN()); - } - - if (!ip_address.empty()) { - container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_IP), ip_address)); - } - if (!ethernet_address.empty()) { - container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_ETHERNET), ethernet_address)); - } - if (!wifi_address.empty()) { - container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_WIFI), wifi_address)); - } - if (!vpn_address.empty()) { - container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_VPN), vpn_address)); - } - - // Avoid an empty bubble in the unlikely event that there is no network - // information at all. - if (!container->has_children()) { - container->AddChildView(CreateInfoBubbleLabel(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_NO_NETWORKS))); - } - - return container; -} - -void NetworkStateListDetailedView::CallRequestScan() { - VLOG(1) << "Requesting Network Scan."; - NetworkHandler::Get()->network_state_handler()->RequestScan(); - // Periodically request a scan while this UI is open. - base::MessageLoopForUI::current()->PostDelayedTask( - FROM_HERE, - base::Bind(&NetworkStateListDetailedView::CallRequestScan, AsWeakPtr()), - base::TimeDelta::FromSeconds(kRequestScanDelaySeconds)); -} - -void NetworkStateListDetailedView::ToggleMobile() { - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - bool enabled = - handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()); - ash::network_connect::SetTechnologyEnabled(NetworkTypePattern::Mobile(), - !enabled); -} - -} // namespace tray -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/network/network_state_list_detailed_view.h b/chromium/ash/system/chromeos/network/network_state_list_detailed_view.h deleted file mode 100644 index 4ad41638c16..00000000000 --- a/chromium/ash/system/chromeos/network/network_state_list_detailed_view.h +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_LIST_DETAILED_VIEW_H -#define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_LIST_DETAILED_VIEW_H - -#include <map> -#include <string> -#include <vector> - -#include "ash/system/chromeos/network/network_detailed_view.h" -#include "ash/system/chromeos/network/network_icon.h" -#include "ash/system/chromeos/network/network_icon_animation_observer.h" -#include "ash/system/tray/view_click_listener.h" -#include "ash/system/user/login_status.h" -#include "base/memory/scoped_vector.h" -#include "base/memory/weak_ptr.h" -#include "ui/views/controls/button/button.h" - -namespace chromeos { -class NetworkTypePattern; -} - -namespace views { -class BubbleDelegateView; -} - -namespace ash { - -class SystemTrayItem; - -namespace internal { - -class HoverHighlightView; -class TrayPopupLabelButton; - -namespace tray { - -struct NetworkInfo; - -class NetworkStateListDetailedView - : public NetworkDetailedView, - public views::ButtonListener, - public ViewClickListener, - public network_icon::AnimationObserver, - public base::SupportsWeakPtr<NetworkStateListDetailedView> { - public: - enum ListType { - LIST_TYPE_NETWORK, - LIST_TYPE_DEBUG_PREFERRED, - LIST_TYPE_VPN - }; - - NetworkStateListDetailedView(SystemTrayItem* owner, - ListType list_type, - user::LoginStatus login); - virtual ~NetworkStateListDetailedView(); - - // Overridden from NetworkDetailedView: - virtual void Init() OVERRIDE; - virtual DetailedViewType GetViewType() const OVERRIDE; - virtual void ManagerChanged() OVERRIDE; - virtual void NetworkListChanged() OVERRIDE; - virtual void NetworkServiceChanged( - const chromeos::NetworkState* network) OVERRIDE; - - // network_icon::AnimationObserver overrides - virtual void NetworkIconChanged() OVERRIDE; - - protected: - // Overridden from ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE; - - // Overridden from ViewClickListener. - virtual void OnViewClicked(views::View* sender) OVERRIDE; - - private: - class InfoBubble; - - typedef std::map<views::View*, std::string> NetworkMap; - typedef std::map<std::string, HoverHighlightView*> ServicePathMap; - - // Create UI components. - void CreateHeaderEntry(); - void CreateHeaderButtons(); - void CreateNetworkExtra(); - - // Update UI components. - void UpdateHeaderButtons(); - void UpdateTechnologyButton(TrayPopupHeaderButton* button, - const chromeos::NetworkTypePattern& technology); - - void UpdateNetworks( - const chromeos::NetworkStateHandler::NetworkStateList& networks); - void UpdatePreferred( - const chromeos::NetworkStateHandler::FavoriteStateList& favorites); - void UpdateNetworkList(); - bool CreateOrUpdateInfoLabel( - int index, const base::string16& text, views::Label** label); - bool UpdateNetworkChild(int index, const NetworkInfo* info); - bool OrderChild(views::View* view, int index); - bool UpdateNetworkListEntries(std::set<std::string>* new_service_paths); - void UpdateNetworkExtra(); - - // Adds a settings entry when logged in, and an entry for changing proxy - // settings otherwise. - void CreateSettingsEntry(); - - // Create and manage the network info bubble. - void ToggleInfoBubble(); - bool ResetInfoBubble(); - void OnInfoBubbleDestroyed(); - views::View* CreateNetworkInfoView(); - - // Periodically request a network scan. - void CallRequestScan(); - - // Handle toggile mobile action - void ToggleMobile(); - - // Type of list (all networks or vpn) - ListType list_type_; - - // Track login state. - user::LoginStatus login_; - - // A map of child views to their network service path. - NetworkMap network_map_; - - // A map of network service paths to their view. - ServicePathMap service_path_map_; - - // An owned list of network info. - ScopedVector<NetworkInfo> network_list_; - - // Child views. - TrayPopupHeaderButton* info_icon_; - TrayPopupHeaderButton* button_wifi_; - TrayPopupHeaderButton* button_mobile_; - TrayPopupLabelButton* other_wifi_; - TrayPopupLabelButton* turn_on_wifi_; - TrayPopupLabelButton* other_mobile_; - TrayPopupLabelButton* other_vpn_; - TrayPopupLabelButton* toggle_debug_preferred_networks_; - TrayPopupLabelButton* settings_; - TrayPopupLabelButton* proxy_settings_; - views::Label* scanning_view_; - views::Label* no_wifi_networks_view_; - views::Label* no_cellular_networks_view_; - - // A small bubble for displaying network info. - views::BubbleDelegateView* info_bubble_; - - DISALLOW_COPY_AND_ASSIGN(NetworkStateListDetailedView); -}; - -} // namespace tray -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_LIST_DETAILED_VIEW diff --git a/chromium/ash/system/chromeos/network/network_state_notifier.cc b/chromium/ash/system/chromeos/network/network_state_notifier.cc deleted file mode 100644 index ac69a8ab559..00000000000 --- a/chromium/ash/system/chromeos/network/network_state_notifier.cc +++ /dev/null @@ -1,288 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/network/network_state_notifier.h" - -#include "ash/shell.h" -#include "ash/system/chromeos/network/network_connect.h" -#include "ash/system/system_notifier.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "base/strings/string16.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "chromeos/network/network_configuration_handler.h" -#include "chromeos/network/network_connection_handler.h" -#include "chromeos/network/network_event_log.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" -#include "chromeos/network/shill_property_util.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "third_party/cros_system_api/dbus/service_constants.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" - -using chromeos::NetworkConnectionHandler; -using chromeos::NetworkHandler; -using chromeos::NetworkState; -using chromeos::NetworkStateHandler; -using chromeos::NetworkTypePattern; - -namespace { - -const char kNetworkOutOfCreditsNotificationId[] = - "chrome://settings/internet/out-of-credits"; - -const int kMinTimeBetweenOutOfCreditsNotifySeconds = 10 * 60; - -// Error messages based on |error_name|, not network_state->error(). -string16 GetConnectErrorString(const std::string& error_name) { - if (error_name == NetworkConnectionHandler::kErrorNotFound) - return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED); - if (error_name == NetworkConnectionHandler::kErrorConfigureFailed) - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_CONFIGURE_FAILED); - if (error_name == ash::network_connect::kErrorActivateFailed) - return l10n_util::GetStringUTF16( - IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED); - return string16(); -} - -void ShowErrorNotification(const std::string& notification_id, - const std::string& network_type, - const base::string16& title, - const base::string16& message, - const base::Closure& callback) { - int icon_id = (network_type == shill::kTypeCellular) ? - IDR_AURA_UBER_TRAY_CELLULAR_NETWORK_FAILED : - IDR_AURA_UBER_TRAY_NETWORK_FAILED; - const gfx::Image& icon = - ui::ResourceBundle::GetSharedInstance().GetImageNamed(icon_id); - message_center::MessageCenter::Get()->AddNotification( - message_center::Notification::CreateSystemNotification( - notification_id, - title, - message, - icon, - ash::system_notifier::kNotifierNetworkError, - callback)); -} - -} // namespace - -namespace ash { - -NetworkStateNotifier::NetworkStateNotifier() - : did_show_out_of_credits_(false), - weak_ptr_factory_(this) { - if (!NetworkHandler::IsInitialized()) - return; - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - handler->AddObserver(this, FROM_HERE); - UpdateDefaultNetwork(handler->DefaultNetwork()); -} - -NetworkStateNotifier::~NetworkStateNotifier() { - if (!NetworkHandler::IsInitialized()) - return; - NetworkHandler::Get()->network_state_handler()->RemoveObserver( - this, FROM_HERE); -} - -void NetworkStateNotifier::DefaultNetworkChanged(const NetworkState* network) { - if (!UpdateDefaultNetwork(network)) - return; - // If the default network changes to another network, allow the out of - // credits notification to be shown again. A delay prevents the notification - // from being shown too frequently (see below). - if (network) - did_show_out_of_credits_ = false; -} - -void NetworkStateNotifier::NetworkPropertiesUpdated( - const NetworkState* network) { - if (network->type() != shill::kTypeCellular) - return; - UpdateCellularOutOfCredits(network); - UpdateCellularActivating(network); -} - -bool NetworkStateNotifier::UpdateDefaultNetwork(const NetworkState* network) { - std::string default_network_path; - if (network) - default_network_path = network->path(); - if (default_network_path != last_default_network_) { - last_default_network_ = default_network_path; - return true; - } - return false; -} - -void NetworkStateNotifier::UpdateCellularOutOfCredits( - const NetworkState* cellular) { - // Only display a notification if we are out of credits and have not already - // shown a notification (or have since connected to another network type). - if (!cellular->cellular_out_of_credits() || did_show_out_of_credits_) - return; - - // Only display a notification if not connected, connecting, or waiting to - // connect to another network. - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - const NetworkState* default_network = handler->DefaultNetwork(); - if (default_network && default_network != cellular) - return; - if (handler->ConnectingNetworkByType(NetworkTypePattern::NonVirtual()) || - NetworkHandler::Get()->network_connection_handler() - ->HasPendingConnectRequest()) - return; - - did_show_out_of_credits_ = true; - base::TimeDelta dtime = base::Time::Now() - out_of_credits_notify_time_; - if (dtime.InSeconds() > kMinTimeBetweenOutOfCreditsNotifySeconds) { - out_of_credits_notify_time_ = base::Time::Now(); - string16 error_msg = l10n_util::GetStringFUTF16( - IDS_NETWORK_OUT_OF_CREDITS_BODY, - UTF8ToUTF16(cellular->name())); - ShowErrorNotification( - kNetworkOutOfCreditsNotificationId, - cellular->type(), - l10n_util::GetStringUTF16(IDS_NETWORK_OUT_OF_CREDITS_TITLE), - error_msg, - base::Bind(&network_connect::ShowNetworkSettings, cellular->path())); - } -} - -void NetworkStateNotifier::UpdateCellularActivating( - const NetworkState* cellular) { - // Keep track of any activating cellular network. - std::string activation_state = cellular->activation_state(); - if (activation_state == shill::kActivationStateActivating) { - cellular_activating_.insert(cellular->path()); - return; - } - // Only display a notification if this network was activating and is now - // activated. - if (!cellular_activating_.count(cellular->path()) || - activation_state != shill::kActivationStateActivated) - return; - - cellular_activating_.erase(cellular->path()); - int icon_id; - if (cellular->network_technology() == shill::kNetworkTechnologyLte) - icon_id = IDR_AURA_UBER_TRAY_NOTIFICATION_LTE; - else - icon_id = IDR_AURA_UBER_TRAY_NOTIFICATION_3G; - const gfx::Image& icon = - ui::ResourceBundle::GetSharedInstance().GetImageNamed(icon_id); - message_center::MessageCenter::Get()->AddNotification( - message_center::Notification::CreateSystemNotification( - ash::network_connect::kNetworkActivateNotificationId, - l10n_util::GetStringUTF16(IDS_NETWORK_CELLULAR_ACTIVATED_TITLE), - l10n_util::GetStringFUTF16(IDS_NETWORK_CELLULAR_ACTIVATED, - UTF8ToUTF16((cellular->name()))), - icon, - system_notifier::kNotifierNetwork, - base::Bind(&ash::network_connect::ShowNetworkSettings, - cellular->path()))); -} - -void NetworkStateNotifier::ShowNetworkConnectError( - const std::string& error_name, - const std::string& shill_error, - const std::string& service_path) { - if (service_path.empty()) { - base::DictionaryValue shill_properties; - ShowConnectErrorNotification(error_name, shill_error, service_path, - shill_properties); - return; - } - // Get the up-to-date properties for the network and display the error. - NetworkHandler::Get()->network_configuration_handler()->GetProperties( - service_path, - base::Bind(&NetworkStateNotifier::ConnectErrorPropertiesSucceeded, - weak_ptr_factory_.GetWeakPtr(), error_name, shill_error), - base::Bind(&NetworkStateNotifier::ConnectErrorPropertiesFailed, - weak_ptr_factory_.GetWeakPtr(), error_name, shill_error, - service_path)); -} - -void NetworkStateNotifier::ConnectErrorPropertiesSucceeded( - const std::string& error_name, - const std::string& shill_error, - const std::string& service_path, - const base::DictionaryValue& shill_properties) { - ShowConnectErrorNotification(error_name, shill_error, service_path, - shill_properties); -} - -void NetworkStateNotifier::ConnectErrorPropertiesFailed( - const std::string& error_name, - const std::string& shill_error, - const std::string& service_path, - const std::string& shill_connect_error, - scoped_ptr<base::DictionaryValue> shill_error_data) { - base::DictionaryValue shill_properties; - ShowConnectErrorNotification(error_name, shill_error, service_path, - shill_properties); -} - -void NetworkStateNotifier::ShowConnectErrorNotification( - const std::string& error_name, - const std::string& shill_error, - const std::string& service_path, - const base::DictionaryValue& shill_properties) { - string16 error = GetConnectErrorString(error_name); - if (error.empty()) { - // Service.Error gets cleared shortly after State transitions to Failure, - // so rely on |shill_error| unless empty. - std::string network_error = shill_error; - if (network_error.empty()) { - shill_properties.GetStringWithoutPathExpansion( - shill::kErrorProperty, &network_error); - } - error = network_connect::ErrorString(network_error, service_path); - if (error.empty()) - error = l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); - } - NET_LOG_ERROR("Connect error notification: " + UTF16ToUTF8(error), - service_path); - - std::string network_name = - chromeos::shill_property_util::GetNameFromProperties(service_path, - shill_properties); - std::string network_error_details; - shill_properties.GetStringWithoutPathExpansion( - shill::kErrorDetailsProperty, &network_error_details); - - string16 error_msg; - if (!network_error_details.empty()) { - // network_name should't be empty if network_error_details is set. - error_msg = l10n_util::GetStringFUTF16( - IDS_NETWORK_CONNECTION_ERROR_MESSAGE_WITH_SERVER_MESSAGE, - UTF8ToUTF16(network_name), error, - UTF8ToUTF16(network_error_details)); - } else if (network_name.empty()) { - error_msg = l10n_util::GetStringFUTF16( - IDS_NETWORK_CONNECTION_ERROR_MESSAGE_NO_NAME, error); - } else { - error_msg = l10n_util::GetStringFUTF16( - IDS_NETWORK_CONNECTION_ERROR_MESSAGE, - UTF8ToUTF16(network_name), error); - } - - std::string network_type; - shill_properties.GetStringWithoutPathExpansion( - shill::kTypeProperty, &network_type); - - ShowErrorNotification( - network_connect::kNetworkConnectNotificationId, - network_type, - l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE), - error_msg, - base::Bind(&network_connect::ShowNetworkSettings, service_path)); -} - -} // namespace ash diff --git a/chromium/ash/system/chromeos/network/network_state_notifier.h b/chromium/ash/system/chromeos/network/network_state_notifier.h deleted file mode 100644 index 1a835bbbe9b..00000000000 --- a/chromium/ash/system/chromeos/network/network_state_notifier.h +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ -#define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ - -#include <set> - -#include "ash/ash_export.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "base/time/time.h" -#include "chromeos/network/network_state_handler_observer.h" - -namespace base { -class DictionaryValue; -} - -namespace chromeos { -class NetworkState; -} - -namespace ash { - -// This class has two purposes: -// 1. ShowNetworkConnectError() gets called after any user initiated connect -// failure. This will handle displaying an error notification. -// TODO(stevenjb): convert this class to use the new MessageCenter -// notification system. -// 2. It observes NetworkState changes to generate notifications when a -// Cellular network is out of credits. -class ASH_EXPORT NetworkStateNotifier : - public chromeos::NetworkStateHandlerObserver { - public: - NetworkStateNotifier(); - virtual ~NetworkStateNotifier(); - - // NetworkStateHandlerObserver - virtual void DefaultNetworkChanged( - const chromeos::NetworkState* network) OVERRIDE; - virtual void NetworkPropertiesUpdated( - const chromeos::NetworkState* network) OVERRIDE; - - // Show a connection error notification. If |error_name| matches an error - // defined in NetworkConnectionHandler for connect, configure, or activation - // failed, then the associated message is shown, otherwise |shill_error| - // is expected to contain Service.Error (which might get cleared before - // GetProperties returns). - void ShowNetworkConnectError(const std::string& error_name, - const std::string& shill_error, - const std::string& service_path); - - private: - void ConnectErrorPropertiesSucceeded( - const std::string& error_name, - const std::string& shill_error, - const std::string& service_path, - const base::DictionaryValue& shill_properties); - void ConnectErrorPropertiesFailed( - const std::string& error_name, - const std::string& shill_error, - const std::string& service_path, - const std::string& shill_connect_error, - scoped_ptr<base::DictionaryValue> shill_error_data); - void ShowConnectErrorNotification( - const std::string& error_name, - const std::string& shill_error, - const std::string& service_path, - const base::DictionaryValue& shill_properties); - - // Returns true if the default network changed. - bool UpdateDefaultNetwork(const chromeos::NetworkState* network); - - // Helper methods to update state and check for notifications. - void UpdateCellularOutOfCredits(const chromeos::NetworkState* cellular); - void UpdateCellularActivating(const chromeos::NetworkState* cellular); - - std::string last_default_network_; - bool did_show_out_of_credits_; - base::Time out_of_credits_notify_time_; - std::set<std::string> cellular_activating_; - base::WeakPtrFactory<NetworkStateNotifier> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier); -}; - -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ diff --git a/chromium/ash/system/chromeos/network/network_state_notifier_unittest.cc b/chromium/ash/system/chromeos/network/network_state_notifier_unittest.cc deleted file mode 100644 index 998db5aa366..00000000000 --- a/chromium/ash/system/chromeos/network/network_state_notifier_unittest.cc +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/network/network_state_notifier.h" - -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/system/chromeos/network/network_connect.h" -#include "ash/system/status_area_widget.h" -#include "ash/system/tray/system_tray.h" -#include "ash/test/ash_test_base.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/shill_device_client.h" -#include "chromeos/dbus/shill_service_client.h" -#include "chromeos/login/login_state.h" -#include "chromeos/network/network_handler.h" -#include "third_party/cros_system_api/dbus/service_constants.h" -#include "ui/message_center/message_center.h" - -namespace { - -ash::SystemTray* GetSystemTray() { - return ash::Shell::GetPrimaryRootWindowController()->shelf()-> - status_area_widget()->system_tray(); -} - -} // namespace - -using chromeos::DBusThreadManager; -using chromeos::ShillDeviceClient; -using chromeos::ShillServiceClient; - -namespace ash { -namespace test { - -class NetworkStateNotifierTest : public AshTestBase { - public: - NetworkStateNotifierTest() {} - virtual ~NetworkStateNotifierTest() {} - - virtual void SetUp() OVERRIDE { - DBusThreadManager::InitializeWithStub(); - chromeos::LoginState::Initialize(); - SetupDefaultShillState(); - chromeos::NetworkHandler::Initialize(); - RunAllPendingInMessageLoop(); - AshTestBase::SetUp(); - } - - virtual void TearDown() OVERRIDE { - AshTestBase::TearDown(); - chromeos::LoginState::Shutdown(); - chromeos::NetworkHandler::Shutdown(); - DBusThreadManager::Shutdown(); - } - - protected: - void SetupDefaultShillState() { - RunAllPendingInMessageLoop(); - ShillDeviceClient::TestInterface* device_test = - DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); - device_test->ClearDevices(); - device_test->AddDevice("/device/stub_wifi_device1", - shill::kTypeWifi, "stub_wifi_device1"); - device_test->AddDevice("/device/stub_cellular_device1", - shill::kTypeCellular, "stub_cellular_device1"); - - ShillServiceClient::TestInterface* service_test = - DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); - service_test->ClearServices(); - const bool add_to_watchlist = true; - const bool add_to_visible = true; - // Create wifi and cellular networks and set to online. - service_test->AddService("wifi1", "wifi1", - shill::kTypeWifi, shill::kStateIdle, - add_to_visible, add_to_watchlist); - service_test->SetServiceProperty("wifi1", - shill::kSecurityProperty, - base::StringValue(shill::kSecurityWep)); - service_test->SetServiceProperty("wifi1", - shill::kConnectableProperty, - base::FundamentalValue(true)); - service_test->SetServiceProperty("wifi1", - shill::kPassphraseProperty, - base::StringValue("failure")); - RunAllPendingInMessageLoop(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest); -}; - -TEST_F(NetworkStateNotifierTest, ConnectionFailure) { - EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); - ash::network_connect::ConnectToNetwork("wifi1", NULL /* owning_window */); - RunAllPendingInMessageLoop(); - // Failure should spawn a notification. - message_center::MessageCenter* message_center = - message_center::MessageCenter::Get(); - EXPECT_TRUE(message_center->HasNotification( - network_connect::kNetworkConnectNotificationId)); -} - -} // namespace test -} // namespace ash diff --git a/chromium/ash/system/chromeos/network/tray_network.cc b/chromium/ash/system/chromeos/network/tray_network.cc deleted file mode 100644 index 4d2c82a2181..00000000000 --- a/chromium/ash/system/chromeos/network/tray_network.cc +++ /dev/null @@ -1,367 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/network/tray_network.h" - -#include "ash/ash_switches.h" -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/shell.h" -#include "ash/system/chromeos/network/network_icon_animation.h" -#include "ash/system/chromeos/network/network_state_list_detailed_view.h" -#include "ash/system/chromeos/network/tray_network_state_observer.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_item_more.h" -#include "ash/system/tray/tray_item_view.h" -#include "ash/system/tray/tray_utils.h" -#include "base/command_line.h" -#include "base/strings/utf_string_conversions.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" -#include "chromeos/network/shill_property_util.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "third_party/cros_system_api/dbus/service_constants.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/link.h" -#include "ui/views/controls/link_listener.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/widget/widget.h" - -using chromeos::NetworkHandler; -using chromeos::NetworkState; -using chromeos::NetworkStateHandler; -using chromeos::NetworkTypePattern; - -namespace ash { -namespace internal { - -namespace tray { - -class NetworkTrayView : public TrayItemView, - public network_icon::AnimationObserver { - public: - explicit NetworkTrayView(TrayNetwork* network_tray) - : TrayItemView(network_tray), - network_tray_(network_tray) { - SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); - - image_view_ = new views::ImageView; - AddChildView(image_view_); - - UpdateNetworkStateHandlerIcon(); - } - - virtual ~NetworkTrayView() { - network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); - } - - virtual const char* GetClassName() const OVERRIDE { - return "NetworkTrayView"; - } - - void UpdateNetworkStateHandlerIcon() { - NetworkStateHandler* handler = - NetworkHandler::Get()->network_state_handler(); - gfx::ImageSkia image; - base::string16 name; - bool animating = false; - network_icon::GetDefaultNetworkImageAndLabel( - network_icon::ICON_TYPE_TRAY, &image, &name, &animating); - bool show_in_tray = !image.isNull(); - UpdateIcon(show_in_tray, image); - if (animating) - network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); - else - network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); - // Update accessibility. - const NetworkState* connected_network = - handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); - if (connected_network) - UpdateConnectionStatus(UTF8ToUTF16(connected_network->name()), true); - else - UpdateConnectionStatus(base::string16(), false); - } - - void UpdateAlignment(ShelfAlignment alignment) { - SetLayoutManager(new views::BoxLayout( - alignment == SHELF_ALIGNMENT_BOTTOM ? - views::BoxLayout::kHorizontal : views::BoxLayout::kVertical, - 0, 0, 0)); - Layout(); - } - - // views::View override. - virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE { - state->name = connection_status_string_; - state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; - } - - // network_icon::AnimationObserver - virtual void NetworkIconChanged() OVERRIDE { - UpdateNetworkStateHandlerIcon(); - } - - private: - // Updates connection status and notifies accessibility event when necessary. - void UpdateConnectionStatus(const base::string16& network_name, - bool connected) { - base::string16 new_connection_status_string; - if (connected) { - new_connection_status_string = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, network_name); - } - if (new_connection_status_string != connection_status_string_) { - connection_status_string_ = new_connection_status_string; - if(!connection_status_string_.empty()) - NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); - } - } - - void UpdateIcon(bool tray_icon_visible, const gfx::ImageSkia& image) { - image_view_->SetImage(image); - SetVisible(tray_icon_visible); - SchedulePaint(); - } - - TrayNetwork* network_tray_; - views::ImageView* image_view_; - base::string16 connection_status_string_; - - DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); -}; - -class NetworkDefaultView : public TrayItemMore, - public network_icon::AnimationObserver { - public: - NetworkDefaultView(TrayNetwork* network_tray, bool show_more) - : TrayItemMore(network_tray, show_more), - network_tray_(network_tray) { - Update(); - } - - virtual ~NetworkDefaultView() { - network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); - } - - void Update() { - gfx::ImageSkia image; - base::string16 label; - bool animating = false; - network_icon::GetDefaultNetworkImageAndLabel( - network_icon::ICON_TYPE_DEFAULT_VIEW, &image, &label, &animating); - if (animating) - network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); - else - network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); - SetImage(&image); - SetLabel(label); - SetAccessibleName(label); - } - - // network_icon::AnimationObserver - virtual void NetworkIconChanged() OVERRIDE { - Update(); - } - - private: - TrayNetwork* network_tray_; - - DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); -}; - -class NetworkWifiDetailedView : public NetworkDetailedView { - public: - explicit NetworkWifiDetailedView(SystemTrayItem* owner) - : NetworkDetailedView(owner) { - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, - kTrayPopupPaddingHorizontal, - 10, - kTrayPopupPaddingBetweenItems)); - image_view_ = new views::ImageView; - AddChildView(image_view_); - - label_view_ = new views::Label(); - label_view_->SetMultiLine(true); - label_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - AddChildView(label_view_); - - Update(); - } - - virtual ~NetworkWifiDetailedView() { - } - - // Overridden from NetworkDetailedView: - - virtual void Init() OVERRIDE { - } - - virtual NetworkDetailedView::DetailedViewType GetViewType() const OVERRIDE { - return NetworkDetailedView::WIFI_VIEW; - } - - virtual void ManagerChanged() OVERRIDE { - Update(); - } - - virtual void NetworkListChanged() OVERRIDE { - Update(); - } - - virtual void NetworkServiceChanged( - const chromeos::NetworkState* network) OVERRIDE { - } - - private: - virtual void Layout() OVERRIDE { - // Center both views vertically. - views::View::Layout(); - image_view_->SetY( - (height() - image_view_->GetPreferredSize().height()) / 2); - label_view_->SetY( - (height() - label_view_->GetPreferredSize().height()) / 2); - } - - void Update() { - bool wifi_enabled = - NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled( - NetworkTypePattern::WiFi()); - const int image_id = wifi_enabled ? - IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED; - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - image_view_->SetImage(bundle.GetImageNamed(image_id).ToImageSkia()); - - const int string_id = wifi_enabled ? - IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED : - IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; - label_view_->SetText(bundle.GetLocalizedString(string_id)); - label_view_->SizeToFit(kTrayPopupMinWidth - - kTrayPopupPaddingHorizontal * 2 - kTrayPopupPaddingBetweenItems - - kTrayPopupDetailsIconWidth); - } - - views::ImageView* image_view_; - views::Label* label_view_; - - DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); -}; - -} // namespace tray - -TrayNetwork::TrayNetwork(SystemTray* system_tray) - : SystemTrayItem(system_tray), - tray_(NULL), - default_(NULL), - detailed_(NULL), - request_wifi_view_(false) { - network_state_observer_.reset(new TrayNetworkStateObserver(this)); - Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); -} - -TrayNetwork::~TrayNetwork() { - Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); -} - -views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { - CHECK(tray_ == NULL); - if (!chromeos::NetworkHandler::IsInitialized()) - return NULL; - tray_ = new tray::NetworkTrayView(this); - return tray_; -} - -views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { - CHECK(default_ == NULL); - if (!chromeos::NetworkHandler::IsInitialized()) - return NULL; - CHECK(tray_ != NULL); - default_ = new tray::NetworkDefaultView( - this, status != user::LOGGED_IN_LOCKED); - return default_; -} - -views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { - CHECK(detailed_ == NULL); - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW); - if (!chromeos::NetworkHandler::IsInitialized()) - return NULL; - if (request_wifi_view_) { - detailed_ = new tray::NetworkWifiDetailedView(this); - request_wifi_view_ = false; - } else { - detailed_ = new tray::NetworkStateListDetailedView( - this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status); - detailed_->Init(); - } - return detailed_; -} - -void TrayNetwork::DestroyTrayView() { - tray_ = NULL; -} - -void TrayNetwork::DestroyDefaultView() { - default_ = NULL; -} - -void TrayNetwork::DestroyDetailedView() { - detailed_ = NULL; -} - -void TrayNetwork::UpdateAfterLoginStatusChange(user::LoginStatus status) { -} - -void TrayNetwork::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { - if (tray_) { - SetTrayImageItemBorder(tray_, alignment); - tray_->UpdateAlignment(alignment); - } -} - -void TrayNetwork::RequestToggleWifi() { - // This will always be triggered by a user action (e.g. keyboard shortcut) - if (!detailed_ || - detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { - request_wifi_view_ = true; - PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); - } - NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); - bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()); - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - enabled ? - ash::UMA_STATUS_AREA_DISABLE_WIFI : - ash::UMA_STATUS_AREA_ENABLE_WIFI); - handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), - !enabled, - chromeos::network_handler::ErrorCallback()); -} - -void TrayNetwork::NetworkStateChanged(bool list_changed) { - if (tray_) - tray_->UpdateNetworkStateHandlerIcon(); - if (default_) - default_->Update(); - if (detailed_) { - if (list_changed) - detailed_->NetworkListChanged(); - else - detailed_->ManagerChanged(); - } -} - -void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) { - if (detailed_) - detailed_->NetworkServiceChanged(network); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/network/tray_network.h b/chromium/ash/system/chromeos/network/tray_network.h deleted file mode 100644 index 240c5c1a669..00000000000 --- a/chromium/ash/system/chromeos/network/tray_network.h +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_NETWORK_H -#define ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_NETWORK_H - -#include <set> - -#include "ash/system/chromeos/network/network_icon.h" -#include "ash/system/chromeos/network/network_observer.h" -#include "ash/system/chromeos/network/tray_network_state_observer.h" -#include "ash/system/tray/system_tray_item.h" -#include "base/memory/scoped_ptr.h" -#include "base/time/time.h" - -namespace chromeos { -class NetworkState; -} - -namespace ash { -namespace internal { - -namespace tray { -class NetworkDefaultView; -class NetworkDetailedView; -class NetworkTrayView; -} - -class TrayNetwork : public SystemTrayItem, - public NetworkObserver, - public TrayNetworkStateObserver::Delegate { - public: - explicit TrayNetwork(SystemTray* system_tray); - virtual ~TrayNetwork(); - - tray::NetworkDetailedView* detailed() { return detailed_; } - - // SystemTrayItem - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) OVERRIDE; - - // NetworkObserver - virtual void RequestToggleWifi() OVERRIDE; - - // TrayNetworkStateObserver::Delegate - virtual void NetworkStateChanged(bool list_changed) OVERRIDE; - virtual void NetworkServiceChanged( - const chromeos::NetworkState* network) OVERRIDE; - - private: - tray::NetworkTrayView* tray_; - tray::NetworkDefaultView* default_; - tray::NetworkDetailedView* detailed_; - bool request_wifi_view_; - scoped_ptr<TrayNetworkStateObserver> network_state_observer_; - - DISALLOW_COPY_AND_ASSIGN(TrayNetwork); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_NETWORK_H diff --git a/chromium/ash/system/chromeos/network/tray_network_state_observer.cc b/chromium/ash/system/chromeos/network/tray_network_state_observer.cc deleted file mode 100644 index d090762a190..00000000000 --- a/chromium/ash/system/chromeos/network/tray_network_state_observer.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/network/tray_network_state_observer.h" - -#include <set> -#include <string> - -#include "ash/system/chromeos/network/network_icon.h" -#include "base/location.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" -#include "third_party/cros_system_api/dbus/service_constants.h" - -using chromeos::NetworkHandler; - -namespace ash { -namespace internal { - -TrayNetworkStateObserver::TrayNetworkStateObserver(Delegate* delegate) - : delegate_(delegate) { - if (NetworkHandler::IsInitialized()) { - NetworkHandler::Get()->network_state_handler()->AddObserver( - this, FROM_HERE); - } -} - -TrayNetworkStateObserver::~TrayNetworkStateObserver() { - if (NetworkHandler::IsInitialized()) { - NetworkHandler::Get()->network_state_handler()->RemoveObserver( - this, FROM_HERE); - } -} - -void TrayNetworkStateObserver::NetworkListChanged() { - delegate_->NetworkStateChanged(true); - network_icon::PurgeNetworkIconCache(); -} - -void TrayNetworkStateObserver::DeviceListChanged() { - delegate_->NetworkStateChanged(false); -} - -void TrayNetworkStateObserver::DefaultNetworkChanged( - const chromeos::NetworkState* network) { - delegate_->NetworkStateChanged(true); -} - -void TrayNetworkStateObserver::NetworkPropertiesUpdated( - const chromeos::NetworkState* network) { - if (network == - NetworkHandler::Get()->network_state_handler()->DefaultNetwork()) - delegate_->NetworkStateChanged(true); - delegate_->NetworkServiceChanged(network); -} - -} // namespace ash -} // namespace internal diff --git a/chromium/ash/system/chromeos/network/tray_network_state_observer.h b/chromium/ash/system/chromeos/network/tray_network_state_observer.h deleted file mode 100644 index e2f47d10255..00000000000 --- a/chromium/ash/system/chromeos/network/tray_network_state_observer.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_NETWORK_STATE_OBSERVER_H -#define ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_NETWORK_STATE_OBSERVER_H - -#include <string> - -#include "base/compiler_specific.h" -#include "chromeos/network/network_state_handler_observer.h" - -namespace ash { -namespace internal { - -class TrayNetworkStateObserver : public chromeos::NetworkStateHandlerObserver { - public: - class Delegate { - public: - // Called when the network state may have changed. If |list_changed| is - // true then the list of networks may have changed. - virtual void NetworkStateChanged(bool list_changed) = 0; - - // Called when the properties for |network| may have been updated. - virtual void NetworkServiceChanged( - const chromeos::NetworkState* network) = 0; - - protected: - virtual ~Delegate() {} - }; - - explicit TrayNetworkStateObserver(Delegate* delegate); - - virtual ~TrayNetworkStateObserver(); - - // NetworkStateHandlerObserver overrides. - virtual void NetworkListChanged() OVERRIDE; - virtual void DeviceListChanged() OVERRIDE; - virtual void DefaultNetworkChanged( - const chromeos::NetworkState* network) OVERRIDE; - virtual void NetworkPropertiesUpdated( - const chromeos::NetworkState* network) OVERRIDE; - - private: - Delegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(TrayNetworkStateObserver); -}; - -} // namespace ash -} // namespace internal - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_NETWORK_STATE_OBSERVER_H diff --git a/chromium/ash/system/chromeos/network/tray_sms.cc b/chromium/ash/system/chromeos/network/tray_sms.cc deleted file mode 100644 index 7b00c276e74..00000000000 --- a/chromium/ash/system/chromeos/network/tray_sms.cc +++ /dev/null @@ -1,420 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/network/tray_sms.h" - -#include "ash/shell.h" -#include "ash/system/tray/fixed_sized_scroll_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_bubble.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_details_view.h" -#include "ash/system/tray/tray_item_more.h" -#include "ash/system/tray/tray_item_view.h" -#include "ash/system/tray/tray_notification_view.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "chromeos/network/network_event_log.h" -#include "chromeos/network/network_handler.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/views/bubble/tray_bubble_view.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/layout/grid_layout.h" -#include "ui/views/view.h" - -namespace { - -// Min height of the list of messages in the popup. -const int kMessageListMinHeight = 200; -// Top/bottom padding of the text items. -const int kPaddingVertical = 10; - -const char kSmsNumberKey[] = "number"; -const char kSmsTextKey[] = "text"; - -bool GetMessageFromDictionary(const base::DictionaryValue* message, - std::string* number, - std::string* text) { - if (!message->GetStringWithoutPathExpansion(kSmsNumberKey, number)) - return false; - if (!message->GetStringWithoutPathExpansion(kSmsTextKey, text)) - return false; - return true; -} - -} // namespace - -namespace ash { -namespace internal { - -class TraySms::SmsDefaultView : public TrayItemMore { - public: - explicit SmsDefaultView(TraySms* owner) - : TrayItemMore(owner, true) { - SetImage(ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_SMS)); - Update(); - } - - virtual ~SmsDefaultView() {} - - void Update() { - int message_count = static_cast<TraySms*>(owner())->messages().GetSize(); - base::string16 label = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_SMS_MESSAGES, base::IntToString16(message_count)); - SetLabel(label); - SetAccessibleName(label); - } - - private: - DISALLOW_COPY_AND_ASSIGN(SmsDefaultView); -}; - -// An entry (row) in SmsDetailedView or NotificationView. -class TraySms::SmsMessageView : public views::View, - public views::ButtonListener { - public: - enum ViewType { - VIEW_DETAILED, - VIEW_NOTIFICATION - }; - - SmsMessageView(TraySms* owner, - ViewType view_type, - size_t index, - const std::string& number, - const std::string& message) - : owner_(owner), - index_(index) { - number_label_ = new views::Label( - l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_SMS_NUMBER, - UTF8ToUTF16(number))); - number_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - number_label_->SetFont( - number_label_->font().DeriveFont(0, gfx::Font::BOLD)); - - message_label_ = new views::Label(UTF8ToUTF16(message)); - message_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - message_label_->SetMultiLine(true); - - if (view_type == VIEW_DETAILED) - LayoutDetailedView(); - else - LayoutNotificationView(); - } - - virtual ~SmsMessageView() { - } - - // Overridden from ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE { - owner_->RemoveMessage(index_); - owner_->Update(false); - } - - private: - void LayoutDetailedView() { - views::ImageButton* close_button = new views::ImageButton(this); - close_button->SetImage(views::CustomButton::STATE_NORMAL, - ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_AURA_WINDOW_CLOSE)); - const int msg_width = owner_->system_tray()->GetSystemBubble()-> - bubble_view()->GetPreferredSize().width() - - (kNotificationIconWidth + kTrayPopupPaddingHorizontal * 2); - message_label_->SizeToFit(msg_width); - - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); - - views::ColumnSet* columns = layout->AddColumnSet(0); - - // Message - columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal); - columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, - 0 /* resize percent */, - views::GridLayout::FIXED, msg_width, msg_width); - - // Close button - columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, - 0, /* resize percent */ - views::GridLayout::FIXED, - kNotificationIconWidth, kNotificationIconWidth); - - - layout->AddPaddingRow(0, kPaddingVertical); - layout->StartRow(0, 0); - layout->AddView(number_label_); - layout->AddView(close_button, 1, 2); // 2 rows for icon - layout->StartRow(0, 0); - layout->AddView(message_label_); - - layout->AddPaddingRow(0, kPaddingVertical); - } - - void LayoutNotificationView() { - SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); - AddChildView(number_label_); - message_label_->SizeToFit(kTrayNotificationContentsWidth); - AddChildView(message_label_); - } - - TraySms* owner_; - size_t index_; - views::Label* number_label_; - views::Label* message_label_; - - DISALLOW_COPY_AND_ASSIGN(SmsMessageView); -}; - -class TraySms::SmsDetailedView : public TrayDetailsView, - public ViewClickListener { - public: - explicit SmsDetailedView(TraySms* owner) - : TrayDetailsView(owner) { - Init(); - Update(); - } - - virtual ~SmsDetailedView() { - } - - void Init() { - CreateScrollableList(); - CreateSpecialRow(IDS_ASH_STATUS_TRAY_SMS, this); - } - - void Update() { - UpdateMessageList(); - Layout(); - SchedulePaint(); - } - - // Overridden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE { - gfx::Size preferred_size = TrayDetailsView::GetPreferredSize(); - if (preferred_size.height() < kMessageListMinHeight) - preferred_size.set_height(kMessageListMinHeight); - return preferred_size; - } - - private: - void UpdateMessageList() { - const base::ListValue& messages = - static_cast<TraySms*>(owner())->messages(); - scroll_content()->RemoveAllChildViews(true); - for (size_t index = 0; index < messages.GetSize(); ++index) { - const base::DictionaryValue* message = NULL; - if (!messages.GetDictionary(index, &message)) { - LOG(ERROR) << "SMS message not a dictionary at: " << index; - continue; - } - std::string number, text; - if (!GetMessageFromDictionary(message, &number, &text)) { - LOG(ERROR) << "Error parsing SMS message"; - continue; - } - SmsMessageView* msgview = new SmsMessageView( - static_cast<TraySms*>(owner()), SmsMessageView::VIEW_DETAILED, index, - number, text); - scroll_content()->AddChildView(msgview); - } - scroller()->Layout(); - } - - // Overridden from ViewClickListener. - virtual void OnViewClicked(views::View* sender) OVERRIDE { - if (sender == footer()->content()) - TransitionToDefaultView(); - } - - DISALLOW_COPY_AND_ASSIGN(SmsDetailedView); -}; - -class TraySms::SmsNotificationView : public TrayNotificationView { - public: - SmsNotificationView(TraySms* owner, - size_t message_index, - const std::string& number, - const std::string& text) - : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_SMS), - message_index_(message_index) { - SmsMessageView* message_view = new SmsMessageView( - owner, SmsMessageView::VIEW_NOTIFICATION, message_index_, number, text); - InitView(message_view); - } - - void Update(size_t message_index, - const std::string& number, - const std::string& text) { - SmsMessageView* message_view = new SmsMessageView( - tray_sms(), SmsMessageView::VIEW_NOTIFICATION, - message_index_, number, text); - UpdateView(message_view); - } - - // Overridden from TrayNotificationView: - virtual void OnClose() OVERRIDE { - tray_sms()->RemoveMessage(message_index_); - } - - virtual void OnClickAction() OVERRIDE { - owner()->PopupDetailedView(0, true); - } - - private: - TraySms* tray_sms() { - return static_cast<TraySms*>(owner()); - } - - size_t message_index_; - - DISALLOW_COPY_AND_ASSIGN(SmsNotificationView); -}; - -TraySms::TraySms(SystemTray* system_tray) - : SystemTrayItem(system_tray), - default_(NULL), - detailed_(NULL), - notification_(NULL) { - // TODO(armansito): SMS could be a special case for cellular that requires a - // user (perhaps the owner) to be logged in. If that is the case, then an - // additional check should be done before subscribing for SMS notifications. - if (chromeos::NetworkHandler::IsInitialized()) - chromeos::NetworkHandler::Get()->network_sms_handler()->AddObserver(this); -} - -TraySms::~TraySms() { - if (chromeos::NetworkHandler::IsInitialized()) { - chromeos::NetworkHandler::Get()->network_sms_handler()->RemoveObserver( - this); - } -} - -views::View* TraySms::CreateDefaultView(user::LoginStatus status) { - CHECK(default_ == NULL); - default_ = new SmsDefaultView(this); - default_->SetVisible(!messages_.empty()); - return default_; -} - -views::View* TraySms::CreateDetailedView(user::LoginStatus status) { - CHECK(detailed_ == NULL); - HideNotificationView(); - if (messages_.empty()) - return NULL; - detailed_ = new SmsDetailedView(this); - return detailed_; -} - -views::View* TraySms::CreateNotificationView(user::LoginStatus status) { - CHECK(notification_ == NULL); - if (detailed_) - return NULL; - size_t index; - std::string number, text; - if (GetLatestMessage(&index, &number, &text)) - notification_ = new SmsNotificationView(this, index, number, text); - return notification_; -} - -void TraySms::DestroyDefaultView() { - default_ = NULL; -} - -void TraySms::DestroyDetailedView() { - detailed_ = NULL; -} - -void TraySms::DestroyNotificationView() { - notification_ = NULL; -} - -void TraySms::MessageReceived(const base::DictionaryValue& message) { - - std::string message_text; - if (!message.GetStringWithoutPathExpansion( - chromeos::NetworkSmsHandler::kTextKey, &message_text)) { - NET_LOG_ERROR("SMS message contains no content.", ""); - return; - } - // TODO(armansito): A message might be due to a special "Message Waiting" - // state that the message is in. Once SMS handling moves to shill, such - // messages should be filtered there so that this check becomes unnecessary. - if (message_text.empty()) { - NET_LOG_DEBUG("SMS has empty content text. Ignoring.", ""); - return; - } - std::string message_number; - if (!message.GetStringWithoutPathExpansion( - chromeos::NetworkSmsHandler::kNumberKey, &message_number)) { - NET_LOG_DEBUG("SMS contains no number. Ignoring.", ""); - return; - } - - NET_LOG_DEBUG("Received SMS from: " + message_number + " with text: " + - message_text, ""); - - base::DictionaryValue* dict = new base::DictionaryValue(); - dict->SetString(kSmsNumberKey, message_number); - dict->SetString(kSmsTextKey, message_text); - messages_.Append(dict); - Update(true); -} - -bool TraySms::GetLatestMessage(size_t* index, - std::string* number, - std::string* text) { - if (messages_.empty()) - return false; - DictionaryValue* message; - size_t message_index = messages_.GetSize() - 1; - if (!messages_.GetDictionary(message_index, &message)) - return false; - if (!GetMessageFromDictionary(message, number, text)) - return false; - *index = message_index; - return true; -} - -void TraySms::RemoveMessage(size_t index) { - if (index < messages_.GetSize()) - messages_.Remove(index, NULL); -} - -void TraySms::Update(bool notify) { - if (messages_.empty()) { - if (default_) - default_->SetVisible(false); - if (detailed_) - HideDetailedView(); - HideNotificationView(); - } else { - if (default_) { - default_->SetVisible(true); - default_->Update(); - } - if (detailed_) - detailed_->Update(); - if (notification_) { - size_t index; - std::string number, text; - if (GetLatestMessage(&index, &number, &text)) - notification_->Update(index, number, text); - } else if (notify) { - ShowNotificationView(); - } - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/network/tray_sms.h b/chromium/ash/system/chromeos/network/tray_sms.h deleted file mode 100644 index 5a79360052a..00000000000 --- a/chromium/ash/system/chromeos/network/tray_sms.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_SMS_H -#define ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_SMS_H - -#include <string> - -#include "ash/system/tray/system_tray_item.h" -#include "base/values.h" -#include "chromeos/network/network_sms_handler.h" - -namespace ash { -namespace internal { - -class TraySms : public SystemTrayItem, - public chromeos::NetworkSmsHandler::Observer { - public: - explicit TraySms(SystemTray* system_tray); - virtual ~TraySms(); - - // Overridden from SystemTrayItem. - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateNotificationView( - user::LoginStatus status) OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void DestroyNotificationView() OVERRIDE; - - // Overridden from chromeos::NetworkSmsHandler::Observer. - virtual void MessageReceived(const base::DictionaryValue& message) OVERRIDE; - - protected: - class SmsDefaultView; - class SmsDetailedView; - class SmsMessageView; - class SmsNotificationView; - - // Gets the most recent message. Returns false if no messages or unable to - // retrieve the numebr and text from the message. - bool GetLatestMessage(size_t* index, std::string* number, std::string* text); - - // Removes message at |index| from message list. - void RemoveMessage(size_t index); - - // Called when sms messages have changed (through - // chromeos::NetworkSmsHandler::Observer). - void Update(bool notify); - - base::ListValue& messages() { return messages_; } - - private: - SmsDefaultView* default_; - SmsDetailedView* detailed_; - SmsNotificationView* notification_; - base::ListValue messages_; - - DISALLOW_COPY_AND_ASSIGN(TraySms); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_SMS_H diff --git a/chromium/ash/system/chromeos/network/tray_vpn.cc b/chromium/ash/system/chromeos/network/tray_vpn.cc deleted file mode 100644 index d150626568f..00000000000 --- a/chromium/ash/system/chromeos/network/tray_vpn.cc +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/network/tray_vpn.h" - -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/shell.h" -#include "ash/system/chromeos/network/network_icon_animation.h" -#include "ash/system/chromeos/network/network_state_list_detailed_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_item_more.h" -#include "ash/system/tray/tray_popup_label_button.h" -#include "chromeos/network/network_state.h" -#include "chromeos/network/network_state_handler.h" -#include "chromeos/network/shill_property_util.h" -#include "grit/ash_strings.h" -#include "third_party/cros_system_api/dbus/service_constants.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" - -using chromeos::NetworkHandler; -using chromeos::NetworkState; -using chromeos::NetworkStateHandler; -using chromeos::NetworkTypePattern; - -namespace ash { -namespace internal { - -namespace tray { - -class VpnDefaultView : public TrayItemMore, - public network_icon::AnimationObserver { - public: - VpnDefaultView(SystemTrayItem* owner, bool show_more) - : TrayItemMore(owner, show_more) { - Update(); - } - - virtual ~VpnDefaultView() { - network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); - } - - static bool ShouldShow() { - // Do not show VPN line in uber tray bubble if VPN is not configured. - NetworkStateHandler* handler = - NetworkHandler::Get()->network_state_handler(); - const NetworkState* vpn = - handler->FirstNetworkByType(NetworkTypePattern::VPN()); - return vpn != NULL; - } - - void Update() { - gfx::ImageSkia image; - base::string16 label; - bool animating = false; - GetNetworkStateHandlerImageAndLabel(&image, &label, &animating); - if (animating) - network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); - else - network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); - SetImage(&image); - SetLabel(label); - SetAccessibleName(label); - } - - // network_icon::AnimationObserver - virtual void NetworkIconChanged() OVERRIDE { - Update(); - } - - private: - void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, - base::string16* label, - bool* animating) { - NetworkStateHandler* handler = - NetworkHandler::Get()->network_state_handler(); - const NetworkState* vpn = - handler->FirstNetworkByType(NetworkTypePattern::VPN()); - if (!vpn || (vpn->connection_state() == shill::kStateIdle)) { - *image = network_icon::GetImageForDisconnectedNetwork( - network_icon::ICON_TYPE_DEFAULT_VIEW, shill::kTypeVPN); - if (label) { - *label = l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); - } - *animating = false; - return; - } - *animating = vpn->IsConnectingState(); - *image = network_icon::GetImageForNetwork( - vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); - if (label) { - *label = network_icon::GetLabelForNetwork( - vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); - } - } - - DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); -}; - -} // namespace tray - -TrayVPN::TrayVPN(SystemTray* system_tray) - : SystemTrayItem(system_tray), - default_(NULL), - detailed_(NULL) { - network_state_observer_.reset(new TrayNetworkStateObserver(this)); -} - -TrayVPN::~TrayVPN() { -} - -views::View* TrayVPN::CreateTrayView(user::LoginStatus status) { - return NULL; -} - -views::View* TrayVPN::CreateDefaultView(user::LoginStatus status) { - CHECK(default_ == NULL); - if (!chromeos::NetworkHandler::IsInitialized()) - return NULL; - if (status == user::LOGGED_IN_NONE) - return NULL; - if (!tray::VpnDefaultView::ShouldShow()) - return NULL; - - default_ = new tray::VpnDefaultView(this, status != user::LOGGED_IN_LOCKED); - return default_; -} - -views::View* TrayVPN::CreateDetailedView(user::LoginStatus status) { - CHECK(detailed_ == NULL); - if (!chromeos::NetworkHandler::IsInitialized()) - return NULL; - - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_DETAILED_VPN_VIEW); - detailed_ = new tray::NetworkStateListDetailedView( - this, tray::NetworkStateListDetailedView::LIST_TYPE_VPN, status); - detailed_->Init(); - return detailed_; -} - -void TrayVPN::DestroyTrayView() { -} - -void TrayVPN::DestroyDefaultView() { - default_ = NULL; -} - -void TrayVPN::DestroyDetailedView() { - detailed_ = NULL; -} - -void TrayVPN::UpdateAfterLoginStatusChange(user::LoginStatus status) { -} - -void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { -} - -void TrayVPN::NetworkStateChanged(bool list_changed) { - if (default_) - default_->Update(); - if (detailed_) { - if (list_changed) - detailed_->NetworkListChanged(); - else - detailed_->ManagerChanged(); - } -} - -void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) { - if (detailed_) - detailed_->NetworkServiceChanged(network); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/network/tray_vpn.h b/chromium/ash/system/chromeos/network/tray_vpn.h deleted file mode 100644 index 1d16e54618e..00000000000 --- a/chromium/ash/system/chromeos/network/tray_vpn.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_VPN_H -#define ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_VPN_H - -#include "ash/system/chromeos/network/tray_network_state_observer.h" -#include "ash/system/tray/system_tray_item.h" -#include "base/memory/scoped_ptr.h" - -namespace ash { -namespace internal { - -class TrayNetworkStateObserver; - -namespace tray { -class NetworkDetailedView; -class VpnDefaultView; -class VpnDetailedView; -} - -class TrayVPN : public SystemTrayItem, - public TrayNetworkStateObserver::Delegate { - public: - explicit TrayVPN(SystemTray* system_tray); - virtual ~TrayVPN(); - - // SystemTrayItem - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) OVERRIDE; - - // TrayNetworkStateObserver::Delegate - virtual void NetworkStateChanged(bool list_changed) OVERRIDE; - virtual void NetworkServiceChanged( - const chromeos::NetworkState* network) OVERRIDE; - - private: - tray::VpnDefaultView* default_; - tray::NetworkDetailedView* detailed_; - scoped_ptr<TrayNetworkStateObserver> network_state_observer_; - - DISALLOW_COPY_AND_ASSIGN(TrayVPN); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_VPN_H diff --git a/chromium/ash/system/chromeos/power/power_event_observer.cc b/chromium/ash/system/chromeos/power/power_event_observer.cc deleted file mode 100644 index c99ae50a6e0..00000000000 --- a/chromium/ash/system/chromeos/power/power_event_observer.cc +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/power/power_event_observer.h" - -#include "ash/session_state_delegate.h" -#include "ash/shell.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/wm/power_button_controller.h" -#include "ash/wm/user_activity_detector.h" -#include "base/prefs/pref_service.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/display/output_configurator.h" - -namespace ash { -namespace internal { - -PowerEventObserver::PowerEventObserver() - : screen_locked_(false) { - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - AddObserver(this); - chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> - AddObserver(this); -} - -PowerEventObserver::~PowerEventObserver() { - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - RemoveObserver(this); - chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> - RemoveObserver(this); -} - -void PowerEventObserver::BrightnessChanged(int level, bool user_initiated) { - Shell::GetInstance()->power_button_controller()->OnScreenBrightnessChanged( - static_cast<double>(level)); -} - -void PowerEventObserver::SuspendImminent() { - Shell* shell = Shell::GetInstance(); - SessionStateDelegate* delegate = shell->session_state_delegate(); - - // If the lock-before-suspending pref is set, get a callback to block - // suspend and ask the session manager to lock the screen. - if (!screen_locked_ && delegate->ShouldLockScreenBeforeSuspending() && - delegate->CanLockScreen()) { - screen_lock_callback_ = chromeos::DBusThreadManager::Get()-> - GetPowerManagerClient()->GetSuspendReadinessCallback(); - VLOG(1) << "Requesting screen lock from PowerEventObserver"; - chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> - RequestLockScreen(); - } - - shell->user_activity_detector()->OnDisplayPowerChanging(); - shell->output_configurator()->SuspendDisplays(); -} - -void PowerEventObserver::SystemResumed(const base::TimeDelta& sleep_duration) { - Shell::GetInstance()->output_configurator()->ResumeDisplays(); - Shell::GetInstance()->system_tray_notifier()->NotifyRefreshClock(); -} - -void PowerEventObserver::ScreenIsLocked() { - screen_locked_ = true; - - // Stop blocking suspend after the screen is locked. - if (!screen_lock_callback_.is_null()) { - VLOG(1) << "Screen locked due to suspend"; - // Run the callback asynchronously. ScreenIsLocked() is currently - // called asynchronously after RequestLockScreen(), but this guards - // against it being made synchronous later. - base::MessageLoop::current()->PostTask(FROM_HERE, screen_lock_callback_); - screen_lock_callback_.Reset(); - } else { - VLOG(1) << "Screen locked without suspend"; - } -} - -void PowerEventObserver::ScreenIsUnlocked() { - screen_locked_ = false; -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/power/power_event_observer.h b/chromium/ash/system/chromeos/power/power_event_observer.h deleted file mode 100644 index b35cb1beeeb..00000000000 --- a/chromium/ash/system/chromeos/power/power_event_observer.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_POWER_POWER_EVENT_OBSERVER_H_ -#define ASH_SYSTEM_CHROMEOS_POWER_POWER_EVENT_OBSERVER_H_ - -#include "ash/ash_export.h" -#include "base/basictypes.h" -#include "base/callback.h" -#include "base/compiler_specific.h" -#include "chromeos/dbus/power_manager_client.h" -#include "chromeos/dbus/session_manager_client.h" - -namespace ash { -namespace internal { - -// A class that observes power-management-related events. -class ASH_EXPORT PowerEventObserver - : public chromeos::PowerManagerClient::Observer, - public chromeos::SessionManagerClient::Observer { - public: - // This class registers/unregisters itself as an observer in ctor/dtor. - PowerEventObserver(); - virtual ~PowerEventObserver(); - - // chromeos::PowerManagerClient::Observer overrides: - virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE; - virtual void SuspendImminent() OVERRIDE; - virtual void SystemResumed(const base::TimeDelta& sleep_duration) OVERRIDE; - - // chromeos::SessionManagerClient::Observer overrides. - virtual void ScreenIsLocked() OVERRIDE; - virtual void ScreenIsUnlocked() OVERRIDE; - - // Is the screen currently locked? - bool screen_locked_; - - // If set, called when the lock screen has been shown to confirm that the - // system is ready to be suspended. - base::Closure screen_lock_callback_; - - private: - DISALLOW_COPY_AND_ASSIGN(PowerEventObserver); -}; - -} // namespace internal -} // namespace chromeos - -#endif // ASH_SYSTEM_CHROMEOS_POWER_POWER_EVENT_OBSERVER_H_ diff --git a/chromium/ash/system/chromeos/power/power_event_observer_unittest.cc b/chromium/ash/system/chromeos/power/power_event_observer_unittest.cc deleted file mode 100644 index a2282c3bb2c..00000000000 --- a/chromium/ash/system/chromeos/power/power_event_observer_unittest.cc +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/power/power_event_observer.h" - -#include "ash/test/ash_test_base.h" -#include "base/memory/scoped_ptr.h" -#include "base/time/time.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/power_manager_client.h" - -namespace ash { -namespace internal { - -class PowerEventObserverTest : public test::AshTestBase { - public: - PowerEventObserverTest() {} - virtual ~PowerEventObserverTest() {} - - // test::AshTestBase::SetUp() overrides: - virtual void SetUp() OVERRIDE { - test::AshTestBase::SetUp(); - observer_.reset(new PowerEventObserver()); - } - - virtual void TearDown() OVERRIDE { - observer_.reset(); - test::AshTestBase::TearDown(); - } - - protected: - scoped_ptr<PowerEventObserver> observer_; - - private: - DISALLOW_COPY_AND_ASSIGN(PowerEventObserverTest); -}; - -TEST_F(PowerEventObserverTest, LockBeforeSuspend) { - chromeos::PowerManagerClient* client = - chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); - ASSERT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); - - // Check that the observer requests a suspend-readiness callback when it hears - // that the system is about to suspend. - SetCanLockScreen(true); - SetShouldLockScreenBeforeSuspending(true); - observer_->SuspendImminent(); - EXPECT_EQ(1, client->GetNumPendingSuspendReadinessCallbacks()); - - // It should run the callback when it hears that the screen is locked. - observer_->ScreenIsLocked(); - RunAllPendingInMessageLoop(); - EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); - - // If the system is already locked, no callback should be requested. - observer_->SystemResumed(base::TimeDelta()); - observer_->ScreenIsUnlocked(); - observer_->ScreenIsLocked(); - observer_->SuspendImminent(); - EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); - - // It also shouldn't request a callback if it isn't instructed to lock the - // screen. - observer_->SystemResumed(base::TimeDelta()); - SetShouldLockScreenBeforeSuspending(false); - observer_->SuspendImminent(); - EXPECT_EQ(0, client->GetNumPendingSuspendReadinessCallbacks()); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/power/power_status.cc b/chromium/ash/system/chromeos/power/power_status.cc deleted file mode 100644 index b4b5d94ccf4..00000000000 --- a/chromium/ash/system/chromeos/power/power_status.cc +++ /dev/null @@ -1,301 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/power/power_status.h" - -#include <algorithm> -#include <cmath> - -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "base/logging.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/power_manager_client.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/l10n/time_format.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image.h" -#include "ui/gfx/image/image_skia_operations.h" -#include "ui/gfx/rect.h" - -namespace ash { -namespace internal { - -namespace { - -// Updates |proto| to ensure that its fields are consistent. -void SanitizeProto(power_manager::PowerSupplyProperties* proto) { - DCHECK(proto); - - if (proto->battery_state() == - power_manager::PowerSupplyProperties_BatteryState_FULL) - proto->set_battery_percent(100.0); - - if (!proto->is_calculating_battery_time()) { - const bool on_line_power = proto->external_power() != - power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED; - if ((on_line_power && proto->battery_time_to_full_sec() < 0) || - (!on_line_power && proto->battery_time_to_empty_sec() < 0)) - proto->set_is_calculating_battery_time(true); - } -} - -base::string16 GetBatteryTimeAccessibilityString(int hour, int min) { - DCHECK(hour || min); - if (hour && !min) { - return ui::TimeFormat::TimeDurationLong(base::TimeDelta::FromHours(hour)); - } - if (min && !hour) { - return ui::TimeFormat::TimeDurationLong(base::TimeDelta::FromMinutes(min)); - } - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_BATTERY_TIME_ACCESSIBLE, - ui::TimeFormat::TimeDurationLong(base::TimeDelta::FromHours(hour)), - ui::TimeFormat::TimeDurationLong(base::TimeDelta::FromMinutes(min))); -} - -static PowerStatus* g_power_status = NULL; - -// Minimum battery percentage rendered in UI. -const int kMinBatteryPercent = 1; - -// Width and height of battery images. -const int kBatteryImageHeight = 25; -const int kBatteryImageWidth = 25; - -// Number of different power states. -const int kNumPowerImages = 15; - -} // namespace - -const int PowerStatus::kMaxBatteryTimeToDisplaySec = 24 * 60 * 60; - -// static -void PowerStatus::Initialize() { - CHECK(!g_power_status); - g_power_status = new PowerStatus(); -} - -// static -void PowerStatus::Shutdown() { - CHECK(g_power_status); - delete g_power_status; - g_power_status = NULL; -} - -// static -bool PowerStatus::IsInitialized() { - return g_power_status != NULL; -} - -// static -PowerStatus* PowerStatus::Get() { - CHECK(g_power_status) << "PowerStatus::Get() called before Initialize()."; - return g_power_status; -} - -// static -bool PowerStatus::ShouldDisplayBatteryTime(const base::TimeDelta& time) { - return time >= base::TimeDelta::FromMinutes(1) && - time.InSeconds() <= kMaxBatteryTimeToDisplaySec; -} - -// static -void PowerStatus::SplitTimeIntoHoursAndMinutes(const base::TimeDelta& time, - int* hours, - int* minutes) { - DCHECK(hours); - DCHECK(minutes); - *hours = time.InHours(); - const double seconds = - (time - base::TimeDelta::FromHours(*hours)).InSecondsF(); - *minutes = static_cast<int>(seconds / 60.0 + 0.5); -} - -void PowerStatus::AddObserver(Observer* observer) { - DCHECK(observer); - observers_.AddObserver(observer); -} - -void PowerStatus::RemoveObserver(Observer* observer) { - DCHECK(observer); - observers_.RemoveObserver(observer); -} - -void PowerStatus::RequestStatusUpdate() { - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - RequestStatusUpdate(); -} - -bool PowerStatus::IsBatteryPresent() const { - return proto_.battery_state() != - power_manager::PowerSupplyProperties_BatteryState_NOT_PRESENT; -} - -bool PowerStatus::IsBatteryFull() const { - return proto_.battery_state() == - power_manager::PowerSupplyProperties_BatteryState_FULL; -} - -bool PowerStatus::IsBatteryCharging() const { - return proto_.battery_state() == - power_manager::PowerSupplyProperties_BatteryState_CHARGING; -} - -bool PowerStatus::IsBatteryDischargingOnLinePower() const { - return IsLinePowerConnected() && proto_.battery_state() == - power_manager::PowerSupplyProperties_BatteryState_DISCHARGING; -} - -double PowerStatus::GetBatteryPercent() const { - return proto_.battery_percent(); -} - -int PowerStatus::GetRoundedBatteryPercent() const { - return std::max(kMinBatteryPercent, - static_cast<int>(GetBatteryPercent() + 0.5)); -} - -bool PowerStatus::IsBatteryTimeBeingCalculated() const { - return proto_.is_calculating_battery_time(); -} - -base::TimeDelta PowerStatus::GetBatteryTimeToEmpty() const { - return base::TimeDelta::FromSeconds(proto_.battery_time_to_empty_sec()); -} - -base::TimeDelta PowerStatus::GetBatteryTimeToFull() const { - return base::TimeDelta::FromSeconds(proto_.battery_time_to_full_sec()); -} - -bool PowerStatus::IsLinePowerConnected() const { - return proto_.external_power() != - power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED; -} - -bool PowerStatus::IsMainsChargerConnected() const { - return proto_.external_power() == - power_manager::PowerSupplyProperties_ExternalPower_AC; -} - -bool PowerStatus::IsUsbChargerConnected() const { - return proto_.external_power() == - power_manager::PowerSupplyProperties_ExternalPower_USB; -} - -bool PowerStatus::IsOriginalSpringChargerConnected() const { - return proto_.external_power() == power_manager:: - PowerSupplyProperties_ExternalPower_ORIGINAL_SPRING_CHARGER; -} - -gfx::ImageSkia PowerStatus::GetBatteryImage(IconSet icon_set) const { - gfx::Image all; - if (IsUsbChargerConnected()) { - all = ui::ResourceBundle::GetSharedInstance().GetImageNamed( - icon_set == ICON_DARK ? - IDR_AURA_UBER_TRAY_POWER_SMALL_CHARGING_UNRELIABLE_DARK : - IDR_AURA_UBER_TRAY_POWER_SMALL_CHARGING_UNRELIABLE); - } else { - all = ui::ResourceBundle::GetSharedInstance().GetImageNamed( - icon_set == ICON_DARK ? - IDR_AURA_UBER_TRAY_POWER_SMALL_DARK : IDR_AURA_UBER_TRAY_POWER_SMALL); - } - - // Get the horizontal offset in the battery icon array image. The USB / - // "unreliable charging" image has a single column of icons; the other - // image contains a "battery" column on the left and a "line power" - // column on the right. - int offset = IsUsbChargerConnected() ? 0 : (IsLinePowerConnected() ? 1 : 0); - - // Get the vertical offset corresponding to the current battery level. - int index = -1; - if (GetBatteryPercent() >= 100.0) { - index = kNumPowerImages - 1; - } else if (!IsBatteryPresent()) { - index = kNumPowerImages; - } else { - index = static_cast<int>( - GetBatteryPercent() / 100.0 * (kNumPowerImages - 1)); - index = std::max(std::min(index, kNumPowerImages - 2), 0); - } - - gfx::Rect region( - offset * kBatteryImageWidth, index * kBatteryImageHeight, - kBatteryImageWidth, kBatteryImageHeight); - return gfx::ImageSkiaOperations::ExtractSubset(*all.ToImageSkia(), region); -} - -base::string16 PowerStatus::GetAccessibleNameString() const { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - if (IsBatteryFull()) { - return rb.GetLocalizedString( - IDS_ASH_STATUS_TRAY_BATTERY_FULL_CHARGE_ACCESSIBLE); - } - - base::string16 battery_percentage_accessible = l10n_util::GetStringFUTF16( - IsBatteryCharging() ? - IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_CHARGING_ACCESSIBLE : - IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ACCESSIBLE, - base::IntToString16(GetRoundedBatteryPercent())); - base::string16 battery_time_accessible = base::string16(); - const base::TimeDelta time = IsBatteryCharging() ? GetBatteryTimeToFull() : - GetBatteryTimeToEmpty(); - - if (IsUsbChargerConnected()) { - battery_time_accessible = rb.GetLocalizedString( - IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE_ACCESSIBLE); - } else if (IsBatteryTimeBeingCalculated()) { - battery_time_accessible = rb.GetLocalizedString( - IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING_ACCESSIBLE); - } else if (ShouldDisplayBatteryTime(time) && - !IsBatteryDischargingOnLinePower()) { - int hour = 0, min = 0; - PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min); - base::string16 minute = min < 10 ? - ASCIIToUTF16("0") + base::IntToString16(min) : - base::IntToString16(min); - battery_time_accessible = - l10n_util::GetStringFUTF16( - IsBatteryCharging() ? - IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL_ACCESSIBLE : - IDS_ASH_STATUS_TRAY_BATTERY_TIME_LEFT_ACCESSIBLE, - GetBatteryTimeAccessibilityString(hour, min)); - } - return battery_time_accessible.empty() ? - battery_percentage_accessible : - battery_percentage_accessible + ASCIIToUTF16(". ") + - battery_time_accessible; -} - -PowerStatus::PowerStatus() { - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - AddObserver(this); - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - RequestStatusUpdate(); -} - -PowerStatus::~PowerStatus() { - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - RemoveObserver(this); -} - -void PowerStatus::SetProtoForTesting( - const power_manager::PowerSupplyProperties& proto) { - proto_ = proto; - SanitizeProto(&proto_); -} - -void PowerStatus::PowerChanged( - const power_manager::PowerSupplyProperties& proto) { - proto_ = proto; - SanitizeProto(&proto_); - FOR_EACH_OBSERVER(Observer, observers_, OnPowerStatusChanged()); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/power/power_status.h b/chromium/ash/system/chromeos/power/power_status.h deleted file mode 100644 index e3060496401..00000000000 --- a/chromium/ash/system/chromeos/power/power_status.h +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ -#define ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ - -#include "ash/ash_export.h" -#include "base/basictypes.h" -#include "base/observer_list.h" -#include "base/strings/string16.h" -#include "base/time/time.h" -#include "chromeos/dbus/power_manager/power_supply_properties.pb.h" -#include "chromeos/dbus/power_manager_client.h" -#include "ui/gfx/image/image_skia.h" - -namespace ash { -namespace internal { - -// PowerStatus is a singleton that receives updates about the system's -// power status from chromeos::PowerManagerClient and makes the information -// available to interested classes within Ash. -class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer { - public: - // Different styles of battery icons. - enum IconSet { - ICON_LIGHT, - ICON_DARK - }; - - // Interface for classes that wish to be notified when the power status - // has changed. - class Observer { - public: - // Called when the power status changes. - virtual void OnPowerStatusChanged() = 0; - - protected: - virtual ~Observer() {} - }; - - // Maximum battery time-to-full or time-to-empty that should be displayed - // in the UI. If the current is close to zero, battery time estimates can - // get very large; avoid displaying these large numbers. - static const int kMaxBatteryTimeToDisplaySec; - - // Sets the global instance. Must be called before any calls to Get(). - static void Initialize(); - - // Destroys the global instance. - static void Shutdown(); - - // Returns true if the global instance is initialized. - static bool IsInitialized(); - - // Gets the global instance. Initialize must be called first. - static PowerStatus* Get(); - - // Returns true if |time|, a time returned by GetBatteryTimeToEmpty() or - // GetBatteryTimeToFull(), should be displayed in the UI. - // Less-than-a-minute or very large values aren't displayed. - static bool ShouldDisplayBatteryTime(const base::TimeDelta& time); - - // Copies the hour and minute components of |time| to |hours| and |minutes|. - // The minute component is rounded rather than truncated: a |time| value - // corresponding to 92 seconds will produce a |minutes| value of 2, for - // example. - static void SplitTimeIntoHoursAndMinutes(const base::TimeDelta& time, - int* hours, - int* minutes); - - // Adds or removes an observer. - void AddObserver(Observer* observer); - void RemoveObserver(Observer* observer); - - // Requests updated status from the power manager. - void RequestStatusUpdate(); - - // Returns true if a battery is present. - bool IsBatteryPresent() const; - - // Returns true if the battery is full. This also implies that a charger - // is connected. - bool IsBatteryFull() const; - - // Returns true if the battery is charging. Note that this implies that a - // charger is connected but the converse is not necessarily true: the - // battery may be discharging even while a (perhaps low-power) charger is - // connected. Use Is*Connected() to test for the presence of a charger - // and also see IsBatteryDischargingOnLinePower(). - bool IsBatteryCharging() const; - - // Returns true if the battery is discharging (or neither charging nor - // discharging while not being full) while line power is connected. - bool IsBatteryDischargingOnLinePower() const; - - // Returns the battery's remaining charge as a value in the range [0.0, - // 100.0]. - double GetBatteryPercent() const; - - // Returns the battery's remaining charge, rounded to an integer with a - // maximum value of 100. - int GetRoundedBatteryPercent() const; - - // Returns true if the battery's time-to-full and time-to-empty estimates - // should not be displayed because the power manager is still calculating - // them. - bool IsBatteryTimeBeingCalculated() const; - - // Returns the estimated time until the battery is empty (if line power - // is disconnected) or full (if line power is connected). These estimates - // should only be used if IsBatteryTimeBeingCalculated() returns false. - base::TimeDelta GetBatteryTimeToEmpty() const; - base::TimeDelta GetBatteryTimeToFull() const; - - // Returns true if line power (including a charger of any type) is connected. - bool IsLinePowerConnected() const; - - // Returns true if an official, non-USB charger is connected. - bool IsMainsChargerConnected() const; - - // Returns true if a USB charger (which is likely to only support a low - // charging rate) is connected. - bool IsUsbChargerConnected() const; - - // Returns true if an original spring charger is connected. - bool IsOriginalSpringChargerConnected() const; - - // Returns the image that should be shown for the battery's current state. - gfx::ImageSkia GetBatteryImage(IconSet icon_set) const; - - // Returns an string describing the current state for accessibility. - base::string16 GetAccessibleNameString() const; - - // Updates |proto_|. Does not notify observers. - void SetProtoForTesting(const power_manager::PowerSupplyProperties& proto); - - protected: - PowerStatus(); - virtual ~PowerStatus(); - - private: - // Overriden from PowerManagerClient::Observer. - virtual void PowerChanged( - const power_manager::PowerSupplyProperties& proto) OVERRIDE; - - ObserverList<Observer> observers_; - - // Current state. - power_manager::PowerSupplyProperties proto_; - - DISALLOW_COPY_AND_ASSIGN(PowerStatus); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ diff --git a/chromium/ash/system/chromeos/power/power_status_unittest.cc b/chromium/ash/system/chromeos/power/power_status_unittest.cc deleted file mode 100644 index ba9d2c11308..00000000000 --- a/chromium/ash/system/chromeos/power/power_status_unittest.cc +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/power/power_status.h" - -#include <set> -#include <string> - -#include "base/command_line.h" -#include "base/memory/scoped_ptr.h" -#include "base/message_loop/message_loop.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/cros_system_api/dbus/service_constants.h" - -namespace ash { -namespace internal { - -namespace { - -class TestObserver : public PowerStatus::Observer { - public: - TestObserver() : power_changed_count_(0) {} - virtual ~TestObserver() {} - - int power_changed_count() const { return power_changed_count_; } - - // PowerStatus::Observer overrides: - virtual void OnPowerStatusChanged() OVERRIDE { ++power_changed_count_; } - - private: - int power_changed_count_; - - DISALLOW_COPY_AND_ASSIGN(TestObserver); -}; - -} // namespace - -class PowerStatusTest : public testing::Test { - public: - PowerStatusTest() : power_status_(NULL) {} - virtual ~PowerStatusTest() {} - - virtual void SetUp() OVERRIDE { - chromeos::DBusThreadManager::InitializeWithStub(); - PowerStatus::Initialize(); - power_status_ = PowerStatus::Get(); - test_observer_.reset(new TestObserver); - power_status_->AddObserver(test_observer_.get()); - } - - virtual void TearDown() OVERRIDE { - power_status_->RemoveObserver(test_observer_.get()); - test_observer_.reset(); - PowerStatus::Shutdown(); - chromeos::DBusThreadManager::Shutdown(); - } - - protected: - base::MessageLoopForUI message_loop_; - PowerStatus* power_status_; // Not owned. - scoped_ptr<TestObserver> test_observer_; - - private: - DISALLOW_COPY_AND_ASSIGN(PowerStatusTest); -}; - -TEST_F(PowerStatusTest, InitializeAndUpdate) { - // Test that the initial power supply state should be acquired after - // PowerStatus is instantiated. This depends on - // PowerManagerClientStubImpl, which responds to power status update - // requests, pretends there is a battery present, and generates some valid - // power supply status data. - message_loop_.RunUntilIdle(); - EXPECT_EQ(1, test_observer_->power_changed_count()); - - // Test RequestUpdate, test_obsever_ should be notified for power suuply - // status change. - power_status_->RequestStatusUpdate(); - message_loop_.RunUntilIdle(); - EXPECT_EQ(2, test_observer_->power_changed_count()); -} - -TEST_F(PowerStatusTest, ShouldDisplayBatteryTime) { - EXPECT_FALSE(PowerStatus::ShouldDisplayBatteryTime( - base::TimeDelta::FromSeconds(-1))); - EXPECT_FALSE(PowerStatus::ShouldDisplayBatteryTime( - base::TimeDelta::FromSeconds(0))); - EXPECT_FALSE(PowerStatus::ShouldDisplayBatteryTime( - base::TimeDelta::FromSeconds(59))); - EXPECT_TRUE(PowerStatus::ShouldDisplayBatteryTime( - base::TimeDelta::FromSeconds(60))); - EXPECT_TRUE(PowerStatus::ShouldDisplayBatteryTime( - base::TimeDelta::FromSeconds(600))); - EXPECT_TRUE(PowerStatus::ShouldDisplayBatteryTime( - base::TimeDelta::FromSeconds(3600))); - EXPECT_TRUE(PowerStatus::ShouldDisplayBatteryTime( - base::TimeDelta::FromSeconds( - PowerStatus::kMaxBatteryTimeToDisplaySec))); - EXPECT_FALSE(PowerStatus::ShouldDisplayBatteryTime( - base::TimeDelta::FromSeconds( - PowerStatus::kMaxBatteryTimeToDisplaySec + 1))); -} - -TEST_F(PowerStatusTest, SplitTimeIntoHoursAndMinutes) { - int hours = 0, minutes = 0; - PowerStatus::SplitTimeIntoHoursAndMinutes( - base::TimeDelta::FromSeconds(0), &hours, &minutes); - EXPECT_EQ(0, hours); - EXPECT_EQ(0, minutes); - - PowerStatus::SplitTimeIntoHoursAndMinutes( - base::TimeDelta::FromSeconds(60), &hours, &minutes); - EXPECT_EQ(0, hours); - EXPECT_EQ(1, minutes); - - PowerStatus::SplitTimeIntoHoursAndMinutes( - base::TimeDelta::FromSeconds(3600), &hours, &minutes); - EXPECT_EQ(1, hours); - EXPECT_EQ(0, minutes); - - PowerStatus::SplitTimeIntoHoursAndMinutes( - base::TimeDelta::FromSeconds(3600 + 60), &hours, &minutes); - EXPECT_EQ(1, hours); - EXPECT_EQ(1, minutes); - - PowerStatus::SplitTimeIntoHoursAndMinutes( - base::TimeDelta::FromSeconds(7 * 3600 + 23 * 60), &hours, &minutes); - EXPECT_EQ(7, hours); - EXPECT_EQ(23, minutes); - - // Check that minutes are rounded. - PowerStatus::SplitTimeIntoHoursAndMinutes( - base::TimeDelta::FromSeconds(2 * 3600 + 3 * 60 + 30), &hours, &minutes); - EXPECT_EQ(2, hours); - EXPECT_EQ(4, minutes); - - PowerStatus::SplitTimeIntoHoursAndMinutes( - base::TimeDelta::FromSeconds(2 * 3600 + 3 * 60 + 29), &hours, &minutes); - EXPECT_EQ(2, hours); - EXPECT_EQ(3, minutes); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/power/power_status_view.cc b/chromium/ash/system/chromeos/power/power_status_view.cc deleted file mode 100644 index f0fe4b1397a..00000000000 --- a/chromium/ash/system/chromeos/power/power_status_view.cc +++ /dev/null @@ -1,221 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/power/power_status_view.h" - -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "ash/system/chromeos/power/power_status.h" -#include "ash/system/chromeos/power/tray_power.h" -#include "ash/system/tray/fixed_sized_image_view.h" -#include "ash/system/tray/tray_constants.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/l10n/time_format.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/grid_layout.h" - -namespace ash { -namespace internal { - -// Padding between battery status text and battery icon on default view. -const int kPaddingBetweenBatteryStatusAndIcon = 3; - -PowerStatusView::PowerStatusView(ViewType view_type, - bool default_view_right_align) - : default_view_right_align_(default_view_right_align), - status_label_(NULL), - time_label_(NULL), - time_status_label_(NULL), - percentage_label_(NULL), - icon_(NULL), - view_type_(view_type) { - PowerStatus::Get()->AddObserver(this); - if (view_type == VIEW_DEFAULT) { - time_status_label_ = new views::Label; - percentage_label_ = new views::Label; - percentage_label_->SetEnabledColor(kHeaderTextColorNormal); - LayoutDefaultView(); - } else { - status_label_ = new views::Label; - time_label_ = new views::Label; - LayoutNotificationView(); - } - OnPowerStatusChanged(); -} - -PowerStatusView::~PowerStatusView() { - PowerStatus::Get()->RemoveObserver(this); -} - -void PowerStatusView::OnPowerStatusChanged() { - view_type_ == VIEW_DEFAULT ? - UpdateTextForDefaultView() : UpdateTextForNotificationView(); - - if (icon_) { - icon_->SetImage( - PowerStatus::Get()->GetBatteryImage(PowerStatus::ICON_DARK)); - icon_->SetVisible(true); - } -} - -void PowerStatusView::LayoutDefaultView() { - if (default_view_right_align_) { - views::BoxLayout* layout = - new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, - kPaddingBetweenBatteryStatusAndIcon); - SetLayoutManager(layout); - - AddChildView(percentage_label_); - AddChildView(time_status_label_); - - icon_ = new views::ImageView; - AddChildView(icon_); - } else { - // PowerStatusView is left aligned on the system tray pop up item. - views::BoxLayout* layout = - new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, - kTrayPopupPaddingBetweenItems); - SetLayoutManager(layout); - - icon_ = - new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); - AddChildView(icon_); - - AddChildView(percentage_label_); - AddChildView(time_status_label_); - } -} - -void PowerStatusView::LayoutNotificationView() { - SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); - status_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - AddChildView(status_label_); - - time_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - AddChildView(time_label_); -} - -void PowerStatusView::UpdateTextForDefaultView() { - const PowerStatus& status = *PowerStatus::Get(); - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - base::string16 battery_percentage; - base::string16 battery_time_status; - - if (status.IsBatteryFull()) { - battery_time_status = - rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL); - } else { - battery_percentage = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ONLY, - base::IntToString16(status.GetRoundedBatteryPercent())); - if (status.IsUsbChargerConnected()) { - battery_time_status = rb.GetLocalizedString( - IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); - } else if (status.IsBatteryTimeBeingCalculated()) { - battery_time_status = - rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); - } else { - base::TimeDelta time = status.IsBatteryCharging() ? - status.GetBatteryTimeToFull() : status.GetBatteryTimeToEmpty(); - if (PowerStatus::ShouldDisplayBatteryTime(time) && - !status.IsBatteryDischargingOnLinePower()) { - int hour = 0, min = 0; - PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min); - base::string16 minute = min < 10 ? - ASCIIToUTF16("0") + base::IntToString16(min) : - base::IntToString16(min); - battery_time_status = - l10n_util::GetStringFUTF16( - status.IsBatteryCharging() ? - IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL_SHORT : - IDS_ASH_STATUS_TRAY_BATTERY_TIME_LEFT_SHORT, - base::IntToString16(hour), - minute); - } - } - battery_percentage = battery_time_status.empty() ? - battery_percentage : battery_percentage + ASCIIToUTF16(" - "); - } - percentage_label_->SetVisible(!battery_percentage.empty()); - percentage_label_->SetText(battery_percentage); - time_status_label_->SetVisible(!battery_time_status.empty()); - time_status_label_->SetText(battery_time_status); -} - -void PowerStatusView::UpdateTextForNotificationView() { - const PowerStatus& status = *PowerStatus::Get(); - if (status.IsBatteryFull()) { - status_label_->SetText( - ui::ResourceBundle::GetSharedInstance().GetLocalizedString( - IDS_ASH_STATUS_TRAY_BATTERY_FULL)); - } else { - status_label_->SetText( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, - base::IntToString16(status.GetRoundedBatteryPercent()))); - } - - const base::TimeDelta time = status.IsBatteryCharging() ? - status.GetBatteryTimeToFull() : status.GetBatteryTimeToEmpty(); - - if (status.IsUsbChargerConnected()) { - time_label_->SetText( - ui::ResourceBundle::GetSharedInstance().GetLocalizedString( - IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE)); - } else if (status.IsBatteryTimeBeingCalculated()) { - time_label_->SetText( - ui::ResourceBundle::GetSharedInstance().GetLocalizedString( - IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING)); - } else if (PowerStatus::ShouldDisplayBatteryTime(time) && - !status.IsBatteryDischargingOnLinePower()) { - int hour = 0, min = 0; - PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min); - if (status.IsBatteryCharging()) { - time_label_->SetText( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL, - base::IntToString16(hour), - base::IntToString16(min))); - } else { - // This is a low battery warning prompting the user in minutes. - time_label_->SetText(ui::TimeFormat::TimeRemaining( - base::TimeDelta::FromMinutes(hour * 60 + min))); - } - } else { - time_label_->SetText(base::string16()); - } -} - -void PowerStatusView::ChildPreferredSizeChanged(views::View* child) { - PreferredSizeChanged(); -} - -gfx::Size PowerStatusView::GetPreferredSize() { - gfx::Size size = views::View::GetPreferredSize(); - return gfx::Size(size.width(), kTrayPopupItemHeight); -} - -int PowerStatusView::GetHeightForWidth(int width) { - return kTrayPopupItemHeight; -} - -void PowerStatusView::Layout() { - views::View::Layout(); - - // Move the time_status_label_ closer to percentage_label_. - if (percentage_label_ && time_status_label_ && - percentage_label_->visible() && time_status_label_->visible()) { - time_status_label_->SetX(percentage_label_->bounds().right() + 1); - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/power/power_status_view.h b/chromium/ash/system/chromeos/power/power_status_view.h deleted file mode 100644 index 465da02b8a3..00000000000 --- a/chromium/ash/system/chromeos/power/power_status_view.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_VIEW_H_ -#define ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_VIEW_H_ - -#include "ash/system/chromeos/power/power_status.h" -#include "ui/views/view.h" - -namespace views { -class ImageView; -class Label; -} - -namespace ash { -namespace internal { - -class PowerStatusView : public views::View, public PowerStatus::Observer { - public: - enum ViewType { - VIEW_DEFAULT, - VIEW_NOTIFICATION - }; - - PowerStatusView(ViewType view_type, bool default_view_right_align); - virtual ~PowerStatusView(); - - // Overridden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual int GetHeightForWidth(int width) OVERRIDE; - virtual void Layout() OVERRIDE; - - // Overridden from PowerStatus::Observer. - virtual void OnPowerStatusChanged() OVERRIDE; - - private: - void LayoutDefaultView(); - void LayoutNotificationView(); - void UpdateTextForDefaultView(); - void UpdateTextForNotificationView(); - - // Overridden from views::View. - virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; - - // Layout default view UI items on the right side of system tray pop up item - // if true; otherwise, layout the UI items on the left side. - bool default_view_right_align_; - - // Labels used only for VIEW_NOTIFICATION. - views::Label* status_label_; - views::Label* time_label_; - - // Labels used only for VIEW_DEFAULT. - views::Label* time_status_label_; - views::Label* percentage_label_; - - // Battery status indicator icon. - views::ImageView* icon_; - - ViewType view_type_; - - DISALLOW_COPY_AND_ASSIGN(PowerStatusView); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_VIEW_H_ diff --git a/chromium/ash/system/chromeos/power/tray_power.cc b/chromium/ash/system/chromeos/power/tray_power.cc deleted file mode 100644 index 1dedf4896e8..00000000000 --- a/chromium/ash/system/chromeos/power/tray_power.cc +++ /dev/null @@ -1,344 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/power/tray_power.h" - -#include "ash/ash_switches.h" -#include "ash/shell.h" -#include "ash/system/chromeos/power/power_status_view.h" -#include "ash/system/date/date_view.h" -#include "ash/system/system_notifier.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_notification_view.h" -#include "ash/system/tray/tray_utils.h" -#include "base/command_line.h" -#include "base/metrics/histogram.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "third_party/icu/source/i18n/unicode/fieldpos.h" -#include "third_party/icu/source/i18n/unicode/fmtable.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" -#include "ui/views/controls/button/button.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/layout/grid_layout.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -using message_center::MessageCenter; -using message_center::Notification; - -namespace ash { -namespace internal { -namespace tray { - -// This view is used only for the tray. -class PowerTrayView : public views::ImageView { - public: - PowerTrayView() { - UpdateImage(); - } - - virtual ~PowerTrayView() { - } - - // Overriden from views::View. - virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE { - state->name = accessible_name_; - state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; - } - - void UpdateStatus(bool battery_alert) { - UpdateImage(); - SetVisible(PowerStatus::Get()->IsBatteryPresent()); - - if (battery_alert) { - accessible_name_ = PowerStatus::Get()->GetAccessibleNameString(); - NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); - } - } - - private: - void UpdateImage() { - SetImage(PowerStatus::Get()->GetBatteryImage(PowerStatus::ICON_LIGHT)); - } - - base::string16 accessible_name_; - - DISALLOW_COPY_AND_ASSIGN(PowerTrayView); -}; - -class PowerNotificationView : public TrayNotificationView { - public: - explicit PowerNotificationView(TrayPower* owner) - : TrayNotificationView(owner, 0) { - power_status_view_ = - new PowerStatusView(PowerStatusView::VIEW_NOTIFICATION, true); - InitView(power_status_view_); - } - - void UpdateStatus() { - SetIconImage(PowerStatus::Get()->GetBatteryImage(PowerStatus::ICON_DARK)); - } - - private: - PowerStatusView* power_status_view_; - - DISALLOW_COPY_AND_ASSIGN(PowerNotificationView); -}; - -} // namespace tray - -using tray::PowerNotificationView; - -const int TrayPower::kCriticalMinutes = 5; -const int TrayPower::kLowPowerMinutes = 15; -const int TrayPower::kNoWarningMinutes = 30; -const int TrayPower::kCriticalPercentage = 5; -const int TrayPower::kLowPowerPercentage = 10; -const int TrayPower::kNoWarningPercentage = 15; - -TrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center) - : SystemTrayItem(system_tray), - message_center_(message_center), - power_tray_(NULL), - notification_view_(NULL), - notification_state_(NOTIFICATION_NONE), - usb_charger_was_connected_(false), - line_power_was_connected_(false) { - PowerStatus::Get()->AddObserver(this); -} - -TrayPower::~TrayPower() { - PowerStatus::Get()->RemoveObserver(this); -} - -views::View* TrayPower::CreateTrayView(user::LoginStatus status) { - // There may not be enough information when this is created about whether - // there is a battery or not. So always create this, and adjust visibility as - // necessary. - CHECK(power_tray_ == NULL); - power_tray_ = new tray::PowerTrayView(); - power_tray_->UpdateStatus(false); - return power_tray_; -} - -views::View* TrayPower::CreateDefaultView(user::LoginStatus status) { - // Make sure icon status is up-to-date. (Also triggers stub activation). - PowerStatus::Get()->RequestStatusUpdate(); - return NULL; -} - -views::View* TrayPower::CreateNotificationView(user::LoginStatus status) { - CHECK(notification_view_ == NULL); - if (!PowerStatus::Get()->IsBatteryPresent()) - return NULL; - - notification_view_ = new PowerNotificationView(this); - notification_view_->UpdateStatus(); - - return notification_view_; -} - -void TrayPower::DestroyTrayView() { - power_tray_ = NULL; -} - -void TrayPower::DestroyDefaultView() { -} - -void TrayPower::DestroyNotificationView() { - notification_view_ = NULL; -} - -void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) { -} - -void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { - SetTrayImageItemBorder(power_tray_, alignment); -} - -void TrayPower::OnPowerStatusChanged() { - RecordChargerType(); - - if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) { - ash::Shell::GetInstance()->system_tray_delegate()-> - ShowSpringChargerReplacementDialog(); - } - - bool battery_alert = UpdateNotificationState(); - if (power_tray_) - power_tray_->UpdateStatus(battery_alert); - if (notification_view_) - notification_view_->UpdateStatus(); - - // Factory testing may place the battery into unusual states. - if (CommandLine::ForCurrentProcess()->HasSwitch( - ash::switches::kAshHideNotificationsForFactory)) - return; - - if (ash::switches::UseUsbChargerNotification()) - MaybeShowUsbChargerNotification(); - - if (battery_alert) - ShowNotificationView(); - else if (notification_state_ == NOTIFICATION_NONE) - HideNotificationView(); - - usb_charger_was_connected_ = PowerStatus::Get()->IsUsbChargerConnected(); - line_power_was_connected_ = PowerStatus::Get()->IsLinePowerConnected(); -} - -bool TrayPower::MaybeShowUsbChargerNotification() { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - const char kNotificationId[] = "usb-charger"; - bool usb_charger_is_connected = PowerStatus::Get()->IsUsbChargerConnected(); - - // Check for a USB charger being connected. - if (usb_charger_is_connected && !usb_charger_was_connected_) { - scoped_ptr<Notification> notification(new Notification( - message_center::NOTIFICATION_TYPE_SIMPLE, - kNotificationId, - rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOW_POWER_CHARGER_TITLE), - rb.GetLocalizedString( - IDS_ASH_STATUS_TRAY_LOW_POWER_CHARGER_MESSAGE_SHORT), - rb.GetImageNamed(IDR_AURA_NOTIFICATION_LOW_POWER_CHARGER), - base::string16(), - message_center::NotifierId( - message_center::NotifierId::SYSTEM_COMPONENT, - system_notifier::kNotifierPower), - message_center::RichNotificationData(), - NULL)); - message_center_->AddNotification(notification.Pass()); - return true; - } - - // Check for unplug of a USB charger while the USB charger notification is - // showing. - if (!usb_charger_is_connected && usb_charger_was_connected_) { - message_center_->RemoveNotification(kNotificationId, false); - return true; - } - return false; -} - -bool TrayPower::UpdateNotificationState() { - const PowerStatus& status = *PowerStatus::Get(); - if (!status.IsBatteryPresent() || - status.IsBatteryTimeBeingCalculated() || - status.IsMainsChargerConnected() || - status.IsOriginalSpringChargerConnected()) { - notification_state_ = NOTIFICATION_NONE; - return false; - } - - return status.IsUsbChargerConnected() ? - UpdateNotificationStateForRemainingPercentage() : - UpdateNotificationStateForRemainingTime(); -} - -bool TrayPower::UpdateNotificationStateForRemainingTime() { - // The notification includes a rounded minutes value, so round the estimate - // received from the power manager to match. - const int remaining_minutes = static_cast<int>( - PowerStatus::Get()->GetBatteryTimeToEmpty().InSecondsF() / 60.0 + 0.5); - - if (remaining_minutes >= kNoWarningMinutes || - PowerStatus::Get()->IsBatteryFull()) { - notification_state_ = NOTIFICATION_NONE; - return false; - } - - switch (notification_state_) { - case NOTIFICATION_NONE: - if (remaining_minutes <= kCriticalMinutes) { - notification_state_ = NOTIFICATION_CRITICAL; - return true; - } - if (remaining_minutes <= kLowPowerMinutes) { - notification_state_ = NOTIFICATION_LOW_POWER; - return true; - } - return false; - case NOTIFICATION_LOW_POWER: - if (remaining_minutes <= kCriticalMinutes) { - notification_state_ = NOTIFICATION_CRITICAL; - return true; - } - return false; - case NOTIFICATION_CRITICAL: - return false; - } - NOTREACHED(); - return false; -} - -bool TrayPower::UpdateNotificationStateForRemainingPercentage() { - // The notification includes a rounded percentage, so round the value received - // from the power manager to match. - const int remaining_percentage = - PowerStatus::Get()->GetRoundedBatteryPercent(); - - if (remaining_percentage >= kNoWarningPercentage || - PowerStatus::Get()->IsBatteryFull()) { - notification_state_ = NOTIFICATION_NONE; - return false; - } - - switch (notification_state_) { - case NOTIFICATION_NONE: - if (remaining_percentage <= kCriticalPercentage) { - notification_state_ = NOTIFICATION_CRITICAL; - return true; - } - if (remaining_percentage <= kLowPowerPercentage) { - notification_state_ = NOTIFICATION_LOW_POWER; - return true; - } - return false; - case NOTIFICATION_LOW_POWER: - if (remaining_percentage <= kCriticalPercentage) { - notification_state_ = NOTIFICATION_CRITICAL; - return true; - } - return false; - case NOTIFICATION_CRITICAL: - return false; - } - NOTREACHED(); - return false; -} - -void TrayPower::RecordChargerType() { - if (!PowerStatus::Get()->IsLinePowerConnected() || - line_power_was_connected_) - return; - - ChargerType current_charger = UNKNOWN_CHARGER; - if (PowerStatus::Get()->IsMainsChargerConnected()) { - current_charger = MAINS_CHARGER; - } else if (PowerStatus::Get()->IsUsbChargerConnected()) { - current_charger = USB_CHARGER; - } else if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) { - current_charger = - ash::Shell::GetInstance()->system_tray_delegate()-> - HasUserConfirmedSafeSpringCharger() ? - SAFE_SPRING_CHARGER : UNCONFIRMED_SPRING_CHARGER; - } - - if (current_charger != UNKNOWN_CHARGER) { - UMA_HISTOGRAM_ENUMERATION("Power.ChargerType", - current_charger, - CHARGER_TYPE_COUNT); - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/power/tray_power.h b/chromium/ash/system/chromeos/power/tray_power.h deleted file mode 100644 index d79ac5e400d..00000000000 --- a/chromium/ash/system/chromeos/power/tray_power.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ -#define ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ - -#include "ash/system/chromeos/power/power_status.h" -#include "ash/system/tray/system_tray_item.h" - -class SkBitmap; - -namespace gfx { -class Image; -class ImageSkia; -} - -namespace message_center { -class MessageCenter; -} - -namespace ash { -namespace internal { - -namespace tray { -class PowerNotificationView; -class PowerTrayView; -} - -class ASH_EXPORT TrayPower : public SystemTrayItem, - public PowerStatus::Observer { - public: - // Visible for testing. - enum NotificationState { - NOTIFICATION_NONE, - - // Low battery charge. - NOTIFICATION_LOW_POWER, - - // Critically low battery charge. - NOTIFICATION_CRITICAL, - }; - - // Time-based notification thresholds when on battery power. - static const int kCriticalMinutes; - static const int kLowPowerMinutes; - static const int kNoWarningMinutes; - - // Percentage-based notification thresholds when using a low-power charger. - static const int kCriticalPercentage; - static const int kLowPowerPercentage; - static const int kNoWarningPercentage; - - TrayPower(SystemTray* system_tray, - message_center::MessageCenter* message_center); - virtual ~TrayPower(); - - private: - friend class TrayPowerTest; - - // This enum is used for histogram. The existing values should not be removed, - // and the new values should be added just before CHARGER_TYPE_COUNT. - enum ChargerType{ - UNKNOWN_CHARGER, - MAINS_CHARGER, - USB_CHARGER, - UNCONFIRMED_SPRING_CHARGER, - SAFE_SPRING_CHARGER, - CHARGER_TYPE_COUNT, - }; - - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateNotificationView( - user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyNotificationView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) OVERRIDE; - - // Overridden from PowerStatus::Observer. - virtual void OnPowerStatusChanged() OVERRIDE; - - // Show a notification that a low-power USB charger has been connected. - // Returns true if a notification was shown or explicitly hidden. - bool MaybeShowUsbChargerNotification(); - - // Sets |notification_state_|. Returns true if a notification should be shown. - bool UpdateNotificationState(); - bool UpdateNotificationStateForRemainingTime(); - bool UpdateNotificationStateForRemainingPercentage(); - - // Records the charger type in UMA. - void RecordChargerType(); - - message_center::MessageCenter* message_center_; // Not owned. - tray::PowerTrayView* power_tray_; - tray::PowerNotificationView* notification_view_; - NotificationState notification_state_; - - // Was a USB charger connected the last time OnPowerStatusChanged() was - // called? - bool usb_charger_was_connected_; - - // Was line power connected the last time onPowerStatusChanged() was called? - bool line_power_was_connected_; - - DISALLOW_COPY_AND_ASSIGN(TrayPower); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ diff --git a/chromium/ash/system/chromeos/power/tray_power_unittest.cc b/chromium/ash/system/chromeos/power/tray_power_unittest.cc deleted file mode 100644 index a5552fab5d2..00000000000 --- a/chromium/ash/system/chromeos/power/tray_power_unittest.cc +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/power/tray_power.h" - -#include "ash/ash_switches.h" -#include "ash/test/ash_test_base.h" -#include "base/memory/scoped_ptr.h" -#include "chromeos/dbus/power_manager/power_supply_properties.pb.h" -#include "ui/message_center/fake_message_center.h" - -using message_center::Notification; -using power_manager::PowerSupplyProperties; - -namespace { - -class MockMessageCenter : public message_center::FakeMessageCenter { - public: - MockMessageCenter() : add_count_(0), remove_count_(0) {} - virtual ~MockMessageCenter() {} - - int add_count() const { return add_count_; } - int remove_count() const { return remove_count_; } - - // message_center::FakeMessageCenter overrides: - virtual void AddNotification(scoped_ptr<Notification> notification) OVERRIDE { - add_count_++; - } - virtual void RemoveNotification(const std::string& id, bool by_user) - OVERRIDE { - remove_count_++; - } - - private: - int add_count_; - int remove_count_; - - DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); -}; - -} // namespace - -namespace ash { -namespace internal { - -class TrayPowerTest : public test::AshTestBase { - public: - TrayPowerTest() {} - virtual ~TrayPowerTest() {} - - MockMessageCenter* message_center() { return message_center_.get(); } - TrayPower* tray_power() { return tray_power_.get(); } - - // test::AshTestBase::SetUp() overrides: - virtual void SetUp() OVERRIDE { - test::AshTestBase::SetUp(); - message_center_.reset(new MockMessageCenter()); - tray_power_.reset(new TrayPower(NULL, message_center_.get())); - } - - virtual void TearDown() OVERRIDE { - tray_power_.reset(); - message_center_.reset(); - test::AshTestBase::TearDown(); - } - - TrayPower::NotificationState notification_state() const { - return tray_power_->notification_state_; - } - - bool MaybeShowUsbChargerNotification(const PowerSupplyProperties& proto) { - PowerStatus::Get()->SetProtoForTesting(proto); - return tray_power_->MaybeShowUsbChargerNotification(); - } - - bool UpdateNotificationState(const PowerSupplyProperties& proto) { - PowerStatus::Get()->SetProtoForTesting(proto); - return tray_power_->UpdateNotificationState(); - } - - void SetUsbChargerConnected(bool connected) { - tray_power_->usb_charger_was_connected_ = connected; - } - - // Returns a discharging PowerSupplyProperties more appropriate for testing. - static PowerSupplyProperties DefaultPowerSupplyProperties() { - PowerSupplyProperties proto; - proto.set_external_power( - power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED); - proto.set_battery_state( - power_manager::PowerSupplyProperties_BatteryState_DISCHARGING); - proto.set_battery_percent(50.0); - proto.set_battery_time_to_empty_sec(3 * 60 * 60); - proto.set_battery_time_to_full_sec(2 * 60 * 60); - proto.set_is_calculating_battery_time(false); - return proto; - } - - private: - scoped_ptr<MockMessageCenter> message_center_; - scoped_ptr<TrayPower> tray_power_; - - DISALLOW_COPY_AND_ASSIGN(TrayPowerTest); -}; - -TEST_F(TrayPowerTest, MaybeShowUsbChargerNotification) { - PowerSupplyProperties discharging = DefaultPowerSupplyProperties(); - EXPECT_FALSE(MaybeShowUsbChargerNotification(discharging)); - EXPECT_EQ(0, message_center()->add_count()); - EXPECT_EQ(0, message_center()->remove_count()); - - // Notification shows when connecting a USB charger. - PowerSupplyProperties usb_connected = DefaultPowerSupplyProperties(); - usb_connected.set_external_power( - power_manager::PowerSupplyProperties_ExternalPower_USB); - EXPECT_TRUE(MaybeShowUsbChargerNotification(usb_connected)); - EXPECT_EQ(1, message_center()->add_count()); - EXPECT_EQ(0, message_center()->remove_count()); - - // Change in charge does not trigger the notification again. - PowerSupplyProperties more_charge = DefaultPowerSupplyProperties(); - more_charge.set_external_power( - power_manager::PowerSupplyProperties_ExternalPower_USB); - more_charge.set_battery_time_to_full_sec(60 * 60); - more_charge.set_battery_percent(75.0); - SetUsbChargerConnected(true); - EXPECT_FALSE(MaybeShowUsbChargerNotification(more_charge)); - EXPECT_EQ(1, message_center()->add_count()); - EXPECT_EQ(0, message_center()->remove_count()); - - // Disconnecting a USB charger with the notification showing should close - // the notification. - EXPECT_TRUE(MaybeShowUsbChargerNotification(discharging)); - EXPECT_EQ(1, message_center()->add_count()); - EXPECT_EQ(1, message_center()->remove_count()); -} - -TEST_F(TrayPowerTest, UpdateNotificationState) { - // No notifications when no battery present. - PowerSupplyProperties no_battery = DefaultPowerSupplyProperties(); - no_battery.set_external_power( - power_manager::PowerSupplyProperties_ExternalPower_AC); - no_battery.set_battery_state( - power_manager::PowerSupplyProperties_BatteryState_NOT_PRESENT); - EXPECT_FALSE(UpdateNotificationState(no_battery)); - EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); - - // No notification when calculating remaining battery time. - PowerSupplyProperties calculating = DefaultPowerSupplyProperties(); - calculating.set_is_calculating_battery_time(true); - EXPECT_FALSE(UpdateNotificationState(calculating)); - EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); - - // No notification when charging. - PowerSupplyProperties charging = DefaultPowerSupplyProperties(); - charging.set_external_power( - power_manager::PowerSupplyProperties_ExternalPower_AC); - charging.set_battery_state( - power_manager::PowerSupplyProperties_BatteryState_CHARGING); - EXPECT_FALSE(UpdateNotificationState(charging)); - EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); - - // When the rounded minutes-to-empty are above the threshold, no notification - // should be shown. - PowerSupplyProperties low = DefaultPowerSupplyProperties(); - low.set_battery_time_to_empty_sec(TrayPower::kLowPowerMinutes * 60 + 30); - EXPECT_FALSE(UpdateNotificationState(low)); - EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); - - // When the rounded value matches the threshold, the notification should - // appear. - low.set_battery_time_to_empty_sec(TrayPower::kLowPowerMinutes * 60 + 29); - EXPECT_TRUE(UpdateNotificationState(low)); - EXPECT_EQ(TrayPower::NOTIFICATION_LOW_POWER, notification_state()); - - // It should persist at lower values. - low.set_battery_time_to_empty_sec(TrayPower::kLowPowerMinutes * 60 - 20); - EXPECT_FALSE(UpdateNotificationState(low)); - EXPECT_EQ(TrayPower::NOTIFICATION_LOW_POWER, notification_state()); - - // The critical low battery notification should be shown when the rounded - // value is at the lower threshold. - PowerSupplyProperties critical = DefaultPowerSupplyProperties(); - critical.set_battery_time_to_empty_sec(TrayPower::kCriticalMinutes * 60 + 29); - EXPECT_TRUE(UpdateNotificationState(critical)); - EXPECT_EQ(TrayPower::NOTIFICATION_CRITICAL, notification_state()); - - // The notification should be dismissed when the no-warning threshold is - // reached. - PowerSupplyProperties safe = DefaultPowerSupplyProperties(); - safe.set_battery_time_to_empty_sec(TrayPower::kNoWarningMinutes * 60 - 29); - EXPECT_FALSE(UpdateNotificationState(safe)); - EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); - - // Test that rounded percentages are used when a USB charger is connected. - PowerSupplyProperties low_usb = DefaultPowerSupplyProperties(); - low_usb.set_external_power( - power_manager::PowerSupplyProperties_ExternalPower_USB); - low_usb.set_battery_percent(TrayPower::kLowPowerPercentage + 0.5); - EXPECT_FALSE(UpdateNotificationState(low_usb)); - EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); - - low_usb.set_battery_percent(TrayPower::kLowPowerPercentage + 0.49); - EXPECT_TRUE(UpdateNotificationState(low_usb)); - EXPECT_EQ(TrayPower::NOTIFICATION_LOW_POWER, notification_state()); - - PowerSupplyProperties critical_usb = DefaultPowerSupplyProperties(); - critical_usb.set_external_power( - power_manager::PowerSupplyProperties_ExternalPower_USB); - critical_usb.set_battery_percent(TrayPower::kCriticalPercentage + 0.2); - EXPECT_TRUE(UpdateNotificationState(critical_usb)); - EXPECT_EQ(TrayPower::NOTIFICATION_CRITICAL, notification_state()); - - PowerSupplyProperties safe_usb = DefaultPowerSupplyProperties(); - safe_usb.set_external_power( - power_manager::PowerSupplyProperties_ExternalPower_USB); - safe_usb.set_battery_percent(TrayPower::kNoWarningPercentage - 0.1); - EXPECT_FALSE(UpdateNotificationState(safe_usb)); - EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); - - // A notification shouldn't be shown when we're in the full state with an - // original Spring charger connected: http://crbug.com/338376 - PowerSupplyProperties spring = DefaultPowerSupplyProperties(); - spring.set_external_power(power_manager:: - PowerSupplyProperties_ExternalPower_ORIGINAL_SPRING_CHARGER); - spring.set_battery_state( - power_manager::PowerSupplyProperties_BatteryState_FULL); - spring.set_battery_time_to_empty_sec(0); - spring.set_battery_time_to_full_sec(0); - EXPECT_FALSE(UpdateNotificationState(spring)); - EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/power/user_activity_notifier.cc b/chromium/ash/system/chromeos/power/user_activity_notifier.cc deleted file mode 100644 index 921363ca72f..00000000000 --- a/chromium/ash/system/chromeos/power/user_activity_notifier.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/power/user_activity_notifier.h" - -#include "ash/shell.h" -#include "ash/wm/user_activity_detector.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/power_manager_client.h" -#include "ui/events/event.h" -#include "ui/events/event_constants.h" -#include "ui/events/keycodes/keyboard_codes_posix.h" - -namespace ash { -namespace internal { - -namespace { - -// Minimum number of seconds between notifications. -const int kNotifyIntervalSec = 5; - -} // namespace - -UserActivityNotifier::UserActivityNotifier(UserActivityDetector* detector) - : detector_(detector) { - detector_->AddObserver(this); -} - -UserActivityNotifier::~UserActivityNotifier() { - detector_->RemoveObserver(this); -} - -void UserActivityNotifier::OnUserActivity(const ui::Event* event) { - base::TimeTicks now = base::TimeTicks::Now(); - // InSeconds() truncates rather than rounding, so it's fine for this - // comparison. - if (last_notify_time_.is_null() || - (now - last_notify_time_).InSeconds() >= kNotifyIntervalSec) { - power_manager::UserActivityType type = power_manager::USER_ACTIVITY_OTHER; - if (event && event->type() == ui::ET_KEY_PRESSED) { - switch (static_cast<const ui::KeyEvent*>(event)->key_code()) { - case ui::VKEY_BRIGHTNESS_UP: - type = power_manager::USER_ACTIVITY_BRIGHTNESS_UP_KEY_PRESS; - break; - case ui::VKEY_BRIGHTNESS_DOWN: - type = power_manager::USER_ACTIVITY_BRIGHTNESS_DOWN_KEY_PRESS; - break; - default: - break; - } - } - - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - NotifyUserActivity(type); - last_notify_time_ = now; - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/power/user_activity_notifier.h b/chromium/ash/system/chromeos/power/user_activity_notifier.h deleted file mode 100644 index 78b2c431144..00000000000 --- a/chromium/ash/system/chromeos/power/user_activity_notifier.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_POWER_USER_ACTIVITY_NOTIFIER_H_ -#define ASH_SYSTEM_CHROMEOS_POWER_USER_ACTIVITY_NOTIFIER_H_ - -#include "ash/wm/user_activity_observer.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/time/time.h" - -namespace ash { - -class UserActivityDetector; - -namespace internal { - -// Notifies the power manager when the user is active. -class UserActivityNotifier : public UserActivityObserver { - public: - explicit UserActivityNotifier(UserActivityDetector* detector); - virtual ~UserActivityNotifier(); - - // UserActivityObserver implementation. - virtual void OnUserActivity(const ui::Event* event) OVERRIDE; - - private: - UserActivityDetector* detector_; // not owned - - // Last time that the power manager was notified. - base::TimeTicks last_notify_time_; - - DISALLOW_COPY_AND_ASSIGN(UserActivityNotifier); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_POWER_USER_ACTIVITY_NOTIFIER_H_ diff --git a/chromium/ash/system/chromeos/power/video_activity_notifier.cc b/chromium/ash/system/chromeos/power/video_activity_notifier.cc deleted file mode 100644 index 0f9ec2555e3..00000000000 --- a/chromium/ash/system/chromeos/power/video_activity_notifier.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/power/video_activity_notifier.h" - -#include "ash/shell.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/power_manager_client.h" - -namespace ash { -namespace internal { - -namespace { - -// Minimum number of seconds between notifications. -const int kNotifyIntervalSec = 5; - -} // namespace - -VideoActivityNotifier::VideoActivityNotifier(VideoDetector* detector) - : detector_(detector) { - detector_->AddObserver(this); -} - -VideoActivityNotifier::~VideoActivityNotifier() { - detector_->RemoveObserver(this); -} - -void VideoActivityNotifier::OnVideoDetected(bool is_fullscreen) { - base::TimeTicks now = base::TimeTicks::Now(); - if (last_notify_time_.is_null() || - (now - last_notify_time_).InSeconds() >= kNotifyIntervalSec) { - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - NotifyVideoActivity(is_fullscreen); - last_notify_time_ = now; - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/power/video_activity_notifier.h b/chromium/ash/system/chromeos/power/video_activity_notifier.h deleted file mode 100644 index 66569c4f7b7..00000000000 --- a/chromium/ash/system/chromeos/power/video_activity_notifier.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_POWER_VIDEO_ACTIVITY_NOTIFIER_H_ -#define ASH_SYSTEM_CHROMEOS_POWER_VIDEO_ACTIVITY_NOTIFIER_H_ - -#include "ash/wm/video_detector.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/time/time.h" - -namespace ash { -namespace internal { - -// Notifies the power manager when a video is playing. -class VideoActivityNotifier : public VideoDetectorObserver { - public: - explicit VideoActivityNotifier(VideoDetector* detector); - virtual ~VideoActivityNotifier(); - - // VideoDetectorObserver implementation. - virtual void OnVideoDetected(bool is_fullscreen) OVERRIDE; - - private: - VideoDetector* detector_; // not owned - - // Last time that the power manager was notified. - base::TimeTicks last_notify_time_; - - DISALLOW_COPY_AND_ASSIGN(VideoActivityNotifier); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_POWER_VIDEO_ACTIVITY_NOTIFIER_H_ diff --git a/chromium/ash/system/chromeos/screen_security/screen_capture_observer.h b/chromium/ash/system/chromeos/screen_security/screen_capture_observer.h deleted file mode 100644 index 6fca492a16b..00000000000 --- a/chromium/ash/system/chromeos/screen_security/screen_capture_observer.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_SCREEN_CAPTURE_SCREEN_CAPTURE_OBSERVER_H_ -#define ASH_SYSTEM_CHROMEOS_SCREEN_CAPTURE_SCREEN_CAPTURE_OBSERVER_H_ - -#include "base/callback.h" -#include "base/strings/string16.h" - -namespace ash { - -class ScreenCaptureObserver { - public: - // Called when screen capture is started. - virtual void OnScreenCaptureStart( - const base::Closure& stop_callback, - const base::string16& screen_capture_status) = 0; - - // Called when screen capture is stopped. - virtual void OnScreenCaptureStop() = 0; - - protected: - virtual ~ScreenCaptureObserver() {} -}; - -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_SCREEN_CAPTURE_SCREEN_CAPTURE_OBSERVER_H_ diff --git a/chromium/ash/system/chromeos/screen_security/screen_capture_tray_item.cc b/chromium/ash/system/chromeos/screen_security/screen_capture_tray_item.cc deleted file mode 100644 index 92e930956b8..00000000000 --- a/chromium/ash/system/chromeos/screen_security/screen_capture_tray_item.cc +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/screen_security/screen_capture_tray_item.h" - -#include "ash/shell.h" -#include "ash/system/system_notifier.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" - -using message_center::Notification; - -namespace ash { -namespace internal { -namespace { - -const char kScreenCaptureNotificationId[] = "chrome://screen/capture"; - -} // namespace - -ScreenCaptureTrayItem::ScreenCaptureTrayItem(SystemTray* system_tray) - : ScreenTrayItem(system_tray) { - Shell::GetInstance()->system_tray_notifier()-> - AddScreenCaptureObserver(this); -} - -ScreenCaptureTrayItem::~ScreenCaptureTrayItem() { - Shell::GetInstance()->system_tray_notifier()-> - RemoveScreenCaptureObserver(this); -} - -views::View* ScreenCaptureTrayItem::CreateTrayView(user::LoginStatus status) { - set_tray_view( - new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_SCREENSHARE)); - return tray_view(); -} - -views::View* ScreenCaptureTrayItem::CreateDefaultView( - user::LoginStatus status) { - set_default_view(new tray::ScreenStatusView( - this, - IDR_AURA_UBER_TRAY_SCREENSHARE_DARK, - screen_capture_status_, - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP))); - return default_view(); -} - -void ScreenCaptureTrayItem::CreateOrUpdateNotification() { - message_center::RichNotificationData data; - data.buttons.push_back(message_center::ButtonInfo( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_CAPTURE_STOP))); - ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); - scoped_ptr<Notification> notification(new Notification( - message_center::NOTIFICATION_TYPE_SIMPLE, - kScreenCaptureNotificationId, - screen_capture_status_, - base::string16() /* body is blank */, - resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK), - base::string16() /* display_source */, - message_center::NotifierId( - message_center::NotifierId::SYSTEM_COMPONENT, - system_notifier::kNotifierScreenCapture), - data, - new tray::ScreenNotificationDelegate(this))); - notification->SetSystemPriority(); - message_center::MessageCenter::Get()->AddNotification(notification.Pass()); -} - -std::string ScreenCaptureTrayItem::GetNotificationId() { - return kScreenCaptureNotificationId; -} - -void ScreenCaptureTrayItem::OnScreenCaptureStart( - const base::Closure& stop_callback, - const base::string16& screen_capture_status) { - screen_capture_status_ = screen_capture_status; - Start(stop_callback); -} - -void ScreenCaptureTrayItem::OnScreenCaptureStop() { - // We do not need to run the stop callback when - // screen capture is stopped externally. - set_is_started(false); - Update(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/screen_security/screen_capture_tray_item.h b/chromium/ash/system/chromeos/screen_security/screen_capture_tray_item.h deleted file mode 100644 index 92f6c8a7117..00000000000 --- a/chromium/ash/system/chromeos/screen_security/screen_capture_tray_item.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_SCREEN_CAPTURE_SCREEN_CAPTURE_TRAY_ITEM_H_ -#define ASH_SYSTEM_CHROMEOS_SCREEN_CAPTURE_SCREEN_CAPTURE_TRAY_ITEM_H_ - -#include "ash/system/chromeos/screen_security/screen_capture_observer.h" -#include "ash/system/chromeos/screen_security/screen_tray_item.h" - -namespace views { -class View; -} - -namespace ash { -namespace internal { - -class ASH_EXPORT ScreenCaptureTrayItem : public ScreenTrayItem, - public ScreenCaptureObserver { - public: - explicit ScreenCaptureTrayItem(SystemTray* system_tray); - virtual ~ScreenCaptureTrayItem(); - - private: - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - - // Overridden from ScreenTrayItem. - virtual void CreateOrUpdateNotification() OVERRIDE; - virtual std::string GetNotificationId() OVERRIDE; - - // Overridden from ScreenCaptureObserver. - virtual void OnScreenCaptureStart( - const base::Closure& stop_callback, - const base::string16& screen_capture_status) OVERRIDE; - virtual void OnScreenCaptureStop() OVERRIDE; - - base::string16 screen_capture_status_; - - DISALLOW_COPY_AND_ASSIGN(ScreenCaptureTrayItem); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_SCREEN_CAPTURE_SCREEN_CAPTURE_TRAY_ITEM_H_ diff --git a/chromium/ash/system/chromeos/screen_security/screen_share_observer.h b/chromium/ash/system/chromeos/screen_security/screen_share_observer.h deleted file mode 100644 index fb6a556fa2c..00000000000 --- a/chromium/ash/system/chromeos/screen_security/screen_share_observer.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_SCREEN_SHARE_SCREEN_SHARE_OBSERVER_H_ -#define ASH_SYSTEM_CHROMEOS_SCREEN_SHARE_SCREEN_SHARE_OBSERVER_H_ - -#include "base/callback.h" -#include "base/strings/string16.h" - -namespace ash { - -class ScreenShareObserver { - public: - // Called when screen share is started. - virtual void OnScreenShareStart( - const base::Closure& stop_callback, - const base::string16& helper_name) = 0; - - // Called when screen share is stopped. - virtual void OnScreenShareStop() = 0; - - protected: - virtual ~ScreenShareObserver() {} -}; - -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_SCREEN_SHARE_SCREEN_SHARE_OBSERVER_H_ diff --git a/chromium/ash/system/chromeos/screen_security/screen_share_tray_item.cc b/chromium/ash/system/chromeos/screen_security/screen_share_tray_item.cc deleted file mode 100644 index 93d858a65a6..00000000000 --- a/chromium/ash/system/chromeos/screen_security/screen_share_tray_item.cc +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/screen_security/screen_share_tray_item.h" - -#include "ash/shell.h" -#include "ash/system/system_notifier.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" - -using message_center::Notification; - -namespace ash { -namespace internal { -namespace { - -const char kScreenShareNotificationId[] = "chrome://screen/share"; - -} - -ScreenShareTrayItem::ScreenShareTrayItem(SystemTray* system_tray) - : ScreenTrayItem(system_tray) { - Shell::GetInstance()->system_tray_notifier()-> - AddScreenShareObserver(this); -} - -ScreenShareTrayItem::~ScreenShareTrayItem() { - Shell::GetInstance()->system_tray_notifier()-> - RemoveScreenShareObserver(this); -} - -views::View* ScreenShareTrayItem::CreateTrayView(user::LoginStatus status) { - set_tray_view( - new tray::ScreenTrayView(this, IDR_AURA_UBER_TRAY_SCREENSHARE)); - return tray_view(); -} - -views::View* ScreenShareTrayItem::CreateDefaultView(user::LoginStatus status) { - set_default_view(new tray::ScreenStatusView( - this, - IDR_AURA_UBER_TRAY_SCREENSHARE_DARK, - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED), - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_SCREEN_SHARE_STOP))); - return default_view(); -} - -void ScreenShareTrayItem::CreateOrUpdateNotification() { - base::string16 help_label_text; - if (!helper_name_.empty()) { - help_label_text = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED_NAME, - helper_name_); - } else { - help_label_text = l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_SCREEN_SHARE_BEING_HELPED); - } - - message_center::RichNotificationData data; - data.buttons.push_back(message_center::ButtonInfo( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCREEN_SHARE_STOP))); - ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); - scoped_ptr<Notification> notification(new Notification( - message_center::NOTIFICATION_TYPE_SIMPLE, - kScreenShareNotificationId, - help_label_text, - base::string16() /* body is blank */, - resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK), - base::string16() /* display_source */, - message_center::NotifierId( - message_center::NotifierId::SYSTEM_COMPONENT, - system_notifier::kNotifierScreenShare), - data, - new tray::ScreenNotificationDelegate(this))); - notification->SetSystemPriority(); - message_center::MessageCenter::Get()->AddNotification(notification.Pass()); -} - -std::string ScreenShareTrayItem::GetNotificationId() { - return kScreenShareNotificationId; -} - -void ScreenShareTrayItem::OnScreenShareStart( - const base::Closure& stop_callback, - const base::string16& helper_name) { - helper_name_ = helper_name; - Start(stop_callback); -} - -void ScreenShareTrayItem::OnScreenShareStop() { - // We do not need to run the stop callback - // when screening is stopped externally. - set_is_started(false); - Update(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/screen_security/screen_share_tray_item.h b/chromium/ash/system/chromeos/screen_security/screen_share_tray_item.h deleted file mode 100644 index 14f26e5667f..00000000000 --- a/chromium/ash/system/chromeos/screen_security/screen_share_tray_item.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_SCREEN_SHARE_SCREEN_SHARE_TRAY_ITEM_H_ -#define ASH_SYSTEM_CHROMEOS_SCREEN_SHARE_SCREEN_SHARE_TRAY_ITEM_H_ - -#include "ash/system/chromeos/screen_security/screen_share_observer.h" -#include "ash/system/chromeos/screen_security/screen_tray_item.h" - -namespace views { -class View; -} - -namespace ash { -namespace internal { - -class ASH_EXPORT ScreenShareTrayItem : public ScreenTrayItem, - public ScreenShareObserver { - public: - explicit ScreenShareTrayItem(SystemTray* system_tray); - virtual ~ScreenShareTrayItem(); - - private: - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - - // Overridden from ScreenTrayItem. - virtual void CreateOrUpdateNotification() OVERRIDE; - virtual std::string GetNotificationId() OVERRIDE; - - // Overridden from ScreenShareObserver. - virtual void OnScreenShareStart( - const base::Closure& stop_callback, - const base::string16& helper_name) OVERRIDE; - virtual void OnScreenShareStop() OVERRIDE; - - base::string16 helper_name_; - - DISALLOW_COPY_AND_ASSIGN(ScreenShareTrayItem); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_SCREEN_SHARE_SCREEN_SHARE_TRAY_ITEM_H_ diff --git a/chromium/ash/system/chromeos/screen_security/screen_tray_item.cc b/chromium/ash/system/chromeos/screen_security/screen_tray_item.cc deleted file mode 100644 index 7e7dc5fd0ee..00000000000 --- a/chromium/ash/system/chromeos/screen_security/screen_tray_item.cc +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/screen_security/screen_tray_item.h" - -#include "ash/system/tray/fixed_sized_image_view.h" -#include "ash/system/tray/tray_constants.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/message_center/message_center.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" - -namespace { -const int kStopButtonRightPadding = 18; -} // namespace - -namespace ash { -namespace internal { - -namespace tray { - -// ScreenTrayView implementations. -ScreenTrayView::ScreenTrayView(ScreenTrayItem* screen_tray_item, int icon_id) - : TrayItemView(screen_tray_item), - screen_tray_item_(screen_tray_item) { - CreateImageView(); - image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() - .GetImageNamed(icon_id).ToImageSkia()); - - Update(); -} - -ScreenTrayView::~ScreenTrayView() { -} - -void ScreenTrayView::Update() { - SetVisible(screen_tray_item_->is_started()); -} - - -// ScreenStatusView implementations. -ScreenStatusView::ScreenStatusView(ScreenTrayItem* screen_tray_item, - int icon_id, - const base::string16& label_text, - const base::string16& stop_button_text) - : screen_tray_item_(screen_tray_item), - icon_(NULL), - label_(NULL), - stop_button_(NULL), - icon_id_(icon_id), - label_text_(label_text), - stop_button_text_(stop_button_text) { - CreateItems(); - Update(); -} - -ScreenStatusView::~ScreenStatusView() { -} - -void ScreenStatusView::Layout() { - views::View::Layout(); - - // Give the stop button the space it requests. - gfx::Size stop_size = stop_button_->GetPreferredSize(); - gfx::Rect stop_bounds(stop_size); - stop_bounds.set_x(width() - stop_size.width() - kStopButtonRightPadding); - stop_bounds.set_y((height() - stop_size.height()) / 2); - stop_button_->SetBoundsRect(stop_bounds); - - // Adjust the label's bounds in case it got cut off by |stop_button_|. - if (label_->bounds().Intersects(stop_button_->bounds())) { - gfx::Rect label_bounds = label_->bounds(); - label_bounds.set_width( - stop_button_->x() - kTrayPopupPaddingBetweenItems - label_->x()); - label_->SetBoundsRect(label_bounds); - } -} - -void ScreenStatusView::ButtonPressed( - views::Button* sender, - const ui::Event& event) { - DCHECK(sender == stop_button_); - screen_tray_item_->Stop(); -} - -void ScreenStatusView::CreateItems() { - set_background(views::Background::CreateSolidBackground(kBackgroundColor)); - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, - kTrayPopupPaddingHorizontal, - 0, - kTrayPopupPaddingBetweenItems)); - icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight); - icon_->SetImage(bundle.GetImageNamed(icon_id_).ToImageSkia()); - AddChildView(icon_); - label_ = new views::Label; - label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - label_->SetMultiLine(true); - label_->SetText(label_text_); - AddChildView(label_); - - stop_button_ = new TrayPopupLabelButton(this, stop_button_text_); - AddChildView(stop_button_); -} - -void ScreenStatusView::Update() { - // Hide the notification bubble when the ash tray bubble opens. - screen_tray_item_->HideNotificationView(); - SetVisible(screen_tray_item_->is_started()); -} - -ScreenNotificationDelegate::ScreenNotificationDelegate( - ScreenTrayItem* screen_tray) - : screen_tray_(screen_tray) { -} - -ScreenNotificationDelegate::~ScreenNotificationDelegate() { -} - -void ScreenNotificationDelegate::Display() { -} - -void ScreenNotificationDelegate::Error() { -} - -void ScreenNotificationDelegate::Close(bool by_user) { -} - -void ScreenNotificationDelegate::Click() { -} - -void ScreenNotificationDelegate::ButtonClick(int button_index) { - DCHECK_EQ(0, button_index); - screen_tray_->Stop(); -} - -} // namespace tray - -ScreenTrayItem::ScreenTrayItem(SystemTray* system_tray) - : SystemTrayItem(system_tray), - tray_view_(NULL), - default_view_(NULL), - is_started_(false), - stop_callback_(base::Bind(&base::DoNothing)) { -} - -ScreenTrayItem::~ScreenTrayItem() {} - -void ScreenTrayItem::Update() { - if (tray_view_) - tray_view_->Update(); - if (default_view_) - default_view_->Update(); - if (is_started_) { - CreateOrUpdateNotification(); - } else { - message_center::MessageCenter::Get()->RemoveNotification( - GetNotificationId(), false /* by_user */); - } -} - -void ScreenTrayItem::Start(const base::Closure& stop_callback) { - stop_callback_ = stop_callback; - is_started_ = true; - - if (tray_view_) - tray_view_->Update(); - - if (default_view_) - default_view_->Update(); - - if (!system_tray()->HasSystemBubbleType( - SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { - CreateOrUpdateNotification(); - } -} - -void ScreenTrayItem::Stop() { - is_started_ = false; - Update(); - - if (stop_callback_.is_null()) - return; - - base::Closure callback = stop_callback_; - stop_callback_.Reset(); - callback.Run(); -} - -void ScreenTrayItem::DestroyTrayView() { - tray_view_ = NULL; -} - -void ScreenTrayItem::DestroyDefaultView() { - default_view_ = NULL; -} - -void ScreenTrayItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { - if (!tray_view_) - return; - - // Center the item dependent on the orientation of the shelf. - views::BoxLayout::Orientation layout = - (alignment == ash::SHELF_ALIGNMENT_BOTTOM || - alignment == ash::SHELF_ALIGNMENT_TOP) - ? views::BoxLayout::kHorizontal - : views::BoxLayout::kVertical; - tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); - tray_view_->Layout(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/screen_security/screen_tray_item.h b/chromium/ash/system/chromeos/screen_security/screen_tray_item.h deleted file mode 100644 index ddbb1264749..00000000000 --- a/chromium/ash/system/chromeos/screen_security/screen_tray_item.h +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_SCREEN_TRAY_ITEM_H_ -#define ASH_SYSTEM_CHROMEOS_SCREEN_TRAY_ITEM_H_ - -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_item.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_item_view.h" -#include "ash/system/tray/tray_notification_view.h" -#include "ash/system/tray/tray_popup_label_button.h" -#include "ui/message_center/notification_delegate.h" -#include "ui/views/controls/button/button.h" -#include "ui/views/controls/image_view.h" - -namespace views { -class View; -} - -namespace ash { -namespace internal { - -class ScreenTrayItem; - -namespace tray { - -class ScreenTrayView : public TrayItemView { - public: - ScreenTrayView(ScreenTrayItem* screen_tray_item, int icon_id); - virtual ~ScreenTrayView(); - - void Update(); - - private: - ScreenTrayItem* screen_tray_item_; - - DISALLOW_COPY_AND_ASSIGN(ScreenTrayView); -}; - -class ScreenStatusView : public views::View, - public views::ButtonListener { - public: - ScreenStatusView(ScreenTrayItem* screen_tray_item, - int icon_id, - const base::string16& label_text, - const base::string16& stop_button_text); - virtual ~ScreenStatusView(); - - // Overridden from views::View. - virtual void Layout() OVERRIDE; - - // Overridden from views::ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE; - - void CreateItems(); - void Update(); - - private: - ScreenTrayItem* screen_tray_item_; - views::ImageView* icon_; - views::Label* label_; - TrayPopupLabelButton* stop_button_; - int icon_id_; - base::string16 label_text_; - base::string16 stop_button_text_; - - DISALLOW_COPY_AND_ASSIGN(ScreenStatusView); -}; - -class ScreenNotificationDelegate : public message_center::NotificationDelegate { - public: - explicit ScreenNotificationDelegate(ScreenTrayItem* screen_tray); - - // message_center::NotificationDelegate overrides: - virtual void Display() OVERRIDE; - virtual void Error() OVERRIDE; - virtual void Close(bool by_user) OVERRIDE; - virtual void Click() OVERRIDE; - virtual void ButtonClick(int button_index) OVERRIDE; - - protected: - virtual ~ScreenNotificationDelegate(); - - private: - ScreenTrayItem* screen_tray_; - - DISALLOW_COPY_AND_ASSIGN(ScreenNotificationDelegate); -}; - -} // namespace tray - - -// The base tray item for screen capture and screen sharing. The -// Start method brings up a notification and a tray item, and the user -// can stop the screen capture/sharing by pressing the stop button. -class ASH_EXPORT ScreenTrayItem : public SystemTrayItem { - public: - explicit ScreenTrayItem(SystemTray* system_tray); - virtual ~ScreenTrayItem(); - - tray::ScreenTrayView* tray_view() { return tray_view_; } - void set_tray_view(tray::ScreenTrayView* tray_view) { - tray_view_ = tray_view; - } - - tray::ScreenStatusView* default_view() { return default_view_; } - void set_default_view(tray::ScreenStatusView* default_view) { - default_view_ = default_view; - } - - bool is_started() const { return is_started_; } - void set_is_started(bool is_started) { is_started_ = is_started; } - - void Update(); - void Start(const base::Closure& stop_callback); - void Stop(); - - // Creates or updates the notification for the tray item. - virtual void CreateOrUpdateNotification() = 0; - - // Returns the id of the notification for the tray item. - virtual std::string GetNotificationId() = 0; - - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE = 0; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE = 0; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) OVERRIDE; - - private: - tray::ScreenTrayView* tray_view_; - tray::ScreenStatusView* default_view_; - bool is_started_; - base::Closure stop_callback_; - - DISALLOW_COPY_AND_ASSIGN(ScreenTrayItem); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_SCREEN_TRAY_ITEM_H_ diff --git a/chromium/ash/system/chromeos/screen_security/screen_tray_item_unittest.cc b/chromium/ash/system/chromeos/screen_security/screen_tray_item_unittest.cc deleted file mode 100644 index 928dad7c1cc..00000000000 --- a/chromium/ash/system/chromeos/screen_security/screen_tray_item_unittest.cc +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/screen_security/screen_tray_item.h" - -#include "ash/shell.h" -#include "ash/system/chromeos/screen_security/screen_capture_tray_item.h" -#include "ash/system/chromeos/screen_security/screen_share_tray_item.h" -#include "ash/system/tray/tray_item_view.h" -#include "ash/test/ash_test_base.h" -#include "base/callback.h" -#include "base/strings/utf_string_conversions.h" -#include "ui/events/event.h" -#include "ui/gfx/point.h" -#include "ui/message_center/message_center.h" -#include "ui/views/view.h" - -namespace ash { -namespace internal { - -// Test with unicode strings. -const char kTestScreenCaptureAppName[] = - "\xE0\xB2\xA0\x5F\xE0\xB2\xA0 (Screen Capture Test)"; -const char kTestScreenShareHelperName[] = - "\xE5\xAE\x8B\xE8\x85\xBE (Screen Share Test)"; - -SystemTray* GetSystemTray() { - return Shell::GetInstance()->GetPrimarySystemTray(); -} - -SystemTrayNotifier* GetSystemTrayNotifier() { - return Shell::GetInstance()->system_tray_notifier(); -} - -void ClickViewCenter(views::View* view) { - gfx::Point click_location_in_local = - gfx::Point(view->width() / 2, view->height() / 2); - view->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED, - click_location_in_local, - click_location_in_local, - ui::EF_NONE)); -} - -class ScreenTrayItemTest : public ash::test::AshTestBase { - public: - ScreenTrayItemTest() - : tray_item_(NULL), stop_callback_hit_count_(0) {} - virtual ~ScreenTrayItemTest() {} - - ScreenTrayItem* tray_item() { return tray_item_; } - void set_tray_item(ScreenTrayItem* tray_item) { tray_item_ = tray_item; } - - int stop_callback_hit_count() const { return stop_callback_hit_count_; } - - virtual void SetUp() OVERRIDE { - test::AshTestBase::SetUp(); - TrayItemView::DisableAnimationsForTest(); - } - - void StartSession() { - tray_item_->Start( - base::Bind(&ScreenTrayItemTest::StopCallback, base::Unretained(this))); - } - - void StopSession() { - tray_item_->Stop(); - } - - void StopCallback() { - stop_callback_hit_count_++; - } - - private: - ScreenTrayItem* tray_item_; - int stop_callback_hit_count_; - - DISALLOW_COPY_AND_ASSIGN(ScreenTrayItemTest); -}; - -class ScreenCaptureTest : public ScreenTrayItemTest { - public: - ScreenCaptureTest() {} - virtual ~ScreenCaptureTest() {} - - virtual void SetUp() OVERRIDE { - ScreenTrayItemTest::SetUp(); - // This tray item is owned by its parent system tray view and will - // be deleted automatically when its parent is destroyed in AshTestBase. - ScreenTrayItem* tray_item = new ScreenCaptureTrayItem(GetSystemTray()); - GetSystemTray()->AddTrayItem(tray_item); - set_tray_item(tray_item); - } - - DISALLOW_COPY_AND_ASSIGN(ScreenCaptureTest); -}; - -class ScreenShareTest : public ScreenTrayItemTest { - public: - ScreenShareTest() {} - virtual ~ScreenShareTest() {} - - virtual void SetUp() OVERRIDE { - ScreenTrayItemTest::SetUp(); - // This tray item is owned by its parent system tray view and will - // be deleted automatically when its parent is destroyed in AshTestBase. - ScreenTrayItem* tray_item = new ScreenShareTrayItem(GetSystemTray()); - GetSystemTray()->AddTrayItem(tray_item); - set_tray_item(tray_item); - } - - DISALLOW_COPY_AND_ASSIGN(ScreenShareTest); -}; - -void TestStartAndStop(ScreenTrayItemTest* test) { - ScreenTrayItem* tray_item = test->tray_item(); - - EXPECT_FALSE(tray_item->is_started()); - EXPECT_EQ(0, test->stop_callback_hit_count()); - - test->StartSession(); - EXPECT_TRUE(tray_item->is_started()); - - test->StopSession(); - EXPECT_FALSE(tray_item->is_started()); - EXPECT_EQ(1, test->stop_callback_hit_count()); -} - -TEST_F(ScreenCaptureTest, StartAndStop) { TestStartAndStop(this); } -TEST_F(ScreenShareTest, StartAndStop) { TestStartAndStop(this); } - -void TestNotificationStartAndStop(ScreenTrayItemTest* test, - const base::Closure& start_function, - const base::Closure& stop_function) { - ScreenTrayItem* tray_item = test->tray_item(); - EXPECT_FALSE(tray_item->is_started()); - - start_function.Run(); - EXPECT_TRUE(tray_item->is_started()); - - // The stop callback shouldn't be called because we stopped - // through the notification system. - stop_function.Run(); - EXPECT_FALSE(tray_item->is_started()); - EXPECT_EQ(0, test->stop_callback_hit_count()); -} - -TEST_F(ScreenCaptureTest, NotificationStartAndStop) { - base::Closure start_function = - base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStart, - base::Unretained(GetSystemTrayNotifier()), - base::Bind(&ScreenTrayItemTest::StopCallback, - base::Unretained(this)), - base::UTF8ToUTF16(kTestScreenCaptureAppName)); - - base::Closure stop_function = - base::Bind(&SystemTrayNotifier::NotifyScreenCaptureStop, - base::Unretained(GetSystemTrayNotifier())); - - TestNotificationStartAndStop(this, start_function, stop_function); -} - -TEST_F(ScreenShareTest, NotificationStartAndStop) { - base::Closure start_func = - base::Bind(&SystemTrayNotifier::NotifyScreenShareStart, - base::Unretained(GetSystemTrayNotifier()), - base::Bind(&ScreenTrayItemTest::StopCallback, - base::Unretained(this)), - base::UTF8ToUTF16(kTestScreenShareHelperName)); - - base::Closure stop_func = - base::Bind(&SystemTrayNotifier::NotifyScreenShareStop, - base::Unretained(GetSystemTrayNotifier())); - - TestNotificationStartAndStop(this, start_func, stop_func); -} - -void TestNotificationView(ScreenTrayItemTest* test) { - ScreenTrayItem* tray_item = test->tray_item(); - - test->StartSession(); - message_center::MessageCenter* message_center = - message_center::MessageCenter::Get(); - EXPECT_TRUE(message_center->HasNotification(tray_item->GetNotificationId())); - test->StopSession(); -} - -TEST_F(ScreenCaptureTest, NotificationView) { TestNotificationView(this); } -TEST_F(ScreenShareTest, NotificationView) { TestNotificationView(this); } - -void TestSystemTrayInteraction(ScreenTrayItemTest* test) { - ScreenTrayItem* tray_item = test->tray_item(); - EXPECT_FALSE(tray_item->tray_view()->visible()); - - const std::vector<SystemTrayItem*>& tray_items = - GetSystemTray()->GetTrayItems(); - EXPECT_NE(std::find(tray_items.begin(), tray_items.end(), tray_item), - tray_items.end()); - - test->StartSession(); - EXPECT_TRUE(tray_item->tray_view()->visible()); - - // The default view should be created in a new bubble. - GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); - EXPECT_TRUE(tray_item->default_view()); - GetSystemTray()->CloseSystemBubble(); - EXPECT_FALSE(tray_item->default_view()); - - test->StopSession(); - EXPECT_FALSE(tray_item->tray_view()->visible()); - - // The default view should not be visible because session is stopped. - GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); - EXPECT_FALSE(tray_item->default_view()->visible()); -} - -TEST_F(ScreenCaptureTest, SystemTrayInteraction) { - TestSystemTrayInteraction(this); -} - -TEST_F(ScreenShareTest, SystemTrayInteraction) { - TestSystemTrayInteraction(this); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/settings/tray_settings.cc b/chromium/ash/system/chromeos/settings/tray_settings.cc deleted file mode 100644 index 8868b7cf50d..00000000000 --- a/chromium/ash/system/chromeos/settings/tray_settings.cc +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/settings/tray_settings.h" - -#include "ash/shell.h" -#include "ash/system/chromeos/power/power_status.h" -#include "ash/system/chromeos/power/power_status_view.h" -#include "ash/system/tray/actionable_view.h" -#include "ash/system/tray/fixed_sized_image_view.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/tray_constants.h" -#include "base/logging.h" -#include "base/strings/utf_string_conversions.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "third_party/skia/include/core/SkColor.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/view.h" - -namespace ash { -namespace internal { - -namespace tray { - -class SettingsDefaultView : public ActionableView, - public PowerStatus::Observer { - public: - explicit SettingsDefaultView(user::LoginStatus status) - : login_status_(status), - label_(NULL), - power_status_view_(NULL) { - PowerStatus::Get()->AddObserver(this); - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, - ash::kTrayPopupPaddingHorizontal, 0, - ash::kTrayPopupPaddingBetweenItems)); - - bool power_view_right_align = false; - if (login_status_ != user::LOGGED_IN_NONE && - login_status_ != user::LOGGED_IN_LOCKED) { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - views::ImageView* icon = - new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); - icon->SetImage( - rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia()); - AddChildView(icon); - - base::string16 text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_SETTINGS); - label_ = new views::Label(text); - AddChildView(label_); - SetAccessibleName(text); - - power_view_right_align = true; - } - - if (PowerStatus::Get()->IsBatteryPresent()) { - power_status_view_ = new ash::internal::PowerStatusView( - ash::internal::PowerStatusView::VIEW_DEFAULT, power_view_right_align); - AddChildView(power_status_view_); - OnPowerStatusChanged(); - } - } - - virtual ~SettingsDefaultView() { - PowerStatus::Get()->RemoveObserver(this); - } - - // Overridden from ash::internal::ActionableView. - virtual bool PerformAction(const ui::Event& event) OVERRIDE { - if (login_status_ == user::LOGGED_IN_NONE || - login_status_ == user::LOGGED_IN_LOCKED) - return false; - - ash::Shell::GetInstance()->system_tray_delegate()->ShowSettings(); - return true; - } - - // Overridden from views::View. - virtual void Layout() OVERRIDE { - views::View::Layout(); - - if (label_ && power_status_view_) { - // Let the box-layout do the layout first. Then move power_status_view_ - // to right align if it is created. - gfx::Size size = power_status_view_->GetPreferredSize(); - gfx::Rect bounds(size); - bounds.set_x(width() - size.width() - ash::kTrayPopupPaddingBetweenItems); - bounds.set_y((height() - size.height()) / 2); - power_status_view_->SetBoundsRect(bounds); - } - } - - // Overridden from views::View. - virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { - views::View::ChildPreferredSizeChanged(child); - Layout(); - } - - // Overridden from PowerStatus::Observer. - virtual void OnPowerStatusChanged() OVERRIDE { - if (!PowerStatus::Get()->IsBatteryPresent()) - return; - - base::string16 accessible_name = label_ ? - label_->text() + ASCIIToUTF16(", ") + - PowerStatus::Get()->GetAccessibleNameString() : - PowerStatus::Get()->GetAccessibleNameString(); - SetAccessibleName(accessible_name); - } - - private: - user::LoginStatus login_status_; - views::Label* label_; - ash::internal::PowerStatusView* power_status_view_; - - DISALLOW_COPY_AND_ASSIGN(SettingsDefaultView); - }; - -} // namespace tray - -TraySettings::TraySettings(SystemTray* system_tray) - : SystemTrayItem(system_tray), - default_view_(NULL) { -} - -TraySettings::~TraySettings() { -} - -views::View* TraySettings::CreateTrayView(user::LoginStatus status) { - return NULL; -} - -views::View* TraySettings::CreateDefaultView(user::LoginStatus status) { - if ((status == user::LOGGED_IN_NONE || status == user::LOGGED_IN_LOCKED) && - !PowerStatus::Get()->IsBatteryPresent()) - return NULL; - - if (!ash::Shell::GetInstance()->system_tray_delegate()->ShouldShowSettings()) - return NULL; - - CHECK(default_view_ == NULL); - default_view_ = new tray::SettingsDefaultView(status); - return default_view_; -} - -views::View* TraySettings::CreateDetailedView(user::LoginStatus status) { - NOTIMPLEMENTED(); - return NULL; -} - -void TraySettings::DestroyTrayView() { -} - -void TraySettings::DestroyDefaultView() { - default_view_ = NULL; -} - -void TraySettings::DestroyDetailedView() { -} - -void TraySettings::UpdateAfterLoginStatusChange(user::LoginStatus status) { -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/settings/tray_settings.h b/chromium/ash/system/chromeos/settings/tray_settings.h deleted file mode 100644 index e48aad3b55d..00000000000 --- a/chromium/ash/system/chromeos/settings/tray_settings.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_SETTINGS_TRAY_SETTINGS_H_ -#define ASH_SYSTEM_CHROMEOS_SETTINGS_TRAY_SETTINGS_H_ - -#include "ash/system/tray/system_tray_item.h" - -namespace ash { -namespace internal { - -namespace tray { -class SettingsDefaultView; -} - -class TraySettings : public SystemTrayItem { - public: - explicit TraySettings(SystemTray* system_tray); - virtual ~TraySettings(); - - private: - // Overridden from SystemTrayItem - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - - tray::SettingsDefaultView* default_view_; - - DISALLOW_COPY_AND_ASSIGN(TraySettings); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_SETTINGS_TRAY_SETTINGS_H_ diff --git a/chromium/ash/system/chromeos/system_clock_observer.cc b/chromium/ash/system/chromeos/system_clock_observer.cc deleted file mode 100644 index c5ab20c3d51..00000000000 --- a/chromium/ash/system/chromeos/system_clock_observer.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/system_clock_observer.h" - -#include "ash/shell.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "chromeos/dbus/dbus_thread_manager.h" - -namespace ash { -namespace internal { - -SystemClockObserver::SystemClockObserver() { - chromeos::DBusThreadManager::Get()->GetSystemClockClient() - ->AddObserver(this); - chromeos::system::TimezoneSettings::GetInstance()->AddObserver(this); -} - -SystemClockObserver::~SystemClockObserver() { - chromeos::DBusThreadManager::Get()->GetSystemClockClient() - ->RemoveObserver(this); - chromeos::system::TimezoneSettings::GetInstance()->RemoveObserver(this); -} - -void SystemClockObserver::SystemClockUpdated() { - Shell::GetInstance()->system_tray_notifier() - ->NotifySystemClockTimeUpdated(); -} - -void SystemClockObserver::TimezoneChanged(const icu::TimeZone& timezone) { - Shell::GetInstance()->system_tray_notifier()->NotifyRefreshClock(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/system_clock_observer.h b/chromium/ash/system/chromeos/system_clock_observer.h deleted file mode 100644 index e2625a8cf4c..00000000000 --- a/chromium/ash/system/chromeos/system_clock_observer.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_SYSTEM_CLOCK_OBSERVER_H_ -#define ASH_SYSTEM_CHROMEOS_SYSTEM_CLOCK_OBSERVER_H_ - -#include "chromeos/dbus/system_clock_client.h" -#include "chromeos/settings/timezone_settings.h" - -namespace ash { -namespace internal { - -class SystemClockObserver - : public chromeos::SystemClockClient::Observer, - public chromeos::system::TimezoneSettings::Observer { - public: - SystemClockObserver(); - virtual ~SystemClockObserver(); - - // chromeos::SystemClockClient::Observer - virtual void SystemClockUpdated() OVERRIDE; - - // chromeos::system::TimezoneSettings::Observer - virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(SystemClockObserver); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_SYSTEM_CLOCK_OBSERVER_H_ diff --git a/chromium/ash/system/chromeos/tray_display.cc b/chromium/ash/system/chromeos/tray_display.cc deleted file mode 100644 index 35627e1ae2b..00000000000 --- a/chromium/ash/system/chromeos/tray_display.cc +++ /dev/null @@ -1,429 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/tray_display.h" - -#include "ash/display/display_controller.h" -#include "ash/display/display_manager.h" -#include "ash/shell.h" -#include "ash/system/system_notifier.h" -#include "ash/system/tray/actionable_view.h" -#include "ash/system/tray/fixed_sized_image_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_notification_view.h" -#include "base/bind.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" -#include "ui/message_center/notification_delegate.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" - -using message_center::Notification; - -namespace ash { -namespace internal { -namespace { - -DisplayManager* GetDisplayManager() { - return Shell::GetInstance()->display_manager(); -} - -base::string16 GetDisplayName(int64 display_id) { - return UTF8ToUTF16(GetDisplayManager()->GetDisplayNameForId(display_id)); -} - -base::string16 GetDisplaySize(int64 display_id) { - DisplayManager* display_manager = GetDisplayManager(); - - const gfx::Display* display = &display_manager->GetDisplayForId(display_id); - - // We don't show display size for mirrored display. Fallback - // to empty string if this happens on release build. - bool mirrored_display = display_manager->mirrored_display_id() == display_id; - DCHECK(!mirrored_display); - if (mirrored_display) - return base::string16(); - - DCHECK(display->is_valid()); - return UTF8ToUTF16(display->size().ToString()); -} - -// Returns 1-line information for the specified display, like -// "InternalDisplay: 1280x750" -base::string16 GetDisplayInfoLine(int64 display_id) { - const DisplayInfo& display_info = - GetDisplayManager()->GetDisplayInfo(display_id); - if (GetDisplayManager()->mirrored_display_id() == display_id) - return GetDisplayName(display_id); - - base::string16 size_text = GetDisplaySize(display_id); - base::string16 display_data; - if (display_info.has_overscan()) { - display_data = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, - size_text, - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN)); - } else { - display_data = size_text; - } - - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, - GetDisplayName(display_id), - display_data); -} - -base::string16 GetAllDisplayInfo() { - DisplayManager* display_manager = GetDisplayManager(); - std::vector<base::string16> lines; - int64 internal_id = gfx::Display::kInvalidDisplayID; - // Make sure to show the internal display first. - if (display_manager->HasInternalDisplay() && - display_manager->IsInternalDisplayId( - display_manager->first_display_id())) { - internal_id = display_manager->first_display_id(); - lines.push_back(GetDisplayInfoLine(internal_id)); - } - - for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { - int64 id = display_manager->GetDisplayAt(i).id(); - if (id == internal_id) - continue; - lines.push_back(GetDisplayInfoLine(id)); - } - - return JoinString(lines, '\n'); -} - -void OpenSettings() { - // switch is intentionally introduced without default, to cause an error when - // a new type of login status is introduced. - switch (Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()) { - case user::LOGGED_IN_NONE: - case user::LOGGED_IN_LOCKED: - return; - - case user::LOGGED_IN_USER: - case user::LOGGED_IN_OWNER: - case user::LOGGED_IN_GUEST: - case user::LOGGED_IN_RETAIL_MODE: - case user::LOGGED_IN_PUBLIC: - case user::LOGGED_IN_LOCALLY_MANAGED: - case user::LOGGED_IN_KIOSK_APP: - Shell::GetInstance()->system_tray_delegate()->ShowDisplaySettings(); - } -} - -} // namespace - -const char TrayDisplay::kNotificationId[] = "chrome://settings/display"; - -class DisplayView : public internal::ActionableView { - public: - explicit DisplayView() { - SetLayoutManager(new views::BoxLayout( - views::BoxLayout::kHorizontal, - kTrayPopupPaddingHorizontal, 0, - kTrayPopupPaddingBetweenItems)); - - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - image_ = new internal::FixedSizedImageView(0, kTrayPopupItemHeight); - image_->SetImage( - bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia()); - AddChildView(image_); - - label_ = new views::Label(); - label_->SetMultiLine(true); - label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - AddChildView(label_); - Update(); - } - - virtual ~DisplayView() {} - - void Update() { - base::string16 message = GetTrayDisplayMessage(NULL); - if (message.empty() && ShouldShowFirstDisplayInfo()) - message = GetDisplayInfoLine(GetDisplayManager()->first_display_id()); - SetVisible(!message.empty()); - label_->SetText(message); - Layout(); - } - - const views::Label* label() const { return label_; } - - // Overridden from views::View. - virtual bool GetTooltipText(const gfx::Point& p, - base::string16* tooltip) const OVERRIDE { - base::string16 tray_message = GetTrayDisplayMessage(NULL); - base::string16 display_message = GetAllDisplayInfo(); - if (tray_message.empty() && display_message.empty()) - return false; - - *tooltip = tray_message + ASCIIToUTF16("\n") + display_message; - return true; - } - - // Returns the name of the currently connected external display. - // This should not be used when the external display is used for - // mirroring. - static base::string16 GetExternalDisplayName() { - DisplayManager* display_manager = GetDisplayManager(); - DCHECK(!display_manager->IsMirrored()); - - int64 external_id = gfx::Display::kInvalidDisplayID; - for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { - int64 id = display_manager->GetDisplayAt(i).id(); - if (id != gfx::Display::InternalDisplayId()) { - external_id = id; - break; - } - } - - if (external_id == gfx::Display::kInvalidDisplayID) { - return l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); - } - - // The external display name may have an annotation of "(width x height)" in - // case that the display is rotated or its resolution is changed. - base::string16 name = GetDisplayName(external_id); - const DisplayInfo& display_info = - display_manager->GetDisplayInfo(external_id); - if (display_info.rotation() != gfx::Display::ROTATE_0 || - display_info.configured_ui_scale() != 1.0f || - !display_info.overscan_insets_in_dip().empty()) { - name = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, - name, GetDisplaySize(external_id)); - } else if (display_info.overscan_insets_in_dip().empty() && - display_info.has_overscan()) { - name = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, - name, l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN)); - } - - return name; - } - - static base::string16 GetTrayDisplayMessage( - base::string16* additional_message_out) { - DisplayManager* display_manager = GetDisplayManager(); - if (display_manager->GetNumDisplays() > 1) { - if (GetDisplayManager()->HasInternalDisplay()) { - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetExternalDisplayName()); - } - return l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); - } - - if (display_manager->IsMirrored()) { - if (GetDisplayManager()->HasInternalDisplay()) { - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, - GetDisplayName(display_manager->mirrored_display_id())); - } - return l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL); - } - - int64 primary_id = Shell::GetScreen()->GetPrimaryDisplay().id(); - if (display_manager->HasInternalDisplay() && - !display_manager->IsInternalDisplayId(primary_id)) { - if (additional_message_out) { - *additional_message_out = l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION); - } - return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED); - } - - return base::string16(); - } - - private: - bool ShouldShowFirstDisplayInfo() const { - const DisplayInfo& display_info = GetDisplayManager()->GetDisplayInfo( - GetDisplayManager()->first_display_id()); - return display_info.rotation() != gfx::Display::ROTATE_0 || - display_info.configured_ui_scale() != 1.0f || - !display_info.overscan_insets_in_dip().empty() || - display_info.has_overscan(); - } - - // Overridden from ActionableView. - virtual bool PerformAction(const ui::Event& event) OVERRIDE { - OpenSettings(); - return true; - } - - virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE { - int label_max_width = bounds().width() - kTrayPopupPaddingHorizontal * 2 - - kTrayPopupPaddingBetweenItems - image_->GetPreferredSize().width(); - label_->SizeToFit(label_max_width); - } - - views::ImageView* image_; - views::Label* label_; - - DISALLOW_COPY_AND_ASSIGN(DisplayView); -}; - -TrayDisplay::TrayDisplay(SystemTray* system_tray) - : SystemTrayItem(system_tray), - default_(NULL) { - Shell::GetInstance()->display_controller()->AddObserver(this); - UpdateDisplayInfo(NULL); -} - -TrayDisplay::~TrayDisplay() { - Shell::GetInstance()->display_controller()->RemoveObserver(this); -} - -void TrayDisplay::UpdateDisplayInfo(TrayDisplay::DisplayInfoMap* old_info) { - if (old_info) - old_info->swap(display_info_); - display_info_.clear(); - - DisplayManager* display_manager = GetDisplayManager(); - for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { - int64 id = display_manager->GetDisplayAt(i).id(); - display_info_[id] = display_manager->GetDisplayInfo(id); - } -} - -bool TrayDisplay::GetDisplayMessageForNotification( - const TrayDisplay::DisplayInfoMap& old_info, - base::string16* message_out, - base::string16* additional_message_out) { - // Display is added or removed. Use the same message as the one in - // the system tray. - if (display_info_.size() != old_info.size()) { - *message_out = DisplayView::GetTrayDisplayMessage(additional_message_out); - return true; - } - - for (DisplayInfoMap::const_iterator iter = display_info_.begin(); - iter != display_info_.end(); ++iter) { - DisplayInfoMap::const_iterator old_iter = old_info.find(iter->first); - // The display's number is same but different displays. This happens - // for the transition between docked mode and mirrored display. Falls back - // to GetTrayDisplayMessage(). - if (old_iter == old_info.end()) { - *message_out = DisplayView::GetTrayDisplayMessage(additional_message_out); - return true; - } - - if (iter->second.configured_ui_scale() != - old_iter->second.configured_ui_scale()) { - *message_out = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, - GetDisplayName(iter->first), - GetDisplaySize(iter->first)); - return true; - } - if (iter->second.rotation() != old_iter->second.rotation()) { - int rotation_text_id = 0; - switch (iter->second.rotation()) { - case gfx::Display::ROTATE_0: - rotation_text_id = IDS_ASH_STATUS_TRAY_DISPLAY_STANDARD_ORIENTATION; - break; - case gfx::Display::ROTATE_90: - rotation_text_id = IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90; - break; - case gfx::Display::ROTATE_180: - rotation_text_id = IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_180; - break; - case gfx::Display::ROTATE_270: - rotation_text_id = IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_270; - break; - } - *message_out = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, - GetDisplayName(iter->first), - l10n_util::GetStringUTF16(rotation_text_id)); - return true; - } - } - - // Found nothing special - return false; -} - -void TrayDisplay::CreateOrUpdateNotification( - const base::string16& message, - const base::string16& additional_message) { - // Always remove the notification to make sure the notification appears - // as a popup in any situation. - message_center::MessageCenter::Get()->RemoveNotification( - kNotificationId, false /* by_user */); - - if (message.empty()) - return; - - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - scoped_ptr<Notification> notification(new Notification( - message_center::NOTIFICATION_TYPE_SIMPLE, - kNotificationId, - message, - additional_message, - bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY), - base::string16(), // display_source - message_center::NotifierId( - message_center::NotifierId::SYSTEM_COMPONENT, - system_notifier::kNotifierDisplay), - message_center::RichNotificationData(), - new message_center::HandleNotificationClickedDelegate( - base::Bind(&OpenSettings)))); - message_center::MessageCenter::Get()->AddNotification(notification.Pass()); -} - -views::View* TrayDisplay::CreateDefaultView(user::LoginStatus status) { - DCHECK(default_ == NULL); - default_ = new DisplayView(); - return default_; -} - -void TrayDisplay::DestroyDefaultView() { - default_ = NULL; -} - -void TrayDisplay::OnDisplayConfigurationChanged() { - DisplayInfoMap old_info; - UpdateDisplayInfo(&old_info); - - if (default_) - default_->Update(); - - if (!Shell::GetInstance()->system_tray_delegate()-> - ShouldShowDisplayNotification()) { - return; - } - - base::string16 message; - base::string16 additional_message; - if (GetDisplayMessageForNotification(old_info, &message, &additional_message)) - CreateOrUpdateNotification(message, additional_message); -} - -base::string16 TrayDisplay::GetDefaultViewMessage() const { - if (!default_ || !default_->visible()) - return base::string16(); - - return static_cast<DisplayView*>(default_)->label()->text(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/tray_display.h b/chromium/ash/system/chromeos/tray_display.h deleted file mode 100644 index 6689a9bbb8d..00000000000 --- a/chromium/ash/system/chromeos/tray_display.h +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_CHROMEOS_TRAY_DISPLAY_H_ -#define ASH_SYSTEM_CHROMEOS_TRAY_DISPLAY_H_ - -#include <map> - -#include "ash/ash_export.h" -#include "ash/display/display_controller.h" -#include "ash/display/display_info.h" -#include "ash/system/tray/system_tray_item.h" -#include "base/strings/string16.h" -#include "ui/views/view.h" - -namespace ash { -namespace test { -class AshTestBase; -} - -namespace internal { -class DisplayView; - -class ASH_EXPORT TrayDisplay : public SystemTrayItem, - public DisplayController::Observer { - public: - explicit TrayDisplay(SystemTray* system_tray); - virtual ~TrayDisplay(); - - // Overridden from DisplayControllerObserver: - virtual void OnDisplayConfigurationChanged() OVERRIDE; - - private: - friend class TrayDisplayTest; - - typedef std::map<int64, DisplayInfo> DisplayInfoMap; - - static const char kNotificationId[]; - - // Scans the current display info and updates |display_info_|. Sets the - // previous data to |old_info| if it's not NULL. - void UpdateDisplayInfo(DisplayInfoMap* old_info); - - // Compares the current display settings with |old_info| and determine what - // message should be shown for notification. Returns true if there's a - // meaningful change. Note that it's possible to return true and set - // |message_out| to empty, which means the notification should be removed. It - // also sets |additional_message_out| which appears in the notification with - // the |message_out|. - bool GetDisplayMessageForNotification( - const DisplayInfoMap& old_info, - base::string16* message_out, - base::string16* additional_message_out); - - // Creates or updates the display notification. - void CreateOrUpdateNotification(const base::string16& message, - const base::string16& additional_message); - - // Overridden from SystemTrayItem. - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - - // Test accessors. - base::string16 GetDefaultViewMessage() const; - const views::View* default_view() const { - return reinterpret_cast<views::View*>(default_); - } - - DisplayView* default_; - DisplayInfoMap display_info_; - - DISALLOW_COPY_AND_ASSIGN(TrayDisplay); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_CHROMEOS_TRAY_DISPLAY_H_ diff --git a/chromium/ash/system/chromeos/tray_display_unittest.cc b/chromium/ash/system/chromeos/tray_display_unittest.cc deleted file mode 100644 index 8884da8bcbf..00000000000 --- a/chromium/ash/system/chromeos/tray_display_unittest.cc +++ /dev/null @@ -1,555 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/tray_display.h" - -#include "ash/display/display_manager.h" -#include "ash/root_window_controller.h" -#include "ash/screen_ash.h" -#include "ash/shell.h" -#include "ash/system/tray/system_tray.h" -#include "ash/test/ash_test_base.h" -#include "ash/test/test_system_tray_delegate.h" -#include "base/strings/string16.h" -#include "base/strings/utf_string_conversions.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/display.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" -#include "ui/message_center/notification_list.h" -#include "ui/views/controls/label.h" - -namespace ash { -namespace internal { - -base::string16 GetTooltipText(const base::string16& headline, - const base::string16& name1, - const std::string& data1, - const base::string16& name2, - const std::string& data2) { - std::vector<base::string16> lines; - lines.push_back(headline); - if (data1.empty()) { - lines.push_back(name1); - } else { - lines.push_back(l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, - name1, UTF8ToUTF16(data1))); - } - if (!name2.empty()) { - lines.push_back(l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, - name2, UTF8ToUTF16(data2))); - } - return JoinString(lines, '\n'); -} - -base::string16 GetMirroredTooltipText(const base::string16& headline, - const base::string16& name, - const std::string& data) { - return GetTooltipText(headline, name, data, base::string16(), ""); -} - -base::string16 GetFirstDisplayName() { - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - return UTF8ToUTF16(display_manager->GetDisplayNameForId( - display_manager->first_display_id())); -} - -base::string16 GetSecondDisplayName() { - return UTF8ToUTF16( - Shell::GetInstance()->display_manager()->GetDisplayNameForId( - ScreenAsh::GetSecondaryDisplay().id())); -} - -base::string16 GetMirroredDisplayName() { - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - return UTF8ToUTF16(display_manager->GetDisplayNameForId( - display_manager->mirrored_display_id())); -} - -class TrayDisplayTest : public ash::test::AshTestBase { - public: - TrayDisplayTest(); - virtual ~TrayDisplayTest(); - - virtual void SetUp() OVERRIDE; - - protected: - SystemTray* tray() { return tray_; } - TrayDisplay* tray_display() { return tray_display_; } - - void CloseNotification(); - bool IsDisplayVisibleInTray() const; - base::string16 GetTrayDisplayText() const; - base::string16 GetTrayDisplayTooltipText() const; - base::string16 GetDisplayNotificationText() const; - base::string16 GetDisplayNotificationAdditionalText() const; - - private: - const message_center::Notification* GetDisplayNotification() const; - - // Weak reference, owned by Shell. - SystemTray* tray_; - - // Weak reference, owned by |tray_|. - TrayDisplay* tray_display_; - - DISALLOW_COPY_AND_ASSIGN(TrayDisplayTest); -}; - -TrayDisplayTest::TrayDisplayTest() : tray_(NULL), tray_display_(NULL) { -} - -TrayDisplayTest::~TrayDisplayTest() { -} - -void TrayDisplayTest::SetUp() { - ash::test::AshTestBase::SetUp(); - tray_ = Shell::GetPrimaryRootWindowController()->GetSystemTray(); - tray_display_ = new TrayDisplay(tray_); - tray_->AddTrayItem(tray_display_); -} - -void TrayDisplayTest::CloseNotification() { - message_center::MessageCenter::Get()->RemoveNotification( - TrayDisplay::kNotificationId, false); - RunAllPendingInMessageLoop(); -} - -bool TrayDisplayTest::IsDisplayVisibleInTray() const { - return tray_->HasSystemBubble() && - tray_display_->default_view() && - tray_display_->default_view()->visible(); -} - -base::string16 TrayDisplayTest::GetTrayDisplayText() const { - return tray_display_->GetDefaultViewMessage(); -} - -base::string16 TrayDisplayTest::GetTrayDisplayTooltipText() const { - if (!tray_display_->default_view()) - return base::string16(); - - base::string16 tooltip; - if (!tray_display_->default_view()->GetTooltipText(gfx::Point(), &tooltip)) - return base::string16(); - return tooltip; -} - -base::string16 TrayDisplayTest::GetDisplayNotificationText() const { - const message_center::Notification* notification = GetDisplayNotification(); - return notification ? notification->title() : base::string16(); -} - -base::string16 TrayDisplayTest::GetDisplayNotificationAdditionalText() const { - const message_center::Notification* notification = GetDisplayNotification(); - return notification ? notification->message() : base::string16(); -} - -const message_center::Notification* TrayDisplayTest::GetDisplayNotification() - const { - const message_center::NotificationList::Notifications notifications = - message_center::MessageCenter::Get()->GetVisibleNotifications(); - for (message_center::NotificationList::Notifications::const_iterator iter = - notifications.begin(); iter != notifications.end(); ++iter) { - if ((*iter)->id() == TrayDisplay::kNotificationId) - return *iter; - } - - return NULL; -} - -TEST_F(TrayDisplayTest, NoInternalDisplay) { - UpdateDisplay("400x400"); - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_FALSE(IsDisplayVisibleInTray()); - - UpdateDisplay("400x400,200x200"); - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_TRUE(IsDisplayVisibleInTray()); - base::string16 expected = l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); - base::string16 first_name = GetFirstDisplayName(); - EXPECT_EQ(expected, GetTrayDisplayText()); - EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", - GetSecondDisplayName(), "200x200"), - GetTrayDisplayTooltipText()); - - // mirroring - Shell::GetInstance()->display_manager()->SetSoftwareMirroring(true); - UpdateDisplay("400x400,200x200"); - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_TRUE(IsDisplayVisibleInTray()); - expected = l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL); - EXPECT_EQ(expected, GetTrayDisplayText()); - EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"), - GetTrayDisplayTooltipText()); -} - -TEST_F(TrayDisplayTest, InternalDisplay) { - UpdateDisplay("400x400"); - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); - - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_FALSE(IsDisplayVisibleInTray()); - - // Extended - UpdateDisplay("400x400,200x200"); - string16 expected = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()); - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_TRUE(IsDisplayVisibleInTray()); - EXPECT_EQ(expected, GetTrayDisplayText()); - EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", - GetSecondDisplayName(), "200x200"), - GetTrayDisplayTooltipText()); - - // Mirroring - display_manager->SetSoftwareMirroring(true); - UpdateDisplay("400x400,200x200"); - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_TRUE(IsDisplayVisibleInTray()); - - expected = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()); - EXPECT_EQ(expected, GetTrayDisplayText()); - EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"), - GetTrayDisplayTooltipText()); -} - -TEST_F(TrayDisplayTest, InternalDisplayResized) { - UpdateDisplay("400x400@1.5"); - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); - - // Shows the tray_display even though there's a single-display. - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_TRUE(IsDisplayVisibleInTray()); - base::string16 internal_info = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, - GetFirstDisplayName(), UTF8ToUTF16("600x600")); - EXPECT_EQ(internal_info, GetTrayDisplayText()); - EXPECT_EQ(GetTooltipText(base::string16(), GetFirstDisplayName(), "600x600", - base::string16(), std::string()), - GetTrayDisplayTooltipText()); - - // Extended - UpdateDisplay("400x400@1.5,200x200"); - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_TRUE(IsDisplayVisibleInTray()); - base::string16 expected = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()); - EXPECT_EQ(expected, GetTrayDisplayText()); - EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "600x600", - GetSecondDisplayName(), "200x200"), - GetTrayDisplayTooltipText()); - - // Mirroring - display_manager->SetSoftwareMirroring(true); - UpdateDisplay("400x400@1.5,200x200"); - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_TRUE(IsDisplayVisibleInTray()); - expected = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()); - EXPECT_EQ(expected, GetTrayDisplayText()); - EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "600x600"), - GetTrayDisplayTooltipText()); - - // Closed lid mode. - display_manager->SetSoftwareMirroring(false); - UpdateDisplay("400x400@1.5,200x200"); - gfx::Display::SetInternalDisplayId(ScreenAsh::GetSecondaryDisplay().id()); - UpdateDisplay("400x400@1.5"); - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_TRUE(IsDisplayVisibleInTray()); - expected = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED); - EXPECT_EQ(expected, GetTrayDisplayText()); - EXPECT_EQ( - GetTooltipText( - expected, GetFirstDisplayName(), "600x600", base::string16(), ""), - GetTrayDisplayTooltipText()); -} - -TEST_F(TrayDisplayTest, ExternalDisplayResized) { - UpdateDisplay("400x400"); - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); - - // Shows the tray_display even though there's a single-display. - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_FALSE(IsDisplayVisibleInTray()); - - // Extended - UpdateDisplay("400x400,200x200@1.5"); - const gfx::Display& secondary_display = ScreenAsh::GetSecondaryDisplay(); - - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_TRUE(IsDisplayVisibleInTray()); - base::string16 expected = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, - GetSecondDisplayName(), - UTF8ToUTF16(secondary_display.size().ToString()))); - EXPECT_EQ(expected, GetTrayDisplayText()); - EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", - GetSecondDisplayName(), "300x300"), - GetTrayDisplayTooltipText()); - - // Mirroring - display_manager->SetSoftwareMirroring(true); - UpdateDisplay("400x400,200x200@1.5"); - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_TRUE(IsDisplayVisibleInTray()); - expected = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()); - EXPECT_EQ(expected, GetTrayDisplayText()); - EXPECT_EQ(GetMirroredTooltipText(expected, GetFirstDisplayName(), "400x400"), - GetTrayDisplayTooltipText()); -} - -TEST_F(TrayDisplayTest, OverscanDisplay) { - UpdateDisplay("400x400,300x300/o"); - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); - - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_TRUE(IsDisplayVisibleInTray()); - - // /o creates the default overscan, and if overscan is set, the annotation - // should be the size. - base::string16 overscan = l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN); - base::string16 headline = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, - GetSecondDisplayName(), UTF8ToUTF16("286x286"))); - std::string second_data = l10n_util::GetStringFUTF8( - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, - UTF8ToUTF16("286x286"), overscan); - EXPECT_EQ(GetTooltipText(headline, GetFirstDisplayName(), "400x400", - GetSecondDisplayName(), second_data), - GetTrayDisplayTooltipText()); - - // reset the overscan. - display_manager->SetOverscanInsets( - ScreenAsh::GetSecondaryDisplay().id(), gfx::Insets()); - headline = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, - GetSecondDisplayName(), overscan)); - second_data = l10n_util::GetStringFUTF8( - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, - UTF8ToUTF16("300x300"), overscan); - EXPECT_EQ(GetTooltipText(headline, GetFirstDisplayName(), "400x400", - GetSecondDisplayName(), second_data), - GetTrayDisplayTooltipText()); -} - -TEST_F(TrayDisplayTest, UpdateDuringDisplayConfigurationChange) { - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - EXPECT_FALSE(IsDisplayVisibleInTray()); - - UpdateDisplay("400x400@1.5"); - EXPECT_TRUE(tray()->HasSystemBubble()); - EXPECT_TRUE(IsDisplayVisibleInTray()); - base::string16 internal_info = l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, - GetFirstDisplayName(), UTF8ToUTF16("600x600")); - EXPECT_EQ(internal_info, GetTrayDisplayText()); - EXPECT_EQ(GetTooltipText(base::string16(), GetFirstDisplayName(), "600x600", - base::string16(), std::string()), - GetTrayDisplayTooltipText()); - - UpdateDisplay("400x400,200x200"); - EXPECT_TRUE(tray()->HasSystemBubble()); - EXPECT_TRUE(IsDisplayVisibleInTray()); - base::string16 expected = l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); - base::string16 first_name = GetFirstDisplayName(); - EXPECT_EQ(expected, GetTrayDisplayText()); - EXPECT_EQ(GetTooltipText(expected, GetFirstDisplayName(), "400x400", - GetSecondDisplayName(), "200x200"), - GetTrayDisplayTooltipText()); - - UpdateDisplay("400x400@1.5"); - tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - - // Back to the default state, the display tray item should disappear. - UpdateDisplay("400x400"); - EXPECT_TRUE(tray()->HasSystemBubble()); - EXPECT_FALSE(IsDisplayVisibleInTray()); -} - -TEST_F(TrayDisplayTest, DisplayNotifications) { - test::TestSystemTrayDelegate* tray_delegate = - static_cast<test::TestSystemTrayDelegate*>( - Shell::GetInstance()->system_tray_delegate()); - tray_delegate->set_should_show_display_notification(true); - - UpdateDisplay("400x400"); - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - gfx::Display::SetInternalDisplayId(display_manager->first_display_id()); - EXPECT_TRUE(GetDisplayNotificationText().empty()); - - // rotation. - UpdateDisplay("400x400/r"); - EXPECT_EQ( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(), - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), - GetDisplayNotificationText()); - EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); - - CloseNotification(); - UpdateDisplay("400x400"); - EXPECT_EQ( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetFirstDisplayName(), - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_STANDARD_ORIENTATION)), - GetDisplayNotificationText()); - EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); - - // UI-scale - CloseNotification(); - UpdateDisplay("400x400@1.5"); - EXPECT_EQ( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, - GetFirstDisplayName(), UTF8ToUTF16("600x600")), - GetDisplayNotificationText()); - EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); - - // UI-scale to 1.0 - CloseNotification(); - UpdateDisplay("400x400"); - EXPECT_EQ( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, - GetFirstDisplayName(), UTF8ToUTF16("400x400")), - GetDisplayNotificationText()); - EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); - - // No-update - CloseNotification(); - UpdateDisplay("400x400"); - EXPECT_TRUE(GetDisplayNotificationText().empty()); - EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); - - // Extended. - CloseNotification(); - UpdateDisplay("400x400,200x200"); - EXPECT_EQ( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()), - GetDisplayNotificationText()); - EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); - - // Mirroring. - CloseNotification(); - display_manager->SetSoftwareMirroring(true); - UpdateDisplay("400x400,200x200"); - EXPECT_EQ( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetMirroredDisplayName()), - GetDisplayNotificationText()); - EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); - - // Back to extended. - CloseNotification(); - display_manager->SetSoftwareMirroring(false); - UpdateDisplay("400x400,200x200"); - EXPECT_EQ( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetSecondDisplayName()), - GetDisplayNotificationText()); - EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); - - // Resize the first display. - UpdateDisplay("400x400@1.5,200x200"); - EXPECT_EQ( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, - GetFirstDisplayName(), UTF8ToUTF16("600x600")), - GetDisplayNotificationText()); - EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); - - // Rotate the second. - UpdateDisplay("400x400@1.5,200x200/r"); - EXPECT_EQ( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, - GetSecondDisplayName(), - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), - GetDisplayNotificationText()); - EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty()); - - // Enters closed lid mode. - UpdateDisplay("400x400@1.5,200x200"); - gfx::Display::SetInternalDisplayId(ScreenAsh::GetSecondaryDisplay().id()); - UpdateDisplay("400x400@1.5"); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED), - GetDisplayNotificationText()); - EXPECT_EQ( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION), - GetDisplayNotificationAdditionalText()); -} - -TEST_F(TrayDisplayTest, DisplayConfigurationChangedTwice) { - test::TestSystemTrayDelegate* tray_delegate = - static_cast<test::TestSystemTrayDelegate*>( - Shell::GetInstance()->system_tray_delegate()); - tray_delegate->set_should_show_display_notification(true); - - UpdateDisplay("400x400,200x200"); - EXPECT_EQ( - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), - GetDisplayNotificationText()); - - // OnDisplayConfigurationChanged() may be called more than once for a single - // update display in case of primary is swapped or recovered from dock mode. - // Should not remove the notification in such case. - tray_display()->OnDisplayConfigurationChanged(); - EXPECT_EQ( - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL), - GetDisplayNotificationText()); - - // Back to the single display. It SHOULD remove the notification since the - // information is stale. - UpdateDisplay("400x400"); - EXPECT_TRUE(GetDisplayNotificationText().empty()); -} - -TEST_F(TrayDisplayTest, UpdateAfterSuppressDisplayNotification) { - UpdateDisplay("400x400,200x200"); - - test::TestSystemTrayDelegate* tray_delegate = - static_cast<test::TestSystemTrayDelegate*>( - Shell::GetInstance()->system_tray_delegate()); - tray_delegate->set_should_show_display_notification(true); - - // rotate the second. - UpdateDisplay("400x400,200x200/r"); - EXPECT_EQ( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, - GetSecondDisplayName(), - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)), - GetDisplayNotificationText()); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/tray_tracing.cc b/chromium/ash/system/chromeos/tray_tracing.cc deleted file mode 100644 index eddeac7fcfa..00000000000 --- a/chromium/ash/system/chromeos/tray_tracing.cc +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/chromeos/tray_tracing.h" - -#include "ash/shell.h" -#include "ash/system/tray/actionable_view.h" -#include "ash/system/tray/fixed_sized_image_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" - -namespace ash { -namespace internal { - -namespace tray { - -class DefaultTracingView : public internal::ActionableView { - public: - DefaultTracingView() { - SetLayoutManager(new views::BoxLayout( - views::BoxLayout::kHorizontal, - kTrayPopupPaddingHorizontal, 0, - kTrayPopupPaddingBetweenItems)); - - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - image_ = new internal::FixedSizedImageView(0, kTrayPopupItemHeight); - image_->SetImage( - bundle.GetImageNamed(IDR_AURA_UBER_TRAY_TRACING).ToImageSkia()); - AddChildView(image_); - - label_ = new views::Label(); - label_->SetMultiLine(true); - label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_TRACING)); - AddChildView(label_); - } - - virtual ~DefaultTracingView() {} - - private: - // Overridden from ActionableView. - virtual bool PerformAction(const ui::Event& event) OVERRIDE { - Shell::GetInstance()->system_tray_delegate()->ShowChromeSlow(); - return true; - } - - views::ImageView* image_; - views::Label* label_; - - DISALLOW_COPY_AND_ASSIGN(DefaultTracingView); -}; - -} // namespace tray - -//////////////////////////////////////////////////////////////////////////////// -// ash::internal::TrayTracing - -TrayTracing::TrayTracing(SystemTray* system_tray) - : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_TRACING), - default_(NULL) { - DCHECK(Shell::GetInstance()->delegate()); - DCHECK(system_tray); - Shell::GetInstance()->system_tray_notifier()->AddTracingObserver(this); -} - -TrayTracing::~TrayTracing() { - Shell::GetInstance()->system_tray_notifier()->RemoveTracingObserver(this); -} - -void TrayTracing::SetTrayIconVisible(bool visible) { - if (tray_view()) - tray_view()->SetVisible(visible); -} - -bool TrayTracing::GetInitialVisibility() { - return false; -} - -views::View* TrayTracing::CreateDefaultView(user::LoginStatus status) { - CHECK(default_ == NULL); - if (tray_view() && tray_view()->visible()) - default_ = new tray::DefaultTracingView(); - return default_; -} - -views::View* TrayTracing::CreateDetailedView(user::LoginStatus status) { - return NULL; -} - -void TrayTracing::DestroyDefaultView() { - default_ = NULL; -} - -void TrayTracing::DestroyDetailedView() { -} - -void TrayTracing::OnTracingModeChanged(bool value) { - SetTrayIconVisible(value); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/chromeos/tray_tracing.h b/chromium/ash/system/chromeos/tray_tracing.h deleted file mode 100644 index f9491e1d903..00000000000 --- a/chromium/ash/system/chromeos/tray_tracing.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRACING_H_ -#define ASH_SYSTEM_TRAY_TRACING_H_ - -#include "ash/ash_export.h" -#include "ash/system/tray/tray_image_item.h" - -namespace views { -class View; -} - -namespace ash { - -class ASH_EXPORT TracingObserver { - public: - virtual ~TracingObserver() {} - - // Notifies when tracing mode changes. - virtual void OnTracingModeChanged(bool value) = 0; -}; - -namespace internal { - -// This is the item that displays when users enable performance tracing at -// chrome://slow. It alerts them that this mode is running, and provides an -// easy way to open the page to disable it. -class TrayTracing : public TrayImageItem, - public TracingObserver { - public: - explicit TrayTracing(SystemTray* system_tray); - virtual ~TrayTracing(); - - private: - void SetTrayIconVisible(bool visible); - - // Overridden from TrayImageItem. - virtual bool GetInitialVisibility() OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - - // Overridden from TracingObserver. - virtual void OnTracingModeChanged(bool value) OVERRIDE; - - views::View* default_; - - DISALLOW_COPY_AND_ASSIGN(TrayTracing); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRACING_H_ diff --git a/chromium/ash/system/date/clock_observer.h b/chromium/ash/system/date/clock_observer.h deleted file mode 100644 index 30465288bf7..00000000000 --- a/chromium/ash/system/date/clock_observer.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_DATE_CLOCK_OBSERVER_H_ -#define ASH_SYSTEM_DATE_CLOCK_OBSERVER_H_ - -namespace ash { - -class ClockObserver { - public: - virtual ~ClockObserver() {} - - virtual void OnDateFormatChanged() = 0; - virtual void OnSystemClockTimeUpdated() = 0; - - // Force a refresh (e.g. after the system is resumed). - virtual void Refresh() = 0; -}; - -}; - -#endif // ASH_SYSTEM_DATE_CLOCK_OBSERVER_H_ diff --git a/chromium/ash/system/date/date_view.cc b/chromium/ash/system/date/date_view.cc deleted file mode 100644 index 63f3af35ce9..00000000000 --- a/chromium/ash/system/date/date_view.cc +++ /dev/null @@ -1,309 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/date/date_view.h" - -#include "ash/shell.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_utils.h" -#include "base/i18n/rtl.h" -#include "base/i18n/time_formatting.h" -#include "base/strings/utf_string_conversions.h" -#include "base/time/time.h" -#include "grit/ash_strings.h" -#include "third_party/icu/source/i18n/unicode/datefmt.h" -#include "third_party/icu/source/i18n/unicode/dtptngen.h" -#include "third_party/icu/source/i18n/unicode/smpdtfmt.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/views/border.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/grid_layout.h" -#include "ui/views/widget/widget.h" - -namespace ash { -namespace internal { -namespace tray { - -namespace { - -// Amount of slop to add into the timer to make sure we're into the next minute -// when the timer goes off. -const int kTimerSlopSeconds = 1; - -// Text color of the vertical clock minutes. -const SkColor kVerticalClockMinuteColor = SkColorSetRGB(0xBA, 0xBA, 0xBA); - -// Padding between the left edge of the shelf and the left edge of the vertical -// clock. -const int kVerticalClockLeftPadding = 9; - -// Offset used to bring the minutes line closer to the hours line in the -// vertical clock. -const int kVerticalClockMinutesTopOffset = -4; - -base::string16 FormatDate(const base::Time& time) { - icu::UnicodeString date_string; - scoped_ptr<icu::DateFormat> formatter( - icu::DateFormat::createDateInstance(icu::DateFormat::kMedium)); - formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); - return base::string16(date_string.getBuffer(), - static_cast<size_t>(date_string.length())); -} - -base::string16 FormatDayOfWeek(const base::Time& time) { - UErrorCode status = U_ZERO_ERROR; - scoped_ptr<icu::DateTimePatternGenerator> generator( - icu::DateTimePatternGenerator::createInstance(status)); - DCHECK(U_SUCCESS(status)); - const char kBasePattern[] = "EEE"; - icu::UnicodeString generated_pattern = - generator->getBestPattern(icu::UnicodeString(kBasePattern), status); - DCHECK(U_SUCCESS(status)); - icu::SimpleDateFormat simple_formatter(generated_pattern, status); - DCHECK(U_SUCCESS(status)); - icu::UnicodeString date_string; - simple_formatter.format( - static_cast<UDate>(time.ToDoubleT() * 1000), date_string, status); - DCHECK(U_SUCCESS(status)); - return base::string16( - date_string.getBuffer(), static_cast<size_t>(date_string.length())); -} - -views::Label* CreateLabel() { - views::Label* label = new views::Label; - label->SetHorizontalAlignment(gfx::ALIGN_LEFT); - label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); - return label; -} - -} // namespace - -BaseDateTimeView::~BaseDateTimeView() { - timer_.Stop(); -} - -void BaseDateTimeView::UpdateText() { - base::Time now = base::Time::Now(); - UpdateTextInternal(now); - SchedulePaint(); - SetTimer(now); -} - -BaseDateTimeView::BaseDateTimeView() { - SetTimer(base::Time::Now()); -} - -void BaseDateTimeView::SetTimer(const base::Time& now) { - // Try to set the timer to go off at the next change of the minute. We don't - // want to have the timer go off more than necessary since that will cause - // the CPU to wake up and consume power. - base::Time::Exploded exploded; - now.LocalExplode(&exploded); - - // Often this will be called at minute boundaries, and we'll actually want - // 60 seconds from now. - int seconds_left = 60 - exploded.second; - if (seconds_left == 0) - seconds_left = 60; - - // Make sure that the timer fires on the next minute. Without this, if it is - // called just a teeny bit early, then it will skip the next minute. - seconds_left += kTimerSlopSeconds; - - timer_.Stop(); - timer_.Start( - FROM_HERE, base::TimeDelta::FromSeconds(seconds_left), - this, &BaseDateTimeView::UpdateText); -} - -void BaseDateTimeView::ChildPreferredSizeChanged(views::View* child) { - PreferredSizeChanged(); -} - -void BaseDateTimeView::OnLocaleChanged() { - UpdateText(); -} - -DateView::DateView() - : hour_type_(ash::Shell::GetInstance()->system_tray_delegate()-> - GetHourClockType()), - actionable_(false) { - SetLayoutManager( - new views::BoxLayout( - views::BoxLayout::kVertical, 0, 0, 0)); - date_label_ = CreateLabel(); - date_label_->SetEnabledColor(kHeaderTextColorNormal); - UpdateTextInternal(base::Time::Now()); - AddChildView(date_label_); - SetFocusable(actionable_); -} - -DateView::~DateView() { -} - -void DateView::SetActionable(bool actionable) { - actionable_ = actionable; - SetFocusable(actionable_); -} - -void DateView::UpdateTimeFormat() { - hour_type_ = - ash::Shell::GetInstance()->system_tray_delegate()->GetHourClockType(); - UpdateText(); -} - -void DateView::UpdateTextInternal(const base::Time& now) { - SetAccessibleName( - base::TimeFormatFriendlyDate(now) + - ASCIIToUTF16(", ") + - base::TimeFormatTimeOfDayWithHourClockType( - now, hour_type_, base::kKeepAmPm)); - date_label_->SetText( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); -} - -bool DateView::PerformAction(const ui::Event& event) { - if (!actionable_) - return false; - - ash::Shell::GetInstance()->system_tray_delegate()->ShowDateSettings(); - return true; -} - -void DateView::OnMouseEntered(const ui::MouseEvent& event) { - if (!actionable_) - return; - date_label_->SetEnabledColor(kHeaderTextColorHover); - SchedulePaint(); -} - -void DateView::OnMouseExited(const ui::MouseEvent& event) { - if (!actionable_) - return; - date_label_->SetEnabledColor(kHeaderTextColorNormal); - SchedulePaint(); -} - -/////////////////////////////////////////////////////////////////////////////// - -TimeView::TimeView(TrayDate::ClockLayout clock_layout) - : hour_type_(ash::Shell::GetInstance()->system_tray_delegate()-> - GetHourClockType()) { - SetupLabels(); - UpdateTextInternal(base::Time::Now()); - UpdateClockLayout(clock_layout); - SetFocusable(false); -} - -TimeView::~TimeView() { -} - -void TimeView::UpdateTimeFormat() { - hour_type_ = - ash::Shell::GetInstance()->system_tray_delegate()->GetHourClockType(); - UpdateText(); -} - -void TimeView::UpdateTextInternal(const base::Time& now) { - // Just in case |now| is null, do NOT update time; otherwise, it will - // crash icu code by calling into base::TimeFormatTimeOfDayWithHourClockType, - // see details in crbug.com/147570. - if (now.is_null()) { - LOG(ERROR) << "Received null value from base::Time |now| in argument"; - return; - } - - base::string16 current_time = base::TimeFormatTimeOfDayWithHourClockType( - now, hour_type_, base::kDropAmPm); - horizontal_label_->SetText(current_time); - horizontal_label_->SetTooltipText(base::TimeFormatFriendlyDate(now)); - - // Calculate vertical clock layout labels. - size_t colon_pos = current_time.find(ASCIIToUTF16(":")); - base::string16 hour = current_time.substr(0, colon_pos); - base::string16 minute = current_time.substr(colon_pos + 1); - - // Sometimes pad single-digit hours with a zero for aesthetic reasons. - if (hour.length() == 1 && - hour_type_ == base::k24HourClock && - !base::i18n::IsRTL()) - hour = ASCIIToUTF16("0") + hour; - - vertical_label_hours_->SetText(hour); - vertical_label_minutes_->SetText(minute); - Layout(); -} - -bool TimeView::PerformAction(const ui::Event& event) { - return false; -} - -bool TimeView::OnMousePressed(const ui::MouseEvent& event) { - // Let the event fall through. - return false; -} - -void TimeView::UpdateClockLayout(TrayDate::ClockLayout clock_layout){ - SetBorder(clock_layout); - if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { - RemoveChildView(vertical_label_hours_.get()); - RemoveChildView(vertical_label_minutes_.get()); - SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); - AddChildView(horizontal_label_.get()); - } else { - RemoveChildView(horizontal_label_.get()); - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); - const int kColumnId = 0; - views::ColumnSet* columns = layout->AddColumnSet(kColumnId); - columns->AddPaddingColumn(0, kVerticalClockLeftPadding); - columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, - 0, views::GridLayout::USE_PREF, 0, 0); - layout->AddPaddingRow(0, kTrayLabelItemVerticalPaddingVerticalAlignment); - layout->StartRow(0, kColumnId); - layout->AddView(vertical_label_hours_.get()); - layout->StartRow(0, kColumnId); - layout->AddView(vertical_label_minutes_.get()); - layout->AddPaddingRow(0, kTrayLabelItemVerticalPaddingVerticalAlignment); - } - Layout(); -} - -void TimeView::SetBorder(TrayDate::ClockLayout clock_layout) { - if (clock_layout == TrayDate::HORIZONTAL_CLOCK) - set_border(views::Border::CreateEmptyBorder( - 0, kTrayLabelItemHorizontalPaddingBottomAlignment, - 0, kTrayLabelItemHorizontalPaddingBottomAlignment)); - else - set_border(NULL); -} - -void TimeView::SetupLabels() { - horizontal_label_.reset(CreateLabel()); - SetupLabel(horizontal_label_.get()); - vertical_label_hours_.reset(CreateLabel()); - SetupLabel(vertical_label_hours_.get()); - vertical_label_minutes_.reset(CreateLabel()); - SetupLabel(vertical_label_minutes_.get()); - vertical_label_minutes_->SetEnabledColor(kVerticalClockMinuteColor); - // Pull the minutes up closer to the hours by using a negative top border. - vertical_label_minutes_->set_border( - views::Border::CreateEmptyBorder( - kVerticalClockMinutesTopOffset, 0, 0, 0)); -} - -void TimeView::SetupLabel(views::Label* label) { - label->set_owned_by_client(); - SetupLabelForTray(label); - gfx::Font font = label->font(); - label->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD)); -} - -} // namespace tray -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/date/date_view.h b/chromium/ash/system/date/date_view.h deleted file mode 100644 index b7a592b4625..00000000000 --- a/chromium/ash/system/date/date_view.h +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_DATE_DATE_VIEW_H_ -#define ASH_SYSTEM_DATE_DATE_VIEW_H_ - -#include "ash/ash_export.h" -#include "ash/system/date/tray_date.h" -#include "ash/system/tray/actionable_view.h" -#include "base/i18n/time_formatting.h" -#include "base/memory/scoped_ptr.h" -#include "base/timer/timer.h" -#include "ui/views/view.h" - -namespace views { -class Label; -} - -namespace ash { -namespace internal { -namespace tray { - -// Abstract base class containing common updating and layout code for the -// DateView popup and the TimeView tray icon. Exported for tests. -class ASH_EXPORT BaseDateTimeView : public ActionableView { - public: - virtual ~BaseDateTimeView(); - - // Updates the displayed text for the current time and calls SetTimer(). - void UpdateText(); - - protected: - BaseDateTimeView(); - - private: - // Starts |timer_| to schedule the next update. - void SetTimer(const base::Time& now); - - // Updates labels to display the current time. - virtual void UpdateTextInternal(const base::Time& now) = 0; - - // Overridden from views::View. - virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; - virtual void OnLocaleChanged() OVERRIDE; - - // Invokes UpdateText() when the displayed time should change. - base::OneShotTimer<BaseDateTimeView> timer_; - - DISALLOW_COPY_AND_ASSIGN(BaseDateTimeView); -}; - -// Popup view used to display the date and day of week. -class DateView : public BaseDateTimeView { - public: - DateView(); - virtual ~DateView(); - - // Sets whether the view is actionable. An actionable date view gives visual - // feedback on hover, can be focused by keyboard, and clicking/pressing space - // or enter on the view shows date-related settings. - void SetActionable(bool actionable); - - // Updates the format of the displayed time. - void UpdateTimeFormat(); - - private: - // Overridden from BaseDateTimeView. - virtual void UpdateTextInternal(const base::Time& now) OVERRIDE; - - // Overridden from ActionableView. - virtual bool PerformAction(const ui::Event& event) OVERRIDE; - - // Overridden from views::View. - virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; - virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; - - views::Label* date_label_; - - // Time format (12/24hr) used for accessibility string. - base::HourClockType hour_type_; - - bool actionable_; - - DISALLOW_COPY_AND_ASSIGN(DateView); -}; - -// Tray view used to display the current time. -// Exported for tests. -class ASH_EXPORT TimeView : public BaseDateTimeView { - public: - explicit TimeView(TrayDate::ClockLayout clock_layout); - virtual ~TimeView(); - - // Updates the format of the displayed time. - void UpdateTimeFormat(); - - // Updates clock layout. - void UpdateClockLayout(TrayDate::ClockLayout clock_layout); - - private: - friend class TimeViewTest; - - // Overridden from BaseDateTimeView. - virtual void UpdateTextInternal(const base::Time& now) OVERRIDE; - - // Overridden from ActionableView. - virtual bool PerformAction(const ui::Event& event) OVERRIDE; - - // Overridden from views::View. - virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; - - void SetBorder(TrayDate::ClockLayout clock_layout); - void SetupLabels(); - void SetupLabel(views::Label* label); - - // Label text used for the normal horizontal shelf. - scoped_ptr<views::Label> horizontal_label_; - - // The time label is split into two lines for the vertical shelf. - scoped_ptr<views::Label> vertical_label_hours_; - scoped_ptr<views::Label> vertical_label_minutes_; - - base::HourClockType hour_type_; - - DISALLOW_COPY_AND_ASSIGN(TimeView); -}; - -} // namespace tray -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_DATE_DATE_VIEW_H_ diff --git a/chromium/ash/system/date/date_view_unittest.cc b/chromium/ash/system/date/date_view_unittest.cc deleted file mode 100644 index 931d220694e..00000000000 --- a/chromium/ash/system/date/date_view_unittest.cc +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/date/date_view.h" - -#include "ash/test/ash_test_base.h" -#include "ui/views/controls/label.h" - -namespace ash { -namespace internal { -namespace tray { - -class TimeViewTest : public ash::test::AshTestBase { - public: - TimeViewTest() {} - virtual ~TimeViewTest() {} - - TimeView* time_view() { return time_view_.get(); } - - // Access to private fields of |time_view_|. - views::Label* horizontal_label() { - return time_view_->horizontal_label_.get(); - } - views::Label* vertical_label_hours() { - return time_view_->vertical_label_hours_.get(); - } - views::Label* vertical_label_minutes() { - return time_view_->vertical_label_minutes_.get(); - } - - // Creates a time view with horizontal or vertical |clock_layout|. - void CreateTimeView(TrayDate::ClockLayout clock_layout) { - time_view_.reset(new TimeView(clock_layout)); - } - - private: - scoped_ptr<TimeView> time_view_; - - DISALLOW_COPY_AND_ASSIGN(TimeViewTest); -}; - -// Test the basics of the time view, mostly to ensure we don't leak memory. -TEST_F(TimeViewTest, Basics) { - // A newly created horizontal clock only has the horizontal label. - CreateTimeView(TrayDate::HORIZONTAL_CLOCK); - EXPECT_EQ(time_view(), horizontal_label()->parent()); - EXPECT_FALSE(vertical_label_hours()->parent()); - EXPECT_FALSE(vertical_label_minutes()->parent()); - - // Switching the clock to vertical updates the labels. - time_view()->UpdateClockLayout(TrayDate::VERTICAL_CLOCK); - EXPECT_FALSE(horizontal_label()->parent()); - EXPECT_EQ(time_view(), vertical_label_hours()->parent()); - EXPECT_EQ(time_view(), vertical_label_minutes()->parent()); - - // Switching back to horizontal updates the labels again. - time_view()->UpdateClockLayout(TrayDate::HORIZONTAL_CLOCK); - EXPECT_EQ(time_view(), horizontal_label()->parent()); - EXPECT_FALSE(vertical_label_hours()->parent()); - EXPECT_FALSE(vertical_label_minutes()->parent()); -} - -} // namespace tray -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/date/tray_date.cc b/chromium/ash/system/date/tray_date.cc deleted file mode 100644 index c2a4b923646..00000000000 --- a/chromium/ash/system/date/tray_date.cc +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/date/tray_date.h" - -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/session_state_delegate.h" -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "ash/system/date/date_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_item_view.h" -#include "ash/system/tray/tray_popup_header_button.h" -#include "base/i18n/time_formatting.h" -#include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "base/time/time.h" -#include "base/timer/timer.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "third_party/icu/source/i18n/unicode/datefmt.h" -#include "third_party/icu/source/i18n/unicode/fieldpos.h" -#include "third_party/icu/source/i18n/unicode/fmtable.h" -#include "third_party/skia/include/core/SkRect.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image.h" -#include "ui/gfx/image/image_skia.h" -#include "ui/gfx/size.h" -#include "ui/views/controls/button/button.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/painter.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -#if defined(OS_CHROMEOS) -#include "ash/system/chromeos/system_clock_observer.h" -#endif - -namespace { - -const int kPaddingVertical = 19; - -} // namespace - -namespace ash { -namespace internal { - -class DateDefaultView : public views::View, - public views::ButtonListener { - public: - explicit DateDefaultView(ash::user::LoginStatus login) - : help_(NULL), - shutdown_(NULL), - lock_(NULL), - date_view_(NULL) { - SetLayoutManager(new views::FillLayout); - - date_view_ = new tray::DateView(); - date_view_->set_border(views::Border::CreateEmptyBorder(kPaddingVertical, - ash::kTrayPopupPaddingHorizontal, - 0, - 0)); - SpecialPopupRow* view = new SpecialPopupRow(); - view->SetContent(date_view_); - AddChildView(view); - - if (login == ash::user::LOGGED_IN_LOCKED || - login == ash::user::LOGGED_IN_NONE) - return; - - date_view_->SetActionable(true); - - help_ = new TrayPopupHeaderButton(this, - IDR_AURA_UBER_TRAY_HELP, - IDR_AURA_UBER_TRAY_HELP, - IDR_AURA_UBER_TRAY_HELP_HOVER, - IDR_AURA_UBER_TRAY_HELP_HOVER, - IDS_ASH_STATUS_TRAY_HELP); - help_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP)); - view->AddButton(help_); - -#if !defined(OS_WIN) - if (login != ash::user::LOGGED_IN_LOCKED && - login != ash::user::LOGGED_IN_RETAIL_MODE) { - shutdown_ = new TrayPopupHeaderButton(this, - IDR_AURA_UBER_TRAY_SHUTDOWN, - IDR_AURA_UBER_TRAY_SHUTDOWN, - IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, - IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, - IDS_ASH_STATUS_TRAY_SHUTDOWN); - shutdown_->SetTooltipText( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN)); - view->AddButton(shutdown_); - } - - if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) { - lock_ = new TrayPopupHeaderButton(this, - IDR_AURA_UBER_TRAY_LOCKSCREEN, - IDR_AURA_UBER_TRAY_LOCKSCREEN, - IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, - IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, - IDS_ASH_STATUS_TRAY_LOCK); - lock_->SetTooltipText( - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK)); - view->AddButton(lock_); - } -#endif // !defined(OS_WIN) - } - - virtual ~DateDefaultView() {} - - views::View* GetHelpButtonView() const { - return help_; - } - - tray::DateView* GetDateView() const { - return date_view_; - } - - private: - // Overridden from views::ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE { - ash::Shell* shell = ash::Shell::GetInstance(); - ash::SystemTrayDelegate* tray_delegate = shell->system_tray_delegate(); - if (sender == help_) { - shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP); - tray_delegate->ShowHelp(); - } else if (sender == shutdown_) { - shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN); - tray_delegate->ShutDown(); - } else if (sender == lock_) { - shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN); - tray_delegate->RequestLockScreen(); - } else { - NOTREACHED(); - } - } - - TrayPopupHeaderButton* help_; - TrayPopupHeaderButton* shutdown_; - TrayPopupHeaderButton* lock_; - tray::DateView* date_view_; - - DISALLOW_COPY_AND_ASSIGN(DateDefaultView); -}; - -TrayDate::TrayDate(SystemTray* system_tray) - : SystemTrayItem(system_tray), - time_tray_(NULL), - default_view_(NULL) { -#if defined(OS_CHROMEOS) - system_clock_observer_.reset(new SystemClockObserver()); -#endif - Shell::GetInstance()->system_tray_notifier()->AddClockObserver(this); -} - -TrayDate::~TrayDate() { - Shell::GetInstance()->system_tray_notifier()->RemoveClockObserver(this); -} - -views::View* TrayDate::GetHelpButtonView() const { - if (!default_view_) - return NULL; - return default_view_->GetHelpButtonView(); -} - -views::View* TrayDate::CreateTrayView(user::LoginStatus status) { - CHECK(time_tray_ == NULL); - ClockLayout clock_layout = - (system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM || - system_tray()->shelf_alignment() == SHELF_ALIGNMENT_TOP) ? - HORIZONTAL_CLOCK : VERTICAL_CLOCK; - time_tray_ = new tray::TimeView(clock_layout); - views::View* view = new TrayItemView(this); - view->AddChildView(time_tray_); - return view; -} - -views::View* TrayDate::CreateDefaultView(user::LoginStatus status) { - default_view_ = new DateDefaultView(status); - return default_view_; -} - -views::View* TrayDate::CreateDetailedView(user::LoginStatus status) { - return NULL; -} - -void TrayDate::DestroyTrayView() { - time_tray_ = NULL; -} - -void TrayDate::DestroyDefaultView() { - default_view_ = NULL; -} - -void TrayDate::DestroyDetailedView() { -} - -void TrayDate::UpdateAfterLoginStatusChange(user::LoginStatus status) { -} - -void TrayDate::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { - if (time_tray_) { - ClockLayout clock_layout = (alignment == SHELF_ALIGNMENT_BOTTOM || - alignment == SHELF_ALIGNMENT_TOP) ? - HORIZONTAL_CLOCK : VERTICAL_CLOCK; - time_tray_->UpdateClockLayout(clock_layout); - } -} - -void TrayDate::OnDateFormatChanged() { - if (time_tray_) - time_tray_->UpdateTimeFormat(); - if (default_view_) - default_view_->GetDateView()->UpdateTimeFormat(); -} - -void TrayDate::OnSystemClockTimeUpdated() { - if (time_tray_) - time_tray_->UpdateTimeFormat(); - if (default_view_) - default_view_->GetDateView()->UpdateTimeFormat(); -} - -void TrayDate::Refresh() { - if (time_tray_) - time_tray_->UpdateText(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/date/tray_date.h b/chromium/ash/system/date/tray_date.h deleted file mode 100644 index 6d5825b5880..00000000000 --- a/chromium/ash/system/date/tray_date.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_DATE_TRAY_DATE_H_ -#define ASH_SYSTEM_DATE_TRAY_DATE_H_ - -#include "ash/system/date/clock_observer.h" -#include "ash/system/tray/system_tray_item.h" -#include "base/memory/scoped_ptr.h" - -namespace views { -class Label; -} - -namespace ash { -namespace internal { - -#if defined(OS_CHROMEOS) -class SystemClockObserver; -#endif -class DateDefaultView; - -namespace tray { -class TimeView; -} - -class TrayDate : public SystemTrayItem, - public ClockObserver { - public: - enum ClockLayout { - HORIZONTAL_CLOCK, - VERTICAL_CLOCK, - }; - explicit TrayDate(SystemTray* system_tray); - virtual ~TrayDate(); - - // Returns view for help button if it is exists. Returns NULL otherwise. - views::View* GetHelpButtonView() const; - - private: - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) OVERRIDE; - - // Overridden from ClockObserver. - virtual void OnDateFormatChanged() OVERRIDE; - virtual void OnSystemClockTimeUpdated() OVERRIDE; - virtual void Refresh() OVERRIDE; - - void SetupLabelForTimeTray(views::Label* label); - - tray::TimeView* time_tray_; - DateDefaultView* default_view_; - -#if defined(OS_CHROMEOS) - scoped_ptr<SystemClockObserver> system_clock_observer_; -#endif - - DISALLOW_COPY_AND_ASSIGN(TrayDate); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_DATE_TRAY_DATE_H_ diff --git a/chromium/ash/system/drive/drive_observer.h b/chromium/ash/system/drive/drive_observer.h deleted file mode 100644 index a721dd44fc7..00000000000 --- a/chromium/ash/system/drive/drive_observer.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_DRIVE_DRIVE_OBSERVER_H_ -#define ASH_SYSTEM_DRIVE_DRIVE_OBSERVER_H_ - -#include "ash/system/tray/system_tray_delegate.h" - -namespace ash { - -class DriveObserver { - public: - virtual void OnDriveJobUpdated(const DriveOperationStatus& status) = 0; - - protected: - virtual ~DriveObserver() {} -}; - -} // namespace ash - -#endif // ASH_SYSTEM_DRIVE_DRIVE_OBSERVER_H_ diff --git a/chromium/ash/system/drive/tray_drive.cc b/chromium/ash/system/drive/tray_drive.cc deleted file mode 100644 index b246d52a7bf..00000000000 --- a/chromium/ash/system/drive/tray_drive.cc +++ /dev/null @@ -1,517 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/drive/tray_drive.h" - -#include <vector> - -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/shell.h" -#include "ash/system/tray/fixed_sized_scroll_view.h" -#include "ash/system/tray/hover_highlight_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_details_view.h" -#include "ash/system/tray/tray_item_more.h" -#include "ash/system/tray/tray_item_view.h" -#include "base/logging.h" -#include "base/stl_util.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/font.h" -#include "ui/gfx/image/image.h" -#include "ui/views/controls/button/image_button.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/controls/progress_bar.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/grid_layout.h" -#include "ui/views/widget/widget.h" - -namespace ash { - -namespace internal { - -namespace { - -const int kSidePadding = 8; -const int kHorizontalPadding = 6; -const int kVerticalPadding = 6; -const int kTopPadding = 6; -const int kBottomPadding = 10; -const int kProgressBarWidth = 100; -const int kProgressBarHeight = 11; -const int64 kHideDelayInMs = 1000; - -base::string16 GetTrayLabel(const ash::DriveOperationStatusList& list) { - return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DRIVE_SYNCING, - base::IntToString16(static_cast<int>(list.size()))); -} - -scoped_ptr<ash::DriveOperationStatusList> GetCurrentOperationList() { - ash::SystemTrayDelegate* delegate = - ash::Shell::GetInstance()->system_tray_delegate(); - scoped_ptr<ash::DriveOperationStatusList> list( - new ash::DriveOperationStatusList); - delegate->GetDriveOperationStatusList(list.get()); - return list.Pass(); -} - -} - -namespace tray { - -class DriveDefaultView : public TrayItemMore { - public: - DriveDefaultView(SystemTrayItem* owner, - const DriveOperationStatusList* list) - : TrayItemMore(owner, true) { - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - - SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DRIVE).ToImageSkia()); - Update(list); - } - - virtual ~DriveDefaultView() {} - - void Update(const DriveOperationStatusList* list) { - DCHECK(list); - base::string16 label = GetTrayLabel(*list); - SetLabel(label); - SetAccessibleName(label); - } - - private: - DISALLOW_COPY_AND_ASSIGN(DriveDefaultView); -}; - -class DriveDetailedView : public TrayDetailsView, - public ViewClickListener { - public: - DriveDetailedView(SystemTrayItem* owner, - const DriveOperationStatusList* list) - : TrayDetailsView(owner), - settings_(NULL), - in_progress_img_(NULL), - done_img_(NULL), - failed_img_(NULL) { - in_progress_img_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_DRIVE); - done_img_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_DRIVE_DONE); - failed_img_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_DRIVE_FAILED); - - Update(list); - } - - virtual ~DriveDetailedView() { - STLDeleteValues(&update_map_); - } - - void Update(const DriveOperationStatusList* list) { - AppendOperationList(list); - AppendSettings(); - AppendHeaderEntry(list); - - SchedulePaint(); - } - - private: - - class OperationProgressBar : public views::ProgressBar { - public: - OperationProgressBar() {} - private: - - // Overridden from View: - virtual gfx::Size GetPreferredSize() OVERRIDE { - return gfx::Size(kProgressBarWidth, kProgressBarHeight); - } - - DISALLOW_COPY_AND_ASSIGN(OperationProgressBar); - }; - - class RowView : public HoverHighlightView, - public views::ButtonListener { - public: - RowView(DriveDetailedView* parent, - ash::DriveOperationStatus::OperationState state, - double progress, - const base::FilePath& file_path, - int32 operation_id) - : HoverHighlightView(parent), - container_(parent), - status_img_(NULL), - label_container_(NULL), - progress_bar_(NULL), - cancel_button_(NULL), - operation_id_(operation_id) { - // Status image. - status_img_ = new views::ImageView(); - AddChildView(status_img_); - - label_container_ = new views::View(); - label_container_->SetLayoutManager(new views::BoxLayout( - views::BoxLayout::kVertical, 0, 0, kVerticalPadding)); -#if defined(OS_POSIX) - base::string16 file_label = UTF8ToUTF16(file_path.BaseName().value()); -#elif defined(OS_WIN) - base::string16 file_label = WideToUTF16(file_path.BaseName().value()); -#endif - views::Label* label = new views::Label(file_label); - label->SetHorizontalAlignment(gfx::ALIGN_LEFT); - label_container_->AddChildView(label); - // Add progress bar. - progress_bar_ = new OperationProgressBar(); - label_container_->AddChildView(progress_bar_); - - AddChildView(label_container_); - - cancel_button_ = new views::ImageButton(this); - cancel_button_->SetImage(views::ImageButton::STATE_NORMAL, - ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_DRIVE_CANCEL)); - cancel_button_->SetImage(views::ImageButton::STATE_HOVERED, - ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_DRIVE_CANCEL_HOVER)); - - UpdateStatus(state, progress); - AddChildView(cancel_button_); - } - - void UpdateStatus(ash::DriveOperationStatus::OperationState state, - double progress) { - status_img_->SetImage(container_->GetImageForState(state)); - progress_bar_->SetValue(progress); - cancel_button_->SetVisible( - state == ash::DriveOperationStatus::OPERATION_NOT_STARTED || - state == ash::DriveOperationStatus::OPERATION_IN_PROGRESS); - } - - private: - - // views::View overrides. - virtual gfx::Size GetPreferredSize() OVERRIDE { - return gfx::Size( - status_img_->GetPreferredSize().width() + - label_container_->GetPreferredSize().width() + - cancel_button_->GetPreferredSize().width() + - 2 * kSidePadding + 2 * kHorizontalPadding, - std::max(status_img_->GetPreferredSize().height(), - std::max(label_container_->GetPreferredSize().height(), - cancel_button_->GetPreferredSize().height())) + - kTopPadding + kBottomPadding); - } - - virtual void Layout() OVERRIDE { - gfx::Rect child_area(GetLocalBounds()); - if (child_area.IsEmpty()) - return; - - int pos_x = child_area.x() + kSidePadding; - int pos_y = child_area.y() + kTopPadding; - - gfx::Rect bounds_status( - gfx::Point(pos_x, - pos_y + (child_area.height() - kTopPadding - - kBottomPadding - - status_img_->GetPreferredSize().height())/2), - status_img_->GetPreferredSize()); - status_img_->SetBoundsRect( - gfx::IntersectRects(bounds_status, child_area)); - pos_x += status_img_->bounds().width() + kHorizontalPadding; - - gfx::Rect bounds_label(pos_x, - pos_y, - child_area.width() - 2 * kSidePadding - - 2 * kHorizontalPadding - - status_img_->GetPreferredSize().width() - - cancel_button_->GetPreferredSize().width(), - label_container_->GetPreferredSize().height()); - label_container_->SetBoundsRect( - gfx::IntersectRects(bounds_label, child_area)); - pos_x += label_container_->bounds().width() + kHorizontalPadding; - - gfx::Rect bounds_button( - gfx::Point(pos_x, - pos_y + (child_area.height() - kTopPadding - - kBottomPadding - - cancel_button_->GetPreferredSize().height())/2), - cancel_button_->GetPreferredSize()); - cancel_button_->SetBoundsRect( - gfx::IntersectRects(bounds_button, child_area)); - } - - // views::ButtonListener overrides. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE { - DCHECK(sender == cancel_button_); - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_DRIVE_CANCEL_OPERATION); - container_->OnCancelOperation(operation_id_); - } - - DriveDetailedView* container_; - views::ImageView* status_img_; - views::View* label_container_; - views::ProgressBar* progress_bar_; - views::ImageButton* cancel_button_; - int32 operation_id_; - - DISALLOW_COPY_AND_ASSIGN(RowView); - }; - - void AppendHeaderEntry(const DriveOperationStatusList* list) { - if (footer()) - return; - CreateSpecialRow(IDS_ASH_STATUS_TRAY_DRIVE, this); - } - - gfx::ImageSkia* GetImageForState( - ash::DriveOperationStatus::OperationState state) { - switch (state) { - case ash::DriveOperationStatus::OPERATION_NOT_STARTED: - case ash::DriveOperationStatus::OPERATION_IN_PROGRESS: - return in_progress_img_; - case ash::DriveOperationStatus::OPERATION_COMPLETED: - return done_img_; - case ash::DriveOperationStatus::OPERATION_FAILED: - return failed_img_; - } - return failed_img_; - } - - void OnCancelOperation(int32 operation_id) { - SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); - delegate->CancelDriveOperation(operation_id); - } - - void AppendOperationList(const DriveOperationStatusList* list) { - if (!scroller()) - CreateScrollableList(); - - // Apply the update. - std::set<base::FilePath> new_set; - bool item_list_changed = false; - for (DriveOperationStatusList::const_iterator it = list->begin(); - it != list->end(); ++it) { - const DriveOperationStatus& operation = *it; - - new_set.insert(operation.file_path); - std::map<base::FilePath, RowView*>::iterator existing_item = - update_map_.find(operation.file_path); - - if (existing_item != update_map_.end()) { - existing_item->second->UpdateStatus(operation.state, - operation.progress); - } else { - RowView* row_view = new RowView(this, - operation.state, - operation.progress, - operation.file_path, - operation.id); - - update_map_[operation.file_path] = row_view; - scroll_content()->AddChildView(row_view); - item_list_changed = true; - } - } - - // Remove items from the list that haven't been added or modified with this - // update batch. - std::set<base::FilePath> remove_set; - for (std::map<base::FilePath, RowView*>::iterator update_iter = - update_map_.begin(); - update_iter != update_map_.end(); ++update_iter) { - if (new_set.find(update_iter->first) == new_set.end()) { - remove_set.insert(update_iter->first); - } - } - - for (std::set<base::FilePath>::iterator removed_iter = remove_set.begin(); - removed_iter != remove_set.end(); ++removed_iter) { - delete update_map_[*removed_iter]; - update_map_.erase(*removed_iter); - item_list_changed = true; - } - - if (item_list_changed) - scroller()->Layout(); - - // Close the details if there is really nothing to show there anymore. - if (new_set.empty() && GetWidget()) - GetWidget()->Close(); - } - - void AppendSettings() { - if (settings_) - return; - - HoverHighlightView* container = new HoverHighlightView(this); - container->AddLabel(ui::ResourceBundle::GetSharedInstance(). - GetLocalizedString(IDS_ASH_STATUS_TRAY_DRIVE_SETTINGS), - gfx::Font::NORMAL); - AddChildView(container); - settings_ = container; - } - - // Overridden from ViewClickListener. - virtual void OnViewClicked(views::View* sender) OVERRIDE { - SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); - if (sender == footer()->content()) { - TransitionToDefaultView(); - } else if (sender == settings_) { - delegate->ShowDriveSettings(); - } - } - - // Maps operation entries to their file paths. - std::map<base::FilePath, RowView*> update_map_; - views::View* settings_; - gfx::ImageSkia* in_progress_img_; - gfx::ImageSkia* done_img_; - gfx::ImageSkia* failed_img_; - - DISALLOW_COPY_AND_ASSIGN(DriveDetailedView); -}; - -} // namespace tray - -TrayDrive::TrayDrive(SystemTray* system_tray) : - TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_DRIVE_LIGHT), - default_(NULL), - detailed_(NULL) { - Shell::GetInstance()->system_tray_notifier()->AddDriveObserver(this); -} - -TrayDrive::~TrayDrive() { - Shell::GetInstance()->system_tray_notifier()->RemoveDriveObserver(this); -} - -bool TrayDrive::GetInitialVisibility() { - return false; -} - -views::View* TrayDrive::CreateDefaultView(user::LoginStatus status) { - DCHECK(!default_); - - if (status != user::LOGGED_IN_USER && status != user::LOGGED_IN_OWNER) - return NULL; - - // If the list is empty AND the tray icon is invisible (= not in the margin - // duration of delayed item hiding), don't show the item. - scoped_ptr<DriveOperationStatusList> list(GetCurrentOperationList()); - if (list->empty() && !tray_view()->visible()) - return NULL; - - default_ = new tray::DriveDefaultView(this, list.get()); - return default_; -} - -views::View* TrayDrive::CreateDetailedView(user::LoginStatus status) { - DCHECK(!detailed_); - - if (status != user::LOGGED_IN_USER && status != user::LOGGED_IN_OWNER) - return NULL; - - // If the list is empty AND the tray icon is invisible (= not in the margin - // duration of delayed item hiding), don't show the item. - scoped_ptr<DriveOperationStatusList> list(GetCurrentOperationList()); - if (list->empty() && !tray_view()->visible()) - return NULL; - - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_DETAILED_DRIVE_VIEW); - detailed_ = new tray::DriveDetailedView(this, list.get()); - return detailed_; -} - -void TrayDrive::DestroyDefaultView() { - default_ = NULL; -} - -void TrayDrive::DestroyDetailedView() { - detailed_ = NULL; -} - -void TrayDrive::UpdateAfterLoginStatusChange(user::LoginStatus status) { - if (status == user::LOGGED_IN_USER || status == user::LOGGED_IN_OWNER) - return; - - tray_view()->SetVisible(false); - DestroyDefaultView(); - DestroyDetailedView(); -} - -void TrayDrive::OnDriveJobUpdated(const DriveOperationStatus& status) { - // The Drive job list manager changed its notification interface *not* to send - // the whole list of operations each time, to clarify which operation is - // updated and to reduce redundancy. - // - // TrayDrive should be able to benefit from the change, but for now, to - // incrementally migrate to the new way with minimum diffs, we still get the - // list of operations each time the event is fired. - // TODO(kinaba) http://crbug.com/128079 clean it up. - scoped_ptr<DriveOperationStatusList> list(GetCurrentOperationList()); - bool is_new_item = true; - for (size_t i = 0; i < list->size(); ++i) { - if ((*list)[i].id == status.id) { - (*list)[i] = status; - is_new_item = false; - break; - } - } - if (is_new_item) - list->push_back(status); - - // Check if all the operations are in the finished state. - bool all_jobs_finished = true; - for (size_t i = 0; i < list->size(); ++i) { - if ((*list)[i].state != DriveOperationStatus::OPERATION_COMPLETED && - (*list)[i].state != DriveOperationStatus::OPERATION_FAILED) { - all_jobs_finished = false; - break; - } - } - - if (all_jobs_finished) { - // If all the jobs ended, the tray item will be hidden after a certain - // amount of delay. This is to avoid flashes between sequentially executed - // Drive operations (see crbug/165679). - hide_timer_.Start(FROM_HERE, - base::TimeDelta::FromMilliseconds(kHideDelayInMs), - this, - &TrayDrive::HideIfNoOperations); - return; - } - - // If the list is non-empty, stop the hiding timer (if any). - hide_timer_.Stop(); - - tray_view()->SetVisible(true); - if (default_) - default_->Update(list.get()); - if (detailed_) - detailed_->Update(list.get()); -} - -void TrayDrive::HideIfNoOperations() { - DriveOperationStatusList empty_list; - - tray_view()->SetVisible(false); - if (default_) - default_->Update(&empty_list); - if (detailed_) - detailed_->Update(&empty_list); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/drive/tray_drive.h b/chromium/ash/system/drive/tray_drive.h deleted file mode 100644 index 6550fdeda8e..00000000000 --- a/chromium/ash/system/drive/tray_drive.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_DRIVE_TRAY_DRIVE_H_ -#define ASH_SYSTEM_DRIVE_TRAY_DRIVE_H_ - -#include "ash/system/drive/drive_observer.h" -#include "ash/system/tray/tray_image_item.h" -#include "base/timer/timer.h" - -namespace views { -class Label; -} - -namespace ash { -namespace internal { - -namespace tray { -class DriveTrayView; -class DriveDefaultView; -class DriveDetailedView; -} - -class TrayDrive : public TrayImageItem, - public DriveObserver { - public: - explicit TrayDrive(SystemTray* system_tray); - virtual ~TrayDrive(); - - private: - // Overridden from TrayImageItem. - virtual bool GetInitialVisibility() OVERRIDE; - - // Overridden from SystemTrayItem. - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - - // Overridden from DriveObserver. - virtual void OnDriveJobUpdated(const DriveOperationStatus& status) OVERRIDE; - - // Delayed hiding of the tray item after encountering an empty operation list. - void HideIfNoOperations(); - - tray::DriveDefaultView* default_; - tray::DriveDetailedView* detailed_; - base::OneShotTimer<TrayDrive> hide_timer_; - - DISALLOW_COPY_AND_ASSIGN(TrayDrive); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_DRIVE_TRAY_DRIVE_H_ diff --git a/chromium/ash/system/ime/ime_observer.h b/chromium/ash/system/ime/ime_observer.h deleted file mode 100644 index aee74aea2ba..00000000000 --- a/chromium/ash/system/ime/ime_observer.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_IME_IME_OBSERVER_H_ -#define ASH_SYSTEM_IME_IME_OBSERVER_H_ - -namespace ash { - -class IMEObserver { - public: - virtual ~IMEObserver() {} - - // Notify the observer that the IME state has changed, and should be - // refreshed. |show_message| indicates whether the user should be alerted of - // the change. - virtual void OnIMERefresh(bool show_message) = 0; -}; - -} // namespace ash - -#endif // ASH_SYSTEM_IME_IME_OBSERVER_H_ diff --git a/chromium/ash/system/ime/tray_ime.cc b/chromium/ash/system/ime/tray_ime.cc deleted file mode 100644 index c558e27ed1e..00000000000 --- a/chromium/ash/system/ime/tray_ime.cc +++ /dev/null @@ -1,321 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/ime/tray_ime.h" - -#include <vector> - -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/system/system_notifier.h" -#include "ash/system/tray/hover_highlight_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_details_view.h" -#include "ash/system/tray/tray_item_more.h" -#include "ash/system/tray/tray_item_view.h" -#include "ash/system/tray/tray_utils.h" -#include "base/logging.h" -#include "base/strings/utf_string_conversions.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/font.h" -#include "ui/gfx/image/image.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" -#include "ui/message_center/notification_delegate.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/widget/widget.h" - -using message_center::Notification; - -namespace { - -const char kIMENotificationId[] = "chrome://settings/ime"; - -} // namespace - -namespace ash { -namespace internal { -namespace tray { - -class IMEDefaultView : public TrayItemMore { - public: - explicit IMEDefaultView(SystemTrayItem* owner) - : TrayItemMore(owner, true) { - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - - SetImage(bundle.GetImageNamed( - IDR_AURA_UBER_TRAY_IME).ToImageSkia()); - - IMEInfo info; - Shell::GetInstance()->system_tray_delegate()->GetCurrentIME(&info); - UpdateLabel(info); - } - - virtual ~IMEDefaultView() {} - - void UpdateLabel(const IMEInfo& info) { - SetLabel(info.name); - SetAccessibleName(info.name); - } - - private: - DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); -}; - -class IMEDetailedView : public TrayDetailsView, - public ViewClickListener { - public: - IMEDetailedView(SystemTrayItem* owner, user::LoginStatus login) - : TrayDetailsView(owner), - login_(login) { - SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); - IMEInfoList list; - delegate->GetAvailableIMEList(&list); - IMEPropertyInfoList property_list; - delegate->GetCurrentIMEProperties(&property_list); - Update(list, property_list); - } - - virtual ~IMEDetailedView() {} - - void Update(const IMEInfoList& list, - const IMEPropertyInfoList& property_list) { - Reset(); - - AppendIMEList(list); - if (!property_list.empty()) - AppendIMEProperties(property_list); - if (login_ != user::LOGGED_IN_NONE && login_ != user::LOGGED_IN_LOCKED) - AppendSettings(); - AppendHeaderEntry(); - - Layout(); - SchedulePaint(); - } - - private: - void AppendHeaderEntry() { - CreateSpecialRow(IDS_ASH_STATUS_TRAY_IME, this); - } - - void AppendIMEList(const IMEInfoList& list) { - ime_map_.clear(); - CreateScrollableList(); - for (size_t i = 0; i < list.size(); i++) { - HoverHighlightView* container = new HoverHighlightView(this); - container->AddLabel(list[i].name, - list[i].selected ? gfx::Font::BOLD : gfx::Font::NORMAL); - scroll_content()->AddChildView(container); - ime_map_[container] = list[i].id; - } - } - - void AppendIMEProperties(const IMEPropertyInfoList& property_list) { - property_map_.clear(); - for (size_t i = 0; i < property_list.size(); i++) { - HoverHighlightView* container = new HoverHighlightView(this); - container->AddLabel( - property_list[i].name, - property_list[i].selected ? gfx::Font::BOLD : gfx::Font::NORMAL); - if (i == 0) - container->set_border(views::Border::CreateSolidSidedBorder(1, 0, 0, 0, - kBorderLightColor)); - scroll_content()->AddChildView(container); - property_map_[container] = property_list[i].key; - } - } - - void AppendSettings() { - HoverHighlightView* container = new HoverHighlightView(this); - container->AddLabel(ui::ResourceBundle::GetSharedInstance(). - GetLocalizedString(IDS_ASH_STATUS_TRAY_IME_SETTINGS), - gfx::Font::NORMAL); - AddChildView(container); - settings_ = container; - } - - // Overridden from ViewClickListener. - virtual void OnViewClicked(views::View* sender) OVERRIDE { - SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); - if (sender == footer()->content()) { - TransitionToDefaultView(); - } else if (sender == settings_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_IME_SHOW_DETAILED); - delegate->ShowIMESettings(); - } else { - std::map<views::View*, std::string>::const_iterator ime_find; - ime_find = ime_map_.find(sender); - if (ime_find != ime_map_.end()) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_IME_SWITCH_MODE); - std::string ime_id = ime_find->second; - delegate->SwitchIME(ime_id); - GetWidget()->Close(); - } else { - std::map<views::View*, std::string>::const_iterator prop_find; - prop_find = property_map_.find(sender); - if (prop_find != property_map_.end()) { - const std::string key = prop_find->second; - delegate->ActivateIMEProperty(key); - GetWidget()->Close(); - } - } - } - } - - user::LoginStatus login_; - - std::map<views::View*, std::string> ime_map_; - std::map<views::View*, std::string> property_map_; - views::View* settings_; - - DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); -}; - -} // namespace tray - -TrayIME::TrayIME(SystemTray* system_tray) - : SystemTrayItem(system_tray), - tray_label_(NULL), - default_(NULL), - detailed_(NULL), - message_shown_(false) { - Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this); -} - -TrayIME::~TrayIME() { - Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this); - message_center::MessageCenter::Get()->RemoveNotification( - kIMENotificationId, false /* by_user */); -} - -void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { - if (tray_label_) { - if (current.third_party) { - tray_label_->label()->SetText(current.short_name + UTF8ToUTF16("*")); - } else { - tray_label_->label()->SetText(current.short_name); - } - tray_label_->SetVisible(count > 1); - SetTrayLabelItemBorder(tray_label_, system_tray()->shelf_alignment()); - tray_label_->Layout(); - } -} - -void TrayIME::UpdateOrCreateNotification() { - message_center::MessageCenter* message_center = - message_center::MessageCenter::Get(); - - if (!message_center->HasNotification(kIMENotificationId) && message_shown_) - return; - - SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); - IMEInfo current; - delegate->GetCurrentIME(¤t); - - ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - scoped_ptr<Notification> notification(new Notification( - message_center::NOTIFICATION_TYPE_SIMPLE, - kIMENotificationId, - // TODO(zork): Use IDS_ASH_STATUS_TRAY_THIRD_PARTY_IME_TURNED_ON_BUBBLE - // for third party IMEs - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_IME_TURNED_ON_BUBBLE, - current.medium_name), - base::string16(), // message - bundle.GetImageNamed(IDR_AURA_UBER_TRAY_IME), - base::string16(), // display_source - message_center::NotifierId( - message_center::NotifierId::SYSTEM_COMPONENT, - system_notifier::kNotifierInputMethod), - message_center::RichNotificationData(), - new message_center::HandleNotificationClickedDelegate( - base::Bind(&TrayIME::PopupDetailedView, - base::Unretained(this), 0, true)))); - message_center->AddNotification(notification.Pass()); - message_shown_ = true; -} - -views::View* TrayIME::CreateTrayView(user::LoginStatus status) { - CHECK(tray_label_ == NULL); - tray_label_ = new TrayItemView(this); - tray_label_->CreateLabel(); - SetupLabelForTray(tray_label_->label()); - // Hide IME tray when it is created, it will be updated when it is notified - // for IME refresh event. - tray_label_->SetVisible(false); - return tray_label_; -} - -views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { - SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); - IMEInfoList list; - IMEPropertyInfoList property_list; - delegate->GetAvailableIMEList(&list); - delegate->GetCurrentIMEProperties(&property_list); - if (list.size() <= 1 && property_list.size() <= 1) - return NULL; - CHECK(default_ == NULL); - default_ = new tray::IMEDefaultView(this); - return default_; -} - -views::View* TrayIME::CreateDetailedView(user::LoginStatus status) { - CHECK(detailed_ == NULL); - detailed_ = new tray::IMEDetailedView(this, status); - return detailed_; -} - -void TrayIME::DestroyTrayView() { - tray_label_ = NULL; -} - -void TrayIME::DestroyDefaultView() { - default_ = NULL; -} - -void TrayIME::DestroyDetailedView() { - detailed_ = NULL; -} - -void TrayIME::UpdateAfterLoginStatusChange(user::LoginStatus status) { -} - -void TrayIME::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { - SetTrayLabelItemBorder(tray_label_, alignment); - tray_label_->Layout(); -} - -void TrayIME::OnIMERefresh(bool show_message) { - SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); - IMEInfoList list; - IMEInfo current; - IMEPropertyInfoList property_list; - delegate->GetCurrentIME(¤t); - delegate->GetAvailableIMEList(&list); - delegate->GetCurrentIMEProperties(&property_list); - - UpdateTrayLabel(current, list.size()); - - if (default_) - default_->UpdateLabel(current); - if (detailed_) - detailed_->Update(list, property_list); - - if (list.size() > 1 && show_message) - UpdateOrCreateNotification(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/ime/tray_ime.h b/chromium/ash/system/ime/tray_ime.h deleted file mode 100644 index b237ae15abc..00000000000 --- a/chromium/ash/system/ime/tray_ime.h +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_IME_TRAY_IME_H_ -#define ASH_SYSTEM_IME_TRAY_IME_H_ - -#include "ash/system/ime/ime_observer.h" -#include "ash/system/tray/system_tray_item.h" - -namespace views { -class Label; -} - -namespace ash { - -struct IMEInfo; - -namespace internal { - -namespace tray { -class IMEDefaultView; -class IMEDetailedView; -class IMENotificationView; -} - -class TrayItemView; - -class TrayIME : public SystemTrayItem, - public IMEObserver { - public: - explicit TrayIME(SystemTray* system_tray); - virtual ~TrayIME(); - - private: - void UpdateTrayLabel(const IMEInfo& info, size_t count); - - // Update the content of the existing IME notification, or create a new one if - // necessary. IME notification should be created only once in a session, i.e. - // if an IME notification is created and removed already, it doesn't create a - // new one. - void UpdateOrCreateNotification(); - - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) OVERRIDE; - - // Overridden from IMEObserver. - virtual void OnIMERefresh(bool show_message) OVERRIDE; - - TrayItemView* tray_label_; - tray::IMEDefaultView* default_; - tray::IMEDetailedView* detailed_; - - bool message_shown_; - - DISALLOW_COPY_AND_ASSIGN(TrayIME); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_IME_TRAY_IME_H_ diff --git a/chromium/ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h b/chromium/ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h deleted file mode 100644 index 96edf84f4d5..00000000000 --- a/chromium/ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_KEYBOARD_BRIGHTNESS_KEYBOARD_BRIGHTNESS_CONTROL_DELEGATE_H_ -#define ASH_SYSTEM_KEYBOARD_BRIGHTNESS_KEYBOARD_BRIGHTNESS_CONTROL_DELEGATE_H_ - -namespace ui { -class Accelerator; -} // namespace ui - -namespace ash { - -// Delegate for controlling the keyboard brightness. -class KeyboardBrightnessControlDelegate { - public: - virtual ~KeyboardBrightnessControlDelegate() {} - - // Handles an accelerator-driven request to decrease or increase the keyboard - // brightness. Returns true if the brightness is changed. - virtual bool HandleKeyboardBrightnessDown( - const ui::Accelerator& accelerator) = 0; - virtual bool HandleKeyboardBrightnessUp( - const ui::Accelerator& accelerator) = 0; -}; - -} // namespace ash - -#endif // ASH_SYSTEM_KEYBOARD_BRIGHTNESS_KEYBOARD_BRIGHTNESS_CONTROL_DELEGATE_H_ diff --git a/chromium/ash/system/locale/locale_notification_controller.cc b/chromium/ash/system/locale/locale_notification_controller.cc deleted file mode 100644 index 419baafb404..00000000000 --- a/chromium/ash/system/locale/locale_notification_controller.cc +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/locale/locale_notification_controller.h" - -#include "ash/shell.h" -#include "ash/system/system_notifier.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "base/strings/string16.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" -#include "ui/message_center/notification_delegate.h" -#include "ui/message_center/notification_types.h" - -using message_center::Notification; - -namespace ash { -namespace internal { -namespace { - -const char kLocaleChangeNotificationId[] = "chrome://settings/locale"; - -class LocaleNotificationDelegate : public message_center::NotificationDelegate { - public: - explicit LocaleNotificationDelegate(LocaleObserver::Delegate* delegate); - - protected: - virtual ~LocaleNotificationDelegate(); - - // message_center::NotificationDelegate overrides: - virtual void Display() OVERRIDE; - virtual void Error() OVERRIDE; - virtual void Close(bool by_user) OVERRIDE; - virtual bool HasClickedListener() OVERRIDE; - virtual void Click() OVERRIDE; - virtual void ButtonClick(int button_index) OVERRIDE; - - private: - LocaleObserver::Delegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(LocaleNotificationDelegate); -}; - -LocaleNotificationDelegate::LocaleNotificationDelegate( - LocaleObserver::Delegate* delegate) - : delegate_(delegate) { - DCHECK(delegate_); -} - -LocaleNotificationDelegate::~LocaleNotificationDelegate() { -} - -void LocaleNotificationDelegate::Display() { -} - -void LocaleNotificationDelegate::Error() { -} - -void LocaleNotificationDelegate::Close(bool by_user) { - delegate_->AcceptLocaleChange(); -} - -bool LocaleNotificationDelegate::HasClickedListener() { - return true; -} - -void LocaleNotificationDelegate::Click() { - delegate_->AcceptLocaleChange(); -} - -void LocaleNotificationDelegate::ButtonClick(int button_index) { - DCHECK_EQ(0, button_index); - delegate_->RevertLocaleChange(); -} - -} // namespace - -LocaleNotificationController::LocaleNotificationController() - : delegate_(NULL) { - Shell::GetInstance()->system_tray_notifier()->AddLocaleObserver(this); -} - -LocaleNotificationController::~LocaleNotificationController() { - Shell::GetInstance()->system_tray_notifier()->RemoveLocaleObserver(this); -} - -void LocaleNotificationController::OnLocaleChanged( - LocaleObserver::Delegate* delegate, - const std::string& cur_locale, - const std::string& from_locale, - const std::string& to_locale) { - if (!delegate) - return; - - base::string16 from = l10n_util::GetDisplayNameForLocale( - from_locale, cur_locale, true); - base::string16 to = l10n_util::GetDisplayNameForLocale( - to_locale, cur_locale, true); - - message_center::RichNotificationData optional; - optional.buttons.push_back(message_center::ButtonInfo( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from))); - optional.never_timeout = true; - - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - scoped_ptr<Notification> notification(new Notification( - message_center::NOTIFICATION_TYPE_SIMPLE, - kLocaleChangeNotificationId, - base::string16() /* title */, - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE, from, to), - bundle.GetImageNamed(IDR_AURA_UBER_TRAY_LOCALE), - base::string16() /* display_source */, - message_center::NotifierId( - message_center::NotifierId::SYSTEM_COMPONENT, - system_notifier::kNotifierLocale), - optional, - new LocaleNotificationDelegate(delegate))); - message_center::MessageCenter::Get()->AddNotification(notification.Pass()); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/locale/locale_notification_controller.h b/chromium/ash/system/locale/locale_notification_controller.h deleted file mode 100644 index d23895c8206..00000000000 --- a/chromium/ash/system/locale/locale_notification_controller.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_LOCALE_LOCALE_NOTIFICATION_CONTROLLER_H_ -#define ASH_SYSTEM_LOCALE_LOCALE_NOTIFICATION_CONTROLLER_H_ - -#include <string> - -#include "ash/system/locale/locale_observer.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" - -namespace ash { -namespace internal { - -// Observes the locale change and creates rich notification for the change. -class LocaleNotificationController : public LocaleObserver { - public: - LocaleNotificationController(); - virtual ~LocaleNotificationController(); - - private: - // Overridden from LocaleObserver. - virtual void OnLocaleChanged(LocaleObserver::Delegate* delegate, - const std::string& cur_locale, - const std::string& from_locale, - const std::string& to_locale) OVERRIDE; - - LocaleObserver::Delegate* delegate_; - std::string cur_locale_; - std::string from_locale_; - std::string to_locale_; - - DISALLOW_COPY_AND_ASSIGN(LocaleNotificationController); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_LOCALE_LOCALE_NOTIFICATION_CONTROLLER_H_ diff --git a/chromium/ash/system/locale/locale_observer.h b/chromium/ash/system/locale/locale_observer.h deleted file mode 100644 index 939bd60faa9..00000000000 --- a/chromium/ash/system/locale/locale_observer.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_LOCALE_LOCALE_OBSERVER_H_ -#define ASH_SYSTEM_LOCALE_LOCALE_OBSERVER_H_ - -#include "ash/ash_export.h" - -namespace ash { - -class ASH_EXPORT LocaleObserver { - public: - class Delegate { - public: - virtual ~Delegate() {} - - virtual void AcceptLocaleChange() = 0; - virtual void RevertLocaleChange() = 0; - }; - - virtual ~LocaleObserver() {} - - virtual void OnLocaleChanged(Delegate* delegate, - const std::string& cur_locale, - const std::string& from_locale, - const std::string& to_locale) = 0; -}; - -} // namespace ash - -#endif // ASH_SYSTEM_LOCALE_LOCALE_OBSERVER_H_ diff --git a/chromium/ash/system/logout_button/logout_button_observer.h b/chromium/ash/system/logout_button/logout_button_observer.h deleted file mode 100644 index 9234c7d758d..00000000000 --- a/chromium/ash/system/logout_button/logout_button_observer.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_OBSERVER_H_ -#define ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_OBSERVER_H_ - -namespace ash { - -// Observer for the value of the kShowLogoutButtonInTray pref that determines -// whether a logout button should be shown in the system tray during a session. -class LogoutButtonObserver { - public: - virtual ~LogoutButtonObserver() {} - - // Called when the value of the kShowLogoutButtonInTray pref changes. - virtual void OnShowLogoutButtonInTrayChanged(bool show) = 0; -}; - -} // namespace ash - -#endif // ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_OBSERVER_H_ diff --git a/chromium/ash/system/logout_button/logout_button_tray.cc b/chromium/ash/system/logout_button/logout_button_tray.cc deleted file mode 100644 index c06073040c5..00000000000 --- a/chromium/ash/system/logout_button/logout_button_tray.cc +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/logout_button/logout_button_tray.h" - -#include "ash/shelf/shelf_types.h" -#include "ash/shell.h" -#include "ash/system/status_area_widget.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_utils.h" -#include "base/logging.h" -#include "grit/ash_resources.h" -#include "third_party/skia/include/core/SkColor.h" -#include "ui/events/event.h" -#include "ui/gfx/font.h" -#include "ui/gfx/insets.h" -#include "ui/gfx/size.h" -#include "ui/views/bubble/tray_bubble_view.h" -#include "ui/views/controls/button/label_button.h" -#include "ui/views/controls/button/label_button_border.h" -#include "ui/views/painter.h" - -namespace ash { - -namespace internal { - -namespace { - -const int kLogoutButtonHorizontalExtraPadding = 7; - -const int kLogoutButtonNormalImages[] = { - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_LEFT, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_RIGHT, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_LEFT, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_CENTER, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_RIGHT, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM_LEFT, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM_RIGHT -}; - -const int kLogoutButtonPushedImages[] = { - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP_LEFT, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP_RIGHT, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_LEFT, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_CENTER, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_RIGHT, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM_LEFT, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM, - IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM_RIGHT -}; - -class LogoutButton : public views::LabelButton { - public: - LogoutButton(views::ButtonListener* listener); - virtual ~LogoutButton(); - - private: - DISALLOW_COPY_AND_ASSIGN(LogoutButton); -}; - -} // namespace - -LogoutButton::LogoutButton(views::ButtonListener* listener) - : views::LabelButton(listener, base::string16()) { - SetupLabelForTray(label()); - SetFont(GetFont().DeriveFont(0, gfx::Font::NORMAL)); - for (size_t state = 0; state < views::Button::STATE_COUNT; ++state) - SetTextColor(static_cast<views::Button::ButtonState>(state), SK_ColorWHITE); - - views::LabelButtonBorder* border = - new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON); - border->SetPainter(false, views::Button::STATE_NORMAL, - views::Painter::CreateImageGridPainter(kLogoutButtonNormalImages)); - border->SetPainter(false, views::Button::STATE_HOVERED, - views::Painter::CreateImageGridPainter(kLogoutButtonNormalImages)); - border->SetPainter(false, views::Button::STATE_PRESSED, - views::Painter::CreateImageGridPainter(kLogoutButtonPushedImages)); - gfx::Insets insets = border->GetInsets(); - insets += gfx::Insets(0, kLogoutButtonHorizontalExtraPadding, - 0, kLogoutButtonHorizontalExtraPadding); - border->set_insets(insets); - set_border(border); - set_animate_on_state_change(false); - - set_min_size(gfx::Size(0, GetShelfItemHeight())); -} - -LogoutButton::~LogoutButton() { -} - -LogoutButtonTray::LogoutButtonTray(StatusAreaWidget* status_area_widget) - : TrayBackgroundView(status_area_widget), - button_(NULL), - login_status_(user::LOGGED_IN_NONE), - show_logout_button_in_tray_(false) { - button_ = new LogoutButton(this); - tray_container()->AddChildView(button_); - tray_container()->set_border(NULL); - Shell::GetInstance()->system_tray_notifier()->AddLogoutButtonObserver(this); -} - -LogoutButtonTray::~LogoutButtonTray() { - Shell::GetInstance()->system_tray_notifier()-> - RemoveLogoutButtonObserver(this); -} - -void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) { - TrayBackgroundView::SetShelfAlignment(alignment); - tray_container()->set_border(NULL); -} - -base::string16 LogoutButtonTray::GetAccessibleNameForTray() { - return button_->GetText(); -} - -void LogoutButtonTray::HideBubbleWithView( - const views::TrayBubbleView* bubble_view) { -} - -bool LogoutButtonTray::ClickedOutsideBubble() { - return false; -} - -void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) { - show_logout_button_in_tray_ = show; - UpdateVisibility(); -} - -void LogoutButtonTray::ButtonPressed(views::Button* sender, - const ui::Event& event) { - DCHECK_EQ(sender, button_); - Shell::GetInstance()->system_tray_delegate()->SignOut(); -} - -void LogoutButtonTray::UpdateAfterLoginStatusChange( - user::LoginStatus login_status) { - login_status_ = login_status; - const base::string16 title = - GetLocalizedSignOutStringForStatus(login_status, false); - button_->SetText(title); - button_->SetAccessibleName(title); - UpdateVisibility(); -} - -void LogoutButtonTray::UpdateVisibility() { - SetVisible(show_logout_button_in_tray_ && - login_status_ != user::LOGGED_IN_NONE && - login_status_ != user::LOGGED_IN_LOCKED); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/logout_button/logout_button_tray.h b/chromium/ash/system/logout_button/logout_button_tray.h deleted file mode 100644 index 5683e5e2654..00000000000 --- a/chromium/ash/system/logout_button/logout_button_tray.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_TRAY_H_ -#define ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_TRAY_H_ - -#include "ash/system/logout_button/logout_button_observer.h" -#include "ash/system/tray/tray_background_view.h" -#include "ash/system/user/login_status.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/views/controls/button/button.h" - -namespace views { -class LabelButton; -} - -namespace ash { -namespace internal { - -class StatusAreaWidget; - -// Adds a logout button to the launcher's status area if enabled by the -// kShowLogoutButtonInTray pref. -class LogoutButtonTray : public TrayBackgroundView, - public LogoutButtonObserver, - public views::ButtonListener { - public: - explicit LogoutButtonTray(StatusAreaWidget* status_area_widget); - virtual ~LogoutButtonTray(); - - // TrayBackgroundView: - virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; - virtual base::string16 GetAccessibleNameForTray() OVERRIDE; - virtual void HideBubbleWithView( - const views::TrayBubbleView* bubble_view) OVERRIDE; - virtual bool ClickedOutsideBubble() OVERRIDE; - - // LogoutButtonObserver: - virtual void OnShowLogoutButtonInTrayChanged(bool show) OVERRIDE; - - // views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE; - - void UpdateAfterLoginStatusChange(user::LoginStatus login_status); - - private: - void UpdateVisibility(); - - views::LabelButton* button_; // Not owned. - user::LoginStatus login_status_; - bool show_logout_button_in_tray_; - - DISALLOW_COPY_AND_ASSIGN(LogoutButtonTray); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_TRAY_H_ diff --git a/chromium/ash/system/monitor/tray_monitor.cc b/chromium/ash/system/monitor/tray_monitor.cc deleted file mode 100644 index bc3d532ea55..00000000000 --- a/chromium/ash/system/monitor/tray_monitor.cc +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/monitor/tray_monitor.h" - -#include "ash/system/tray/tray_item_view.h" -#include "base/process/memory.h" -#include "base/process/process_metrics.h" -#include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "content/public/browser/gpu_data_manager.h" -#include "ui/base/text/bytes_formatting.h" -#include "ui/views/border.h" -#include "ui/views/controls/label.h" - -namespace { -const int kRefreshTimeoutMs = 1000; -} - -namespace ash { -namespace internal { - -TrayMonitor::TrayMonitor(SystemTray* system_tray) - : SystemTrayItem(system_tray), - label_(NULL) { - refresh_timer_.Start(FROM_HERE, - base::TimeDelta::FromMilliseconds(kRefreshTimeoutMs), - this, &TrayMonitor::OnTimer); -} - -TrayMonitor::~TrayMonitor() { - label_ = NULL; -} - -views::View* TrayMonitor::CreateTrayView(user::LoginStatus status) { - TrayItemView* view = new TrayItemView(this); - view->CreateLabel(); - label_ = view->label(); - label_->SetAutoColorReadabilityEnabled(false); - label_->SetEnabledColor(SK_ColorWHITE); - label_->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); - label_->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), - SkColorSetARGB(64, 0, 0, 0)); - label_->SetShadowOffset(0, 1); - label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - label_->SetFont(label_->font().DeriveFont(-2)); - return view; -} - -void TrayMonitor::DestroyTrayView() { - label_ = NULL; -} - -void TrayMonitor::OnTimer() { - content::GpuDataManager::GetGpuProcessHandlesCallback callback = - base::Bind(&TrayMonitor::OnGotHandles, base::Unretained(this)); - refresh_timer_.Stop(); - content::GpuDataManager::GetInstance()->GetGpuProcessHandles(callback); -} - -void TrayMonitor::OnGotHandles(const std::list<base::ProcessHandle>& handles) { - base::SystemMemoryInfoKB mem_info; - base::GetSystemMemoryInfo(&mem_info); - std::string output; - base::string16 free_bytes = - ui::FormatBytes(static_cast<int64>(mem_info.free) * 1024); - output = base::StringPrintf("free: %s", UTF16ToUTF8(free_bytes).c_str()); -#if defined(OS_CHROMEOS) - if (mem_info.gem_size != -1) { - base::string16 gem_size = ui::FormatBytes(mem_info.gem_size); - output += base::StringPrintf(" gmem: %s", UTF16ToUTF8(gem_size).c_str()); - if (mem_info.gem_objects != -1) - output += base::StringPrintf(" gobjects: %d", mem_info.gem_objects); - } -#endif - size_t total_private_bytes = 0, total_shared_bytes = 0; - for (std::list<base::ProcessHandle>::const_iterator i = handles.begin(); - i != handles.end(); ++i) { - base::ProcessMetrics* pm = base::ProcessMetrics::CreateProcessMetrics(*i); - size_t private_bytes, shared_bytes; - pm->GetMemoryBytes(&private_bytes, &shared_bytes); - total_private_bytes += private_bytes; - total_shared_bytes += shared_bytes; - delete pm; - } - base::string16 private_size = ui::FormatBytes(total_private_bytes); - base::string16 shared_size = ui::FormatBytes(total_shared_bytes); - - output += base::StringPrintf("\nGPU private: %s shared: %s", - UTF16ToUTF8(private_size).c_str(), - UTF16ToUTF8(shared_size).c_str()); - label_->SetText(UTF8ToUTF16(output)); - refresh_timer_.Start(FROM_HERE, - base::TimeDelta::FromMilliseconds(kRefreshTimeoutMs), - this, &TrayMonitor::OnTimer); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/monitor/tray_monitor.h b/chromium/ash/system/monitor/tray_monitor.h deleted file mode 100644 index 31c4f146cda..00000000000 --- a/chromium/ash/system/monitor/tray_monitor.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_DATE_TRAY_MONITOR_H_ -#define ASH_SYSTEM_DATE_TRAY_MONITOR_H_ - -#include <list> - -#include "ash/system/tray/system_tray_item.h" -#include "base/process/process.h" -#include "base/timer/timer.h" - -namespace views { -class Label; -} - -namespace ash { -namespace internal { - -class TrayMonitor : public SystemTrayItem { - public: - explicit TrayMonitor(SystemTray* system_tray); - virtual ~TrayMonitor(); - - private: - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - - void OnTimer(); - void OnGotHandles(const std::list<base::ProcessHandle>& handles); - - views::Label* label_; - base::RepeatingTimer<TrayMonitor> refresh_timer_; - - DISALLOW_COPY_AND_ASSIGN(TrayMonitor); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_DATE_TRAY_MONITOR_H_ diff --git a/chromium/ash/system/session_length_limit/session_length_limit_observer.h b/chromium/ash/system/session_length_limit/session_length_limit_observer.h deleted file mode 100644 index 3fcba64d7e1..00000000000 --- a/chromium/ash/system/session_length_limit/session_length_limit_observer.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_SESSION_LENGTH_LIMIT_SESSION_LENGTH_LIMIT_OBSERVER_H_ -#define ASH_SYSTEM_SESSION_LENGTH_LIMIT_SESSION_LENGTH_LIMIT_OBSERVER_H_ - -#include "ash/ash_export.h" - -namespace ash { - -// Observer for the session length limit. -class ASH_EXPORT SessionLengthLimitObserver { - public: - virtual ~SessionLengthLimitObserver() {} - - // Called when the session start time is updated. - virtual void OnSessionStartTimeChanged() = 0; - - // Called when the session length limit is updated. - virtual void OnSessionLengthLimitChanged() = 0; -}; - -} // namespace ash - -#endif // ASH_SYSTEM_SESSION_LENGTH_LIMIT_SESSION_LENGTH_LIMIT_OBSERVER_H_ diff --git a/chromium/ash/system/session_length_limit/tray_session_length_limit.cc b/chromium/ash/system/session_length_limit/tray_session_length_limit.cc deleted file mode 100644 index 81425afbade..00000000000 --- a/chromium/ash/system/session_length_limit/tray_session_length_limit.cc +++ /dev/null @@ -1,386 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/session_length_limit/tray_session_length_limit.h" - -#include <algorithm> - -#include "ash/shelf/shelf_types.h" -#include "ash/shell.h" -#include "ash/system/system_notifier.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_utils.h" -#include "base/location.h" -#include "base/logging.h" -#include "base/strings/string16.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "third_party/skia/include/core/SkColor.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/l10n/time_format.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/font.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" -#include "ui/views/border.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/grid_layout.h" -#include "ui/views/view.h" - -using message_center::Notification; - -namespace ash { -namespace internal { - -namespace { - -// If the remaining session time falls below this threshold, the user should be -// informed that the session is about to expire. -const int kExpiringSoonThresholdInSeconds = 5 * 60; // 5 minutes. - -// Color in which the remaining session time is normally shown. -const SkColor kRemainingTimeColor = SK_ColorWHITE; -// Color in which the remaining session time is shown when it is expiring soon. -const SkColor kRemainingTimeExpiringSoonColor = SK_ColorRED; - -views::Label* CreateAndSetupLabel() { - views::Label* label = new views::Label; - label->SetHorizontalAlignment(gfx::ALIGN_LEFT); - SetupLabelForTray(label); - gfx::Font font = label->font(); - label->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD)); - return label; -} - -base::string16 IntToTwoDigitString(int value) { - DCHECK_GE(value, 0); - DCHECK_LE(value, 99); - if (value < 10) - return ASCIIToUTF16("0") + base::IntToString16(value); - return base::IntToString16(value); -} - -base::string16 FormatRemainingSessionTimeNotification( - const base::TimeDelta& remaining_session_time) { - return l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_REMAINING_SESSION_TIME_NOTIFICATION, - ui::TimeFormat::TimeDurationLong(remaining_session_time)); -} - -// Creates, or updates the notification for session length timeout with -// |remaining_time|. |state_changed| is true when its internal state has been -// changed from another. -void CreateOrUpdateNotification(const std::string& notification_id, - const base::TimeDelta& remaining_time, - bool state_changed) { - message_center::MessageCenter* message_center = - message_center::MessageCenter::Get(); - - // Do not create a new notification if no state has changed. It may happen - // when the notification is already closed by the user, see crbug.com/285941. - if (!state_changed && !message_center->HasNotification(notification_id)) - return; - - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - message_center::RichNotificationData data; - // Makes the spoken feedback only when the state has been changed. - data.should_make_spoken_feedback_for_popup_updates = state_changed; - scoped_ptr<Notification> notification(new Notification( - message_center::NOTIFICATION_TYPE_SIMPLE, - notification_id, - FormatRemainingSessionTimeNotification(remaining_time), - base::string16() /* message */, - bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SESSION_LENGTH_LIMIT_TIMER), - base::string16() /* display_source */, - message_center::NotifierId( - message_center::NotifierId::SYSTEM_COMPONENT, - system_notifier::kNotifierSessionLengthTimeout), - data, - NULL /* delegate */)); - notification->SetSystemPriority(); - message_center::MessageCenter::Get()->AddNotification(notification.Pass()); -} - -} // namespace - -namespace tray { - -class RemainingSessionTimeTrayView : public views::View { - public: - RemainingSessionTimeTrayView(const TraySessionLengthLimit* owner, - ShelfAlignment shelf_alignment); - virtual ~RemainingSessionTimeTrayView(); - - void UpdateClockLayout(ShelfAlignment shelf_alignment); - void Update(); - - private: - void SetBorder(ShelfAlignment shelf_alignment); - - const TraySessionLengthLimit* owner_; - - views::Label* horizontal_layout_label_; - views::Label* vertical_layout_label_hours_left_; - views::Label* vertical_layout_label_hours_right_; - views::Label* vertical_layout_label_minutes_left_; - views::Label* vertical_layout_label_minutes_right_; - views::Label* vertical_layout_label_seconds_left_; - views::Label* vertical_layout_label_seconds_right_; - - DISALLOW_COPY_AND_ASSIGN(RemainingSessionTimeTrayView); -}; - -RemainingSessionTimeTrayView::RemainingSessionTimeTrayView( - const TraySessionLengthLimit* owner, - ShelfAlignment shelf_alignment) - : owner_(owner), - horizontal_layout_label_(NULL), - vertical_layout_label_hours_left_(NULL), - vertical_layout_label_hours_right_(NULL), - vertical_layout_label_minutes_left_(NULL), - vertical_layout_label_minutes_right_(NULL), - vertical_layout_label_seconds_left_(NULL), - vertical_layout_label_seconds_right_(NULL) { - UpdateClockLayout(shelf_alignment); -} - -RemainingSessionTimeTrayView::~RemainingSessionTimeTrayView() { -} - -void RemainingSessionTimeTrayView::UpdateClockLayout( - ShelfAlignment shelf_alignment) { - SetBorder(shelf_alignment); - const bool horizontal_layout = (shelf_alignment == SHELF_ALIGNMENT_BOTTOM || - shelf_alignment == SHELF_ALIGNMENT_TOP); - if (horizontal_layout && !horizontal_layout_label_) { - // Remove labels used for vertical layout. - RemoveAllChildViews(true); - vertical_layout_label_hours_left_ = NULL; - vertical_layout_label_hours_right_ = NULL; - vertical_layout_label_minutes_left_ = NULL; - vertical_layout_label_minutes_right_ = NULL; - vertical_layout_label_seconds_left_ = NULL; - vertical_layout_label_seconds_right_ = NULL; - - // Create label used for horizontal layout. - horizontal_layout_label_ = CreateAndSetupLabel(); - - // Construct layout. - SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); - AddChildView(horizontal_layout_label_); - - } else if (!horizontal_layout && horizontal_layout_label_) { - // Remove label used for horizontal layout. - RemoveAllChildViews(true); - horizontal_layout_label_ = NULL; - - // Create labels used for vertical layout. - vertical_layout_label_hours_left_ = CreateAndSetupLabel(); - vertical_layout_label_hours_right_ = CreateAndSetupLabel(); - vertical_layout_label_minutes_left_ = CreateAndSetupLabel(); - vertical_layout_label_minutes_right_ = CreateAndSetupLabel(); - vertical_layout_label_seconds_left_ = CreateAndSetupLabel(); - vertical_layout_label_seconds_right_ = CreateAndSetupLabel(); - - // Construct layout. - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); - views::ColumnSet* columns = layout->AddColumnSet(0); - columns->AddPaddingColumn(0, 6); - columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, - 0, views::GridLayout::USE_PREF, 0, 0); - columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, - 0, views::GridLayout::USE_PREF, 0, 0); - layout->AddPaddingRow(0, kTrayLabelItemVerticalPaddingVerticalAlignment); - layout->StartRow(0, 0); - layout->AddView(vertical_layout_label_hours_left_); - layout->AddView(vertical_layout_label_hours_right_); - layout->StartRow(0, 0); - layout->AddView(vertical_layout_label_minutes_left_); - layout->AddView(vertical_layout_label_minutes_right_); - layout->StartRow(0, 0); - layout->AddView(vertical_layout_label_seconds_left_); - layout->AddView(vertical_layout_label_seconds_right_); - layout->AddPaddingRow(0, kTrayLabelItemVerticalPaddingVerticalAlignment); - } - Update(); -} - -void RemainingSessionTimeTrayView::Update() { - const TraySessionLengthLimit::LimitState limit_state = - owner_->GetLimitState(); - - if (limit_state == TraySessionLengthLimit::LIMIT_NONE) { - SetVisible(false); - return; - } - - int seconds = owner_->GetRemainingSessionTime().InSeconds(); - // If the remaining session time is 100 hours or more, show 99:59:59 instead. - seconds = std::min(seconds, 100 * 60 * 60 - 1); // 100 hours - 1 second. - int minutes = seconds / 60; - seconds %= 60; - const int hours = minutes / 60; - minutes %= 60; - - const base::string16 hours_str = IntToTwoDigitString(hours); - const base::string16 minutes_str = IntToTwoDigitString(minutes); - const base::string16 seconds_str = IntToTwoDigitString(seconds); - const SkColor color = - limit_state == TraySessionLengthLimit::LIMIT_EXPIRING_SOON ? - kRemainingTimeExpiringSoonColor : kRemainingTimeColor; - - if (horizontal_layout_label_) { - horizontal_layout_label_->SetText(l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_REMAINING_SESSION_TIME, - hours_str, minutes_str, seconds_str)); - horizontal_layout_label_->SetEnabledColor(color); - } else if (vertical_layout_label_hours_left_) { - vertical_layout_label_hours_left_->SetText(hours_str.substr(0, 1)); - vertical_layout_label_hours_right_->SetText(hours_str.substr(1, 1)); - vertical_layout_label_minutes_left_->SetText(minutes_str.substr(0, 1)); - vertical_layout_label_minutes_right_->SetText(minutes_str.substr(1, 1)); - vertical_layout_label_seconds_left_->SetText(seconds_str.substr(0, 1)); - vertical_layout_label_seconds_right_->SetText(seconds_str.substr(1, 1)); - vertical_layout_label_hours_left_->SetEnabledColor(color); - vertical_layout_label_hours_right_->SetEnabledColor(color); - vertical_layout_label_minutes_left_->SetEnabledColor(color); - vertical_layout_label_minutes_right_->SetEnabledColor(color); - vertical_layout_label_seconds_left_->SetEnabledColor(color); - vertical_layout_label_seconds_right_->SetEnabledColor(color); - } - - Layout(); - SetVisible(true); -} - -void RemainingSessionTimeTrayView::SetBorder(ShelfAlignment shelf_alignment) { - if (shelf_alignment == SHELF_ALIGNMENT_BOTTOM || - shelf_alignment == SHELF_ALIGNMENT_TOP) { - set_border(views::Border::CreateEmptyBorder( - 0, kTrayLabelItemHorizontalPaddingBottomAlignment, - 0, kTrayLabelItemHorizontalPaddingBottomAlignment)); - } else { - set_border(NULL); - } -} - -} // namespace tray - -// static -const char TraySessionLengthLimit::kNotificationId[] = - "chrome://session/timeout"; - -TraySessionLengthLimit::TraySessionLengthLimit(SystemTray* system_tray) - : SystemTrayItem(system_tray), - tray_view_(NULL), - limit_state_(LIMIT_NONE) { - Shell::GetInstance()->system_tray_notifier()-> - AddSessionLengthLimitObserver(this); - Update(); -} - -TraySessionLengthLimit::~TraySessionLengthLimit() { - Shell::GetInstance()->system_tray_notifier()-> - RemoveSessionLengthLimitObserver(this); -} - -views::View* TraySessionLengthLimit::CreateTrayView(user::LoginStatus status) { - CHECK(tray_view_ == NULL); - tray_view_ = new tray::RemainingSessionTimeTrayView( - this, system_tray()->shelf_alignment()); - return tray_view_; -} - -void TraySessionLengthLimit::DestroyTrayView() { - tray_view_ = NULL; -} - -void TraySessionLengthLimit::UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) { - if (tray_view_) - tray_view_->UpdateClockLayout(alignment); -} - -void TraySessionLengthLimit::OnSessionStartTimeChanged() { - Update(); -} - -void TraySessionLengthLimit::OnSessionLengthLimitChanged() { - Update(); -} - -TraySessionLengthLimit::LimitState - TraySessionLengthLimit::GetLimitState() const { - return limit_state_; -} - -base::TimeDelta TraySessionLengthLimit::GetRemainingSessionTime() const { - return remaining_session_time_; -} - -void TraySessionLengthLimit::Update() { - SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); - const LimitState previous_limit_state = limit_state_; - if (!delegate->GetSessionStartTime(&session_start_time_) || - !delegate->GetSessionLengthLimit(&limit_)) { - remaining_session_time_ = base::TimeDelta(); - limit_state_ = LIMIT_NONE; - timer_.reset(); - } else { - remaining_session_time_ = std::max( - limit_ - (base::TimeTicks::Now() - session_start_time_), - base::TimeDelta()); - limit_state_ = remaining_session_time_.InSeconds() <= - kExpiringSoonThresholdInSeconds ? LIMIT_EXPIRING_SOON : LIMIT_SET; - if (!timer_) - timer_.reset(new base::RepeatingTimer<TraySessionLengthLimit>); - if (!timer_->IsRunning()) { - // Start a timer that will update the remaining session time every second. - timer_->Start(FROM_HERE, - base::TimeDelta::FromSeconds(1), - this, - &TraySessionLengthLimit::Update); - } - } - - switch (limit_state_) { - case LIMIT_NONE: - message_center::MessageCenter::Get()->RemoveNotification( - kNotificationId, false /* by_user */); - break; - case LIMIT_SET: - CreateOrUpdateNotification( - kNotificationId, - remaining_session_time_, - previous_limit_state == LIMIT_NONE); - break; - case LIMIT_EXPIRING_SOON: - CreateOrUpdateNotification( - kNotificationId, - remaining_session_time_, - previous_limit_state == LIMIT_NONE || - previous_limit_state == LIMIT_SET); - break; - } - - // Update the tray view last so that it can check whether the notification - // view is currently visible or not. - if (tray_view_) - tray_view_->Update(); -} - -bool TraySessionLengthLimit::IsTrayViewVisibleForTest() { - return tray_view_ && tray_view_->visible(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/session_length_limit/tray_session_length_limit.h b/chromium/ash/system/session_length_limit/tray_session_length_limit.h deleted file mode 100644 index 6fcd76ef45a..00000000000 --- a/chromium/ash/system/session_length_limit/tray_session_length_limit.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_SESSION_LENGTH_LIMIT_TRAY_SESSION_LENGTH_LIMIT_H_ -#define ASH_SYSTEM_SESSION_LENGTH_LIMIT_TRAY_SESSION_LENGTH_LIMIT_H_ - -#include "ash/system/session_length_limit/session_length_limit_observer.h" -#include "ash/system/tray/system_tray_item.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "base/time/time.h" -#include "base/timer/timer.h" - -namespace ash { - -namespace test { -class TraySessionLengthLimitTest; -} - -namespace internal { - -namespace tray { -class RemainingSessionTimeTrayView; -} - -// Adds a countdown timer to the system tray if the session length is limited. -class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem, - public SessionLengthLimitObserver { - public: - enum LimitState { - LIMIT_NONE, - LIMIT_SET, - LIMIT_EXPIRING_SOON - }; - - explicit TraySessionLengthLimit(SystemTray* system_tray); - virtual ~TraySessionLengthLimit(); - - // SystemTrayItem: - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) OVERRIDE; - - // SessionLengthLimitObserver: - virtual void OnSessionStartTimeChanged() OVERRIDE; - virtual void OnSessionLengthLimitChanged() OVERRIDE; - - LimitState GetLimitState() const; - base::TimeDelta GetRemainingSessionTime() const; - - private: - friend class test::TraySessionLengthLimitTest; - - static const char kNotificationId[]; - - void Update(); - - bool IsTrayViewVisibleForTest(); - - tray::RemainingSessionTimeTrayView* tray_view_; - - LimitState limit_state_; - base::TimeTicks session_start_time_; - base::TimeDelta limit_; - base::TimeDelta remaining_session_time_; - scoped_ptr<base::RepeatingTimer<TraySessionLengthLimit> > timer_; - - DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_SESSION_LENGTH_LIMIT_TRAY_SESSION_LENGTH_LIMIT_H_ diff --git a/chromium/ash/system/session_length_limit/tray_session_length_limit_unittest.cc b/chromium/ash/system/session_length_limit/tray_session_length_limit_unittest.cc deleted file mode 100644 index 2b05de9c381..00000000000 --- a/chromium/ash/system/session_length_limit/tray_session_length_limit_unittest.cc +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/session_length_limit/tray_session_length_limit.h" - -#include "ash/root_window_controller.h" -#include "ash/shell.h" -#include "ash/system/tray/system_tray.h" -#include "ash/test/ash_test_base.h" -#include "ash/test/test_system_tray_delegate.h" -#include "base/time/time.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/notification.h" -#include "ui/message_center/notification_types.h" - -namespace ash { -namespace test { - -class TraySessionLengthLimitTest : public AshTestBase { - public: - TraySessionLengthLimitTest() {} - virtual ~TraySessionLengthLimitTest() {} - - virtual void SetUp() OVERRIDE { - AshTestBase::SetUp(); - SystemTray* system_tray = - Shell::GetPrimaryRootWindowController()->GetSystemTray(); - tray_session_length_limit_ = new internal::TraySessionLengthLimit( - system_tray); - system_tray->AddTrayItem(tray_session_length_limit_); - } - - virtual void TearDown() OVERRIDE { - AshTestBase::TearDown(); - } - - protected: - void UpdateSessionLengthLimitInMin(int mins) { - GetSystemTrayDelegate()->SetSessionLengthLimitForTest( - base::TimeDelta::FromMinutes(mins)); - tray_session_length_limit_->OnSessionLengthLimitChanged(); - } - - message_center::Notification* GetNotification() { - const message_center::NotificationList::Notifications& notifications = - message_center::MessageCenter::Get()->GetVisibleNotifications(); - for (message_center::NotificationList::Notifications::const_iterator iter = - notifications.begin(); iter != notifications.end(); ++iter) { - if ((*iter)->id() == internal::TraySessionLengthLimit::kNotificationId) - return *iter; - } - return NULL; - } - - void ClearSessionLengthLimit() { - GetSystemTrayDelegate()->ClearSessionLengthLimit(); - tray_session_length_limit_->OnSessionLengthLimitChanged(); - } - - void RemoveNotification() { - message_center::MessageCenter::Get()->RemoveNotification( - internal::TraySessionLengthLimit::kNotificationId, true /* by_user */); - } - - internal::TraySessionLengthLimit* tray_session_length_limit() { - return tray_session_length_limit_; - } - - bool IsTrayViewVisible() { - return tray_session_length_limit_->IsTrayViewVisibleForTest(); - } - - private: - // Weak reference, owned by the SystemTray. - internal::TraySessionLengthLimit* tray_session_length_limit_; - - DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimitTest); -}; - -TEST_F(TraySessionLengthLimitTest, TrayView) { - // No session limit. - EXPECT_FALSE(IsTrayViewVisible()); - - // Limit is 15 min. - UpdateSessionLengthLimitInMin(15); - EXPECT_EQ(internal::TraySessionLengthLimit::LIMIT_SET, - tray_session_length_limit()->GetLimitState()); - EXPECT_TRUE(IsTrayViewVisible()); - - // Limit is 3 min. - UpdateSessionLengthLimitInMin(3); - EXPECT_EQ(internal::TraySessionLengthLimit::LIMIT_EXPIRING_SOON, - tray_session_length_limit()->GetLimitState()); - EXPECT_TRUE(IsTrayViewVisible()); - - // Nothing left. - UpdateSessionLengthLimitInMin(0); - EXPECT_EQ(internal::TraySessionLengthLimit::LIMIT_EXPIRING_SOON, - tray_session_length_limit()->GetLimitState()); - EXPECT_TRUE(IsTrayViewVisible()); - - // Checks the behavior in case the limit goes negative. - UpdateSessionLengthLimitInMin(-5); - EXPECT_EQ(internal::TraySessionLengthLimit::LIMIT_EXPIRING_SOON, - tray_session_length_limit()->GetLimitState()); - EXPECT_TRUE(IsTrayViewVisible()); - - // Clears the session length limit, the TrayView should get invisible. - ClearSessionLengthLimit(); - ASSERT_EQ(internal::TraySessionLengthLimit::LIMIT_NONE, - tray_session_length_limit()->GetLimitState()); - EXPECT_FALSE(IsTrayViewVisible()); -} - -TEST_F(TraySessionLengthLimitTest, Notification) { - // No notifications when no session limit. - EXPECT_FALSE(GetNotification()); - - // Limit is 15 min. - UpdateSessionLengthLimitInMin(15); - message_center::Notification* notification = GetNotification(); - EXPECT_TRUE(notification); - EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); - base::string16 first_content = notification->title(); - // Should read the content. - EXPECT_TRUE(notification->rich_notification_data(). - should_make_spoken_feedback_for_popup_updates); - - // Limit is 10 min. - UpdateSessionLengthLimitInMin(10); - notification = GetNotification(); - EXPECT_TRUE(notification); - EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); - // The content should be updated. - EXPECT_NE(first_content, notification->title()); - // Should NOT read, because just update the remaining time. - EXPECT_FALSE(notification->rich_notification_data(). - should_make_spoken_feedback_for_popup_updates); - - // Limit is 3 min. - UpdateSessionLengthLimitInMin(3); - notification = GetNotification(); - EXPECT_TRUE(notification); - EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); - // Should read the content again because the state has changed. - EXPECT_TRUE(notification->rich_notification_data(). - should_make_spoken_feedback_for_popup_updates); - - // Session length limit is updated to longer. This should not read the - // notification content again. - UpdateSessionLengthLimitInMin(15); - notification = GetNotification(); - EXPECT_TRUE(notification); - EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); - // Should not read again because the state has changed to longer. - EXPECT_FALSE(notification->rich_notification_data(). - should_make_spoken_feedback_for_popup_updates); - - // Clears the limit: the notification should be gone. - ClearSessionLengthLimit(); - EXPECT_FALSE(GetNotification()); -} - -TEST_F(TraySessionLengthLimitTest, RemoveNotification) { - // Limit is 15 min. - UpdateSessionLengthLimitInMin(15); - EXPECT_TRUE(GetNotification()); - - // Limit is 14 min. - UpdateSessionLengthLimitInMin(14); - EXPECT_TRUE(GetNotification()); - - // Removes the notification. - RemoveNotification(); - EXPECT_FALSE(GetNotification()); - - // Limit is 13 min. The notification should not re-appear. - UpdateSessionLengthLimitInMin(13); - EXPECT_FALSE(GetNotification()); - - // Limit is 3 min. The notification should re-appear because of state change. - UpdateSessionLengthLimitInMin(3); - EXPECT_TRUE(GetNotification()); - - RemoveNotification(); - - // Session length limit is updated to longer state. This should not re-appear - // the notification. - UpdateSessionLengthLimitInMin(15); - EXPECT_FALSE(GetNotification()); -} - -} // namespace test -} // namespace ash diff --git a/chromium/ash/system/status_area_widget.cc b/chromium/ash/system/status_area_widget.cc deleted file mode 100644 index 19649b1731d..00000000000 --- a/chromium/ash/system/status_area_widget.cc +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/status_area_widget.h" - -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_layout_manager.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "ash/shell_window_ids.h" -#include "ash/system/bluetooth/bluetooth_observer.h" -#include "ash/system/logout_button/logout_button_tray.h" -#include "ash/system/status_area_widget_delegate.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/web_notification/web_notification_tray.h" -#include "ash/wm/window_properties.h" -#include "base/i18n/time_formatting.h" -#include "ui/aura/window.h" -#include "ui/gfx/screen.h" - -namespace ash { - -namespace internal { - -const char StatusAreaWidget::kNativeViewName[] = "StatusAreaWidget"; - -StatusAreaWidget::StatusAreaWidget(aura::Window* status_container) - : status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate), - system_tray_(NULL), - web_notification_tray_(NULL), - logout_button_tray_(NULL), - login_status_(user::LOGGED_IN_NONE) { - views::Widget::InitParams params( - views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - params.delegate = status_area_widget_delegate_; - params.parent = status_container; - params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; - Init(params); - set_focus_on_creation(false); - SetContentsView(status_area_widget_delegate_); - GetNativeView()->SetName(kNativeViewName); -} - -StatusAreaWidget::~StatusAreaWidget() { -} - -void StatusAreaWidget::CreateTrayViews() { - AddSystemTray(); - AddWebNotificationTray(); - AddLogoutButtonTray(); - SystemTrayDelegate* delegate = - ash::Shell::GetInstance()->system_tray_delegate(); - DCHECK(delegate); - // Initialize after all trays have been created. - if (system_tray_) - system_tray_->InitializeTrayItems(delegate); - if (web_notification_tray_) - web_notification_tray_->Initialize(); - if (logout_button_tray_) - logout_button_tray_->Initialize(); - UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); -} - -void StatusAreaWidget::Shutdown() { - // Destroy the trays early, causing them to be removed from the view - // hierarchy. Do not used scoped pointers since we don't want to destroy them - // in the destructor if Shutdown() is not called (e.g. in tests). - delete logout_button_tray_; - logout_button_tray_ = NULL; - delete web_notification_tray_; - web_notification_tray_ = NULL; - delete system_tray_; - system_tray_ = NULL; -} - -bool StatusAreaWidget::ShouldShowLauncher() const { - if ((system_tray_ && system_tray_->ShouldShowLauncher()) || - (web_notification_tray_ && - web_notification_tray_->ShouldBlockLauncherAutoHide())) - return true; - - if (!RootWindowController::ForLauncher(GetNativeView())->shelf()->IsVisible()) - return false; - - // If the launcher is currently visible, don't hide the launcher if the mouse - // is in any of the notification bubbles. - return (system_tray_ && system_tray_->IsMouseInNotificationBubble()) || - (web_notification_tray_ && - web_notification_tray_->IsMouseInNotificationBubble()); -} - -bool StatusAreaWidget::IsMessageBubbleShown() const { - return ((system_tray_ && system_tray_->IsAnyBubbleVisible()) || - (web_notification_tray_ && - web_notification_tray_->IsMessageCenterBubbleVisible())); -} - -void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { - Widget::OnNativeWidgetActivationChanged(active); - if (active) - status_area_widget_delegate_->SetPaneFocusAndFocusDefault(); -} - -void StatusAreaWidget::AddSystemTray() { - system_tray_ = new SystemTray(this); - status_area_widget_delegate_->AddTray(system_tray_); -} - -void StatusAreaWidget::AddWebNotificationTray() { - web_notification_tray_ = new WebNotificationTray(this); - status_area_widget_delegate_->AddTray(web_notification_tray_); -} - -void StatusAreaWidget::AddLogoutButtonTray() { - logout_button_tray_ = new LogoutButtonTray(this); - status_area_widget_delegate_->AddTray(logout_button_tray_); -} - -void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { - status_area_widget_delegate_->set_alignment(alignment); - if (system_tray_) - system_tray_->SetShelfAlignment(alignment); - if (web_notification_tray_) - web_notification_tray_->SetShelfAlignment(alignment); - if (logout_button_tray_) - logout_button_tray_->SetShelfAlignment(alignment); - status_area_widget_delegate_->UpdateLayout(); -} - -void StatusAreaWidget::SetHideSystemNotifications(bool hide) { - if (system_tray_) - system_tray_->SetHideNotifications(hide); -} - -void StatusAreaWidget::UpdateAfterLoginStatusChange( - user::LoginStatus login_status) { - if (login_status_ == login_status) - return; - login_status_ = login_status; - if (system_tray_) - system_tray_->UpdateAfterLoginStatusChange(login_status); - if (web_notification_tray_) - web_notification_tray_->UpdateAfterLoginStatusChange(login_status); - if (logout_button_tray_) - logout_button_tray_->UpdateAfterLoginStatusChange(login_status); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/status_area_widget.h b/chromium/ash/system/status_area_widget.h deleted file mode 100644 index 731eed1c130..00000000000 --- a/chromium/ash/system/status_area_widget.h +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_STATUS_AREA_WIDGET_H_ -#define ASH_SYSTEM_STATUS_AREA_WIDGET_H_ - -#include "ash/ash_export.h" -#include "ash/shelf/shelf_types.h" -#include "ash/system/user/login_status.h" -#include "ui/views/widget/widget.h" - -namespace ash { - -class ShellDelegate; -class SystemTray; -class WebNotificationTray; - -namespace internal { - -class LogoutButtonTray; -class StatusAreaWidgetDelegate; - -class ASH_EXPORT StatusAreaWidget : public views::Widget { - public: - static const char kNativeViewName[]; - - explicit StatusAreaWidget(aura::Window* status_container); - virtual ~StatusAreaWidget(); - - // Creates the SystemTray, WebNotificationTray and LogoutButtonTray. - void CreateTrayViews(); - - // Destroys the system tray and web notification tray. Called before - // tearing down the windows to avoid shutdown ordering issues. - void Shutdown(); - - // Update the alignment of the widget and tray views. - void SetShelfAlignment(ShelfAlignment alignment); - - // Set the visibility of system notifications. - void SetHideSystemNotifications(bool hide); - - // Called by the client when the login status changes. Caches login_status - // and calls UpdateAfterLoginStatusChange for the system tray and the web - // notification tray. - void UpdateAfterLoginStatusChange(user::LoginStatus login_status); - - internal::StatusAreaWidgetDelegate* status_area_widget_delegate() { - return status_area_widget_delegate_; - } - SystemTray* system_tray() { return system_tray_; } - WebNotificationTray* web_notification_tray() { - return web_notification_tray_; - } - - user::LoginStatus login_status() const { return login_status_; } - - // Returns true if the launcher should be visible. This is used when the - // launcher is configured to auto-hide and test if the shelf should force - // the launcher to remain visible. - bool ShouldShowLauncher() const; - - // True if any message bubble is shown. - bool IsMessageBubbleShown() const; - - // Overridden from views::Widget: - virtual void OnNativeWidgetActivationChanged(bool active) OVERRIDE; - - private: - void AddSystemTray(); - void AddWebNotificationTray(); - void AddLogoutButtonTray(); - - // Weak pointers to View classes that are parented to StatusAreaWidget: - internal::StatusAreaWidgetDelegate* status_area_widget_delegate_; - SystemTray* system_tray_; - WebNotificationTray* web_notification_tray_; - LogoutButtonTray* logout_button_tray_; - user::LoginStatus login_status_; - - DISALLOW_COPY_AND_ASSIGN(StatusAreaWidget); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_STATUS_AREA_WIDGET_H_ diff --git a/chromium/ash/system/status_area_widget_delegate.cc b/chromium/ash/system/status_area_widget_delegate.cc deleted file mode 100644 index c1c62f39084..00000000000 --- a/chromium/ash/system/status_area_widget_delegate.cc +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/status_area_widget_delegate.h" - -#include "ash/ash_export.h" -#include "ash/ash_switches.h" -#include "ash/focus_cycler.h" -#include "ash/shell.h" -#include "ash/shell_window_ids.h" -#include "ash/system/tray/tray_constants.h" -#include "base/strings/utf_string_conversions.h" -#include "ui/aura/root_window.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/image/image.h" -#include "ui/views/accessible_pane_view.h" -#include "ui/views/layout/grid_layout.h" -#include "ui/views/widget/widget.h" - -namespace ash { -namespace internal { -namespace { - -const int kStatusTrayOffsetFromScreenEdge = 4; - -} - -StatusAreaWidgetDelegate::StatusAreaWidgetDelegate() - : focus_cycler_for_testing_(NULL), - alignment_(SHELF_ALIGNMENT_BOTTOM) { - // Allow the launcher to surrender the focus to another window upon - // navigation completion by the user. - set_allow_deactivate_on_esc(true); -} - -StatusAreaWidgetDelegate::~StatusAreaWidgetDelegate() { -} - -void StatusAreaWidgetDelegate::SetFocusCyclerForTesting( - const FocusCycler* focus_cycler) { - focus_cycler_for_testing_ = focus_cycler; -} - -views::View* StatusAreaWidgetDelegate::GetDefaultFocusableChild() { - return child_at(0); -} - -views::Widget* StatusAreaWidgetDelegate::GetWidget() { - return View::GetWidget(); -} - -const views::Widget* StatusAreaWidgetDelegate::GetWidget() const { - return View::GetWidget(); -} - -void StatusAreaWidgetDelegate::OnGestureEvent(ui::GestureEvent* event) { - if (gesture_handler_.ProcessGestureEvent(*event)) - event->StopPropagation(); - else - views::AccessiblePaneView::OnGestureEvent(event); -} - -bool StatusAreaWidgetDelegate::CanActivate() const { - // We don't want mouse clicks to activate us, but we need to allow - // activation when the user is using the keyboard (FocusCycler). - const FocusCycler* focus_cycler = focus_cycler_for_testing_ ? - focus_cycler_for_testing_ : Shell::GetInstance()->focus_cycler(); - return focus_cycler->widget_activating() == GetWidget(); -} - -void StatusAreaWidgetDelegate::DeleteDelegate() { -} - -void StatusAreaWidgetDelegate::AddTray(views::View* tray) { - SetLayoutManager(NULL); // Reset layout manager before adding a child. - AddChildView(tray); - // Set the layout manager with the new list of children. - UpdateLayout(); -} - -void StatusAreaWidgetDelegate::UpdateLayout() { - // Use a grid layout so that the trays can be centered in each cell, and - // so that the widget gets laid out correctly when tray sizes change. - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); - - views::ColumnSet* columns = layout->AddColumnSet(0); - if (alignment_ == SHELF_ALIGNMENT_BOTTOM || - alignment_ == SHELF_ALIGNMENT_TOP) { - // Alternate shelf layout insets are all handled by tray_background_view. - if (!ash::switches::UseAlternateShelfLayout()) { - if (alignment_ == SHELF_ALIGNMENT_TOP) - layout->SetInsets(kStatusTrayOffsetFromScreenEdge, 0, 0, 0); - else - layout->SetInsets(0, 0, kStatusTrayOffsetFromScreenEdge, 0); - } - bool is_first_visible_child = true; - for (int c = 0; c < child_count(); ++c) { - views::View* child = child_at(c); - if (!child->visible()) - continue; - if (!is_first_visible_child) - columns->AddPaddingColumn(0, GetTraySpacing()); - is_first_visible_child = false; - columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, - 0, /* resize percent */ - views::GridLayout::USE_PREF, 0, 0); - } - layout->StartRow(0, 0); - for (int c = child_count() - 1; c >= 0; --c) { - views::View* child = child_at(c); - if (child->visible()) - layout->AddView(child); - } - } else { - if (!ash::switches::UseAlternateShelfLayout()) { - if (alignment_ == SHELF_ALIGNMENT_LEFT) - layout->SetInsets(0, kStatusTrayOffsetFromScreenEdge, 0, 0); - else - layout->SetInsets(0, 0, 0, kStatusTrayOffsetFromScreenEdge); - } - columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, - 0, /* resize percent */ - views::GridLayout::USE_PREF, 0, 0); - bool is_first_visible_child = true; - for (int c = child_count() - 1; c >= 0; --c) { - views::View* child = child_at(c); - if (!child->visible()) - continue; - if (!is_first_visible_child) - layout->AddPaddingRow(0, GetTraySpacing()); - is_first_visible_child = false; - layout->StartRow(0, 0); - layout->AddView(child); - } - } - Layout(); - UpdateWidgetSize(); -} - -void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { - // Need to resize the window when trays or items are added/removed. - UpdateWidgetSize(); -} - -void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { - UpdateLayout(); -} - -void StatusAreaWidgetDelegate::UpdateWidgetSize() { - if (GetWidget()) - GetWidget()->SetSize(GetPreferredSize()); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/status_area_widget_delegate.h b/chromium/ash/system/status_area_widget_delegate.h deleted file mode 100644 index 751c31beced..00000000000 --- a/chromium/ash/system/status_area_widget_delegate.h +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_STATUS_AREA_WIDGET_DELEGATE_H_ -#define ASH_SYSTEM_STATUS_AREA_WIDGET_DELEGATE_H_ - -#include "ash/ash_export.h" -#include "ash/shelf/shelf_types.h" -#include "ash/wm/gestures/shelf_gesture_handler.h" -#include "ui/gfx/image/image_skia.h" -#include "ui/views/accessible_pane_view.h" -#include "ui/views/widget/widget_delegate.h" - -namespace ash { -namespace internal { - -class FocusCycler; - -class ASH_EXPORT StatusAreaWidgetDelegate : public views::AccessiblePaneView, - public views::WidgetDelegate { - public: - StatusAreaWidgetDelegate(); - virtual ~StatusAreaWidgetDelegate(); - - // Add a tray view to the widget (e.g. system tray, web notifications). - void AddTray(views::View* tray); - - // Called whenever layout might change (e.g. alignment changed). - void UpdateLayout(); - - // Sets the focus cycler. - void SetFocusCyclerForTesting(const FocusCycler* focus_cycler); - - void set_alignment(ShelfAlignment alignment) { alignment_ = alignment; } - - // Overridden from views::AccessiblePaneView. - virtual View* GetDefaultFocusableChild() OVERRIDE; - - // Overridden from views::View: - virtual views::Widget* GetWidget() OVERRIDE; - virtual const views::Widget* GetWidget() const OVERRIDE; - - // Overridden from ui::EventHandler: - virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; - - // views::WidgetDelegate overrides: - virtual bool CanActivate() const OVERRIDE; - virtual void DeleteDelegate() OVERRIDE; - - protected: - // Overridden from views::View: - virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; - virtual void ChildVisibilityChanged(views::View* child) OVERRIDE; - - private: - void UpdateWidgetSize(); - - const FocusCycler* focus_cycler_for_testing_; - ShelfAlignment alignment_; - - ShelfGestureHandler gesture_handler_; - - DISALLOW_COPY_AND_ASSIGN(StatusAreaWidgetDelegate); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_STATUS_AREA_WIDGET_DELEGATE_H_ diff --git a/chromium/ash/system/system_notifier.cc b/chromium/ash/system/system_notifier.cc deleted file mode 100644 index e4d65d27338..00000000000 --- a/chromium/ash/system/system_notifier.cc +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/system_notifier.h" - -#include "base/logging.h" - -namespace ash { -namespace system_notifier { - -namespace { - -// See http://dev.chromium.org/chromium-os/chromiumos-design-docs/ -// system-notifications for the reasoning. -const char* kAlwaysShownNotifierIds[] = { - kNotifierDisplay, - kNotifierDisplayError, - kNotifierPower, - NULL -}; - -const char* kAshSystemNotifiers[] = { - kNotifierDisplay, - kNotifierDisplayResolutionChange, - kNotifierDisplayError, - kNotifierInputMethod, - kNotifierLocale, - kNotifierLocallyManagedUser, - kNotifierMultiProfileFirstRun, - kNotifierNetwork, - kNotifierNetworkError, - kNotifierScreenshot, - kNotifierScreenCapture, - kNotifierScreenShare, - kNotifierSessionLengthTimeout, - kNotifierPower, - NULL -}; - -bool MatchSystemNotifierId(const message_center::NotifierId& notifier_id, - const char* id_list[]) { - if (notifier_id.type != message_center::NotifierId::SYSTEM_COMPONENT) - return false; - - for (size_t i = 0; id_list[i] != NULL; ++i) { - if (notifier_id.id == id_list[i]) - return true; - } - return false; -} - -} // namespace - -const char kNotifierDisplay[] = "ash.display"; -const char kNotifierDisplayResolutionChange[] = "ash.display.resolution-change"; -const char kNotifierDisplayError[] = "ash.display.error"; -const char kNotifierInputMethod[] = "ash.input-method"; -const char kNotifierLocale[] = "ash.locale"; -const char kNotifierLocallyManagedUser[] = "ash.locally-managed-user"; -const char kNotifierMultiProfileFirstRun[] = "ash.multi-profile.first-run"; -const char kNotifierNetwork[] = "ash.network"; -const char kNotifierNetworkError[] = "ash.network.error"; -const char kNotifierScreenshot[] = "ash.screenshot"; -const char kNotifierScreenCapture[] = "ash.screen-capture"; -const char kNotifierScreenShare[] = "ash.screen-share"; -const char kNotifierSessionLengthTimeout[] = "ash.session-length-timeout"; -const char kNotifierPower[] = "ash.power"; - -bool ShouldAlwaysShowPopups(const message_center::NotifierId& notifier_id) { - return MatchSystemNotifierId(notifier_id, kAlwaysShownNotifierIds); -} - -bool IsAshSystemNotifier(const message_center::NotifierId& notifier_id) { - return MatchSystemNotifierId(notifier_id, kAshSystemNotifiers); -} - -} // namespace system_notifier -} // namespace ash diff --git a/chromium/ash/system/system_notifier.h b/chromium/ash/system/system_notifier.h deleted file mode 100644 index 53ac77db7d5..00000000000 --- a/chromium/ash/system/system_notifier.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_SYSTEM_NOTIFIER_H_ -#define ASH_SYSTEM_SYSTEM_NOTIFIER_H_ - -#include <string> - -#include "ash/ash_export.h" -#include "ui/message_center/notifier_settings.h" - -namespace ash { -namespace system_notifier { - -// The list of ash system notifier IDs. Alphabetical order. -ASH_EXPORT extern const char kNotifierDisplay[]; -ASH_EXPORT extern const char kNotifierDisplayResolutionChange[]; -ASH_EXPORT extern const char kNotifierDisplayError[]; -ASH_EXPORT extern const char kNotifierInputMethod[]; -ASH_EXPORT extern const char kNotifierLocale[]; -ASH_EXPORT extern const char kNotifierLocallyManagedUser[]; -ASH_EXPORT extern const char kNotifierMultiProfileFirstRun[]; -ASH_EXPORT extern const char kNotifierNetwork[]; -ASH_EXPORT extern const char kNotifierNetworkError[]; -ASH_EXPORT extern const char kNotifierScreenshot[]; -ASH_EXPORT extern const char kNotifierScreenCapture[]; -ASH_EXPORT extern const char kNotifierScreenShare[]; -ASH_EXPORT extern const char kNotifierSessionLengthTimeout[]; -ASH_EXPORT extern const char kNotifierPower[]; - -// Returns true if notifications from |notifier_id| should always appear as -// popups. "Always appear" means the popups should appear even in login screen, -// lock screen, or fullscreen state. -ASH_EXPORT bool ShouldAlwaysShowPopups( - const message_center::NotifierId& notifier_id); - -// Returns true if |notifier_id| is the system notifier from Ash. -ASH_EXPORT bool IsAshSystemNotifier( - const message_center::NotifierId& notifier_id); - -} // namespace system_notifier -} // namespace ash - -#endif // ASH_SYSTEM_SYSTEM_NOTIFIER_H_ diff --git a/chromium/ash/system/tray/actionable_view.cc b/chromium/ash/system/tray/actionable_view.cc deleted file mode 100644 index 261cefd30a1..00000000000 --- a/chromium/ash/system/tray/actionable_view.cc +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/actionable_view.h" - -#include "ash/ash_constants.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/gfx/canvas.h" - -namespace ash { -namespace internal { - -// static -const char ActionableView::kViewClassName[] = "tray/ActionableView"; - -ActionableView::ActionableView() - : has_capture_(false) { - SetFocusable(true); -} - -ActionableView::~ActionableView() { -} - -void ActionableView::OnPaintFocus(gfx::Canvas* canvas) { - gfx::Rect rect(GetFocusBounds()); - rect.Inset(1, 1, 3, 2); - canvas->DrawSolidFocusRect(rect, kFocusBorderColor); -} - -gfx::Rect ActionableView::GetFocusBounds() { - return GetLocalBounds(); -} - -const char* ActionableView::GetClassName() const { - return kViewClassName; -} - -bool ActionableView::OnKeyPressed(const ui::KeyEvent& event) { - if (event.key_code() == ui::VKEY_SPACE || - event.key_code() == ui::VKEY_RETURN) { - return PerformAction(event); - } - return false; -} - -bool ActionableView::OnMousePressed(const ui::MouseEvent& event) { - // Return true so that this view starts capturing the events. - has_capture_ = true; - return true; -} - -void ActionableView::OnMouseReleased(const ui::MouseEvent& event) { - if (has_capture_ && GetLocalBounds().Contains(event.location())) - PerformAction(event); -} - -void ActionableView::OnMouseCaptureLost() { - has_capture_ = false; -} - -void ActionableView::SetAccessibleName(const base::string16& name) { - accessible_name_ = name; -} - -void ActionableView::GetAccessibleState(ui::AccessibleViewState* state) { - state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; - state->name = accessible_name_; -} - -void ActionableView::OnPaint(gfx::Canvas* canvas) { - View::OnPaint(canvas); - if (HasFocus()) - OnPaintFocus(canvas); -} - -void ActionableView::OnFocus() { - View::OnFocus(); - // We render differently when focused. - SchedulePaint(); -} - -void ActionableView::OnBlur() { - View::OnBlur(); - // We render differently when focused. - SchedulePaint(); -} - -void ActionableView::OnGestureEvent(ui::GestureEvent* event) { - if (event->type() == ui::ET_GESTURE_TAP && PerformAction(*event)) - event->SetHandled(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/actionable_view.h b/chromium/ash/system/tray/actionable_view.h deleted file mode 100644 index f2b3ec1deba..00000000000 --- a/chromium/ash/system/tray/actionable_view.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_ACTIONABLE_VIEW_H_ -#define ASH_SYSTEM_TRAY_ACTIONABLE_VIEW_H_ - -#include "ash/ash_export.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/views/view.h" - -namespace ash { -namespace internal { - -// A focusable view that performs an action when user clicks on it, or presses -// enter or space when focused. Note that the action is triggered on mouse-up, -// instead of on mouse-down. So if user presses the mouse on the view, then -// moves the mouse out of the view and then releases, then the action will not -// be performed. -// Exported for SystemTray. -class ASH_EXPORT ActionableView : public views::View { - public: - static const char kViewClassName[]; - - ActionableView(); - - virtual ~ActionableView(); - - void SetAccessibleName(const base::string16& name); - const base::string16& accessible_name() const { return accessible_name_; } - - protected: - void OnPaintFocus(gfx::Canvas* canvas); - - // Returns the bounds to paint the focus rectangle in. - virtual gfx::Rect GetFocusBounds(); - - // Performs an action when user clicks on the view (on mouse-press event), or - // presses a key when this view is in focus. Returns true if the event has - // been handled and an action was performed. Returns false otherwise. - virtual bool PerformAction(const ui::Event& event) = 0; - - // Overridden from views::View. - virtual const char* GetClassName() const OVERRIDE; - virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; - virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; - virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; - virtual void OnMouseCaptureLost() OVERRIDE; - virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; - virtual void OnFocus() OVERRIDE; - virtual void OnBlur() OVERRIDE; - - // Overridden from ui::EventHandler. - virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; - - private: - base::string16 accessible_name_; - bool has_capture_; - - DISALLOW_COPY_AND_ASSIGN(ActionableView); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_ACTIONABLE_VIEW_H_ diff --git a/chromium/ash/system/tray/default_system_tray_delegate.cc b/chromium/ash/system/tray/default_system_tray_delegate.cc deleted file mode 100644 index 37836f0277f..00000000000 --- a/chromium/ash/system/tray/default_system_tray_delegate.cc +++ /dev/null @@ -1,279 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/default_system_tray_delegate.h" - -#include <string> - -#include "ash/session_state_delegate.h" -#include "ash/shell.h" -#include "ash/volume_control_delegate.h" -#include "base/message_loop/message_loop.h" -#include "base/time/time.h" - -namespace ash { - -namespace { - -class DefaultVolumnControlDelegate : public VolumeControlDelegate { - public: - DefaultVolumnControlDelegate() {} - virtual ~DefaultVolumnControlDelegate() {} - - virtual bool HandleVolumeMute(const ui::Accelerator& accelerator) OVERRIDE { - return true; - } - virtual bool HandleVolumeDown(const ui::Accelerator& accelerator) OVERRIDE { - return true; - } - virtual bool HandleVolumeUp(const ui::Accelerator& accelerator) OVERRIDE { - return true; - } - - private: - DISALLOW_COPY_AND_ASSIGN(DefaultVolumnControlDelegate); -}; - -} // namespace - -DefaultSystemTrayDelegate::DefaultSystemTrayDelegate() - : bluetooth_enabled_(true), - volume_control_delegate_(new DefaultVolumnControlDelegate) { -} - -DefaultSystemTrayDelegate::~DefaultSystemTrayDelegate() { -} - -void DefaultSystemTrayDelegate::Initialize() { -} - -void DefaultSystemTrayDelegate::Shutdown() { -} - -bool DefaultSystemTrayDelegate::GetTrayVisibilityOnStartup() { - return true; -} - -user::LoginStatus DefaultSystemTrayDelegate::GetUserLoginStatus() const { - return user::LOGGED_IN_USER; -} - -bool DefaultSystemTrayDelegate::IsOobeCompleted() const { - return true; -} - -void DefaultSystemTrayDelegate::ChangeProfilePicture() { -} - -const std::string DefaultSystemTrayDelegate::GetEnterpriseDomain() const { - return std::string(); -} - -const base::string16 DefaultSystemTrayDelegate::GetEnterpriseMessage() const { - return string16(); -} - -const std::string -DefaultSystemTrayDelegate::GetLocallyManagedUserManager() const { - return std::string(); -} - -const base::string16 -DefaultSystemTrayDelegate::GetLocallyManagedUserManagerName() - const { - return string16(); -} - -const base::string16 DefaultSystemTrayDelegate::GetLocallyManagedUserMessage() - const { - return string16(); -} - -bool DefaultSystemTrayDelegate::SystemShouldUpgrade() const { - return true; -} - -base::HourClockType DefaultSystemTrayDelegate::GetHourClockType() const { - return base::k24HourClock; -} - -void DefaultSystemTrayDelegate::ShowSettings() { -} - -bool DefaultSystemTrayDelegate::ShouldShowSettings() { - return true; -} - -void DefaultSystemTrayDelegate::ShowDateSettings() { -} - -void DefaultSystemTrayDelegate::ShowNetworkSettings( - const std::string& service_path) { -} - -void DefaultSystemTrayDelegate::ShowBluetoothSettings() { -} - -void DefaultSystemTrayDelegate::ShowDisplaySettings() { -} - -void DefaultSystemTrayDelegate::ShowChromeSlow() { -} - -bool DefaultSystemTrayDelegate::ShouldShowDisplayNotification() { - return false; -} - -void DefaultSystemTrayDelegate::ShowDriveSettings() { -} - -void DefaultSystemTrayDelegate::ShowIMESettings() { -} - -void DefaultSystemTrayDelegate::ShowHelp() { -} - -void DefaultSystemTrayDelegate::ShowAccessibilityHelp() { -} - -void DefaultSystemTrayDelegate::ShowAccessibilitySettings() { -} - -void DefaultSystemTrayDelegate::ShowPublicAccountInfo() { -} - -void DefaultSystemTrayDelegate::ShowEnterpriseInfo() { -} - -void DefaultSystemTrayDelegate::ShowLocallyManagedUserInfo() { -} - -void DefaultSystemTrayDelegate::ShowUserLogin() { -} - -void DefaultSystemTrayDelegate::ShowSpringChargerReplacementDialog() { -} - -bool DefaultSystemTrayDelegate::HasUserConfirmedSafeSpringCharger() { - return false; -} - -void DefaultSystemTrayDelegate::ShutDown() { -} - -void DefaultSystemTrayDelegate::SignOut() { -} - -void DefaultSystemTrayDelegate::RequestLockScreen() { -} - -void DefaultSystemTrayDelegate::RequestRestartForUpdate() { -} - -void DefaultSystemTrayDelegate::GetAvailableBluetoothDevices( - BluetoothDeviceList* list) { -} - -void DefaultSystemTrayDelegate::BluetoothStartDiscovering() { -} - -void DefaultSystemTrayDelegate::BluetoothStopDiscovering() { -} - -void DefaultSystemTrayDelegate::ConnectToBluetoothDevice( - const std::string& address) { -} - -void DefaultSystemTrayDelegate::GetCurrentIME(IMEInfo* info) { -} - -void DefaultSystemTrayDelegate::GetAvailableIMEList(IMEInfoList* list) { -} - -void DefaultSystemTrayDelegate::GetCurrentIMEProperties( - IMEPropertyInfoList* list) { -} - -void DefaultSystemTrayDelegate::SwitchIME(const std::string& ime_id) { -} - -void DefaultSystemTrayDelegate::ActivateIMEProperty(const std::string& key) { -} - -void DefaultSystemTrayDelegate::CancelDriveOperation(int32 operation_id) { -} - -void DefaultSystemTrayDelegate::GetDriveOperationStatusList( - ash::DriveOperationStatusList*) { -} - -void DefaultSystemTrayDelegate::ShowNetworkConfigure( - const std::string& network_id, - gfx::NativeWindow parent_window) { -} - -bool DefaultSystemTrayDelegate::EnrollNetwork(const std::string& network_id, - gfx::NativeWindow parent_window) { - return true; -} - -void DefaultSystemTrayDelegate::ManageBluetoothDevices() { -} - -void DefaultSystemTrayDelegate::ToggleBluetooth() { - bluetooth_enabled_ = !bluetooth_enabled_; -} - -bool DefaultSystemTrayDelegate::IsBluetoothDiscovering() { - return false; -} - -void DefaultSystemTrayDelegate::ShowMobileSimDialog() { -} - -void DefaultSystemTrayDelegate::ShowMobileSetupDialog( - const std::string& service_path) { -} - -void DefaultSystemTrayDelegate::ShowOtherNetworkDialog( - const std::string& type) { -} - -bool DefaultSystemTrayDelegate::GetBluetoothAvailable() { - return true; -} - -bool DefaultSystemTrayDelegate::GetBluetoothEnabled() { - return bluetooth_enabled_; -} - -void DefaultSystemTrayDelegate::ChangeProxySettings() { -} - -VolumeControlDelegate* DefaultSystemTrayDelegate::GetVolumeControlDelegate() - const { - return volume_control_delegate_.get(); -} - -void DefaultSystemTrayDelegate::SetVolumeControlDelegate( - scoped_ptr<VolumeControlDelegate> delegate) { - volume_control_delegate_ = delegate.Pass(); -} - -bool DefaultSystemTrayDelegate::GetSessionStartTime( - base::TimeTicks* session_start_time) { - return false; -} - -bool DefaultSystemTrayDelegate::GetSessionLengthLimit( - base::TimeDelta* session_length_limit) { - return false; -} - -int DefaultSystemTrayDelegate::GetSystemTrayMenuWidth() { - // This is the default width for English languages. - return 300; -} - -} // namespace ash diff --git a/chromium/ash/system/tray/default_system_tray_delegate.h b/chromium/ash/system/tray/default_system_tray_delegate.h deleted file mode 100644 index f85b6ca2cd4..00000000000 --- a/chromium/ash/system/tray/default_system_tray_delegate.h +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_DEFAULT_SYSTEM_TRAY_DELEGATE_H_ -#define ASH_SYSTEM_TRAY_DEFAULT_SYSTEM_TRAY_DELEGATE_H_ - -#include "ash/ash_export.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" - -namespace ash { - -class ASH_EXPORT DefaultSystemTrayDelegate : public SystemTrayDelegate { - public: - DefaultSystemTrayDelegate(); - virtual ~DefaultSystemTrayDelegate(); - - // Overridden from SystemTrayDelegate: - virtual void Initialize() OVERRIDE; - virtual void Shutdown() OVERRIDE; - virtual bool GetTrayVisibilityOnStartup() OVERRIDE; - virtual user::LoginStatus GetUserLoginStatus() const OVERRIDE; - virtual bool IsOobeCompleted() const OVERRIDE; - virtual void ChangeProfilePicture() OVERRIDE; - virtual const std::string GetEnterpriseDomain() const OVERRIDE; - virtual const base::string16 GetEnterpriseMessage() const OVERRIDE; - virtual const std::string GetLocallyManagedUserManager() const OVERRIDE; - virtual const base::string16 GetLocallyManagedUserManagerName() const - OVERRIDE; - virtual const base::string16 GetLocallyManagedUserMessage() const OVERRIDE; - virtual bool SystemShouldUpgrade() const OVERRIDE; - virtual base::HourClockType GetHourClockType() const OVERRIDE; - virtual void ShowSettings() OVERRIDE; - virtual bool ShouldShowSettings() OVERRIDE; - virtual void ShowDateSettings() OVERRIDE; - virtual void ShowNetworkSettings(const std::string& service_path) OVERRIDE; - virtual void ShowBluetoothSettings() OVERRIDE; - virtual void ShowDisplaySettings() OVERRIDE; - virtual void ShowChromeSlow() OVERRIDE; - virtual bool ShouldShowDisplayNotification() OVERRIDE; - virtual void ShowDriveSettings() OVERRIDE; - virtual void ShowIMESettings() OVERRIDE; - virtual void ShowHelp() OVERRIDE; - virtual void ShowAccessibilityHelp() OVERRIDE; - virtual void ShowAccessibilitySettings() OVERRIDE; - virtual void ShowPublicAccountInfo() OVERRIDE; - virtual void ShowEnterpriseInfo() OVERRIDE; - virtual void ShowLocallyManagedUserInfo() OVERRIDE; - virtual void ShowUserLogin() OVERRIDE; - virtual void ShowSpringChargerReplacementDialog() OVERRIDE; - virtual bool HasUserConfirmedSafeSpringCharger() OVERRIDE; - virtual void ShutDown() OVERRIDE; - virtual void SignOut() OVERRIDE; - virtual void RequestLockScreen() OVERRIDE; - virtual void RequestRestartForUpdate() OVERRIDE; - virtual void GetAvailableBluetoothDevices(BluetoothDeviceList* list) OVERRIDE; - virtual void BluetoothStartDiscovering() OVERRIDE; - virtual void BluetoothStopDiscovering() OVERRIDE; - virtual void ConnectToBluetoothDevice(const std::string& address) OVERRIDE; - virtual void GetCurrentIME(IMEInfo* info) OVERRIDE; - virtual void GetAvailableIMEList(IMEInfoList* list) OVERRIDE; - virtual void GetCurrentIMEProperties(IMEPropertyInfoList* list) OVERRIDE; - virtual void SwitchIME(const std::string& ime_id) OVERRIDE; - virtual void ActivateIMEProperty(const std::string& key) OVERRIDE; - virtual void CancelDriveOperation(int32 operation_id) OVERRIDE; - virtual void GetDriveOperationStatusList( - ash::DriveOperationStatusList*) OVERRIDE; - virtual void ShowNetworkConfigure(const std::string& network_id, - gfx::NativeWindow parent_window) OVERRIDE; - virtual bool EnrollNetwork(const std::string& network_id, - gfx::NativeWindow parent_window) OVERRIDE; - virtual void ManageBluetoothDevices() OVERRIDE; - virtual void ToggleBluetooth() OVERRIDE; - virtual bool IsBluetoothDiscovering() OVERRIDE; - virtual void ShowMobileSimDialog() OVERRIDE; - virtual void ShowMobileSetupDialog(const std::string& service_path) OVERRIDE; - virtual void ShowOtherNetworkDialog(const std::string& type) OVERRIDE; - virtual bool GetBluetoothAvailable() OVERRIDE; - virtual bool GetBluetoothEnabled() OVERRIDE; - virtual void ChangeProxySettings() OVERRIDE; - virtual VolumeControlDelegate* GetVolumeControlDelegate() const OVERRIDE; - virtual void SetVolumeControlDelegate( - scoped_ptr<VolumeControlDelegate> delegate) OVERRIDE; - virtual bool GetSessionStartTime( - base::TimeTicks* session_start_time) OVERRIDE; - virtual bool GetSessionLengthLimit( - base::TimeDelta* session_length_limit) OVERRIDE; - virtual int GetSystemTrayMenuWidth() OVERRIDE; - - private: - bool bluetooth_enabled_; - scoped_ptr<VolumeControlDelegate> volume_control_delegate_; - - DISALLOW_COPY_AND_ASSIGN(DefaultSystemTrayDelegate); -}; - -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_DEFAULT_SYSTEM_TRAY_DELEGATE_H_ diff --git a/chromium/ash/system/tray/fixed_sized_image_view.cc b/chromium/ash/system/tray/fixed_sized_image_view.cc deleted file mode 100644 index d0d49b92f21..00000000000 --- a/chromium/ash/system/tray/fixed_sized_image_view.cc +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/fixed_sized_image_view.h" - -namespace ash { -namespace internal { - -FixedSizedImageView::FixedSizedImageView(int width, int height) - : width_(width), - height_(height) { - SetHorizontalAlignment(views::ImageView::CENTER); - SetVerticalAlignment(views::ImageView::CENTER); -} - -FixedSizedImageView::~FixedSizedImageView() { -} - -gfx::Size FixedSizedImageView::GetPreferredSize() { - gfx::Size size = views::ImageView::GetPreferredSize(); - return gfx::Size(width_ ? width_ : size.width(), - height_ ? height_ : size.height()); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/fixed_sized_image_view.h b/chromium/ash/system/tray/fixed_sized_image_view.h deleted file mode 100644 index 1e5c7cda785..00000000000 --- a/chromium/ash/system/tray/fixed_sized_image_view.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_FIXED_SIZED_IMAGE_VIEW_H_ -#define ASH_SYSTEM_TRAY_FIXED_SIZED_IMAGE_VIEW_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/views/controls/image_view.h" - -namespace ash { -namespace internal { - -// An image view with a specified width and height (kTrayPopupDetailsIconWidth). -// If the specified width or height is zero, then the image size is used for -// that dimension. -class FixedSizedImageView : public views::ImageView { - public: - FixedSizedImageView(int width, int height); - virtual ~FixedSizedImageView(); - - private: - virtual gfx::Size GetPreferredSize() OVERRIDE; - - int width_; - int height_; - - DISALLOW_COPY_AND_ASSIGN(FixedSizedImageView); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_FIXED_SIZED_IMAGE_VIEW_H_ diff --git a/chromium/ash/system/tray/fixed_sized_scroll_view.cc b/chromium/ash/system/tray/fixed_sized_scroll_view.cc deleted file mode 100644 index d3fff9ad1ae..00000000000 --- a/chromium/ash/system/tray/fixed_sized_scroll_view.cc +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/fixed_sized_scroll_view.h" - -namespace ash { -namespace internal { - -FixedSizedScrollView::FixedSizedScrollView() { - set_notify_enter_exit_on_child(true); -} - -FixedSizedScrollView::~FixedSizedScrollView() { -} - -void FixedSizedScrollView::SetContentsView(views::View* view) { - SetContents(view); - view->SetBoundsRect(gfx::Rect(view->GetPreferredSize())); -} - -void FixedSizedScrollView::SetFixedSize(const gfx::Size& size) { - if (fixed_size_ == size) - return; - fixed_size_ = size; - PreferredSizeChanged(); -} - -gfx::Size FixedSizedScrollView::GetPreferredSize() { - gfx::Size size = fixed_size_.IsEmpty() ? - contents()->GetPreferredSize() : fixed_size_; - gfx::Insets insets = GetInsets(); - size.Enlarge(insets.width(), insets.height()); - return size; -} - -void FixedSizedScrollView::Layout() { - gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); - bounds.set_width(std::max(0, width() - GetScrollBarWidth())); - contents()->SetBoundsRect(bounds); - - views::ScrollView::Layout(); - if (!vertical_scroll_bar()->visible()) { - gfx::Rect bounds = contents()->bounds(); - bounds.set_width(bounds.width() + GetScrollBarWidth()); - contents()->SetBoundsRect(bounds); - } -} - -void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect& previous_bounds) { - gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); - bounds.set_width(std::max(0, width() - GetScrollBarWidth())); - contents()->SetBoundsRect(bounds); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/fixed_sized_scroll_view.h b/chromium/ash/system/tray/fixed_sized_scroll_view.h deleted file mode 100644 index aff53c217a6..00000000000 --- a/chromium/ash/system/tray/fixed_sized_scroll_view.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_FIXED_SIZED_SCROLL_VIEW_H_ -#define ASH_SYSTEM_TRAY_FIXED_SIZED_SCROLL_VIEW_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/views/controls/scroll_view.h" - -namespace ash { -namespace internal { - -// A custom scroll-view that has a specified dimension. -class FixedSizedScrollView : public views::ScrollView { - public: - FixedSizedScrollView(); - virtual ~FixedSizedScrollView(); - - void SetContentsView(views::View* view); - - // Change the fixed size of the view. Invalidates the layout (by calling - // PreferredSizeChanged()). - void SetFixedSize(const gfx::Size& size); - - void set_fixed_size(const gfx::Size& size) { fixed_size_ = size; } - - // Overridden from views::View: - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual void Layout() OVERRIDE; - - protected: - // Overridden from views::View: - virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; - - private: - gfx::Size fixed_size_; - - DISALLOW_COPY_AND_ASSIGN(FixedSizedScrollView); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_FIXED_SIZED_SCROLL_VIEW_H_ diff --git a/chromium/ash/system/tray/hover_highlight_view.cc b/chromium/ash/system/tray/hover_highlight_view.cc deleted file mode 100644 index 8afa2de4003..00000000000 --- a/chromium/ash/system/tray/hover_highlight_view.cc +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/hover_highlight_view.h" - -#include "ash/system/tray/fixed_sized_image_view.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/view_click_listener.h" -#include "grit/ui_resources.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/views/border.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/fill_layout.h" - -namespace { - -const int kCheckLabelPadding = 4; - -} // namespace - -namespace ash { -namespace internal { - -HoverHighlightView::HoverHighlightView(ViewClickListener* listener) - : listener_(listener), - text_label_(NULL), - highlight_color_(kHoverBackgroundColor), - default_color_(0), - text_highlight_color_(0), - text_default_color_(0), - hover_(false), - expandable_(false), - checkable_(false), - checked_(false) { - set_notify_enter_exit_on_child(true); -} - -HoverHighlightView::~HoverHighlightView() { -} - -void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, - const base::string16& text, - gfx::Font::FontStyle style) { - SetLayoutManager(new views::BoxLayout( - views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems)); - views::ImageView* image_view = - new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); - image_view->SetImage(image); - AddChildView(image_view); - - text_label_ = new views::Label(text); - text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - text_label_->SetFont(text_label_->font().DeriveFont(0, style)); - if (text_default_color_) - text_label_->SetEnabledColor(text_default_color_); - AddChildView(text_label_); - - SetAccessibleName(text); -} - -views::Label* HoverHighlightView::AddLabel(const base::string16& text, - gfx::Font::FontStyle style) { - SetLayoutManager(new views::FillLayout()); - text_label_ = new views::Label(text); - int margin = kTrayPopupPaddingHorizontal + - kTrayPopupDetailsLabelExtraLeftMargin; - int left_margin = 0; - int right_margin = 0; - if (base::i18n::IsRTL()) - right_margin = margin; - else - left_margin = margin; - text_label_->set_border( - views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin)); - text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - text_label_->SetFont(text_label_->font().DeriveFont(0, style)); - // Do not set alpha value in disable color. It will have issue with elide - // blending filter in disabled state for rendering label text color. - text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127)); - if (text_default_color_) - text_label_->SetEnabledColor(text_default_color_); - AddChildView(text_label_); - - SetAccessibleName(text); - return text_label_; -} - -views::Label* HoverHighlightView::AddCheckableLabel(const base::string16& text, - gfx::Font::FontStyle style, - bool checked) { - checkable_ = true; - checked_ = checked; - if (checked) { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - const gfx::ImageSkia* check = - rb.GetImageNamed(IDR_MENU_CHECK).ToImageSkia(); - int margin = kTrayPopupPaddingHorizontal + - kTrayPopupDetailsLabelExtraLeftMargin - kCheckLabelPadding; - SetLayoutManager(new views::BoxLayout( - views::BoxLayout::kHorizontal, 0, 3, kCheckLabelPadding)); - views::ImageView* image_view = new FixedSizedImageView(margin, 0); - image_view->SetImage(check); - image_view->SetHorizontalAlignment(views::ImageView::TRAILING); - AddChildView(image_view); - - text_label_ = new views::Label(text); - text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - text_label_->SetFont(text_label_->font().DeriveFont(0, style)); - text_label_->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0)); - if (text_default_color_) - text_label_->SetEnabledColor(text_default_color_); - AddChildView(text_label_); - - SetAccessibleName(text); - return text_label_; - } - return AddLabel(text, style); -} - -void HoverHighlightView::SetExpandable(bool expandable) { - if (expandable != expandable_) { - expandable_ = expandable; - InvalidateLayout(); - } -} - -bool HoverHighlightView::PerformAction(const ui::Event& event) { - if (!listener_) - return false; - listener_->OnViewClicked(this); - return true; -} - -void HoverHighlightView::GetAccessibleState(ui::AccessibleViewState* state) { - ActionableView::GetAccessibleState(state); - - if (checkable_) { - state->role = ui::AccessibilityTypes::ROLE_CHECKBUTTON; - state->state = checked_ ? ui::AccessibilityTypes::STATE_CHECKED : 0; - } -} - -gfx::Size HoverHighlightView::GetPreferredSize() { - gfx::Size size = ActionableView::GetPreferredSize(); - if (!expandable_ || size.height() < kTrayPopupItemHeight) - size.set_height(kTrayPopupItemHeight); - return size; -} - -int HoverHighlightView::GetHeightForWidth(int width) { - return GetPreferredSize().height(); -} - -void HoverHighlightView::OnMouseEntered(const ui::MouseEvent& event) { - hover_ = true; - if (text_highlight_color_ && text_label_) - text_label_->SetEnabledColor(text_highlight_color_); - SchedulePaint(); -} - -void HoverHighlightView::OnMouseExited(const ui::MouseEvent& event) { - hover_ = false; - if (text_default_color_ && text_label_) - text_label_->SetEnabledColor(text_default_color_); - SchedulePaint(); -} - -void HoverHighlightView::OnEnabledChanged() { - for (int i = 0; i < child_count(); ++i) - child_at(i)->SetEnabled(enabled()); -} - -void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { - canvas->DrawColor(hover_ ? highlight_color_ : default_color_); -} - -void HoverHighlightView::OnFocus() { - ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); - ActionableView::OnFocus(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/hover_highlight_view.h b/chromium/ash/system/tray/hover_highlight_view.h deleted file mode 100644 index e19c3ef77f1..00000000000 --- a/chromium/ash/system/tray/hover_highlight_view.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ -#define ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ - -#include "ash/system/tray/actionable_view.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/gfx/font.h" - -namespace views { -class Label; -} - -namespace ash { -namespace internal { - -class ViewClickListener; - -// A view that changes background color on hover, and triggers a callback in the -// associated ViewClickListener on click. The view can also be forced to -// maintain a fixed height. -class HoverHighlightView : public ActionableView { - public: - explicit HoverHighlightView(ViewClickListener* listener); - virtual ~HoverHighlightView(); - - // Convenience function for adding an icon and a label. This also sets the - // accessible name. - void AddIconAndLabel(const gfx::ImageSkia& image, - const base::string16& text, - gfx::Font::FontStyle style); - - // Convenience function for adding a label with padding on the left for a - // blank icon. This also sets the accessible name. - // Returns label after parenting it. - views::Label* AddLabel(const base::string16& text, - gfx::Font::FontStyle style); - - // Convenience function for adding an optional check and a label. In the - // absence of a check, padding is added to align with checked items. - // Returns label after parenting it. - views::Label* AddCheckableLabel(const base::string16& text, - gfx::Font::FontStyle style, - bool checked); - - // Allows view to expand its height. - // Size of unexapandable view is fixed and equals to kTrayPopupItemHeight. - void SetExpandable(bool expandable); - - void set_highlight_color(SkColor color) { highlight_color_ = color; } - void set_default_color(SkColor color) { default_color_ = color; } - void set_text_highlight_color(SkColor c) { text_highlight_color_ = c; } - void set_text_default_color(SkColor color) { text_default_color_ = color; } - - views::Label* text_label() { return text_label_; } - - bool hover() const { return hover_; } - - private: - // Overridden from ActionableView: - virtual bool PerformAction(const ui::Event& event) OVERRIDE; - - // Overridden from views::View. - virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual int GetHeightForWidth(int width) OVERRIDE; - virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; - virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; - virtual void OnEnabledChanged() OVERRIDE; - virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; - virtual void OnFocus() OVERRIDE; - - ViewClickListener* listener_; - views::Label* text_label_; - SkColor highlight_color_; - SkColor default_color_; - SkColor text_highlight_color_; - SkColor text_default_color_; - bool hover_; - bool expandable_; - bool checkable_; - bool checked_; - - DISALLOW_COPY_AND_ASSIGN(HoverHighlightView); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ diff --git a/chromium/ash/system/tray/special_popup_row.cc b/chromium/ash/system/tray/special_popup_row.cc deleted file mode 100644 index fd10f4721bd..00000000000 --- a/chromium/ash/system/tray/special_popup_row.cc +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/special_popup_row.h" - -#include "ash/system/tray/hover_highlight_view.h" -#include "ash/system/tray/throbber_view.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_popup_header_button.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/rect.h" -#include "ui/views/background.h" -#include "ui/views/border.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/painter.h" - -namespace ash { -namespace internal { - -namespace { - -const int kIconPaddingLeft = 5; -const int kSpecialPopupRowHeight = 55; -const int kBorderHeight = 1; -const SkColor kBorderColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); - -views::View* CreatePopupHeaderButtonsContainer() { - views::View* view = new views::View; - view->SetLayoutManager(new - views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, -1)); - view->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 5)); - return view; -} - -} // namespace - -SpecialPopupRow::SpecialPopupRow() - : content_(NULL), - button_container_(NULL) { - set_background(views::Background::CreateSolidBackground( - kHeaderBackgroundColor)); - set_border(views::Border::CreateSolidSidedBorder( - kBorderHeight, 0, 0, 0, kBorderColor)); - SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); -} - -SpecialPopupRow::~SpecialPopupRow() { -} - -void SpecialPopupRow::SetTextLabel(int string_id, ViewClickListener* listener) { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - HoverHighlightView* container = new HoverHighlightView(listener); - container->SetLayoutManager(new - views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); - - container->set_highlight_color(SkColorSetARGB(0, 0, 0, 0)); - container->set_default_color(SkColorSetARGB(0, 0, 0, 0)); - container->set_text_highlight_color(kHeaderTextColorHover); - container->set_text_default_color(kHeaderTextColorNormal); - - container->AddIconAndLabel( - *rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToImageSkia(), - rb.GetLocalizedString(string_id), - gfx::Font::BOLD); - - container->set_border(views::Border::CreateEmptyBorder(0, - kTrayPopupPaddingHorizontal, 0, 0)); - - container->SetAccessibleName( - rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU)); - SetContent(container); -} - -void SpecialPopupRow::SetContent(views::View* view) { - CHECK(!content_); - content_ = view; - AddChildViewAt(content_, 0); -} - -void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) { - if (!button_container_) { - button_container_ = CreatePopupHeaderButtonsContainer(); - AddChildView(button_container_); - } - button_container_->AddChildView(button); -} - -void SpecialPopupRow::AddThrobber(ThrobberView* throbber) { - if (!button_container_) { - button_container_ = CreatePopupHeaderButtonsContainer(); - AddChildView(button_container_); - } - button_container_->AddChildView(throbber); -} - -gfx::Size SpecialPopupRow::GetPreferredSize() { - gfx::Size size = views::View::GetPreferredSize(); - size.set_height(kSpecialPopupRowHeight); - return size; -} - -int SpecialPopupRow::GetHeightForWidth(int width) { - return kSpecialPopupRowHeight; -} - -void SpecialPopupRow::Layout() { - views::View::Layout(); - gfx::Rect content_bounds = GetContentsBounds(); - if (content_bounds.IsEmpty()) - return; - if (!button_container_) { - content_->SetBoundsRect(GetContentsBounds()); - return; - } - - gfx::Rect bounds(button_container_->GetPreferredSize()); - bounds.set_height(content_bounds.height()); - gfx::Rect container_bounds = content_bounds; - container_bounds.ClampToCenteredSize(bounds.size()); - container_bounds.set_x(content_bounds.width() - container_bounds.width()); - button_container_->SetBoundsRect(container_bounds); - - bounds = content_->bounds(); - bounds.set_width(button_container_->x()); - content_->SetBoundsRect(bounds); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/special_popup_row.h b/chromium/ash/system/tray/special_popup_row.h deleted file mode 100644 index ee068e4eb8a..00000000000 --- a/chromium/ash/system/tray/special_popup_row.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_SPECIAL_POPUP_ROW_H_ -#define ASH_SYSTEM_TRAY_SPECIAL_POPUP_ROW_H_ - -#include "ui/gfx/size.h" -#include "ui/views/view.h" - -namespace views { -class Label; -} - -namespace ash { -namespace internal { - -class ThrobberView; -class TrayItemView; -class TrayPopupHeaderButton; -class ViewClickListener; - -// The 'special' looking row in the uber-tray popups. This is usually the bottom -// row in the popups, and has a fixed height. -class SpecialPopupRow : public views::View { - public: - SpecialPopupRow(); - virtual ~SpecialPopupRow(); - - void SetTextLabel(int string_id, ViewClickListener* listener); - void SetContent(views::View* view); - - void AddButton(TrayPopupHeaderButton* button); - void AddThrobber(ThrobberView* throbber); - - views::View* content() const { return content_; } - - private: - // Overridden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual int GetHeightForWidth(int width) OVERRIDE; - virtual void Layout() OVERRIDE; - - views::View* content_; - views::View* button_container_; - views::Label* text_label_; - - DISALLOW_COPY_AND_ASSIGN(SpecialPopupRow); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_SPECIAL_POPUP_ROW_H_ diff --git a/chromium/ash/system/tray/system_tray.cc b/chromium/ash/system/tray/system_tray.cc deleted file mode 100644 index cee88472837..00000000000 --- a/chromium/ash/system/tray/system_tray.cc +++ /dev/null @@ -1,732 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/system_tray.h" - -#include "ash/ash_switches.h" -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/shelf/shelf_layout_manager.h" -#include "ash/shell.h" -#include "ash/shell/panel_window.h" -#include "ash/shell_window_ids.h" -#include "ash/system/bluetooth/tray_bluetooth.h" -#include "ash/system/date/tray_date.h" -#include "ash/system/drive/tray_drive.h" -#include "ash/system/ime/tray_ime.h" -#include "ash/system/monitor/tray_monitor.h" -#include "ash/system/session_length_limit/tray_session_length_limit.h" -#include "ash/system/status_area_widget.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_item.h" -#include "ash/system/tray/tray_bubble_wrapper.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray_accessibility.h" -#include "ash/system/tray_caps_lock.h" -#include "ash/system/tray_update.h" -#include "ash/system/user/login_status.h" -#include "ash/system/user/tray_user.h" -#include "ash/system/user/tray_user_separator.h" -#include "ash/system/web_notification/web_notification_tray.h" -#include "base/command_line.h" -#include "base/logging.h" -#include "base/strings/utf_string_conversions.h" -#include "base/timer/timer.h" -#include "grit/ash_strings.h" -#include "ui/aura/root_window.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/compositor/layer.h" -#include "ui/events/event_constants.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/screen.h" -#include "ui/gfx/skia_util.h" -#include "ui/views/border.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/view.h" - -#if defined(OS_CHROMEOS) -#include "ash/system/chromeos/audio/tray_audio.h" -#include "ash/system/chromeos/brightness/tray_brightness.h" -#include "ash/system/chromeos/enterprise/tray_enterprise.h" -#include "ash/system/chromeos/managed/tray_locally_managed_user.h" -#include "ash/system/chromeos/network/tray_network.h" -#include "ash/system/chromeos/network/tray_sms.h" -#include "ash/system/chromeos/network/tray_vpn.h" -#include "ash/system/chromeos/power/tray_power.h" -#include "ash/system/chromeos/screen_security/screen_capture_tray_item.h" -#include "ash/system/chromeos/screen_security/screen_share_tray_item.h" -#include "ash/system/chromeos/settings/tray_settings.h" -#include "ash/system/chromeos/tray_display.h" -#include "ash/system/chromeos/tray_tracing.h" -#include "ui/message_center/message_center.h" -#endif - -using views::TrayBubbleView; - -namespace ash { - -// The minimum width of the system tray menu width. -const int kMinimumSystemTrayMenuWidth = 300; - -namespace internal { - -// Class to initialize and manage the SystemTrayBubble and TrayBubbleWrapper -// instances for a bubble. - -class SystemBubbleWrapper { - public: - // Takes ownership of |bubble|. - explicit SystemBubbleWrapper(internal::SystemTrayBubble* bubble) - : bubble_(bubble), - is_persistent_(false) { - } - - // Initializes the bubble view and creates |bubble_wrapper_|. - void InitView(TrayBackgroundView* tray, - views::View* anchor, - TrayBubbleView::InitParams* init_params, - bool is_persistent) { - DCHECK(anchor); - user::LoginStatus login_status = - Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus(); - bubble_->InitView(anchor, login_status, init_params); - bubble_wrapper_.reset( - new internal::TrayBubbleWrapper(tray, bubble_->bubble_view())); - if (ash::switches::UseAlternateShelfLayout()) { - // The system bubble should not have an arrow. - bubble_->bubble_view()->SetArrowPaintType( - views::BubbleBorder::PAINT_NONE); - } - is_persistent_ = is_persistent; - - // If ChromeVox is enabled, focus the default item if no item is focused. - if (Shell::GetInstance()->accessibility_delegate()-> - IsSpokenFeedbackEnabled()) { - bubble_->FocusDefaultIfNeeded(); - } - } - - // Convenience accessors: - SystemTrayBubble* bubble() const { return bubble_.get(); } - SystemTrayBubble::BubbleType bubble_type() const { - return bubble_->bubble_type(); - } - TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } - bool is_persistent() const { return is_persistent_; } - - private: - scoped_ptr<internal::SystemTrayBubble> bubble_; - scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; - bool is_persistent_; - - DISALLOW_COPY_AND_ASSIGN(SystemBubbleWrapper); -}; - -} // namespace internal - -// SystemTray - -using internal::SystemTrayBubble; - -SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) - : internal::TrayBackgroundView(status_area_widget), - items_(), - default_bubble_height_(0), - hide_notifications_(false), - full_system_tray_menu_(false), - tray_accessibility_(NULL), - tray_date_(NULL) { - SetContentsBackground(); -} - -SystemTray::~SystemTray() { - // Destroy any child views that might have back pointers before ~View(). - system_bubble_.reset(); - notification_bubble_.reset(); - for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); - it != items_.end(); - ++it) { - (*it)->DestroyTrayView(); - } -} - -void SystemTray::InitializeTrayItems(SystemTrayDelegate* delegate) { - internal::TrayBackgroundView::Initialize(); - CreateItems(delegate); -} - -void SystemTray::CreateItems(SystemTrayDelegate* delegate) { -#if !defined(OS_WIN) - AddTrayItem(new internal::TraySessionLengthLimit(this)); - // Create user items for each possible user. - ash::Shell* shell = ash::Shell::GetInstance(); - int maximum_user_profiles = - shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers(); - for (int i = 0; i < maximum_user_profiles; i++) { - internal::TrayUser* tray_user = new internal::TrayUser(this, i); - AddTrayItem(tray_user); - user_items_.push_back(tray_user); - } - if (maximum_user_profiles > 1) { - // Add a special double line separator between users and the rest of the - // menu if more then one user is logged in. - AddTrayItem(new internal::TrayUserSeparator(this)); - } -#endif - - tray_accessibility_ = new internal::TrayAccessibility(this); - tray_date_ = new internal::TrayDate(this); - -#if defined(OS_CHROMEOS) - AddTrayItem(new internal::TrayEnterprise(this)); - AddTrayItem(new internal::TrayLocallyManagedUser(this)); - AddTrayItem(new internal::TrayIME(this)); - AddTrayItem(tray_accessibility_); - AddTrayItem(new internal::TrayTracing(this)); - AddTrayItem( - new internal::TrayPower(this, message_center::MessageCenter::Get())); - AddTrayItem(new internal::TrayNetwork(this)); - AddTrayItem(new internal::TrayVPN(this)); - AddTrayItem(new internal::TraySms(this)); - AddTrayItem(new internal::TrayBluetooth(this)); - AddTrayItem(new internal::TrayDrive(this)); - AddTrayItem(new internal::TrayDisplay(this)); - AddTrayItem(new internal::ScreenCaptureTrayItem(this)); - AddTrayItem(new internal::ScreenShareTrayItem(this)); - AddTrayItem(new internal::TrayAudio(this)); - AddTrayItem(new internal::TrayBrightness(this)); - AddTrayItem(new internal::TrayCapsLock(this)); - AddTrayItem(new internal::TraySettings(this)); - AddTrayItem(new internal::TrayUpdate(this)); - AddTrayItem(tray_date_); -#elif defined(OS_WIN) - AddTrayItem(tray_accessibility_); - AddTrayItem(new internal::TrayUpdate(this)); - AddTrayItem(tray_date_); -#elif defined(OS_LINUX) - AddTrayItem(new internal::TrayIME(this)); - AddTrayItem(tray_accessibility_); - AddTrayItem(new internal::TrayBluetooth(this)); - AddTrayItem(new internal::TrayDrive(this)); - AddTrayItem(new internal::TrayCapsLock(this)); - AddTrayItem(new internal::TrayUpdate(this)); - AddTrayItem(tray_date_); -#endif - -#if defined(OS_LINUX) - CommandLine* cmd = CommandLine::ForCurrentProcess(); - if (cmd->HasSwitch(ash::switches::kAshEnableMemoryMonitor)) - AddTrayItem(new internal::TrayMonitor(this)); -#endif - - SetVisible(ash::Shell::GetInstance()->system_tray_delegate()-> - GetTrayVisibilityOnStartup()); -} - -void SystemTray::AddTrayItem(SystemTrayItem* item) { - items_.push_back(item); - - SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); - views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); - item->UpdateAfterShelfAlignmentChange(shelf_alignment()); - - if (tray_item) { - tray_container()->AddChildViewAt(tray_item, 0); - PreferredSizeChanged(); - tray_item_map_[item] = tray_item; - } -} - -void SystemTray::RemoveTrayItem(SystemTrayItem* item) { - NOTIMPLEMENTED(); -} - -const std::vector<SystemTrayItem*>& SystemTray::GetTrayItems() const { - return items_.get(); -} - -const std::vector<internal::TrayUser*>& SystemTray::GetTrayUserItems() const { - return user_items_; -} - -void SystemTray::ShowDefaultView(BubbleCreationType creation_type) { - ShowDefaultViewWithOffset( - creation_type, - TrayBubbleView::InitParams::kArrowDefaultOffset, - false); -} - -void SystemTray::ShowPersistentDefaultView() { - ShowItems(items_.get(), - false, - false, - BUBBLE_CREATE_NEW, - TrayBubbleView::InitParams::kArrowDefaultOffset, - true); -} - -void SystemTray::ShowDetailedView(SystemTrayItem* item, - int close_delay, - bool activate, - BubbleCreationType creation_type) { - std::vector<SystemTrayItem*> items; - items.push_back(item); - ShowItems(items, true, activate, creation_type, GetTrayXOffset(item), false); - if (system_bubble_) - system_bubble_->bubble()->StartAutoCloseTimer(close_delay); -} - -void SystemTray::SetDetailedViewCloseDelay(int close_delay) { - if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DETAILED)) - system_bubble_->bubble()->StartAutoCloseTimer(close_delay); -} - -void SystemTray::HideDetailedView(SystemTrayItem* item) { - if (item != detailed_item_) - return; - DestroySystemBubble(); - UpdateNotificationBubble(); -} - -void SystemTray::ShowNotificationView(SystemTrayItem* item) { - if (std::find(notification_items_.begin(), notification_items_.end(), item) - != notification_items_.end()) - return; - notification_items_.push_back(item); - UpdateNotificationBubble(); -} - -void SystemTray::HideNotificationView(SystemTrayItem* item) { - std::vector<SystemTrayItem*>::iterator found_iter = - std::find(notification_items_.begin(), notification_items_.end(), item); - if (found_iter == notification_items_.end()) - return; - notification_items_.erase(found_iter); - // Only update the notification bubble if visible (i.e. don't create one). - if (notification_bubble_) - UpdateNotificationBubble(); -} - -void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) { - DestroySystemBubble(); - UpdateNotificationBubble(); - - for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); - it != items_.end(); - ++it) { - (*it)->UpdateAfterLoginStatusChange(login_status); - } - - // Items default to SHELF_ALIGNMENT_BOTTOM. Update them if the initial - // position of the shelf differs. - if (shelf_alignment() != SHELF_ALIGNMENT_BOTTOM) - UpdateAfterShelfAlignmentChange(shelf_alignment()); - - SetVisible(true); - PreferredSizeChanged(); -} - -void SystemTray::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { - for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); - it != items_.end(); - ++it) { - (*it)->UpdateAfterShelfAlignmentChange(alignment); - } -} - -void SystemTray::SetHideNotifications(bool hide_notifications) { - if (notification_bubble_) - notification_bubble_->bubble()->SetVisible(!hide_notifications); - hide_notifications_ = hide_notifications; -} - -bool SystemTray::ShouldShowLauncher() const { - return system_bubble_.get() && system_bubble_->bubble()->ShouldShowLauncher(); -} - -bool SystemTray::HasSystemBubble() const { - return system_bubble_.get() != NULL; -} - -bool SystemTray::HasNotificationBubble() const { - return notification_bubble_.get() != NULL; -} - -internal::SystemTrayBubble* SystemTray::GetSystemBubble() { - if (!system_bubble_) - return NULL; - return system_bubble_->bubble(); -} - -bool SystemTray::IsAnyBubbleVisible() const { - return ((system_bubble_.get() && - system_bubble_->bubble()->IsVisible()) || - (notification_bubble_.get() && - notification_bubble_->bubble()->IsVisible())); -} - -bool SystemTray::IsMouseInNotificationBubble() const { - if (!notification_bubble_) - return false; - return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains( - Shell::GetScreen()->GetCursorScreenPoint()); -} - -bool SystemTray::CloseSystemBubble() const { - if (!system_bubble_) - return false; - system_bubble_->bubble()->Close(); - return true; -} - -views::View* SystemTray::GetHelpButtonView() const { - return tray_date_->GetHelpButtonView(); -} - -bool SystemTray::CloseNotificationBubbleForTest() const { - if (!notification_bubble_) - return false; - notification_bubble_->bubble()->Close(); - return true; -} - -// Private methods. - -bool SystemTray::HasSystemBubbleType(SystemTrayBubble::BubbleType type) { - DCHECK(type != SystemTrayBubble::BUBBLE_TYPE_NOTIFICATION); - return system_bubble_.get() && system_bubble_->bubble_type() == type; -} - -void SystemTray::DestroySystemBubble() { - CloseSystemBubbleAndDeactivateSystemTray(); - detailed_item_ = NULL; - UpdateWebNotifications(); -} - -void SystemTray::DestroyNotificationBubble() { - if (notification_bubble_) { - notification_bubble_.reset(); - UpdateWebNotifications(); - } -} - -int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { - // Don't attempt to align the arrow if the shelf is on the left or right. - if (shelf_alignment() != SHELF_ALIGNMENT_BOTTOM && - shelf_alignment() != SHELF_ALIGNMENT_TOP) - return TrayBubbleView::InitParams::kArrowDefaultOffset; - - std::map<SystemTrayItem*, views::View*>::const_iterator it = - tray_item_map_.find(item); - if (it == tray_item_map_.end()) - return TrayBubbleView::InitParams::kArrowDefaultOffset; - - const views::View* item_view = it->second; - if (item_view->bounds().IsEmpty()) { - // The bounds of item could be still empty if it does not have a visible - // tray view. In that case, use the default (minimum) offset. - return TrayBubbleView::InitParams::kArrowDefaultOffset; - } - - gfx::Point point(item_view->width() / 2, 0); - ConvertPointToWidget(item_view, &point); - return point.x(); -} - -void SystemTray::ShowDefaultViewWithOffset(BubbleCreationType creation_type, - int arrow_offset, - bool persistent) { - if (creation_type != BUBBLE_USE_EXISTING) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_MENU_OPENED); - } - ShowItems(items_.get(), false, true, creation_type, arrow_offset, persistent); -} - -void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items, - bool detailed, - bool can_activate, - BubbleCreationType creation_type, - int arrow_offset, - bool persistent) { - // No system tray bubbles in kiosk mode. - if (Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus() == - ash::user::LOGGED_IN_KIOSK_APP) { - return; - } - - // Destroy any existing bubble and create a new one. - SystemTrayBubble::BubbleType bubble_type = detailed ? - SystemTrayBubble::BUBBLE_TYPE_DETAILED : - SystemTrayBubble::BUBBLE_TYPE_DEFAULT; - - // Destroy the notification bubble here so that it doesn't get rebuilt - // while we add items to the main bubble_ (e.g. in HideNotificationView). - notification_bubble_.reset(); - if (system_bubble_.get() && creation_type == BUBBLE_USE_EXISTING) { - system_bubble_->bubble()->UpdateView(items, bubble_type); - // If ChromeVox is enabled, focus the default item if no item is focused. - if (Shell::GetInstance()->accessibility_delegate()-> - IsSpokenFeedbackEnabled()) { - system_bubble_->bubble()->FocusDefaultIfNeeded(); - } - } else { - // Remember if the menu is a single property (like e.g. volume) or the - // full tray menu. Note that in case of the |BUBBLE_USE_EXISTING| case - // above, |full_system_tray_menu_| does not get changed since the fact that - // the menu is full (or not) doesn't change even if a "single property" - // (like network) replaces most of the menu. - full_system_tray_menu_ = items.size() > 1; - // The menu width is fixed, and it is a per language setting. - int menu_width = std::max(kMinimumSystemTrayMenuWidth, - Shell::GetInstance()->system_tray_delegate()->GetSystemTrayMenuWidth()); - - TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, - GetAnchorAlignment(), - menu_width, - kTrayPopupMaxWidth); - init_params.can_activate = can_activate; - init_params.first_item_has_no_margin = - ash::switches::UseAlternateShelfLayout(); - if (detailed) { - // This is the case where a volume control or brightness control bubble - // is created. - init_params.max_height = default_bubble_height_; - init_params.arrow_color = kBackgroundColor; - } else { - init_params.arrow_color = kHeaderBackgroundColor; - } - init_params.arrow_offset = arrow_offset; - if (bubble_type == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) - init_params.close_on_deactivate = !persistent; - // For Volume and Brightness we don't want to show an arrow when - // they are shown in a bubble by themselves. - init_params.arrow_paint_type = views::BubbleBorder::PAINT_NORMAL; - if (items.size() == 1 && items[0]->ShouldHideArrow()) - init_params.arrow_paint_type = views::BubbleBorder::PAINT_TRANSPARENT; - SystemTrayBubble* bubble = new SystemTrayBubble(this, items, bubble_type); - system_bubble_.reset(new internal::SystemBubbleWrapper(bubble)); - system_bubble_->InitView(this, tray_container(), &init_params, persistent); - } - // Save height of default view for creating detailed views directly. - if (!detailed) - default_bubble_height_ = system_bubble_->bubble_view()->height(); - - if (detailed && items.size() > 0) - detailed_item_ = items[0]; - else - detailed_item_ = NULL; - - UpdateNotificationBubble(); // State changed, re-create notifications. - if (!notification_bubble_) - UpdateWebNotifications(); - GetShelfLayoutManager()->UpdateAutoHideState(); - - // When we show the system menu in our alternate shelf layout, we need to - // tint the background. - if (full_system_tray_menu_) - SetDrawBackgroundAsActive(true); -} - -void SystemTray::UpdateNotificationBubble() { - // Only show the notification bubble if we have notifications. - if (notification_items_.empty()) { - DestroyNotificationBubble(); - return; - } - // Destroy the existing bubble before constructing a new one. - notification_bubble_.reset(); - SystemTrayBubble* notification_bubble; - notification_bubble = new SystemTrayBubble( - this, notification_items_, SystemTrayBubble::BUBBLE_TYPE_NOTIFICATION); - views::View* anchor; - TrayBubbleView::AnchorType anchor_type; - // Tray items might want to show notifications while we are creating and - // initializing the |system_bubble_| - but it might not be fully initialized - // when coming here - this would produce a crashed like crbug.com/247416. - // As such we check the existence of the widget here. - if (system_bubble_.get() && - system_bubble_->bubble_view() && - system_bubble_->bubble_view()->GetWidget()) { - anchor = system_bubble_->bubble_view(); - anchor_type = TrayBubbleView::ANCHOR_TYPE_BUBBLE; - } else { - anchor = tray_container(); - anchor_type = TrayBubbleView::ANCHOR_TYPE_TRAY; - } - TrayBubbleView::InitParams init_params(anchor_type, - GetAnchorAlignment(), - kTrayPopupMinWidth, - kTrayPopupMaxWidth); - init_params.first_item_has_no_margin = - ash::switches::UseAlternateShelfLayout(); - init_params.arrow_color = kBackgroundColor; - init_params.arrow_offset = GetTrayXOffset(notification_items_[0]); - notification_bubble_.reset( - new internal::SystemBubbleWrapper(notification_bubble)); - notification_bubble_->InitView(this, anchor, &init_params, false); - - if (notification_bubble->bubble_view()->child_count() == 0) { - // It is possible that none of the items generated actual notifications. - DestroyNotificationBubble(); - return; - } - if (hide_notifications_) - notification_bubble->SetVisible(false); - else - UpdateWebNotifications(); -} - -void SystemTray::UpdateWebNotifications() { - TrayBubbleView* bubble_view = NULL; - if (notification_bubble_) - bubble_view = notification_bubble_->bubble_view(); - else if (system_bubble_) - bubble_view = system_bubble_->bubble_view(); - - int height = 0; - if (bubble_view) { - gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( - bubble_view->GetWidget()->GetNativeView()).work_area(); - if (GetShelfLayoutManager()->GetAlignment() != SHELF_ALIGNMENT_TOP) { - height = std::max( - 0, work_area.height() - bubble_view->GetBoundsInScreen().y()); - } else { - height = std::max( - 0, bubble_view->GetBoundsInScreen().bottom() - work_area.y()); - } - } - status_area_widget()->web_notification_tray()->SetSystemTrayHeight(height); -} - -void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { - if (alignment == shelf_alignment()) - return; - internal::TrayBackgroundView::SetShelfAlignment(alignment); - UpdateAfterShelfAlignmentChange(alignment); - // Destroy any existing bubble so that it is rebuilt correctly. - CloseSystemBubbleAndDeactivateSystemTray(); - // Rebuild any notification bubble. - if (notification_bubble_) { - notification_bubble_.reset(); - UpdateNotificationBubble(); - } -} - -void SystemTray::AnchorUpdated() { - if (notification_bubble_) { - notification_bubble_->bubble_view()->UpdateBubble(); - // Ensure that the notification buble is above the launcher/status area. - notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); - UpdateBubbleViewArrow(notification_bubble_->bubble_view()); - } - if (system_bubble_) { - system_bubble_->bubble_view()->UpdateBubble(); - UpdateBubbleViewArrow(system_bubble_->bubble_view()); - } -} - -base::string16 SystemTray::GetAccessibleNameForTray() { - return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); -} - -void SystemTray::BubbleResized(const TrayBubbleView* bubble_view) { - UpdateWebNotifications(); -} - -void SystemTray::HideBubbleWithView(const TrayBubbleView* bubble_view) { - if (system_bubble_.get() && bubble_view == system_bubble_->bubble_view()) { - DestroySystemBubble(); - UpdateNotificationBubble(); // State changed, re-create notifications. - GetShelfLayoutManager()->UpdateAutoHideState(); - } else if (notification_bubble_.get() && - bubble_view == notification_bubble_->bubble_view()) { - DestroyNotificationBubble(); - } -} - -bool SystemTray::ClickedOutsideBubble() { - if (!system_bubble_ || system_bubble_->is_persistent()) - return false; - HideBubbleWithView(system_bubble_->bubble_view()); - return true; -} - -void SystemTray::BubbleViewDestroyed() { - if (system_bubble_) { - system_bubble_->bubble()->DestroyItemViews(); - system_bubble_->bubble()->BubbleViewDestroyed(); - } -} - -void SystemTray::OnMouseEnteredView() { - if (system_bubble_) - system_bubble_->bubble()->StopAutoCloseTimer(); -} - -void SystemTray::OnMouseExitedView() { - if (system_bubble_) - system_bubble_->bubble()->RestartAutoCloseTimer(); -} - -base::string16 SystemTray::GetAccessibleNameForBubble() { - return GetAccessibleNameForTray(); -} - -gfx::Rect SystemTray::GetAnchorRect( - views::Widget* anchor_widget, - TrayBubbleView::AnchorType anchor_type, - TrayBubbleView::AnchorAlignment anchor_alignment) { - return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); -} - -void SystemTray::HideBubble(const TrayBubbleView* bubble_view) { - HideBubbleWithView(bubble_view); -} - -views::View* SystemTray::GetTrayItemViewForTest(SystemTrayItem* item) { - std::map<SystemTrayItem*, views::View*>::iterator it = - tray_item_map_.find(item); - return it == tray_item_map_.end() ? NULL : it->second; -} - -void SystemTray::AddTrayUserItemForTest(internal::TrayUser* tray_user) { - AddTrayItem(tray_user); - user_items_.push_back(tray_user); -} - -bool SystemTray::PerformAction(const ui::Event& event) { - // If we're already showing the default view, hide it; otherwise, show it - // (and hide any popup that's currently shown). - if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { - system_bubble_->bubble()->Close(); - } else { - int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; - if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { - const ui::LocatedEvent& located_event = - static_cast<const ui::LocatedEvent&>(event); - if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM || - shelf_alignment() == SHELF_ALIGNMENT_TOP) { - gfx::Point point(located_event.x(), 0); - ConvertPointToWidget(this, &point); - arrow_offset = point.x(); - } - } - ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset, false); - } - return true; -} - -void SystemTray::CloseSystemBubbleAndDeactivateSystemTray() { - system_bubble_.reset(); - // When closing a system bubble with the alternate shelf layout, we need to - // turn off the active tinting of the shelf. - if (full_system_tray_menu_) { - SetDrawBackgroundAsActive(false); - full_system_tray_menu_ = false; - } -} - -} // namespace ash diff --git a/chromium/ash/system/tray/system_tray.h b/chromium/ash/system/tray/system_tray.h deleted file mode 100644 index 7b1681d1733..00000000000 --- a/chromium/ash/system/tray/system_tray.h +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_ -#define ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_ - -#include "ash/ash_export.h" -#include "ash/system/tray/system_tray_bubble.h" -#include "ash/system/tray/tray_background_view.h" -#include "ash/system/user/login_status.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/scoped_vector.h" -#include "ui/views/bubble/tray_bubble_view.h" -#include "ui/views/view.h" - -#include <map> -#include <vector> - -namespace ash { - -class SystemTrayDelegate; -class SystemTrayItem; - -namespace internal { -class SystemBubbleWrapper; -class TrayAccessibility; -class TrayDate; -class TrayUser; -} - -// There are different methods for creating bubble views. -enum BubbleCreationType { - BUBBLE_CREATE_NEW, // Closes any existing bubble and creates a new one. - BUBBLE_USE_EXISTING, // Uses any existing bubble, or creates a new one. -}; - -class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, - public views::TrayBubbleView::Delegate { - public: - explicit SystemTray(internal::StatusAreaWidget* status_area_widget); - virtual ~SystemTray(); - - // Calls TrayBackgroundView::Initialize(), creates the tray items, and - // adds them to SystemTrayNotifier. - void InitializeTrayItems(SystemTrayDelegate* delegate); - - // Adds a new item in the tray. - void AddTrayItem(SystemTrayItem* item); - - // Removes an existing tray item. - void RemoveTrayItem(SystemTrayItem* item); - - // Returns all tray items that has been added to system tray. - const std::vector<SystemTrayItem*>& GetTrayItems() const; - - // Returns all tray user items that were added to the system tray. - const std::vector<internal::TrayUser*>& GetTrayUserItems() const; - - // Shows the default view of all items. - void ShowDefaultView(BubbleCreationType creation_type); - - // Shows default view that ingnores outside clicks and activation loss. - void ShowPersistentDefaultView(); - - // Shows details of a particular item. If |close_delay_in_seconds| is - // non-zero, then the view is automatically closed after the specified time. - void ShowDetailedView(SystemTrayItem* item, - int close_delay_in_seconds, - bool activate, - BubbleCreationType creation_type); - - // Continue showing the existing detailed view, if any, for |close_delay| - // seconds. - void SetDetailedViewCloseDelay(int close_delay); - - // Hides the detailed view for |item|. - void HideDetailedView(SystemTrayItem* item); - - // Shows the notification view for |item|. - void ShowNotificationView(SystemTrayItem* item); - - // Hides the notification view for |item|. - void HideNotificationView(SystemTrayItem* item); - - // Updates the items when the login status of the system changes. - void UpdateAfterLoginStatusChange(user::LoginStatus login_status); - - // Updates the items when the shelf alignment changes. - void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment); - - // Temporarily hides/unhides the notification bubble. - void SetHideNotifications(bool hidden); - - // Returns true if the launcher should be forced visible when auto-hidden. - bool ShouldShowLauncher() const; - - // Returns true if there is a system bubble (already visible or in the process - // of being created). - bool HasSystemBubble() const; - - // Returns true if there is a notification bubble. - bool HasNotificationBubble() const; - - // Returns true if the system_bubble_ exists and is of type |type|. - bool HasSystemBubbleType(internal::SystemTrayBubble::BubbleType type); - - // Returns a pointer to the system bubble or NULL if none. - internal::SystemTrayBubble* GetSystemBubble(); - - // Returns true if any bubble is visible. - bool IsAnyBubbleVisible() const; - - // Returns true if the mouse is inside the notification bubble. - bool IsMouseInNotificationBubble() const; - - // Closes system bubble and returns true if it did exist. - bool CloseSystemBubble() const; - - // Returns view for help button if default view is shown. Returns NULL - // otherwise. - views::View* GetHelpButtonView() const; - - // Accessors for testing. - - // Returns true if the bubble exists. - bool CloseNotificationBubbleForTest() const; - - // Overridden from TrayBackgroundView. - virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; - virtual void AnchorUpdated() OVERRIDE; - virtual base::string16 GetAccessibleNameForTray() OVERRIDE; - virtual void BubbleResized(const views::TrayBubbleView* bubble_view) OVERRIDE; - virtual void HideBubbleWithView( - const views::TrayBubbleView* bubble_view) OVERRIDE; - virtual bool ClickedOutsideBubble() OVERRIDE; - - // Overridden from message_center::TrayBubbleView::Delegate. - virtual void BubbleViewDestroyed() OVERRIDE; - virtual void OnMouseEnteredView() OVERRIDE; - virtual void OnMouseExitedView() OVERRIDE; - virtual base::string16 GetAccessibleNameForBubble() OVERRIDE; - virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget, - AnchorType anchor_type, - AnchorAlignment anchor_alignment) OVERRIDE; - virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE; - - internal::TrayAccessibility* GetTrayAccessibilityForTest() { - return tray_accessibility_; - } - - // Get the tray item view (or NULL) for a given |tray_item| in a unit test. - views::View* GetTrayItemViewForTest(SystemTrayItem* tray_item); - - // Add a tray user item for testing purposes. Note: The passed |tray_user| - // will be owned by the SystemTray after the call. - void AddTrayUserItemForTest(internal::TrayUser* tray_user); - - private: - // Creates the default set of items for the sytem tray. - void CreateItems(SystemTrayDelegate* delegate); - - // Resets |system_bubble_| and clears any related state. - void DestroySystemBubble(); - - // Resets |notification_bubble_| and clears any related state. - void DestroyNotificationBubble(); - - // Calculates the x-offset for the item in the tray. Returns -1 if its tray - // item view is not visible. - int GetTrayXOffset(SystemTrayItem* item) const; - - // Shows the default view and its arrow position is shifted by |x_offset|. - void ShowDefaultViewWithOffset(BubbleCreationType creation_type, - int x_offset, - bool persistent); - - // Constructs or re-constructs |system_bubble_| and populates it with |items|. - // Specify |change_tray_status| to true if want to change the tray background - // status. - void ShowItems(const std::vector<SystemTrayItem*>& items, - bool details, - bool activate, - BubbleCreationType creation_type, - int x_offset, - bool persistent); - - // Constructs or re-constructs |notification_bubble_| and populates it with - // |notification_items_|, or destroys it if there are no notification items. - void UpdateNotificationBubble(); - - // Checks the current status of the system tray and updates the web - // notification tray according to the current status. - void UpdateWebNotifications(); - - // Deactivate the system tray in the shelf if it was active before. - void CloseSystemBubbleAndDeactivateSystemTray(); - - const ScopedVector<SystemTrayItem>& items() const { return items_; } - - // Overridden from internal::ActionableView. - virtual bool PerformAction(const ui::Event& event) OVERRIDE; - - // Owned items. - ScopedVector<SystemTrayItem> items_; - - // User items - note, this is a subset of the |items_| list. Note that no - // item in this list needs to be deleted. - std::vector<internal::TrayUser*> user_items_; - - // Pointers to members of |items_|. - SystemTrayItem* detailed_item_; - std::vector<SystemTrayItem*> notification_items_; - - // Mappings of system tray item and it's view in the tray. - std::map<SystemTrayItem*, views::View*> tray_item_map_; - - // Bubble for default and detailed views. - scoped_ptr<internal::SystemBubbleWrapper> system_bubble_; - - // Bubble for notifications. - scoped_ptr<internal::SystemBubbleWrapper> notification_bubble_; - - // Keep track of the default view height so that when we create detailed - // views directly (e.g. from a notification) we know what height to use. - int default_bubble_height_; - - // Set to true when system notifications should be hidden (e.g. web - // notification bubble is visible). - bool hide_notifications_; - - // This is true when the displayed system tray menu is a full tray menu, - // otherwise a single line item menu like the volume slider is shown. - // Note that the value is only valid when |system_bubble_| is true. - bool full_system_tray_menu_; - - internal::TrayAccessibility* tray_accessibility_; // not owned - internal::TrayDate* tray_date_; - - DISALLOW_COPY_AND_ASSIGN(SystemTray); -}; - -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_ diff --git a/chromium/ash/system/tray/system_tray_bubble.cc b/chromium/ash/system/tray/system_tray_bubble.cc deleted file mode 100644 index 1aa60bc5541..00000000000 --- a/chromium/ash/system/tray/system_tray_bubble.cc +++ /dev/null @@ -1,388 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/system_tray_bubble.h" - -#include "ash/shell.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_item.h" -#include "ash/system/tray/tray_bubble_wrapper.h" -#include "ash/system/tray/tray_constants.h" -#include "base/message_loop/message_loop.h" -#include "ui/aura/window.h" -#include "ui/compositor/layer.h" -#include "ui/compositor/layer_animation_observer.h" -#include "ui/compositor/scoped_layer_animation_settings.h" -#include "ui/gfx/canvas.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -using views::TrayBubbleView; - -namespace ash { - -namespace { - -// Normally a detailed view is the same size as the default view. However, -// when showing a detailed view directly (e.g. clicking on a notification), -// we may not know the height of the default view, or the default view may -// be too short, so we use this as a default and minimum height for any -// detailed view. -const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; - -// Duration of swipe animation used when transitioning from a default to -// detailed view or vice versa. -const int kSwipeDelayMS = 150; - -// A view with some special behaviour for tray items in the popup: -// - optionally changes background color on hover. -class TrayPopupItemContainer : public views::View { - public: - TrayPopupItemContainer(views::View* view, - bool change_background, - bool draw_border) - : hover_(false), - change_background_(change_background) { - set_notify_enter_exit_on_child(true); - if (draw_border) { - set_border( - views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kBorderLightColor)); - } - views::BoxLayout* layout = new views::BoxLayout( - views::BoxLayout::kVertical, 0, 0, 0); - layout->set_spread_blank_space(true); - SetLayoutManager(layout); - SetPaintToLayer(view->layer() != NULL); - if (view->layer()) - SetFillsBoundsOpaquely(view->layer()->fills_bounds_opaquely()); - AddChildView(view); - SetVisible(view->visible()); - } - - virtual ~TrayPopupItemContainer() {} - - private: - // Overridden from views::View. - virtual void ChildVisibilityChanged(View* child) OVERRIDE { - if (visible() == child->visible()) - return; - SetVisible(child->visible()); - PreferredSizeChanged(); - } - - virtual void ChildPreferredSizeChanged(View* child) OVERRIDE { - PreferredSizeChanged(); - } - - virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { - hover_ = true; - SchedulePaint(); - } - - virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE { - hover_ = false; - SchedulePaint(); - } - - virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE { - if (child_count() == 0) - return; - - views::View* view = child_at(0); - if (!view->background()) { - canvas->FillRect(gfx::Rect(size()), (hover_ && change_background_) ? - kHoverBackgroundColor : kBackgroundColor); - } - } - - bool hover_; - bool change_background_; - - DISALLOW_COPY_AND_ASSIGN(TrayPopupItemContainer); -}; - -// Implicit animation observer that deletes itself and the layer at the end of -// the animation. -class AnimationObserverDeleteLayer : public ui::ImplicitAnimationObserver { - public: - explicit AnimationObserverDeleteLayer(ui::Layer* layer) - : layer_(layer) { - } - - virtual ~AnimationObserverDeleteLayer() { - } - - virtual void OnImplicitAnimationsCompleted() OVERRIDE { - base::MessageLoopForUI::current()->DeleteSoon(FROM_HERE, this); - } - - private: - scoped_ptr<ui::Layer> layer_; - - DISALLOW_COPY_AND_ASSIGN(AnimationObserverDeleteLayer); -}; - -} // namespace - -namespace internal { - -// SystemTrayBubble - -SystemTrayBubble::SystemTrayBubble( - ash::SystemTray* tray, - const std::vector<ash::SystemTrayItem*>& items, - BubbleType bubble_type) - : tray_(tray), - bubble_view_(NULL), - items_(items), - bubble_type_(bubble_type), - autoclose_delay_(0) { -} - -SystemTrayBubble::~SystemTrayBubble() { - DestroyItemViews(); - // Reset the host pointer in bubble_view_ in case its destruction is deferred. - if (bubble_view_) - bubble_view_->reset_delegate(); -} - -void SystemTrayBubble::UpdateView( - const std::vector<ash::SystemTrayItem*>& items, - BubbleType bubble_type) { - DCHECK(bubble_type != BUBBLE_TYPE_NOTIFICATION); - - scoped_ptr<ui::Layer> scoped_layer; - if (bubble_type != bubble_type_) { - base::TimeDelta swipe_duration = - base::TimeDelta::FromMilliseconds(kSwipeDelayMS); - scoped_layer.reset(bubble_view_->RecreateLayer()); - // Keep the reference to layer as we need it after releasing it. - ui::Layer* layer = scoped_layer.get(); - DCHECK(layer); - layer->SuppressPaint(); - - // When transitioning from detailed view to default view, animate the - // existing view (slide out towards the right). - if (bubble_type == BUBBLE_TYPE_DEFAULT) { - ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); - settings.AddObserver( - new AnimationObserverDeleteLayer(scoped_layer.release())); - settings.SetTransitionDuration(swipe_duration); - settings.SetTweenType(gfx::Tween::EASE_OUT); - gfx::Transform transform; - transform.Translate(layer->bounds().width(), 0.0); - layer->SetTransform(transform); - } - - { - // Add a shadow layer to make the old layer darker as the animation - // progresses. - ui::Layer* shadow = new ui::Layer(ui::LAYER_SOLID_COLOR); - shadow->SetColor(SK_ColorBLACK); - shadow->SetOpacity(0.01f); - shadow->SetBounds(layer->bounds()); - layer->Add(shadow); - layer->StackAtTop(shadow); - { - // Animate the darkening effect a little longer than the swipe-in. This - // is to make sure the darkening animation does not end up finishing - // early, because the dark layer goes away at the end of the animation, - // and there is a brief moment when the old view is still visible, but - // it does not have the shadow layer on top. - ui::ScopedLayerAnimationSettings settings(shadow->GetAnimator()); - settings.AddObserver(new AnimationObserverDeleteLayer(shadow)); - settings.SetTransitionDuration(swipe_duration + - base::TimeDelta::FromMilliseconds(150)); - settings.SetTweenType(gfx::Tween::LINEAR); - shadow->SetOpacity(0.15f); - } - } - } - - DestroyItemViews(); - bubble_view_->RemoveAllChildViews(true); - - items_ = items; - bubble_type_ = bubble_type; - CreateItemViews( - Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()); - - // Close bubble view if we failed to create the item view. - if (!bubble_view_->has_children()) { - Close(); - return; - } - - bubble_view_->GetWidget()->GetContentsView()->Layout(); - // Make sure that the bubble is large enough for the default view. - if (bubble_type_ == BUBBLE_TYPE_DEFAULT) { - bubble_view_->SetMaxHeight(0); // Clear max height limit. - } - - if (scoped_layer) { - // When transitioning from default view to detailed view, animate the new - // view (slide in from the right). - if (bubble_type == BUBBLE_TYPE_DETAILED) { - ui::Layer* new_layer = bubble_view_->layer(); - - // Make sure the new layer is stacked above the old layer during the - // animation. - new_layer->parent()->StackAbove(new_layer, scoped_layer.get()); - - gfx::Rect bounds = new_layer->bounds(); - gfx::Transform transform; - transform.Translate(bounds.width(), 0.0); - new_layer->SetTransform(transform); - { - ui::ScopedLayerAnimationSettings settings(new_layer->GetAnimator()); - settings.AddObserver( - new AnimationObserverDeleteLayer(scoped_layer.release())); - settings.SetTransitionDuration( - base::TimeDelta::FromMilliseconds(kSwipeDelayMS)); - settings.SetTweenType(gfx::Tween::EASE_OUT); - new_layer->SetTransform(gfx::Transform()); - } - } - } -} - -void SystemTrayBubble::InitView(views::View* anchor, - user::LoginStatus login_status, - TrayBubbleView::InitParams* init_params) { - DCHECK(bubble_view_ == NULL); - - if (bubble_type_ == BUBBLE_TYPE_DETAILED && - init_params->max_height < kDetailedBubbleMaxHeight) { - init_params->max_height = kDetailedBubbleMaxHeight; - } else if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) { - init_params->close_on_deactivate = false; - } - bubble_view_ = TrayBubbleView::Create( - tray_->GetBubbleWindowContainer(), anchor, tray_, init_params); - bubble_view_->set_adjust_if_offscreen(false); - CreateItemViews(login_status); - - if (bubble_view_->CanActivate()) { - bubble_view_->NotifyAccessibilityEvent( - ui::AccessibilityTypes::EVENT_ALERT, true); - } -} - -void SystemTrayBubble::FocusDefaultIfNeeded() { - views::FocusManager* manager = bubble_view_->GetFocusManager(); - if (!manager || manager->GetFocusedView()) - return; - - views::View* view = manager->GetNextFocusableView(NULL, NULL, false, false); - if (view) - view->RequestFocus(); -} - -void SystemTrayBubble::DestroyItemViews() { - for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); - it != items_.end(); - ++it) { - switch (bubble_type_) { - case BUBBLE_TYPE_DEFAULT: - (*it)->DestroyDefaultView(); - break; - case BUBBLE_TYPE_DETAILED: - (*it)->DestroyDetailedView(); - break; - case BUBBLE_TYPE_NOTIFICATION: - (*it)->DestroyNotificationView(); - break; - } - } -} - -void SystemTrayBubble::BubbleViewDestroyed() { - bubble_view_ = NULL; -} - -void SystemTrayBubble::StartAutoCloseTimer(int seconds) { - autoclose_.Stop(); - autoclose_delay_ = seconds; - if (autoclose_delay_) { - autoclose_.Start(FROM_HERE, - base::TimeDelta::FromSeconds(autoclose_delay_), - this, &SystemTrayBubble::Close); - } -} - -void SystemTrayBubble::StopAutoCloseTimer() { - autoclose_.Stop(); -} - -void SystemTrayBubble::RestartAutoCloseTimer() { - if (autoclose_delay_) - StartAutoCloseTimer(autoclose_delay_); -} - -void SystemTrayBubble::Close() { - tray_->HideBubbleWithView(bubble_view()); -} - -void SystemTrayBubble::SetVisible(bool is_visible) { - if (!bubble_view_) - return; - views::Widget* bubble_widget = bubble_view_->GetWidget(); - if (is_visible) - bubble_widget->Show(); - else - bubble_widget->Hide(); -} - -bool SystemTrayBubble::IsVisible() { - return bubble_view() && bubble_view()->GetWidget()->IsVisible(); -} - -bool SystemTrayBubble::ShouldShowLauncher() const { - for (std::vector<ash::SystemTrayItem*>::const_iterator it = items_.begin(); - it != items_.end(); - ++it) { - if ((*it)->ShouldShowLauncher()) - return true; - } - return false; -} - -void SystemTrayBubble::CreateItemViews(user::LoginStatus login_status) { - std::vector<views::View*> item_views; - views::View* focus_view = NULL; - for (size_t i = 0; i < items_.size(); ++i) { - views::View* view = NULL; - switch (bubble_type_) { - case BUBBLE_TYPE_DEFAULT: - view = items_[i]->CreateDefaultView(login_status); - if (items_[i]->restore_focus()) - focus_view = view; - break; - case BUBBLE_TYPE_DETAILED: - view = items_[i]->CreateDetailedView(login_status); - break; - case BUBBLE_TYPE_NOTIFICATION: - view = items_[i]->CreateNotificationView(login_status); - break; - } - if (view) - item_views.push_back(view); - } - - bool is_default_bubble = bubble_type_ == BUBBLE_TYPE_DEFAULT; - for (size_t i = 0; i < item_views.size(); ++i) { - // For default view, draw bottom border for each item, except the last - // 2 items, which are the bottom header row and the one just above it. - bubble_view_->AddChildView(new TrayPopupItemContainer( - item_views[i], is_default_bubble, - is_default_bubble && (i < item_views.size() - 2))); - } - if (focus_view) - focus_view->RequestFocus(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/system_tray_bubble.h b/chromium/ash/system/tray/system_tray_bubble.h deleted file mode 100644 index b84c3ea022e..00000000000 --- a/chromium/ash/system/tray/system_tray_bubble.h +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_SYSTEM_TRAY_BUBBLE_H_ -#define ASH_SYSTEM_TRAY_SYSTEM_TRAY_BUBBLE_H_ - -#include "ash/system/user/login_status.h" -#include "base/base_export.h" -#include "base/memory/scoped_ptr.h" -#include "base/timer/timer.h" -#include "ui/views/bubble/tray_bubble_view.h" - -#include <vector> - -namespace ash { - -class SystemTray; -class SystemTrayItem; - -namespace internal { - -class SystemTrayBubble { - public: - enum BubbleType { - BUBBLE_TYPE_DEFAULT, - BUBBLE_TYPE_DETAILED, - BUBBLE_TYPE_NOTIFICATION - }; - - SystemTrayBubble(ash::SystemTray* tray, - const std::vector<ash::SystemTrayItem*>& items, - BubbleType bubble_type); - virtual ~SystemTrayBubble(); - - // Change the items displayed in the bubble. - void UpdateView(const std::vector<ash::SystemTrayItem*>& items, - BubbleType bubble_type); - - // Creates |bubble_view_| and a child views for each member of |items_|. - // Also creates |bubble_wrapper_|. |init_params| may be modified. - void InitView(views::View* anchor, - user::LoginStatus login_status, - views::TrayBubbleView::InitParams* init_params); - - // Focus the default item if no item is focused. Othewise, do nothing. - void FocusDefaultIfNeeded(); - - BubbleType bubble_type() const { return bubble_type_; } - views::TrayBubbleView* bubble_view() const { return bubble_view_; } - - void DestroyItemViews(); - void BubbleViewDestroyed(); - void StartAutoCloseTimer(int seconds); - void StopAutoCloseTimer(); - void RestartAutoCloseTimer(); - void Close(); - void SetVisible(bool is_visible); - bool IsVisible(); - - // Returns true if any of the SystemTrayItems return true from - // ShouldShowLauncher(). - bool ShouldShowLauncher() const; - - private: - void CreateItemViews(user::LoginStatus login_status); - - ash::SystemTray* tray_; - views::TrayBubbleView* bubble_view_; - std::vector<ash::SystemTrayItem*> items_; - BubbleType bubble_type_; - - int autoclose_delay_; - base::OneShotTimer<SystemTrayBubble> autoclose_; - - DISALLOW_COPY_AND_ASSIGN(SystemTrayBubble); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_BUBBLE_H_ diff --git a/chromium/ash/system/tray/system_tray_delegate.cc b/chromium/ash/system/tray/system_tray_delegate.cc deleted file mode 100644 index 084e1587661..00000000000 --- a/chromium/ash/system/tray/system_tray_delegate.cc +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/system_tray_delegate.h" - -namespace ash { - -NetworkIconInfo::NetworkIconInfo() - : connecting(false), - connected(false), - tray_icon_visible(true), - is_cellular(false) { -} - -NetworkIconInfo::~NetworkIconInfo() { -} - -BluetoothDeviceInfo::BluetoothDeviceInfo() - : connected(false), - connecting(false), - paired(false) { -} - -BluetoothDeviceInfo::~BluetoothDeviceInfo() { -} - -DriveOperationStatus::DriveOperationStatus() - : id(-1), - progress(0.0), - type(OPERATION_DOWNLOAD), - state(OPERATION_NOT_STARTED) { -} - -DriveOperationStatus::~DriveOperationStatus() { -} - -IMEInfo::IMEInfo() - : selected(false), - third_party(false) { -} - -IMEInfo::~IMEInfo() { -} - -IMEPropertyInfo::IMEPropertyInfo() - : selected(false) { -} - -IMEPropertyInfo::~IMEPropertyInfo() { -} - -} // namespace ash diff --git a/chromium/ash/system/tray/system_tray_delegate.h b/chromium/ash/system/tray/system_tray_delegate.h deleted file mode 100644 index ee325dd95ba..00000000000 --- a/chromium/ash/system/tray/system_tray_delegate.h +++ /dev/null @@ -1,321 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_SYSTEM_TRAY_DELEGATE_H_ -#define ASH_SYSTEM_TRAY_SYSTEM_TRAY_DELEGATE_H_ - -#include <string> -#include <vector> - -#include "ash/ash_export.h" -#include "ash/system/user/login_status.h" -#include "base/files/file_path.h" -#include "base/i18n/time_formatting.h" -#include "base/memory/scoped_ptr.h" -#include "base/strings/string16.h" -#include "ui/gfx/image/image_skia.h" -#include "ui/gfx/native_widget_types.h" - -namespace base { -class TimeDelta; -class TimeTicks; -} - -namespace ash { - -struct ASH_EXPORT NetworkIconInfo { - NetworkIconInfo(); - ~NetworkIconInfo(); - - bool highlight() const { return connected || connecting; } - - bool connecting; - bool connected; - bool tray_icon_visible; - gfx::ImageSkia image; - base::string16 name; - base::string16 description; - std::string service_path; - bool is_cellular; -}; - -struct ASH_EXPORT BluetoothDeviceInfo { - BluetoothDeviceInfo(); - ~BluetoothDeviceInfo(); - - std::string address; - base::string16 display_name; - bool connected; - bool connecting; - bool paired; -}; - -typedef std::vector<BluetoothDeviceInfo> BluetoothDeviceList; - -// Structure that packs progress information of each operation. -struct ASH_EXPORT DriveOperationStatus { - enum OperationType { - OPERATION_UPLOAD, - OPERATION_DOWNLOAD - }; - - enum OperationState { - OPERATION_NOT_STARTED, - OPERATION_IN_PROGRESS, - OPERATION_COMPLETED, - OPERATION_FAILED, - }; - - DriveOperationStatus(); - ~DriveOperationStatus(); - - // Unique ID for the operation. - int32 id; - - // File path. - base::FilePath file_path; - // Current operation completion progress [0.0 - 1.0]. - double progress; - OperationType type; - OperationState state; -}; - -typedef std::vector<DriveOperationStatus> DriveOperationStatusList; - - -struct ASH_EXPORT IMEPropertyInfo { - IMEPropertyInfo(); - ~IMEPropertyInfo(); - - bool selected; - std::string key; - base::string16 name; -}; - -typedef std::vector<IMEPropertyInfo> IMEPropertyInfoList; - -struct ASH_EXPORT IMEInfo { - IMEInfo(); - ~IMEInfo(); - - bool selected; - bool third_party; - std::string id; - base::string16 name; - base::string16 medium_name; - base::string16 short_name; -}; - -typedef std::vector<IMEInfo> IMEInfoList; - -class VolumeControlDelegate; - -class ASH_EXPORT SystemTrayDelegate { - public: - virtual ~SystemTrayDelegate() {} - - // Called after SystemTray has been instantiated. - virtual void Initialize() = 0; - - // Called before SystemTray is destroyed. - virtual void Shutdown() = 0; - - // Returns true if system tray should be visible on startup. - virtual bool GetTrayVisibilityOnStartup() = 0; - - // Gets information about the active user. - virtual user::LoginStatus GetUserLoginStatus() const = 0; - virtual bool IsOobeCompleted() const = 0; - - // Shows UI for changing user's profile picture. - virtual void ChangeProfilePicture() = 0; - - // Returns the domain that manages the device, if it is enterprise-enrolled. - virtual const std::string GetEnterpriseDomain() const = 0; - - // Returns notification for enterprise enrolled devices. - virtual const base::string16 GetEnterpriseMessage() const = 0; - - // Returns the display email of user that manages current - // locally managed user. - virtual const std::string GetLocallyManagedUserManager() const = 0; - - // Returns the name of user that manages current locally managed user. - virtual const base::string16 GetLocallyManagedUserManagerName() const = 0; - - // Returns notification for locally managed users. - virtual const base::string16 GetLocallyManagedUserMessage() const = 0; - - // Returns whether a system upgrade is available. - virtual bool SystemShouldUpgrade() const = 0; - - // Returns the desired hour clock type. - virtual base::HourClockType GetHourClockType() const = 0; - - // Shows settings. - virtual void ShowSettings() = 0; - - // Returns true if settings menu item should appear. - virtual bool ShouldShowSettings() = 0; - - // Shows the settings related to date, timezone etc. - virtual void ShowDateSettings() = 0; - - // Shows the settings related to network. If |service_path| is not empty, - // show the settings for that network. - virtual void ShowNetworkSettings(const std::string& service_path) = 0; - - // Shows the settings related to bluetooth. - virtual void ShowBluetoothSettings() = 0; - - // Shows settings related to multiple displays. - virtual void ShowDisplaySettings() = 0; - - // Shows the page that lets you disable performance tracing. - virtual void ShowChromeSlow() = 0; - - // Returns true if the notification for the display configuration change - // should appear. - virtual bool ShouldShowDisplayNotification() = 0; - - // Shows settings related to Google Drive. - virtual void ShowDriveSettings() = 0; - - // Shows settings related to input methods. - virtual void ShowIMESettings() = 0; - - // Shows help. - virtual void ShowHelp() = 0; - - // Show accessilibity help. - virtual void ShowAccessibilityHelp() = 0; - - // Show the settings related to accessilibity. - virtual void ShowAccessibilitySettings() = 0; - - // Shows more information about public account mode. - virtual void ShowPublicAccountInfo() = 0; - - // Shows information about enterprise enrolled devices. - virtual void ShowEnterpriseInfo() = 0; - - // Shows information about locally managed users. - virtual void ShowLocallyManagedUserInfo() = 0; - - // Shows login UI to add other users to this session. - virtual void ShowUserLogin() = 0; - - // Shows the spring charger replacement dialog if necessary. - virtual void ShowSpringChargerReplacementDialog() = 0; - - // True if user has confirmed using safe spring charger. - virtual bool HasUserConfirmedSafeSpringCharger() = 0; - - // Attempts to shut down the system. - virtual void ShutDown() = 0; - - // Attempts to sign out the user. - virtual void SignOut() = 0; - - // Attempts to lock the screen. - virtual void RequestLockScreen() = 0; - - // Attempts to restart the system for update. - virtual void RequestRestartForUpdate() = 0; - - // Returns a list of available bluetooth devices. - virtual void GetAvailableBluetoothDevices(BluetoothDeviceList* devices) = 0; - - // Requests bluetooth start discovering devices. - virtual void BluetoothStartDiscovering() = 0; - - // Requests bluetooth stop discovering devices. - virtual void BluetoothStopDiscovering() = 0; - - // Connect to a specific bluetooth device. - virtual void ConnectToBluetoothDevice(const std::string& address) = 0; - - // Returns true if bluetooth adapter is discovering bluetooth devices. - virtual bool IsBluetoothDiscovering() = 0; - - // Returns the currently selected IME. - virtual void GetCurrentIME(IMEInfo* info) = 0; - - // Returns a list of availble IMEs. - virtual void GetAvailableIMEList(IMEInfoList* list) = 0; - - // Returns a list of properties for the currently selected IME. - virtual void GetCurrentIMEProperties(IMEPropertyInfoList* list) = 0; - - // Switches to the selected input method. - virtual void SwitchIME(const std::string& ime_id) = 0; - - // Activates an IME property. - virtual void ActivateIMEProperty(const std::string& key) = 0; - - // Cancels ongoing drive operation. - virtual void CancelDriveOperation(int32 operation_id) = 0; - - // Returns information about the ongoing drive operations. - virtual void GetDriveOperationStatusList( - DriveOperationStatusList* list) = 0; - - // Shows UI to configure or activate the network specified by |network_id|, - // which may include showing Payment or Portal UI when appropriate. - // |parent_window| is used to parent any configuration UI. If NULL a default - // window will be used. - virtual void ShowNetworkConfigure(const std::string& network_id, - gfx::NativeWindow parent_window) = 0; - - // Shows UI to enroll the network specified by |network_id| if appropriate - // and returns true, otherwise returns false. |parent_window| is used - // to parent any configuration UI. If NULL a default window will be used. - virtual bool EnrollNetwork(const std::string& network_id, - gfx::NativeWindow parent_window) = 0; - - // Shows UI to manage bluetooth devices. - virtual void ManageBluetoothDevices() = 0; - - // Toggles bluetooth. - virtual void ToggleBluetooth() = 0; - - // Shows UI to unlock a mobile sim. - virtual void ShowMobileSimDialog() = 0; - - // Shows UI to setup a mobile network. - virtual void ShowMobileSetupDialog(const std::string& service_path) = 0; - - // Shows UI to connect to an unlisted network of type |type|. On Chrome OS - // |type| corresponds to a Shill network type. - virtual void ShowOtherNetworkDialog(const std::string& type) = 0; - - // Returns whether bluetooth capability is available. - virtual bool GetBluetoothAvailable() = 0; - - // Returns whether bluetooth is enabled. - virtual bool GetBluetoothEnabled() = 0; - - // Shows UI for changing proxy settings. - virtual void ChangeProxySettings() = 0; - - // Returns VolumeControlDelegate. - virtual VolumeControlDelegate* GetVolumeControlDelegate() const = 0; - - // Sets VolumeControlDelegate. - virtual void SetVolumeControlDelegate( - scoped_ptr<VolumeControlDelegate> delegate) = 0; - - // Retrieves the session start time. Returns |false| if the time is not set. - virtual bool GetSessionStartTime(base::TimeTicks* session_start_time) = 0; - - // Retrieves the session length limit. Returns |false| if no limit is set. - virtual bool GetSessionLengthLimit(base::TimeDelta* session_length_limit) = 0; - - // Get the system tray menu size in pixels (dependent on the language). - virtual int GetSystemTrayMenuWidth() = 0; -}; - -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_DELEGATE_H_ diff --git a/chromium/ash/system/tray/system_tray_item.cc b/chromium/ash/system/tray/system_tray_item.cc deleted file mode 100644 index f5d5b717c74..00000000000 --- a/chromium/ash/system/tray/system_tray_item.cc +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/system_tray_item.h" - -#include "ash/shell.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ui/views/view.h" - -namespace ash { - -SystemTrayItem::SystemTrayItem(SystemTray* system_tray) - : system_tray_(system_tray), - restore_focus_(false) { -} - -SystemTrayItem::~SystemTrayItem() { -} - -views::View* SystemTrayItem::CreateTrayView(user::LoginStatus status) { - return NULL; -} - -views::View* SystemTrayItem::CreateDefaultView(user::LoginStatus status) { - return NULL; -} - -views::View* SystemTrayItem::CreateDetailedView(user::LoginStatus status) { - return NULL; -} - -views::View* SystemTrayItem::CreateNotificationView(user::LoginStatus status) { - return NULL; -} - -void SystemTrayItem::DestroyTrayView() { -} - -void SystemTrayItem::DestroyDefaultView() { -} - -void SystemTrayItem::DestroyDetailedView() { -} - -void SystemTrayItem::DestroyNotificationView() { -} - -void SystemTrayItem::TransitionDetailedView() { - system_tray()->ShowDetailedView(this, 0, true, BUBBLE_USE_EXISTING); -} - -void SystemTrayItem::UpdateAfterLoginStatusChange(user::LoginStatus status) { -} - -void SystemTrayItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { -} - -void SystemTrayItem::PopupDetailedView(int for_seconds, bool activate) { - // Never show a detailed view during OOBE, e.g. from a notification. - if (!Shell::GetInstance()->system_tray_delegate()->IsOobeCompleted()) - return; - system_tray()->ShowDetailedView( - this, for_seconds, activate, BUBBLE_CREATE_NEW); -} - -void SystemTrayItem::SetDetailedViewCloseDelay(int for_seconds) { - system_tray()->SetDetailedViewCloseDelay(for_seconds); -} - -void SystemTrayItem::HideDetailedView() { - system_tray()->HideDetailedView(this); -} - -void SystemTrayItem::ShowNotificationView() { - system_tray()->ShowNotificationView(this); -} - -void SystemTrayItem::HideNotificationView() { - system_tray()->HideNotificationView(this); -} - -bool SystemTrayItem::ShouldHideArrow() const { - return false; -} - -bool SystemTrayItem::ShouldShowLauncher() const { - return true; -} - -} // namespace ash diff --git a/chromium/ash/system/tray/system_tray_item.h b/chromium/ash/system/tray/system_tray_item.h deleted file mode 100644 index b42f3f5b35f..00000000000 --- a/chromium/ash/system/tray/system_tray_item.h +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_SYSTEM_TRAY_ITEM_H_ -#define ASH_SYSTEM_TRAY_SYSTEM_TRAY_ITEM_H_ - -#include "ash/ash_export.h" -#include "ash/shelf/shelf_types.h" -#include "ash/system/user/login_status.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" - -namespace views { -class View; -} - -namespace ash { - -class SystemTray; - -namespace internal { -class TrayItemView; -} - -class ASH_EXPORT SystemTrayItem { - public: - explicit SystemTrayItem(SystemTray* system_tray); - virtual ~SystemTrayItem(); - - // Create* functions may return NULL if nothing should be displayed for the - // type of view. The default implementations return NULL. - - // Returns a view to be displayed in the system tray. If this returns NULL, - // then this item is not displayed in the tray. - // NOTE: The returned view should almost always be a TrayItemView, which - // automatically resizes the widget when the size of the view changes, and - // adds animation when the visibility of the view changes. If a view wants to - // avoid this behavior, then it should not be a TrayItemView. - virtual views::View* CreateTrayView(user::LoginStatus status); - - // Returns a view for the item to be displayed in the list. This view can be - // displayed with a number of other tray items, so this should not be too - // big. - virtual views::View* CreateDefaultView(user::LoginStatus status); - - // Returns a detailed view for the item. This view is displayed standalone. - virtual views::View* CreateDetailedView(user::LoginStatus status); - - // Returns a notification view for the item. This view is displayed with - // other notifications and should be the same size as default views. - virtual views::View* CreateNotificationView(user::LoginStatus status); - - // These functions are called when the corresponding view item is about to be - // removed. An item should do appropriate cleanup in these functions. - // The default implementation does nothing. - virtual void DestroyTrayView(); - virtual void DestroyDefaultView(); - virtual void DestroyDetailedView(); - virtual void DestroyNotificationView(); - - // Updates the tray view (if applicable) when the user's login status changes. - // It is not necessary the update the default or detailed view, since the - // default/detailed popup is closed when login status changes. The default - // implementation does nothing. - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status); - - // Updates the tray view (if applicable) when shelf's alignment changes. - // The default implementation does nothing. - virtual void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment); - - // Shows the detailed view for this item. If the main popup for the tray is - // currently visible, then making this call would use the existing window to - // display the detailed item. The detailed item will inherit the bounds of the - // existing window. - // If there is no existing view, then this is equivalent to calling - // PopupDetailedView(0, true). - void TransitionDetailedView(); - - // Pops up the detailed view for this item. An item can request to show its - // detailed view using this function (e.g. from an observer callback when - // something, e.g. volume, network availability etc. changes). If - // |for_seconds| is non-zero, then the popup is closed after the specified - // time. - void PopupDetailedView(int for_seconds, bool activate); - - // Continue showing the currently-shown detailed view, if any, for - // |for_seconds| seconds. The caller is responsible for checking that the - // currently-shown view is for this item. - void SetDetailedViewCloseDelay(int for_seconds); - - // Hides the detailed view for this item. - void HideDetailedView(); - - // Shows a notification for this item. - void ShowNotificationView(); - - // Hides the notification for this item. - void HideNotificationView(); - - // Returns true if item should hide the arrow. - virtual bool ShouldHideArrow() const; - - // Returns true if this item needs to force the launcher to be visible when - // the launcher is in the auto-hide state. Default is true. - virtual bool ShouldShowLauncher() const; - - // Returns the system tray that this item belongs to. - SystemTray* system_tray() const { return system_tray_; } - - bool restore_focus() const { return restore_focus_; } - void set_restore_focus(bool restore_focus) { - restore_focus_ = restore_focus; - } - - private: - SystemTray* system_tray_; - bool restore_focus_; - - DISALLOW_COPY_AND_ASSIGN(SystemTrayItem); -}; - -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_ITEM_H_ diff --git a/chromium/ash/system/tray/system_tray_notifier.cc b/chromium/ash/system/tray/system_tray_notifier.cc deleted file mode 100644 index e2035ad357f..00000000000 --- a/chromium/ash/system/tray/system_tray_notifier.cc +++ /dev/null @@ -1,316 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/system_tray_notifier.h" - -#if defined(OS_CHROMEOS) -#include "ash/system/chromeos/network/network_state_notifier.h" -#endif - -namespace ash { - -SystemTrayNotifier::SystemTrayNotifier() { -#if defined(OS_CHROMEOS) - network_state_notifier_.reset(new NetworkStateNotifier()); -#endif -} - -SystemTrayNotifier::~SystemTrayNotifier() { -} - -void SystemTrayNotifier::AddAccessibilityObserver( - AccessibilityObserver* observer) { - accessibility_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveAccessibilityObserver( - AccessibilityObserver* observer) { - accessibility_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddBluetoothObserver(BluetoothObserver* observer) { - bluetooth_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveBluetoothObserver(BluetoothObserver* observer) { - bluetooth_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddCapsLockObserver(CapsLockObserver* observer) { - caps_lock_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveCapsLockObserver(CapsLockObserver* observer) { - caps_lock_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddClockObserver(ClockObserver* observer) { - clock_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveClockObserver(ClockObserver* observer) { - clock_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddDriveObserver(DriveObserver* observer) { - drive_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveDriveObserver(DriveObserver* observer) { - drive_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddIMEObserver(IMEObserver* observer) { - ime_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveIMEObserver(IMEObserver* observer) { - ime_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddLocaleObserver(LocaleObserver* observer) { - locale_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveLocaleObserver(LocaleObserver* observer) { - locale_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddLogoutButtonObserver( - LogoutButtonObserver* observer) { - logout_button_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveLogoutButtonObserver( - LogoutButtonObserver* observer) { - logout_button_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddSessionLengthLimitObserver( - SessionLengthLimitObserver* observer) { - session_length_limit_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveSessionLengthLimitObserver( - SessionLengthLimitObserver* observer) { - session_length_limit_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddTracingObserver(TracingObserver* observer) { - tracing_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveTracingObserver(TracingObserver* observer) { - tracing_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddUpdateObserver(UpdateObserver* observer) { - update_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveUpdateObserver(UpdateObserver* observer) { - update_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddUserObserver(UserObserver* observer) { - user_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveUserObserver(UserObserver* observer) { - user_observers_.RemoveObserver(observer); -} - -#if defined(OS_CHROMEOS) - -void SystemTrayNotifier::AddNetworkObserver(NetworkObserver* observer) { - network_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveNetworkObserver(NetworkObserver* observer) { - network_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddEnterpriseDomainObserver( - EnterpriseDomainObserver* observer) { - enterprise_domain_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveEnterpriseDomainObserver( - EnterpriseDomainObserver* observer) { - enterprise_domain_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddScreenCaptureObserver( - ScreenCaptureObserver* observer) { - screen_capture_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveScreenCaptureObserver( - ScreenCaptureObserver* observer) { - screen_capture_observers_.RemoveObserver(observer); -} - -void SystemTrayNotifier::AddScreenShareObserver( - ScreenShareObserver* observer) { - screen_share_observers_.AddObserver(observer); -} - -void SystemTrayNotifier::RemoveScreenShareObserver( - ScreenShareObserver* observer) { - screen_share_observers_.RemoveObserver(observer); -} -#endif - -void SystemTrayNotifier::NotifyAccessibilityModeChanged( - AccessibilityNotificationVisibility notify) { - FOR_EACH_OBSERVER( - AccessibilityObserver, - accessibility_observers_, - OnAccessibilityModeChanged(notify)); -} - -void SystemTrayNotifier::NotifyTracingModeChanged(bool value) { - FOR_EACH_OBSERVER( - TracingObserver, - tracing_observers_, - OnTracingModeChanged(value)); -} - -void SystemTrayNotifier::NotifyRefreshBluetooth() { - FOR_EACH_OBSERVER(BluetoothObserver, - bluetooth_observers_, - OnBluetoothRefresh()); -} - -void SystemTrayNotifier::NotifyBluetoothDiscoveringChanged() { - FOR_EACH_OBSERVER(BluetoothObserver, - bluetooth_observers_, - OnBluetoothDiscoveringChanged()); -} - -void SystemTrayNotifier::NotifyCapsLockChanged( - bool enabled, - bool search_mapped_to_caps_lock) { - FOR_EACH_OBSERVER(CapsLockObserver, - caps_lock_observers_, - OnCapsLockChanged(enabled, search_mapped_to_caps_lock)); -} - -void SystemTrayNotifier::NotifyRefreshClock() { - FOR_EACH_OBSERVER(ClockObserver, clock_observers_, Refresh()); -} - -void SystemTrayNotifier::NotifyDateFormatChanged() { - FOR_EACH_OBSERVER(ClockObserver, - clock_observers_, - OnDateFormatChanged()); -} - -void SystemTrayNotifier::NotifySystemClockTimeUpdated() { - FOR_EACH_OBSERVER(ClockObserver, - clock_observers_, - OnSystemClockTimeUpdated()); -} - -void SystemTrayNotifier::NotifyDriveJobUpdated( - const DriveOperationStatus& status) { - FOR_EACH_OBSERVER(DriveObserver, - drive_observers_, - OnDriveJobUpdated(status)); -} - -void SystemTrayNotifier::NotifyRefreshIME(bool show_message) { - FOR_EACH_OBSERVER(IMEObserver, - ime_observers_, - OnIMERefresh(show_message)); -} - -void SystemTrayNotifier::NotifyShowLoginButtonChanged(bool show_login_button) { - FOR_EACH_OBSERVER(LogoutButtonObserver, - logout_button_observers_, - OnShowLogoutButtonInTrayChanged(show_login_button)); -} - -void SystemTrayNotifier::NotifyLocaleChanged( - LocaleObserver::Delegate* delegate, - const std::string& cur_locale, - const std::string& from_locale, - const std::string& to_locale) { - FOR_EACH_OBSERVER( - LocaleObserver, - locale_observers_, - OnLocaleChanged(delegate, cur_locale, from_locale, to_locale)); -} - -void SystemTrayNotifier::NotifySessionStartTimeChanged() { - FOR_EACH_OBSERVER(SessionLengthLimitObserver, - session_length_limit_observers_, - OnSessionStartTimeChanged()); -} - -void SystemTrayNotifier::NotifySessionLengthLimitChanged() { - FOR_EACH_OBSERVER(SessionLengthLimitObserver, - session_length_limit_observers_, - OnSessionLengthLimitChanged()); -} - -void SystemTrayNotifier::NotifyUpdateRecommended( - UpdateObserver::UpdateSeverity severity) { - FOR_EACH_OBSERVER(UpdateObserver, - update_observers_, - OnUpdateRecommended(severity)); -} - -void SystemTrayNotifier::NotifyUserUpdate() { - FOR_EACH_OBSERVER(UserObserver, - user_observers_, - OnUserUpdate()); -} - -void SystemTrayNotifier::NotifyUserAddedToSession() { - FOR_EACH_OBSERVER(UserObserver, - user_observers_, - OnUserAddedToSession()); -} - -#if defined(OS_CHROMEOS) - -void SystemTrayNotifier::NotifyRequestToggleWifi() { - FOR_EACH_OBSERVER(NetworkObserver, - network_observers_, - RequestToggleWifi()); -} - -void SystemTrayNotifier::NotifyEnterpriseDomainChanged() { - FOR_EACH_OBSERVER(EnterpriseDomainObserver, enterprise_domain_observers_, - OnEnterpriseDomainChanged()); -} - -void SystemTrayNotifier::NotifyScreenCaptureStart( - const base::Closure& stop_callback, - const base::string16& sharing_app_name) { - FOR_EACH_OBSERVER(ScreenCaptureObserver, screen_capture_observers_, - OnScreenCaptureStart(stop_callback, sharing_app_name)); -} - -void SystemTrayNotifier::NotifyScreenCaptureStop() { - FOR_EACH_OBSERVER(ScreenCaptureObserver, screen_capture_observers_, - OnScreenCaptureStop()); -} - -void SystemTrayNotifier::NotifyScreenShareStart( - const base::Closure& stop_callback, - const base::string16& helper_name) { - FOR_EACH_OBSERVER(ScreenShareObserver, screen_share_observers_, - OnScreenShareStart(stop_callback, helper_name)); -} - -void SystemTrayNotifier::NotifyScreenShareStop() { - FOR_EACH_OBSERVER(ScreenShareObserver, screen_share_observers_, - OnScreenShareStop()); -} - -#endif // OS_CHROMEOS - -} // namespace ash diff --git a/chromium/ash/system/tray/system_tray_notifier.h b/chromium/ash/system/tray/system_tray_notifier.h deleted file mode 100644 index 3d7fb0e63e0..00000000000 --- a/chromium/ash/system/tray/system_tray_notifier.h +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_SYSTEM_TRAY_NOTIFIER_H_ -#define ASH_SYSTEM_TRAY_SYSTEM_TRAY_NOTIFIER_H_ - -#include <string> -#include <vector> - -#include "ash/ash_export.h" -#include "ash/system/bluetooth/bluetooth_observer.h" -#include "ash/system/chromeos/tray_tracing.h" -#include "ash/system/date/clock_observer.h" -#include "ash/system/drive/drive_observer.h" -#include "ash/system/ime/ime_observer.h" -#include "ash/system/locale/locale_observer.h" -#include "ash/system/logout_button/logout_button_observer.h" -#include "ash/system/session_length_limit/session_length_limit_observer.h" -#include "ash/system/tray_accessibility.h" -#include "ash/system/tray_caps_lock.h" -#include "ash/system/user/update_observer.h" -#include "ash/system/user/user_observer.h" -#include "base/observer_list.h" - -#if defined(OS_CHROMEOS) -#include "ash/system/chromeos/enterprise/enterprise_domain_observer.h" -#include "ash/system/chromeos/network/network_observer.h" -#include "ash/system/chromeos/screen_security/screen_capture_observer.h" -#include "ash/system/chromeos/screen_security/screen_share_observer.h" -#endif - -namespace ash { - -#if defined(OS_CHROMEOS) -class NetworkStateNotifier; -#endif - -class ASH_EXPORT SystemTrayNotifier { -public: - SystemTrayNotifier(); - ~SystemTrayNotifier(); - - void AddAccessibilityObserver(AccessibilityObserver* observer); - void RemoveAccessibilityObserver(AccessibilityObserver* observer); - - void AddBluetoothObserver(BluetoothObserver* observer); - void RemoveBluetoothObserver(BluetoothObserver* observer); - - void AddCapsLockObserver(CapsLockObserver* observer); - void RemoveCapsLockObserver(CapsLockObserver* observer); - - void AddClockObserver(ClockObserver* observer); - void RemoveClockObserver(ClockObserver* observer); - - void AddDriveObserver(DriveObserver* observer); - void RemoveDriveObserver(DriveObserver* observer); - - void AddIMEObserver(IMEObserver* observer); - void RemoveIMEObserver(IMEObserver* observer); - - void AddLocaleObserver(LocaleObserver* observer); - void RemoveLocaleObserver(LocaleObserver* observer); - - void AddLogoutButtonObserver(LogoutButtonObserver* observer); - void RemoveLogoutButtonObserver(LogoutButtonObserver* observer); - - void AddSessionLengthLimitObserver(SessionLengthLimitObserver* observer); - void RemoveSessionLengthLimitObserver(SessionLengthLimitObserver* observer); - - void AddTracingObserver(TracingObserver* observer); - void RemoveTracingObserver(TracingObserver* observer); - - void AddUpdateObserver(UpdateObserver* observer); - void RemoveUpdateObserver(UpdateObserver* observer); - - void AddUserObserver(UserObserver* observer); - void RemoveUserObserver(UserObserver* observer); - -#if defined(OS_CHROMEOS) - void AddNetworkObserver(NetworkObserver* observer); - void RemoveNetworkObserver(NetworkObserver* observer); - - void AddEnterpriseDomainObserver(EnterpriseDomainObserver* observer); - void RemoveEnterpriseDomainObserver(EnterpriseDomainObserver* observer); - - void AddScreenCaptureObserver(ScreenCaptureObserver* observer); - void RemoveScreenCaptureObserver(ScreenCaptureObserver* observer); - - void AddScreenShareObserver(ScreenShareObserver* observer); - void RemoveScreenShareObserver(ScreenShareObserver* observer); -#endif - - void NotifyAccessibilityModeChanged( - AccessibilityNotificationVisibility notify); - void NotifyTracingModeChanged(bool value); - void NotifyRefreshBluetooth(); - void NotifyBluetoothDiscoveringChanged(); - void NotifyCapsLockChanged(bool enabled, bool search_mapped_to_caps_lock); - void NotifyRefreshClock(); - void NotifyDateFormatChanged(); - void NotifySystemClockTimeUpdated(); - void NotifyDriveJobUpdated(const DriveOperationStatus& status); - void NotifyRefreshIME(bool show_message); - void NotifyShowLoginButtonChanged(bool show_login_button); - void NotifyLocaleChanged(LocaleObserver::Delegate* delegate, - const std::string& cur_locale, - const std::string& from_locale, - const std::string& to_locale); - void NotifySessionStartTimeChanged(); - void NotifySessionLengthLimitChanged(); - void NotifyUpdateRecommended(UpdateObserver::UpdateSeverity severity); - void NotifyUserUpdate(); - void NotifyUserAddedToSession(); -#if defined(OS_CHROMEOS) - void NotifyRequestToggleWifi(); - void NotifyEnterpriseDomainChanged(); - void NotifyScreenCaptureStart(const base::Closure& stop_callback, - const base::string16& sharing_app_name); - void NotifyScreenCaptureStop(); - void NotifyScreenShareStart(const base::Closure& stop_callback, - const base::string16& helper_name); - void NotifyScreenShareStop(); - - NetworkStateNotifier* network_state_notifier() { - return network_state_notifier_.get(); - } -#endif - - private: - ObserverList<AccessibilityObserver> accessibility_observers_; - ObserverList<BluetoothObserver> bluetooth_observers_; - ObserverList<CapsLockObserver> caps_lock_observers_; - ObserverList<ClockObserver> clock_observers_; - ObserverList<DriveObserver> drive_observers_; - ObserverList<IMEObserver> ime_observers_; - ObserverList<LocaleObserver> locale_observers_; - ObserverList<LogoutButtonObserver> logout_button_observers_; - ObserverList<SessionLengthLimitObserver> session_length_limit_observers_; - ObserverList<TracingObserver> tracing_observers_; - ObserverList<UpdateObserver> update_observers_; - ObserverList<UserObserver> user_observers_; -#if defined(OS_CHROMEOS) - ObserverList<NetworkObserver> network_observers_; - ObserverList<EnterpriseDomainObserver> enterprise_domain_observers_; - ObserverList<ScreenCaptureObserver> screen_capture_observers_; - ObserverList<ScreenShareObserver> screen_share_observers_; - scoped_ptr<NetworkStateNotifier> network_state_notifier_; -#endif - - DISALLOW_COPY_AND_ASSIGN(SystemTrayNotifier); -}; - -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_NOTIFIER_H_ diff --git a/chromium/ash/system/tray/system_tray_unittest.cc b/chromium/ash/system/tray/system_tray_unittest.cc deleted file mode 100644 index 779975ac621..00000000000 --- a/chromium/ash/system/tray/system_tray_unittest.cc +++ /dev/null @@ -1,421 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/system_tray.h" - -#include <vector> - -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_layout_manager.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/system/status_area_widget.h" -#include "ash/system/tray/system_tray_item.h" -#include "ash/test/ash_test_base.h" -#include "ash/wm/window_util.h" -#include "base/run_loop.h" -#include "base/strings/utf_string_conversions.h" -#include "ui/aura/test/event_generator.h" -#include "ui/aura/window.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -#if defined(OS_WIN) -#include "base/win/windows_version.h" -#endif - -namespace ash { -namespace test { - -namespace { - -SystemTray* GetSystemTray() { - return Shell::GetPrimaryRootWindowController()->shelf()-> - status_area_widget()->system_tray(); -} - -// Trivial item implementation that tracks its views for testing. -class TestItem : public SystemTrayItem { - public: - TestItem() : SystemTrayItem(GetSystemTray()), tray_view_(NULL) {} - - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE { - tray_view_ = new views::View; - // Add a label so it has non-zero width. - tray_view_->SetLayoutManager(new views::FillLayout); - tray_view_->AddChildView(new views::Label(UTF8ToUTF16("Tray"))); - return tray_view_; - } - - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE { - default_view_ = new views::View; - default_view_->SetLayoutManager(new views::FillLayout); - default_view_->AddChildView(new views::Label(UTF8ToUTF16("Default"))); - return default_view_; - } - - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE { - detailed_view_ = new views::View; - detailed_view_->SetLayoutManager(new views::FillLayout); - detailed_view_->AddChildView(new views::Label(UTF8ToUTF16("Detailed"))); - return detailed_view_; - } - - virtual views::View* CreateNotificationView( - user::LoginStatus status) OVERRIDE { - notification_view_ = new views::View; - return notification_view_; - } - - virtual void DestroyTrayView() OVERRIDE { - tray_view_ = NULL; - } - - virtual void DestroyDefaultView() OVERRIDE { - default_view_ = NULL; - } - - virtual void DestroyDetailedView() OVERRIDE { - detailed_view_ = NULL; - } - - virtual void DestroyNotificationView() OVERRIDE { - notification_view_ = NULL; - } - - virtual void UpdateAfterLoginStatusChange( - user::LoginStatus status) OVERRIDE { - } - - views::View* tray_view() const { return tray_view_; } - views::View* default_view() const { return default_view_; } - views::View* detailed_view() const { return detailed_view_; } - views::View* notification_view() const { return notification_view_; } - - private: - views::View* tray_view_; - views::View* default_view_; - views::View* detailed_view_; - views::View* notification_view_; -}; - -// Trivial item implementation that returns NULL from tray/default/detailed -// view creation methods. -class TestNoViewItem : public SystemTrayItem { - public: - TestNoViewItem() : SystemTrayItem(GetSystemTray()) {} - - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE { - return NULL; - } - - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE { - return NULL; - } - - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE { - return NULL; - } - - virtual views::View* CreateNotificationView( - user::LoginStatus status) OVERRIDE { - return NULL; - } - - virtual void DestroyTrayView() OVERRIDE {} - virtual void DestroyDefaultView() OVERRIDE {} - virtual void DestroyDetailedView() OVERRIDE {} - virtual void DestroyNotificationView() OVERRIDE {} - virtual void UpdateAfterLoginStatusChange( - user::LoginStatus status) OVERRIDE { - } -}; - -} // namespace - -typedef AshTestBase SystemTrayTest; - -TEST_F(SystemTrayTest, SystemTrayDefaultView) { - SystemTray* tray = GetSystemTray(); - ASSERT_TRUE(tray->GetWidget()); - - tray->ShowDefaultView(BUBBLE_CREATE_NEW); - - // Ensure that closing the bubble destroys it. - ASSERT_TRUE(tray->CloseSystemBubble()); - RunAllPendingInMessageLoop(); - ASSERT_FALSE(tray->CloseSystemBubble()); -} - -// Opening and closing the bubble should change the coloring of the tray. -TEST_F(SystemTrayTest, SystemTrayColoring) { - SystemTray* tray = GetSystemTray(); - ASSERT_TRUE(tray->GetWidget()); - // At the beginning the tray coloring is not active. - ASSERT_FALSE(tray->draw_background_as_active()); - - // Showing the system bubble should show the background as active. - tray->ShowDefaultView(BUBBLE_CREATE_NEW); - ASSERT_TRUE(tray->draw_background_as_active()); - - // Closing the system menu should change the coloring back to normal. - ASSERT_TRUE(tray->CloseSystemBubble()); - RunAllPendingInMessageLoop(); - ASSERT_FALSE(tray->draw_background_as_active()); -} - -// Closing the system bubble through an alignment change should change the -// system tray coloring back to normal. -TEST_F(SystemTrayTest, SystemTrayColoringAfterAlignmentChange) { - SystemTray* tray = GetSystemTray(); - ASSERT_TRUE(tray->GetWidget()); - internal::ShelfLayoutManager* manager = - Shell::GetPrimaryRootWindowController()->shelf()->shelf_layout_manager(); - manager->SetAlignment(SHELF_ALIGNMENT_BOTTOM); - // At the beginning the tray coloring is not active. - ASSERT_FALSE(tray->draw_background_as_active()); - - // Showing the system bubble should show the background as active. - tray->ShowDefaultView(BUBBLE_CREATE_NEW); - ASSERT_TRUE(tray->draw_background_as_active()); - - // Changing the alignment should close the system bubble and change the - // background color. - manager->SetAlignment(SHELF_ALIGNMENT_LEFT); - ASSERT_FALSE(tray->draw_background_as_active()); - RunAllPendingInMessageLoop(); - // The bubble should already be closed by now. - ASSERT_FALSE(tray->CloseSystemBubble()); -} - -TEST_F(SystemTrayTest, SystemTrayTestItems) { - SystemTray* tray = GetSystemTray(); - ASSERT_TRUE(tray->GetWidget()); - - TestItem* test_item = new TestItem; - TestItem* detailed_item = new TestItem; - tray->AddTrayItem(test_item); - tray->AddTrayItem(detailed_item); - - // Check items have been added - const std::vector<SystemTrayItem*>& items = tray->GetTrayItems(); - ASSERT_TRUE( - std::find(items.begin(), items.end(), test_item) != items.end()); - ASSERT_TRUE( - std::find(items.begin(), items.end(), detailed_item) != items.end()); - - // Ensure the tray views are created. - ASSERT_TRUE(test_item->tray_view() != NULL); - ASSERT_TRUE(detailed_item->tray_view() != NULL); - - // Ensure a default views are created. - tray->ShowDefaultView(BUBBLE_CREATE_NEW); - ASSERT_TRUE(test_item->default_view() != NULL); - ASSERT_TRUE(detailed_item->default_view() != NULL); - - // Show the detailed view, ensure it's created and the default view destroyed. - tray->ShowDetailedView(detailed_item, 0, false, BUBBLE_CREATE_NEW); - RunAllPendingInMessageLoop(); - ASSERT_TRUE(test_item->default_view() == NULL); - ASSERT_TRUE(detailed_item->detailed_view() != NULL); - - // Show the default view, ensure it's created and the detailed view destroyed. - tray->ShowDefaultView(BUBBLE_CREATE_NEW); - RunAllPendingInMessageLoop(); - ASSERT_TRUE(test_item->default_view() != NULL); - ASSERT_TRUE(detailed_item->detailed_view() == NULL); -} - -TEST_F(SystemTrayTest, SystemTrayNoViewItems) { - SystemTray* tray = GetSystemTray(); - ASSERT_TRUE(tray->GetWidget()); - - // Verify that no crashes occur on items lacking some views. - TestNoViewItem* no_view_item = new TestNoViewItem; - tray->AddTrayItem(no_view_item); - tray->ShowDefaultView(BUBBLE_CREATE_NEW); - tray->ShowDetailedView(no_view_item, 0, false, BUBBLE_USE_EXISTING); - RunAllPendingInMessageLoop(); -} - -TEST_F(SystemTrayTest, TrayWidgetAutoResizes) { - SystemTray* tray = GetSystemTray(); - ASSERT_TRUE(tray->GetWidget()); - - // Add an initial tray item so that the tray gets laid out correctly. - TestItem* initial_item = new TestItem; - tray->AddTrayItem(initial_item); - - gfx::Size initial_size = tray->GetWidget()->GetWindowBoundsInScreen().size(); - - TestItem* new_item = new TestItem; - tray->AddTrayItem(new_item); - - gfx::Size new_size = tray->GetWidget()->GetWindowBoundsInScreen().size(); - - // Adding the new item should change the size of the tray. - EXPECT_NE(initial_size.ToString(), new_size.ToString()); - - // Hiding the tray view of the new item should also change the size of the - // tray. - new_item->tray_view()->SetVisible(false); - EXPECT_EQ(initial_size.ToString(), - tray->GetWidget()->GetWindowBoundsInScreen().size().ToString()); - - new_item->tray_view()->SetVisible(true); - EXPECT_EQ(new_size.ToString(), - tray->GetWidget()->GetWindowBoundsInScreen().size().ToString()); -} - -TEST_F(SystemTrayTest, SystemTrayNotifications) { - SystemTray* tray = GetSystemTray(); - ASSERT_TRUE(tray->GetWidget()); - - TestItem* test_item = new TestItem; - TestItem* detailed_item = new TestItem; - tray->AddTrayItem(test_item); - tray->AddTrayItem(detailed_item); - - // Ensure the tray views are created. - ASSERT_TRUE(test_item->tray_view() != NULL); - ASSERT_TRUE(detailed_item->tray_view() != NULL); - - // Ensure a notification view is created. - tray->ShowNotificationView(test_item); - ASSERT_TRUE(test_item->notification_view() != NULL); - - // Show the default view, notification view should remain. - tray->ShowDefaultView(BUBBLE_CREATE_NEW); - RunAllPendingInMessageLoop(); - ASSERT_TRUE(test_item->notification_view() != NULL); - - // Show the detailed view, ensure the notificaiton view remains. - tray->ShowDetailedView(detailed_item, 0, false, BUBBLE_CREATE_NEW); - RunAllPendingInMessageLoop(); - ASSERT_TRUE(detailed_item->detailed_view() != NULL); - ASSERT_TRUE(test_item->notification_view() != NULL); - - // Hide the detailed view, ensure the notification view still exists. - ASSERT_TRUE(tray->CloseSystemBubble()); - RunAllPendingInMessageLoop(); - ASSERT_TRUE(detailed_item->detailed_view() == NULL); - ASSERT_TRUE(test_item->notification_view() != NULL); -} - -TEST_F(SystemTrayTest, BubbleCreationTypesTest) { - SystemTray* tray = GetSystemTray(); - ASSERT_TRUE(tray->GetWidget()); - - TestItem* test_item = new TestItem; - tray->AddTrayItem(test_item); - - // Ensure the tray views are created. - ASSERT_TRUE(test_item->tray_view() != NULL); - - // Show the default view, ensure the notification view is destroyed. - tray->ShowDefaultView(BUBBLE_CREATE_NEW); - RunAllPendingInMessageLoop(); - - views::Widget* widget = test_item->default_view()->GetWidget(); - gfx::Rect bubble_bounds = widget->GetWindowBoundsInScreen(); - - tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING); - RunAllPendingInMessageLoop(); - - EXPECT_FALSE(test_item->default_view()); - - EXPECT_EQ(bubble_bounds.ToString(), test_item->detailed_view()->GetWidget()-> - GetWindowBoundsInScreen().ToString()); - EXPECT_EQ(widget, test_item->detailed_view()->GetWidget()); - - tray->ShowDefaultView(BUBBLE_USE_EXISTING); - RunAllPendingInMessageLoop(); - - EXPECT_EQ(bubble_bounds.ToString(), test_item->default_view()->GetWidget()-> - GetWindowBoundsInScreen().ToString()); - EXPECT_EQ(widget, test_item->default_view()->GetWidget()); -} - -// Tests that the tray is laid out properly and is fully contained within -// the shelf. -TEST_F(SystemTrayTest, TrayBoundsInWidget) { - internal::ShelfLayoutManager* manager = - Shell::GetPrimaryRootWindowController()->shelf()->shelf_layout_manager(); - internal::StatusAreaWidget* widget = - Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget(); - SystemTray* tray = widget->system_tray(); - - // Test in bottom alignment. - manager->SetAlignment(SHELF_ALIGNMENT_BOTTOM); - gfx::Rect window_bounds = widget->GetWindowBoundsInScreen(); - gfx::Rect tray_bounds = tray->GetBoundsInScreen(); - EXPECT_TRUE(window_bounds.bottom() >= tray_bounds.bottom()); - EXPECT_TRUE(window_bounds.right() >= tray_bounds.right()); - EXPECT_TRUE(window_bounds.x() >= tray_bounds.x()); - EXPECT_TRUE(window_bounds.y() >= tray_bounds.y()); - - // Test in the left alignment. - manager->SetAlignment(SHELF_ALIGNMENT_LEFT); - window_bounds = widget->GetWindowBoundsInScreen(); - tray_bounds = tray->GetBoundsInScreen(); - EXPECT_TRUE(window_bounds.bottom() >= tray_bounds.bottom()); - EXPECT_TRUE(window_bounds.right() >= tray_bounds.right()); - EXPECT_TRUE(window_bounds.x() >= tray_bounds.x()); - EXPECT_TRUE(window_bounds.y() >= tray_bounds.y()); - - // Test in the right alignment. - manager->SetAlignment(SHELF_ALIGNMENT_LEFT); - window_bounds = widget->GetWindowBoundsInScreen(); - tray_bounds = tray->GetBoundsInScreen(); - EXPECT_TRUE(window_bounds.bottom() >= tray_bounds.bottom()); - EXPECT_TRUE(window_bounds.right() >= tray_bounds.right()); - EXPECT_TRUE(window_bounds.x() >= tray_bounds.x()); - EXPECT_TRUE(window_bounds.y() >= tray_bounds.y()); -} - -TEST_F(SystemTrayTest, PersistentBubble) { - SystemTray* tray = GetSystemTray(); - ASSERT_TRUE(tray->GetWidget()); - - TestItem* test_item = new TestItem; - tray->AddTrayItem(test_item); - - scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); - - // Tests for usual default view. - // Activating window. - tray->ShowDefaultView(BUBBLE_CREATE_NEW); - ASSERT_TRUE(tray->HasSystemBubble()); - wm::ActivateWindow(window.get()); - base::RunLoop().RunUntilIdle(); - ASSERT_FALSE(tray->HasSystemBubble()); - - tray->ShowDefaultView(BUBBLE_CREATE_NEW); - ASSERT_TRUE(tray->HasSystemBubble()); - { - aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), - gfx::Point(5, 5)); - generator.ClickLeftButton(); - ASSERT_FALSE(tray->HasSystemBubble()); - } - - // Same tests for persistent default view. - tray->ShowPersistentDefaultView(); - ASSERT_TRUE(tray->HasSystemBubble()); - wm::ActivateWindow(window.get()); - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(tray->HasSystemBubble()); - - { - aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), - gfx::Point(5, 5)); - generator.ClickLeftButton(); - ASSERT_TRUE(tray->HasSystemBubble()); - } -} - -} // namespace test -} // namespace ash diff --git a/chromium/ash/system/tray/throbber_view.cc b/chromium/ash/system/tray/throbber_view.cc deleted file mode 100644 index 2c2cc206904..00000000000 --- a/chromium/ash/system/tray/throbber_view.cc +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/throbber_view.h" - -#include "ash/system/tray/tray_constants.h" -#include "grit/ash_resources.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/compositor/layer.h" -#include "ui/compositor/scoped_layer_animation_settings.h" - -namespace ash { -namespace internal { - -namespace { - -// Time in ms per throbber frame. -const int kThrobberFrameMs = 30; - -// Duration for showing/hiding animation in milliseconds. -const int kThrobberAnimationDurationMs = 200; - -} // namespace - -SystemTrayThrobber::SystemTrayThrobber(int frame_delay_ms) - : views::SmoothedThrobber(frame_delay_ms) { -} - -SystemTrayThrobber::~SystemTrayThrobber() { -} - -void SystemTrayThrobber::SetTooltipText(const base::string16& tooltip_text) { - tooltip_text_ = tooltip_text; -} - -bool SystemTrayThrobber::GetTooltipText(const gfx::Point& p, - base::string16* tooltip) const { - if (tooltip_text_.empty()) - return false; - - *tooltip = tooltip_text_; - return true; -} - -ThrobberView::ThrobberView() { - throbber_ = new SystemTrayThrobber(kThrobberFrameMs); - throbber_->SetFrames(ui::ResourceBundle::GetSharedInstance().GetImageNamed( - IDR_AURA_CROS_DEFAULT_THROBBER).ToImageSkia()); - throbber_->set_stop_delay_ms(kThrobberAnimationDurationMs); - AddChildView(throbber_); - - SetPaintToLayer(true); - layer()->SetFillsBoundsOpaquely(false); - layer()->SetOpacity(0.0); -} - -ThrobberView::~ThrobberView() { -} - -gfx::Size ThrobberView::GetPreferredSize() { - return gfx::Size(ash::kTrayPopupItemHeight, ash::kTrayPopupItemHeight); -} - -void ThrobberView::Layout() { - View* child = child_at(0); - gfx::Size ps = child->GetPreferredSize(); - child->SetBounds((width() - ps.width()) / 2, - (height() - ps.height()) / 2, - ps.width(), ps.height()); - SizeToPreferredSize(); -} - -bool ThrobberView::GetTooltipText(const gfx::Point& p, - base::string16* tooltip) const { - if (tooltip_text_.empty()) - return false; - - *tooltip = tooltip_text_; - return true; -} - -void ThrobberView::Start() { - ScheduleAnimation(true); - throbber_->Start(); -} - -void ThrobberView::Stop() { - ScheduleAnimation(false); - throbber_->Stop(); -} - -void ThrobberView::SetTooltipText(const base::string16& tooltip_text) { - tooltip_text_ = tooltip_text; - throbber_->SetTooltipText(tooltip_text); -} - -void ThrobberView::ScheduleAnimation(bool start_throbber) { - // Stop any previous animation. - layer()->GetAnimator()->StopAnimating(); - - ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); - animation.SetTransitionDuration( - base::TimeDelta::FromMilliseconds(kThrobberAnimationDurationMs)); - - layer()->SetOpacity(start_throbber ? 1.0 : 0.0); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/throbber_view.h b/chromium/ash/system/tray/throbber_view.h deleted file mode 100644 index 0f2663280e2..00000000000 --- a/chromium/ash/system/tray/throbber_view.h +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_THROBBER_VIEW_H_ -#define ASH_SYSTEM_TRAY_THROBBER_VIEW_H_ - -#include "ui/gfx/size.h" -#include "ui/views/controls/throbber.h" -#include "ui/views/view.h" - -namespace ash { -namespace internal { - -// A SmoothedThrobber with tooltip. -class SystemTrayThrobber : public views::SmoothedThrobber { - public: - SystemTrayThrobber(int frame_delay_ms); - virtual ~SystemTrayThrobber(); - - void SetTooltipText(const base::string16& tooltip_text); - - // Overriden from views::View. - virtual bool GetTooltipText( - const gfx::Point& p, base::string16* tooltip) const OVERRIDE; - - private: - // The current tooltip text. - base::string16 tooltip_text_; - - DISALLOW_COPY_AND_ASSIGN(SystemTrayThrobber); -}; - -// A View containing a SystemTrayThrobber with animation for starting/stopping. -class ThrobberView : public views::View { - public: - ThrobberView(); - virtual ~ThrobberView(); - - void Start(); - void Stop(); - void SetTooltipText(const base::string16& tooltip_text); - - // Overriden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual void Layout() OVERRIDE; - virtual bool GetTooltipText( - const gfx::Point& p, base::string16* tooltip) const OVERRIDE; - - private: - // Schedules animation for starting/stopping throbber. - void ScheduleAnimation(bool start_throbber); - - SystemTrayThrobber* throbber_; - - // The current tooltip text. - base::string16 tooltip_text_; - - DISALLOW_COPY_AND_ASSIGN(ThrobberView); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_THROBBER_VIEW_H_ diff --git a/chromium/ash/system/tray/tray_background_view.cc b/chromium/ash/system/tray/tray_background_view.cc deleted file mode 100644 index 80cac07e364..00000000000 --- a/chromium/ash/system/tray/tray_background_view.cc +++ /dev/null @@ -1,634 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_background_view.h" - -#include "ash/ash_switches.h" -#include "ash/root_window_controller.h" -#include "ash/screen_ash.h" -#include "ash/shelf/shelf_layout_manager.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/shell_window_ids.h" -#include "ash/system/status_area_widget.h" -#include "ash/system/status_area_widget_delegate.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_event_filter.h" -#include "ash/wm/window_animations.h" -#include "grit/ash_resources.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/image/image_skia.h" -#include "ui/gfx/image/image_skia_operations.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/screen.h" -#include "ui/gfx/skia_util.h" -#include "ui/views/background.h" -#include "ui/views/layout/box_layout.h" - -namespace { - -const int kTrayBackgroundAlpha = 100; -const int kTrayBackgroundHoverAlpha = 150; -const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244); - -// Adjust the size of TrayContainer with additional padding. -const int kTrayContainerVerticalPaddingBottomAlignment = 1; -const int kTrayContainerHorizontalPaddingBottomAlignment = 1; -const int kTrayContainerVerticalPaddingVerticalAlignment = 1; -const int kTrayContainerHorizontalPaddingVerticalAlignment = 1; - -const int kAnimationDurationForPopupMS = 200; - -} // namespace - -using views::TrayBubbleView; - -namespace ash { -namespace internal { - -// static -const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; - -// Used to track when the anchor widget changes position on screen so that the -// bubble position can be updated. -class TrayBackgroundView::TrayWidgetObserver : public views::WidgetObserver { - public: - explicit TrayWidgetObserver(TrayBackgroundView* host) - : host_(host) { - } - - virtual void OnWidgetBoundsChanged(views::Widget* widget, - const gfx::Rect& new_bounds) OVERRIDE { - host_->AnchorUpdated(); - } - - virtual void OnWidgetVisibilityChanged(views::Widget* widget, - bool visible) OVERRIDE { - host_->AnchorUpdated(); - } - - private: - TrayBackgroundView* host_; - - DISALLOW_COPY_AND_ASSIGN(TrayWidgetObserver); -}; - -class TrayBackground : public views::Background { - public: - const static int kImageTypeDefault = 0; - const static int kImageTypeOnBlack = 1; - const static int kImageTypePressed = 2; - const static int kNumStates = 3; - - const static int kImageHorizontal = 0; - const static int kImageVertical = 1; - const static int kNumOrientations = 2; - - explicit TrayBackground(TrayBackgroundView* tray_background_view) : - tray_background_view_(tray_background_view) { - set_alpha(kTrayBackgroundAlpha); - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - leading_images_[kImageHorizontal][kImageTypeDefault] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT).ToImageSkia(); - middle_images_[kImageHorizontal][kImageTypeDefault] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER).ToImageSkia(); - trailing_images_[kImageHorizontal][kImageTypeDefault] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT).ToImageSkia(); - - leading_images_[kImageHorizontal][kImageTypeOnBlack] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT_ONBLACK).ToImageSkia(); - middle_images_[kImageHorizontal][kImageTypeOnBlack] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER_ONBLACK).ToImageSkia(); - trailing_images_[kImageHorizontal][kImageTypeOnBlack] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT_ONBLACK).ToImageSkia(); - - leading_images_[kImageHorizontal][kImageTypePressed] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT_PRESSED).ToImageSkia(); - middle_images_[kImageHorizontal][kImageTypePressed] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER_PRESSED).ToImageSkia(); - trailing_images_[kImageHorizontal][kImageTypePressed] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT_PRESSED).ToImageSkia(); - - leading_images_[kImageVertical][kImageTypeDefault] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP).ToImageSkia(); - middle_images_[kImageVertical][kImageTypeDefault] = - rb.GetImageNamed( - IDR_AURA_TRAY_BG_VERTICAL_CENTER).ToImageSkia(); - trailing_images_[kImageVertical][kImageTypeDefault] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_BOTTOM).ToImageSkia(); - - leading_images_[kImageVertical][kImageTypeOnBlack] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP_ONBLACK).ToImageSkia(); - middle_images_[kImageVertical][kImageTypeOnBlack] = - rb.GetImageNamed( - IDR_AURA_TRAY_BG_VERTICAL_CENTER_ONBLACK).ToImageSkia(); - trailing_images_[kImageVertical][kImageTypeOnBlack] = - rb.GetImageNamed( - IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_ONBLACK).ToImageSkia(); - - leading_images_[kImageVertical][kImageTypePressed] = - rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP_PRESSED).ToImageSkia(); - middle_images_[kImageVertical][kImageTypePressed] = - rb.GetImageNamed( - IDR_AURA_TRAY_BG_VERTICAL_CENTER_PRESSED).ToImageSkia(); - trailing_images_[kImageVertical][kImageTypePressed] = - rb.GetImageNamed( - IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_PRESSED).ToImageSkia(); - } - - virtual ~TrayBackground() {} - - SkColor color() { return color_; } - void set_color(SkColor color) { color_ = color; } - void set_alpha(int alpha) { color_ = SkColorSetARGB(alpha, 0, 0, 0); } - - private: - ShelfWidget* GetShelfWidget() const { - return RootWindowController::ForWindow(tray_background_view_-> - status_area_widget()->GetNativeWindow())->shelf(); - } - - void PaintForAlternateShelf(gfx::Canvas* canvas, views::View* view) const { - int orientation = kImageHorizontal; - ShelfWidget* shelf_widget = GetShelfWidget(); - if (shelf_widget && - !shelf_widget->shelf_layout_manager()->IsHorizontalAlignment()) - orientation = kImageVertical; - - int state = kImageTypeDefault; - if (tray_background_view_->draw_background_as_active()) - state = kImageTypePressed; - else if (shelf_widget && shelf_widget->GetDimsShelf()) - state = kImageTypeOnBlack; - else - state = kImageTypeDefault; - - const gfx::ImageSkia* leading = leading_images_[orientation][state]; - const gfx::ImageSkia* middle = middle_images_[orientation][state]; - const gfx::ImageSkia* trailing = trailing_images_[orientation][state]; - - gfx::Rect bounds(view->GetLocalBounds()); - gfx::Point leading_location, trailing_location; - gfx::Rect middle_bounds; - - if (orientation == kImageHorizontal) { - leading_location = gfx::Point(0, 0); - trailing_location = gfx::Point(bounds.width() - trailing->width(), 0); - middle_bounds = gfx::Rect( - leading->width(), - 0, - bounds.width() - (leading->width() + trailing->width()), - bounds.height()); - } else { - leading_location = gfx::Point(0, 0); - trailing_location = gfx::Point(0, bounds.height() - trailing->height()); - middle_bounds = gfx::Rect( - 0, - leading->height(), - bounds.width(), - bounds.height() - (leading->height() + trailing->height())); - } - - canvas->DrawImageInt(*leading, - leading_location.x(), - leading_location.y()); - - canvas->DrawImageInt(*trailing, - trailing_location.x(), - trailing_location.y()); - - canvas->TileImageInt(*middle, - middle_bounds.x(), - middle_bounds.y(), - middle_bounds.width(), - middle_bounds.height()); - } - - // Overridden from views::Background. - virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { - if (ash::switches::UseAlternateShelfLayout()) { - PaintForAlternateShelf(canvas, view); - } else { - SkPaint paint; - paint.setAntiAlias(true); - paint.setStyle(SkPaint::kFill_Style); - paint.setColor(color_); - SkPath path; - gfx::Rect bounds(view->GetLocalBounds()); - SkScalar radius = SkIntToScalar(kTrayRoundedBorderRadius); - path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); - canvas->DrawPath(path, paint); - } - } - - SkColor color_; - // Reference to the TrayBackgroundView for which this is a background. - TrayBackgroundView* tray_background_view_; - - // References to the images used as backgrounds, they are owned by the - // resource bundle class. - const gfx::ImageSkia* leading_images_[kNumOrientations][kNumStates]; - const gfx::ImageSkia* middle_images_[kNumOrientations][kNumStates]; - const gfx::ImageSkia* trailing_images_[kNumOrientations][kNumStates]; - - DISALLOW_COPY_AND_ASSIGN(TrayBackground); -}; - -TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment) - : alignment_(alignment) { - UpdateLayout(); -} - -void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) { - if (alignment_ == alignment) - return; - alignment_ = alignment; - UpdateLayout(); -} - -gfx::Size TrayBackgroundView::TrayContainer::GetPreferredSize() { - if (size_.IsEmpty()) - return views::View::GetPreferredSize(); - return size_; -} - -void TrayBackgroundView::TrayContainer::ChildPreferredSizeChanged( - views::View* child) { - PreferredSizeChanged(); -} - -void TrayBackgroundView::TrayContainer::ChildVisibilityChanged(View* child) { - PreferredSizeChanged(); -} - -void TrayBackgroundView::TrayContainer::ViewHierarchyChanged( - const ViewHierarchyChangedDetails& details) { - if (details.parent == this) - PreferredSizeChanged(); -} - -void TrayBackgroundView::TrayContainer::UpdateLayout() { - // Adjust the size of status tray dark background by adding additional - // empty border. - if (alignment_ == SHELF_ALIGNMENT_BOTTOM || - alignment_ == SHELF_ALIGNMENT_TOP) { - int vertical_padding = kTrayContainerVerticalPaddingBottomAlignment; - int horizontal_padding = kTrayContainerHorizontalPaddingBottomAlignment; - if (ash::switches::UseAlternateShelfLayout()) { - vertical_padding = kPaddingFromEdgeOfShelf; - horizontal_padding = kPaddingFromEdgeOfShelf; - } - set_border(views::Border::CreateEmptyBorder( - vertical_padding, - horizontal_padding, - vertical_padding, - horizontal_padding)); - - views::BoxLayout* layout = - new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); - layout->set_spread_blank_space(true); - views::View::SetLayoutManager(layout); - } else { - int vertical_padding = kTrayContainerVerticalPaddingVerticalAlignment; - int horizontal_padding = kTrayContainerHorizontalPaddingVerticalAlignment; - if (ash::switches::UseAlternateShelfLayout()) { - vertical_padding = kPaddingFromEdgeOfShelf; - horizontal_padding = kPaddingFromEdgeOfShelf; - } - set_border(views::Border::CreateEmptyBorder( - vertical_padding, - horizontal_padding, - vertical_padding, - horizontal_padding)); - - views::BoxLayout* layout = - new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); - layout->set_spread_blank_space(true); - views::View::SetLayoutManager(layout); - } - PreferredSizeChanged(); -} - -//////////////////////////////////////////////////////////////////////////////// -// TrayBackgroundView - -TrayBackgroundView::TrayBackgroundView( - internal::StatusAreaWidget* status_area_widget) - : status_area_widget_(status_area_widget), - tray_container_(NULL), - shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), - background_(NULL), - hide_background_animator_(this, 0, kTrayBackgroundAlpha), - hover_background_animator_( - this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha), - hovered_(false), - draw_background_as_active_(false), - widget_observer_(new TrayWidgetObserver(this)) { - set_notify_enter_exit_on_child(true); - - // Initially we want to paint the background, but without the hover effect. - hide_background_animator_.SetPaintsBackground( - true, BACKGROUND_CHANGE_IMMEDIATE); - hover_background_animator_.SetPaintsBackground( - false, BACKGROUND_CHANGE_IMMEDIATE); - - tray_container_ = new TrayContainer(shelf_alignment_); - SetContents(tray_container_); - tray_event_filter_.reset(new TrayEventFilter); -} - -TrayBackgroundView::~TrayBackgroundView() { - if (GetWidget()) - GetWidget()->RemoveObserver(widget_observer_.get()); -} - -void TrayBackgroundView::Initialize() { - GetWidget()->AddObserver(widget_observer_.get()); - SetBorder(); -} - -const char* TrayBackgroundView::GetClassName() const { - return kViewClassName; -} - -void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { - hovered_ = true; - if (!background_ || draw_background_as_active_ || - ash::switches::UseAlternateShelfLayout()) - return; - hover_background_animator_.SetPaintsBackground( - true, BACKGROUND_CHANGE_ANIMATE); -} - -void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { - hovered_ = false; - if (!background_ || draw_background_as_active_ || - ash::switches::UseAlternateShelfLayout()) - return; - hover_background_animator_.SetPaintsBackground( - false, BACKGROUND_CHANGE_ANIMATE); -} - -void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { - PreferredSizeChanged(); -} - -void TrayBackgroundView::GetAccessibleState(ui::AccessibleViewState* state) { - state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; - state->name = GetAccessibleNameForTray(); -} - -void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { - // Return focus to the login view. See crbug.com/120500. - views::View* v = GetNextFocusableView(); - if (v) - v->AboutToRequestFocusFromTabTraversal(reverse); -} - -bool TrayBackgroundView::PerformAction(const ui::Event& event) { - return false; -} - -gfx::Rect TrayBackgroundView::GetFocusBounds() { - // The tray itself expands to the right and bottom edge of the screen to make - // sure clicking on the edges brings up the popup. However, the focus border - // should be only around the container. - return GetContentsBounds(); -} - -void TrayBackgroundView::UpdateBackground(int alpha) { - // The animator should never fire when the alternate shelf layout is used. - if (!background_ || draw_background_as_active_) - return; - DCHECK(!ash::switches::UseAlternateShelfLayout()); - background_->set_alpha(hide_background_animator_.alpha() + - hover_background_animator_.alpha()); - SchedulePaint(); -} - -void TrayBackgroundView::SetContents(views::View* contents) { - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); - AddChildView(contents); -} - -void TrayBackgroundView::SetPaintsBackground( - bool value, BackgroundAnimatorChangeType change_type) { - DCHECK(!ash::switches::UseAlternateShelfLayout()); - hide_background_animator_.SetPaintsBackground(value, change_type); -} - -void TrayBackgroundView::SetContentsBackground() { - background_ = new internal::TrayBackground(this); - tray_container_->set_background(background_); -} - -ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() { - return ShelfLayoutManager::ForLauncher(GetWidget()->GetNativeView()); -} - -void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { - shelf_alignment_ = alignment; - SetBorder(); - tray_container_->SetAlignment(alignment); -} - -void TrayBackgroundView::SetBorder() { - views::View* parent = status_area_widget_->status_area_widget_delegate(); - // Tray views are laid out right-to-left or bottom-to-top - bool on_edge = (this == parent->child_at(0)); - int left_edge, top_edge, right_edge, bottom_edge; - if (ash::switches::UseAlternateShelfLayout()) { - if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { - top_edge = ShelfLayoutManager::kShelfItemInset; - left_edge = 0; - bottom_edge = ShelfLayoutManager::GetPreferredShelfSize() - - ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight(); - right_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; - } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { - top_edge = 0; - left_edge = ShelfLayoutManager::GetPreferredShelfSize() - - ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight(); - bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; - right_edge = ShelfLayoutManager::kShelfItemInset; - } else { // SHELF_ALIGNMENT_RIGHT - top_edge = 0; - left_edge = ShelfLayoutManager::kShelfItemInset; - bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; - right_edge = ShelfLayoutManager::GetPreferredShelfSize() - - ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight(); - } - } else { - // Change the border padding for different shelf alignment. - if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { - top_edge = 0; - left_edge = 0; - bottom_edge = on_edge ? kPaddingFromBottomOfScreenBottomAlignment : - kPaddingFromBottomOfScreenBottomAlignment - 1; - right_edge = on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0; - } else if (shelf_alignment() == SHELF_ALIGNMENT_TOP) { - top_edge = on_edge ? kPaddingFromBottomOfScreenBottomAlignment : - kPaddingFromBottomOfScreenBottomAlignment - 1; - left_edge = 0; - bottom_edge = 0; - right_edge = on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0; - } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { - top_edge = 0; - left_edge = kPaddingFromOuterEdgeOfLauncherVerticalAlignment; - bottom_edge = on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0; - right_edge = kPaddingFromInnerEdgeOfLauncherVerticalAlignment; - } else { - top_edge = 0; - left_edge = kPaddingFromInnerEdgeOfLauncherVerticalAlignment; - bottom_edge = on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0; - right_edge = kPaddingFromOuterEdgeOfLauncherVerticalAlignment; - } - } - set_border(views::Border::CreateEmptyBorder( - top_edge, left_edge, bottom_edge, right_edge)); -} - -void TrayBackgroundView::InitializeBubbleAnimations( - views::Widget* bubble_widget) { - views::corewm::SetWindowVisibilityAnimationType( - bubble_widget->GetNativeWindow(), - views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); - views::corewm::SetWindowVisibilityAnimationTransition( - bubble_widget->GetNativeWindow(), - views::corewm::ANIMATE_HIDE); - views::corewm::SetWindowVisibilityAnimationDuration( - bubble_widget->GetNativeWindow(), - base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS)); -} - -aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { - return ash::Shell::GetContainer( - tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), - ash::internal::kShellWindowId_SettingBubbleContainer); -} - -gfx::Rect TrayBackgroundView::GetBubbleAnchorRect( - views::Widget* anchor_widget, - TrayBubbleView::AnchorType anchor_type, - TrayBubbleView::AnchorAlignment anchor_alignment) const { - gfx::Rect rect; - if (anchor_widget && anchor_widget->IsVisible()) { - rect = anchor_widget->GetWindowBoundsInScreen(); - if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) { - if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { - bool rtl = base::i18n::IsRTL(); - if (!ash::switches::UseAlternateShelfLayout()) { - rect.Inset( - rtl ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0, - kTrayBubbleAnchorTopInsetBottomAnchor, - rtl ? 0 : kPaddingFromRightEdgeOfScreenBottomAlignment, - kPaddingFromBottomOfScreenBottomAlignment); - } else { - rect.Inset( - rtl ? kAlternateLayoutBubblePaddingHorizontalSide : 0, - kAlternateLayoutBubblePaddingHorizontalBottom, - rtl ? 0 : kAlternateLayoutBubblePaddingHorizontalSide, - 0); - } - } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { - if (!ash::switches::UseAlternateShelfLayout()) { - rect.Inset(0, 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 5, - kPaddingFromBottomOfScreenVerticalAlignment); - } else { - rect.Inset(0, 0, kAlternateLayoutBubblePaddingVerticalSide + 4, - kAlternateLayoutBubblePaddingVerticalBottom); - } - } else { - if (!ash::switches::UseAlternateShelfLayout()) { - rect.Inset(kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 1, - 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); - } else { - rect.Inset(kAlternateLayoutBubblePaddingVerticalSide, 0, 0, - kAlternateLayoutBubblePaddingVerticalBottom); - } - } - } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) { - // Invert the offsets to align with the bubble below. - // Note that with the alternate shelf layout the tips are not shown and - // the offsets for left and right alignment do not need to be applied. - int vertical_alignment = ash::switches::UseAlternateShelfLayout() ? - 0 : - kPaddingFromInnerEdgeOfLauncherVerticalAlignment; - int horizontal_alignment = ash::switches::UseAlternateShelfLayout() ? - kAlternateLayoutBubblePaddingVerticalBottom : - kPaddingFromBottomOfScreenVerticalAlignment; - if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) - rect.Inset(vertical_alignment, 0, 0, horizontal_alignment); - else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) - rect.Inset(0, 0, vertical_alignment, horizontal_alignment); - } - } - - // TODO(jennyz): May need to add left/right alignment in the following code. - if (rect.IsEmpty()) { - aura::Window* target_root = anchor_widget ? - anchor_widget->GetNativeView()->GetRootWindow() : - Shell::GetPrimaryRootWindow(); - rect = target_root->bounds(); - rect = gfx::Rect( - base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreenBottomAlignment : - rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, - rect.height() - kPaddingFromBottomOfScreenBottomAlignment, - 0, 0); - rect = ScreenAsh::ConvertRectToScreen(target_root, rect); - } - return rect; -} - -TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const { - switch (shelf_alignment_) { - case SHELF_ALIGNMENT_BOTTOM: - return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; - case SHELF_ALIGNMENT_LEFT: - return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT; - case SHELF_ALIGNMENT_RIGHT: - return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; - case SHELF_ALIGNMENT_TOP: - return TrayBubbleView::ANCHOR_ALIGNMENT_TOP; - } - NOTREACHED(); - return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; -} - -void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) { - draw_background_as_active_ = visible; - if (!background_ || !switches::UseAlternateShelfLayout()) - return; - - // Do not change gradually, changing color between grey and blue is weird. - if (draw_background_as_active_) - background_->set_color(kTrayBackgroundPressedColor); - else if (hovered_) - background_->set_alpha(kTrayBackgroundHoverAlpha); - else - background_->set_alpha(kTrayBackgroundAlpha); - SchedulePaint(); -} - -void TrayBackgroundView::UpdateBubbleViewArrow( - views::TrayBubbleView* bubble_view) { - if (switches::UseAlternateShelfLayout()) - return; - - aura::Window* root_window = - bubble_view->GetWidget()->GetNativeView()->GetRootWindow(); - ash::internal::ShelfLayoutManager* shelf = - ShelfLayoutManager::ForLauncher(root_window); - bubble_view->SetArrowPaintType( - (shelf && shelf->IsVisible()) ? - views::BubbleBorder::PAINT_NORMAL : - views::BubbleBorder::PAINT_TRANSPARENT); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_background_view.h b/chromium/ash/system/tray/tray_background_view.h deleted file mode 100644 index 5adaf4ec0c7..00000000000 --- a/chromium/ash/system/tray/tray_background_view.h +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ -#define ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ - -#include "ash/ash_export.h" -#include "ash/shelf/background_animator.h" -#include "ash/shelf/shelf_types.h" -#include "ash/system/tray/actionable_view.h" -#include "ui/views/bubble/tray_bubble_view.h" - -namespace ash { -namespace internal { - -class ShelfLayoutManager; -class StatusAreaWidget; -class TrayEventFilter; -class TrayBackground; - -// Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray, -// LogoutButtonTray. -// This class handles setting and animating the background when the Launcher -// his shown/hidden. It also inherits from ActionableView so that the tray -// items can override PerformAction when clicked on. -class ASH_EXPORT TrayBackgroundView : public ActionableView, - public BackgroundAnimatorDelegate { - public: - static const char kViewClassName[]; - - // Base class for tray containers. Sets the border and layout. The container - // auto-resizes the widget when necessary. - class TrayContainer : public views::View { - public: - explicit TrayContainer(ShelfAlignment alignment); - virtual ~TrayContainer() {} - - void SetAlignment(ShelfAlignment alignment); - - void set_size(const gfx::Size& size) { size_ = size; } - - // Overridden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE; - - protected: - // Overridden from views::View. - virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; - virtual void ChildVisibilityChanged(View* child) OVERRIDE; - virtual void ViewHierarchyChanged( - const ViewHierarchyChangedDetails& details) OVERRIDE; - - private: - void UpdateLayout(); - - ShelfAlignment alignment_; - gfx::Size size_; - - DISALLOW_COPY_AND_ASSIGN(TrayContainer); - }; - - explicit TrayBackgroundView(internal::StatusAreaWidget* status_area_widget); - virtual ~TrayBackgroundView(); - - // Called after the tray has been added to the widget containing it. - virtual void Initialize(); - - // Overridden from views::View. - virtual const char* GetClassName() const OVERRIDE; - virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; - virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; - virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; - virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; - virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE; - - // Overridden from internal::ActionableView. - virtual bool PerformAction(const ui::Event& event) OVERRIDE; - virtual gfx::Rect GetFocusBounds() OVERRIDE; - - // Overridden from internal::BackgroundAnimatorDelegate. - virtual void UpdateBackground(int alpha) OVERRIDE; - - // Called whenever the shelf alignment changes. - virtual void SetShelfAlignment(ShelfAlignment alignment); - - // Called when the anchor (tray or bubble) may have moved or changed. - virtual void AnchorUpdated() {} - - // Called from GetAccessibleState, must return a valid accessible name. - virtual base::string16 GetAccessibleNameForTray() = 0; - - // Called when the bubble is resized. - virtual void BubbleResized(const views::TrayBubbleView* bubble_view) {} - - // Hides the bubble associated with |bubble_view|. Called when the widget - // is closed. - virtual void HideBubbleWithView(const views::TrayBubbleView* bubble_view) = 0; - - // Called by the bubble wrapper when a click event occurs outside the bubble. - // May close the bubble. Returns true if the event is handled. - virtual bool ClickedOutsideBubble() = 0; - - // Sets |contents| as a child. - void SetContents(views::View* contents); - - // Creates and sets contents background to |background_|. - void SetContentsBackground(); - - // Sets whether the tray paints a background. Default is true, but is set to - // false if a window overlaps the shelf. - void SetPaintsBackground(bool value, - BackgroundAnimatorChangeType change_type); - - // Initializes animations for the bubble. - void InitializeBubbleAnimations(views::Widget* bubble_widget); - - // Returns the window hosting the bubble. - aura::Window* GetBubbleWindowContainer() const; - - // Returns the anchor rect for the bubble. - gfx::Rect GetBubbleAnchorRect( - views::Widget* anchor_widget, - views::TrayBubbleView::AnchorType anchor_type, - views::TrayBubbleView::AnchorAlignment anchor_alignment) const; - - // Returns the bubble anchor alignment based on |shelf_alignment_|. - views::TrayBubbleView::AnchorAlignment GetAnchorAlignment() const; - - // Forces the background to be drawn active if set to true. - void SetDrawBackgroundAsActive(bool visible); - - // Returns true when the the background was overridden to be drawn as active. - bool draw_background_as_active() const {return draw_background_as_active_; } - - StatusAreaWidget* status_area_widget() { - return status_area_widget_; - } - const StatusAreaWidget* status_area_widget() const { - return status_area_widget_; - } - TrayContainer* tray_container() const { return tray_container_; } - ShelfAlignment shelf_alignment() const { return shelf_alignment_; } - TrayEventFilter* tray_event_filter() { return tray_event_filter_.get(); } - - ShelfLayoutManager* GetShelfLayoutManager(); - - // Updates the arrow visibility based on the launcher visibility. - void UpdateBubbleViewArrow(views::TrayBubbleView* bubble_view); - - private: - class TrayWidgetObserver; - - // Called from Initialize after all status area trays have been created. - // Sets the border based on the position of the view. - void SetBorder(); - - // Unowned pointer to parent widget. - StatusAreaWidget* status_area_widget_; - - // Convenience pointer to the contents view. - TrayContainer* tray_container_; - - // Shelf alignment. - ShelfAlignment shelf_alignment_; - - // Owned by the view passed to SetContents(). - internal::TrayBackground* background_; - - // Animators for the background. They are only used for the old shelf layout. - internal::BackgroundAnimator hide_background_animator_; - internal::BackgroundAnimator hover_background_animator_; - - // True if the background gets hovered. - bool hovered_; - - // This variable stores the activation override which will tint the background - // differently if set to true. - bool draw_background_as_active_; - - scoped_ptr<TrayWidgetObserver> widget_observer_; - scoped_ptr<TrayEventFilter> tray_event_filter_; - - DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_BACKGROUND_VIEW_H_ diff --git a/chromium/ash/system/tray/tray_bar_button_with_title.cc b/chromium/ash/system/tray/tray_bar_button_with_title.cc deleted file mode 100644 index 0fd94d84892..00000000000 --- a/chromium/ash/system/tray/tray_bar_button_with_title.cc +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_bar_button_with_title.h" - -#include "ash/system/tray/tray_constants.h" -#include "base/memory/scoped_ptr.h" -#include "grit/ui_resources.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image_skia.h" -#include "ui/views/controls/label.h" -#include "ui/views/painter.h" - -namespace ash { -namespace internal { - -namespace { - -const int kBarImagesActive[] = { - IDR_SLIDER_ACTIVE_LEFT, - IDR_SLIDER_ACTIVE_CENTER, - IDR_SLIDER_ACTIVE_RIGHT, -}; - -const int kBarImagesDisabled[] = { - IDR_SLIDER_DISABLED_LEFT, - IDR_SLIDER_DISABLED_CENTER, - IDR_SLIDER_DISABLED_RIGHT, -}; - -} // namespace - -class TrayBarButtonWithTitle::TrayBarButton : public views::View { - public: - TrayBarButton(const int bar_active_images[], const int bar_disabled_images[]) - : views::View(), - bar_active_images_(bar_active_images), - bar_disabled_images_(bar_disabled_images), - painter_(new views::HorizontalPainter(bar_active_images_)){ - } - virtual ~TrayBarButton() {} - - // Overriden from views::View: - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { - painter_->Paint(canvas, size()); - } - - void Update(bool control_on) { - painter_.reset(new views::HorizontalPainter( - control_on ? bar_active_images_ : bar_disabled_images_)); - SchedulePaint(); - } - - private: - const int* bar_active_images_; - const int* bar_disabled_images_; - scoped_ptr<views::HorizontalPainter> painter_; - - DISALLOW_COPY_AND_ASSIGN(TrayBarButton); -}; - -TrayBarButtonWithTitle::TrayBarButtonWithTitle(views::ButtonListener* listener, - int title_id, - int width) - : views::CustomButton(listener), - image_(new TrayBarButton(kBarImagesActive, kBarImagesDisabled)), - title_(NULL), - width_(width) { - AddChildView(image_); - if (title_id != -1) { - title_ = new views::Label; - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - base::string16 text = rb.GetLocalizedString(title_id); - title_->SetText(text); - AddChildView(title_); - } - - image_height_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed( - kBarImagesActive[0]).ToImageSkia()->height(); -} - -TrayBarButtonWithTitle::~TrayBarButtonWithTitle() {} - -void TrayBarButtonWithTitle::UpdateButton(bool control_on) { - image_->Update(control_on); -} - -gfx::Size TrayBarButtonWithTitle::GetPreferredSize() { - return gfx::Size(width_, kTrayPopupItemHeight); -} - -void TrayBarButtonWithTitle::Layout() { - gfx::Rect rect(GetContentsBounds()); - int bar_image_y = rect.height() / 2 - image_height_ / 2; - gfx::Rect bar_image_rect(rect.x(), - bar_image_y, - rect.width(), - image_height_); - image_->SetBoundsRect(bar_image_rect); - if (title_) { - // The image_ has some empty space below the bar image, move the title - // a little bit up to look closer to the bar. - gfx::Size title_size = title_->GetPreferredSize(); - title_->SetBounds(rect.x(), - bar_image_y + image_height_ - 3, - rect.width(), - title_size.height()); - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_bar_button_with_title.h b/chromium/ash/system/tray/tray_bar_button_with_title.h deleted file mode 100644 index 8b63d4f8fa7..00000000000 --- a/chromium/ash/system/tray/tray_bar_button_with_title.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_BAR_BUTTON_WITH_TITLE_H_ -#define ASH_SYSTEM_TRAY_TRAY_BAR_BUTTON_WITH_TITLE_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/views/controls/button/custom_button.h" - -namespace views { -class Label; -} - -namespace ash { -namespace internal { - -// A button with a bar image and title text below the bar image. These buttons -// will be used in audio and brightness control UI, which can be toggled with -// on/off states. -class TrayBarButtonWithTitle : public views::CustomButton { - public: - TrayBarButtonWithTitle(views::ButtonListener* listener, - int title_id, - int width); - virtual ~TrayBarButtonWithTitle(); - - void UpdateButton(bool control_on); - - private: - class TrayBarButton; - - // Overridden from views::CustomButton: - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual void Layout() OVERRIDE; - - TrayBarButton* image_; - views::Label* title_; - int width_; - int image_height_; - - DISALLOW_COPY_AND_ASSIGN(TrayBarButtonWithTitle); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_BAR_BUTTON_WITH_TITLE_H_ diff --git a/chromium/ash/system/tray/tray_bubble_wrapper.cc b/chromium/ash/system/tray/tray_bubble_wrapper.cc deleted file mode 100644 index 2bcb07bb3de..00000000000 --- a/chromium/ash/system/tray/tray_bubble_wrapper.cc +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_bubble_wrapper.h" - -#include "ash/system/tray/tray_background_view.h" -#include "ash/system/tray/tray_event_filter.h" -#include "ash/wm/window_properties.h" -#include "ui/aura/client/capture_client.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/views/bubble/tray_bubble_view.h" -#include "ui/views/widget/widget.h" - -namespace ash { -namespace internal { - -TrayBubbleWrapper::TrayBubbleWrapper(TrayBackgroundView* tray, - views::TrayBubbleView* bubble_view) - : tray_(tray), - bubble_view_(bubble_view) { - bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); - bubble_widget_->AddObserver(this); - - tray_->InitializeBubbleAnimations(bubble_widget_); - tray_->UpdateBubbleViewArrow(bubble_view_); - bubble_view_->InitializeAndShowBubble(); - - tray->tray_event_filter()->AddWrapper(this); -} - -TrayBubbleWrapper::~TrayBubbleWrapper() { - tray_->tray_event_filter()->RemoveWrapper(this); - if (bubble_widget_) { - bubble_widget_->RemoveObserver(this); - bubble_widget_->Close(); - } -} - -void TrayBubbleWrapper::OnWidgetDestroying(views::Widget* widget) { - CHECK_EQ(bubble_widget_, widget); - bubble_widget_->RemoveObserver(this); - bubble_widget_ = NULL; - - // Although the bubble is already closed, the next mouse release event - // will invoke PerformAction which reopens the bubble again. To prevent the - // reopen, the mouse capture of |tray_| has to be released. - // See crbug.com/177075 - aura::client::CaptureClient* capture_client = aura::client::GetCaptureClient( - tray_->GetWidget()->GetNativeView()->GetRootWindow()); - if (capture_client) - capture_client->ReleaseCapture(tray_->GetWidget()->GetNativeView()); - tray_->HideBubbleWithView(bubble_view_); // May destroy |bubble_view_| -} - -void TrayBubbleWrapper::OnWidgetBoundsChanged(views::Widget* widget, - const gfx::Rect& new_bounds) { - DCHECK_EQ(bubble_widget_, widget); - tray_->BubbleResized(bubble_view_); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_bubble_wrapper.h b/chromium/ash/system/tray/tray_bubble_wrapper.h deleted file mode 100644 index 9ce443a8b30..00000000000 --- a/chromium/ash/system/tray/tray_bubble_wrapper.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_BUBBLE_WRAPPER_H_ -#define ASH_SYSTEM_TRAY_TRAY_BUBBLE_WRAPPER_H_ - -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "ui/views/widget/widget_observer.h" - -namespace views { -class TrayBubbleView; -} - -namespace ash { -namespace internal { - -class TrayBackgroundView; -class TrayEventFilter; - -// Creates and manages the Widget and EventFilter components of a bubble. - -class TrayBubbleWrapper : public views::WidgetObserver { - public: - TrayBubbleWrapper(TrayBackgroundView* tray, - views::TrayBubbleView* bubble_view); - virtual ~TrayBubbleWrapper(); - - // views::WidgetObserver overrides: - virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; - virtual void OnWidgetBoundsChanged(views::Widget* widget, - const gfx::Rect& new_bounds) OVERRIDE; - - const TrayBackgroundView* tray() const { return tray_; } - TrayBackgroundView* tray() { return tray_; } - const views::TrayBubbleView* bubble_view() const { return bubble_view_; } - const views::Widget* bubble_widget() const { return bubble_widget_; } - - private: - TrayBackgroundView* tray_; - views::TrayBubbleView* bubble_view_; // unowned - views::Widget* bubble_widget_; - - DISALLOW_COPY_AND_ASSIGN(TrayBubbleWrapper); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_WRAPPER_H_ diff --git a/chromium/ash/system/tray/tray_constants.cc b/chromium/ash/system/tray/tray_constants.cc deleted file mode 100644 index db769ef6678..00000000000 --- a/chromium/ash/system/tray/tray_constants.cc +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_constants.h" - -#include "ash/ash_switches.h" -#include "third_party/skia/include/core/SkColor.h" - -namespace ash { - -const int kPaddingFromRightEdgeOfScreenBottomAlignment = 7; -const int kPaddingFromBottomOfScreenBottomAlignment = 7; -const int kPaddingFromOuterEdgeOfLauncherVerticalAlignment = 8; -const int kPaddingFromInnerEdgeOfLauncherVerticalAlignment = 9; -const int kPaddingFromBottomOfScreenVerticalAlignment = 10; - -// Padding used to position the system menu relative to the status area. -const int kAlternateLayoutBubblePaddingHorizontalBottom = 6; -const int kAlternateLayoutBubblePaddingHorizontalSide = 10; -const int kAlternateLayoutBubblePaddingVerticalBottom = 3; -const int kAlternateLayoutBubblePaddingVerticalSide = 15; - -const int kPaddingFromEdgeOfShelf = 3; - -// Top inset of system tray bubble for bottom anchor alignment. -const int kTrayBubbleAnchorTopInsetBottomAnchor = 3; - -const int kTrayImageItemHorizontalPaddingBottomAlignment = 1; -const int kTrayImageItemHorizontalPaddingVerticalAlignment = 1; -const int kTrayImageItemVerticalPaddingVerticalAlignment = 1; - -const int kTrayLabelItemHorizontalPaddingBottomAlignment = 7; - -// Vertical padding between status tray items when the shelf is vertical. -const int kTrayLabelItemVerticalPaddingVerticalAlignment = 4; - -const int kTrayMenuBottomRowPadding = 5; -const int kTrayMenuBottomRowPaddingBetweenItems = -1; - -const int kTrayPopupAutoCloseDelayInSeconds = 2; -const int kTrayPopupAutoCloseDelayForTextInSeconds = 5; -const int kTrayPopupPaddingHorizontal = 18; -const int kTrayPopupPaddingBetweenItems = 10; -const int kTrayPopupTextSpacingVertical = 4; - -const int kTrayPopupItemHeight = 48; -const int kTrayPopupDetailsIconWidth = 25; -const int kTrayPopupDetailsLabelExtraLeftMargin = 8; -const int kTrayPopupScrollSeparatorHeight = 15; -const int kTrayRoundedBorderRadius = 2; -const int kTrayBarButtonWidth = 39; - -const SkColor kBackgroundColor = SkColorSetRGB(0xfe, 0xfe, 0xfe); -const SkColor kHoverBackgroundColor = SkColorSetRGB(0xf3, 0xf3, 0xf3); -const SkColor kPublicAccountBackgroundColor = SkColorSetRGB(0xf8, 0xe5, 0xb6); -const SkColor kPublicAccountUserCardTextColor = SkColorSetRGB(0x66, 0x66, 0x66); -const SkColor kPublicAccountUserCardNameColor = SK_ColorBLACK; - -const SkColor kHeaderBackgroundColor = SkColorSetRGB(0xf5, 0xf5, 0xf5); - -const SkColor kBorderDarkColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); -const SkColor kBorderLightColor = SkColorSetRGB(0xeb, 0xeb, 0xeb); -const SkColor kButtonStrokeColor = SkColorSetRGB(0xdd, 0xdd, 0xdd); - -const SkColor kHeaderTextColorNormal = SkColorSetARGB(0x7f, 0, 0, 0); -const SkColor kHeaderTextColorHover = SkColorSetARGB(0xd3, 0, 0, 0); - -const int kTrayPopupMinWidth = 300; -const int kTrayPopupMaxWidth = 500; -const int kNotificationIconWidth = 40; -const int kNotificationButtonWidth = 32; -const int kTrayNotificationContentsWidth = kTrayPopupMinWidth - - (kNotificationIconWidth + kNotificationButtonWidth + - (kTrayPopupPaddingHorizontal / 2) * 3); -const int kTraySpacing = 8; -const int kAlternateTraySpacing = 4; -const int kShelfItemHeight = 31; -const int kAlternateShelfItemHeight = 38; - -int GetTraySpacing() { - return ash::switches::UseAlternateShelfLayout() ? - kAlternateTraySpacing : kTraySpacing; -} - -int GetShelfItemHeight() { - return ash::switches::UseAlternateShelfLayout() ? - kAlternateShelfItemHeight : kShelfItemHeight; -} - -} // namespace ash diff --git a/chromium/ash/system/tray/tray_constants.h b/chromium/ash/system/tray/tray_constants.h deleted file mode 100644 index d5187f38fa5..00000000000 --- a/chromium/ash/system/tray/tray_constants.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_CONSTANTS_H_ -#define ASH_SYSTEM_TRAY_TRAY_CONSTANTS_H_ - -typedef unsigned int SkColor; - -namespace ash { - -extern const int kPaddingFromRightEdgeOfScreenBottomAlignment; -extern const int kPaddingFromBottomOfScreenBottomAlignment; -extern const int kPaddingFromOuterEdgeOfLauncherVerticalAlignment; -extern const int kPaddingFromInnerEdgeOfLauncherVerticalAlignment; -extern const int kPaddingFromBottomOfScreenVerticalAlignment; - -extern const int kAlternateLayoutBubblePaddingHorizontalBottom; -extern const int kAlternateLayoutBubblePaddingHorizontalSide; -extern const int kAlternateLayoutBubblePaddingVerticalBottom; -extern const int kAlternateLayoutBubblePaddingVerticalSide; - -extern const int kPaddingFromEdgeOfShelf; -extern const int kTrayBubbleAnchorTopInsetBottomAnchor; - -extern const int kTrayImageItemHorizontalPaddingBottomAlignment; -extern const int kTrayImageItemHorizontalPaddingVerticalAlignment; -extern const int kTrayImageItemVerticalPaddingVerticalAlignment; - -extern const int kTrayLabelItemHorizontalPaddingBottomAlignment; -extern const int kTrayLabelItemVerticalPaddingVerticalAlignment; - -extern const int kTrayMenuBottomRowPadding; -extern const int kTrayMenuBottomRowPaddingBetweenItems; - -extern const int kTrayPopupAutoCloseDelayInSeconds; -extern const int kTrayPopupAutoCloseDelayForTextInSeconds; -extern const int kTrayPopupPaddingHorizontal; -extern const int kTrayPopupPaddingBetweenItems; -extern const int kTrayPopupTextSpacingVertical; - -extern const int kTrayPopupItemHeight; -extern const int kTrayPopupDetailsIconWidth; -extern const int kTrayPopupDetailsLabelExtraLeftMargin; -extern const int kTrayPopupScrollSeparatorHeight; -extern const int kTrayRoundedBorderRadius; -extern const int kTrayBarButtonWidth; - -extern const SkColor kBackgroundColor; -extern const SkColor kHoverBackgroundColor; -extern const SkColor kPublicAccountBackgroundColor; -extern const SkColor kPublicAccountUserCardTextColor; -extern const SkColor kPublicAccountUserCardNameColor; - -extern const SkColor kHeaderBackgroundColor; - -extern const SkColor kBorderDarkColor; -extern const SkColor kBorderLightColor; -extern const SkColor kButtonStrokeColor; - -extern const SkColor kHeaderTextColorNormal; -extern const SkColor kHeaderTextColorHover; - -extern const int kTrayPopupMinWidth; -extern const int kTrayPopupMaxWidth; -extern const int kNotificationIconWidth; -extern const int kNotificationButtonWidth; -extern const int kTrayNotificationContentsWidth; - -// Returns kTraySpacing or kAlternateTraySpacing as applicable -// (Determined by ash::switches::UseAlternateShelfLayout). -int GetTraySpacing(); - -// Returns kShelfItemHeight or kAlternateShelfItemHeight as applicable -// (Determined by ash::switches::UseAlternateShelfLayout). -int GetShelfItemHeight(); - -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_CONSTANTS_H_ diff --git a/chromium/ash/system/tray/tray_details_view.cc b/chromium/ash/system/tray/tray_details_view.cc deleted file mode 100644 index 72efe4ffe0b..00000000000 --- a/chromium/ash/system/tray/tray_details_view.cc +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_details_view.h" - -#include "ash/system/tray/fixed_sized_scroll_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_item.h" -#include "ash/system/tray/tray_constants.h" -#include "ui/gfx/canvas.h" -#include "ui/views/background.h" -#include "ui/views/border.h" -#include "ui/views/controls/scroll_view.h" -#include "ui/views/layout/box_layout.h" - -namespace ash { -namespace internal { - -class ScrollSeparator : public views::View { - public: - ScrollSeparator() {} - - virtual ~ScrollSeparator() {} - - private: - // Overriden from views::View. - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { - canvas->FillRect(gfx::Rect(0, height() / 2, width(), 1), kBorderLightColor); - } - virtual gfx::Size GetPreferredSize() OVERRIDE { - return gfx::Size(1, kTrayPopupScrollSeparatorHeight); - } - - DISALLOW_COPY_AND_ASSIGN(ScrollSeparator); -}; - -class ScrollBorder : public views::Border { - public: - ScrollBorder() {} - virtual ~ScrollBorder() {} - - void set_visible(bool visible) { visible_ = visible; } - - private: - // Overridden from views::Border. - virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE { - if (!visible_) - return; - canvas->FillRect(gfx::Rect(0, view.height() - 1, view.width(), 1), - kBorderLightColor); - } - - virtual gfx::Insets GetInsets() const OVERRIDE { - return gfx::Insets(0, 0, 1, 0); - } - - virtual gfx::Size GetMinimumSize() const OVERRIDE { - return gfx::Size(0, 1); - } - - bool visible_; - - DISALLOW_COPY_AND_ASSIGN(ScrollBorder); -}; - -TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) - : owner_(owner), - footer_(NULL), - scroller_(NULL), - scroll_content_(NULL), - scroll_border_(NULL) { - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, - 0, 0, 0)); - set_background(views::Background::CreateSolidBackground(kBackgroundColor)); -} - -TrayDetailsView::~TrayDetailsView() { -} - -void TrayDetailsView::CreateSpecialRow(int string_id, - ViewClickListener* listener) { - DCHECK(!footer_); - footer_ = new SpecialPopupRow(); - footer_->SetTextLabel(string_id, listener); - AddChildViewAt(footer_, child_count()); -} - -void TrayDetailsView::CreateScrollableList() { - DCHECK(!scroller_); - scroll_content_ = new views::View; - scroll_content_->SetLayoutManager(new views::BoxLayout( - views::BoxLayout::kVertical, 0, 0, 1)); - scroller_ = new FixedSizedScrollView; - scroller_->SetContentsView(scroll_content_); - - // Note: |scroller_| takes ownership of |scroll_border_|. - scroll_border_ = new ScrollBorder; - scroller_->set_border(scroll_border_); - - AddChildView(scroller_); -} - -void TrayDetailsView::AddScrollSeparator() { - DCHECK(scroll_content_); - // Do not draw the separator if it is the very first item - // in the scrollable list. - if (scroll_content_->has_children()) - scroll_content_->AddChildView(new ScrollSeparator); -} - -void TrayDetailsView::Reset() { - RemoveAllChildViews(true); - footer_ = NULL; - scroller_ = NULL; - scroll_content_ = NULL; -} - -void TrayDetailsView::TransitionToDefaultView() { - // Cache pointer to owner in this function scope. TrayDetailsView will be - // deleted after called ShowDefaultView. - SystemTrayItem* owner = owner_; - if (footer_ && footer_->content() && footer_->content()->HasFocus()) - owner->set_restore_focus(true); - owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); - owner->set_restore_focus(false); -} - -void TrayDetailsView::Layout() { - if (!scroller_ || !footer_ || bounds().IsEmpty()) { - views::View::Layout(); - return; - } - - scroller_->set_fixed_size(gfx::Size()); - gfx::Size size = GetPreferredSize(); - - // Set the scroller to fill the space above the bottom row, so that the - // bottom row of the detailed view will always stay just above the footer. - gfx::Size scroller_size = scroll_content_->GetPreferredSize(); - scroller_->set_fixed_size(gfx::Size( - width() + scroller_->GetScrollBarWidth(), - scroller_size.height() - (size.height() - height()))); - - views::View::Layout(); - // Always make sure the footer element is bottom aligned. - gfx::Rect fbounds = footer_->bounds(); - fbounds.set_y(height() - footer_->height()); - footer_->SetBoundsRect(fbounds); -} - -void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) { - if (scroll_border_) { - int index = GetIndexOf(scroller_); - if (index < child_count() - 1 && child_at(index + 1) != footer_) - scroll_border_->set_visible(true); - else - scroll_border_->set_visible(false); - } - - views::View::OnPaintBorder(canvas); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_details_view.h b/chromium/ash/system/tray/tray_details_view.h deleted file mode 100644 index 28e9082c58f..00000000000 --- a/chromium/ash/system/tray/tray_details_view.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_DETAILS_VIEW_H_ -#define ASH_SYSTEM_TRAY_TRAY_DETAILS_VIEW_H_ - -#include "ash/ash_export.h" -#include "ash/system/tray/special_popup_row.h" -#include "ui/views/view.h" - -namespace views { -class ScrollView; -} - -namespace ash { - -class SystemTrayItem; - -namespace internal { - -class FixedSizedScrollView; -class ScrollBorder; -class ViewClickListener; - -class ASH_EXPORT TrayDetailsView : public views::View { - public: - explicit TrayDetailsView(SystemTrayItem* owner); - virtual ~TrayDetailsView(); - - // Creates a row with special highlighting etc. This is typically the - // bottom-most row in the popup. - void CreateSpecialRow(int string_id, ViewClickListener* listener); - - // Creates a scrollable list. The list has a border at the bottom if there is - // any other view between the list and the footer row at the bottom. - void CreateScrollableList(); - - // Adds a separator in scrollable list. - void AddScrollSeparator(); - - // Removes (and destroys) all child views. - void Reset(); - - // Transition to default view from details view. If |footer_| has focus before - // transition, the default view should focus on the owner of this details - // view. - void TransitionToDefaultView(); - - SystemTrayItem* owner() const { return owner_; } - SpecialPopupRow* footer() const { return footer_; } - FixedSizedScrollView* scroller() const { return scroller_; } - views::View* scroll_content() const { return scroll_content_; } - - protected: - // Overridden from views::View. - virtual void Layout() OVERRIDE; - virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE; - - private: - SystemTrayItem* owner_; - SpecialPopupRow* footer_; - FixedSizedScrollView* scroller_; - views::View* scroll_content_; - ScrollBorder* scroll_border_; - - DISALLOW_COPY_AND_ASSIGN(TrayDetailsView); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_DETAILS_VIEW_H_ diff --git a/chromium/ash/system/tray/tray_details_view_unittest.cc b/chromium/ash/system/tray/tray_details_view_unittest.cc deleted file mode 100644 index c608120411a..00000000000 --- a/chromium/ash/system/tray/tray_details_view_unittest.cc +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_details_view.h" - -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/system/status_area_widget.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_item.h" -#include "ash/system/tray/tray_details_view.h" -#include "ash/system/tray/view_click_listener.h" -#include "ash/test/ash_test_base.h" -#include "base/run_loop.h" -#include "grit/ash_strings.h" -#include "ui/aura/window.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -namespace ash { -namespace test { - -namespace { - -SystemTray* GetSystemTray() { - return Shell::GetPrimaryRootWindowController()->shelf()-> - status_area_widget()->system_tray(); -} - -class TestDetailsView : public internal::TrayDetailsView, - public internal::ViewClickListener { - public: - explicit TestDetailsView(SystemTrayItem* owner) - : internal::TrayDetailsView(owner) {} - - virtual ~TestDetailsView() {} - - void CreateFooterAndFocus() { - // Uses bluetooth label for testing purpose. It can be changed to any - // string_id. - CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); - footer()->content()->RequestFocus(); - } - - // Overridden from internal::ViewClickListener: - virtual void OnViewClicked(views::View* sender) OVERRIDE {} - - private: - DISALLOW_COPY_AND_ASSIGN(TestDetailsView); -}; - -// Trivial item implementation that tracks its views for testing. -class TestItem : public SystemTrayItem { - public: - TestItem() : SystemTrayItem(GetSystemTray()), tray_view_(NULL) {} - - // Overridden from SystemTrayItem: - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE { - tray_view_ = new views::View; - return tray_view_; - } - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE { - default_view_ = new views::View; - default_view_->SetFocusable(true); - return default_view_; - } - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE { - detailed_view_ = new TestDetailsView(this); - return detailed_view_; - } - virtual void DestroyTrayView() OVERRIDE { - tray_view_ = NULL; - } - virtual void DestroyDefaultView() OVERRIDE { - default_view_ = NULL; - } - virtual void DestroyDetailedView() OVERRIDE { - detailed_view_ = NULL; - } - - views::View* tray_view() const { return tray_view_; } - views::View* default_view() const { return default_view_; } - TestDetailsView* detailed_view() const { return detailed_view_; } - - private: - views::View* tray_view_; - views::View* default_view_; - TestDetailsView* detailed_view_; - - DISALLOW_COPY_AND_ASSIGN(TestItem); -}; - -} // namespace - -typedef AshTestBase TrayDetailsViewTest; - -TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) { - SystemTray* tray = GetSystemTray(); - ASSERT_TRUE(tray->GetWidget()); - - TestItem* test_item_1 = new TestItem; - TestItem* test_item_2 = new TestItem; - tray->AddTrayItem(test_item_1); - tray->AddTrayItem(test_item_2); - - // Ensure the tray views are created. - ASSERT_TRUE(test_item_1->tray_view() != NULL); - ASSERT_TRUE(test_item_2->tray_view() != NULL); - - // Show the default view. - tray->ShowDefaultView(BUBBLE_CREATE_NEW); - RunAllPendingInMessageLoop(); - - // Show the detailed view of item 2. - tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); - EXPECT_TRUE(test_item_2->detailed_view()); - RunAllPendingInMessageLoop(); - EXPECT_FALSE(test_item_2->default_view()); - - // Transition back to default view, the default view of item 2 should have - // focus. - test_item_2->detailed_view()->CreateFooterAndFocus(); - test_item_2->detailed_view()->TransitionToDefaultView(); - RunAllPendingInMessageLoop(); - - EXPECT_TRUE(test_item_2->default_view()); - EXPECT_FALSE(test_item_2->detailed_view()); - EXPECT_TRUE(test_item_2->default_view()->HasFocus()); - - // Show the detailed view of item 2 again. - tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); - EXPECT_TRUE(test_item_2->detailed_view()); - RunAllPendingInMessageLoop(); - EXPECT_FALSE(test_item_2->default_view()); - - // Transition back to default view, the default view of item 2 should NOT have - // focus. - test_item_2->detailed_view()->TransitionToDefaultView(); - RunAllPendingInMessageLoop(); - - EXPECT_TRUE(test_item_2->default_view()); - EXPECT_FALSE(test_item_2->detailed_view()); - EXPECT_FALSE(test_item_2->default_view()->HasFocus()); -} - -} // namespace test -} // namespace ash diff --git a/chromium/ash/system/tray/tray_empty.cc b/chromium/ash/system/tray/tray_empty.cc deleted file mode 100644 index f15f7b31e73..00000000000 --- a/chromium/ash/system/tray/tray_empty.cc +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_empty.h" - -#include "ui/views/layout/box_layout.h" -#include "ui/views/background.h" -#include "ui/views/border.h" -#include "ui/views/view.h" - -namespace { - -class EmptyBackground : public views::Background { - public: - EmptyBackground() {} - virtual ~EmptyBackground() {} - - private: - virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { - } - - DISALLOW_COPY_AND_ASSIGN(EmptyBackground); -}; - -} - -namespace ash { -namespace internal { - -TrayEmpty::TrayEmpty(SystemTray* system_tray) - : SystemTrayItem(system_tray) { -} - -TrayEmpty::~TrayEmpty() {} - -views::View* TrayEmpty::CreateTrayView(user::LoginStatus status) { - return NULL; -} - -views::View* TrayEmpty::CreateDefaultView(user::LoginStatus status) { - if (status == user::LOGGED_IN_NONE) - return NULL; - - views::View* view = new views::View; - view->set_background(new EmptyBackground()); - view->set_border(views::Border::CreateEmptyBorder(10, 0, 0, 0)); - view->SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, - 0, 0, 0)); - view->SetPaintToLayer(true); - view->SetFillsBoundsOpaquely(false); - return view; -} - -views::View* TrayEmpty::CreateDetailedView(user::LoginStatus status) { - return NULL; -} - -void TrayEmpty::DestroyTrayView() {} - -void TrayEmpty::DestroyDefaultView() {} - -void TrayEmpty::DestroyDetailedView() {} - -void TrayEmpty::UpdateAfterLoginStatusChange(user::LoginStatus status) {} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_empty.h b/chromium/ash/system/tray/tray_empty.h deleted file mode 100644 index a7575cf46e3..00000000000 --- a/chromium/ash/system/tray/tray_empty.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_EMPTY_H_ -#define ASH_SYSTEM_TRAY_TRAY_EMPTY_H_ - -#include "ash/system/tray/system_tray_item.h" - -namespace ash { -namespace internal { - -class TrayEmpty : public SystemTrayItem { - public: - explicit TrayEmpty(SystemTray* system_tray); - virtual ~TrayEmpty(); - - private: - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(TrayEmpty); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_EMPTY_H_ diff --git a/chromium/ash/system/tray/tray_event_filter.cc b/chromium/ash/system/tray/tray_event_filter.cc deleted file mode 100644 index 676c8b6346c..00000000000 --- a/chromium/ash/system/tray/tray_event_filter.cc +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_event_filter.h" - -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_layout_manager.h" -#include "ash/shell.h" -#include "ash/shell_window_ids.h" -#include "ash/system/tray/tray_background_view.h" -#include "ash/system/tray/tray_bubble_wrapper.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_event_filter.h" -#include "ui/aura/client/screen_position_client.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/views/widget/widget.h" - -namespace ash { -namespace internal { - -TrayEventFilter::TrayEventFilter() { -} - -TrayEventFilter::~TrayEventFilter() { - DCHECK(wrappers_.empty()); -} - -void TrayEventFilter::AddWrapper(TrayBubbleWrapper* wrapper) { - bool was_empty = wrappers_.empty(); - wrappers_.insert(wrapper); - if (was_empty && !wrappers_.empty()) - ash::Shell::GetInstance()->AddPreTargetHandler(this); -} - -void TrayEventFilter::RemoveWrapper(TrayBubbleWrapper* wrapper) { - wrappers_.erase(wrapper); - if (wrappers_.empty()) - ash::Shell::GetInstance()->RemovePreTargetHandler(this); -} - -void TrayEventFilter::OnMouseEvent(ui::MouseEvent* event) { - if (event->type() == ui::ET_MOUSE_PRESSED && - ProcessLocatedEvent(event)) { - event->StopPropagation(); - } -} - -void TrayEventFilter::OnTouchEvent(ui::TouchEvent* event) { - if (event->type() == ui::ET_TOUCH_PRESSED && ProcessLocatedEvent(event)) - event->StopPropagation(); -} - -bool TrayEventFilter::ProcessLocatedEvent(ui::LocatedEvent* event) { - if (event->target()) { - aura::Window* target = static_cast<aura::Window*>(event->target()); - // Don't process events that occurred inside an embedded menu. - internal::RootWindowController* root_controller = - internal::GetRootWindowController(target->GetRootWindow()); - if (root_controller && root_controller->GetContainer( - internal::kShellWindowId_MenuContainer)->Contains(target)) { - return false; - } - } - - // Check the boundary for all wrappers, and do not handle the event if it - // happens inside of any of those wrappers. - for (std::set<TrayBubbleWrapper*>::const_iterator iter = wrappers_.begin(); - iter != wrappers_.end(); ++iter) { - const TrayBubbleWrapper* wrapper = *iter; - const views::Widget* bubble_widget = wrapper->bubble_widget(); - if (!bubble_widget) - continue; - - gfx::Rect bounds = bubble_widget->GetWindowBoundsInScreen(); - bounds.Inset(wrapper->bubble_view()->GetBorderInsets()); - aura::Window* root = bubble_widget->GetNativeView()->GetRootWindow(); - aura::client::ScreenPositionClient* screen_position_client = - aura::client::GetScreenPositionClient(root); - gfx::Point screen_point(event->root_location()); - screen_position_client->ConvertPointToScreen(root, &screen_point); - - if (bounds.Contains(screen_point)) - return false; - if (wrapper->tray()) { - // If the user clicks on the parent tray, don't process the event here, - // let the tray logic handle the event and determine show/hide behavior. - bounds = wrapper->tray()->GetBoundsInScreen(); - if (bounds.Contains(screen_point)) - return false; - } - } - - // Handle clicking outside the bubble and tray and return true if the - // event was handled. - // Cannot iterate |wrappers_| directly, because clicking outside will remove - // the wrapper, which shrinks |wrappers_| unsafely. - std::set<TrayBackgroundView*> trays; - for (std::set<TrayBubbleWrapper*>::iterator iter = wrappers_.begin(); - iter != wrappers_.end(); ++iter) { - trays.insert((*iter)->tray()); - } - bool handled = false; - for (std::set<TrayBackgroundView*>::iterator iter = trays.begin(); - iter != trays.end(); ++iter) { - handled |= (*iter)->ClickedOutsideBubble(); - } - return handled; -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_event_filter.h b/chromium/ash/system/tray/tray_event_filter.h deleted file mode 100644 index 40593155c2c..00000000000 --- a/chromium/ash/system/tray/tray_event_filter.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_EVENT_FILTER_H_ -#define ASH_SYSTEM_TRAY_TRAY_EVENT_FILTER_H_ - -#include <set> - -#include "base/basictypes.h" -#include "ui/events/event.h" -#include "ui/events/event_handler.h" - -namespace aura { -class Window; -} - -namespace ash { -namespace internal { - -class TrayBubbleWrapper; - -// Handles events for a tray bubble. - -class TrayEventFilter : public ui::EventHandler { - public: - explicit TrayEventFilter(); - virtual ~TrayEventFilter(); - - void AddWrapper(TrayBubbleWrapper* wrapper); - void RemoveWrapper(TrayBubbleWrapper* wrapper); - - // Overridden from ui::EventHandler. - virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; - virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; - - private: - // Returns true if the event is handled. - bool ProcessLocatedEvent(ui::LocatedEvent* event); - - std::set<TrayBubbleWrapper*> wrappers_; - - DISALLOW_COPY_AND_ASSIGN(TrayEventFilter); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_EVENT_FILTER_H_ diff --git a/chromium/ash/system/tray/tray_image_item.cc b/chromium/ash/system/tray/tray_image_item.cc deleted file mode 100644 index 7c5e216c942..00000000000 --- a/chromium/ash/system/tray/tray_image_item.cc +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_image_item.h" - -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/tray_item_view.h" -#include "ash/system/tray/tray_utils.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/layout/box_layout.h" - -namespace ash { -namespace internal { - -TrayImageItem::TrayImageItem(SystemTray* system_tray, int resource_id) - : SystemTrayItem(system_tray), - resource_id_(resource_id), - tray_view_(NULL) { -} - -TrayImageItem::~TrayImageItem() {} - -views::View* TrayImageItem::tray_view() { - return tray_view_; -} - -void TrayImageItem::SetImageFromResourceId(int resource_id) { - resource_id_ = resource_id; - if (!tray_view_) - return; - tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance(). - GetImageNamed(resource_id_).ToImageSkia()); -} - -views::View* TrayImageItem::CreateTrayView(user::LoginStatus status) { - CHECK(tray_view_ == NULL); - tray_view_ = new TrayItemView(this); - tray_view_->CreateImageView(); - tray_view_->image_view()->SetImage(ui::ResourceBundle::GetSharedInstance(). - GetImageNamed(resource_id_).ToImageSkia()); - tray_view_->SetVisible(GetInitialVisibility()); - SetItemAlignment(system_tray()->shelf_alignment()); - return tray_view_; -} - -views::View* TrayImageItem::CreateDefaultView(user::LoginStatus status) { - return NULL; -} - -views::View* TrayImageItem::CreateDetailedView(user::LoginStatus status) { - return NULL; -} - -void TrayImageItem::UpdateAfterLoginStatusChange(user::LoginStatus status) { -} - -void TrayImageItem::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { - SetTrayImageItemBorder(tray_view_, alignment); - SetItemAlignment(alignment); -} - -void TrayImageItem::DestroyTrayView() { - tray_view_ = NULL; -} - -void TrayImageItem::DestroyDefaultView() { -} - -void TrayImageItem::DestroyDetailedView() { -} - -void TrayImageItem::SetItemAlignment(ShelfAlignment alignment) { - // Center the item dependent on the orientation of the shelf. - views::BoxLayout::Orientation layout = views::BoxLayout::kHorizontal; - switch (alignment) { - case ash::SHELF_ALIGNMENT_BOTTOM: - case ash::SHELF_ALIGNMENT_TOP: - layout = views::BoxLayout::kHorizontal; - break; - case ash::SHELF_ALIGNMENT_LEFT: - case ash::SHELF_ALIGNMENT_RIGHT: - layout = views::BoxLayout::kVertical; - break; - } - tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); - tray_view_->Layout(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_image_item.h b/chromium/ash/system/tray/tray_image_item.h deleted file mode 100644 index 6dea5c8372f..00000000000 --- a/chromium/ash/system/tray/tray_image_item.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_IMAGE_ITEM_H_ -#define ASH_SYSTEM_TRAY_TRAY_IMAGE_ITEM_H_ - -#include "ash/system/tray/system_tray_item.h" - -namespace views { -class ImageView; -} - -namespace ash { -namespace internal { - -class TrayItemView; - -class TrayImageItem : public SystemTrayItem { - public: - TrayImageItem(SystemTray* system_tray, int resource_id); - virtual ~TrayImageItem(); - - views::View* tray_view(); - - // Changes the icon of the tray-view to the specified resource. - void SetImageFromResourceId(int resource_id); - - protected: - virtual bool GetInitialVisibility() = 0; - - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) OVERRIDE; - - private: - // Set the alignment of the image depending on the shelf alignment. - void SetItemAlignment(ShelfAlignment alignment); - - int resource_id_; - TrayItemView* tray_view_; - - DISALLOW_COPY_AND_ASSIGN(TrayImageItem); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_IMAGE_ITEM_H_ diff --git a/chromium/ash/system/tray/tray_item_more.cc b/chromium/ash/system/tray/tray_item_more.cc deleted file mode 100644 index 9284b47d053..00000000000 --- a/chromium/ash/system/tray/tray_item_more.cc +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_item_more.h" - -#include "ash/system/tray/fixed_sized_image_view.h" -#include "ash/system/tray/system_tray_item.h" -#include "ash/system/tray/tray_constants.h" -#include "grit/ash_resources.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" - -namespace ash { -namespace internal { - -TrayItemMore::TrayItemMore(SystemTrayItem* owner, bool show_more) - : owner_(owner), - show_more_(show_more), - icon_(NULL), - label_(NULL), - more_(NULL) { - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, - kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems)); - - icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight); - AddChildView(icon_); - - label_ = new views::Label; - label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - AddChildView(label_); - - if (show_more) { - more_ = new views::ImageView; - more_->EnableCanvasFlippingForRTLUI(true); - more_->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageNamed( - IDR_AURA_UBER_TRAY_MORE).ToImageSkia()); - AddChildView(more_); - } -} - -TrayItemMore::~TrayItemMore() { -} - -void TrayItemMore::SetLabel(const base::string16& label) { - label_->SetText(label); - Layout(); - SchedulePaint(); -} - -void TrayItemMore::SetImage(const gfx::ImageSkia* image_skia) { - icon_->SetImage(image_skia); - SchedulePaint(); -} - -void TrayItemMore::SetAccessibleName(const base::string16& name) { - accessible_name_ = name; -} - -void TrayItemMore::ReplaceIcon(views::View* view) { - delete icon_; - icon_ = NULL; - AddChildViewAt(view, 0); -} - -bool TrayItemMore::PerformAction(const ui::Event& event) { - if (!show_more_) - return false; - - owner()->TransitionDetailedView(); - return true; -} - -void TrayItemMore::Layout() { - // Let the box-layout do the layout first. Then move the '>' arrow to right - // align. - views::View::Layout(); - - if (!show_more_) - return; - - // Make sure the chevron always has the full size. - gfx::Size size = more_->GetPreferredSize(); - gfx::Rect bounds(size); - bounds.set_x(width() - size.width() - kTrayPopupPaddingBetweenItems); - bounds.set_y((height() - size.height()) / 2); - more_->SetBoundsRect(bounds); - - // Adjust the label's bounds in case it got cut off by |more_|. - if (label_->bounds().Intersects(more_->bounds())) { - gfx::Rect bounds = label_->bounds(); - bounds.set_width(more_->x() - kTrayPopupPaddingBetweenItems - label_->x()); - label_->SetBoundsRect(bounds); - } -} - -void TrayItemMore::GetAccessibleState(ui::AccessibleViewState* state) { - state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; - state->name = accessible_name_; -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_item_more.h b/chromium/ash/system/tray/tray_item_more.h deleted file mode 100644 index 49287240d40..00000000000 --- a/chromium/ash/system/tray/tray_item_more.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_ITEM_MORE_H_ -#define ASH_SYSTEM_TRAY_TRAY_ITEM_MORE_H_ - -#include "ash/system/tray/actionable_view.h" -#include "ui/views/view.h" - -namespace views { -class ImageView; -class Label; -class View; -} - -namespace ash { - -class SystemTrayItem; - -namespace internal { - -// A view with a chevron ('>') on the right edge. Clicking on the view brings up -// the detailed view of the tray-item that owns it. -class TrayItemMore : public ActionableView { - public: - TrayItemMore(SystemTrayItem* owner, bool show_more); - virtual ~TrayItemMore(); - - SystemTrayItem* owner() const { return owner_; } - - void SetLabel(const base::string16& label); - void SetImage(const gfx::ImageSkia* image_skia); - void SetAccessibleName(const base::string16& name); - - protected: - // Replaces the default icon (on the left of the label), and allows a custom - // view to be placed there. Once the default icon is replaced, |SetImage| - // should never be called. - void ReplaceIcon(views::View* view); - - private: - // Overridden from ActionableView. - virtual bool PerformAction(const ui::Event& event) OVERRIDE; - - // Overridden from views::View. - virtual void Layout() OVERRIDE; - virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; - - SystemTrayItem* owner_; - // True if |more_| should be shown. - bool show_more_; - views::ImageView* icon_; - views::Label* label_; - views::ImageView* more_; - base::string16 accessible_name_; - - DISALLOW_COPY_AND_ASSIGN(TrayItemMore); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_ITEM_MORE_H_ diff --git a/chromium/ash/system/tray/tray_item_view.cc b/chromium/ash/system/tray/tray_item_view.cc deleted file mode 100644 index 9a7a75c4378..00000000000 --- a/chromium/ash/system/tray/tray_item_view.cc +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_item_view.h" - -#include "ash/shelf/shelf_types.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_item.h" -#include "ui/compositor/layer.h" -#include "ui/gfx/animation/slide_animation.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/widget/widget.h" - -namespace { -const int kTrayIconHeight = 29; -const int kTrayIconWidth = 29; -const int kTrayItemAnimationDurationMS = 200; - -// Animations can be disabled for testing. -bool animations_enabled = true; -} - -namespace ash { -namespace internal { - -TrayItemView::TrayItemView(SystemTrayItem* owner) - : owner_(owner), - label_(NULL), - image_view_(NULL) { - SetPaintToLayer(true); - SetFillsBoundsOpaquely(false); - SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); -} - -TrayItemView::~TrayItemView() {} - -// static -void TrayItemView::DisableAnimationsForTest() { - animations_enabled = false; -} - -void TrayItemView::CreateLabel() { - label_ = new views::Label; - AddChildView(label_); -} - -void TrayItemView::CreateImageView() { - image_view_ = new views::ImageView; - AddChildView(image_view_); -} - -void TrayItemView::SetVisible(bool set_visible) { - if (!GetWidget() || !animations_enabled) { - views::View::SetVisible(set_visible); - return; - } - - if (!animation_) { - animation_.reset(new gfx::SlideAnimation(this)); - animation_->SetSlideDuration(GetAnimationDurationMS()); - animation_->SetTweenType(gfx::Tween::LINEAR); - animation_->Reset(visible() ? 1.0 : 0.0); - } - - if (!set_visible) { - animation_->Hide(); - AnimationProgressed(animation_.get()); - } else { - animation_->Show(); - AnimationProgressed(animation_.get()); - views::View::SetVisible(true); - } -} - -gfx::Size TrayItemView::DesiredSize() { - return views::View::GetPreferredSize(); -} - -int TrayItemView::GetAnimationDurationMS() { - return kTrayItemAnimationDurationMS; -} - -gfx::Size TrayItemView::GetPreferredSize() { - gfx::Size size = DesiredSize(); - if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM || - owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_TOP) - size.set_height(kTrayIconHeight); - else - size.set_width(kTrayIconWidth); - if (!animation_.get() || !animation_->is_animating()) - return size; - if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM || - owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_TOP) { - size.set_width(std::max(1, - static_cast<int>(size.width() * animation_->GetCurrentValue()))); - } else { - size.set_height(std::max(1, - static_cast<int>(size.height() * animation_->GetCurrentValue()))); - } - return size; -} - -int TrayItemView::GetHeightForWidth(int width) { - return GetPreferredSize().height(); -} - -void TrayItemView::ChildPreferredSizeChanged(views::View* child) { - PreferredSizeChanged(); -} - -void TrayItemView::AnimationProgressed(const gfx::Animation* animation) { - gfx::Transform transform; - if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM || - owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_TOP) { - transform.Translate(0, animation->CurrentValueBetween( - static_cast<double>(height()) / 2, 0.)); - } else { - transform.Translate(animation->CurrentValueBetween( - static_cast<double>(width() / 2), 0.), 0); - } - transform.Scale(animation->GetCurrentValue(), - animation->GetCurrentValue()); - layer()->SetTransform(transform); - PreferredSizeChanged(); -} - -void TrayItemView::AnimationEnded(const gfx::Animation* animation) { - if (animation->GetCurrentValue() < 0.1) - views::View::SetVisible(false); -} - -void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { - AnimationEnded(animation); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_item_view.h b/chromium/ash/system/tray/tray_item_view.h deleted file mode 100644 index 761e918791c..00000000000 --- a/chromium/ash/system/tray/tray_item_view.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_ -#define ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_ - -#include "ash/ash_export.h" -#include "ui/gfx/animation/animation_delegate.h" -#include "ui/views/view.h" - -namespace gfx { -class SlideAnimation; -} - -namespace views { -class ImageView; -class Label; -} - -namespace ash { - -class SystemTrayItem; - -namespace internal { - -// Base-class for items in the tray. It makes sure the widget is updated -// correctly when the visibility/size of the tray item changes. It also adds -// animation when showing/hiding the item in the tray. -class ASH_EXPORT TrayItemView : public views::View, - public gfx::AnimationDelegate { - public: - explicit TrayItemView(SystemTrayItem* owner); - virtual ~TrayItemView(); - - static void DisableAnimationsForTest(); - - // Convenience function for creating a child Label or ImageView. - void CreateLabel(); - void CreateImageView(); - - SystemTrayItem* owner() const { return owner_; } - views::Label* label() const { return label_; } - views::ImageView* image_view() const { return image_view_; } - - // Overridden from views::View. - virtual void SetVisible(bool visible) OVERRIDE; - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual int GetHeightForWidth(int width) OVERRIDE; - - protected: - // Makes sure the widget relayouts after the size/visibility of the view - // changes. - void ApplyChange(); - - // This should return the desired size of the view. For most views, this - // returns GetPreferredSize. But since this class overrides GetPreferredSize - // for animation purposes, we allow a different way to get this size, and do - // not allow GetPreferredSize to be overridden. - virtual gfx::Size DesiredSize(); - - // The default animation duration is 200ms. But each view can customize this. - virtual int GetAnimationDurationMS(); - - private: - // Overridden from views::View. - virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; - - // Overridden from gfx::AnimationDelegate. - virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; - virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; - virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE; - - SystemTrayItem* owner_; - scoped_ptr<gfx::SlideAnimation> animation_; - views::Label* label_; - views::ImageView* image_view_; - - DISALLOW_COPY_AND_ASSIGN(TrayItemView); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_ITEM_VIEW_H_ diff --git a/chromium/ash/system/tray/tray_notification_view.cc b/chromium/ash/system/tray/tray_notification_view.cc deleted file mode 100644 index c09589285ea..00000000000 --- a/chromium/ash/system/tray/tray_notification_view.cc +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_notification_view.h" - -#include "ash/system/tray/system_tray_item.h" -#include "ash/system/tray/tray_constants.h" -#include "grit/ash_strings.h" -#include "grit/ui_resources.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image_skia.h" -#include "ui/views/background.h" -#include "ui/views/controls/button/image_button.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/layout/grid_layout.h" - -namespace ash { -namespace internal { - -TrayNotificationView::TrayNotificationView(SystemTrayItem* owner, int icon_id) - : owner_(owner), - icon_id_(icon_id), - icon_(NULL) { -} - -TrayNotificationView::~TrayNotificationView() { -} - -void TrayNotificationView::InitView(views::View* contents) { - set_background(views::Background::CreateSolidBackground(kBackgroundColor)); - - views::GridLayout* layout = new views::GridLayout(this); - SetLayoutManager(layout); - - views::ImageButton* close_button = new views::ImageButton(this); - close_button->SetImage(views::CustomButton::STATE_NORMAL, - ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_MESSAGE_CLOSE)); - close_button->SetImageAlignment(views::ImageButton::ALIGN_CENTER, - views::ImageButton::ALIGN_MIDDLE); - - icon_ = new views::ImageView; - if (icon_id_ != 0) { - icon_->SetImage( - ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_)); - } - - views::ColumnSet* columns = layout->AddColumnSet(0); - - columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); - - // Icon - columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, - 0, /* resize percent */ - views::GridLayout::FIXED, - kNotificationIconWidth, kNotificationIconWidth); - - columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); - - // Contents - columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, - 100, /* resize percent */ - views::GridLayout::FIXED, - kTrayNotificationContentsWidth, - kTrayNotificationContentsWidth); - - columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); - - // Close button - columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, - 0, /* resize percent */ - views::GridLayout::FIXED, - kNotificationButtonWidth, kNotificationButtonWidth); - - // Layout rows - layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); - layout->StartRow(0, 0); - layout->AddView(icon_); - layout->AddView(contents); - layout->AddView(close_button); - layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); -} - -void TrayNotificationView::SetIconImage(const gfx::ImageSkia& image) { - icon_->SetImage(image); - SchedulePaint(); -} - -const gfx::ImageSkia& TrayNotificationView::GetIconImage() const { - return icon_->GetImage(); -} - -void TrayNotificationView::UpdateView(views::View* new_contents) { - RemoveAllChildViews(true); - InitView(new_contents); - Layout(); - PreferredSizeChanged(); - SchedulePaint(); -} - -void TrayNotificationView::UpdateViewAndImage(views::View* new_contents, - const gfx::ImageSkia& image) { - RemoveAllChildViews(true); - InitView(new_contents); - icon_->SetImage(image); - Layout(); - PreferredSizeChanged(); - SchedulePaint(); -} - -void TrayNotificationView::StartAutoCloseTimer(int seconds) { - autoclose_.Stop(); - autoclose_delay_ = seconds; - if (autoclose_delay_) { - autoclose_.Start(FROM_HERE, - base::TimeDelta::FromSeconds(autoclose_delay_), - this, &TrayNotificationView::HandleClose); - } -} - -void TrayNotificationView::StopAutoCloseTimer() { - autoclose_.Stop(); -} - -void TrayNotificationView::RestartAutoCloseTimer() { - if (autoclose_delay_) - StartAutoCloseTimer(autoclose_delay_); -} - -void TrayNotificationView::ButtonPressed(views::Button* sender, - const ui::Event& event) { - HandleClose(); -} - -bool TrayNotificationView::OnMousePressed(const ui::MouseEvent& event) { - HandleClickAction(); - return true; -} - -void TrayNotificationView::OnGestureEvent(ui::GestureEvent* event) { - SlideOutView::OnGestureEvent(event); - if (event->handled()) - return; - if (event->type() != ui::ET_GESTURE_TAP) - return; - HandleClickAction(); - event->SetHandled(); -} - -void TrayNotificationView::OnClose() { -} - -void TrayNotificationView::OnClickAction() { -} - -void TrayNotificationView::OnSlideOut() { - owner_->HideNotificationView(); -} - -void TrayNotificationView::HandleClose() { - OnClose(); - owner_->HideNotificationView(); -} - -void TrayNotificationView::HandleClickAction() { - HandleClose(); - OnClickAction(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_notification_view.h b/chromium/ash/system/tray/tray_notification_view.h deleted file mode 100644 index 314b8aad7d2..00000000000 --- a/chromium/ash/system/tray/tray_notification_view.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_NOTIFICATION_VIEW_H_ -#define ASH_SYSTEM_TRAY_TRAY_NOTIFICATION_VIEW_H_ - -#include "base/timer/timer.h" -#include "ui/views/controls/button/image_button.h" -#include "ui/views/controls/slide_out_view.h" - -namespace gfx { -class ImageSkia; -} - -namespace views { -class ImageView; -} - -namespace ash { - -class SystemTrayItem; - -namespace internal { - -// A view for closable notification views, laid out like: -// ------------------- -// | icon contents x | -// ----------------v-- -// The close button will call OnClose() when clicked. -class TrayNotificationView : public views::SlideOutView, - public views::ButtonListener { - public: - // If icon_id is 0, no icon image will be set. SetIconImage can be called - // to later set the icon image. - TrayNotificationView(SystemTrayItem* owner, int icon_id); - virtual ~TrayNotificationView(); - - // InitView must be called once with the contents to be displayed. - void InitView(views::View* contents); - - // Sets/updates the icon image. - void SetIconImage(const gfx::ImageSkia& image); - - // Gets the icons image. - const gfx::ImageSkia& GetIconImage() const; - - // Replaces the contents view. - void UpdateView(views::View* new_contents); - - // Replaces the contents view and updates the icon image. - void UpdateViewAndImage(views::View* new_contents, - const gfx::ImageSkia& image); - - // Autoclose timer operations. - void StartAutoCloseTimer(int seconds); - void StopAutoCloseTimer(); - void RestartAutoCloseTimer(); - - // Overridden from ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE; - - // Overridden from views::View. - virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; - - // Overridden from ui::EventHandler. - virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; - - protected: - // Called when the close button is pressed. Does nothing by default. - virtual void OnClose(); - // Called when the notification is clicked on. Does nothing by default. - virtual void OnClickAction(); - - // Overridden from views::SlideOutView. - virtual void OnSlideOut() OVERRIDE; - - SystemTrayItem* owner() { return owner_; } - - private: - void HandleClose(); - void HandleClickAction(); - - SystemTrayItem* owner_; - int icon_id_; - views::ImageView* icon_; - - int autoclose_delay_; - base::OneShotTimer<TrayNotificationView> autoclose_; - - DISALLOW_COPY_AND_ASSIGN(TrayNotificationView); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_NOTIFICATION_VIEW_H_ diff --git a/chromium/ash/system/tray/tray_popup_header_button.cc b/chromium/ash/system/tray/tray_popup_header_button.cc deleted file mode 100644 index d19cbc54823..00000000000 --- a/chromium/ash/system/tray/tray_popup_header_button.cc +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_popup_header_button.h" - -#include "ash/ash_constants.h" -#include "ash/system/tray/tray_constants.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/views/painter.h" - -namespace ash { -namespace internal { - -// static -const char TrayPopupHeaderButton::kViewClassName[] = - "tray/TrayPopupHeaderButton"; - -TrayPopupHeaderButton::TrayPopupHeaderButton(views::ButtonListener* listener, - int enabled_resource_id, - int disabled_resource_id, - int enabled_resource_id_hover, - int disabled_resource_id_hover, - int accessible_name_id) - : views::ToggleImageButton(listener) { - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - SetImage(views::Button::STATE_NORMAL, - bundle.GetImageNamed(enabled_resource_id).ToImageSkia()); - SetToggledImage(views::Button::STATE_NORMAL, - bundle.GetImageNamed(disabled_resource_id).ToImageSkia()); - SetImage(views::Button::STATE_HOVERED, - bundle.GetImageNamed(enabled_resource_id_hover).ToImageSkia()); - SetToggledImage(views::Button::STATE_HOVERED, - bundle.GetImageNamed(disabled_resource_id_hover).ToImageSkia()); - SetImageAlignment(views::ImageButton::ALIGN_CENTER, - views::ImageButton::ALIGN_MIDDLE); - SetAccessibleName(bundle.GetLocalizedString(accessible_name_id)); - SetFocusable(true); - set_request_focus_on_press(false); - - SetFocusPainter(views::Painter::CreateSolidFocusPainter( - kFocusBorderColor, - gfx::Insets(1, 2, 2, 3))); -} - -TrayPopupHeaderButton::~TrayPopupHeaderButton() {} - -const char* TrayPopupHeaderButton::GetClassName() const { - return kViewClassName; -} - -gfx::Size TrayPopupHeaderButton::GetPreferredSize() { - return gfx::Size(ash::kTrayPopupItemHeight, ash::kTrayPopupItemHeight); -} - -void TrayPopupHeaderButton::OnPaintBorder(gfx::Canvas* canvas) { - // Just the left border. - const int kBorderHeight = 25; - int padding = (height() - kBorderHeight) / 2; - canvas->FillRect(gfx::Rect(0, padding, 1, height() - padding * 2), - ash::kBorderDarkColor); -} - -void TrayPopupHeaderButton::StateChanged() { - SchedulePaint(); -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_popup_header_button.h b/chromium/ash/system/tray/tray_popup_header_button.h deleted file mode 100644 index 37849bc2e97..00000000000 --- a/chromium/ash/system/tray/tray_popup_header_button.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_POPUP_HEADER_BUTTON_H_ -#define ASH_SYSTEM_TRAY_TRAY_POPUP_HEADER_BUTTON_H_ - -#include "ash/ash_export.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/views/controls/button/image_button.h" - -namespace ash { -namespace internal { - -// A ToggleImageButton with fixed size, paddings and hover effects. These -// buttons are used in the header. -class ASH_EXPORT TrayPopupHeaderButton : public views::ToggleImageButton { - public: - static const char kViewClassName[]; - - TrayPopupHeaderButton(views::ButtonListener* listener, - int enabled_resource_id, - int disabled_resource_id, - int enabled_resource_id_hover, - int disabled_resource_id_hover, - int accessible_name_id); - virtual ~TrayPopupHeaderButton(); - - private: - // Overridden from views::View: - virtual const char* GetClassName() const OVERRIDE; - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE; - - // Overridden from views::CustomButton: - virtual void StateChanged() OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(TrayPopupHeaderButton); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_POPUP_HEADER_BUTTON_H_ diff --git a/chromium/ash/system/tray/tray_popup_label_button.cc b/chromium/ash/system/tray/tray_popup_label_button.cc deleted file mode 100644 index 5b00c02a060..00000000000 --- a/chromium/ash/system/tray/tray_popup_label_button.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_popup_label_button.h" - -#include "ash/ash_constants.h" -#include "ash/system/tray/tray_popup_label_button_border.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/rect.h" -#include "ui/views/painter.h" - -namespace ash { -namespace internal { - -TrayPopupLabelButton::TrayPopupLabelButton(views::ButtonListener* listener, - const base::string16& text) - : views::LabelButton(listener, text) { - set_border(new TrayPopupLabelButtonBorder); - SetFocusable(true); - set_request_focus_on_press(false); - set_animate_on_state_change(false); - SetHorizontalAlignment(gfx::ALIGN_CENTER); - SetFocusPainter(views::Painter::CreateSolidFocusPainter( - kFocusBorderColor, - gfx::Insets(1, 1, 2, 2))); -} - -TrayPopupLabelButton::~TrayPopupLabelButton() {} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_popup_label_button.h b/chromium/ash/system/tray/tray_popup_label_button.h deleted file mode 100644 index a1f9db6b7b4..00000000000 --- a/chromium/ash/system/tray/tray_popup_label_button.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_POPUP_LABEL_BUTTON_H_ -#define ASH_SYSTEM_TRAY_TRAY_POPUP_LABEL_BUTTON_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/strings/string16.h" -#include "ui/views/controls/button/label_button.h" - -namespace ash { -namespace internal { - -// A label button with custom alignment, border and focus border. -class TrayPopupLabelButton : public views::LabelButton { - public: - TrayPopupLabelButton(views::ButtonListener* listener, - const base::string16& text); - virtual ~TrayPopupLabelButton(); - - private: - DISALLOW_COPY_AND_ASSIGN(TrayPopupLabelButton); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_POPUP_LABEL_BUTTON_H_ diff --git a/chromium/ash/system/tray/tray_popup_label_button_border.cc b/chromium/ash/system/tray/tray_popup_label_button_border.cc deleted file mode 100644 index d5be6bcc324..00000000000 --- a/chromium/ash/system/tray/tray_popup_label_button_border.cc +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_popup_label_button_border.h" - -#include "base/i18n/rtl.h" -#include "grit/ash_resources.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/vector2d.h" -#include "ui/native_theme/native_theme.h" -#include "ui/views/controls/button/label_button.h" -#include "ui/views/native_theme_delegate.h" - -namespace ash { -namespace internal { - -TrayPopupLabelButtonBorder::TrayPopupLabelButtonBorder() - : LabelButtonBorder(views::Button::STYLE_TEXTBUTTON) { - const int kTrayPopupLabelButtonBorderImagesNormal[] = { - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, - }; - SetPainter(false, views::Button::STATE_NORMAL, - views::Painter::CreateImageGridPainter( - kTrayPopupLabelButtonBorderImagesNormal)); - SetPainter(false, views::Button::STATE_DISABLED, - views::Painter::CreateImageGridPainter( - kTrayPopupLabelButtonBorderImagesNormal)); - - const int kTrayPopupLabelButtonBorderImagesHovered[] = { - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_HOVER_BACKGROUND, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, - }; - SetPainter(false, views::Button::STATE_HOVERED, - views::Painter::CreateImageGridPainter( - kTrayPopupLabelButtonBorderImagesHovered)); - SetPainter(false, views::Button::STATE_PRESSED, - views::Painter::CreateImageGridPainter( - kTrayPopupLabelButtonBorderImagesHovered)); - - const int kTrayPopupLabelButtonPaddingHorizontal = 16; - const int kTrayPopupLabelButtonPaddingVertical = 8; - set_insets(gfx::Insets(kTrayPopupLabelButtonPaddingVertical, - kTrayPopupLabelButtonPaddingHorizontal, - kTrayPopupLabelButtonPaddingVertical, - kTrayPopupLabelButtonPaddingHorizontal)); -} - -TrayPopupLabelButtonBorder::~TrayPopupLabelButtonBorder() {} - -void TrayPopupLabelButtonBorder::Paint(const views::View& view, - gfx::Canvas* canvas) { - const views::NativeThemeDelegate* native_theme_delegate = - static_cast<const views::LabelButton*>(&view); - ui::NativeTheme::ExtraParams extra; - const ui::NativeTheme::State state = - native_theme_delegate->GetThemeState(&extra); - if (state == ui::NativeTheme::kNormal || - state == ui::NativeTheme::kDisabled) { - // In normal and disabled state, the border is a vertical bar separating the - // button from the preceding sibling. If this button is its parent's first - // visible child, the separator bar should be omitted. - const views::View* first_visible_child = NULL; - for (int i = 0; i < view.parent()->child_count(); ++i) { - const views::View* child = view.parent()->child_at(i); - if (child->visible()) { - first_visible_child = child; - break; - } - } - if (first_visible_child == &view) - return; - } - if (base::i18n::IsRTL()) { - canvas->Save(); - canvas->Translate(gfx::Vector2d(view.width(), 0)); - canvas->Scale(-1, 1); - LabelButtonBorder::Paint(view, canvas); - canvas->Restore(); - } else { - LabelButtonBorder::Paint(view, canvas); - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_popup_label_button_border.h b/chromium/ash/system/tray/tray_popup_label_button_border.h deleted file mode 100644 index 04e5c7356d8..00000000000 --- a/chromium/ash/system/tray/tray_popup_label_button_border.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_POPUP_LABEL_BUTTON_BORDER_H_ -#define ASH_SYSTEM_TRAY_TRAY_POPUP_LABEL_BUTTON_BORDER_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/views/controls/button/label_button_border.h" - -namespace ash { -namespace internal { - -// A border for label buttons that paints a vertical separator in normal state -// and a custom hover effect in hovered or pressed state. -class TrayPopupLabelButtonBorder : public views::LabelButtonBorder { - public: - TrayPopupLabelButtonBorder(); - virtual ~TrayPopupLabelButtonBorder(); - - // views::LabelButtonBorder: - virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(TrayPopupLabelButtonBorder); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_POPUP_LABEL_BUTTON_BORDER_H_ diff --git a/chromium/ash/system/tray/tray_utils.cc b/chromium/ash/system/tray/tray_utils.cc deleted file mode 100644 index 34582b6fb5e..00000000000 --- a/chromium/ash/system/tray/tray_utils.cc +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray/tray_utils.h" - -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_item_view.h" -#include "ui/gfx/font.h" -#include "ui/views/border.h" -#include "ui/views/controls/label.h" - -namespace ash { -namespace internal { - -void SetupLabelForTray(views::Label* label) { - // Making label_font static to avoid the time penalty of DeriveFont for - // all but the first call. - static const gfx::Font label_font(gfx::Font().DeriveFont(1, gfx::Font::BOLD)); - label->SetFont(label_font); - label->SetAutoColorReadabilityEnabled(false); - label->SetEnabledColor(SK_ColorWHITE); - label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); - label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), - SkColorSetARGB(64, 0, 0, 0)); - label->SetShadowOffset(0, 1); -} - -void SetTrayImageItemBorder(views::View* tray_view, - ShelfAlignment alignment) { - if (alignment == SHELF_ALIGNMENT_BOTTOM || - alignment == SHELF_ALIGNMENT_TOP) { - tray_view->set_border(views::Border::CreateEmptyBorder( - 0, kTrayImageItemHorizontalPaddingBottomAlignment, - 0, kTrayImageItemHorizontalPaddingBottomAlignment)); - } else { - tray_view->set_border(views::Border::CreateEmptyBorder( - kTrayImageItemVerticalPaddingVerticalAlignment, - kTrayImageItemHorizontalPaddingVerticalAlignment, - kTrayImageItemVerticalPaddingVerticalAlignment, - kTrayImageItemHorizontalPaddingVerticalAlignment)); - } -} - -void SetTrayLabelItemBorder(TrayItemView* tray_view, - ShelfAlignment alignment) { - if (alignment == SHELF_ALIGNMENT_BOTTOM || - alignment == SHELF_ALIGNMENT_TOP) { - tray_view->set_border(views::Border::CreateEmptyBorder( - 0, kTrayLabelItemHorizontalPaddingBottomAlignment, - 0, kTrayLabelItemHorizontalPaddingBottomAlignment)); - } else { - // Center the label for vertical launcher alignment. - int horizontal_padding = std::max(0, - (tray_view->GetPreferredSize().width() - - tray_view->label()->GetPreferredSize().width()) / 2); - tray_view->set_border(views::Border::CreateEmptyBorder( - kTrayLabelItemVerticalPaddingVerticalAlignment, - horizontal_padding, - kTrayLabelItemVerticalPaddingVerticalAlignment, - horizontal_padding)); - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray/tray_utils.h b/chromium/ash/system/tray/tray_utils.h deleted file mode 100644 index 412fb97d8da..00000000000 --- a/chromium/ash/system/tray/tray_utils.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_TRAY_UTILS_H_ -#define ASH_SYSTEM_TRAY_TRAY_UTILS_H_ - -#include "ash/shelf/shelf_types.h" - -namespace views { -class Label; -class View; -} - -namespace ash { -namespace internal { - -class TrayItemView; - -// Sets up a Label properly for the tray (sets color, font etc.). -void SetupLabelForTray(views::Label* label); - -// TODO(jennyz): refactor these two functions to SystemTrayItem. -// Sets the empty border of an image tray item for adjusting the space -// around it. -void SetTrayImageItemBorder(views::View* tray_view, ShelfAlignment alignment); -// Sets the empty border around a label tray item for adjusting the space -// around it. -void SetTrayLabelItemBorder(TrayItemView* tray_view, - ShelfAlignment alignment); - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_TRAY_UTILS_H_ diff --git a/chromium/ash/system/tray/view_click_listener.h b/chromium/ash/system/tray/view_click_listener.h deleted file mode 100644 index b5f4bb886f0..00000000000 --- a/chromium/ash/system/tray/view_click_listener.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_VIEW_CLICK_LISTENER_H_ -#define ASH_SYSTEM_TRAY_VIEW_CLICK_LISTENER_H_ - -namespace views { -class View; -} - -namespace ash { -namespace internal { - -class ViewClickListener { - public: - virtual void OnViewClicked(views::View* sender) = 0; - - protected: - virtual ~ViewClickListener() {} -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_VIEW_CLICK_LISTENER_H_ diff --git a/chromium/ash/system/tray_accessibility.cc b/chromium/ash/system/tray_accessibility.cc deleted file mode 100644 index 8b1902df5e6..00000000000 --- a/chromium/ash/system/tray_accessibility.cc +++ /dev/null @@ -1,396 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray_accessibility.h" - -#include "ash/accessibility_delegate.h" -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/shell.h" -#include "ash/system/tray/hover_highlight_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_details_view.h" -#include "ash/system/tray/tray_item_more.h" -#include "ash/system/tray/tray_notification_view.h" -#include "ash/system/tray/tray_popup_label_button.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/widget/widget.h" - -namespace ash { -namespace internal { - -namespace { - -enum AccessibilityState { - A11Y_NONE = 0, - A11Y_SPOKEN_FEEDBACK = 1 << 0, - A11Y_HIGH_CONTRAST = 1 << 1, - A11Y_SCREEN_MAGNIFIER = 1 << 2, - A11Y_LARGE_CURSOR = 1 << 3, - A11Y_AUTOCLICK = 1 << 4, -}; - -uint32 GetAccessibilityState() { - AccessibilityDelegate* delegate = - Shell::GetInstance()->accessibility_delegate(); - uint32 state = A11Y_NONE; - if (delegate->IsSpokenFeedbackEnabled()) - state |= A11Y_SPOKEN_FEEDBACK; - if (delegate->IsHighContrastEnabled()) - state |= A11Y_HIGH_CONTRAST; - if (delegate->IsMagnifierEnabled()) - state |= A11Y_SCREEN_MAGNIFIER; - if (delegate->IsLargeCursorEnabled()) - state |= A11Y_LARGE_CURSOR; - if (delegate->IsAutoclickEnabled()) - state |= A11Y_AUTOCLICK; - return state; -} - -user::LoginStatus GetCurrentLoginStatus() { - return Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus(); -} - -} // namespace - -namespace tray { - -class DefaultAccessibilityView : public TrayItemMore { - public: - explicit DefaultAccessibilityView(SystemTrayItem* owner) - : TrayItemMore(owner, true) { - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK). - ToImageSkia()); - base::string16 label = bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_ACCESSIBILITY); - SetLabel(label); - SetAccessibleName(label); - } - - virtual ~DefaultAccessibilityView() { - } - - private: - DISALLOW_COPY_AND_ASSIGN(DefaultAccessibilityView); -}; - -class AccessibilityPopupView : public TrayNotificationView { - public: - AccessibilityPopupView(SystemTrayItem* owner) - : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK) { - InitView(GetLabel()); - } - - private: - views::Label* GetLabel() { - views::Label* label = new views::Label( - l10n_util::GetStringUTF16( - IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_BUBBLE)); - label->SetMultiLine(true); - label->SetHorizontalAlignment(gfx::ALIGN_LEFT); - return label; - } - - DISALLOW_COPY_AND_ASSIGN(AccessibilityPopupView); -}; - -//////////////////////////////////////////////////////////////////////////////// -// ash::internal::tray::AccessibilityDetailedView - -AccessibilityDetailedView::AccessibilityDetailedView( - SystemTrayItem* owner, user::LoginStatus login) : - TrayDetailsView(owner), - spoken_feedback_view_(NULL), - high_contrast_view_(NULL), - screen_magnifier_view_(NULL), - large_cursor_view_(NULL), - help_view_(NULL), - settings_view_(NULL), - autoclick_view_(NULL), - spoken_feedback_enabled_(false), - high_contrast_enabled_(false), - screen_magnifier_enabled_(false), - large_cursor_enabled_(false), - autoclick_enabled_(false), - login_(login) { - - Reset(); - - AppendAccessibilityList(); - AppendHelpEntries(); - CreateSpecialRow(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_TITLE, this); - - Layout(); -} - -void AccessibilityDetailedView::AppendAccessibilityList() { - CreateScrollableList(); - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - - AccessibilityDelegate* delegate = - Shell::GetInstance()->accessibility_delegate(); - spoken_feedback_enabled_ = delegate->IsSpokenFeedbackEnabled(); - spoken_feedback_view_ = AddScrollListItem( - bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SPOKEN_FEEDBACK), - spoken_feedback_enabled_ ? gfx::Font::BOLD : gfx::Font::NORMAL, - spoken_feedback_enabled_); - - // Large Cursor item is shown only in Login screen. - if (login_ == user::LOGGED_IN_NONE) { - large_cursor_enabled_ = delegate->IsLargeCursorEnabled(); - large_cursor_view_ = AddScrollListItem( - bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_ACCESSIBILITY_LARGE_CURSOR), - large_cursor_enabled_ ? gfx::Font::BOLD : gfx::Font::NORMAL, - large_cursor_enabled_); - } - - high_contrast_enabled_ = delegate->IsHighContrastEnabled(); - high_contrast_view_ = AddScrollListItem( - bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGH_CONTRAST_MODE), - high_contrast_enabled_ ? gfx::Font::BOLD : gfx::Font::NORMAL, - high_contrast_enabled_); - screen_magnifier_enabled_ = delegate->IsMagnifierEnabled(); - screen_magnifier_view_ = AddScrollListItem( - bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SCREEN_MAGNIFIER), - screen_magnifier_enabled_ ? gfx::Font::BOLD : gfx::Font::NORMAL, - screen_magnifier_enabled_); - - // Don't show autoclick option at login screen. - if (login_ != user::LOGGED_IN_NONE) { - autoclick_enabled_ = delegate->IsAutoclickEnabled(); - autoclick_view_ = AddScrollListItem( - bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_ACCESSIBILITY_AUTOCLICK), - autoclick_enabled_ ? gfx::Font::BOLD : gfx::Font::NORMAL, - autoclick_enabled_); - } -} - -void AccessibilityDetailedView::AppendHelpEntries() { - // Currently the help page requires a browser window. - // TODO(yoshiki): show this even on login/lock screen. crbug.com/158286 - if (login_ == user::LOGGED_IN_NONE || - login_ == user::LOGGED_IN_LOCKED) - return; - - views::View* bottom_row = new View(); - views::BoxLayout* layout = new - views::BoxLayout(views::BoxLayout::kHorizontal, - kTrayMenuBottomRowPadding, - kTrayMenuBottomRowPadding, - kTrayMenuBottomRowPaddingBetweenItems); - layout->set_spread_blank_space(true); - bottom_row->SetLayoutManager(layout); - - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - - TrayPopupLabelButton* help = new TrayPopupLabelButton( - this, - bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_ACCESSIBILITY_LEARN_MORE)); - bottom_row->AddChildView(help); - help_view_ = help; - - TrayPopupLabelButton* settings = new TrayPopupLabelButton( - this, - bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SETTINGS)); - bottom_row->AddChildView(settings); - settings_view_ = settings; - - AddChildView(bottom_row); -} - -HoverHighlightView* AccessibilityDetailedView::AddScrollListItem( - const base::string16& text, - gfx::Font::FontStyle style, - bool checked) { - HoverHighlightView* container = new HoverHighlightView(this); - container->AddCheckableLabel(text, style, checked); - scroll_content()->AddChildView(container); - return container; -} - -void AccessibilityDetailedView::OnViewClicked(views::View* sender) { - AccessibilityDelegate* delegate = - Shell::GetInstance()->accessibility_delegate(); - if (sender == footer()->content()) { - TransitionToDefaultView(); - } else if (sender == spoken_feedback_view_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - delegate->IsSpokenFeedbackEnabled() ? - ash::UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK : - ash::UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK); - delegate->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE); - } else if (sender == high_contrast_view_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - delegate->IsHighContrastEnabled() ? - ash::UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST : - ash::UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST); - delegate->ToggleHighContrast(); - } else if (sender == screen_magnifier_view_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - delegate->IsMagnifierEnabled() ? - ash::UMA_STATUS_AREA_DISABLE_MAGNIFIER : - ash::UMA_STATUS_AREA_ENABLE_MAGNIFIER); - delegate->SetMagnifierEnabled(!delegate->IsMagnifierEnabled()); - } else if (large_cursor_view_ && sender == large_cursor_view_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - delegate->IsLargeCursorEnabled() ? - ash::UMA_STATUS_AREA_DISABLE_LARGE_CURSOR : - ash::UMA_STATUS_AREA_ENABLE_LARGE_CURSOR); - delegate->SetLargeCursorEnabled(!delegate->IsLargeCursorEnabled()); - } else if (autoclick_view_ && sender == autoclick_view_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - delegate->IsAutoclickEnabled() ? - ash::UMA_STATUS_AREA_DISABLE_AUTO_CLICK : - ash::UMA_STATUS_AREA_ENABLE_AUTO_CLICK); - delegate->SetAutoclickEnabled(!delegate->IsAutoclickEnabled()); - } -} - -void AccessibilityDetailedView::ButtonPressed(views::Button* sender, - const ui::Event& event) { - SystemTrayDelegate* tray_delegate = - Shell::GetInstance()->system_tray_delegate(); - if (sender == help_view_) - tray_delegate->ShowAccessibilityHelp(); - else if (sender == settings_view_) - tray_delegate->ShowAccessibilitySettings(); -} - -} // namespace tray - -//////////////////////////////////////////////////////////////////////////////// -// ash::internal::TrayAccessibility - -TrayAccessibility::TrayAccessibility(SystemTray* system_tray) - : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_ACCESSIBILITY), - default_(NULL), - detailed_popup_(NULL), - detailed_menu_(NULL), - request_popup_view_(false), - tray_icon_visible_(false), - login_(GetCurrentLoginStatus()), - previous_accessibility_state_(GetAccessibilityState()), - show_a11y_menu_on_lock_screen_(true) { - DCHECK(Shell::GetInstance()->delegate()); - DCHECK(system_tray); - Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this); -} - -TrayAccessibility::~TrayAccessibility() { - Shell::GetInstance()->system_tray_notifier()-> - RemoveAccessibilityObserver(this); -} - -void TrayAccessibility::SetTrayIconVisible(bool visible) { - if (tray_view()) - tray_view()->SetVisible(visible); - tray_icon_visible_ = visible; -} - -tray::AccessibilityDetailedView* TrayAccessibility::CreateDetailedMenu() { - return new tray::AccessibilityDetailedView(this, login_); -} - -bool TrayAccessibility::GetInitialVisibility() { - // Shows accessibility icon if any accessibility feature is enabled. - // Otherwise, doen't show it. - return GetAccessibilityState() != A11Y_NONE; -} - -views::View* TrayAccessibility::CreateDefaultView(user::LoginStatus status) { - CHECK(default_ == NULL); - - // Shows accessibility menu if: - // - on login screen (not logged in); - // - "Enable accessibility menu" on chrome://settings is checked; - // - or any of accessibility features is enabled - // Otherwise, not shows it. - AccessibilityDelegate* delegate = - Shell::GetInstance()->accessibility_delegate(); - if (login_ != user::LOGGED_IN_NONE && - !delegate->ShouldShowAccessibilityMenu() && - // On login screen, keeps the initial visibility of the menu. - (status != user::LOGGED_IN_LOCKED || !show_a11y_menu_on_lock_screen_)) - return NULL; - - CHECK(default_ == NULL); - default_ = new tray::DefaultAccessibilityView(this); - - return default_; -} - -views::View* TrayAccessibility::CreateDetailedView(user::LoginStatus status) { - CHECK(detailed_popup_ == NULL); - CHECK(detailed_menu_ == NULL); - - if (request_popup_view_) { - detailed_popup_ = new tray::AccessibilityPopupView(this); - request_popup_view_ = false; - return detailed_popup_; - } else { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY); - detailed_menu_ = CreateDetailedMenu(); - return detailed_menu_; - } -} - -void TrayAccessibility::DestroyDefaultView() { - default_ = NULL; -} - -void TrayAccessibility::DestroyDetailedView() { - detailed_popup_ = NULL; - detailed_menu_ = NULL; -} - -void TrayAccessibility::UpdateAfterLoginStatusChange(user::LoginStatus status) { - // Stores the a11y feature status on just entering the lock screen. - if (login_ != user::LOGGED_IN_LOCKED && status == user::LOGGED_IN_LOCKED) - show_a11y_menu_on_lock_screen_ = (GetAccessibilityState() != A11Y_NONE); - - login_ = status; - SetTrayIconVisible(GetInitialVisibility()); -} - -void TrayAccessibility::OnAccessibilityModeChanged( - AccessibilityNotificationVisibility notify) { - SetTrayIconVisible(GetInitialVisibility()); - - uint32 accessibility_state = GetAccessibilityState(); - if ((notify == ash::A11Y_NOTIFICATION_SHOW) && - !(previous_accessibility_state_ & A11Y_SPOKEN_FEEDBACK) && - (accessibility_state & A11Y_SPOKEN_FEEDBACK)) { - // Shows popup if |notify| is true and the spoken feedback is being enabled. - request_popup_view_ = true; - PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); - } else { - if (detailed_popup_) - detailed_popup_->GetWidget()->Close(); - if (detailed_menu_) - detailed_menu_->GetWidget()->Close(); - } - - previous_accessibility_state_ = accessibility_state; -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray_accessibility.h b/chromium/ash/system/tray_accessibility.h deleted file mode 100644 index a3f53cbfec2..00000000000 --- a/chromium/ash/system/tray_accessibility.h +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_ACCESSIBILITY_H_ -#define ASH_SYSTEM_TRAY_ACCESSIBILITY_H_ - -#include "ash/accessibility_delegate.h" -#include "ash/shell_observer.h" -#include "ash/system/tray/tray_details_view.h" -#include "ash/system/tray/tray_image_item.h" -#include "ash/system/tray/view_click_listener.h" -#include "base/gtest_prod_util.h" -#include "ui/gfx/font.h" -#include "ui/views/controls/button/button.h" - -namespace chromeos { -class TrayAccessibilityTest; -} - -namespace views { -class Button; -class ImageView; -class View; -} - -namespace ash { - -class SystemTrayItem; - -class ASH_EXPORT AccessibilityObserver { - public: - virtual ~AccessibilityObserver() {} - - // Notifies when accessibilty mode changes. - virtual void OnAccessibilityModeChanged( - AccessibilityNotificationVisibility notify) = 0; -}; - -namespace internal { - -class HoverHighlightView; - -namespace tray { - -class AccessibilityPopupView; - -class AccessibilityDetailedView : public TrayDetailsView, - public ViewClickListener, - public views::ButtonListener, - public ShellObserver { - public: - explicit AccessibilityDetailedView(SystemTrayItem* owner, - user::LoginStatus login); - virtual ~AccessibilityDetailedView() {} - - private: - // Add the accessibility feature list. - void AppendAccessibilityList(); - - // Add help entries. - void AppendHelpEntries(); - - HoverHighlightView* AddScrollListItem(const base::string16& text, - gfx::Font::FontStyle style, - bool checked); - // Overridden from ViewClickListener. - virtual void OnViewClicked(views::View* sender) OVERRIDE; - // Overridden from ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE; - - views::View* spoken_feedback_view_; - views::View* high_contrast_view_; - views::View* screen_magnifier_view_;; - views::View* large_cursor_view_;; - views::View* help_view_; - views::View* settings_view_; - views::View* autoclick_view_; - - bool spoken_feedback_enabled_; - bool high_contrast_enabled_; - bool screen_magnifier_enabled_; - bool large_cursor_enabled_; - bool autoclick_enabled_; - user::LoginStatus login_; - - friend class chromeos::TrayAccessibilityTest; - DISALLOW_COPY_AND_ASSIGN(AccessibilityDetailedView); -}; - -} // namespace tray - -class TrayAccessibility : public TrayImageItem, - public AccessibilityObserver { - public: - explicit TrayAccessibility(SystemTray* system_tray); - virtual ~TrayAccessibility(); - - private: - void SetTrayIconVisible(bool visible); - tray::AccessibilityDetailedView* CreateDetailedMenu(); - - // Overridden from TrayImageItem. - virtual bool GetInitialVisibility() OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - - // Overridden from AccessibilityObserver. - virtual void OnAccessibilityModeChanged( - AccessibilityNotificationVisibility notify) OVERRIDE; - - views::View* default_; - tray::AccessibilityPopupView* detailed_popup_; - tray::AccessibilityDetailedView* detailed_menu_; - - bool request_popup_view_; - bool tray_icon_visible_; - user::LoginStatus login_; - - // Bitmap of values from AccessibilityState enum. - uint32 previous_accessibility_state_; - - // A11y feature status on just entering the lock screen. - bool show_a11y_menu_on_lock_screen_; - - friend class chromeos::TrayAccessibilityTest; - DISALLOW_COPY_AND_ASSIGN(TrayAccessibility); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_ACCESSIBILITY_H_ diff --git a/chromium/ash/system/tray_caps_lock.cc b/chromium/ash/system/tray_caps_lock.cc deleted file mode 100644 index ce7b976f0ec..00000000000 --- a/chromium/ash/system/tray_caps_lock.cc +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray_caps_lock.h" - -#include "ash/caps_lock_delegate.h" -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/shell.h" -#include "ash/system/tray/actionable_view.h" -#include "ash/system/tray/fixed_sized_image_view.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/widget/widget.h" - -namespace ash { -namespace internal { - -class CapsLockDefaultView : public ActionableView { - public: - CapsLockDefaultView() - : text_label_(new views::Label), - shortcut_label_(new views::Label) { - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, - kTrayPopupPaddingHorizontal, - 0, - kTrayPopupPaddingBetweenItems)); - - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - FixedSizedImageView* image = - new FixedSizedImageView(0, kTrayPopupItemHeight); - image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK). - ToImageSkia()); - AddChildView(image); - - text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); - AddChildView(text_label_); - - shortcut_label_->SetEnabled(false); - AddChildView(shortcut_label_); - } - - virtual ~CapsLockDefaultView() {} - - // Updates the label text and the shortcut text. - void Update(bool caps_lock_enabled, bool search_mapped_to_caps_lock) { - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - const int text_string_id = caps_lock_enabled ? - IDS_ASH_STATUS_TRAY_CAPS_LOCK_ENABLED : - IDS_ASH_STATUS_TRAY_CAPS_LOCK_DISABLED; - text_label_->SetText(bundle.GetLocalizedString(text_string_id)); - - int shortcut_string_id = 0; - if (caps_lock_enabled) { - shortcut_string_id = search_mapped_to_caps_lock ? - IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH_OR_SHIFT : - IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH_OR_SHIFT; - } else { - shortcut_string_id = search_mapped_to_caps_lock ? - IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH : - IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH; - } - shortcut_label_->SetText(bundle.GetLocalizedString(shortcut_string_id)); - - Layout(); - } - - private: - // Overridden from views::View: - virtual void Layout() OVERRIDE { - views::View::Layout(); - - // Align the shortcut text with the right end - const int old_x = shortcut_label_->x(); - const int new_x = - width() - shortcut_label_->width() - kTrayPopupPaddingHorizontal; - shortcut_label_->SetX(new_x); - const gfx::Size text_size = text_label_->size(); - text_label_->SetSize(gfx::Size(text_size.width() + new_x - old_x, - text_size.height())); - } - - virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE { - state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; - state->name = text_label_->text(); - } - - // Overridden from ActionableView: - virtual bool PerformAction(const ui::Event& event) OVERRIDE { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - Shell::GetInstance()->caps_lock_delegate()->IsCapsLockEnabled() ? - ash::UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK : - ash::UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK); - Shell::GetInstance()->caps_lock_delegate()->ToggleCapsLock(); - return true; - } - - views::Label* text_label_; - views::Label* shortcut_label_; - - DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView); -}; - -TrayCapsLock::TrayCapsLock(SystemTray* system_tray) - : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_CAPS_LOCK), - default_(NULL), - detailed_(NULL), - search_mapped_to_caps_lock_(false), - caps_lock_enabled_( - Shell::GetInstance()->caps_lock_delegate()->IsCapsLockEnabled()), - message_shown_(false) { - Shell::GetInstance()->system_tray_notifier()->AddCapsLockObserver(this); -} - -TrayCapsLock::~TrayCapsLock() { - Shell::GetInstance()->system_tray_notifier()->RemoveCapsLockObserver(this); -} - -bool TrayCapsLock::GetInitialVisibility() { - return Shell::GetInstance()->caps_lock_delegate()->IsCapsLockEnabled(); -} - -views::View* TrayCapsLock::CreateDefaultView(user::LoginStatus status) { - if (!caps_lock_enabled_) - return NULL; - DCHECK(default_ == NULL); - default_ = new CapsLockDefaultView; - default_->Update(caps_lock_enabled_, search_mapped_to_caps_lock_); - return default_; -} - -views::View* TrayCapsLock::CreateDetailedView(user::LoginStatus status) { - DCHECK(detailed_ == NULL); - detailed_ = new views::View; - - detailed_->SetLayoutManager(new - views::BoxLayout(views::BoxLayout::kHorizontal, - kTrayPopupPaddingHorizontal, 10, kTrayPopupPaddingBetweenItems)); - - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - views::ImageView* image = new views::ImageView; - image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK). - ToImageSkia()); - - detailed_->AddChildView(image); - - const int string_id = search_mapped_to_caps_lock_ ? - IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_SEARCH : - IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_ALT_SEARCH; - views::Label* label = new views::Label(bundle.GetLocalizedString(string_id)); - label->SetMultiLine(true); - label->SetHorizontalAlignment(gfx::ALIGN_LEFT); - detailed_->AddChildView(label); - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_CAPS_LOCK_DETAILED); - - return detailed_; -} - -void TrayCapsLock::DestroyDefaultView() { - default_ = NULL; -} - -void TrayCapsLock::DestroyDetailedView() { - detailed_ = NULL; -} - -void TrayCapsLock::OnCapsLockChanged(bool enabled, - bool search_mapped_to_caps_lock) { - if (tray_view()) - tray_view()->SetVisible(enabled); - - caps_lock_enabled_ = enabled; - search_mapped_to_caps_lock_ = search_mapped_to_caps_lock; - - if (default_) { - default_->Update(enabled, search_mapped_to_caps_lock); - } else { - if (enabled) { - if (!message_shown_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP); - PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); - message_shown_ = true; - } - } else if (detailed_) { - detailed_->GetWidget()->Close(); - } - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray_caps_lock.h b/chromium/ash/system/tray_caps_lock.h deleted file mode 100644 index a9e32b2bb73..00000000000 --- a/chromium/ash/system/tray_caps_lock.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_CAPS_LOCK_H_ -#define ASH_SYSTEM_TRAY_CAPS_LOCK_H_ - -#include "ash/system/tray/tray_image_item.h" - -namespace views { -class ImageView; -class View; -} - -namespace ash { - -class ASH_EXPORT CapsLockObserver { - public: - virtual ~CapsLockObserver() {} - - virtual void OnCapsLockChanged(bool enabled, - bool search_mapped_to_caps_lock) = 0; -}; - -namespace internal { - -class CapsLockDefaultView; - -class TrayCapsLock : public TrayImageItem, - public CapsLockObserver { - public: - explicit TrayCapsLock(SystemTray* system_tray); - virtual ~TrayCapsLock(); - - private: - // Overridden from TrayImageItem. - virtual bool GetInitialVisibility() OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - - // Overridden from CapsLockObserver. - virtual void OnCapsLockChanged(bool enabled, - bool search_mapped_to_caps_lock) OVERRIDE; - - CapsLockDefaultView* default_; - views::View* detailed_; - - bool search_mapped_to_caps_lock_; - bool caps_lock_enabled_; - bool message_shown_; - - DISALLOW_COPY_AND_ASSIGN(TrayCapsLock); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_CAPS_LOCK_H_ diff --git a/chromium/ash/system/tray_update.cc b/chromium/ash/system/tray_update.cc deleted file mode 100644 index e01dd97fcb2..00000000000 --- a/chromium/ash/system/tray_update.cc +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/tray_update.h" - -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_layout_manager.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/system/status_area_widget.h" -#include "ash/system/tray/fixed_sized_image_view.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "base/time/time.h" -#include "base/timer/timer.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "ui/aura/window.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/compositor/layer.h" -#include "ui/compositor/layer_animation_observer.h" -#include "ui/compositor/layer_animation_sequence.h" -#include "ui/gfx/image/image.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/widget/widget.h" - -namespace { - -// How many seconds should we wait before showing the nag reminder? -const int kUpdateNaggingTimeSeconds = 24 * 60 * 60; - -// How long should the nag reminder be displayed? -const int kShowUpdateNaggerForSeconds = 15; - -int DecideResource(ash::UpdateObserver::UpdateSeverity severity, bool dark) { - switch (severity) { - case ash::UpdateObserver::UPDATE_NORMAL: - return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK: - IDR_AURA_UBER_TRAY_UPDATE; - - case ash::UpdateObserver::UPDATE_LOW_GREEN: - return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN : - IDR_AURA_UBER_TRAY_UPDATE_GREEN; - - case ash::UpdateObserver::UPDATE_HIGH_ORANGE: - return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE : - IDR_AURA_UBER_TRAY_UPDATE_ORANGE; - - case ash::UpdateObserver::UPDATE_SEVERE_RED: - return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED : - IDR_AURA_UBER_TRAY_UPDATE_RED; - } - - NOTREACHED() << "Unknown update severity level."; - return 0; -} - -class UpdateView : public ash::internal::ActionableView { - public: - explicit UpdateView(ash::UpdateObserver::UpdateSeverity severity) { - SetLayoutManager(new - views::BoxLayout(views::BoxLayout::kHorizontal, - ash::kTrayPopupPaddingHorizontal, 0, - ash::kTrayPopupPaddingBetweenItems)); - - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - views::ImageView* image = - new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); - image->SetImage(bundle.GetImageNamed(DecideResource(severity, true)). - ToImageSkia()); - - AddChildView(image); - AddChildView(new views::Label( - bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE))); - SetAccessibleName(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE)); - } - - virtual ~UpdateView() {} - - private: - // Overridden from ActionableView. - virtual bool PerformAction(const ui::Event& event) OVERRIDE { - ash::Shell::GetInstance()-> - system_tray_delegate()->RequestRestartForUpdate(); - return true; - } - - DISALLOW_COPY_AND_ASSIGN(UpdateView); -}; - -} - -namespace ash { -namespace internal { - -namespace tray { - -class UpdateNagger : public ui::LayerAnimationObserver { - public: - explicit UpdateNagger(SystemTrayItem* owner) - : owner_(owner) { - RestartTimer(); - owner_->system_tray()->GetWidget()->GetNativeView()->layer()-> - GetAnimator()->AddObserver(this); - } - - virtual ~UpdateNagger() { - internal::StatusAreaWidget* status_area = - Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget(); - if (status_area) { - status_area->system_tray()->GetWidget()->GetNativeView()->layer()-> - GetAnimator()->RemoveObserver(this); - } - } - - void RestartTimer() { - timer_.Stop(); - timer_.Start(FROM_HERE, - base::TimeDelta::FromSeconds(kUpdateNaggingTimeSeconds), - this, - &UpdateNagger::Nag); - } - - private: - void Nag() { - owner_->PopupDetailedView(kShowUpdateNaggerForSeconds, false); - } - - // Overridden from ui::LayerAnimationObserver. - virtual void OnLayerAnimationEnded( - ui::LayerAnimationSequence* sequence) OVERRIDE { - // TODO(oshima): Find out if the updator will be shown on non - // primary display. - if (Shell::GetPrimaryRootWindowController()->shelf()->IsVisible()) - timer_.Stop(); - else if (!timer_.IsRunning()) - RestartTimer(); - } - - virtual void OnLayerAnimationAborted( - ui::LayerAnimationSequence* sequence) OVERRIDE {} - - virtual void OnLayerAnimationScheduled( - ui::LayerAnimationSequence* sequence) OVERRIDE {} - - SystemTrayItem* owner_; - base::OneShotTimer<UpdateNagger> timer_; - - DISALLOW_COPY_AND_ASSIGN(UpdateNagger); -}; - -} // namespace tray - -TrayUpdate::TrayUpdate(SystemTray* system_tray) - : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE), - severity_(UpdateObserver::UPDATE_NORMAL) { - Shell::GetInstance()->system_tray_notifier()->AddUpdateObserver(this); -} - -TrayUpdate::~TrayUpdate() { - Shell::GetInstance()->system_tray_notifier()->RemoveUpdateObserver(this); -} - -bool TrayUpdate::GetInitialVisibility() { - return Shell::GetInstance()->system_tray_delegate()->SystemShouldUpgrade(); -} - -views::View* TrayUpdate::CreateDefaultView(user::LoginStatus status) { - if (!Shell::GetInstance()->system_tray_delegate()->SystemShouldUpgrade()) - return NULL; - return new UpdateView(severity_); -} - -views::View* TrayUpdate::CreateDetailedView(user::LoginStatus status) { - return CreateDefaultView(status); -} - -void TrayUpdate::DestroyDetailedView() { - if (nagger_) { - // The nagger was being displayed. Now that the detailed view is being - // closed, that means either the user clicks on it to restart, or the user - // didn't click on it to restart. In either case, start the timer to show - // the nag reminder again after the specified time. - nagger_->RestartTimer(); - } -} - -void TrayUpdate::OnUpdateRecommended(UpdateObserver::UpdateSeverity severity) { - severity_ = severity; - SetImageFromResourceId(DecideResource(severity_, false)); - tray_view()->SetVisible(true); - if (!Shell::GetPrimaryRootWindowController()->shelf()->IsVisible() && - !nagger_.get()) { - // The shelf is not visible, and there is no nagger scheduled. - nagger_.reset(new tray::UpdateNagger(this)); - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/tray_update.h b/chromium/ash/system/tray_update.h deleted file mode 100644 index 123cde19f3b..00000000000 --- a/chromium/ash/system/tray_update.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_TRAY_UPDATE_H_ -#define ASH_SYSTEM_TRAY_UPDATE_H_ - -#include "ash/system/tray/tray_image_item.h" -#include "ash/system/user/update_observer.h" -#include "base/memory/scoped_ptr.h" - -namespace views { -class View; -} - -namespace ash { -namespace internal { - -namespace tray { -class UpdateNagger; -} - -class TrayUpdate : public TrayImageItem, - public UpdateObserver { - public: - explicit TrayUpdate(SystemTray* system_tray); - virtual ~TrayUpdate(); - - private: - // Overridden from TrayImageItem. - virtual bool GetInitialVisibility() OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - - // Overridden from UpdateObserver. - virtual void OnUpdateRecommended(UpdateSeverity severity) OVERRIDE; - - // Used to nag the user in case the tray has been hidden too long with an - // unseen update notification. - scoped_ptr<tray::UpdateNagger> nagger_; - - UpdateObserver::UpdateSeverity severity_; - - DISALLOW_COPY_AND_ASSIGN(TrayUpdate); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_TRAY_UPDATE_H_ diff --git a/chromium/ash/system/user/login_status.cc b/chromium/ash/system/user/login_status.cc deleted file mode 100644 index 93678fd2d3d..00000000000 --- a/chromium/ash/system/user/login_status.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/user/login_status.h" - -#include "ash/session_state_delegate.h" -#include "ash/shell.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "grit/ash_strings.h" -#include "ui/base/resource/resource_bundle.h" - -namespace ash { -namespace user { - -base::string16 GetLocalizedSignOutStringForStatus(LoginStatus status, - bool multiline) { - int message_id; - switch (status) { - case LOGGED_IN_GUEST: - message_id = IDS_ASH_STATUS_TRAY_EXIT_GUEST; - break; - case LOGGED_IN_RETAIL_MODE: - message_id = IDS_ASH_STATUS_TRAY_EXIT_KIOSK; - break; - case LOGGED_IN_PUBLIC: - message_id = IDS_ASH_STATUS_TRAY_EXIT_PUBLIC; - break; - default: - if (ash::Shell::GetInstance()->session_state_delegate()-> - NumberOfLoggedInUsers() > 1) { - message_id = IDS_ASH_STATUS_TRAY_SIGN_OUT_ALL; - } else { - message_id = IDS_ASH_STATUS_TRAY_SIGN_OUT; - } - break; - } - base::string16 message = - ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id); - // Desirable line breaking points are marked using \n. As the resource - // framework does not evaluate escape sequences, the \n need to be explicitly - // handled. Depending on the value of |multiline|, actual line breaks or - // spaces are substituted. - base::string16 newline = multiline ? ASCIIToUTF16("\n") : ASCIIToUTF16(" "); - ReplaceSubstringsAfterOffset(&message, 0, ASCIIToUTF16("\\n"), newline); - return message; -} - -} // namespace user -} // namespace ash diff --git a/chromium/ash/system/user/login_status.h b/chromium/ash/system/user/login_status.h deleted file mode 100644 index d08a1604a06..00000000000 --- a/chromium/ash/system/user/login_status.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_USER_LOGIN_STATUS_H_ -#define ASH_SYSTEM_USER_LOGIN_STATUS_H_ - -#include "base/strings/string16.h" - -namespace ash { -namespace user { - -enum LoginStatus { - LOGGED_IN_NONE, // Not logged in - LOGGED_IN_LOCKED, // A user has locked the screen - LOGGED_IN_USER, // A regular user is logged in - LOGGED_IN_OWNER, // The owner of the device is logged in - LOGGED_IN_GUEST, // A guest is logged in (i.e. incognito) - LOGGED_IN_RETAIL_MODE, // Is in retail mode - LOGGED_IN_PUBLIC, // A public account is logged in - LOGGED_IN_LOCALLY_MANAGED, // A locally managed user is logged in - LOGGED_IN_KIOSK_APP // Is in kiosk app mode -}; - -base::string16 GetLocalizedSignOutStringForStatus(LoginStatus status, - bool multiline); - -} // namespace user -} // namespace ash - -#endif // ASH_SYSTEM_USER_LOGIN_STATUS_H_ diff --git a/chromium/ash/system/user/tray_user.cc b/chromium/ash/system/user/tray_user.cc deleted file mode 100644 index ff14fe168c0..00000000000 --- a/chromium/ash/system/user/tray_user.cc +++ /dev/null @@ -1,1425 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/user/tray_user.h" - -#include <algorithm> -#include <climits> -#include <vector> - -#include "ash/ash_switches.h" -#include "ash/metrics/user_metrics_recorder.h" -#include "ash/multi_profile_uma.h" -#include "ash/popup_message.h" -#include "ash/root_window_controller.h" -#include "ash/session_state_delegate.h" -#include "ash/shelf/shelf_layout_manager.h" -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_delegate.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_item_view.h" -#include "ash/system/tray/tray_popup_label_button.h" -#include "ash/system/tray/tray_popup_label_button_border.h" -#include "ash/system/tray/tray_utils.h" -#include "base/i18n/rtl.h" -#include "base/logging.h" -#include "base/memory/scoped_vector.h" -#include "base/strings/string16.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "grit/ash_resources.h" -#include "grit/ash_strings.h" -#include "skia/ext/image_operations.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkPaint.h" -#include "third_party/skia/include/core/SkPath.h" -#include "ui/aura/window.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/font_list.h" -#include "ui/gfx/image/image.h" -#include "ui/gfx/image/image_skia_operations.h" -#include "ui/gfx/insets.h" -#include "ui/gfx/range/range.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/render_text.h" -#include "ui/gfx/size.h" -#include "ui/gfx/skia_util.h" -#include "ui/gfx/text_elider.h" -#include "ui/gfx/text_utils.h" -#include "ui/views/border.h" -#include "ui/views/bubble/tray_bubble_view.h" -#include "ui/views/controls/button/button.h" -#include "ui/views/controls/button/custom_button.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/controls/link.h" -#include "ui/views/controls/link_listener.h" -#include "ui/views/corewm/shadow_types.h" -#include "ui/views/layout/box_layout.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/mouse_watcher.h" -#include "ui/views/painter.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -namespace { - -const int kUserDetailsVerticalPadding = 5; -const int kUserCardVerticalPadding = 10; -const int kProfileRoundedCornerRadius = 2; -const int kUserIconSize = 27; -const int kUserIconLargeSize = 32; -const int kUserIconLargeCornerRadius = 2; -const int kUserLabelToIconPadding = 5; -// When using multi login, this spacing is added between user icons. -const int kTrayLabelSpacing = 1; - -// When a hover border is used, it is starting this many pixels before the icon -// position. -const int kTrayUserTileHoverBorderInset = 10; - -// The border color of the user button. -const SkColor kBorderColor = 0xffdcdcdc; - -// The invisible word joiner character, used as a marker to indicate the start -// and end of the user's display name in the public account user card's text. -const char16 kDisplayNameMark[] = { 0x2060, 0 }; - -const int kPublicAccountLogoutButtonBorderImagesNormal[] = { - IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, - IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, - IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, -}; - -const int kPublicAccountLogoutButtonBorderImagesHovered[] = { - IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_LABEL_BUTTON_HOVER_BACKGROUND, - IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, - IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, -}; - -// Offsetting the popup message relative to the tray menu. -const int kPopupMessageOffset = 25; - -// Switch to a user with the given |user_index|. -void SwitchUser(ash::MultiProfileIndex user_index) { - // Do not switch users when the log screen is presented. - if (ash::Shell::GetInstance()->session_state_delegate()-> - IsUserSessionBlocked()) - return; - - DCHECK(user_index > 0); - ash::SessionStateDelegate* delegate = - ash::Shell::GetInstance()->session_state_delegate(); - ash::MultiProfileUMA::RecordSwitchActiveUser( - ash::MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); - delegate->SwitchActiveUser(delegate->GetUserID(user_index)); -} - -} // namespace - -namespace ash { -namespace internal { - -namespace tray { - -// A custom image view with rounded edges. -class RoundedImageView : public views::View { - public: - // Constructs a new rounded image view with rounded corners of radius - // |corner_radius|. If |active_user| is set, the icon will be drawn in - // full colors - otherwise it will fade into the background. - RoundedImageView(int corner_radius, bool active_user); - virtual ~RoundedImageView(); - - // Set the image that should be displayed. The image contents is copied to the - // receiver's image. - void SetImage(const gfx::ImageSkia& img, const gfx::Size& size); - - // Set the radii of the corners independently. - void SetCornerRadii(int top_left, - int top_right, - int bottom_right, - int bottom_left); - - private: - // Overridden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; - - gfx::ImageSkia image_; - gfx::ImageSkia resized_; - gfx::Size image_size_; - int corner_radius_[4]; - - // True if the given user is the active user and the icon should get - // painted as active. - bool active_user_; - - DISALLOW_COPY_AND_ASSIGN(RoundedImageView); -}; - -// An inactive user view which can be clicked to make active. Note that this -// "button" does not show as a button any click or hover changes. -class UserSwitcherView : public RoundedImageView { - public: - UserSwitcherView(int corner_radius, MultiProfileIndex user_index); - virtual ~UserSwitcherView() {} - - virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; - virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; - - private: - // The user index to activate when the item was clicked. Note that this - // index refers to the LRU list of logged in users. - MultiProfileIndex user_index_; - - DISALLOW_COPY_AND_ASSIGN(UserSwitcherView); -}; - -// The user details shown in public account mode. This is essentially a label -// but with custom painting code as the text is styled with multiple colors and -// contains a link. -class PublicAccountUserDetails : public views::View, - public views::LinkListener { - public: - PublicAccountUserDetails(SystemTrayItem* owner, int used_width); - virtual ~PublicAccountUserDetails(); - - private: - // Overridden from views::View. - virtual void Layout() OVERRIDE; - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; - - // Overridden from views::LinkListener. - virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; - - // Calculate a preferred size that ensures the label text and the following - // link do not wrap over more than three lines in total for aesthetic reasons - // if possible. - void CalculatePreferredSize(SystemTrayItem* owner, int used_width); - - base::string16 text_; - views::Link* learn_more_; - gfx::Size preferred_size_; - ScopedVector<gfx::RenderText> lines_; - - DISALLOW_COPY_AND_ASSIGN(PublicAccountUserDetails); -}; - -// The button which holds the user card in case of multi profile. -class UserCard : public views::CustomButton { - public: - UserCard(views::ButtonListener* listener, bool active_user); - virtual ~UserCard(); - - // Called when the border should remain even in the non highlighted state. - void ForceBorderVisible(bool show); - - // Overridden from views::View - virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; - virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; - - // Check if the item is hovered. - bool is_hovered_for_test() {return button_hovered_; } - - private: - // Change the hover/active state of the "button" when the status changes. - void ShowActive(); - - // True if this is the active user. - bool is_active_user_; - - // True if button is hovered. - bool button_hovered_; - - // True if the border should be visible. - bool show_border_; - - DISALLOW_COPY_AND_ASSIGN(UserCard); -}; - -class UserViewMouseWatcherHost : public views::MouseWatcherHost { -public: - explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area) - : screen_area_(screen_area) {} - virtual ~UserViewMouseWatcherHost() {} - - // Implementation of MouseWatcherHost. - virtual bool Contains(const gfx::Point& screen_point, - views::MouseWatcherHost::MouseEventType type) OVERRIDE { - return screen_area_.Contains(screen_point); - } - -private: - gfx::Rect screen_area_; - - DISALLOW_COPY_AND_ASSIGN(UserViewMouseWatcherHost); -}; - -// The view of a user item. -class UserView : public views::View, - public views::ButtonListener, - public views::MouseWatcherListener { - public: - UserView(SystemTrayItem* owner, - ash::user::LoginStatus login, - MultiProfileIndex index); - virtual ~UserView(); - - // Overridden from MouseWatcherListener: - virtual void MouseMovedOutOfHost() OVERRIDE; - - TrayUser::TestState GetStateForTest() const; - gfx::Rect GetBoundsInScreenOfUserButtonForTest(); - - private: - // Overridden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual int GetHeightForWidth(int width) OVERRIDE; - virtual void Layout() OVERRIDE; - - // Overridden from views::ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE; - - void AddLogoutButton(user::LoginStatus login); - void AddUserCard(SystemTrayItem* owner, user::LoginStatus login); - - // Create a user icon representation for the user card. - views::View* CreateIconForUserCard(user::LoginStatus login); - - // Create the additional user card content for the retail logged in mode. - void AddLoggedInRetailModeUserCardContent(); - - // Create the additional user card content for the public mode. - void AddLoggedInPublicModeUserCardContent(SystemTrayItem* owner); - - // Create the menu option to add another user. If |disabled| is set the user - // cannot actively click on the item. - void ToggleAddUserMenuOption(); - - // Returns true when multi profile is supported. - bool SupportsMultiProfile(); - - MultiProfileIndex multiprofile_index_; - // The view of the user card. - views::View* user_card_view_; - - // This is the owner system tray item of this view. - SystemTrayItem* owner_; - - // True if |user_card_view_| is a |UserView| - otherwise it is only a - // |views::View|. - bool is_user_card_; - views::View* logout_button_; - scoped_ptr<PopupMessage> popup_message_; - scoped_ptr<views::Widget> add_menu_option_; - - // True when the add user panel is visible but not activatable. - bool add_user_visible_but_disabled_; - - // The mouse watcher which takes care of out of window hover events. - scoped_ptr<views::MouseWatcher> mouse_watcher_; - - DISALLOW_COPY_AND_ASSIGN(UserView); -}; - -// The menu item view which gets shown when the user clicks in multi profile -// mode onto the user item. -class AddUserView : public views::CustomButton, - public views::ButtonListener { - public: - // The |owner| is the view for which this view gets created. The |listener| - // will get notified when this item gets clicked. - AddUserView(UserCard* owner, views::ButtonListener* listener); - virtual ~AddUserView(); - - // Get the anchor view for a message. - views::View* anchor() { return anchor_; } - - // Overridden from views::ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE; - - private: - // Overridden from views::View. - virtual gfx::Size GetPreferredSize() OVERRIDE; - virtual int GetHeightForWidth(int width) OVERRIDE; - virtual void Layout() OVERRIDE; - - // Create the additional client content for this item. - void AddContent(); - - // This is the content we create and show. - views::View* add_user_; - - // This listener will get informed when someone clicks on this button. - views::ButtonListener* listener_; - - // This is the owner view of this item. - UserCard* owner_; - - // The anchor view for targetted bubble messages. - views::View* anchor_; - - DISALLOW_COPY_AND_ASSIGN(AddUserView); -}; - -RoundedImageView::RoundedImageView(int corner_radius, bool active_user) - : active_user_(active_user) { - for (int i = 0; i < 4; ++i) - corner_radius_[i] = corner_radius; -} - -RoundedImageView::~RoundedImageView() {} - -void RoundedImageView::SetImage(const gfx::ImageSkia& img, - const gfx::Size& size) { - image_ = img; - image_size_ = size; - - // Try to get the best image quality for the avatar. - resized_ = gfx::ImageSkiaOperations::CreateResizedImage(image_, - skia::ImageOperations::RESIZE_BEST, size); - if (GetWidget() && visible()) { - PreferredSizeChanged(); - SchedulePaint(); - } -} - -void RoundedImageView::SetCornerRadii(int top_left, - int top_right, - int bottom_right, - int bottom_left) { - corner_radius_[0] = top_left; - corner_radius_[1] = top_right; - corner_radius_[2] = bottom_right; - corner_radius_[3] = bottom_left; -} - -gfx::Size RoundedImageView::GetPreferredSize() { - return gfx::Size(image_size_.width() + GetInsets().width(), - image_size_.height() + GetInsets().height()); -} - -void RoundedImageView::OnPaint(gfx::Canvas* canvas) { - View::OnPaint(canvas); - gfx::Rect image_bounds(size()); - image_bounds.ClampToCenteredSize(GetPreferredSize()); - image_bounds.Inset(GetInsets()); - const SkScalar kRadius[8] = { - SkIntToScalar(corner_radius_[0]), - SkIntToScalar(corner_radius_[0]), - SkIntToScalar(corner_radius_[1]), - SkIntToScalar(corner_radius_[1]), - SkIntToScalar(corner_radius_[2]), - SkIntToScalar(corner_radius_[2]), - SkIntToScalar(corner_radius_[3]), - SkIntToScalar(corner_radius_[3]) - }; - SkPath path; - path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius); - SkPaint paint; - paint.setAntiAlias(true); - paint.setXfermodeMode(active_user_ ? SkXfermode::kSrcOver_Mode : - SkXfermode::kLuminosity_Mode); - canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(), - path, paint); -} - -UserSwitcherView::UserSwitcherView(int corner_radius, - MultiProfileIndex user_index) - : RoundedImageView(corner_radius, false), - user_index_(user_index) { - SetEnabled(true); -} - -void UserSwitcherView::OnMouseEvent(ui::MouseEvent* event) { - if (event->type() == ui::ET_MOUSE_PRESSED) { - SwitchUser(user_index_); - event->SetHandled(); - } -} - -void UserSwitcherView::OnTouchEvent(ui::TouchEvent* event) { - if (event->type() == ui::ET_TOUCH_PRESSED) { - SwitchUser(user_index_); - event->SetHandled(); - } -} - -PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner, - int used_width) - : learn_more_(NULL) { - const int inner_padding = - kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; - const bool rtl = base::i18n::IsRTL(); - set_border(views::Border::CreateEmptyBorder( - kUserDetailsVerticalPadding, rtl ? 0 : inner_padding, - kUserDetailsVerticalPadding, rtl ? inner_padding : 0)); - - // Retrieve the user's display name and wrap it with markers. - // Note that since this is a public account it always has to be the primary - // user. - base::string16 display_name = - Shell::GetInstance()->session_state_delegate()->GetUserDisplayName(0); - base::RemoveChars(display_name, kDisplayNameMark, &display_name); - display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0]; - // Retrieve the domain managing the device and wrap it with markers. - base::string16 domain = UTF8ToUTF16( - Shell::GetInstance()->system_tray_delegate()->GetEnterpriseDomain()); - base::RemoveChars(domain, kDisplayNameMark, &domain); - base::i18n::WrapStringWithLTRFormatting(&domain); - // Retrieve the label text, inserting the display name and domain. - text_ = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_PUBLIC_LABEL, - display_name, domain); - - learn_more_ = new views::Link(l10n_util::GetStringUTF16(IDS_ASH_LEARN_MORE)); - learn_more_->SetUnderline(false); - learn_more_->set_listener(this); - AddChildView(learn_more_); - - CalculatePreferredSize(owner, used_width); -} - -PublicAccountUserDetails::~PublicAccountUserDetails() {} - -void PublicAccountUserDetails::Layout() { - lines_.clear(); - const gfx::Rect contents_area = GetContentsBounds(); - if (contents_area.IsEmpty()) - return; - - // Word-wrap the label text. - const gfx::FontList font_list; - std::vector<base::string16> lines; - gfx::ElideRectangleText(text_, font_list, contents_area.width(), - contents_area.height(), gfx::ELIDE_LONG_WORDS, - &lines); - // Loop through the lines, creating a renderer for each. - gfx::Point position = contents_area.origin(); - gfx::Range display_name(gfx::Range::InvalidRange()); - for (std::vector<base::string16>::const_iterator it = lines.begin(); - it != lines.end(); ++it) { - gfx::RenderText* line = gfx::RenderText::CreateInstance(); - line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI); - line->SetText(*it); - const gfx::Size size(contents_area.width(), line->GetStringSize().height()); - line->SetDisplayRect(gfx::Rect(position, size)); - position.set_y(position.y() + size.height()); - - // Set the default text color for the line. - line->SetColor(kPublicAccountUserCardTextColor); - - // If a range of the line contains the user's display name, apply a custom - // text color to it. - if (display_name.is_empty()) - display_name.set_start(it->find(kDisplayNameMark)); - if (!display_name.is_empty()) { - display_name.set_end( - it->find(kDisplayNameMark, display_name.start() + 1)); - gfx::Range line_range(0, it->size()); - line->ApplyColor(kPublicAccountUserCardNameColor, - display_name.Intersect(line_range)); - // Update the range for the next line. - if (display_name.end() >= line_range.end()) - display_name.set_start(0); - else - display_name = gfx::Range::InvalidRange(); - } - - lines_.push_back(line); - } - - // Position the link after the label text, separated by a space. If it does - // not fit onto the last line of the text, wrap the link onto its own line. - const gfx::Size last_line_size = lines_.back()->GetStringSize(); - const int space_width = gfx::GetStringWidth(ASCIIToUTF16(" "), font_list); - const gfx::Size link_size = learn_more_->GetPreferredSize(); - if (contents_area.width() - last_line_size.width() >= - space_width + link_size.width()) { - position.set_x(position.x() + last_line_size.width() + space_width); - position.set_y(position.y() - last_line_size.height()); - } - position.set_y(position.y() - learn_more_->GetInsets().top()); - gfx::Rect learn_more_bounds(position, link_size); - learn_more_bounds.Intersect(contents_area); - if (base::i18n::IsRTL()) { - const gfx::Insets insets = GetInsets(); - learn_more_bounds.Offset(insets.right() - insets.left(), 0); - } - learn_more_->SetBoundsRect(learn_more_bounds); -} - -gfx::Size PublicAccountUserDetails::GetPreferredSize() { - return preferred_size_; -} - -void PublicAccountUserDetails::OnPaint(gfx::Canvas* canvas) { - for (ScopedVector<gfx::RenderText>::const_iterator it = lines_.begin(); - it != lines_.end(); ++it) { - (*it)->Draw(canvas); - } - views::View::OnPaint(canvas); -} - -void PublicAccountUserDetails::LinkClicked(views::Link* source, - int event_flags) { - DCHECK_EQ(source, learn_more_); - Shell::GetInstance()->system_tray_delegate()->ShowPublicAccountInfo(); -} - -void PublicAccountUserDetails::CalculatePreferredSize(SystemTrayItem* owner, - int used_width) { - const gfx::FontList font_list; - const gfx::Size link_size = learn_more_->GetPreferredSize(); - const int space_width = gfx::GetStringWidth(ASCIIToUTF16(" "), font_list); - const gfx::Insets insets = GetInsets(); - views::TrayBubbleView* bubble_view = - owner->system_tray()->GetSystemBubble()->bubble_view(); - int min_width = std::max( - link_size.width(), - bubble_view->GetPreferredSize().width() - (used_width + insets.width())); - int max_width = std::min( - gfx::GetStringWidth(text_, font_list) + space_width + link_size.width(), - bubble_view->GetMaximumSize().width() - (used_width + insets.width())); - // Do a binary search for the minimum width that ensures no more than three - // lines are needed. The lower bound is the minimum of the current bubble - // width and the width of the link (as no wrapping is permitted inside the - // link). The upper bound is the maximum of the largest allowed bubble width - // and the sum of the label text and link widths when put on a single line. - std::vector<base::string16> lines; - while (min_width < max_width) { - lines.clear(); - const int width = (min_width + max_width) / 2; - const bool too_narrow = - gfx::ElideRectangleText(text_, font_list, width, INT_MAX, - gfx::TRUNCATE_LONG_WORDS, &lines) != 0; - int line_count = lines.size(); - if (!too_narrow && line_count == 3 && - width - gfx::GetStringWidth(lines.back(), font_list) <= - space_width + link_size.width()) - ++line_count; - if (too_narrow || line_count > 3) - min_width = width + 1; - else - max_width = width; - } - - // Calculate the corresponding height and set the preferred size. - lines.clear(); - gfx::ElideRectangleText( - text_, font_list, min_width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines); - int line_count = lines.size(); - if (min_width - gfx::GetStringWidth(lines.back(), font_list) <= - space_width + link_size.width()) { - ++line_count; - } - const int line_height = font_list.GetHeight(); - const int link_extra_height = std::max( - link_size.height() - learn_more_->GetInsets().top() - line_height, 0); - preferred_size_ = gfx::Size( - min_width + insets.width(), - line_count * line_height + link_extra_height + insets.height()); - - bubble_view->SetWidth(preferred_size_.width() + used_width); -} - -UserCard::UserCard(views::ButtonListener* listener, bool active_user) - : CustomButton(listener), - is_active_user_(active_user), - button_hovered_(false), - show_border_(false) { - if (is_active_user_) { - set_background( - views::Background::CreateSolidBackground(kBackgroundColor)); - ShowActive(); - } -} - -UserCard::~UserCard() {} - -void UserCard::ForceBorderVisible(bool show) { - show_border_ = show; - ShowActive(); -} - -void UserCard::OnMouseEntered(const ui::MouseEvent& event) { - if (is_active_user_) { - button_hovered_ = true; - background()->SetNativeControlColor(kHoverBackgroundColor); - ShowActive(); - } -} - -void UserCard::OnMouseExited(const ui::MouseEvent& event) { - if (is_active_user_) { - button_hovered_ = false; - background()->SetNativeControlColor(kBackgroundColor); - ShowActive(); - } -} - -void UserCard::ShowActive() { - int width = button_hovered_ || show_border_ ? 1 : 0; - set_border(views::Border::CreateSolidSidedBorder(width, width, width, 1, - kBorderColor)); - SchedulePaint(); -} - -UserView::UserView(SystemTrayItem* owner, - user::LoginStatus login, - MultiProfileIndex index) - : multiprofile_index_(index), - user_card_view_(NULL), - owner_(owner), - is_user_card_(false), - logout_button_(NULL), - add_user_visible_but_disabled_(false) { - CHECK_NE(user::LOGGED_IN_NONE, login); - if (!index) { - // Only the logged in user will have a background. All other users will have - // to allow the TrayPopupContainer highlighting the menu line. - set_background(views::Background::CreateSolidBackground( - login == user::LOGGED_IN_PUBLIC ? kPublicAccountBackgroundColor : - kBackgroundColor)); - } - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, - kTrayPopupPaddingBetweenItems)); - // The logout button must be added before the user card so that the user card - // can correctly calculate the remaining available width. - // Note that only the current multiprofile user gets a button. - if (!multiprofile_index_) - AddLogoutButton(login); - AddUserCard(owner, login); -} - -UserView::~UserView() {} - -void UserView::MouseMovedOutOfHost() { - popup_message_.reset(); - mouse_watcher_.reset(); - add_menu_option_.reset(); -} - -TrayUser::TestState UserView::GetStateForTest() const { - if (add_menu_option_.get()) { - return add_user_visible_but_disabled_ ? TrayUser::ACTIVE_BUT_DISABLED : - TrayUser::ACTIVE; - } - - if (!is_user_card_) - return TrayUser::SHOWN; - - return static_cast<UserCard*>(user_card_view_)->is_hovered_for_test() ? - TrayUser::HOVERED : TrayUser::SHOWN; -} - -gfx::Rect UserView::GetBoundsInScreenOfUserButtonForTest() { - DCHECK(user_card_view_); - return user_card_view_->GetBoundsInScreen(); -} - -gfx::Size UserView::GetPreferredSize() { - gfx::Size size = views::View::GetPreferredSize(); - // Only the active user panel will be forced to a certain height. - if (!multiprofile_index_) { - size.set_height(std::max(size.height(), - kTrayPopupItemHeight + GetInsets().height())); - } - return size; -} - -int UserView::GetHeightForWidth(int width) { - return GetPreferredSize().height(); -} - -void UserView::Layout() { - gfx::Rect contents_area(GetContentsBounds()); - if (user_card_view_ && logout_button_) { - // Give the logout button the space it requests. - gfx::Rect logout_area = contents_area; - logout_area.ClampToCenteredSize(logout_button_->GetPreferredSize()); - logout_area.set_x(contents_area.right() - logout_area.width()); - - // Give the remaining space to the user card. - gfx::Rect user_card_area = contents_area; - int remaining_width = contents_area.width() - logout_area.width(); - if (SupportsMultiProfile()) { - // In multiprofile case |user_card_view_| and |logout_button_| have to - // have the same height. - int y = std::min(user_card_area.y(), logout_area.y()); - int height = std::max(user_card_area.height(), logout_area.height()); - logout_area.set_y(y); - logout_area.set_height(height); - user_card_area.set_y(y); - user_card_area.set_height(height); - - // In multiprofile mode we have also to increase the size of the card by - // the size of the border to make it overlap with the logout button. - user_card_area.set_width(std::max(0, remaining_width + 1)); - - // To make the logout button symmetrical with the user card we also make - // the button longer by the same size the hover area in front of the icon - // got inset. - logout_area.set_width(logout_area.width() + - kTrayUserTileHoverBorderInset); - } else { - // In all other modes we have to make sure that there is enough spacing - // between the two. - remaining_width -= kTrayPopupPaddingBetweenItems; - } - user_card_area.set_width(remaining_width); - user_card_view_->SetBoundsRect(user_card_area); - logout_button_->SetBoundsRect(logout_area); - } else if (user_card_view_) { - user_card_view_->SetBoundsRect(contents_area); - } else if (logout_button_) { - logout_button_->SetBoundsRect(contents_area); - } -} - -void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { - if (sender == logout_button_) { - Shell::GetInstance()->metrics()->RecordUserMetricsAction( - ash::UMA_STATUS_AREA_SIGN_OUT); - Shell::GetInstance()->system_tray_delegate()->SignOut(); - } else if (sender == user_card_view_ && SupportsMultiProfile()) { - if (!multiprofile_index_) { - ToggleAddUserMenuOption(); - } else { - SwitchUser(multiprofile_index_); - // Since the user list is about to change the system menu should get - // closed. - owner_->system_tray()->CloseSystemBubble(); - } - } else if (add_menu_option_.get() && - sender == add_menu_option_->GetContentsView()) { - // Let the user add another account to the session. - MultiProfileUMA::RecordSigninUser(MultiProfileUMA::SIGNIN_USER_BY_TRAY); - Shell::GetInstance()->system_tray_delegate()->ShowUserLogin(); - } else { - NOTREACHED(); - } -} - -void UserView::AddLogoutButton(user::LoginStatus login) { - const base::string16 title = user::GetLocalizedSignOutStringForStatus(login, - true); - TrayPopupLabelButton* logout_button = new TrayPopupLabelButton(this, title); - logout_button->SetAccessibleName(title); - logout_button_ = logout_button; - // In public account mode, the logout button border has a custom color. - if (login == user::LOGGED_IN_PUBLIC) { - TrayPopupLabelButtonBorder* border = - static_cast<TrayPopupLabelButtonBorder*>(logout_button_->border()); - border->SetPainter(false, views::Button::STATE_NORMAL, - views::Painter::CreateImageGridPainter( - kPublicAccountLogoutButtonBorderImagesNormal)); - border->SetPainter(false, views::Button::STATE_HOVERED, - views::Painter::CreateImageGridPainter( - kPublicAccountLogoutButtonBorderImagesHovered)); - border->SetPainter(false, views::Button::STATE_PRESSED, - views::Painter::CreateImageGridPainter( - kPublicAccountLogoutButtonBorderImagesHovered)); - } - AddChildView(logout_button_); -} - -void UserView::AddUserCard(SystemTrayItem* owner, user::LoginStatus login) { - // Add padding around the panel. - set_border(views::Border::CreateEmptyBorder( - kUserCardVerticalPadding, kTrayPopupPaddingHorizontal, - kUserCardVerticalPadding, kTrayPopupPaddingHorizontal)); - - if (SupportsMultiProfile() && login != user::LOGGED_IN_RETAIL_MODE) { - user_card_view_ = new UserCard(this, multiprofile_index_ == 0); - is_user_card_ = true; - } else { - user_card_view_ = new views::View(); - is_user_card_ = false; - } - - user_card_view_->SetLayoutManager(new views::BoxLayout( - views::BoxLayout::kHorizontal, 0, 0 , kTrayPopupPaddingBetweenItems)); - AddChildViewAt(user_card_view_, 0); - - if (login == user::LOGGED_IN_RETAIL_MODE) { - AddLoggedInRetailModeUserCardContent(); - return; - } - - // The entire user card should trigger hover (the inner items get disabled). - user_card_view_->SetEnabled(true); - user_card_view_->set_notify_enter_exit_on_child(true); - - if (login == user::LOGGED_IN_PUBLIC) { - AddLoggedInPublicModeUserCardContent(owner); - return; - } - - views::View* icon = CreateIconForUserCard(login); - user_card_view_->AddChildView(icon); - - // To allow the border to start before the icon, reduce the size before and - // add an inset to the icon to get the spacing. - if (multiprofile_index_ == 0 && SupportsMultiProfile()) { - icon->set_border(views::Border::CreateEmptyBorder( - 0, kTrayUserTileHoverBorderInset, 0, 0)); - set_border(views::Border::CreateEmptyBorder( - kUserCardVerticalPadding, - kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset, - kUserCardVerticalPadding, - kTrayPopupPaddingHorizontal)); - } - SessionStateDelegate* delegate = - Shell::GetInstance()->session_state_delegate(); - views::Label* username = NULL; - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - if (!multiprofile_index_) { - base::string16 user_name_string = - login == user::LOGGED_IN_GUEST ? - bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL) : - delegate->GetUserDisplayName(multiprofile_index_); - if (!user_name_string.empty()) { - username = new views::Label(user_name_string); - username->SetHorizontalAlignment(gfx::ALIGN_LEFT); - } - } - - views::Label* additional = NULL; - if (login != user::LOGGED_IN_GUEST) { - base::string16 user_email_string = - login == user::LOGGED_IN_LOCALLY_MANAGED ? - bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL) : - UTF8ToUTF16(delegate->GetUserEmail(multiprofile_index_)); - if (!user_email_string.empty()) { - additional = new views::Label(user_email_string); - additional->SetFontList( - bundle.GetFontList(ui::ResourceBundle::SmallFont)); - additional->SetHorizontalAlignment(gfx::ALIGN_LEFT); - } - } - - // Adjust text properties dependent on if it is an active or inactive user. - if (multiprofile_index_) { - // Fade the text of non active users to 50%. - SkColor text_color = additional->enabled_color(); - text_color = SkColorSetA(text_color, SkColorGetA(text_color) / 2); - if (additional) - additional->SetDisabledColor(text_color); - if (username) - username->SetDisabledColor(text_color); - } - - if (additional && username) { - views::View* details = new views::View; - details->SetLayoutManager(new views::BoxLayout( - views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0)); - details->AddChildView(username); - details->AddChildView(additional); - user_card_view_->AddChildView(details); - } else { - if (username) - user_card_view_->AddChildView(username); - if (additional) - user_card_view_->AddChildView(additional); - } -} - -views::View* UserView::CreateIconForUserCard(user::LoginStatus login) { - RoundedImageView* icon = new RoundedImageView(kProfileRoundedCornerRadius, - multiprofile_index_ == 0); - icon->SetEnabled(false); - if (login == user::LOGGED_IN_GUEST) { - icon->SetImage(*ui::ResourceBundle::GetSharedInstance(). - GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON).ToImageSkia(), - gfx::Size(kUserIconSize, kUserIconSize)); - } else { - icon->SetImage( - Shell::GetInstance()->session_state_delegate()-> - GetUserImage(multiprofile_index_), - gfx::Size(kUserIconSize, kUserIconSize)); - } - return icon; -} - -void UserView::AddLoggedInRetailModeUserCardContent() { - views::Label* details = new views::Label; - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - details->SetText( - bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_KIOSK_LABEL)); - details->set_border(views::Border::CreateEmptyBorder(0, 4, 0, 1)); - details->SetHorizontalAlignment(gfx::ALIGN_LEFT); - user_card_view_->AddChildView(details); -} - -void UserView::AddLoggedInPublicModeUserCardContent(SystemTrayItem* owner) { - user_card_view_->AddChildView(CreateIconForUserCard(user::LOGGED_IN_PUBLIC)); - user_card_view_->AddChildView(new PublicAccountUserDetails( - owner, GetPreferredSize().width() + kTrayPopupPaddingBetweenItems)); -} - -void UserView::ToggleAddUserMenuOption() { - if (add_menu_option_.get()) { - popup_message_.reset(); - mouse_watcher_.reset(); - add_menu_option_.reset(); - return; - } - - // Note: We do not need to install a global event handler to delete this - // item since it will destroyed automatically before the menu / user menu item - // gets destroyed.. - const SessionStateDelegate* session_state_delegate = - Shell::GetInstance()->session_state_delegate(); - add_user_visible_but_disabled_ = - session_state_delegate->NumberOfLoggedInUsers() >= - session_state_delegate->GetMaximumNumberOfLoggedInUsers(); - add_menu_option_.reset(new views::Widget); - views::Widget::InitParams params; - params.type = views::Widget::InitParams::TYPE_TOOLTIP; - params.keep_on_top = true; - params.context = this->GetWidget()->GetNativeWindow(); - params.accept_events = true; - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; - add_menu_option_->Init(params); - add_menu_option_->SetOpacity(0xFF); - add_menu_option_->GetNativeWindow()->set_owned_by_parent(false); - SetShadowType(add_menu_option_->GetNativeView(), - views::corewm::SHADOW_TYPE_NONE); - - // Position it below our user card. - gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); - bounds.set_y(bounds.y() + bounds.height()); - add_menu_option_->SetBounds(bounds); - - // Show the content. - AddUserView* add_user_view = new AddUserView( - static_cast<UserCard*>(user_card_view_), this); - add_menu_option_->SetContentsView(add_user_view); - add_menu_option_->SetAlwaysOnTop(true); - add_menu_option_->Show(); - if (add_user_visible_but_disabled_) { - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - popup_message_.reset(new PopupMessage( - bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER), - bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER), - PopupMessage::ICON_WARNING, - add_user_view->anchor(), - views::BubbleBorder::TOP_LEFT, - gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0), - 2 * kPopupMessageOffset)); - } - // Find the screen area which encloses both elements and sets then a mouse - // watcher which will close the "menu". - gfx::Rect area = user_card_view_->GetBoundsInScreen(); - area.set_height(2 * area.height()); - mouse_watcher_.reset(new views::MouseWatcher( - new UserViewMouseWatcherHost(area), - this)); - mouse_watcher_->Start(); -} - -bool UserView::SupportsMultiProfile() { - // We do not want to see any multi profile additions to a user view when the - // log in screen is shown. - return Shell::GetInstance()->delegate()->IsMultiProfilesEnabled() && - !Shell::GetInstance()->session_state_delegate()->IsUserSessionBlocked(); -} - -AddUserView::AddUserView(UserCard* owner, views::ButtonListener* listener) - : CustomButton(listener_), - add_user_(NULL), - listener_(listener), - owner_(owner), - anchor_(NULL) { - AddContent(); - owner_->ForceBorderVisible(true); -} - -AddUserView::~AddUserView() { - owner_->ForceBorderVisible(false); -} - -gfx::Size AddUserView::GetPreferredSize() { - return owner_->bounds().size(); -} - -int AddUserView::GetHeightForWidth(int width) { - return owner_->bounds().size().height(); -} - -void AddUserView::Layout() { - gfx::Rect contents_area(GetContentsBounds()); - add_user_->SetBoundsRect(contents_area); -} - -void AddUserView::ButtonPressed(views::Button* sender, const ui::Event& event) { - if (add_user_ == sender) - listener_->ButtonPressed(this, event); - else - NOTREACHED(); -} - -void AddUserView::AddContent() { - set_notify_enter_exit_on_child(true); - - const SessionStateDelegate* delegate = - Shell::GetInstance()->session_state_delegate(); - bool enable = delegate->NumberOfLoggedInUsers() < - delegate->GetMaximumNumberOfLoggedInUsers(); - - SetLayoutManager(new views::FillLayout()); - set_background(views::Background::CreateSolidBackground(kBackgroundColor)); - - // Add padding around the panel. - set_border(views::Border::CreateSolidBorder(1, kBorderColor)); - - add_user_ = new UserCard(this, enable); - add_user_->set_border(views::Border::CreateEmptyBorder( - kUserCardVerticalPadding, - kTrayPopupPaddingHorizontal- kTrayUserTileHoverBorderInset, - kUserCardVerticalPadding, - kTrayPopupPaddingHorizontal- kTrayUserTileHoverBorderInset)); - - add_user_->SetLayoutManager(new views::BoxLayout( - views::BoxLayout::kHorizontal, 0, 0 , kTrayPopupPaddingBetweenItems)); - AddChildViewAt(add_user_, 0); - - // Add the [+] icon which is also the anchor for messages. - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - RoundedImageView* icon = new RoundedImageView(kProfileRoundedCornerRadius, - true); - anchor_ = icon; - icon->SetImage(*ui::ResourceBundle::GetSharedInstance(). - GetImageNamed(IDR_AURA_UBER_TRAY_ADD_MULTIPROFILE_USER).ToImageSkia(), - gfx::Size(kUserIconSize, kUserIconSize)); - add_user_->AddChildView(icon); - - // Add the command text. - views::Label* command_label = new views::Label( - bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); - command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); - add_user_->AddChildView(command_label); -} - -} // namespace tray - -TrayUser::TrayUser(SystemTray* system_tray, MultiProfileIndex index) - : SystemTrayItem(system_tray), - multiprofile_index_(index), - user_(NULL), - layout_view_(NULL), - avatar_(NULL), - label_(NULL) { - Shell::GetInstance()->system_tray_notifier()->AddUserObserver(this); -} - -TrayUser::~TrayUser() { - Shell::GetInstance()->system_tray_notifier()->RemoveUserObserver(this); -} - -TrayUser::TestState TrayUser::GetStateForTest() const { - if (!user_) - return HIDDEN; - return user_->GetStateForTest(); -} - -bool TrayUser::CanDropWindowHereToTransferToUser( - const gfx::Point& point_in_screen) { - // Check that this item is shown in the system tray (which means it must have - // a view there) and that the user it represents is not the current user (in - // which case |GetTrayIndex()| would return NULL). - if (!layout_view_ || !GetTrayIndex()) - return false; - return layout_view_->GetBoundsInScreen().Contains(point_in_screen); -} - -bool TrayUser::TransferWindowToUser(aura::Window* window) { - SessionStateDelegate* session_state_delegate = - ash::Shell::GetInstance()->session_state_delegate(); - return session_state_delegate->TransferWindowToDesktopOfUser(window, - GetTrayIndex()); -} - -gfx::Rect TrayUser::GetUserPanelBoundsInScreenForTest() const { - DCHECK(user_); - return user_->GetBoundsInScreenOfUserButtonForTest(); -} - -views::View* TrayUser::CreateTrayView(user::LoginStatus status) { - CHECK(layout_view_ == NULL); - // When the full multi profile mode is used, only the active user will be - // shown in the system tray, otherwise all users which are logged in. - if (GetTrayIndex() && switches::UseFullMultiProfileMode()) - return NULL; - - layout_view_ = new views::View(); - layout_view_->SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kHorizontal, - 0, 0, kUserLabelToIconPadding)); - UpdateAfterLoginStatusChange(status); - return layout_view_; -} - -views::View* TrayUser::CreateDefaultView(user::LoginStatus status) { - if (status == user::LOGGED_IN_NONE) - return NULL; - const SessionStateDelegate* session_state_delegate = - Shell::GetInstance()->session_state_delegate(); - - // If the screen is locked show only the currently active user. - if (multiprofile_index_ && session_state_delegate->IsUserSessionBlocked()) - return NULL; - - CHECK(user_ == NULL); - - int logged_in_users = session_state_delegate->NumberOfLoggedInUsers(); - - // Do not show more UserView's then there are logged in users. - if (multiprofile_index_ >= logged_in_users) - return NULL; - - user_ = new tray::UserView(this, status, multiprofile_index_); - return user_; -} - -views::View* TrayUser::CreateDetailedView(user::LoginStatus status) { - return NULL; -} - -void TrayUser::DestroyTrayView() { - layout_view_ = NULL; - avatar_ = NULL; - label_ = NULL; -} - -void TrayUser::DestroyDefaultView() { - user_ = NULL; -} - -void TrayUser::DestroyDetailedView() { -} - -void TrayUser::UpdateAfterLoginStatusChange(user::LoginStatus status) { - // Only the active user is represented in the tray. - if (!layout_view_) - return; - if (GetTrayIndex() > 0 && !ash::switches::UseMultiUserTray()) - return; - bool need_label = false; - bool need_avatar = false; - switch (status) { - case user::LOGGED_IN_LOCKED: - case user::LOGGED_IN_USER: - case user::LOGGED_IN_OWNER: - case user::LOGGED_IN_PUBLIC: - need_avatar = true; - break; - case user::LOGGED_IN_LOCALLY_MANAGED: - need_avatar = true; - need_label = true; - break; - case user::LOGGED_IN_GUEST: - need_label = true; - break; - case user::LOGGED_IN_RETAIL_MODE: - case user::LOGGED_IN_KIOSK_APP: - case user::LOGGED_IN_NONE: - break; - } - - if ((need_avatar != (avatar_ != NULL)) || - (need_label != (label_ != NULL))) { - layout_view_->RemoveAllChildViews(true); - if (need_label) { - label_ = new views::Label; - SetupLabelForTray(label_); - layout_view_->AddChildView(label_); - } else { - label_ = NULL; - } - if (need_avatar) { - MultiProfileIndex tray_index = GetTrayIndex(); - if (!tray_index) { - // The active user (index #0) will always be the first. - avatar_ = new tray::RoundedImageView(kProfileRoundedCornerRadius, true); - } else { - // All other users will be inactive users. - avatar_ = new tray::UserSwitcherView(kProfileRoundedCornerRadius, - tray_index); - } - layout_view_->AddChildView(avatar_); - } else { - avatar_ = NULL; - } - } - - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); - if (status == user::LOGGED_IN_LOCALLY_MANAGED) { - label_->SetText( - bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)); - } else if (status == user::LOGGED_IN_GUEST) { - label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); - } - - if (avatar_ && switches::UseAlternateShelfLayout()) { - int corner_radius = GetTrayItemRadius(); - avatar_->SetCornerRadii(0, corner_radius, corner_radius, 0); - avatar_->set_border(NULL); - } - UpdateAvatarImage(status); - - // Update layout after setting label_ and avatar_ with new login status. - UpdateLayoutOfItem(); -} - -void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { - // Inactive users won't have a layout. - if (!layout_view_) - return; - int corner_radius = GetTrayItemRadius(); - if (alignment == SHELF_ALIGNMENT_BOTTOM || - alignment == SHELF_ALIGNMENT_TOP) { - if (avatar_) { - if (switches::UseAlternateShelfLayout()) { - if (multiprofile_index_) { - avatar_->set_border( - views::Border::CreateEmptyBorder(0, kTrayLabelSpacing, 0, 0)); - } else { - avatar_->set_border(NULL); - } - avatar_->SetCornerRadii(0, corner_radius, corner_radius, 0); - } else { - avatar_->set_border(views::Border::CreateEmptyBorder( - 0, kTrayImageItemHorizontalPaddingBottomAlignment + 2, - 0, kTrayImageItemHorizontalPaddingBottomAlignment)); - } - } - if (label_) { - label_->set_border(views::Border::CreateEmptyBorder( - 0, kTrayLabelItemHorizontalPaddingBottomAlignment, - 0, kTrayLabelItemHorizontalPaddingBottomAlignment)); - } - layout_view_->SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kHorizontal, - 0, 0, kUserLabelToIconPadding)); - } else { - if (avatar_) { - if (switches::UseAlternateShelfLayout()) { - if (multiprofile_index_) { - avatar_->set_border( - views::Border::CreateEmptyBorder(kTrayLabelSpacing, 0, 0, 0)); - } else { - avatar_->set_border(NULL); - } - avatar_->SetCornerRadii(0, 0, corner_radius, corner_radius); - } else { - SetTrayImageItemBorder(avatar_, alignment); - } - } - if (label_) { - label_->set_border(views::Border::CreateEmptyBorder( - kTrayLabelItemVerticalPaddingVerticalAlignment, - kTrayLabelItemHorizontalPaddingBottomAlignment, - kTrayLabelItemVerticalPaddingVerticalAlignment, - kTrayLabelItemHorizontalPaddingBottomAlignment)); - } - layout_view_->SetLayoutManager( - new views::BoxLayout(views::BoxLayout::kVertical, - 0, 0, kUserLabelToIconPadding)); - } -} - -void TrayUser::OnUserUpdate() { - UpdateAvatarImage(Shell::GetInstance()->system_tray_delegate()-> - GetUserLoginStatus()); -} - -void TrayUser::OnUserAddedToSession() { - SessionStateDelegate* session_state_delegate = - Shell::GetInstance()->session_state_delegate(); - // Only create views for user items which are logged in. - if (GetTrayIndex() >= session_state_delegate->NumberOfLoggedInUsers()) - return; - - // Enforce a layout change that newly added items become visible. - UpdateLayoutOfItem(); - - // Update the user item. - UpdateAvatarImage( - Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()); -} - -void TrayUser::UpdateAvatarImage(user::LoginStatus status) { - SessionStateDelegate* session_state_delegate = - Shell::GetInstance()->session_state_delegate(); - if (!avatar_ || - GetTrayIndex() >= session_state_delegate->NumberOfLoggedInUsers()) - return; - - int icon_size = switches::UseAlternateShelfLayout() ? - kUserIconLargeSize : kUserIconSize; - - avatar_->SetImage( - Shell::GetInstance()->session_state_delegate()->GetUserImage( - GetTrayIndex()), - gfx::Size(icon_size, icon_size)); - - // Unit tests might come here with no images for some users. - if (avatar_->size().IsEmpty()) - avatar_->SetSize(gfx::Size(icon_size, icon_size)); -} - -MultiProfileIndex TrayUser::GetTrayIndex() { - Shell* shell = Shell::GetInstance(); - // If multi profile is not enabled we can use the normal index. - if (!shell->delegate()->IsMultiProfilesEnabled()) - return multiprofile_index_; - // In case of multi profile we need to mirror the indices since the system - // tray items are in the reverse order then the menu items. - return shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers() - - 1 - multiprofile_index_; -} - -int TrayUser::GetTrayItemRadius() { - SessionStateDelegate* delegate = - Shell::GetInstance()->session_state_delegate(); - bool is_last_item = GetTrayIndex() == (delegate->NumberOfLoggedInUsers() - 1); - return is_last_item ? kUserIconLargeCornerRadius : 0; -} - -void TrayUser::UpdateLayoutOfItem() { - internal::RootWindowController* controller = - internal::GetRootWindowController( - system_tray()->GetWidget()->GetNativeWindow()->GetRootWindow()); - if (controller && controller->shelf()) { - UpdateAfterShelfAlignmentChange( - controller->GetShelfLayoutManager()->GetAlignment()); - } -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/user/tray_user.h b/chromium/ash/system/user/tray_user.h deleted file mode 100644 index 079bf75e4f7..00000000000 --- a/chromium/ash/system/user/tray_user.h +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_USER_TRAY_USER_H_ -#define ASH_SYSTEM_USER_TRAY_USER_H_ - -#include "ash/ash_export.h" -#include "ash/session_state_delegate.h" -#include "ash/system/tray/system_tray_item.h" -#include "ash/system/user/user_observer.h" -#include "base/compiler_specific.h" - -namespace gfx { -class Rect; -class Point; -} - -namespace views { -class ImageView; -class Label; -} - -namespace ash { -namespace internal { - -namespace tray { -class UserView; -class RoundedImageView; -} - -class ASH_EXPORT TrayUser : public SystemTrayItem, - public UserObserver { - public: - // The given |multiprofile_index| is the user number in a multi profile - // scenario. Index #0 is the running user, the other indices are other logged - // in users (if there are any). Depending on the multi user mode, there will - // be either one (index #0) or all users be visible in the system tray. - TrayUser(SystemTray* system_tray, MultiProfileIndex index); - virtual ~TrayUser(); - - // Allows unit tests to see if the item was created. - enum TestState { - HIDDEN, // The item is hidden. - SHOWN, // The item gets presented to the user. - HOVERED, // The item is hovered and presented to the user. - ACTIVE, // The item was clicked and can add a user. - ACTIVE_BUT_DISABLED // The item was clicked anc cannot add a user. - }; - TestState GetStateForTest() const; - - // Checks if a drag and drop operation would be able to land a window on this - // |point_in_screen|. - bool CanDropWindowHereToTransferToUser(const gfx::Point& point_in_screen); - - // Try to re-parent the |window| to a new owner. Returns true if the window - // got transfered. - bool TransferWindowToUser(aura::Window* window); - - // Returns the bounds of the user panel in screen coordinates. - // Note: This only works when the panel shown. - gfx::Rect GetUserPanelBoundsInScreenForTest() const; - - private: - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE; - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE; - virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) OVERRIDE; - - // Overridden from UserObserver. - virtual void OnUserUpdate() OVERRIDE; - virtual void OnUserAddedToSession() OVERRIDE; - - void UpdateAvatarImage(user::LoginStatus status); - - // Get the user index which should be used for the tray icon of this item. - MultiProfileIndex GetTrayIndex(); - - // Return the radius for the tray item to use. - int GetTrayItemRadius(); - - // Updates the layout of this item. - void UpdateLayoutOfItem(); - - // The user index to use. - MultiProfileIndex multiprofile_index_; - - tray::UserView* user_; - - // View that contains label and/or avatar. - views::View* layout_view_; - tray::RoundedImageView* avatar_; - views::Label* label_; - - DISALLOW_COPY_AND_ASSIGN(TrayUser); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_USER_TRAY_USER_H_ diff --git a/chromium/ash/system/user/tray_user_separator.cc b/chromium/ash/system/user/tray_user_separator.cc deleted file mode 100644 index dc63bff9f4d..00000000000 --- a/chromium/ash/system/user/tray_user_separator.cc +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/user/tray_user_separator.h" - -#include "ash/session_state_delegate.h" -#include "ash/shell.h" -#include "ui/views/view.h" - -namespace ash { -namespace internal { - -TrayUserSeparator::TrayUserSeparator(SystemTray* system_tray) - : SystemTrayItem(system_tray), - separator_shown_(false) { -} - -views::View* TrayUserSeparator::CreateTrayView(user::LoginStatus status) { - return NULL; -} - -views::View* TrayUserSeparator::CreateDefaultView(user::LoginStatus status) { - if (status == user::LOGGED_IN_NONE) - return NULL; - - const SessionStateDelegate* session_state_delegate = - Shell::GetInstance()->session_state_delegate(); - - // If the screen is locked, or only a single user is shown, show nothing. - if (session_state_delegate->IsUserSessionBlocked() || - session_state_delegate->NumberOfLoggedInUsers() < 2) - return NULL; - - separator_shown_ = true; - return new views::View(); -} - -views::View* TrayUserSeparator::CreateDetailedView(user::LoginStatus status) { - return NULL; -} - -void TrayUserSeparator::DestroyDefaultView() { - separator_shown_ = false; -} - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/user/tray_user_separator.h b/chromium/ash/system/user/tray_user_separator.h deleted file mode 100644 index 62e52092d8a..00000000000 --- a/chromium/ash/system/user/tray_user_separator.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_USER_TRAY_USER_SEPARATOR_H_ -#define ASH_SYSTEM_USER_TRAY_USER_SEPARATOR_H_ - -#include "ash/ash_export.h" -#include "ash/system/tray/system_tray_item.h" - -namespace ash { -namespace internal { - -// This tray item is showing an additional separator line between the logged in -// users and the rest of the system tray menu. The separator will only be shown -// when there are at least two users logged in. -class ASH_EXPORT TrayUserSeparator : public SystemTrayItem { - public: - explicit TrayUserSeparator(SystemTray* system_tray); - virtual ~TrayUserSeparator() {} - - // Returns true if the separator gets shown. - bool separator_shown() { return separator_shown_; } - - private: - // Overridden from SystemTrayItem. - virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual void DestroyTrayView() OVERRIDE {} - virtual void DestroyDefaultView() OVERRIDE; - virtual void DestroyDetailedView() OVERRIDE {} - virtual void UpdateAfterLoginStatusChange( - user::LoginStatus status) OVERRIDE {} - virtual void UpdateAfterShelfAlignmentChange( - ShelfAlignment alignment) OVERRIDE {} - - // True if the separator gets shown. - bool separator_shown_; - - DISALLOW_COPY_AND_ASSIGN(TrayUserSeparator); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_SYSTEM_USER_TRAY_USER_SEPARATOR_H_ diff --git a/chromium/ash/system/user/tray_user_unittest.cc b/chromium/ash/system/user/tray_user_unittest.cc deleted file mode 100644 index ad6966104f8..00000000000 --- a/chromium/ash/system/user/tray_user_unittest.cc +++ /dev/null @@ -1,320 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <vector> - -#include "ash/ash_switches.h" -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_layout_manager.h" -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/user/tray_user.h" -#include "ash/system/user/tray_user_separator.h" -#include "ash/test/ash_test_base.h" -#include "ash/test/test_session_state_delegate.h" -#include "ash/test/test_shell_delegate.h" -#include "base/command_line.h" -#include "ui/aura/test/event_generator.h" -#include "ui/gfx/animation/animation_container_element.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -#if defined(OS_CHROMEOS) -#include "ash/system/tray/system_tray_notifier.h" -#endif - -namespace ash { -namespace internal { - -class TrayUserTest : public ash::test::AshTestBase { - public: - TrayUserTest(); - - // testing::Test: - virtual void SetUp() OVERRIDE; - - // This has to be called prior to first use with the proper configuration. - void InitializeParameters(int users_logged_in, bool multiprofile); - - // Show the system tray menu using the provided event generator. - void ShowTrayMenu(aura::test::EventGenerator* generator); - - // Move the mouse over the user item. - void MoveOverUserItem(aura::test::EventGenerator* generator, int index); - - // Click on the user item. Note that the tray menu needs to be shown. - void ClickUserItem(aura::test::EventGenerator* generator, int index); - - // Accessors to various system components. - ShelfLayoutManager* shelf() { return shelf_; } - SystemTray* tray() { return tray_; } - ash::test::TestSessionStateDelegate* delegate() { return delegate_; } - ash::internal::TrayUser* tray_user(int index) { return tray_user_[index]; } - ash::internal::TrayUserSeparator* tray_user_separator() { - return tray_user_separator_; - } - - private: - ShelfLayoutManager* shelf_; - SystemTray* tray_; - ash::test::TestSessionStateDelegate* delegate_; - - // Note that the ownership of these items is on the shelf. - std::vector<ash::internal::TrayUser*> tray_user_; - - // The separator between the tray users and the rest of the menu. - // Note: The item will get owned by the shelf. - TrayUserSeparator* tray_user_separator_; - - DISALLOW_COPY_AND_ASSIGN(TrayUserTest); -}; - -#if defined(OS_CHROMEOS) -// The tray user test which tests functionality where multiple tray items are -// visible in the system tray. -class MultiTrayUserTest : public TrayUserTest { - public: - MultiTrayUserTest() {} - - virtual void SetUp() OVERRIDE { - CommandLine* command_line = CommandLine::ForCurrentProcess(); - command_line->AppendSwitch(ash::switches::kAshEnableMultiUserTray); - TrayUserTest::SetUp(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(MultiTrayUserTest); -}; -#endif - -TrayUserTest::TrayUserTest() - : shelf_(NULL), - tray_(NULL), - delegate_(NULL), - tray_user_separator_(NULL) { -} - -void TrayUserTest::SetUp() { - ash::test::AshTestBase::SetUp(); - shelf_ = Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); - tray_ = Shell::GetPrimaryRootWindowController()->GetSystemTray(); - delegate_ = static_cast<ash::test::TestSessionStateDelegate*>( - ash::Shell::GetInstance()->session_state_delegate()); -} - -void TrayUserTest::InitializeParameters(int users_logged_in, - bool multiprofile) { - // Show the shelf. - shelf()->LayoutShelf(); - shelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); - - // Set our default assumptions. Note that it is sufficient to set these - // after everything was created. - delegate_->set_logged_in_users(users_logged_in); - ash::test::TestShellDelegate* shell_delegate = - static_cast<ash::test::TestShellDelegate*>( - ash::Shell::GetInstance()->delegate()); - shell_delegate->set_multi_profiles_enabled(multiprofile); - - // Instead of using the existing tray panels we create new ones which makes - // the access easier. - for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) { - tray_user_.push_back(new ash::internal::TrayUser(tray_, i)); - tray_->AddTrayItem(tray_user_[i]); - } - // We then add also the separator. - tray_user_separator_ = new ash::internal::TrayUserSeparator(tray_); - tray_->AddTrayItem(tray_user_separator_); -} - -void TrayUserTest::ShowTrayMenu(aura::test::EventGenerator* generator) { - gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); - - generator->MoveMouseTo(center.x(), center.y()); - EXPECT_FALSE(tray()->IsAnyBubbleVisible()); - generator->ClickLeftButton(); -} - -void TrayUserTest::MoveOverUserItem(aura::test::EventGenerator* generator, - int index) { - gfx::Point center = - tray_user(index)->GetUserPanelBoundsInScreenForTest().CenterPoint(); - - generator->MoveMouseTo(center.x(), center.y()); -} - -void TrayUserTest::ClickUserItem(aura::test::EventGenerator* generator, - int index) { - MoveOverUserItem(generator, index); - generator->ClickLeftButton(); -} - -// Make sure that in single user mode the user panel cannot be activated and no -// separators are being created. -TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { - InitializeParameters(1, false); - - // Move the mouse over the status area and click to open the status menu. - aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); - - EXPECT_FALSE(tray()->IsAnyBubbleVisible()); - - for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) - EXPECT_EQ(ash::internal::TrayUser::HIDDEN, - tray_user(i)->GetStateForTest()); - EXPECT_FALSE(tray_user_separator()->separator_shown()); - - ShowTrayMenu(&generator); - - EXPECT_TRUE(tray()->HasSystemBubble()); - EXPECT_TRUE(tray()->IsAnyBubbleVisible()); - - for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) - EXPECT_EQ(i == 0 ? ash::internal::TrayUser::SHOWN : - ash::internal::TrayUser::HIDDEN, - tray_user(i)->GetStateForTest()); - EXPECT_FALSE(tray_user_separator()->separator_shown()); - tray()->CloseSystemBubble(); -} - -#if defined(OS_CHROMEOS) -// Make sure that in multi user mode the user panel can be activated and there -// will be one panel for each user plus one additional separator at the end. -// Note: the mouse watcher (for automatic closing upon leave) cannot be tested -// here since it does not work with the event system in unit tests. -TEST_F(TrayUserTest, MutiUserModeDoesNotAllowToAddUser) { - InitializeParameters(1, true); - - // Move the mouse over the status area and click to open the status menu. - aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); - generator.set_async(false); - - int max_users = delegate()->GetMaximumNumberOfLoggedInUsers(); - // Checking now for each amount of users that the correct is done. - for (int j = 1; j < max_users; j++) { - // Set the number of logged in users. - delegate()->set_logged_in_users(j); - - // Verify that nothing is shown. - EXPECT_FALSE(tray()->IsAnyBubbleVisible()); - for (int i = 0; i < max_users; i++) - EXPECT_FALSE(tray_user(i)->GetStateForTest()); - EXPECT_FALSE(tray_user_separator()->separator_shown()); - // After clicking on the tray the menu should get shown and for each logged - // in user we should get a visible item. In addition, the separator should - // show up when we reach more then one user. - ShowTrayMenu(&generator); - - EXPECT_TRUE(tray()->HasSystemBubble()); - EXPECT_TRUE(tray()->IsAnyBubbleVisible()); - for (int i = 0; i < max_users; i++) { - EXPECT_EQ(i < j ? ash::internal::TrayUser::SHOWN : - ash::internal::TrayUser::HIDDEN, - tray_user(i)->GetStateForTest()); - } - - // Check the visibility of the separator. - EXPECT_EQ(j > 1 ? true : false, tray_user_separator()->separator_shown()); - - // Move the mouse over the user item and it should hover. - MoveOverUserItem(&generator, 0); - EXPECT_EQ(ash::internal::TrayUser::HOVERED, - tray_user(0)->GetStateForTest()); - for (int i = 1; i < max_users; i++) { - EXPECT_EQ(i < j ? ash::internal::TrayUser::SHOWN : - ash::internal::TrayUser::HIDDEN, - tray_user(i)->GetStateForTest()); - } - - // Check that clicking the button allows to add item if we have still room - // for one more user. - ClickUserItem(&generator, 0); - EXPECT_EQ(j == max_users ? - ash::internal::TrayUser::ACTIVE_BUT_DISABLED : - ash::internal::TrayUser::ACTIVE, - tray_user(0)->GetStateForTest()); - - // Click the button again to see that the menu goes away. - ClickUserItem(&generator, 0); - EXPECT_EQ(ash::internal::TrayUser::HOVERED, - tray_user(0)->GetStateForTest()); - - // Close and check that everything is deleted. - tray()->CloseSystemBubble(); - EXPECT_FALSE(tray()->IsAnyBubbleVisible()); - for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) - EXPECT_EQ(ash::internal::TrayUser::HIDDEN, - tray_user(i)->GetStateForTest()); - } -} - -// Make sure that user changing gets properly executed. -TEST_F(TrayUserTest, MutiUserModeButtonClicks) { - // Have two users. - InitializeParameters(2, true); - aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); - ShowTrayMenu(&generator); - - // Switch to a new user - which has a capitalized name. - ClickUserItem(&generator, 1); - EXPECT_EQ(delegate()->get_activated_user(), delegate()->GetUserID(1)); - // Since the name is capitalized, the email should be different then the - // user_id. - EXPECT_NE(delegate()->get_activated_user(), delegate()->GetUserEmail(1)); - tray()->CloseSystemBubble(); -} - -// Make sure that we show items for all users in the tray accordingly. -TEST_F(MultiTrayUserTest, CheckTrayUserItems) { - InitializeParameters(1, true); - - int max_users = delegate()->GetMaximumNumberOfLoggedInUsers(); - // Checking now for each amount of users that the proper items are visible in - // the tray. The proper item is hereby: - // 2 -> User #1 - // 1 -> User #2 - // 0 -> User #3 - // Note: Tray items are required to populate system tray items as well as the - // system tray menu. The system tray menu changes it's appearance with the - // addition of more users, but the system tray does not create new items after - // it got created. - for (int present_users = 1; present_users <= max_users; ++present_users) { - // We simulate the user addition by telling the delegate the new number of - // users, then change all user tray items and finally tell the tray to - // re-layout itself. - delegate()->set_logged_in_users(present_users); - Shell::GetInstance()->system_tray_notifier()->NotifyUserAddedToSession(); - tray()->Layout(); - - // Check that the tray items are being shown in the reverse order. - for (int i = 0; i < max_users; i++) { - gfx::Rect rect = - tray()->GetTrayItemViewForTest(tray_user(i))->GetBoundsInScreen(); - if (max_users - 1 - i < present_users) - EXPECT_FALSE(rect.IsEmpty()); - else - EXPECT_TRUE(rect.IsEmpty()); - } - } - - // Click on the last item to see that the user changes. - aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); - generator.set_async(false); - - // Switch to a new user - again, note that we have to click on the reverse - // item in the list. Since the first clickable item is 1, we get user #2. - gfx::Point point = - tray()->GetTrayItemViewForTest(tray_user(1))-> - GetBoundsInScreen().CenterPoint(); - - generator.MoveMouseTo(point.x(), point.y()); - generator.ClickLeftButton(); - EXPECT_EQ(delegate()->get_activated_user(), delegate()->GetUserID(1)); -} - -#endif - -} // namespace internal -} // namespace ash diff --git a/chromium/ash/system/user/update_observer.h b/chromium/ash/system/user/update_observer.h deleted file mode 100644 index e509f62d3cb..00000000000 --- a/chromium/ash/system/user/update_observer.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_USER_UPDATE_OBSERVER_H_ -#define ASH_SYSTEM_USER_UPDATE_OBSERVER_H_ - -#include "ash/ash_export.h" - -namespace ash { - -class ASH_EXPORT UpdateObserver { - public: - enum UpdateSeverity { - UPDATE_NORMAL, - UPDATE_LOW_GREEN, - UPDATE_HIGH_ORANGE, - UPDATE_SEVERE_RED, - }; - - virtual ~UpdateObserver() {} - - virtual void OnUpdateRecommended(UpdateSeverity severity) = 0; -}; - -} // namespace ash - -#endif //ASH_SYSTEM_USER_UPDATE_OBSERVER_H_ diff --git a/chromium/ash/system/user/user_observer.h b/chromium/ash/system/user/user_observer.h deleted file mode 100644 index 64c2b9de40f..00000000000 --- a/chromium/ash/system/user/user_observer.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_USER_USER_OBSERVER_H_ -#define ASH_SYSTEM_USER_USER_OBSERVER_H_ - -#include "ash/ash_export.h" - -namespace ash { - -class ASH_EXPORT UserObserver { - public: - virtual ~UserObserver() {} - - // A user got updated / changed. - virtual void OnUserUpdate() = 0; - - // A user was added to the existing session. - virtual void OnUserAddedToSession() = 0; -}; - -} // namespace ash - -#endif // ASH_SYSTEM_USER_USER_OBSERVER_H_ diff --git a/chromium/ash/system/web_notification/web_notification_tray.cc b/chromium/ash/system/web_notification/web_notification_tray.cc deleted file mode 100644 index b0b75d87dfc..00000000000 --- a/chromium/ash/system/web_notification/web_notification_tray.cc +++ /dev/null @@ -1,624 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/web_notification/web_notification_tray.h" - -#include "ash/ash_switches.h" -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_layout_manager.h" -#include "ash/shelf/shelf_layout_manager_observer.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/shell_window_ids.h" -#include "ash/system/status_area_widget.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/tray_background_view.h" -#include "ash/system/tray/tray_bubble_wrapper.h" -#include "ash/system/tray/tray_constants.h" -#include "ash/system/tray/tray_utils.h" -#include "base/auto_reset.h" -#include "base/i18n/number_formatting.h" -#include "base/i18n/rtl.h" -#include "base/strings/utf_string_conversions.h" -#include "grit/ash_strings.h" -#include "grit/ui_strings.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/screen.h" -#include "ui/message_center/message_center_style.h" -#include "ui/message_center/message_center_tray_delegate.h" -#include "ui/message_center/message_center_util.h" -#include "ui/message_center/views/message_bubble_base.h" -#include "ui/message_center/views/message_center_bubble.h" -#include "ui/message_center/views/message_popup_collection.h" -#include "ui/views/bubble/tray_bubble_view.h" -#include "ui/views/controls/button/custom_button.h" -#include "ui/views/controls/image_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/controls/menu/menu_runner.h" -#include "ui/views/layout/fill_layout.h" - -#if defined(OS_CHROMEOS) - -namespace message_center { - -MessageCenterTrayDelegate* CreateMessageCenterTray() { - // On Windows+Ash the Tray will not be hosted in ash::Shell. - NOTREACHED(); - return NULL; -} - -} // namespace message_center - -#endif // defined(OS_CHROMEOS) - -namespace ash { -namespace { - -// Menu commands -const int kToggleQuietMode = 0; -const int kEnableQuietModeDay = 2; - -} - -namespace internal { -namespace { - -const SkColor kWebNotificationColorNoUnread = SkColorSetA(SK_ColorWHITE, 128); -const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; - -} - -// Observes the change of work area (including temporary change by auto-hide) -// and notifies MessagePopupCollection. -class WorkAreaObserver : public ShelfLayoutManagerObserver, - public ShellObserver { - public: - WorkAreaObserver(); - virtual ~WorkAreaObserver(); - - void SetSystemTrayHeight(int height); - - // Starts observing |shelf| and shell and sends the change to |collection|. - void StartObserving(message_center::MessagePopupCollection* collection, - aura::Window* root_window); - - // Stops the observing session. - void StopObserving(); - - // Overridden from ShellObserver: - virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE; - - // Overridden from ShelfLayoutManagerObserver: - virtual void OnAutoHideStateChanged(ShelfAutoHideState new_state) OVERRIDE; - - private: - // Updates |shelf_| from |root_window_|. - void UpdateShelf(); - - message_center::MessagePopupCollection* collection_; - aura::Window* root_window_; - ShelfLayoutManager* shelf_; - int system_tray_height_; - - DISALLOW_COPY_AND_ASSIGN(WorkAreaObserver); -}; - -WorkAreaObserver::WorkAreaObserver() - : collection_(NULL), - root_window_(NULL), - shelf_(NULL), - system_tray_height_(0) { -} - -WorkAreaObserver::~WorkAreaObserver() { - StopObserving(); -} - -void WorkAreaObserver::SetSystemTrayHeight(int height) { - system_tray_height_ = height; - - // If the shelf is shown during auto-hide state, the distance from the edge - // should be reduced by the height of shelf's shown height. - if (shelf_ && shelf_->visibility_state() == SHELF_AUTO_HIDE && - shelf_->auto_hide_state() == SHELF_AUTO_HIDE_SHOWN) { - system_tray_height_ -= ShelfLayoutManager::GetPreferredShelfSize() - - ShelfLayoutManager::kAutoHideSize; - } - - if (system_tray_height_ > 0 && ash::switches::UseAlternateShelfLayout()) - system_tray_height_ += message_center::kMarginBetweenItems; - - if (!shelf_) - return; - - OnAutoHideStateChanged(shelf_->auto_hide_state()); -} - -void WorkAreaObserver::StartObserving( - message_center::MessagePopupCollection* collection, - aura::Window* root_window) { - DCHECK(collection); - collection_ = collection; - root_window_ = root_window; - UpdateShelf(); - Shell::GetInstance()->AddShellObserver(this); - if (system_tray_height_ > 0) - OnAutoHideStateChanged(shelf_->auto_hide_state()); -} - -void WorkAreaObserver::StopObserving() { - Shell::GetInstance()->RemoveShellObserver(this); - if (shelf_) - shelf_->RemoveObserver(this); - collection_ = NULL; - shelf_ = NULL; -} - -void WorkAreaObserver::OnDisplayWorkAreaInsetsChanged() { - UpdateShelf(); - - collection_->OnDisplayBoundsChanged( - Shell::GetScreen()->GetDisplayNearestWindow( - shelf_->shelf_widget()->GetNativeView())); -} - -void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) { - gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( - shelf_->shelf_widget()->GetNativeView()); - gfx::Rect work_area = display.work_area(); - int width = 0; - if ((shelf_->visibility_state() == SHELF_AUTO_HIDE) && - new_state == SHELF_AUTO_HIDE_SHOWN) { - // Since the work_area is already reduced by kAutoHideSize, the inset width - // should be just the difference. - width = ShelfLayoutManager::GetPreferredShelfSize() - - ShelfLayoutManager::kAutoHideSize; - } - work_area.Inset(shelf_->SelectValueForShelfAlignment( - gfx::Insets(0, 0, width, 0), - gfx::Insets(0, width, 0, 0), - gfx::Insets(0, 0, 0, width), - gfx::Insets(width, 0, 0, 0))); - if (system_tray_height_ > 0) { - work_area.set_height( - std::max(0, work_area.height() - system_tray_height_)); - if (shelf_->GetAlignment() == SHELF_ALIGNMENT_TOP) - work_area.set_y(work_area.y() + system_tray_height_); - } - collection_->SetDisplayInfo(work_area, display.bounds()); -} - -void WorkAreaObserver::UpdateShelf() { - if (shelf_) - return; - - shelf_ = ShelfLayoutManager::ForLauncher(root_window_); - if (shelf_) - shelf_->AddObserver(this); -} - -// Class to initialize and manage the WebNotificationBubble and -// TrayBubbleWrapper instances for a bubble. -class WebNotificationBubbleWrapper { - public: - // Takes ownership of |bubble| and creates |bubble_wrapper_|. - WebNotificationBubbleWrapper(WebNotificationTray* tray, - message_center::MessageBubbleBase* bubble) { - bubble_.reset(bubble); - views::TrayBubbleView::AnchorAlignment anchor_alignment = - tray->GetAnchorAlignment(); - views::TrayBubbleView::InitParams init_params = - bubble->GetInitParams(anchor_alignment); - views::View* anchor = tray->tray_container(); - if (anchor_alignment == views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { - gfx::Point bounds(anchor->width() / 2, 0); - views::View::ConvertPointToWidget(anchor, &bounds); - init_params.arrow_offset = bounds.x(); - } - views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( - tray->GetBubbleWindowContainer(), anchor, tray, &init_params); - if (ash::switches::UseAlternateShelfLayout()) - bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); - bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); - bubble->InitializeContents(bubble_view); - } - - message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } - - // Convenience accessors. - views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } - - private: - scoped_ptr<message_center::MessageBubbleBase> bubble_; - scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; - - DISALLOW_COPY_AND_ASSIGN(WebNotificationBubbleWrapper); -}; - -class WebNotificationButton : public views::CustomButton { - public: - WebNotificationButton(views::ButtonListener* listener) - : views::CustomButton(listener), - is_bubble_visible_(false), - unread_count_(0) { - SetLayoutManager(new views::FillLayout); - unread_label_ = new views::Label(); - SetupLabelForTray(unread_label_); - AddChildView(unread_label_); - } - - void SetBubbleVisible(bool visible) { - if (visible == is_bubble_visible_) - return; - - is_bubble_visible_ = visible; - UpdateIconVisibility(); - } - - void SetUnreadCount(int unread_count) { - // base::FormatNumber doesn't convert to arabic numeric characters. - // TODO(mukai): use ICU to support conversion for such locales. - unread_count_ = unread_count; - // TODO(mukai): move NINE_PLUS message to ui_strings, it doesn't need to be - // in ash_strings. - unread_label_->SetText((unread_count > 9) ? - l10n_util::GetStringUTF16(IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) : - base::FormatNumber(unread_count)); - UpdateIconVisibility(); - } - - protected: - // Overridden from views::ImageButton: - virtual gfx::Size GetPreferredSize() OVERRIDE { - const int notification_item_size = GetShelfItemHeight(); - return gfx::Size(notification_item_size, notification_item_size); - } - - virtual int GetHeightForWidth(int width) OVERRIDE { - return GetPreferredSize().height(); - } - - private: - void UpdateIconVisibility() { - unread_label_->SetEnabledColor( - (!is_bubble_visible_ && unread_count_ > 0) ? - kWebNotificationColorWithUnread : kWebNotificationColorNoUnread); - SchedulePaint(); - } - - bool is_bubble_visible_; - int unread_count_; - - views::Label* unread_label_; - - DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); -}; - -} // namespace internal - -WebNotificationTray::WebNotificationTray( - internal::StatusAreaWidget* status_area_widget) - : TrayBackgroundView(status_area_widget), - button_(NULL), - show_message_center_on_unlock_(false), - should_update_tray_content_(false), - should_block_shelf_auto_hide_(false) { - button_ = new internal::WebNotificationButton(this); - button_->set_triggerable_event_flags( - ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); - tray_container()->AddChildView(button_); - SetContentsBackground(); - tray_container()->set_border(NULL); - SetVisible(false); - message_center_tray_.reset(new message_center::MessageCenterTray( - this, - message_center::MessageCenter::Get())); - work_area_observer_.reset(new internal::WorkAreaObserver()); - OnMessageCenterTrayChanged(); -} - -WebNotificationTray::~WebNotificationTray() { - // Release any child views that might have back pointers before ~View(). - message_center_bubble_.reset(); - popup_collection_.reset(); - work_area_observer_.reset(); -} - -// Public methods. - -bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { - if (!ShouldShowMessageCenter()) - return false; - - should_block_shelf_auto_hide_ = true; - message_center::MessageCenterBubble* message_center_bubble = - new message_center::MessageCenterBubble( - message_center(), - message_center_tray_.get(), - ash::switches::UseAlternateShelfLayout()); - - int max_height = 0; - aura::Window* status_area_window = status_area_widget()->GetNativeView(); - switch (GetShelfLayoutManager()->GetAlignment()) { - case SHELF_ALIGNMENT_BOTTOM: { - gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); - max_height = shelf_bounds.y(); - break; - } - case SHELF_ALIGNMENT_TOP: { - aura::Window* root = status_area_window->GetRootWindow(); - max_height = - root->bounds().height() - status_area_window->bounds().height(); - break; - } - case SHELF_ALIGNMENT_LEFT: - case SHELF_ALIGNMENT_RIGHT: { - // Assume that the bottom line of the status area widget and the bubble - // are aligned. - max_height = status_area_window->GetBoundsInRootWindow().bottom(); - break; - } - default: - NOTREACHED(); - } - - message_center_bubble->SetMaxHeight(std::max(0, - max_height - GetTraySpacing())); - if (show_settings) - message_center_bubble->SetSettingsVisible(); - message_center_bubble_.reset( - new internal::WebNotificationBubbleWrapper(this, message_center_bubble)); - - status_area_widget()->SetHideSystemNotifications(true); - GetShelfLayoutManager()->UpdateAutoHideState(); - button_->SetBubbleVisible(true); - SetDrawBackgroundAsActive(true); - return true; -} - -bool WebNotificationTray::ShowMessageCenter() { - return ShowMessageCenterInternal(false /* show_settings */); -} - -void WebNotificationTray::HideMessageCenter() { - if (!message_center_bubble()) - return; - SetDrawBackgroundAsActive(false); - message_center_bubble_.reset(); - should_block_shelf_auto_hide_ = false; - show_message_center_on_unlock_ = false; - status_area_widget()->SetHideSystemNotifications(false); - GetShelfLayoutManager()->UpdateAutoHideState(); - button_->SetBubbleVisible(false); -} - -void WebNotificationTray::SetSystemTrayHeight(int height) { - work_area_observer_->SetSystemTrayHeight(height); -} - -bool WebNotificationTray::ShowPopups() { - if (message_center_bubble()) - return false; - - popup_collection_.reset(new message_center::MessagePopupCollection( - ash::Shell::GetContainer( - GetWidget()->GetNativeView()->GetRootWindow(), - internal::kShellWindowId_StatusContainer), - message_center(), - message_center_tray_.get(), - ash::switches::UseAlternateShelfLayout())); - work_area_observer_->StartObserving( - popup_collection_.get(), GetWidget()->GetNativeView()->GetRootWindow()); - return true; -} - -void WebNotificationTray::HidePopups() { - DCHECK(popup_collection_.get()); - - popup_collection_->MarkAllPopupsShown(); - popup_collection_.reset(); - work_area_observer_->StopObserving(); -} - -// Private methods. - -bool WebNotificationTray::ShouldShowMessageCenter() { - return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && - !(status_area_widget()->system_tray() && - status_area_widget()->system_tray()->HasNotificationBubble()); -} - -bool WebNotificationTray::ShouldBlockLauncherAutoHide() const { - return should_block_shelf_auto_hide_; -} - -bool WebNotificationTray::IsMessageCenterBubbleVisible() const { - return (message_center_bubble() && - message_center_bubble()->bubble()->IsVisible()); -} - -bool WebNotificationTray::IsMouseInNotificationBubble() const { - return false; -} - -void WebNotificationTray::ShowMessageCenterBubble() { - if (!IsMessageCenterBubbleVisible()) - message_center_tray_->ShowMessageCenterBubble(); -} - -void WebNotificationTray::UpdateAfterLoginStatusChange( - user::LoginStatus login_status) { - OnMessageCenterTrayChanged(); -} - -void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { - if (alignment == shelf_alignment()) - return; - internal::TrayBackgroundView::SetShelfAlignment(alignment); - tray_container()->set_border(NULL); - // Destroy any existing bubble so that it will be rebuilt correctly. - message_center_tray_->HideMessageCenterBubble(); - message_center_tray_->HidePopupBubble(); -} - -void WebNotificationTray::AnchorUpdated() { - if (message_center_bubble()) { - message_center_bubble()->bubble_view()->UpdateBubble(); - UpdateBubbleViewArrow(message_center_bubble()->bubble_view()); - } -} - -base::string16 WebNotificationTray::GetAccessibleNameForTray() { - return l10n_util::GetStringUTF16( - IDS_MESSAGE_CENTER_ACCESSIBLE_NAME); -} - -void WebNotificationTray::HideBubbleWithView( - const views::TrayBubbleView* bubble_view) { - if (message_center_bubble() && - bubble_view == message_center_bubble()->bubble_view()) { - message_center_tray_->HideMessageCenterBubble(); - } else if (popup_collection_.get()) { - message_center_tray_->HidePopupBubble(); - } -} - -bool WebNotificationTray::PerformAction(const ui::Event& event) { - if (message_center_bubble()) - message_center_tray_->HideMessageCenterBubble(); - else - message_center_tray_->ShowMessageCenterBubble(); - return true; -} - -void WebNotificationTray::BubbleViewDestroyed() { - if (message_center_bubble()) - message_center_bubble()->bubble()->BubbleViewDestroyed(); -} - -void WebNotificationTray::OnMouseEnteredView() {} - -void WebNotificationTray::OnMouseExitedView() {} - -base::string16 WebNotificationTray::GetAccessibleNameForBubble() { - return GetAccessibleNameForTray(); -} - -gfx::Rect WebNotificationTray::GetAnchorRect( - views::Widget* anchor_widget, - views::TrayBubbleView::AnchorType anchor_type, - views::TrayBubbleView::AnchorAlignment anchor_alignment) { - return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); -} - -void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { - HideBubbleWithView(bubble_view); -} - -bool WebNotificationTray::ShowNotifierSettings() { - if (message_center_bubble()) { - static_cast<message_center::MessageCenterBubble*>( - message_center_bubble()->bubble())->SetSettingsVisible(); - return true; - } - return ShowMessageCenterInternal(true /* show_settings */); -} - -message_center::MessageCenterTray* WebNotificationTray::GetMessageCenterTray() { - return message_center_tray_.get(); -} - -bool WebNotificationTray::IsCommandIdChecked(int command_id) const { - if (command_id != kToggleQuietMode) - return false; - return message_center()->IsQuietMode(); -} - -bool WebNotificationTray::IsCommandIdEnabled(int command_id) const { - return true; -} - -bool WebNotificationTray::GetAcceleratorForCommandId( - int command_id, - ui::Accelerator* accelerator) { - return false; -} - -void WebNotificationTray::ExecuteCommand(int command_id, int event_flags) { - if (command_id == kToggleQuietMode) { - bool in_quiet_mode = message_center()->IsQuietMode(); - message_center()->SetQuietMode(!in_quiet_mode); - return; - } - base::TimeDelta expires_in = command_id == kEnableQuietModeDay ? - base::TimeDelta::FromDays(1): - base::TimeDelta::FromHours(1); - message_center()->EnterQuietModeWithExpire(expires_in); -} - -void WebNotificationTray::ButtonPressed(views::Button* sender, - const ui::Event& event) { - DCHECK_EQ(button_, sender); - PerformAction(event); -} - -void WebNotificationTray::OnMessageCenterTrayChanged() { - // Do not update the tray contents directly. Multiple change events can happen - // consecutively, and calling Update in the middle of those events will show - // intermediate unread counts for a moment. - should_update_tray_content_ = true; - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&WebNotificationTray::UpdateTrayContent, AsWeakPtr())); -} - -void WebNotificationTray::UpdateTrayContent() { - if (!should_update_tray_content_) - return; - should_update_tray_content_ = false; - - message_center::MessageCenter* message_center = - message_center_tray_->message_center(); - button_->SetUnreadCount(message_center->UnreadNotificationCount()); - if (IsMessageCenterBubbleVisible()) - button_->SetState(views::CustomButton::STATE_PRESSED); - else - button_->SetState(views::CustomButton::STATE_NORMAL); - SetVisible((status_area_widget()->login_status() != user::LOGGED_IN_NONE) && - (status_area_widget()->login_status() != user::LOGGED_IN_LOCKED) && - (message_center->NotificationCount() > 0)); - Layout(); - SchedulePaint(); -} - -bool WebNotificationTray::ClickedOutsideBubble() { - // Only hide the message center - if (!message_center_bubble()) - return false; - - message_center_tray_->HideMessageCenterBubble(); - return true; -} - -message_center::MessageCenter* WebNotificationTray::message_center() const { - return message_center_tray_->message_center(); -} - -// Methods for testing - -bool WebNotificationTray::IsPopupVisible() const { - return message_center_tray_->popups_visible(); -} - -message_center::MessageCenterBubble* -WebNotificationTray::GetMessageCenterBubbleForTest() { - if (!message_center_bubble()) - return NULL; - return static_cast<message_center::MessageCenterBubble*>( - message_center_bubble()->bubble()); -} - -} // namespace ash diff --git a/chromium/ash/system/web_notification/web_notification_tray.h b/chromium/ash/system/web_notification/web_notification_tray.h deleted file mode 100644 index e08afbc8d10..00000000000 --- a/chromium/ash/system/web_notification/web_notification_tray.h +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ -#define ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ - -#include "ash/ash_export.h" -#include "ash/system/tray/tray_background_view.h" -#include "ash/system/user/login_status.h" -#include "base/gtest_prod_util.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "ui/base/models/simple_menu_model.h" -#include "ui/message_center/message_center_tray.h" -#include "ui/message_center/message_center_tray_delegate.h" -#include "ui/views/bubble/tray_bubble_view.h" -#include "ui/views/controls/button/button.h" - -// Status area tray for showing browser and app notifications. This hosts -// a MessageCenter class which manages the notification list. This class -// contains the Ash specific tray implementation. -// -// Note: These are not related to system notifications (i.e NotificationView -// generated by SystemTrayItem). Visibility of one notification type or other -// is controlled by StatusAreaWidget. - -namespace views { -class ImageButton; -class MenuRunner; -} - -namespace message_center { -class MessageBubbleBase; -class MessageCenter; -class MessageCenterBubble; -class MessagePopupCollection; -} - -namespace ash { -namespace internal { -class StatusAreaWidget; -class WebNotificationBubbleWrapper; -class WebNotificationButton; -class WorkAreaObserver; -} - -class ASH_EXPORT WebNotificationTray - : public internal::TrayBackgroundView, - public views::TrayBubbleView::Delegate, - public message_center::MessageCenterTrayDelegate, - public views::ButtonListener, - public base::SupportsWeakPtr<WebNotificationTray>, - public ui::SimpleMenuModel::Delegate { - public: - explicit WebNotificationTray( - internal::StatusAreaWidget* status_area_widget); - virtual ~WebNotificationTray(); - - // Sets the height of the system tray from the edge of the work area so that - // the notification popups don't overlap with the tray. Passes 0 if no UI is - // shown in the system tray side. - void SetSystemTrayHeight(int height); - - // Returns true if it should block the auto hide behavior of the launcher. - bool ShouldBlockLauncherAutoHide() const; - - // Returns true if the message center bubble is visible. - bool IsMessageCenterBubbleVisible() const; - - // Returns true if the mouse is inside the notification bubble. - bool IsMouseInNotificationBubble() const; - - // Shows the message center bubble. - void ShowMessageCenterBubble(); - - // Called when the login status is changed. - void UpdateAfterLoginStatusChange(user::LoginStatus login_status); - - // Overridden from TrayBackgroundView. - virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; - virtual void AnchorUpdated() OVERRIDE; - virtual base::string16 GetAccessibleNameForTray() OVERRIDE; - virtual void HideBubbleWithView( - const views::TrayBubbleView* bubble_view) OVERRIDE; - virtual bool ClickedOutsideBubble() OVERRIDE; - - // Overridden from internal::ActionableView. - virtual bool PerformAction(const ui::Event& event) OVERRIDE; - - // Overridden from views::TrayBubbleView::Delegate. - virtual void BubbleViewDestroyed() OVERRIDE; - virtual void OnMouseEnteredView() OVERRIDE; - virtual void OnMouseExitedView() OVERRIDE; - virtual base::string16 GetAccessibleNameForBubble() OVERRIDE; - virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget, - AnchorType anchor_type, - AnchorAlignment anchor_alignment) OVERRIDE; - virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE; - - // Overridden from ButtonListener. - virtual void ButtonPressed(views::Button* sender, - const ui::Event& event) OVERRIDE; - - // Overridden from MessageCenterTrayDelegate. - virtual void OnMessageCenterTrayChanged() OVERRIDE; - virtual bool ShowMessageCenter() OVERRIDE; - virtual void HideMessageCenter() OVERRIDE; - virtual bool ShowPopups() OVERRIDE; - virtual void HidePopups() OVERRIDE; - virtual bool ShowNotifierSettings() OVERRIDE; - virtual message_center::MessageCenterTray* GetMessageCenterTray() OVERRIDE; - - // Overridden from SimpleMenuModel::Delegate. - virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; - virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; - virtual bool GetAcceleratorForCommandId( - int command_id, - ui::Accelerator* accelerator) OVERRIDE; - virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; - - message_center::MessageCenter* message_center() const; - - private: - friend class WebNotificationTrayTest; - - FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); - FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble); - FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, - ManyMessageCenterNotifications); - FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications); - FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupShownOnBothDisplays); - FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndSystemTray); - FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndAutoHideShelf); - - void UpdateTrayContent(); - - // The actual process to show the message center. Set |show_settings| to true - // if the message center should be initialized with the settings visible. - // Returns true if the center is successfully created. - bool ShowMessageCenterInternal(bool show_settings); - - // Queries login status and the status area widget to determine visibility of - // the message center. - bool ShouldShowMessageCenter(); - - // Returns true if it should show the quiet mode menu. - bool ShouldShowQuietModeMenu(const ui::Event& event); - - // Shows the quiet mode menu. - void ShowQuietModeMenu(const ui::Event& event); - - // Creates the menu model for quiet mode and returns it. - ui::MenuModel* CreateQuietModeMenu(); - - internal::WebNotificationBubbleWrapper* message_center_bubble() const { - return message_center_bubble_.get(); - } - - // Testing accessors. - bool IsPopupVisible() const; - message_center::MessageCenterBubble* GetMessageCenterBubbleForTest(); - - scoped_ptr<message_center::MessageCenterTray> message_center_tray_; - scoped_ptr<internal::WebNotificationBubbleWrapper> message_center_bubble_; - scoped_ptr<message_center::MessagePopupCollection> popup_collection_; - internal::WebNotificationButton* button_; - - bool show_message_center_on_unlock_; - - bool should_update_tray_content_; - - // True when the shelf auto hide behavior has to be blocked. Previously - // this was done by checking |message_center_bubble_| but actually - // the check can be called when creating this object, so it would cause - // flickers of the shelf from hidden to shown. See: crbug.com/181213 - bool should_block_shelf_auto_hide_; - - // Observes the work area for |popup_collection_| and notifies to it. - scoped_ptr<internal::WorkAreaObserver> work_area_observer_; - - DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); -}; - -} // namespace ash - -#endif // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ diff --git a/chromium/ash/system/web_notification/web_notification_tray_unittest.cc b/chromium/ash/system/web_notification/web_notification_tray_unittest.cc deleted file mode 100644 index b64e2b8f7f4..00000000000 --- a/chromium/ash/system/web_notification/web_notification_tray_unittest.cc +++ /dev/null @@ -1,487 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/system/web_notification/web_notification_tray.h" - -#include <vector> - -#include "ash/display/display_manager.h" -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_layout_manager.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/system/status_area_widget.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_item.h" -#include "ash/test/ash_test_base.h" -#include "ash/test/test_system_tray_delegate.h" -#include "ash/wm/window_state.h" -#include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/test/event_generator.h" -#include "ui/aura/window.h" -#include "ui/gfx/display.h" -#include "ui/gfx/screen.h" -#include "ui/message_center/message_center_style.h" -#include "ui/message_center/message_center_tray.h" -#include "ui/message_center/message_center_util.h" -#include "ui/message_center/notification_list.h" -#include "ui/message_center/notification_types.h" -#include "ui/message_center/views/message_center_bubble.h" -#include "ui/message_center/views/message_popup_collection.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -namespace ash { - -namespace { - -WebNotificationTray* GetTray() { - return Shell::GetPrimaryRootWindowController()->shelf()-> - status_area_widget()->web_notification_tray(); -} - -WebNotificationTray* GetSecondaryTray() { - internal::RootWindowController* primary_controller = - Shell::GetPrimaryRootWindowController(); - Shell::RootWindowControllerList controllers = - Shell::GetAllRootWindowControllers(); - for (size_t i = 0; i < controllers.size(); ++i) { - if (controllers[i] != primary_controller) { - return controllers[i]->shelf()-> - status_area_widget()->web_notification_tray(); - } - } - - return NULL; -} - -message_center::MessageCenter* GetMessageCenter() { - return GetTray()->message_center(); -} - -SystemTray* GetSystemTray() { - return Shell::GetPrimaryRootWindowController()->shelf()-> - status_area_widget()->system_tray(); -} - -// Trivial item implementation for testing PopupAndSystemTray test case. -class TestItem : public SystemTrayItem { - public: - TestItem() : SystemTrayItem(GetSystemTray()) {} - - virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE { - views::View* default_view = new views::View; - default_view->SetLayoutManager(new views::FillLayout); - default_view->AddChildView(new views::Label(UTF8ToUTF16("Default"))); - return default_view; - } - - virtual views::View* CreateNotificationView( - user::LoginStatus status) OVERRIDE { - return new views::View; - } - - private: - DISALLOW_COPY_AND_ASSIGN(TestItem); -}; - -} // namespace - -class WebNotificationTrayTest : public test::AshTestBase { - public: - WebNotificationTrayTest() {} - virtual ~WebNotificationTrayTest() {} - - virtual void TearDown() OVERRIDE { - GetMessageCenter()->RemoveAllNotifications(false); - test::AshTestBase::TearDown(); - } - - protected: - void AddNotification(const std::string& id) { - scoped_ptr<message_center::Notification> notification; - notification.reset(new message_center::Notification( - message_center::NOTIFICATION_TYPE_SIMPLE, - id, - ASCIIToUTF16("Test Web Notification"), - ASCIIToUTF16("Notification message body."), - gfx::Image(), - ASCIIToUTF16("www.test.org"), - message_center::NotifierId(), - message_center::RichNotificationData(), - NULL /* delegate */)); - GetMessageCenter()->AddNotification(notification.Pass()); - } - - void UpdateNotification(const std::string& old_id, - const std::string& new_id) { - scoped_ptr<message_center::Notification> notification; - notification.reset(new message_center::Notification( - message_center::NOTIFICATION_TYPE_SIMPLE, - new_id, - ASCIIToUTF16("Updated Web Notification"), - ASCIIToUTF16("Updated message body."), - gfx::Image(), - ASCIIToUTF16("www.test.org"), - message_center::NotifierId(), - message_center::RichNotificationData(), - NULL /* delegate */)); - GetMessageCenter()->UpdateNotification(old_id, notification.Pass()); - } - - void RemoveNotification(const std::string& id) { - GetMessageCenter()->RemoveNotification(id, false); - } - - views::Widget* GetWidget() { - return GetTray()->GetWidget(); - } - - gfx::Rect GetPopupWorkArea() { - return GetPopupWorkAreaForTray(GetTray()); - } - - gfx::Rect GetPopupWorkAreaForTray(WebNotificationTray* tray) { - return tray->popup_collection_->work_area_; - } - - bool IsPopupVisible() { - return GetTray()->IsPopupVisible(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(WebNotificationTrayTest); -}; - -TEST_F(WebNotificationTrayTest, WebNotifications) { - // TODO(mukai): move this test case to ui/message_center. - ASSERT_TRUE(GetWidget()); - - // Add a notification. - AddNotification("test_id1"); - EXPECT_EQ(1u, GetMessageCenter()->NotificationCount()); - EXPECT_TRUE(GetMessageCenter()->HasNotification("test_id1")); - AddNotification("test_id2"); - AddNotification("test_id2"); - EXPECT_EQ(2u, GetMessageCenter()->NotificationCount()); - EXPECT_TRUE(GetMessageCenter()->HasNotification("test_id2")); - - // Ensure that updating a notification does not affect the count. - UpdateNotification("test_id2", "test_id3"); - UpdateNotification("test_id3", "test_id3"); - EXPECT_EQ(2u, GetMessageCenter()->NotificationCount()); - EXPECT_FALSE(GetMessageCenter()->HasNotification("test_id2")); - - // Ensure that Removing the first notification removes it from the tray. - RemoveNotification("test_id1"); - EXPECT_FALSE(GetMessageCenter()->HasNotification("test_id1")); - EXPECT_EQ(1u, GetMessageCenter()->NotificationCount()); - - // Remove the remianing notification. - RemoveNotification("test_id3"); - EXPECT_EQ(0u, GetMessageCenter()->NotificationCount()); - EXPECT_FALSE(GetMessageCenter()->HasNotification("test_id3")); -} - -TEST_F(WebNotificationTrayTest, WebNotificationPopupBubble) { - // TODO(mukai): move this test case to ui/message_center. - ASSERT_TRUE(GetWidget()); - - // Adding a notification should show the popup bubble. - AddNotification("test_id1"); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - - // Updating a notification should not hide the popup bubble. - AddNotification("test_id2"); - UpdateNotification("test_id2", "test_id3"); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - - // Removing the first notification should not hide the popup bubble. - RemoveNotification("test_id1"); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - - // Removing the visible notification should hide the popup bubble. - RemoveNotification("test_id3"); - EXPECT_FALSE(GetTray()->IsPopupVisible()); - - // Now test that we can show multiple popups and then show the message center. - AddNotification("test_id4"); - AddNotification("test_id5"); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - - GetTray()->message_center_tray_->ShowMessageCenterBubble(); - GetTray()->message_center_tray_->HideMessageCenterBubble(); - - EXPECT_FALSE(GetTray()->IsPopupVisible()); -} - -using message_center::NotificationList; - - -// Flakily fails. http://crbug.com/229791 -TEST_F(WebNotificationTrayTest, DISABLED_ManyMessageCenterNotifications) { - // Add the max visible notifications +1, ensure the correct visible number. - size_t notifications_to_add = - message_center::kMaxVisibleMessageCenterNotifications + 1; - for (size_t i = 0; i < notifications_to_add; ++i) { - std::string id = base::StringPrintf("test_id%d", static_cast<int>(i)); - AddNotification(id); - } - bool shown = GetTray()->message_center_tray_->ShowMessageCenterBubble(); - EXPECT_TRUE(shown); - RunAllPendingInMessageLoop(); - EXPECT_TRUE(GetTray()->message_center_bubble() != NULL); - EXPECT_EQ(notifications_to_add, - GetMessageCenter()->NotificationCount()); - EXPECT_EQ(message_center::kMaxVisibleMessageCenterNotifications, - GetTray()->GetMessageCenterBubbleForTest()-> - NumMessageViewsForTest()); -} - -// Flakily times out. http://crbug.com/229792 -TEST_F(WebNotificationTrayTest, DISABLED_ManyPopupNotifications) { - // Add the max visible popup notifications +1, ensure the correct num visible. - size_t notifications_to_add = - message_center::kMaxVisiblePopupNotifications + 1; - for (size_t i = 0; i < notifications_to_add; ++i) { - std::string id = base::StringPrintf("test_id%d", static_cast<int>(i)); - AddNotification(id); - } - GetTray()->ShowPopups(); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - EXPECT_EQ(notifications_to_add, - GetMessageCenter()->NotificationCount()); - NotificationList::PopupNotifications popups = - GetMessageCenter()->GetPopupNotifications(); - EXPECT_EQ(message_center::kMaxVisiblePopupNotifications, popups.size()); -} - -#if defined(OS_CHROMEOS) -// Display notification is ChromeOS only. -#define MAYBE_PopupShownOnBothDisplays PopupShownOnBothDisplays -#define MAYBE_PopupAndSystemTrayMultiDisplay PopupAndSystemTrayMultiDisplay -#else -#define MAYBE_PopupShownOnBothDisplays DISABLED_PopupShownOnBothDisplays -#define MAYBE_PopupAndSystemTrayMultiDisplay \ - DISABLED_PopupAndSystemTrayMultiDisplay -#endif - -// Verifies if the notification appears on both displays when extended mode. -TEST_F(WebNotificationTrayTest, MAYBE_PopupShownOnBothDisplays) { - if (!SupportsMultipleDisplays()) - return; - - // Enables to appear the notification for display changes. - test::TestSystemTrayDelegate* tray_delegate = - static_cast<test::TestSystemTrayDelegate*>( - Shell::GetInstance()->system_tray_delegate()); - tray_delegate->set_should_show_display_notification(true); - - UpdateDisplay("400x400,200x200"); - // UpdateDisplay() creates the display notifications, so popup is visible. - EXPECT_TRUE(GetTray()->IsPopupVisible()); - WebNotificationTray* secondary_tray = GetSecondaryTray(); - ASSERT_TRUE(secondary_tray); - EXPECT_TRUE(secondary_tray->IsPopupVisible()); - - // Transition to mirroring and then back to extended display, which recreates - // root window controller and shelf with having notifications. This code - // verifies it doesn't cause crash and popups are still visible. See - // http://crbug.com/263664 - internal::DisplayManager* display_manager = - Shell::GetInstance()->display_manager(); - - display_manager->SetSecondDisplayMode(internal::DisplayManager::MIRRORING); - UpdateDisplay("400x400,200x200"); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - EXPECT_FALSE(GetSecondaryTray()); - - display_manager->SetSecondDisplayMode(internal::DisplayManager::EXTENDED); - UpdateDisplay("400x400,200x200"); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - secondary_tray = GetSecondaryTray(); - ASSERT_TRUE(secondary_tray); - EXPECT_TRUE(secondary_tray->IsPopupVisible()); -} - -#if defined(OS_CHROMEOS) -// PopupAndSystemTray may fail in platforms other than ChromeOS because the -// RootWindow's bound can be bigger than gfx::Display's work area so that -// openingsystem tray doesn't affect at all the work area of popups. -#define MAYBE_PopupAndSystemTray PopupAndSystemTray -#define MAYBE_PopupAndAutoHideShelf PopupAndAutoHideShelf -#define MAYBE_PopupAndFullscreen PopupAndFullscreen -#else -#define MAYBE_PopupAndSystemTray DISABLED_PopupAndSystemTray -#define MAYBE_PopupAndAutoHideShelf DISABLED_PopupAndAutoHideShelf -#define MAYBE_PopupAndFullscreen DISABLED_PopupAndFullscreen -#endif - -TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTray) { - TestItem* test_item = new TestItem; - GetSystemTray()->AddTrayItem(test_item); - - AddNotification("test_id"); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - gfx::Rect work_area = GetPopupWorkArea(); - - // System tray is created, the popup's work area should be narrowed but still - // visible. - GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - gfx::Rect work_area_with_tray = GetPopupWorkArea(); - EXPECT_GT(work_area.size().GetArea(), work_area_with_tray.size().GetArea()); - - // System tray notification is also created, the popup's work area is narrowed - // even more, but still visible. - GetSystemTray()->ShowNotificationView(test_item); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - gfx::Rect work_area_with_tray_notificaiton = GetPopupWorkArea(); - EXPECT_GT(work_area.size().GetArea(), - work_area_with_tray_notificaiton.size().GetArea()); - EXPECT_GT(work_area_with_tray.size().GetArea(), - work_area_with_tray_notificaiton.size().GetArea()); - - // Close system tray, only system tray notifications. - GetSystemTray()->ClickedOutsideBubble(); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - gfx::Rect work_area_with_notification = GetPopupWorkArea(); - EXPECT_GT(work_area.size().GetArea(), - work_area_with_notification.size().GetArea()); - EXPECT_LT(work_area_with_tray_notificaiton.size().GetArea(), - work_area_with_notification.size().GetArea()); - - // Close the system tray notifications. - GetSystemTray()->HideNotificationView(test_item); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - EXPECT_EQ(work_area.ToString(), GetPopupWorkArea().ToString()); -} - -TEST_F(WebNotificationTrayTest, MAYBE_PopupAndAutoHideShelf) { - AddNotification("test_id"); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - gfx::Rect work_area = GetPopupWorkArea(); - - // Shelf's auto-hide state won't be HIDDEN unless window exists. - scoped_ptr<aura::Window> window( - CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); - internal::ShelfLayoutManager* shelf = - Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); - shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); - - EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); - gfx::Rect work_area_auto_hidden = GetPopupWorkArea(); - EXPECT_LT(work_area.size().GetArea(), work_area_auto_hidden.size().GetArea()); - - // Close the window, which shows the shelf. - window.reset(); - EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); - gfx::Rect work_area_auto_shown = GetPopupWorkArea(); - EXPECT_EQ(work_area.ToString(), work_area_auto_shown.ToString()); - - // Create the system tray during auto-hide. - window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); - TestItem* test_item = new TestItem; - GetSystemTray()->AddTrayItem(test_item); - GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); - - EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); - EXPECT_TRUE(GetTray()->IsPopupVisible()); - gfx::Rect work_area_with_tray = GetPopupWorkArea(); - EXPECT_GT(work_area_auto_shown.size().GetArea(), - work_area_with_tray.size().GetArea()); - - // Create tray notification. - GetSystemTray()->ShowNotificationView(test_item); - EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); - gfx::Rect work_area_with_tray_notification = GetPopupWorkArea(); - EXPECT_GT(work_area_with_tray.size().GetArea(), - work_area_with_tray_notification.size().GetArea()); - - // Close the system tray. - GetSystemTray()->ClickedOutsideBubble(); - shelf->UpdateAutoHideState(); - RunAllPendingInMessageLoop(); - EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); - gfx::Rect work_area_hidden_with_tray_notification = GetPopupWorkArea(); - EXPECT_LT(work_area_with_tray_notification.size().GetArea(), - work_area_hidden_with_tray_notification.size().GetArea()); - EXPECT_GT(work_area_auto_hidden.size().GetArea(), - work_area_hidden_with_tray_notification.size().GetArea()); - - // Close the window again, which shows the shelf. - window.reset(); - EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); - gfx::Rect work_area_shown_with_tray_notification = GetPopupWorkArea(); - EXPECT_GT(work_area_hidden_with_tray_notification.size().GetArea(), - work_area_shown_with_tray_notification.size().GetArea()); - EXPECT_GT(work_area_auto_shown.size().GetArea(), - work_area_shown_with_tray_notification.size().GetArea()); -} - -TEST_F(WebNotificationTrayTest, MAYBE_PopupAndFullscreen) { - AddNotification("test_id"); - EXPECT_TRUE(IsPopupVisible()); - gfx::Rect work_area = GetPopupWorkArea(); - - // Checks the work area for normal auto-hidden state. - scoped_ptr<aura::Window> window( - CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); - internal::ShelfLayoutManager* shelf = - Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); - shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); - EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); - gfx::Rect work_area_auto_hidden = GetPopupWorkArea(); - shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); - - // Put |window| into fullscreen without forcing the shelf to hide. Currently, - // this is used by immersive fullscreen and forces the shelf to be auto - // hidden. - wm::GetWindowState(window.get())->set_hide_shelf_when_fullscreen(false); - window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); - RunAllPendingInMessageLoop(); - - // The work area for auto-hidden status of fullscreen is a bit larger - // since it doesn't even have the 3-pixel width. - EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); - gfx::Rect work_area_fullscreen_hidden = GetPopupWorkArea(); - EXPECT_EQ(work_area_auto_hidden.ToString(), - work_area_fullscreen_hidden.ToString()); - - // Move the mouse cursor at the bottom, which shows the shelf. - aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); - gfx::Point bottom_right = - Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom_right(); - bottom_right.Offset(-1, -1); - generator.MoveMouseTo(bottom_right); - shelf->UpdateAutoHideStateNow(); - EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); - EXPECT_EQ(work_area.ToString(), GetPopupWorkArea().ToString()); - - generator.MoveMouseTo(work_area.CenterPoint()); - shelf->UpdateAutoHideStateNow(); - EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); - EXPECT_EQ(work_area_auto_hidden.ToString(), GetPopupWorkArea().ToString()); -} - -TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTrayMultiDisplay) { - UpdateDisplay("800x600,600x400"); - - AddNotification("test_id"); - gfx::Rect work_area = GetPopupWorkArea(); - gfx::Rect work_area_second = GetPopupWorkAreaForTray(GetSecondaryTray()); - - // System tray is created on the primary display. The popups in the secondary - // tray aren't affected. - GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW); - EXPECT_GT(work_area.size().GetArea(), GetPopupWorkArea().size().GetArea()); - EXPECT_EQ(work_area_second.ToString(), - GetPopupWorkAreaForTray(GetSecondaryTray()).ToString()); -} - -} // namespace ash |