Commit ef3e5f0e authored by mazda@chromium.org's avatar mazda@chromium.org

Support toggling Wi-Fi with keyboard shortcut.

- F11 key toggles Wi-Fi when Debugging keyboard shortcuts is enabled.
- A notification is shown when Wi-Fi enable/disable is toggled.

BUG=139039
TEST=F11 key toggles Wi-Fi with "Debug keyboard shortcuts" enabled in about:flags.


Review URL: https://chromiumcodereview.appspot.com/10824142

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149887 0039d316-1c4b-4281-b951-d872f2087c98
parent 0249553b
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "ash/system/brightness/brightness_control_delegate.h" #include "ash/system/brightness/brightness_control_delegate.h"
#include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
#include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/volume_control_delegate.h" #include "ash/volume_control_delegate.h"
#include "ash/wm/partial_screenshot_view.h" #include "ash/wm/partial_screenshot_view.h"
#include "ash/wm/property_util.h" #include "ash/wm/property_util.h"
...@@ -408,6 +409,10 @@ bool AcceleratorController::PerformAction(int action, ...@@ -408,6 +409,10 @@ bool AcceleratorController::PerformAction(int action,
return HandleCrosh(); return HandleCrosh();
case TOGGLE_SPOKEN_FEEDBACK: case TOGGLE_SPOKEN_FEEDBACK:
return HandleToggleSpokenFeedback(); return HandleToggleSpokenFeedback();
case TOGGLE_WIFI:
if (Shell::GetInstance()->tray_delegate())
Shell::GetInstance()->tray_delegate()->ToggleWifi();
return true;
case CYCLE_DISPLAY_MODE: { case CYCLE_DISPLAY_MODE: {
internal::OutputConfiguratorAnimation* animation = internal::OutputConfiguratorAnimation* animation =
Shell::GetInstance()->output_configurator_animation(); Shell::GetInstance()->output_configurator_animation();
......
...@@ -139,6 +139,7 @@ const AcceleratorData kDebugAcceleratorData[] = { ...@@ -139,6 +139,7 @@ const AcceleratorData kDebugAcceleratorData[] = {
{ true, ui::VKEY_B, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, { true, ui::VKEY_B, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
TOGGLE_DESKTOP_BACKGROUND_MODE }, TOGGLE_DESKTOP_BACKGROUND_MODE },
{ true, ui::VKEY_F11, ui::EF_CONTROL_DOWN, TOGGLE_ROOT_WINDOW_FULL_SCREEN }, { true, ui::VKEY_F11, ui::EF_CONTROL_DOWN, TOGGLE_ROOT_WINDOW_FULL_SCREEN },
{ true, ui::VKEY_W, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, TOGGLE_WIFI },
// For testing on systems where Alt-Tab is already mapped. // For testing on systems where Alt-Tab is already mapped.
{ true, ui::VKEY_W, ui::EF_ALT_DOWN, CYCLE_FORWARD_MRU }, { true, ui::VKEY_W, ui::EF_ALT_DOWN, CYCLE_FORWARD_MRU },
{ true, ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, CYCLE_BACKWARD_MRU }, { true, ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, CYCLE_BACKWARD_MRU },
...@@ -204,6 +205,7 @@ const AcceleratorAction kActionsAllowedAtLoginOrLockScreen[] = { ...@@ -204,6 +205,7 @@ const AcceleratorAction kActionsAllowedAtLoginOrLockScreen[] = {
TAKE_PARTIAL_SCREENSHOT, TAKE_PARTIAL_SCREENSHOT,
TOGGLE_CAPS_LOCK, TOGGLE_CAPS_LOCK,
TOGGLE_SPOKEN_FEEDBACK, TOGGLE_SPOKEN_FEEDBACK,
TOGGLE_WIFI,
VOLUME_DOWN, VOLUME_DOWN,
VOLUME_MUTE, VOLUME_MUTE,
VOLUME_UP, VOLUME_UP,
......
...@@ -61,6 +61,7 @@ enum AcceleratorAction { ...@@ -61,6 +61,7 @@ enum AcceleratorAction {
TOGGLE_DESKTOP_BACKGROUND_MODE, TOGGLE_DESKTOP_BACKGROUND_MODE,
TOGGLE_ROOT_WINDOW_FULL_SCREEN, TOGGLE_ROOT_WINDOW_FULL_SCREEN,
TOGGLE_SPOKEN_FEEDBACK, TOGGLE_SPOKEN_FEEDBACK,
TOGGLE_WIFI,
VOLUME_DOWN, VOLUME_DOWN,
VOLUME_MUTE, VOLUME_MUTE,
VOLUME_UP, VOLUME_UP,
......
...@@ -242,6 +242,12 @@ Press Ctrl+Alt+Z to cancel. ...@@ -242,6 +242,12 @@ Press Ctrl+Alt+Z to cancel.
<message name="IDS_ASH_STATUS_TRAY_NETWORK_PROXY_SETTINGS" desc="The label used in the proxy settings entry in the network dialog in the login screen."> <message name="IDS_ASH_STATUS_TRAY_NETWORK_PROXY_SETTINGS" desc="The label used in the proxy settings entry in the network dialog in the login screen.">
Proxy... Proxy...
</message> </message>
<message name="IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED" desc="The label used in the tray popup to notify that Wi-Fi is turned on.">
Wi-Fi is turned on.
</message>
<message name="IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED" desc="The label used in the tray popup to notify that Wi-Fi is turned off.">
Wi-Fi is turned off.
</message>
<message name="IDS_ASH_STATUS_TRAY_SMS" desc="The label used in the status tray for SMS."> <message name="IDS_ASH_STATUS_TRAY_SMS" desc="The label used in the status tray for SMS.">
SMS SMS
</message> </message>
......
...@@ -42,6 +42,11 @@ class NetworkObserver { ...@@ -42,6 +42,11 @@ class NetworkObserver {
const string16& link_text) = 0; const string16& link_text) = 0;
// Clears the error notification for |error_type|. // Clears the error notification for |error_type|.
virtual void ClearNetworkError(ErrorType error_type) = 0; virtual void ClearNetworkError(ErrorType error_type) = 0;
// Called when the user attempted to toggle Wi-Fi enable/disable.
// NOTE: Toggling is asynchronous and subsequent calls to query the current
// state may return the old value.
virtual void OnWillToggleWifi() = 0;
}; };
} // namespace ash } // namespace ash
......
...@@ -197,11 +197,22 @@ class NetworkDefaultView : public TrayItemMore { ...@@ -197,11 +197,22 @@ class NetworkDefaultView : public TrayItemMore {
DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView);
}; };
class NetworkDetailedView : public TrayDetailsView, class NetworkDetailedView : public TrayDetailsView {
public:
NetworkDetailedView() {}
virtual ~NetworkDetailedView() {}
virtual TrayNetwork::DetailedViewType GetViewType() const = 0;
virtual void Update() = 0;
};
class NetworkListDetailedView : public NetworkDetailedView,
public views::ButtonListener, public views::ButtonListener,
public ViewClickListener { public ViewClickListener {
public: public:
explicit NetworkDetailedView(user::LoginStatus login) NetworkListDetailedView(user::LoginStatus login)
: login_(login), : login_(login),
airplane_(NULL), airplane_(NULL),
info_icon_(NULL), info_icon_(NULL),
...@@ -220,7 +231,7 @@ class NetworkDetailedView : public TrayDetailsView, ...@@ -220,7 +231,7 @@ class NetworkDetailedView : public TrayDetailsView,
Update(); Update();
} }
virtual ~NetworkDetailedView() { virtual ~NetworkListDetailedView() {
if (info_bubble_) if (info_bubble_)
info_bubble_->GetWidget()->CloseNow(); info_bubble_->GetWidget()->CloseNow();
} }
...@@ -247,7 +258,12 @@ class NetworkDetailedView : public TrayDetailsView, ...@@ -247,7 +258,12 @@ class NetworkDetailedView : public TrayDetailsView,
Update(); Update();
} }
void Update() { // Overridden from NetworkDetailedView:
virtual TrayNetwork::DetailedViewType GetViewType() const OVERRIDE {
return TrayNetwork::LIST_VIEW;
}
virtual void Update() OVERRIDE {
UpdateHeaderButtons(); UpdateHeaderButtons();
UpdateNetworkEntries(); UpdateNetworkEntries();
UpdateNetworkExtra(); UpdateNetworkExtra();
...@@ -611,7 +627,44 @@ class NetworkDetailedView : public TrayDetailsView, ...@@ -611,7 +627,44 @@ class NetworkDetailedView : public TrayDetailsView,
views::BubbleDelegateView* info_bubble_; views::BubbleDelegateView* info_bubble_;
DISALLOW_COPY_AND_ASSIGN(NetworkDetailedView); DISALLOW_COPY_AND_ASSIGN(NetworkListDetailedView);
};
class NetworkWifiDetailedView : public NetworkDetailedView {
public:
explicit NetworkWifiDetailedView(bool wifi_enabled) {
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
kTrayPopupPaddingHorizontal,
10,
kTrayPopupPaddingBetweenItems));
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
views::ImageView* image = new views::ImageView;
const int image_id = wifi_enabled ?
IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED;
image->SetImage(bundle.GetImageNamed(image_id).ToImageSkia());
AddChildView(image);
const int string_id = wifi_enabled ?
IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED:
IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
views::Label* label =
new views::Label(bundle.GetLocalizedString(string_id));
label->SetMultiLine(true);
label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
AddChildView(label);
}
virtual ~NetworkWifiDetailedView() {}
// Overridden from NetworkDetailedView:
virtual TrayNetwork::DetailedViewType GetViewType() const OVERRIDE {
return TrayNetwork::WIFI_VIEW;
}
virtual void Update() OVERRIDE {}
private:
DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
}; };
class NetworkErrorView : public views::View, class NetworkErrorView : public views::View,
...@@ -715,7 +768,8 @@ TrayNetwork::TrayNetwork() ...@@ -715,7 +768,8 @@ TrayNetwork::TrayNetwork()
default_(NULL), default_(NULL),
detailed_(NULL), detailed_(NULL),
notification_(NULL), notification_(NULL),
errors_(new tray::NetworkErrors()) { errors_(new tray::NetworkErrors()),
request_wifi_view_(false) {
} }
TrayNetwork::~TrayNetwork() { TrayNetwork::~TrayNetwork() {
...@@ -735,7 +789,14 @@ views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { ...@@ -735,7 +789,14 @@ views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) {
views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) {
CHECK(detailed_ == NULL); CHECK(detailed_ == NULL);
detailed_ = new tray::NetworkDetailedView(status); if (request_wifi_view_) {
SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate();
// The Wi-Fi state is not toggled yet at this point.
detailed_ = new tray::NetworkWifiDetailedView(!delegate->GetWifiEnabled());
request_wifi_view_ = false;
} else {
detailed_ = new tray::NetworkListDetailedView(status);
}
return detailed_; return detailed_;
} }
...@@ -805,6 +866,13 @@ void TrayNetwork::ClearNetworkError(ErrorType error_type) { ...@@ -805,6 +866,13 @@ void TrayNetwork::ClearNetworkError(ErrorType error_type) {
ShowNotificationView(); ShowNotificationView();
} }
void TrayNetwork::OnWillToggleWifi() {
if (!detailed_ || detailed_->GetViewType() == WIFI_VIEW) {
request_wifi_view_ = true;
PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
}
}
void TrayNetwork::LinkClicked(ErrorType error_type) { void TrayNetwork::LinkClicked(ErrorType error_type) {
tray::NetworkErrors::ErrorMap::const_iterator iter = tray::NetworkErrors::ErrorMap::const_iterator iter =
errors()->messages().find(error_type); errors()->messages().find(error_type);
......
...@@ -24,6 +24,11 @@ class NetworkTrayView; ...@@ -24,6 +24,11 @@ class NetworkTrayView;
class TrayNetwork : public SystemTrayItem, class TrayNetwork : public SystemTrayItem,
public NetworkObserver { public NetworkObserver {
public: public:
enum DetailedViewType {
LIST_VIEW,
WIFI_VIEW,
};
TrayNetwork(); TrayNetwork();
virtual ~TrayNetwork(); virtual ~TrayNetwork();
...@@ -49,6 +54,7 @@ class TrayNetwork : public SystemTrayItem, ...@@ -49,6 +54,7 @@ class TrayNetwork : public SystemTrayItem,
const string16& message, const string16& message,
const string16& link_text) OVERRIDE; const string16& link_text) OVERRIDE;
virtual void ClearNetworkError(ErrorType error_type) OVERRIDE; virtual void ClearNetworkError(ErrorType error_type) OVERRIDE;
virtual void OnWillToggleWifi() OVERRIDE;
private: private:
friend class tray::NetworkErrorView; friend class tray::NetworkErrorView;
...@@ -63,6 +69,7 @@ class TrayNetwork : public SystemTrayItem, ...@@ -63,6 +69,7 @@ class TrayNetwork : public SystemTrayItem,
tray::NetworkDetailedView* detailed_; tray::NetworkDetailedView* detailed_;
tray::NetworkNotificationView* notification_; tray::NetworkNotificationView* notification_;
scoped_ptr<tray::NetworkErrors> errors_; scoped_ptr<tray::NetworkErrors> errors_;
bool request_wifi_view_;
DISALLOW_COPY_AND_ASSIGN(TrayNetwork); DISALLOW_COPY_AND_ASSIGN(TrayNetwork);
}; };
......
...@@ -689,6 +689,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -689,6 +689,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
} }
virtual void ToggleWifi() OVERRIDE { virtual void ToggleWifi() OVERRIDE {
tray_->network_observer()->OnWillToggleWifi();
network_menu_->ToggleWifi(); network_menu_->ToggleWifi();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment