| Index: ash/accelerators/accelerator_controller.cc
|
| diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
|
| deleted file mode 100644
|
| index 6dbdbfa681009b92eb23ba3d2cc271b17dfb4c1d..0000000000000000000000000000000000000000
|
| --- a/ash/accelerators/accelerator_controller.cc
|
| +++ /dev/null
|
| @@ -1,836 +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/accelerators/accelerator_controller.h"
|
| -
|
| -#include "ash/accelerators/accelerator_commands.h"
|
| -#include "ash/accelerators/accelerator_controller_delegate.h"
|
| -#include "ash/accelerators/debug_commands.h"
|
| -#include "ash/common/accessibility_delegate.h"
|
| -#include "ash/common/accessibility_types.h"
|
| -#include "ash/common/focus_cycler.h"
|
| -#include "ash/common/media_delegate.h"
|
| -#include "ash/common/multi_profile_uma.h"
|
| -#include "ash/common/session/session_state_delegate.h"
|
| -#include "ash/common/shell_delegate.h"
|
| -#include "ash/common/system/brightness_control_delegate.h"
|
| -#include "ash/common/system/keyboard_brightness_control_delegate.h"
|
| -#include "ash/common/system/tray/system_tray_delegate.h"
|
| -#include "ash/common/system/tray/system_tray_notifier.h"
|
| -#include "ash/common/system/volume_control_delegate.h"
|
| -#include "ash/common/wm/mru_window_tracker.h"
|
| -#include "ash/common/wm/overview/window_selector_controller.h"
|
| -#include "ash/common/wm/window_cycle_controller.h"
|
| -#include "ash/common/wm/window_positioning_utils.h"
|
| -#include "ash/common/wm/window_state.h"
|
| -#include "ash/common/wm/wm_event.h"
|
| -#include "ash/common/wm_shell.h"
|
| -#include "ash/common/wm_window.h"
|
| -#include "ash/ime_control_delegate.h"
|
| -#include "base/metrics/histogram_macros.h"
|
| -#include "base/metrics/user_metrics.h"
|
| -#include "ui/base/accelerators/accelerator.h"
|
| -#include "ui/base/accelerators/accelerator_manager.h"
|
| -
|
| -#if defined(OS_CHROMEOS)
|
| -#include "chromeos/dbus/dbus_thread_manager.h"
|
| -#include "chromeos/dbus/power_manager_client.h"
|
| -#include "ui/base/ime/chromeos/ime_keyboard.h"
|
| -#include "ui/base/ime/chromeos/input_method_manager.h"
|
| -#endif // defined(OS_CHROMEOS)
|
| -
|
| -namespace ash {
|
| -namespace {
|
| -
|
| -using base::UserMetricsAction;
|
| -
|
| -ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode,
|
| - int modifiers,
|
| - bool trigger_on_press) {
|
| - ui::Accelerator accelerator(keycode, modifiers);
|
| - accelerator.set_type(trigger_on_press ? ui::ET_KEY_PRESSED
|
| - : ui::ET_KEY_RELEASED);
|
| - return accelerator;
|
| -}
|
| -
|
| -void RecordUmaHistogram(const char* histogram_name,
|
| - DeprecatedAcceleratorUsage sample) {
|
| - auto* histogram = base::LinearHistogram::FactoryGet(
|
| - histogram_name, 1, DEPRECATED_USAGE_COUNT, DEPRECATED_USAGE_COUNT + 1,
|
| - base::HistogramBase::kUmaTargetedHistogramFlag);
|
| - histogram->Add(sample);
|
| -}
|
| -
|
| -void HandleCycleBackwardMRU(const ui::Accelerator& accelerator) {
|
| - if (accelerator.key_code() == ui::VKEY_TAB)
|
| - base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab"));
|
| -
|
| - WmShell::Get()->window_cycle_controller()->HandleCycleWindow(
|
| - WindowCycleController::BACKWARD);
|
| -}
|
| -
|
| -void HandleCycleForwardMRU(const ui::Accelerator& accelerator) {
|
| - if (accelerator.key_code() == ui::VKEY_TAB)
|
| - base::RecordAction(base::UserMetricsAction("Accel_NextWindow_Tab"));
|
| -
|
| - WmShell::Get()->window_cycle_controller()->HandleCycleWindow(
|
| - WindowCycleController::FORWARD);
|
| -}
|
| -
|
| -void HandleRotatePaneFocus(FocusCycler::Direction direction) {
|
| - switch (direction) {
|
| - // TODO(stevet): Not sure if this is the same as IDC_FOCUS_NEXT_PANE.
|
| - case FocusCycler::FORWARD: {
|
| - base::RecordAction(UserMetricsAction("Accel_Focus_Next_Pane"));
|
| - break;
|
| - }
|
| - case FocusCycler::BACKWARD: {
|
| - base::RecordAction(UserMetricsAction("Accel_Focus_Previous_Pane"));
|
| - break;
|
| - }
|
| - }
|
| - WmShell::Get()->focus_cycler()->RotateFocus(direction);
|
| -}
|
| -
|
| -void HandleMediaNextTrack() {
|
| - WmShell::Get()->media_delegate()->HandleMediaNextTrack();
|
| -}
|
| -
|
| -void HandleMediaPlayPause() {
|
| - WmShell::Get()->media_delegate()->HandleMediaPlayPause();
|
| -}
|
| -
|
| -void HandleMediaPrevTrack() {
|
| - WmShell::Get()->media_delegate()->HandleMediaPrevTrack();
|
| -}
|
| -
|
| -bool CanHandleNextIme(ImeControlDelegate* ime_control_delegate) {
|
| - return ime_control_delegate && ime_control_delegate->CanCycleIme();
|
| -}
|
| -
|
| -// We must avoid showing the Deprecated NEXT_IME notification erronously.
|
| -bool ShouldShowDeprecatedNextImeNotification(
|
| - const ui::Accelerator& previous_accelerator) {
|
| - // We only show the deprecation notification if the previous accelerator key
|
| - // is ONLY either Shift, or Alt.
|
| - const ui::KeyboardCode previous_key_code = previous_accelerator.key_code();
|
| - switch (previous_key_code) {
|
| - case ui::VKEY_SHIFT:
|
| - case ui::VKEY_LSHIFT:
|
| - case ui::VKEY_RSHIFT:
|
| - case ui::VKEY_MENU:
|
| - case ui::VKEY_LMENU:
|
| - case ui::VKEY_RMENU:
|
| - return true;
|
| -
|
| - default:
|
| - return false;
|
| - }
|
| -}
|
| -
|
| -void HandleNextIme(ImeControlDelegate* ime_control_delegate) {
|
| - base::RecordAction(UserMetricsAction("Accel_Next_Ime"));
|
| - ime_control_delegate->HandleNextIme();
|
| -}
|
| -
|
| -bool CanHandlePreviousIme(ImeControlDelegate* ime_control_delegate) {
|
| - return ime_control_delegate && ime_control_delegate->CanCycleIme();
|
| -}
|
| -
|
| -void HandlePreviousIme(ImeControlDelegate* ime_control_delegate,
|
| - const ui::Accelerator& accelerator) {
|
| - base::RecordAction(UserMetricsAction("Accel_Previous_Ime"));
|
| - if (accelerator.type() == ui::ET_KEY_PRESSED)
|
| - ime_control_delegate->HandlePreviousIme();
|
| - // Else: consume the Ctrl+Space ET_KEY_RELEASED event but do not do anything.
|
| -}
|
| -
|
| -bool CanHandleSwitchIme(ImeControlDelegate* ime_control_delegate,
|
| - const ui::Accelerator& accelerator) {
|
| - return ime_control_delegate &&
|
| - ime_control_delegate->CanSwitchIme(accelerator);
|
| -}
|
| -
|
| -void HandleSwitchIme(ImeControlDelegate* ime_control_delegate,
|
| - const ui::Accelerator& accelerator) {
|
| - base::RecordAction(UserMetricsAction("Accel_Switch_Ime"));
|
| - ime_control_delegate->HandleSwitchIme(accelerator);
|
| -}
|
| -
|
| -void HandleToggleFullscreen(const ui::Accelerator& accelerator) {
|
| - if (accelerator.key_code() == ui::VKEY_MEDIA_LAUNCH_APP2)
|
| - base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4"));
|
| - accelerators::ToggleFullscreen();
|
| -}
|
| -
|
| -void HandleToggleOverview() {
|
| - base::RecordAction(base::UserMetricsAction("Accel_Overview_F5"));
|
| - WmShell::Get()->window_selector_controller()->ToggleOverview();
|
| -}
|
| -
|
| -bool CanHandleWindowSnapOrDock() {
|
| - WmWindow* active_window = WmShell::Get()->GetActiveWindow();
|
| - if (!active_window)
|
| - return false;
|
| - wm::WindowState* window_state = active_window->GetWindowState();
|
| - // Disable window snapping shortcut key for full screen window due to
|
| - // http://crbug.com/135487.
|
| - return (window_state && window_state->IsUserPositionable() &&
|
| - !window_state->IsFullscreen());
|
| -}
|
| -
|
| -void HandleWindowSnapOrDock(AcceleratorAction action) {
|
| - if (action == WINDOW_CYCLE_SNAP_DOCK_LEFT)
|
| - base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left"));
|
| - else
|
| - base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right"));
|
| -
|
| - const wm::WMEvent event(action == WINDOW_CYCLE_SNAP_DOCK_LEFT
|
| - ? wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT
|
| - : wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT);
|
| - WmWindow* active_window = WmShell::Get()->GetActiveWindow();
|
| - DCHECK(active_window);
|
| - active_window->GetWindowState()->OnWMEvent(&event);
|
| -}
|
| -
|
| -void HandleWindowMinimize() {
|
| - base::RecordAction(base::UserMetricsAction("Accel_Toggle_Minimized_Minus"));
|
| - accelerators::ToggleMinimized();
|
| -}
|
| -
|
| -bool CanHandlePositionCenter() {
|
| - // Docked windows do not support centering.
|
| - WmWindow* active_window = WmShell::Get()->GetActiveWindow();
|
| - return (active_window && !active_window->GetWindowState()->IsDocked());
|
| -}
|
| -
|
| -void HandlePositionCenter() {
|
| - base::RecordAction(UserMetricsAction("Accel_Window_Position_Center"));
|
| - wm::CenterWindow(WmShell::Get()->GetActiveWindow());
|
| -}
|
| -
|
| -#if defined(OS_CHROMEOS)
|
| -bool CanHandleDisableCapsLock(const ui::Accelerator& previous_accelerator) {
|
| - ui::KeyboardCode previous_key_code = previous_accelerator.key_code();
|
| - if (previous_accelerator.type() == ui::ET_KEY_RELEASED ||
|
| - (previous_key_code != ui::VKEY_LSHIFT &&
|
| - previous_key_code != ui::VKEY_SHIFT &&
|
| - previous_key_code != ui::VKEY_RSHIFT)) {
|
| - // If something else was pressed between the Shift key being pressed
|
| - // and released, then ignore the release of the Shift key.
|
| - return false;
|
| - }
|
| - chromeos::input_method::InputMethodManager* ime =
|
| - chromeos::input_method::InputMethodManager::Get();
|
| - chromeos::input_method::ImeKeyboard* keyboard =
|
| - ime ? ime->GetImeKeyboard() : NULL;
|
| - return (keyboard && keyboard->CapsLockIsEnabled());
|
| -}
|
| -
|
| -void HandleDisableCapsLock() {
|
| - base::RecordAction(UserMetricsAction("Accel_Disable_Caps_Lock"));
|
| - chromeos::input_method::InputMethodManager* ime =
|
| - chromeos::input_method::InputMethodManager::Get();
|
| - ime->GetImeKeyboard()->SetCapsLockEnabled(false);
|
| -}
|
| -
|
| -bool CanHandleLock() {
|
| - return WmShell::Get()->GetSessionStateDelegate()->CanLockScreen();
|
| -}
|
| -
|
| -void HandleLock() {
|
| - base::RecordAction(UserMetricsAction("Accel_LockScreen_L"));
|
| - WmShell::Get()->GetSessionStateDelegate()->LockScreen();
|
| -}
|
| -
|
| -void HandleSuspend() {
|
| - base::RecordAction(UserMetricsAction("Accel_Suspend"));
|
| - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestSuspend();
|
| -}
|
| -
|
| -bool CanHandleCycleUser() {
|
| - return WmShell::Get()->delegate()->IsMultiProfilesEnabled() &&
|
| - WmShell::Get()->GetSessionStateDelegate()->NumberOfLoggedInUsers() > 1;
|
| -}
|
| -
|
| -void HandleCycleUser(SessionStateDelegate::CycleUser cycle_user) {
|
| - MultiProfileUMA::RecordSwitchActiveUser(
|
| - MultiProfileUMA::SWITCH_ACTIVE_USER_BY_ACCELERATOR);
|
| - switch (cycle_user) {
|
| - case SessionStateDelegate::CYCLE_TO_NEXT_USER:
|
| - base::RecordAction(UserMetricsAction("Accel_Switch_To_Next_User"));
|
| - break;
|
| - case SessionStateDelegate::CYCLE_TO_PREVIOUS_USER:
|
| - base::RecordAction(UserMetricsAction("Accel_Switch_To_Previous_User"));
|
| - break;
|
| - }
|
| - WmShell::Get()->GetSessionStateDelegate()->CycleActiveUser(cycle_user);
|
| -}
|
| -
|
| -bool CanHandleToggleCapsLock(const ui::Accelerator& accelerator,
|
| - const ui::Accelerator& previous_accelerator) {
|
| - if (accelerator.key_code() == ui::VKEY_LWIN) {
|
| - // If something else was pressed between the Search key (LWIN)
|
| - // being pressed and released, then ignore the release of the
|
| - // Search key.
|
| - // TODO(danakj): Releasing Alt first breaks this: crbug.com/166495
|
| - if (previous_accelerator.type() == ui::ET_KEY_RELEASED ||
|
| - previous_accelerator.key_code() != ui::VKEY_LWIN)
|
| - return false;
|
| - }
|
| - chromeos::input_method::InputMethodManager* ime =
|
| - chromeos::input_method::InputMethodManager::Get();
|
| - return ime && ime->GetImeKeyboard();
|
| -}
|
| -
|
| -void HandleToggleCapsLock() {
|
| - base::RecordAction(UserMetricsAction("Accel_Toggle_Caps_Lock"));
|
| - chromeos::input_method::InputMethodManager* ime =
|
| - chromeos::input_method::InputMethodManager::Get();
|
| - chromeos::input_method::ImeKeyboard* keyboard = ime->GetImeKeyboard();
|
| - keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled());
|
| -}
|
| -
|
| -void HandleToggleSpokenFeedback() {
|
| - base::RecordAction(UserMetricsAction("Accel_Toggle_Spoken_Feedback"));
|
| -
|
| - WmShell::Get()->accessibility_delegate()->ToggleSpokenFeedback(
|
| - A11Y_NOTIFICATION_SHOW);
|
| -}
|
| -
|
| -void HandleVolumeDown(const ui::Accelerator& accelerator) {
|
| - VolumeControlDelegate* volume_delegate =
|
| - WmShell::Get()->system_tray_delegate()->GetVolumeControlDelegate();
|
| - if (volume_delegate)
|
| - volume_delegate->HandleVolumeDown(accelerator);
|
| -}
|
| -
|
| -void HandleVolumeMute(const ui::Accelerator& accelerator) {
|
| - VolumeControlDelegate* volume_delegate =
|
| - WmShell::Get()->system_tray_delegate()->GetVolumeControlDelegate();
|
| - if (volume_delegate)
|
| - volume_delegate->HandleVolumeMute(accelerator);
|
| -}
|
| -
|
| -void HandleVolumeUp(const ui::Accelerator& accelerator) {
|
| - VolumeControlDelegate* volume_delegate =
|
| - WmShell::Get()->system_tray_delegate()->GetVolumeControlDelegate();
|
| - if (volume_delegate)
|
| - volume_delegate->HandleVolumeUp(accelerator);
|
| -}
|
| -
|
| -#endif // defined(OS_CHROMEOS)
|
| -
|
| -} // namespace
|
| -
|
| -////////////////////////////////////////////////////////////////////////////////
|
| -// AcceleratorController, public:
|
| -
|
| -AcceleratorController::AcceleratorController(
|
| - AcceleratorControllerDelegate* delegate)
|
| - : delegate_(delegate),
|
| - accelerator_manager_(new ui::AcceleratorManager),
|
| - accelerator_history_(new ui::AcceleratorHistory) {
|
| - Init();
|
| -}
|
| -
|
| -AcceleratorController::~AcceleratorController() {}
|
| -
|
| -void AcceleratorController::Register(const ui::Accelerator& accelerator,
|
| - ui::AcceleratorTarget* target) {
|
| - accelerator_manager_->Register(
|
| - accelerator, ui::AcceleratorManager::kNormalPriority, target);
|
| -}
|
| -
|
| -void AcceleratorController::Unregister(const ui::Accelerator& accelerator,
|
| - ui::AcceleratorTarget* target) {
|
| - accelerator_manager_->Unregister(accelerator, target);
|
| -}
|
| -
|
| -void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) {
|
| - accelerator_manager_->UnregisterAll(target);
|
| -}
|
| -
|
| -bool AcceleratorController::Process(const ui::Accelerator& accelerator) {
|
| - return accelerator_manager_->Process(accelerator);
|
| -}
|
| -
|
| -bool AcceleratorController::IsRegistered(
|
| - const ui::Accelerator& accelerator) const {
|
| - return accelerator_manager_->IsRegistered(accelerator);
|
| -}
|
| -
|
| -bool AcceleratorController::IsPreferred(
|
| - const ui::Accelerator& accelerator) const {
|
| - std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter =
|
| - accelerators_.find(accelerator);
|
| - if (iter == accelerators_.end())
|
| - return false; // not an accelerator.
|
| -
|
| - return preferred_actions_.find(iter->second) != preferred_actions_.end();
|
| -}
|
| -
|
| -bool AcceleratorController::IsReserved(
|
| - const ui::Accelerator& accelerator) const {
|
| - std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter =
|
| - accelerators_.find(accelerator);
|
| - if (iter == accelerators_.end())
|
| - return false; // not an accelerator.
|
| -
|
| - return reserved_actions_.find(iter->second) != reserved_actions_.end();
|
| -}
|
| -
|
| -bool AcceleratorController::IsDeprecated(
|
| - const ui::Accelerator& accelerator) const {
|
| - return deprecated_accelerators_.count(accelerator) != 0;
|
| -}
|
| -
|
| -bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action) {
|
| - if (CanPerformAction(action, ui::Accelerator())) {
|
| - PerformAction(action, ui::Accelerator());
|
| - return true;
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -AcceleratorController::AcceleratorProcessingRestriction
|
| -AcceleratorController::GetCurrentAcceleratorRestriction() {
|
| - return GetAcceleratorProcessingRestriction(-1);
|
| -}
|
| -
|
| -void AcceleratorController::SetImeControlDelegate(
|
| - std::unique_ptr<ImeControlDelegate> ime_control_delegate) {
|
| - ime_control_delegate_ = std::move(ime_control_delegate);
|
| -}
|
| -
|
| -bool AcceleratorController::ShouldCloseMenuAndRepostAccelerator(
|
| - const ui::Accelerator& accelerator) const {
|
| - auto itr = accelerators_.find(accelerator);
|
| - if (itr == accelerators_.end())
|
| - return false; // Menu shouldn't be closed for an invalid accelerator.
|
| -
|
| - AcceleratorAction action = itr->second;
|
| - return actions_keeping_menu_open_.count(action) == 0;
|
| -}
|
| -
|
| -////////////////////////////////////////////////////////////////////////////////
|
| -// AcceleratorController, ui::AcceleratorTarget implementation:
|
| -
|
| -bool AcceleratorController::AcceleratorPressed(
|
| - const ui::Accelerator& accelerator) {
|
| - std::map<ui::Accelerator, AcceleratorAction>::const_iterator it =
|
| - accelerators_.find(accelerator);
|
| - DCHECK(it != accelerators_.end());
|
| - AcceleratorAction action = it->second;
|
| - if (CanPerformAction(action, accelerator)) {
|
| - // Handling the deprecated accelerators (if any) only if action can be
|
| - // performed.
|
| - auto itr = actions_with_deprecations_.find(action);
|
| - if (itr != actions_with_deprecations_.end()) {
|
| - const DeprecatedAcceleratorData* data = itr->second;
|
| - if (deprecated_accelerators_.count(accelerator)) {
|
| - // This accelerator has been deprecated and should be treated according
|
| - // to its |DeprecatedAcceleratorData|.
|
| -
|
| - // Record UMA stats.
|
| - RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED);
|
| -
|
| - // We always display the notification as long as this entry exists,
|
| - // except for NEXT_IME, we must check to avoid showing it for the wrong
|
| - // shortcut, as Alt+Shift is tricky and trigger the action on release.
|
| - if (delegate_ &&
|
| - (action != NEXT_IME ||
|
| - (action == NEXT_IME &&
|
| - ShouldShowDeprecatedNextImeNotification(
|
| - accelerator_history_->previous_accelerator())))) {
|
| - delegate_->ShowDeprecatedAcceleratorNotification(
|
| - data->uma_histogram_name, data->notification_message_id,
|
| - data->old_shortcut_id, data->new_shortcut_id);
|
| - }
|
| -
|
| - if (!data->deprecated_enabled)
|
| - return false;
|
| - } else {
|
| - // This is a new accelerator replacing the old deprecated one.
|
| - // Record UMA stats and proceed normally.
|
| - RecordUmaHistogram(data->uma_histogram_name, NEW_USED);
|
| - }
|
| - }
|
| -
|
| - PerformAction(action, accelerator);
|
| - return ShouldActionConsumeKeyEvent(action);
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -bool AcceleratorController::CanHandleAccelerators() const {
|
| - return true;
|
| -}
|
| -
|
| -///////////////////////////////////////////////////////////////////////////////
|
| -// AcceleratorController, private:
|
| -
|
| -void AcceleratorController::Init() {
|
| - for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) {
|
| - actions_allowed_at_login_screen_.insert(
|
| - kActionsAllowedAtLoginOrLockScreen[i]);
|
| - actions_allowed_at_lock_screen_.insert(
|
| - kActionsAllowedAtLoginOrLockScreen[i]);
|
| - }
|
| - for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i)
|
| - actions_allowed_at_lock_screen_.insert(kActionsAllowedAtLockScreen[i]);
|
| - for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i)
|
| - actions_allowed_at_modal_window_.insert(kActionsAllowedAtModalWindow[i]);
|
| - for (size_t i = 0; i < kPreferredActionsLength; ++i)
|
| - preferred_actions_.insert(kPreferredActions[i]);
|
| - for (size_t i = 0; i < kReservedActionsLength; ++i)
|
| - reserved_actions_.insert(kReservedActions[i]);
|
| - for (size_t i = 0; i < kRepeatableActionsLength; ++i)
|
| - repeatable_actions_.insert(kRepeatableActions[i]);
|
| - for (size_t i = 0; i < kActionsAllowedInAppModeOrPinnedModeLength; ++i) {
|
| - actions_allowed_in_app_mode_.insert(
|
| - kActionsAllowedInAppModeOrPinnedMode[i]);
|
| - actions_allowed_in_pinned_mode_.insert(
|
| - kActionsAllowedInAppModeOrPinnedMode[i]);
|
| - }
|
| - for (size_t i = 0; i < kActionsAllowedInPinnedModeLength; ++i)
|
| - actions_allowed_in_pinned_mode_.insert(kActionsAllowedInPinnedMode[i]);
|
| - for (size_t i = 0; i < kActionsNeedingWindowLength; ++i)
|
| - actions_needing_window_.insert(kActionsNeedingWindow[i]);
|
| - for (size_t i = 0; i < kActionsKeepingMenuOpenLength; ++i)
|
| - actions_keeping_menu_open_.insert(kActionsKeepingMenuOpen[i]);
|
| -
|
| - RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength);
|
| -
|
| - RegisterDeprecatedAccelerators();
|
| -
|
| - if (debug::DebugAcceleratorsEnabled()) {
|
| - RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength);
|
| - // All debug accelerators are reserved.
|
| - for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i)
|
| - reserved_actions_.insert(kDebugAcceleratorData[i].action);
|
| - }
|
| -}
|
| -
|
| -void AcceleratorController::RegisterAccelerators(
|
| - const AcceleratorData accelerators[],
|
| - size_t accelerators_length) {
|
| - for (size_t i = 0; i < accelerators_length; ++i) {
|
| - ui::Accelerator accelerator =
|
| - CreateAccelerator(accelerators[i].keycode, accelerators[i].modifiers,
|
| - accelerators[i].trigger_on_press);
|
| - Register(accelerator, this);
|
| - accelerators_.insert(std::make_pair(accelerator, accelerators[i].action));
|
| - }
|
| -}
|
| -
|
| -void AcceleratorController::RegisterDeprecatedAccelerators() {
|
| -#if defined(OS_CHROMEOS)
|
| - for (size_t i = 0; i < kDeprecatedAcceleratorsDataLength; ++i) {
|
| - const DeprecatedAcceleratorData* data = &kDeprecatedAcceleratorsData[i];
|
| - actions_with_deprecations_[data->action] = data;
|
| - }
|
| -
|
| - for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) {
|
| - const AcceleratorData& accelerator_data = kDeprecatedAccelerators[i];
|
| - const ui::Accelerator deprecated_accelerator =
|
| - CreateAccelerator(accelerator_data.keycode, accelerator_data.modifiers,
|
| - accelerator_data.trigger_on_press);
|
| -
|
| - Register(deprecated_accelerator, this);
|
| - accelerators_[deprecated_accelerator] = accelerator_data.action;
|
| - deprecated_accelerators_.insert(deprecated_accelerator);
|
| - }
|
| -#endif // defined(OS_CHROMEOS)
|
| -}
|
| -
|
| -bool AcceleratorController::CanPerformAction(
|
| - AcceleratorAction action,
|
| - const ui::Accelerator& accelerator) {
|
| - if (accelerator.IsRepeat() && !repeatable_actions_.count(action))
|
| - return false;
|
| -
|
| - AcceleratorProcessingRestriction restriction =
|
| - GetAcceleratorProcessingRestriction(action);
|
| - if (restriction != RESTRICTION_NONE)
|
| - return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
|
| -
|
| - const ui::Accelerator& previous_accelerator =
|
| - accelerator_history_->previous_accelerator();
|
| -
|
| - // True should be returned if running |action| does something. Otherwise,
|
| - // false should be returned to give the web contents a chance at handling the
|
| - // accelerator.
|
| - switch (action) {
|
| - case DEBUG_PRINT_LAYER_HIERARCHY:
|
| - case DEBUG_PRINT_VIEW_HIERARCHY:
|
| - case DEBUG_PRINT_WINDOW_HIERARCHY:
|
| - return debug::DebugAcceleratorsEnabled();
|
| - case NEXT_IME:
|
| - return CanHandleNextIme(ime_control_delegate_.get());
|
| - case PREVIOUS_IME:
|
| - return CanHandlePreviousIme(ime_control_delegate_.get());
|
| - case SWITCH_IME:
|
| - return CanHandleSwitchIme(ime_control_delegate_.get(), accelerator);
|
| - case WINDOW_CYCLE_SNAP_DOCK_LEFT:
|
| - case WINDOW_CYCLE_SNAP_DOCK_RIGHT:
|
| - return CanHandleWindowSnapOrDock();
|
| - case WINDOW_POSITION_CENTER:
|
| - return CanHandlePositionCenter();
|
| -#if defined(OS_CHROMEOS)
|
| - case DEBUG_SHOW_TOAST:
|
| - case DEBUG_TOGGLE_TOUCH_PAD:
|
| - case DEBUG_TOGGLE_TOUCH_SCREEN:
|
| - case DEBUG_TOGGLE_TOUCH_VIEW:
|
| - return debug::DebugAcceleratorsEnabled();
|
| - case DISABLE_CAPS_LOCK:
|
| - return CanHandleDisableCapsLock(previous_accelerator);
|
| - case LOCK_SCREEN:
|
| - return CanHandleLock();
|
| - case SWITCH_TO_PREVIOUS_USER:
|
| - case SWITCH_TO_NEXT_USER:
|
| - return CanHandleCycleUser();
|
| - case TOGGLE_CAPS_LOCK:
|
| - return CanHandleToggleCapsLock(accelerator, previous_accelerator);
|
| -#endif
|
| - case CYCLE_BACKWARD_MRU:
|
| - case CYCLE_FORWARD_MRU:
|
| - case EXIT:
|
| - case FOCUS_NEXT_PANE:
|
| - case FOCUS_PREVIOUS_PANE:
|
| - case MEDIA_NEXT_TRACK:
|
| - case MEDIA_PLAY_PAUSE:
|
| - case MEDIA_PREV_TRACK:
|
| - case PRINT_UI_HIERARCHIES:
|
| - case TOGGLE_FULLSCREEN:
|
| - case TOGGLE_MAXIMIZED:
|
| - case TOGGLE_OVERVIEW:
|
| - case WINDOW_MINIMIZE:
|
| -#if defined(OS_CHROMEOS)
|
| - case BRIGHTNESS_DOWN:
|
| - case BRIGHTNESS_UP:
|
| - case KEYBOARD_BRIGHTNESS_DOWN:
|
| - case KEYBOARD_BRIGHTNESS_UP:
|
| - case SUSPEND:
|
| - case TOGGLE_SPOKEN_FEEDBACK:
|
| - case TOGGLE_WIFI:
|
| - case VOLUME_DOWN:
|
| - case VOLUME_MUTE:
|
| - case VOLUME_UP:
|
| -#else
|
| - case DUMMY_FOR_RESERVED:
|
| -#endif
|
| - return true;
|
| -
|
| - default:
|
| - // Default switch is temporary until mash transition complete. Needed as
|
| - // some actions don't yet work with mash.
|
| - break;
|
| - }
|
| - return delegate_ && delegate_->HandlesAction(action) &&
|
| - delegate_->CanPerformAction(action, accelerator, previous_accelerator);
|
| -}
|
| -
|
| -void AcceleratorController::PerformAction(AcceleratorAction action,
|
| - const ui::Accelerator& accelerator) {
|
| - AcceleratorProcessingRestriction restriction =
|
| - GetAcceleratorProcessingRestriction(action);
|
| - if (restriction != RESTRICTION_NONE)
|
| - return;
|
| -
|
| - // If your accelerator invokes more than one line of code, please either
|
| - // implement it in your module's controller code or pull it into a HandleFoo()
|
| - // function above.
|
| - switch (action) {
|
| - case CYCLE_BACKWARD_MRU:
|
| - HandleCycleBackwardMRU(accelerator);
|
| - break;
|
| - case CYCLE_FORWARD_MRU:
|
| - HandleCycleForwardMRU(accelerator);
|
| - break;
|
| - case DEBUG_PRINT_LAYER_HIERARCHY:
|
| - case DEBUG_PRINT_VIEW_HIERARCHY:
|
| - case DEBUG_PRINT_WINDOW_HIERARCHY:
|
| - debug::PerformDebugActionIfEnabled(action);
|
| - break;
|
| - case EXIT:
|
| - // UMA metrics are recorded in the handler.
|
| - exit_warning_handler_.HandleAccelerator();
|
| - break;
|
| - case FOCUS_NEXT_PANE:
|
| - HandleRotatePaneFocus(FocusCycler::FORWARD);
|
| - break;
|
| - case FOCUS_PREVIOUS_PANE:
|
| - HandleRotatePaneFocus(FocusCycler::BACKWARD);
|
| - break;
|
| - case MEDIA_NEXT_TRACK:
|
| - HandleMediaNextTrack();
|
| - break;
|
| - case MEDIA_PLAY_PAUSE:
|
| - HandleMediaPlayPause();
|
| - break;
|
| - case MEDIA_PREV_TRACK:
|
| - HandleMediaPrevTrack();
|
| - break;
|
| - case NEXT_IME:
|
| - HandleNextIme(ime_control_delegate_.get());
|
| - break;
|
| - case PREVIOUS_IME:
|
| - HandlePreviousIme(ime_control_delegate_.get(), accelerator);
|
| - break;
|
| - case PRINT_UI_HIERARCHIES:
|
| - debug::PrintUIHierarchies();
|
| - break;
|
| - case SWITCH_IME:
|
| - HandleSwitchIme(ime_control_delegate_.get(), accelerator);
|
| - break;
|
| - case TOGGLE_FULLSCREEN:
|
| - HandleToggleFullscreen(accelerator);
|
| - break;
|
| - case TOGGLE_MAXIMIZED:
|
| - accelerators::ToggleMaximized();
|
| - break;
|
| - case TOGGLE_OVERVIEW:
|
| - HandleToggleOverview();
|
| - break;
|
| - case WINDOW_CYCLE_SNAP_DOCK_LEFT:
|
| - case WINDOW_CYCLE_SNAP_DOCK_RIGHT:
|
| - HandleWindowSnapOrDock(action);
|
| - break;
|
| - case WINDOW_MINIMIZE:
|
| - HandleWindowMinimize();
|
| - break;
|
| - case WINDOW_POSITION_CENTER:
|
| - HandlePositionCenter();
|
| - break;
|
| -#if defined(OS_CHROMEOS)
|
| - case BRIGHTNESS_DOWN: {
|
| - BrightnessControlDelegate* delegate =
|
| - WmShell::Get()->brightness_control_delegate();
|
| - if (delegate)
|
| - delegate->HandleBrightnessDown(accelerator);
|
| - break;
|
| - }
|
| - case BRIGHTNESS_UP: {
|
| - BrightnessControlDelegate* delegate =
|
| - WmShell::Get()->brightness_control_delegate();
|
| - if (delegate)
|
| - delegate->HandleBrightnessUp(accelerator);
|
| - break;
|
| - }
|
| - case DEBUG_SHOW_TOAST:
|
| - case DEBUG_TOGGLE_TOUCH_PAD:
|
| - case DEBUG_TOGGLE_TOUCH_SCREEN:
|
| - case DEBUG_TOGGLE_TOUCH_VIEW:
|
| - debug::PerformDebugActionIfEnabled(action);
|
| - break;
|
| - case DISABLE_CAPS_LOCK:
|
| - HandleDisableCapsLock();
|
| - break;
|
| - case KEYBOARD_BRIGHTNESS_DOWN: {
|
| - KeyboardBrightnessControlDelegate* delegate =
|
| - WmShell::Get()->keyboard_brightness_control_delegate();
|
| - if (delegate)
|
| - delegate->HandleKeyboardBrightnessDown(accelerator);
|
| - break;
|
| - }
|
| - case KEYBOARD_BRIGHTNESS_UP: {
|
| - KeyboardBrightnessControlDelegate* delegate =
|
| - WmShell::Get()->keyboard_brightness_control_delegate();
|
| - if (delegate)
|
| - delegate->HandleKeyboardBrightnessUp(accelerator);
|
| - break;
|
| - }
|
| - case LOCK_SCREEN:
|
| - HandleLock();
|
| - break;
|
| - case SUSPEND:
|
| - HandleSuspend();
|
| - break;
|
| - case SWITCH_TO_NEXT_USER:
|
| - HandleCycleUser(SessionStateDelegate::CYCLE_TO_NEXT_USER);
|
| - break;
|
| - case SWITCH_TO_PREVIOUS_USER:
|
| - HandleCycleUser(SessionStateDelegate::CYCLE_TO_PREVIOUS_USER);
|
| - break;
|
| - case TOGGLE_CAPS_LOCK:
|
| - HandleToggleCapsLock();
|
| - break;
|
| - case TOGGLE_SPOKEN_FEEDBACK:
|
| - HandleToggleSpokenFeedback();
|
| - break;
|
| - case TOGGLE_WIFI:
|
| - WmShell::Get()->system_tray_notifier()->NotifyRequestToggleWifi();
|
| - break;
|
| - case VOLUME_DOWN:
|
| - HandleVolumeDown(accelerator);
|
| - break;
|
| - case VOLUME_MUTE:
|
| - HandleVolumeMute(accelerator);
|
| - break;
|
| - case VOLUME_UP:
|
| - HandleVolumeUp(accelerator);
|
| - break;
|
| -#else
|
| - case DUMMY_FOR_RESERVED:
|
| - NOTREACHED();
|
| - break;
|
| -#endif
|
| - default:
|
| - // Temporary until mash transition complete. Needed as some actions
|
| - // don't yet work with mash.
|
| - DCHECK(delegate_ && delegate_->HandlesAction(action));
|
| - delegate_->PerformAction(action, accelerator);
|
| - break;
|
| - }
|
| -}
|
| -
|
| -bool AcceleratorController::ShouldActionConsumeKeyEvent(
|
| - AcceleratorAction action) {
|
| - // Adding new exceptions is *STRONGLY* discouraged.
|
| - return true;
|
| -}
|
| -
|
| -AcceleratorController::AcceleratorProcessingRestriction
|
| -AcceleratorController::GetAcceleratorProcessingRestriction(int action) {
|
| - if (WmShell::Get()->IsPinned() &&
|
| - actions_allowed_in_pinned_mode_.find(action) ==
|
| - actions_allowed_in_pinned_mode_.end()) {
|
| - return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
|
| - }
|
| - WmShell* wm_shell = WmShell::Get();
|
| - if (!wm_shell->GetSessionStateDelegate()->IsActiveUserSessionStarted() &&
|
| - actions_allowed_at_login_screen_.find(action) ==
|
| - actions_allowed_at_login_screen_.end()) {
|
| - return RESTRICTION_PREVENT_PROCESSING;
|
| - }
|
| - if (wm_shell->GetSessionStateDelegate()->IsScreenLocked() &&
|
| - actions_allowed_at_lock_screen_.find(action) ==
|
| - actions_allowed_at_lock_screen_.end()) {
|
| - return RESTRICTION_PREVENT_PROCESSING;
|
| - }
|
| - if (wm_shell->delegate()->IsRunningInForcedAppMode() &&
|
| - actions_allowed_in_app_mode_.find(action) ==
|
| - actions_allowed_in_app_mode_.end()) {
|
| - return RESTRICTION_PREVENT_PROCESSING;
|
| - }
|
| - if (WmShell::Get()->IsSystemModalWindowOpen() &&
|
| - actions_allowed_at_modal_window_.find(action) ==
|
| - actions_allowed_at_modal_window_.end()) {
|
| - // Note we prevent the shortcut from propagating so it will not
|
| - // be passed to the modal window. This is important for things like
|
| - // Alt+Tab that would cause an undesired effect in the modal window by
|
| - // cycling through its window elements.
|
| - return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
|
| - }
|
| - if (wm_shell->mru_window_tracker()->BuildMruWindowList().empty() &&
|
| - actions_needing_window_.find(action) != actions_needing_window_.end()) {
|
| - wm_shell->accessibility_delegate()->TriggerAccessibilityAlert(
|
| - A11Y_ALERT_WINDOW_NEEDED);
|
| - return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
|
| - }
|
| - return RESTRICTION_NONE;
|
| -}
|
| -
|
| -} // namespace ash
|
|
|