Commit 1bfa5903 authored by James Cook's avatar James Cook Committed by Commit Bot

cros: Eliminate ash::AcceleratorControllerDelegate

A previous CL left AcceleratorControllerDelegateMash empty. Most of the
commands in AcceleratorControllerDelegateClassic work fine under mash,
so put all the commands back in AcceleratorController. Add early exits
for the few that don't work under mash.

These files were split up during the WmWindow conversion, when some ash
subdirectories were not allowed to use aura.

Bug: 612331
Test: ash_unittests, chrome browser_tests
Change-Id: Ic4ce3783c1c50ef85091bd012c7b366b26761120
Reviewed-on: https://chromium-review.googlesource.com/803054
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521140}
parent 61124039
...@@ -21,15 +21,8 @@ component("ash") { ...@@ -21,15 +21,8 @@ component("ash") {
sources = [ sources = [
"accelerators/accelerator_commands.cc", "accelerators/accelerator_commands.cc",
"accelerators/accelerator_commands.h", "accelerators/accelerator_commands.h",
"accelerators/accelerator_commands_classic.cc",
"accelerators/accelerator_commands_classic.h",
"accelerators/accelerator_controller.cc", "accelerators/accelerator_controller.cc",
"accelerators/accelerator_controller.h", "accelerators/accelerator_controller.h",
"accelerators/accelerator_controller_delegate.h",
"accelerators/accelerator_controller_delegate_classic.cc",
"accelerators/accelerator_controller_delegate_classic.h",
"accelerators/accelerator_controller_delegate_mash.cc",
"accelerators/accelerator_controller_delegate_mash.h",
"accelerators/accelerator_controller_registrar.cc", "accelerators/accelerator_controller_registrar.cc",
"accelerators/accelerator_controller_registrar.h", "accelerators/accelerator_controller_registrar.h",
"accelerators/accelerator_delegate.cc", "accelerators/accelerator_delegate.cc",
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wm/mru_window_tracker.h" #include "ash/wm/mru_window_tracker.h"
#include "ash/wm/screen_pinning_controller.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h" #include "ash/wm/wm_event.h"
...@@ -73,5 +74,20 @@ void ToggleFullscreen() { ...@@ -73,5 +74,20 @@ void ToggleFullscreen() {
wm::GetWindowState(active_window)->OnWMEvent(&event); wm::GetWindowState(active_window)->OnWMEvent(&event);
} }
bool CanUnpinWindow() {
// WindowStateType::TRUSTED_PINNED does not allow the user to press a key to
// exit pinned mode.
wm::WindowState* window_state = wm::GetActiveWindowState();
return window_state &&
window_state->GetStateType() == mojom::WindowStateType::PINNED;
}
void UnpinWindow() {
aura::Window* pinned_window =
Shell::Get()->screen_pinning_controller()->pinned_window();
if (pinned_window)
wm::GetWindowState(pinned_window)->Restore();
}
} // namespace accelerators } // namespace accelerators
} // namespace ash } // namespace ash
...@@ -34,6 +34,13 @@ ASH_EXPORT void ToggleMaximized(); ...@@ -34,6 +34,13 @@ ASH_EXPORT void ToggleMaximized();
// by WindowStateDelegate::ToggleFullscreen(). // by WindowStateDelegate::ToggleFullscreen().
ASH_EXPORT void ToggleFullscreen(); ASH_EXPORT void ToggleFullscreen();
// True if the user can press a key to exit pinned mode (aka forced
// fullscreen).
ASH_EXPORT bool CanUnpinWindow();
// If a window is pinned (aka forced fullscreen), exit from pinned mode.
ASH_EXPORT void UnpinWindow();
} // namespace accelerators } // namespace accelerators
} // namespace ash } // namespace ash
......
// 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/accelerators/accelerator_commands_classic.h"
#include "ash/shell.h"
#include "ash/wm/screen_pinning_controller.h"
#include "ash/wm/window_state.h"
namespace ash {
namespace accelerators {
void Unpin() {
aura::Window* pinned_window =
Shell::Get()->screen_pinning_controller()->pinned_window();
if (pinned_window)
wm::GetWindowState(pinned_window)->Restore();
}
} // namespace accelerators
} // namespace ash
// Copyright 2016 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_ACCELERATORS_ACCELERATOR_COMMANDS_CLASSIC_H_
#define ASH_ACCELERATORS_ACCELERATOR_COMMANDS_CLASSIC_H_
#include "ash/ash_export.h"
// This file contains implementations of commands that are bound to keyboard
// shortcuts in Ash or in the embedding application (e.g. Chrome).
// TODO(jamescook): Combine classic ash and mash command files.
namespace ash {
namespace accelerators {
// If a window is pinned (aka forced fullscreen), exit from pinned mode.
ASH_EXPORT void Unpin();
} // namespace accelerators
} // namespace ash
#endif // ASH_ACCELERATORS_ACCELERATOR_COMMANDS_CLASSIC_H_
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <memory> #include <memory>
#include "ash/accelerators/accelerator_commands_classic.h" #include "ash/accelerators/accelerator_commands.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
...@@ -60,7 +60,7 @@ TEST_F(AcceleratorCommandsTest, Unpin) { ...@@ -60,7 +60,7 @@ TEST_F(AcceleratorCommandsTest, Unpin) {
wm::PinWindow(window1.get(), /* trusted */ false); wm::PinWindow(window1.get(), /* trusted */ false);
EXPECT_TRUE(window_state1->IsPinned()); EXPECT_TRUE(window_state1->IsPinned());
Unpin(); UnpinWindow();
EXPECT_FALSE(window_state1->IsPinned()); EXPECT_FALSE(window_state1->IsPinned());
} }
......
...@@ -4,22 +4,26 @@ ...@@ -4,22 +4,26 @@
#include "ash/accelerators/accelerator_controller.h" #include "ash/accelerators/accelerator_controller.h"
#include <algorithm>
#include <cmath>
#include <string> #include <string>
#include <utility> #include <utility>
#include "ash/accelerators/accelerator_commands.h" #include "ash/accelerators/accelerator_commands.h"
#include "ash/accelerators/accelerator_controller_delegate.h"
#include "ash/accelerators/debug_commands.h" #include "ash/accelerators/debug_commands.h"
#include "ash/accessibility/accessibility_controller.h" #include "ash/accessibility/accessibility_controller.h"
#include "ash/accessibility/accessibility_delegate.h" #include "ash/accessibility/accessibility_delegate.h"
#include "ash/debug.h"
#include "ash/display/display_configuration_controller.h" #include "ash/display/display_configuration_controller.h"
#include "ash/display/display_move_window_util.h" #include "ash/display/display_move_window_util.h"
#include "ash/focus_cycler.h" #include "ash/focus_cycler.h"
#include "ash/ime/ime_controller.h" #include "ash/ime/ime_controller.h"
#include "ash/ime/ime_switch_type.h" #include "ash/ime/ime_switch_type.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/media_controller.h" #include "ash/media_controller.h"
#include "ash/multi_profile_uma.h" #include "ash/multi_profile_uma.h"
#include "ash/new_window_controller.h" #include "ash/new_window_controller.h"
#include "ash/public/cpp/config.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "ash/root_window_controller.h" #include "ash/root_window_controller.h"
#include "ash/rotator/window_rotation.h" #include "ash/rotator/window_rotation.h"
...@@ -35,6 +39,7 @@ ...@@ -35,6 +39,7 @@
#include "ash/system/keyboard_brightness_control_delegate.h" #include "ash/system/keyboard_brightness_control_delegate.h"
#include "ash/system/palette/palette_tray.h" #include "ash/system/palette/palette_tray.h"
#include "ash/system/palette/palette_utils.h" #include "ash/system/palette/palette_utils.h"
#include "ash/system/power/power_button_controller.h"
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
#include "ash/system/system_notifier.h" #include "ash/system/system_notifier.h"
#include "ash/system/toast/toast_data.h" #include "ash/system/toast/toast_data.h"
...@@ -42,6 +47,7 @@ ...@@ -42,6 +47,7 @@
#include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/web_notification/web_notification_tray.h" #include "ash/system/web_notification/web_notification_tray.h"
#include "ash/touch/touch_hud_debug.h"
#include "ash/utility/screenshot_controller.h" #include "ash/utility/screenshot_controller.h"
#include "ash/voice_interaction/voice_interaction_controller.h" #include "ash/voice_interaction/voice_interaction_controller.h"
#include "ash/wm/mru_window_tracker.h" #include "ash/wm/mru_window_tracker.h"
...@@ -57,6 +63,7 @@ ...@@ -57,6 +63,7 @@
#include "base/optional.h" #include "base/optional.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/sys_info.h"
#include "chromeos/chromeos_switches.h" #include "chromeos/chromeos_switches.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h" #include "chromeos/dbus/power_manager_client.h"
...@@ -858,16 +865,72 @@ void HandleVolumeUp(mojom::VolumeController* volume_controller, ...@@ -858,16 +865,72 @@ void HandleVolumeUp(mojom::VolumeController* volume_controller,
volume_controller->VolumeUp(); volume_controller->VolumeUp();
} }
bool CanHandleMagnifyScreen() {
return Shell::Get()->magnification_controller()->IsEnabled();
}
// Magnify the screen
void HandleMagnifyScreen(int delta_index) {
// TODO(crbug.com/612331): Mash support.
if (Shell::GetAshConfig() == Config::MASH) {
NOTIMPLEMENTED();
return;
}
if (!Shell::Get()->magnification_controller()->IsEnabled())
return;
// TODO(yoshiki): Move the following logic to MagnificationController.
float scale = Shell::Get()->magnification_controller()->GetScale();
// Calculate rounded logarithm (base kMagnificationScaleFactor) of scale.
int scale_index =
std::round(std::log(scale) /
std::log(MagnificationController::kMagnificationScaleFactor));
int new_scale_index = std::max(0, std::min(8, scale_index + delta_index));
Shell::Get()->magnification_controller()->SetScale(
std::pow(MagnificationController::kMagnificationScaleFactor,
new_scale_index),
true);
}
bool CanHandleTouchHud() {
// TODO(crbug.com/612331): Mash support.
if (Shell::GetAshConfig() == Config::MASH)
return false;
return RootWindowController::ForTargetRootWindow()->touch_hud_debug();
}
void HandleTouchHudClear() {
// TODO(crbug.com/612331): Mash support.
if (Shell::GetAshConfig() == Config::MASH) {
NOTIMPLEMENTED();
return;
}
RootWindowController::ForTargetRootWindow()->touch_hud_debug()->Clear();
}
void HandleTouchHudModeChange() {
// TODO(crbug.com/612331): Mash support.
if (Shell::GetAshConfig() == Config::MASH) {
NOTIMPLEMENTED();
return;
}
RootWindowController* controller =
RootWindowController::ForTargetRootWindow();
controller->touch_hud_debug()->ChangeToNextMode();
}
} // namespace } // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// AcceleratorController, public: // AcceleratorController, public:
AcceleratorController::AcceleratorController( AcceleratorController::AcceleratorController(
AcceleratorControllerDelegate* delegate,
ui::AcceleratorManagerDelegate* manager_delegate) ui::AcceleratorManagerDelegate* manager_delegate)
: delegate_(delegate), : accelerator_manager_(new ui::AcceleratorManager(manager_delegate)),
accelerator_manager_(new ui::AcceleratorManager(manager_delegate)),
accelerator_history_(new ui::AcceleratorHistory) { accelerator_history_(new ui::AcceleratorHistory) {
Init(); Init();
} }
...@@ -1104,6 +1167,9 @@ bool AcceleratorController::CanPerformAction( ...@@ -1104,6 +1167,9 @@ bool AcceleratorController::CanPerformAction(
case DEBUG_PRINT_WINDOW_HIERARCHY: case DEBUG_PRINT_WINDOW_HIERARCHY:
case DEBUG_SHOW_TOAST: case DEBUG_SHOW_TOAST:
case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR:
case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS:
case DEBUG_TOGGLE_SHOW_FPS_COUNTER:
case DEBUG_TOGGLE_SHOW_PAINT_RECTS:
case DEBUG_TOGGLE_TOUCH_PAD: case DEBUG_TOGGLE_TOUCH_PAD:
case DEBUG_TOGGLE_TOUCH_SCREEN: case DEBUG_TOGGLE_TOUCH_SCREEN:
case DEBUG_TOGGLE_TABLET_MODE: case DEBUG_TOGGLE_TABLET_MODE:
...@@ -1117,6 +1183,9 @@ bool AcceleratorController::CanPerformAction( ...@@ -1117,6 +1183,9 @@ bool AcceleratorController::CanPerformAction(
return CanHandleDisableCapsLock(previous_accelerator); return CanHandleDisableCapsLock(previous_accelerator);
case LOCK_SCREEN: case LOCK_SCREEN:
return CanHandleLock(); return CanHandleLock();
case MAGNIFY_SCREEN_ZOOM_IN:
case MAGNIFY_SCREEN_ZOOM_OUT:
return CanHandleMagnifyScreen();
case MOVE_WINDOW_TO_ABOVE_DISPLAY: case MOVE_WINDOW_TO_ABOVE_DISPLAY:
case MOVE_WINDOW_TO_BELOW_DISPLAY: case MOVE_WINDOW_TO_BELOW_DISPLAY:
case MOVE_WINDOW_TO_LEFT_DISPLAY: case MOVE_WINDOW_TO_LEFT_DISPLAY:
...@@ -1153,6 +1222,11 @@ bool AcceleratorController::CanPerformAction( ...@@ -1153,6 +1222,11 @@ bool AcceleratorController::CanPerformAction(
return CanHandleToggleMessageCenterBubble(); return CanHandleToggleMessageCenterBubble();
case TOGGLE_MIRROR_MODE: case TOGGLE_MIRROR_MODE:
return true; return true;
case TOUCH_HUD_CLEAR:
case TOUCH_HUD_MODE_CHANGE:
return CanHandleTouchHud();
case UNPIN:
return accelerators::CanUnpinWindow();
case WINDOW_CYCLE_SNAP_LEFT: case WINDOW_CYCLE_SNAP_LEFT:
case WINDOW_CYCLE_SNAP_RIGHT: case WINDOW_CYCLE_SNAP_RIGHT:
return CanHandleWindowSnap(); return CanHandleWindowSnap();
...@@ -1177,6 +1251,8 @@ bool AcceleratorController::CanPerformAction( ...@@ -1177,6 +1251,8 @@ bool AcceleratorController::CanPerformAction(
case LAUNCH_APP_6: case LAUNCH_APP_6:
case LAUNCH_APP_7: case LAUNCH_APP_7:
case LAUNCH_LAST_APP: case LAUNCH_LAST_APP:
case LOCK_PRESSED:
case LOCK_RELEASED:
case MEDIA_NEXT_TRACK: case MEDIA_NEXT_TRACK:
case MEDIA_PLAY_PAUSE: case MEDIA_PLAY_PAUSE:
case MEDIA_PREV_TRACK: case MEDIA_PREV_TRACK:
...@@ -1186,6 +1262,8 @@ bool AcceleratorController::CanPerformAction( ...@@ -1186,6 +1262,8 @@ bool AcceleratorController::CanPerformAction(
case OPEN_FEEDBACK_PAGE: case OPEN_FEEDBACK_PAGE:
case OPEN_FILE_MANAGER: case OPEN_FILE_MANAGER:
case OPEN_GET_HELP: case OPEN_GET_HELP:
case POWER_PRESSED:
case POWER_RELEASED:
case PRINT_UI_HIERARCHIES: case PRINT_UI_HIERARCHIES:
case RESTORE_TAB: case RESTORE_TAB:
case ROTATE_WINDOW: case ROTATE_WINDOW:
...@@ -1208,14 +1286,7 @@ bool AcceleratorController::CanPerformAction( ...@@ -1208,14 +1286,7 @@ bool AcceleratorController::CanPerformAction(
case VOLUME_UP: case VOLUME_UP:
case WINDOW_MINIMIZE: case WINDOW_MINIMIZE:
return true; 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, void AcceleratorController::PerformAction(AcceleratorAction action,
...@@ -1254,6 +1325,17 @@ void AcceleratorController::PerformAction(AcceleratorAction action, ...@@ -1254,6 +1325,17 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
case DEBUG_PRINT_WINDOW_HIERARCHY: case DEBUG_PRINT_WINDOW_HIERARCHY:
case DEBUG_SHOW_TOAST: case DEBUG_SHOW_TOAST:
case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR:
debug::PerformDebugActionIfEnabled(action);
break;
case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS:
debug::ToggleShowDebugBorders();
break;
case DEBUG_TOGGLE_SHOW_FPS_COUNTER:
debug::ToggleShowFpsCounter();
break;
case DEBUG_TOGGLE_SHOW_PAINT_RECTS:
debug::ToggleShowPaintRects();
break;
case DEBUG_TOGGLE_TOUCH_PAD: case DEBUG_TOGGLE_TOUCH_PAD:
case DEBUG_TOGGLE_TOUCH_SCREEN: case DEBUG_TOGGLE_TOUCH_SCREEN:
case DEBUG_TOGGLE_TABLET_MODE: case DEBUG_TOGGLE_TABLET_MODE:
...@@ -1324,9 +1406,20 @@ void AcceleratorController::PerformAction(AcceleratorAction action, ...@@ -1324,9 +1406,20 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
case LAUNCH_LAST_APP: case LAUNCH_LAST_APP:
HandleLaunchLastApp(); HandleLaunchLastApp();
break; break;
case LOCK_PRESSED:
case LOCK_RELEASED:
Shell::Get()->power_button_controller()->OnLockButtonEvent(
action == LOCK_PRESSED, base::TimeTicks());
break;
case LOCK_SCREEN: case LOCK_SCREEN:
HandleLock(); HandleLock();
break; break;
case MAGNIFY_SCREEN_ZOOM_IN:
HandleMagnifyScreen(1);
break;
case MAGNIFY_SCREEN_ZOOM_OUT:
HandleMagnifyScreen(-1);
break;
case MEDIA_NEXT_TRACK: case MEDIA_NEXT_TRACK:
HandleMediaNextTrack(); HandleMediaNextTrack();
break; break;
...@@ -1366,6 +1459,19 @@ void AcceleratorController::PerformAction(AcceleratorAction action, ...@@ -1366,6 +1459,19 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
case OPEN_GET_HELP: case OPEN_GET_HELP:
HandleGetHelp(); HandleGetHelp();
break; break;
case POWER_PRESSED:
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::Get()->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 PREVIOUS_IME: case PREVIOUS_IME:
HandlePreviousIme(accelerator); HandlePreviousIme(accelerator);
break; break;
...@@ -1462,6 +1568,15 @@ void AcceleratorController::PerformAction(AcceleratorAction action, ...@@ -1462,6 +1568,15 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
case TOGGLE_WIFI: case TOGGLE_WIFI:
Shell::Get()->system_tray_notifier()->NotifyRequestToggleWifi(); Shell::Get()->system_tray_notifier()->NotifyRequestToggleWifi();
break; break;
case TOUCH_HUD_CLEAR:
HandleTouchHudClear();
break;
case TOUCH_HUD_MODE_CHANGE:
HandleTouchHudModeChange();
break;
case UNPIN:
accelerators::UnpinWindow();
break;
case VOLUME_DOWN: case VOLUME_DOWN:
HandleVolumeDown(volume_controller_.get(), accelerator); HandleVolumeDown(volume_controller_.get(), accelerator);
break; break;
...@@ -1481,12 +1596,6 @@ void AcceleratorController::PerformAction(AcceleratorAction action, ...@@ -1481,12 +1596,6 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
case WINDOW_POSITION_CENTER: case WINDOW_POSITION_CENTER:
HandlePositionCenter(); HandlePositionCenter();
break; break;
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;
} }
} }
......
...@@ -31,7 +31,6 @@ class AcceleratorManagerDelegate; ...@@ -31,7 +31,6 @@ class AcceleratorManagerDelegate;
namespace ash { namespace ash {
struct AcceleratorData; struct AcceleratorData;
class AcceleratorControllerDelegate;
class ExitWarningHandler; class ExitWarningHandler;
// Identifier for the high contrast toggle accelerator notification. // Identifier for the high contrast toggle accelerator notification.
...@@ -43,8 +42,8 @@ ASH_EXPORT extern const char kHighContrastToggleAccelNotificationId[]; ...@@ -43,8 +42,8 @@ ASH_EXPORT extern const char kHighContrastToggleAccelNotificationId[];
class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget, class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget,
public mojom::AcceleratorController { public mojom::AcceleratorController {
public: public:
AcceleratorController(AcceleratorControllerDelegate* delegate, explicit AcceleratorController(
ui::AcceleratorManagerDelegate* manager_delegate); ui::AcceleratorManagerDelegate* manager_delegate);
~AcceleratorController() override; ~AcceleratorController() override;
// A list of possible ways in which an accelerator should be restricted before // A list of possible ways in which an accelerator should be restricted before
...@@ -178,8 +177,6 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget, ...@@ -178,8 +177,6 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget,
AcceleratorAction action, AcceleratorAction action,
const ui::Accelerator& accelerator) const; const ui::Accelerator& accelerator) const;
AcceleratorControllerDelegate* delegate_;
std::unique_ptr<ui::AcceleratorManager> accelerator_manager_; std::unique_ptr<ui::AcceleratorManager> accelerator_manager_;
// A tracker for the current and previous accelerators. // A tracker for the current and previous accelerators.
......
// Copyright 2016 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_ACCELERATORS_ACCELERATOR_CONTROLLER_DELEGATE_H_
#define ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_DELEGATE_H_
#include "ash/accelerators/accelerator_table.h"
#include "ash/ash_export.h"
namespace ui {
class Accelerator;
}
namespace ash {
// Used by AcceleratorController to handle environment specific commands. This
// file is temporary while ash supports both mus and aura.
class ASH_EXPORT AcceleratorControllerDelegate {
public:
// Returns true if the delegate is responsible for handling |action|. This
// should not return whether the action may be enabled, only if this delegate
// handles the action.
virtual bool HandlesAction(AcceleratorAction action) = 0;
// Returns true if the delegate can perform the action at this time. Only
// invoked if HandlesAction() returns true.
virtual bool CanPerformAction(
AcceleratorAction action,
const ui::Accelerator& accelerator,
const ui::Accelerator& previous_accelerator) = 0;
// Performs the specified action.
virtual void PerformAction(AcceleratorAction action,
const ui::Accelerator& accelerator) = 0;
protected:
virtual ~AcceleratorControllerDelegate() {}
};
} // namespace ash
#endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_DELEGATE_H_
// Copyright 2016 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_delegate_classic.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <string>
#include <utility>
#include "ash/accelerators/accelerator_commands_classic.h"
#include "ash/accelerators/debug_commands.h"
#include "ash/debug.h"
#include "ash/host/ash_window_tree_host.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/system/power/power_button_controller.h"
#include "ash/system/system_notifier.h"
#include "ash/touch/touch_hud_debug.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_state.h"
#include "ash/wm/wm_event.h"
#include "base/sys_info.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/display/manager/display_manager.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace ash {
namespace {
bool CanHandleMagnifyScreen() {
return Shell::Get()->magnification_controller()->IsEnabled();
}
// Magnify the screen
void HandleMagnifyScreen(int delta_index) {
if (Shell::Get()->magnification_controller()->IsEnabled()) {
// TODO(yoshiki): Move the following logic to MagnificationController.
float scale = Shell::Get()->magnification_controller()->GetScale();
// Calculate rounded logarithm (base kMagnificationScaleFactor) of scale.
int scale_index = std::round(
std::log(scale) /
std::log(MagnificationController::kMagnificationScaleFactor));
int new_scale_index = std::max(0, std::min(8, scale_index + delta_index));
Shell::Get()->magnification_controller()->SetScale(
std::pow(MagnificationController::kMagnificationScaleFactor,
new_scale_index),
true);
}
}
bool CanHandleUnpin() {
// Returns true only for WindowStateType::PINNED.
// WindowStateType::TRUSTED_PINNED does not accept user's unpin operation.
wm::WindowState* window_state = wm::GetActiveWindowState();
return window_state &&
window_state->GetStateType() == mojom::WindowStateType::PINNED;
}
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();
}
} // namespace
AcceleratorControllerDelegateClassic::AcceleratorControllerDelegateClassic() =
default;
AcceleratorControllerDelegateClassic::~AcceleratorControllerDelegateClassic() =
default;
bool AcceleratorControllerDelegateClassic::HandlesAction(
AcceleratorAction action) {
// NOTE: When adding a new accelerator that only depends on //ash/common code,
// add it to accelerator_controller.cc instead. See class comment.
switch (action) {
case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS:
case DEBUG_TOGGLE_SHOW_FPS_COUNTER:
case DEBUG_TOGGLE_SHOW_PAINT_RECTS:
case LOCK_PRESSED:
case LOCK_RELEASED:
case MAGNIFY_SCREEN_ZOOM_IN:
case MAGNIFY_SCREEN_ZOOM_OUT:
case POWER_PRESSED:
case POWER_RELEASED:
case TOGGLE_MESSAGE_CENTER_BUBBLE:
case TOUCH_HUD_CLEAR:
case TOUCH_HUD_MODE_CHANGE:
case UNPIN:
return true;
default:
break;
}
return false;
}
bool AcceleratorControllerDelegateClassic::CanPerformAction(
AcceleratorAction action,
const ui::Accelerator& accelerator,
const ui::Accelerator& previous_accelerator) {
switch (action) {
case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS:
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 UNPIN:
return CanHandleUnpin();
// Following are always enabled:
case LOCK_PRESSED:
case LOCK_RELEASED:
case POWER_PRESSED:
case POWER_RELEASED:
return true;
case TOUCH_HUD_CLEAR:
case TOUCH_HUD_MODE_CHANGE:
return CanHandleTouchHud();
default:
NOTREACHED();
break;
}
return false;
}
void AcceleratorControllerDelegateClassic::PerformAction(
AcceleratorAction action,
const ui::Accelerator& accelerator) {
switch (action) {
case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS:
debug::ToggleShowDebugBorders();
break;
case DEBUG_TOGGLE_SHOW_FPS_COUNTER:
debug::ToggleShowFpsCounter();
break;
case DEBUG_TOGGLE_SHOW_PAINT_RECTS:
debug::ToggleShowPaintRects();
break;
case LOCK_PRESSED:
case LOCK_RELEASED:
Shell::Get()->power_button_controller()->OnLockButtonEvent(
action == LOCK_PRESSED, base::TimeTicks());
break;
case MAGNIFY_SCREEN_ZOOM_IN:
HandleMagnifyScreen(1);
break;
case MAGNIFY_SCREEN_ZOOM_OUT:
HandleMagnifyScreen(-1);
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::Get()->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 TOUCH_HUD_CLEAR:
HandleTouchHudClear();
break;
case TOUCH_HUD_MODE_CHANGE:
HandleTouchHudModeChange();
break;
case UNPIN:
accelerators::Unpin();
break;
default:
break;
}
}
} // namespace ash
// Copyright 2016 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_ACCELERATORS_ACCELERATOR_CONTROLLER_DELEGATE_CLASSIC_H_
#define ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_DELEGATE_CLASSIC_H_
#include <memory>
#include "ash/accelerators/accelerator_controller_delegate.h"
#include "base/macros.h"
namespace ash {
// Support for accelerators that only work in classic ash and not in mash,
// for example accelerators related to display management. These sorts of
// accelerators should be rare. Most new accelerators should be added to
// accelerator_controller.cc instead.
class ASH_EXPORT AcceleratorControllerDelegateClassic
: public AcceleratorControllerDelegate {
public:
AcceleratorControllerDelegateClassic();
~AcceleratorControllerDelegateClassic() override;
// AcceleratorControllerDelegate:
bool HandlesAction(AcceleratorAction action) override;
bool CanPerformAction(AcceleratorAction action,
const ui::Accelerator& accelerator,
const ui::Accelerator& previous_accelerator) override;
void PerformAction(AcceleratorAction action,
const ui::Accelerator& accelerator) override;
private:
DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerDelegateClassic);
};
} // namespace ash
#endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_DELEGATE_CLASSIC_H_
// Copyright 2016 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_delegate_mash.h"
#include "base/logging.h"
namespace ash {
AcceleratorControllerDelegateMash::AcceleratorControllerDelegateMash() =
default;
AcceleratorControllerDelegateMash::~AcceleratorControllerDelegateMash() =
default;
bool AcceleratorControllerDelegateMash::HandlesAction(
AcceleratorAction action) {
return false;
}
bool AcceleratorControllerDelegateMash::CanPerformAction(
AcceleratorAction action,
const ui::Accelerator& accelerator,
const ui::Accelerator& previous_accelerator) {
return false;
}
void AcceleratorControllerDelegateMash::PerformAction(
AcceleratorAction action,
const ui::Accelerator& accelerator) {}
} // namespace ash
// Copyright 2016 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_ACCELERATORS_ACCELERATOR_CONTROLLER_DELEGATE_MASH_H_
#define ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_DELEGATE_MASH_H_
#include "ash/accelerators/accelerator_controller_delegate.h"
#include "base/macros.h"
namespace ash {
// Controls accelerators that are specific to mash.
// TODO(jamescook): Eliminate this class and inline the checks for mash into
// AcceleratorController.
class AcceleratorControllerDelegateMash : public AcceleratorControllerDelegate {
public:
AcceleratorControllerDelegateMash();
~AcceleratorControllerDelegateMash() override;
// AcceleratorControllerDelegate:
bool HandlesAction(AcceleratorAction action) override;
bool CanPerformAction(AcceleratorAction action,
const ui::Accelerator& accelerator,
const ui::Accelerator& previous_accelerator) override;
void PerformAction(AcceleratorAction action,
const ui::Accelerator& accelerator) override;
private:
DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerDelegateMash);
};
} // namespace ash
#endif // ASH_ACCELERATORS_ACCELERATOR_CONTROLLER_DELEGATE_MASH_H_
...@@ -551,7 +551,7 @@ TEST_F(AcceleratorControllerTest, RotateScreen) { ...@@ -551,7 +551,7 @@ TEST_F(AcceleratorControllerTest, RotateScreen) {
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
display::Display::Rotation new_rotation = display::Display::Rotation new_rotation =
GetActiveDisplayRotation(display.id()); GetActiveDisplayRotation(display.id());
// |new_rotation| is determined by the AcceleratorControllerDelegate. // |new_rotation| is determined by the AcceleratorController.
EXPECT_NE(initial_rotation, new_rotation); EXPECT_NE(initial_rotation, new_rotation);
} }
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <utility> #include <utility>
#include "ash/accelerators/accelerator_controller.h" #include "ash/accelerators/accelerator_controller.h"
#include "ash/accelerators/accelerator_controller_delegate_classic.h"
#include "ash/host/ash_window_tree_host.h" #include "ash/host/ash_window_tree_host.h"
#include "ash/host/ash_window_tree_host_init_params.h" #include "ash/host/ash_window_tree_host_init_params.h"
#include "ash/keyboard/keyboard_ui.h" #include "ash/keyboard/keyboard_ui.h"
...@@ -165,11 +164,7 @@ ShellPortClassic::CreateNativeDisplayDelegate() { ...@@ -165,11 +164,7 @@ ShellPortClassic::CreateNativeDisplayDelegate() {
std::unique_ptr<AcceleratorController> std::unique_ptr<AcceleratorController>
ShellPortClassic::CreateAcceleratorController() { ShellPortClassic::CreateAcceleratorController() {
DCHECK(!accelerator_controller_delegate_); return std::make_unique<AcceleratorController>(nullptr);
accelerator_controller_delegate_ =
std::make_unique<AcceleratorControllerDelegateClassic>();
return std::make_unique<AcceleratorController>(
accelerator_controller_delegate_.get(), nullptr);
} }
void ShellPortClassic::AddVideoDetectorObserver( void ShellPortClassic::AddVideoDetectorObserver(
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
namespace ash { namespace ash {
class AcceleratorControllerDelegateClassic;
class PointerWatcherAdapterClassic; class PointerWatcherAdapterClassic;
// Implementation of ShellPort for classic ash/aura. See ash/README.md for more // Implementation of ShellPort for classic ash/aura. See ash/README.md for more
...@@ -26,10 +25,6 @@ class ASH_EXPORT ShellPortClassic : public ShellPort { ...@@ -26,10 +25,6 @@ class ASH_EXPORT ShellPortClassic : public ShellPort {
static ShellPortClassic* Get(); static ShellPortClassic* Get();
AcceleratorControllerDelegateClassic* accelerator_controller_delegate() {
return accelerator_controller_delegate_.get();
}
// ShellPort: // ShellPort:
void Shutdown() override; void Shutdown() override;
Config GetAshConfig() const override; Config GetAshConfig() const override;
...@@ -74,9 +69,6 @@ class ASH_EXPORT ShellPortClassic : public ShellPort { ...@@ -74,9 +69,6 @@ class ASH_EXPORT ShellPortClassic : public ShellPort {
private: private:
std::unique_ptr<PointerWatcherAdapterClassic> pointer_watcher_adapter_; std::unique_ptr<PointerWatcherAdapterClassic> pointer_watcher_adapter_;
std::unique_ptr<AcceleratorControllerDelegateClassic>
accelerator_controller_delegate_;
DISALLOW_COPY_AND_ASSIGN(ShellPortClassic); DISALLOW_COPY_AND_ASSIGN(ShellPortClassic);
}; };
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <utility> #include <utility>
#include "ash/accelerators/accelerator_controller.h" #include "ash/accelerators/accelerator_controller.h"
#include "ash/accelerators/accelerator_controller_delegate_mash.h"
#include "ash/accelerators/accelerator_controller_registrar.h" #include "ash/accelerators/accelerator_controller_registrar.h"
#include "ash/keyboard/keyboard_ui_mash.h" #include "ash/keyboard/keyboard_ui_mash.h"
#include "ash/public/cpp/config.h" #include "ash/public/cpp/config.h"
...@@ -152,8 +151,6 @@ void ShellPortMash::CreatePointerWatcherAdapter() { ...@@ -152,8 +151,6 @@ void ShellPortMash::CreatePointerWatcherAdapter() {
std::unique_ptr<AcceleratorController> std::unique_ptr<AcceleratorController>
ShellPortMash::CreateAcceleratorController() { ShellPortMash::CreateAcceleratorController() {
DCHECK(!accelerator_controller_delegate_);
uint16_t accelerator_namespace_id = 0u; uint16_t accelerator_namespace_id = 0u;
const bool add_result = const bool add_result =
window_manager_->GetNextAcceleratorNamespaceId(&accelerator_namespace_id); window_manager_->GetNextAcceleratorNamespaceId(&accelerator_namespace_id);
...@@ -161,13 +158,10 @@ ShellPortMash::CreateAcceleratorController() { ...@@ -161,13 +158,10 @@ ShellPortMash::CreateAcceleratorController() {
// should always succeed. // should always succeed.
DCHECK(add_result); DCHECK(add_result);
accelerator_controller_delegate_ =
std::make_unique<AcceleratorControllerDelegateMash>();
accelerator_controller_registrar_ = accelerator_controller_registrar_ =
std::make_unique<AcceleratorControllerRegistrar>( std::make_unique<AcceleratorControllerRegistrar>(
window_manager_, accelerator_namespace_id); window_manager_, accelerator_namespace_id);
return std::make_unique<AcceleratorController>( return std::make_unique<AcceleratorController>(
accelerator_controller_delegate_.get(),
accelerator_controller_registrar_.get()); accelerator_controller_registrar_.get());
} }
......
...@@ -19,7 +19,6 @@ class PointerWatcherEventRouter; ...@@ -19,7 +19,6 @@ class PointerWatcherEventRouter;
namespace ash { namespace ash {
class AcceleratorControllerDelegateMash;
class AcceleratorControllerRegistrar; class AcceleratorControllerRegistrar;
class ImmersiveHandlerFactoryMash; class ImmersiveHandlerFactoryMash;
class WindowManager; class WindowManager;
...@@ -68,8 +67,6 @@ class ShellPortMash : public ShellPortMus { ...@@ -68,8 +67,6 @@ class ShellPortMash : public ShellPortMus {
private: private:
views::PointerWatcherEventRouter* pointer_watcher_event_router_ = nullptr; views::PointerWatcherEventRouter* pointer_watcher_event_router_ = nullptr;
std::unique_ptr<AcceleratorControllerDelegateMash>
accelerator_controller_delegate_;
std::unique_ptr<AcceleratorControllerRegistrar> std::unique_ptr<AcceleratorControllerRegistrar>
accelerator_controller_registrar_; accelerator_controller_registrar_;
std::unique_ptr<ImmersiveHandlerFactoryMash> immersive_handler_factory_; std::unique_ptr<ImmersiveHandlerFactoryMash> immersive_handler_factory_;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <utility> #include <utility>
#include "ash/accelerators/accelerator_controller.h" #include "ash/accelerators/accelerator_controller.h"
#include "ash/accelerators/accelerator_controller_delegate_classic.h"
#include "ash/display/display_synchronizer.h" #include "ash/display/display_synchronizer.h"
#include "ash/host/ash_window_tree_host_init_params.h" #include "ash/host/ash_window_tree_host_init_params.h"
#include "ash/host/ash_window_tree_host_mus.h" #include "ash/host/ash_window_tree_host_mus.h"
...@@ -255,11 +254,7 @@ ShellPortMus::CreateNativeDisplayDelegate() { ...@@ -255,11 +254,7 @@ ShellPortMus::CreateNativeDisplayDelegate() {
std::unique_ptr<AcceleratorController> std::unique_ptr<AcceleratorController>
ShellPortMus::CreateAcceleratorController() { ShellPortMus::CreateAcceleratorController() {
DCHECK(!accelerator_controller_delegate_); return std::make_unique<AcceleratorController>(nullptr);
accelerator_controller_delegate_ =
std::make_unique<AcceleratorControllerDelegateClassic>();
return std::make_unique<AcceleratorController>(
accelerator_controller_delegate_.get(), nullptr);
} }
void ShellPortMus::AddVideoDetectorObserver( void ShellPortMus::AddVideoDetectorObserver(
......
...@@ -18,7 +18,6 @@ class WindowTreeClient; ...@@ -18,7 +18,6 @@ class WindowTreeClient;
namespace ash { namespace ash {
class AcceleratorControllerDelegateClassic;
class DisplaySynchronizer; class DisplaySynchronizer;
class PointerWatcherAdapterClassic; class PointerWatcherAdapterClassic;
class RootWindowController; class RootWindowController;
...@@ -36,10 +35,6 @@ class ShellPortMus : public ShellPort { ...@@ -36,10 +35,6 @@ class ShellPortMus : public ShellPort {
ash::RootWindowController* GetRootWindowControllerWithDisplayId(int64_t id); ash::RootWindowController* GetRootWindowControllerWithDisplayId(int64_t id);
AcceleratorControllerDelegateClassic* accelerator_controller_delegate() {
return accelerator_controller_delegate_.get();
}
aura::WindowTreeClient* window_tree_client(); aura::WindowTreeClient* window_tree_client();
WindowManager* window_manager() { return window_manager_; } WindowManager* window_manager() { return window_manager_; }
...@@ -90,8 +85,6 @@ class ShellPortMus : public ShellPort { ...@@ -90,8 +85,6 @@ class ShellPortMus : public ShellPort {
private: private:
std::unique_ptr<PointerWatcherAdapterClassic> pointer_watcher_adapter_; std::unique_ptr<PointerWatcherAdapterClassic> pointer_watcher_adapter_;
std::unique_ptr<AcceleratorControllerDelegateClassic>
accelerator_controller_delegate_;
std::unique_ptr<DisplaySynchronizer> display_synchronizer_; std::unique_ptr<DisplaySynchronizer> display_synchronizer_;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "ash/accelerators/accelerator_commands.h" #include "ash/accelerators/accelerator_commands.h"
#include "ash/accelerators/accelerator_commands_classic.h" #include "ash/accelerators/accelerator_commands.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "base/command_line.h" #include "base/command_line.h"
......
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