Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2760)

Unified Diff: ash/accelerators/accelerator_controller.cc

Issue 2162193003: Separates out accelerators using non-common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@accelerators
Patch Set: sim=20 Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/accelerators/accelerator_controller.h ('k') | ash/accelerators/accelerator_controller_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/accelerators/accelerator_controller.cc
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index 8b354056338afd208391fd72f395d6a1d869dcef..da65a610a90dc696d73c0fd1d3954e4173d3e9f6 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -4,84 +4,36 @@
#include "ash/accelerators/accelerator_controller.h"
-#include <algorithm>
-#include <cmath>
-#include <string>
-#include <utility>
-
#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/ash_switches.h"
#include "ash/common/focus_cycler.h"
-#include "ash/common/gpu_support.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/shelf/shelf_model.h"
#include "ash/common/shell_delegate.h"
-#include "ash/common/shell_window_ids.h"
#include "ash/common/system/brightness_control_delegate.h"
#include "ash/common/system/keyboard_brightness_control_delegate.h"
-#include "ash/common/system/status_area_widget.h"
-#include "ash/common/system/system_notifier.h"
-#include "ash/common/system/tray/system_tray.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/system/web_notification/web_notification_tray.h"
-#include "ash/common/wm/maximize_mode/maximize_mode_controller.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/debug.h"
-#include "ash/display/window_tree_host_manager.h"
+#include "ash/common/wm_window.h"
#include "ash/ime_control_delegate.h"
-#include "ash/magnifier/magnification_controller.h"
-#include "ash/magnifier/partial_magnification_controller.h"
-#include "ash/new_window_delegate.h"
-#include "ash/root_window_controller.h"
-#include "ash/rotator/screen_rotation_animator.h"
-#include "ash/rotator/window_rotation.h"
-#include "ash/screen_util.h"
-#include "ash/screenshot_delegate.h"
-#include "ash/shelf/shelf.h"
-#include "ash/shelf/shelf_delegate.h"
-#include "ash/shelf/shelf_widget.h"
-#include "ash/shell.h"
-#include "ash/touch/touch_hud_debug.h"
-#include "ash/utility/screenshot_controller.h"
-#include "ash/wm/power_button_controller.h"
-#include "ash/wm/window_state_aura.h"
-#include "ash/wm/window_util.h"
-#include "base/bind.h"
-#include "base/command_line.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
-#include "base/strings/string_split.h"
-#include "base/strings/utf_string_conversions.h"
-#include "ui/aura/env.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/accelerators/accelerator_manager.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/compositor/layer.h"
-#include "ui/compositor/layer_animation_sequence.h"
-#include "ui/compositor/layer_animator.h"
-#include "ui/display/screen.h"
-#include "ui/events/event.h"
-#include "ui/events/keycodes/keyboard_codes.h"
-#include "ui/message_center/message_center.h"
-#include "ui/message_center/notification.h"
-#include "ui/message_center/notifier_settings.h"
#if defined(OS_CHROMEOS)
-#include "ash/display/display_configuration_controller.h"
-#include "base/sys_info.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h"
#include "ui/base/ime/chromeos/ime_keyboard.h"
@@ -93,28 +45,6 @@ namespace {
using base::UserMetricsAction;
-// The notification delegate that will be used to open the keyboard shortcut
-// help page when the notification is clicked.
-class DeprecatedAcceleratorNotificationDelegate
- : public message_center::NotificationDelegate {
- public:
- DeprecatedAcceleratorNotificationDelegate() {}
-
- // message_center::NotificationDelegate:
- bool HasClickedListener() override { return true; }
-
- void Click() override {
- if (!WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked())
- WmShell::Get()->delegate()->OpenKeyboardShortcutHelpPage();
- }
-
- private:
- // Private destructor since NotificationDelegate is ref-counted.
- ~DeprecatedAcceleratorNotificationDelegate() override {}
-
- DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorNotificationDelegate);
-};
-
ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode,
int modifiers,
bool trigger_on_press) {
@@ -124,63 +54,6 @@ ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode,
return accelerator;
}
-// Ensures that there are no word breaks at the "+"s in the shortcut texts such
-// as "Ctrl+Shift+Space".
-void EnsureNoWordBreaks(base::string16* shortcut_text) {
- std::vector<base::string16> keys =
- base::SplitString(*shortcut_text, base::ASCIIToUTF16("+"),
- base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
-
- if (keys.size() < 2U)
- return;
-
- // The plus sign surrounded by the word joiner to guarantee an non-breaking
- // shortcut.
- const base::string16 non_breaking_plus =
- base::UTF8ToUTF16("\xe2\x81\xa0+\xe2\x81\xa0");
- shortcut_text->clear();
- for (size_t i = 0; i < keys.size() - 1; ++i) {
- *shortcut_text += keys[i];
- *shortcut_text += non_breaking_plus;
- }
-
- *shortcut_text += keys.back();
-}
-
-// Gets the notification message after it formats it in such a way that there
-// are no line breaks in the middle of the shortcut texts.
-base::string16 GetNotificationText(int message_id,
- int old_shortcut_id,
- int new_shortcut_id) {
- base::string16 old_shortcut = l10n_util::GetStringUTF16(old_shortcut_id);
- base::string16 new_shortcut = l10n_util::GetStringUTF16(new_shortcut_id);
- EnsureNoWordBreaks(&old_shortcut);
- EnsureNoWordBreaks(&new_shortcut);
-
- return l10n_util::GetStringFUTF16(message_id, new_shortcut, old_shortcut);
-}
-
-void ShowDeprecatedAcceleratorNotification(const char* const notification_id,
- int message_id,
- int old_shortcut_id,
- int new_shortcut_id) {
- const base::string16 message =
- GetNotificationText(message_id, old_shortcut_id, new_shortcut_id);
- std::unique_ptr<message_center::Notification> notification(
- new message_center::Notification(
- message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
- base::string16(), message,
- WmShell::Get()->delegate()->GetDeprecatedAcceleratorImage(),
- base::string16(), GURL(),
- message_center::NotifierId(
- message_center::NotifierId::SYSTEM_COMPONENT,
- system_notifier::kNotifierDeprecatedAccelerator),
- message_center::RichNotificationData(),
- new DeprecatedAcceleratorNotificationDelegate));
- message_center::MessageCenter::Get()->AddNotification(
- std::move(notification));
-}
-
void RecordUmaHistogram(const char* histogram_name,
DeprecatedAcceleratorUsage sample) {
auto* histogram = base::LinearHistogram::FactoryGet(
@@ -220,49 +93,6 @@ void HandleRotatePaneFocus(FocusCycler::Direction direction) {
WmShell::Get()->focus_cycler()->RotateFocus(direction);
}
-void HandleFocusShelf() {
- base::RecordAction(base::UserMetricsAction("Accel_Focus_Shelf"));
- WmShell::Get()->focus_cycler()->FocusWidget(
- Shelf::ForPrimaryDisplay()->shelf_widget());
-}
-
-void HandleLaunchAppN(int n) {
- base::RecordAction(UserMetricsAction("Accel_Launch_App"));
- Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(n);
-}
-
-void HandleLaunchLastApp() {
- base::RecordAction(UserMetricsAction("Accel_Launch_Last_App"));
- Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(-1);
-}
-
-bool CanHandleMagnifyScreen() {
- Shell* shell = Shell::GetInstance();
- return shell->magnification_controller()->IsEnabled() ||
- shell->partial_magnification_controller()->is_enabled();
-}
-
-// Magnify the screen
-void HandleMagnifyScreen(int delta_index) {
- if (Shell::GetInstance()->magnification_controller()->IsEnabled()) {
- // TODO(yoshiki): Move the following logic to MagnificationController.
- float scale = Shell::GetInstance()->magnification_controller()->GetScale();
- // Calculate rounded logarithm (base kMagnificationScaleFactor) of scale.
- int scale_index =
- std::floor(std::log(scale) / std::log(kMagnificationScaleFactor) + 0.5);
-
- int new_scale_index = std::max(0, std::min(8, scale_index + delta_index));
-
- Shell::GetInstance()->magnification_controller()->SetScale(
- std::pow(kMagnificationScaleFactor, new_scale_index), true);
- } else if (Shell::GetInstance()
- ->partial_magnification_controller()
- ->is_enabled()) {
- float scale = delta_index > 0 ? kDefaultPartialMagnifiedScale : 1;
- Shell::GetInstance()->partial_magnification_controller()->SetScale(scale);
- }
-}
-
void HandleMediaNextTrack() {
WmShell::Get()->media_delegate()->HandleMediaNextTrack();
}
@@ -275,28 +105,6 @@ void HandleMediaPrevTrack() {
WmShell::Get()->media_delegate()->HandleMediaPrevTrack();
}
-bool CanHandleNewIncognitoWindow() {
- return WmShell::Get()->delegate()->IsIncognitoAllowed();
-}
-
-void HandleNewIncognitoWindow() {
- base::RecordAction(UserMetricsAction("Accel_New_Incognito_Window"));
- Shell::GetInstance()->new_window_delegate()->NewWindow(
- true /* is_incognito */);
-}
-
-void HandleNewTab(const ui::Accelerator& accelerator) {
- if (accelerator.key_code() == ui::VKEY_T)
- base::RecordAction(base::UserMetricsAction("Accel_NewTab_T"));
- Shell::GetInstance()->new_window_delegate()->NewTab();
-}
-
-void HandleNewWindow() {
- base::RecordAction(base::UserMetricsAction("Accel_New_Window"));
- Shell::GetInstance()->new_window_delegate()->NewWindow(
- false /* is_incognito */);
-}
-
bool CanHandleNextIme(ImeControlDelegate* ime_control_delegate) {
return ime_control_delegate && ime_control_delegate->CanCycleIme();
}
@@ -326,11 +134,6 @@ void HandleNextIme(ImeControlDelegate* ime_control_delegate) {
ime_control_delegate->HandleNextIme();
}
-void HandleOpenFeedbackPage() {
- base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page"));
- Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage();
-}
-
bool CanHandlePreviousIme(ImeControlDelegate* ime_control_delegate) {
return ime_control_delegate && ime_control_delegate->CanCycleIme();
}
@@ -343,100 +146,6 @@ void HandlePreviousIme(ImeControlDelegate* ime_control_delegate,
// Else: consume the Ctrl+Space ET_KEY_RELEASED event but do not do anything.
}
-void HandleRestoreTab() {
- base::RecordAction(base::UserMetricsAction("Accel_Restore_Tab"));
- Shell::GetInstance()->new_window_delegate()->RestoreTab();
-}
-
-display::Display::Rotation GetNextRotation(display::Display::Rotation current) {
- switch (current) {
- case display::Display::ROTATE_0:
- return display::Display::ROTATE_90;
- case display::Display::ROTATE_90:
- return display::Display::ROTATE_180;
- case display::Display::ROTATE_180:
- return display::Display::ROTATE_270;
- case display::Display::ROTATE_270:
- return display::Display::ROTATE_0;
- }
- NOTREACHED() << "Unknown rotation:" << current;
- return display::Display::ROTATE_0;
-}
-
-// Rotates the screen.
-void HandleRotateScreen() {
- if (Shell::GetInstance()->display_manager()->IsInUnifiedMode())
- return;
-
- base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
- gfx::Point point = display::Screen::GetScreen()->GetCursorScreenPoint();
- display::Display display =
- display::Screen::GetScreen()->GetDisplayNearestPoint(point);
- const DisplayInfo& display_info =
- Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id());
- ScreenRotationAnimator(display.id())
- .Rotate(GetNextRotation(display_info.GetActiveRotation()),
- display::Display::ROTATION_SOURCE_USER);
-}
-
-// Rotate the active window.
-void HandleRotateActiveWindow() {
- base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
- aura::Window* active_window = wm::GetActiveWindow();
- if (active_window) {
- // The rotation animation bases its target transform on the current
- // rotation and position. Since there could be an animation in progress
- // right now, queue this animation so when it starts it picks up a neutral
- // rotation and position. Use replace so we only enqueue one at a time.
- active_window->layer()->GetAnimator()->set_preemption_strategy(
- ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
- active_window->layer()->GetAnimator()->StartAnimation(
- new ui::LayerAnimationSequence(
- new WindowRotation(360, active_window->layer())));
- }
-}
-
-void HandleShowKeyboardOverlay() {
- base::RecordAction(UserMetricsAction("Accel_Show_Keyboard_Overlay"));
- Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay();
-}
-
-bool CanHandleShowMessageCenterBubble() {
- RootWindowController* controller =
- RootWindowController::ForTargetRootWindow();
- StatusAreaWidget* status_area_widget =
- controller->shelf_widget()->status_area_widget();
- return status_area_widget &&
- status_area_widget->web_notification_tray()->visible();
-}
-
-void HandleShowMessageCenterBubble() {
- base::RecordAction(UserMetricsAction("Accel_Show_Message_Center_Bubble"));
- RootWindowController* controller =
- RootWindowController::ForTargetRootWindow();
- StatusAreaWidget* status_area_widget =
- controller->shelf_widget()->status_area_widget();
- if (status_area_widget) {
- WebNotificationTray* notification_tray =
- status_area_widget->web_notification_tray();
- if (notification_tray->visible())
- notification_tray->ShowMessageCenterBubble();
- }
-}
-
-void HandleShowSystemTrayBubble() {
- base::RecordAction(UserMetricsAction("Accel_Show_System_Tray_Bubble"));
- RootWindowController* controller =
- RootWindowController::ForTargetRootWindow();
- if (!controller->GetSystemTray()->HasSystemBubble())
- controller->GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
-}
-
-void HandleShowTaskManager() {
- base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager"));
- Shell::GetInstance()->new_window_delegate()->ShowTaskManager();
-}
-
bool CanHandleSwitchIme(ImeControlDelegate* ime_control_delegate,
const ui::Accelerator& accelerator) {
return ime_control_delegate &&
@@ -449,53 +158,6 @@ void HandleSwitchIme(ImeControlDelegate* ime_control_delegate,
ime_control_delegate->HandleSwitchIme(accelerator);
}
-void HandleTakeWindowScreenshot(ScreenshotDelegate* screenshot_delegate) {
- base::RecordAction(UserMetricsAction("Accel_Take_Window_Screenshot"));
- DCHECK(screenshot_delegate);
- Shell::GetInstance()->screenshot_controller()->StartWindowScreenshotSession(
- screenshot_delegate);
-}
-
-void HandleTakePartialScreenshot(ScreenshotDelegate* screenshot_delegate) {
- base::RecordAction(UserMetricsAction("Accel_Take_Partial_Screenshot"));
- DCHECK(screenshot_delegate);
- Shell::GetInstance()->screenshot_controller()->StartPartialScreenshotSession(
- screenshot_delegate);
-}
-
-void HandleTakeScreenshot(ScreenshotDelegate* screenshot_delegate) {
- base::RecordAction(UserMetricsAction("Accel_Take_Screenshot"));
- DCHECK(screenshot_delegate);
- if (screenshot_delegate->CanTakeScreenshot())
- screenshot_delegate->HandleTakeScreenshotForAllRootWindows();
-}
-
-bool CanHandleToggleAppList(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.
- if (previous_accelerator.type() != ui::ET_KEY_PRESSED ||
- previous_accelerator.key_code() != ui::VKEY_LWIN) {
- return false;
- }
-
- // When spoken feedback is enabled, we should neither toggle the list nor
- // consume the key since Search+Shift is one of the shortcuts the a11y
- // feature uses. crbug.com/132296
- if (WmShell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled())
- return false;
- }
- return true;
-}
-
-void HandleToggleAppList(const ui::Accelerator& accelerator) {
- if (accelerator.key_code() == ui::VKEY_LWIN)
- base::RecordAction(base::UserMetricsAction("Accel_Search_LWin"));
- Shell::GetInstance()->ToggleAppList(NULL);
-}
-
void HandleToggleFullscreen(const ui::Accelerator& accelerator) {
if (accelerator.key_code() == ui::VKEY_MEDIA_LAUNCH_APP2)
base::RecordAction(UserMetricsAction("Accel_Fullscreen_F4"));
@@ -508,7 +170,10 @@ void HandleToggleOverview() {
}
bool CanHandleWindowSnapOrDock() {
- wm::WindowState* window_state = wm::GetActiveWindowState();
+ 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() &&
@@ -524,7 +189,9 @@ void HandleWindowSnapOrDock(AcceleratorAction action) {
const wm::WMEvent event(action == WINDOW_CYCLE_SNAP_DOCK_LEFT
? wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT
: wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT);
- wm::GetActiveWindowState()->OnWMEvent(&event);
+ WmWindow* active_window = WmShell::Get()->GetActiveWindow();
+ DCHECK(active_window);
+ active_window->GetWindowState()->OnWMEvent(&event);
}
void HandleWindowMinimize() {
@@ -534,22 +201,13 @@ void HandleWindowMinimize() {
bool CanHandlePositionCenter() {
// Docked windows do not support centering.
- wm::WindowState* window_state = wm::GetActiveWindowState();
- return (window_state && !window_state->IsDocked());
+ WmWindow* active_window = WmShell::Get()->GetActiveWindow();
+ return (active_window && !active_window->GetWindowState()->IsDocked());
}
void HandlePositionCenter() {
base::RecordAction(UserMetricsAction("Accel_Window_Position_Center"));
- wm::CenterWindow(wm::GetActiveWindow());
-}
-
-bool CanHandleUnpin() {
- wm::WindowState* window_state = wm::GetActiveWindowState();
- return window_state && window_state->IsPinned();
-}
-
-void HandleUnpin() {
- accelerators::Unpin();
+ wm::CenterWindow(WmShell::Get()->GetActiveWindow());
}
#if defined(OS_CHROMEOS)
@@ -591,28 +249,6 @@ void HandleSuspend() {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestSuspend();
}
-void HandleCrosh() {
- base::RecordAction(UserMetricsAction("Accel_Open_Crosh"));
-
- Shell::GetInstance()->new_window_delegate()->OpenCrosh();
-}
-
-void HandleFileManager() {
- base::RecordAction(UserMetricsAction("Accel_Open_File_Manager"));
-
- Shell::GetInstance()->new_window_delegate()->OpenFileManager();
-}
-
-void HandleGetHelp() {
- Shell::GetInstance()->new_window_delegate()->OpenGetHelp();
-}
-
-void HandleSwapPrimaryDisplay() {
- base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display"));
- Shell::GetInstance()->display_configuration_controller()->SetPrimaryDisplayId(
- ScreenUtil::GetSecondaryDisplay().id(), true /* user_action */);
-}
-
bool CanHandleCycleUser() {
return WmShell::Get()->delegate()->IsMultiProfilesEnabled() &&
WmShell::Get()->GetSessionStateDelegate()->NumberOfLoggedInUsers() > 1;
@@ -656,13 +292,6 @@ void HandleToggleCapsLock() {
keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled());
}
-void HandleToggleMirrorMode() {
- base::RecordAction(UserMetricsAction("Accel_Toggle_Mirror_Mode"));
- bool mirror = !Shell::GetInstance()->display_manager()->IsInMirrorMode();
- Shell::GetInstance()->display_configuration_controller()->SetMirrorMode(
- mirror, true /* user_action */);
-}
-
void HandleToggleSpokenFeedback() {
base::RecordAction(UserMetricsAction("Accel_Toggle_Spoken_Feedback"));
@@ -670,20 +299,6 @@ void HandleToggleSpokenFeedback() {
A11Y_NOTIFICATION_SHOW);
}
-bool CanHandleTouchHud() {
- return RootWindowController::ForTargetRootWindow()->touch_hud_debug();
-}
-
-void HandleTouchHudClear() {
- RootWindowController::ForTargetRootWindow()->touch_hud_debug()->Clear();
-}
-
-void HandleTouchHudModeChange() {
- RootWindowController* controller =
- RootWindowController::ForTargetRootWindow();
- controller->touch_hud_debug()->ChangeToNextMode();
-}
-
void HandleVolumeDown(const ui::Accelerator& accelerator) {
VolumeControlDelegate* volume_delegate =
WmShell::Get()->system_tray_delegate()->GetVolumeControlDelegate();
@@ -712,8 +327,10 @@ void HandleVolumeUp(const ui::Accelerator& accelerator) {
////////////////////////////////////////////////////////////////////////////////
// AcceleratorController, public:
-AcceleratorController::AcceleratorController()
- : accelerator_manager_(new ui::AcceleratorManager),
+AcceleratorController::AcceleratorController(
+ AcceleratorControllerDelegate* delegate)
+ : delegate_(delegate),
+ accelerator_manager_(new ui::AcceleratorManager),
accelerator_history_(new ui::AcceleratorHistory) {
Init();
}
@@ -787,11 +404,6 @@ void AcceleratorController::SetImeControlDelegate(
ime_control_delegate_ = std::move(ime_control_delegate);
}
-void AcceleratorController::SetScreenshotDelegate(
- std::unique_ptr<ScreenshotDelegate> screenshot_delegate) {
- screenshot_delegate_ = std::move(screenshot_delegate);
-}
-
bool AcceleratorController::ShouldCloseMenuAndRepostAccelerator(
const ui::Accelerator& accelerator) const {
auto itr = accelerators_.find(accelerator);
@@ -827,11 +439,12 @@ bool AcceleratorController::AcceleratorPressed(
// 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 (action != NEXT_IME ||
- (action == NEXT_IME &&
- ShouldShowDeprecatedNextImeNotification(
- accelerator_history_->previous_accelerator()))) {
- ShowDeprecatedAcceleratorNotification(
+ 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);
}
@@ -960,32 +573,17 @@ bool AcceleratorController::CanPerformAction(
case DEBUG_TOGGLE_SHOW_FPS_COUNTER:
case DEBUG_TOGGLE_SHOW_PAINT_RECTS:
return debug::DebugAcceleratorsEnabled();
- case MAGNIFY_SCREEN_ZOOM_IN:
- case MAGNIFY_SCREEN_ZOOM_OUT:
- return CanHandleMagnifyScreen();
- case NEW_INCOGNITO_WINDOW:
- return CanHandleNewIncognitoWindow();
case NEXT_IME:
return CanHandleNextIme(ime_control_delegate_.get());
case PREVIOUS_IME:
return CanHandlePreviousIme(ime_control_delegate_.get());
- case SCALE_UI_RESET:
- case SCALE_UI_UP:
- case SCALE_UI_DOWN:
- return accelerators::IsInternalDisplayZoomEnabled();
- case SHOW_MESSAGE_CENTER_BUBBLE:
- return CanHandleShowMessageCenterBubble();
case SWITCH_IME:
return CanHandleSwitchIme(ime_control_delegate_.get(), accelerator);
- case TOGGLE_APP_LIST:
- return CanHandleToggleAppList(accelerator, previous_accelerator);
case WINDOW_CYCLE_SNAP_DOCK_LEFT:
case WINDOW_CYCLE_SNAP_DOCK_RIGHT:
return CanHandleWindowSnapOrDock();
case WINDOW_POSITION_CENTER:
return CanHandlePositionCenter();
- case UNPIN:
- return CanHandleUnpin();
#if defined(OS_CHROMEOS)
case DEBUG_ADD_REMOVE_DISPLAY:
case DEBUG_SHOW_TOAST:
@@ -1003,43 +601,16 @@ bool AcceleratorController::CanPerformAction(
return CanHandleCycleUser();
case TOGGLE_CAPS_LOCK:
return CanHandleToggleCapsLock(accelerator, previous_accelerator);
- case TOUCH_HUD_CLEAR:
- case TOUCH_HUD_MODE_CHANGE:
- return CanHandleTouchHud();
- case SWAP_PRIMARY_DISPLAY:
- return display::Screen::GetScreen()->GetNumDisplays() > 1;
#endif
case CYCLE_BACKWARD_MRU:
case CYCLE_FORWARD_MRU:
case EXIT:
case FOCUS_NEXT_PANE:
case FOCUS_PREVIOUS_PANE:
- case FOCUS_SHELF:
- case LAUNCH_APP_0:
- case LAUNCH_APP_1:
- case LAUNCH_APP_2:
- case LAUNCH_APP_3:
- case LAUNCH_APP_4:
- case LAUNCH_APP_5:
- case LAUNCH_APP_6:
- case LAUNCH_APP_7:
- case LAUNCH_LAST_APP:
case MEDIA_NEXT_TRACK:
case MEDIA_PLAY_PAUSE:
case MEDIA_PREV_TRACK:
- case NEW_TAB:
- case NEW_WINDOW:
- case OPEN_FEEDBACK_PAGE:
case PRINT_UI_HIERARCHIES:
- case RESTORE_TAB:
- case ROTATE_SCREEN:
- case ROTATE_WINDOW:
- case SHOW_KEYBOARD_OVERLAY:
- case SHOW_SYSTEM_TRAY_BUBBLE:
- case SHOW_TASK_MANAGER:
- case TAKE_WINDOW_SCREENSHOT:
- case TAKE_PARTIAL_SCREENSHOT:
- case TAKE_SCREENSHOT:
case TOGGLE_FULLSCREEN:
case TOGGLE_MAXIMIZED:
case TOGGLE_OVERVIEW:
@@ -1047,21 +618,11 @@ bool AcceleratorController::CanPerformAction(
#if defined(OS_CHROMEOS)
case BRIGHTNESS_DOWN:
case BRIGHTNESS_UP:
- case DISABLE_GPU_WATCHDOG:
case KEYBOARD_BRIGHTNESS_DOWN:
case KEYBOARD_BRIGHTNESS_UP:
- case LOCK_PRESSED:
- case LOCK_RELEASED:
- case OPEN_CROSH:
- case OPEN_FILE_MANAGER:
- case OPEN_GET_HELP:
- case POWER_PRESSED:
- case POWER_RELEASED:
case SUSPEND:
- case TOGGLE_MIRROR_MODE:
case TOGGLE_SPOKEN_FEEDBACK:
case TOGGLE_WIFI:
- case TOUCH_HUD_PROJECTION_TOGGLE:
case VOLUME_DOWN:
case VOLUME_MUTE:
case VOLUME_UP:
@@ -1069,8 +630,14 @@ bool AcceleratorController::CanPerformAction(
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 false;
+ DCHECK(delegate_ && delegate_->HandlesAction(action));
+ return delegate_->CanPerformAction(action, accelerator, previous_accelerator);
}
void AcceleratorController::PerformAction(AcceleratorAction action,
@@ -1081,8 +648,8 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
return;
// If your accelerator invokes more than one line of code, please either
- // implement it in your module's controller code (like TOGGLE_MIRROR_MODE
- // below) or pull it into a HandleFoo() function above.
+ // implement it in your module's controller code or pull it into a HandleFoo()
+ // function above.
switch (action) {
case CYCLE_BACKWARD_MRU:
HandleCycleBackwardMRU(accelerator);
@@ -1111,42 +678,6 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
case FOCUS_PREVIOUS_PANE:
HandleRotatePaneFocus(FocusCycler::BACKWARD);
break;
- case FOCUS_SHELF:
- HandleFocusShelf();
- break;
- case LAUNCH_APP_0:
- HandleLaunchAppN(0);
- break;
- case LAUNCH_APP_1:
- HandleLaunchAppN(1);
- break;
- case LAUNCH_APP_2:
- HandleLaunchAppN(2);
- break;
- case LAUNCH_APP_3:
- HandleLaunchAppN(3);
- break;
- case LAUNCH_APP_4:
- HandleLaunchAppN(4);
- break;
- case LAUNCH_APP_5:
- HandleLaunchAppN(5);
- break;
- case LAUNCH_APP_6:
- HandleLaunchAppN(6);
- break;
- case LAUNCH_APP_7:
- HandleLaunchAppN(7);
- break;
- case LAUNCH_LAST_APP:
- HandleLaunchLastApp();
- break;
- case MAGNIFY_SCREEN_ZOOM_IN:
- HandleMagnifyScreen(1);
- break;
- case MAGNIFY_SCREEN_ZOOM_OUT:
- HandleMagnifyScreen(-1);
- break;
case MEDIA_NEXT_TRACK:
HandleMediaNextTrack();
break;
@@ -1156,72 +687,18 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
case MEDIA_PREV_TRACK:
HandleMediaPrevTrack();
break;
- case NEW_INCOGNITO_WINDOW:
- HandleNewIncognitoWindow();
- break;
- case NEW_TAB:
- HandleNewTab(accelerator);
- break;
- case NEW_WINDOW:
- HandleNewWindow();
- break;
case NEXT_IME:
HandleNextIme(ime_control_delegate_.get());
break;
- case OPEN_FEEDBACK_PAGE:
- HandleOpenFeedbackPage();
- break;
case PREVIOUS_IME:
HandlePreviousIme(ime_control_delegate_.get(), accelerator);
break;
case PRINT_UI_HIERARCHIES:
debug::PrintUIHierarchies();
break;
- case RESTORE_TAB:
- HandleRestoreTab();
- break;
- case ROTATE_SCREEN:
- HandleRotateScreen();
- break;
- case ROTATE_WINDOW:
- HandleRotateActiveWindow();
- break;
- case SCALE_UI_DOWN:
- accelerators::ZoomInternalDisplay(false /* down */);
- break;
- case SCALE_UI_RESET:
- accelerators::ResetInternalDisplayZoom();
- break;
- case SCALE_UI_UP:
- accelerators::ZoomInternalDisplay(true /* up */);
- break;
- case SHOW_KEYBOARD_OVERLAY:
- HandleShowKeyboardOverlay();
- break;
- case SHOW_MESSAGE_CENTER_BUBBLE:
- HandleShowMessageCenterBubble();
- break;
- case SHOW_SYSTEM_TRAY_BUBBLE:
- HandleShowSystemTrayBubble();
- break;
- case SHOW_TASK_MANAGER:
- HandleShowTaskManager();
- break;
case SWITCH_IME:
HandleSwitchIme(ime_control_delegate_.get(), accelerator);
break;
- case TAKE_WINDOW_SCREENSHOT:
- HandleTakeWindowScreenshot(screenshot_delegate_.get());
- break;
- case TAKE_PARTIAL_SCREENSHOT:
- HandleTakePartialScreenshot(screenshot_delegate_.get());
- break;
- case TAKE_SCREENSHOT:
- HandleTakeScreenshot(screenshot_delegate_.get());
- break;
- case TOGGLE_APP_LIST:
- HandleToggleAppList(accelerator);
- break;
case TOGGLE_FULLSCREEN:
HandleToggleFullscreen(accelerator);
break;
@@ -1241,9 +718,6 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
case WINDOW_POSITION_CENTER:
HandlePositionCenter();
break;
- case UNPIN:
- HandleUnpin();
- break;
#if defined(OS_CHROMEOS)
case BRIGHTNESS_DOWN: {
BrightnessControlDelegate* delegate =
@@ -1270,9 +744,6 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
case DISABLE_CAPS_LOCK:
HandleDisableCapsLock();
break;
- case DISABLE_GPU_WATCHDOG:
- Shell::GetInstance()->gpu_support()->DisableGpuWatchdog();
- break;
case KEYBOARD_BRIGHTNESS_DOWN: {
KeyboardBrightnessControlDelegate* delegate =
WmShell::Get()->keyboard_brightness_control_delegate();
@@ -1287,42 +758,12 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
delegate->HandleKeyboardBrightnessUp(accelerator);
break;
}
- case LOCK_PRESSED:
- case LOCK_RELEASED:
- Shell::GetInstance()->power_button_controller()->OnLockButtonEvent(
- action == LOCK_PRESSED, base::TimeTicks());
- break;
case LOCK_SCREEN:
HandleLock();
break;
- case OPEN_CROSH:
- HandleCrosh();
- break;
- case OPEN_FILE_MANAGER:
- HandleFileManager();
- break;
- case OPEN_GET_HELP:
- HandleGetHelp();
- break;
- case POWER_PRESSED: // fallthrough
- case POWER_RELEASED:
- if (!base::SysInfo::IsRunningOnChromeOS()) {
- // There is no powerd, the Chrome OS power manager, in linux desktop,
- // so call the PowerButtonController here.
- Shell::GetInstance()->power_button_controller()->OnPowerButtonEvent(
- action == POWER_PRESSED, base::TimeTicks());
- }
- // We don't do anything with these at present on the device,
- // (power button events are reported to us from powerm via
- // D-BUS), but we consume them to prevent them from getting
- // passed to apps -- see http://crbug.com/146609.
- break;
case SUSPEND:
HandleSuspend();
break;
- case SWAP_PRIMARY_DISPLAY:
- HandleSwapPrimaryDisplay();
- break;
case SWITCH_TO_NEXT_USER:
HandleCycleUser(SessionStateDelegate::CYCLE_TO_NEXT_USER);
break;
@@ -1332,24 +773,12 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
case TOGGLE_CAPS_LOCK:
HandleToggleCapsLock();
break;
- case TOGGLE_MIRROR_MODE:
- HandleToggleMirrorMode();
- break;
case TOGGLE_SPOKEN_FEEDBACK:
HandleToggleSpokenFeedback();
break;
case TOGGLE_WIFI:
WmShell::Get()->system_tray_notifier()->NotifyRequestToggleWifi();
break;
- case TOUCH_HUD_CLEAR:
- HandleTouchHudClear();
- break;
- case TOUCH_HUD_MODE_CHANGE:
- HandleTouchHudModeChange();
- break;
- case TOUCH_HUD_PROJECTION_TOGGLE:
- accelerators::ToggleTouchHudProjection();
- break;
case VOLUME_DOWN:
HandleVolumeDown(accelerator);
break;
@@ -1364,6 +793,12 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
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;
}
}
« no previous file with comments | « ash/accelerators/accelerator_controller.h ('k') | ash/accelerators/accelerator_controller_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698