Commit 9f0ad50c authored by Min Chen's avatar Min Chen Committed by Commit Bot

Add |source_device_id_| for Accelerator.

Add |source_device_id_| for Accelerator. Then the InputDevice can be
gotten from the |source_device_id_| when perform the accelerator. This
is added to differentiate the side volume button from all the other
volume control input currently.

Bug: 937907
Change-Id: Iec90a6b35cef9db6e6eaceb50aef26c07ba1b3ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1559434
Commit-Queue: Min Chen <minch@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649690}
parent 24bacb80
......@@ -1089,9 +1089,11 @@ bool AcceleratorController::IsDeprecated(
return deprecated_accelerators_.count(accelerator) != 0;
}
bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action) {
if (CanPerformAction(action, ui::Accelerator())) {
PerformAction(action, ui::Accelerator());
bool AcceleratorController::PerformActionIfEnabled(
AcceleratorAction action,
const ui::Accelerator& accelerator) {
if (CanPerformAction(action, accelerator)) {
PerformAction(action, accelerator);
return true;
}
return false;
......@@ -1407,6 +1409,12 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
if (restriction != RESTRICTION_NONE)
return;
// TODO(minch): For VOLUME_DOWN and VOLUME_UP. Do the calculation based on
// accelerator.source_device_id() and
// ui::InputDeviceManager::GetInstance()->GetOtherInputDevices() to see
// whether we need to flip its action on current screen orientation for side
// volume button. http://crbug.com/937907.
// 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.
......
......@@ -105,7 +105,9 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget,
// Performs the specified action if it is enabled. Returns whether the action
// was performed successfully.
bool PerformActionIfEnabled(AcceleratorAction action);
bool PerformActionIfEnabled(
AcceleratorAction action,
const ui::Accelerator& accelerator = ui::Accelerator());
// Returns the restriction for the current context.
AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction();
......
......@@ -108,8 +108,10 @@ void PowerButtonScreenshotController::OnKeyEvent(ui::KeyEvent* event) {
if (!volume_down_timer_.IsRunning()) {
volume_down_timer_.Start(
FROM_HERE, kScreenshotChordDelay, this,
&PowerButtonScreenshotController::OnVolumeDownTimeout);
FROM_HERE, kScreenshotChordDelay,
base::BindOnce(
&PowerButtonScreenshotController::OnVolumeDownTimeout,
base::Unretained(this), ui::Accelerator(*event)));
}
}
}
......@@ -140,8 +142,10 @@ bool PowerButtonScreenshotController::InterceptScreenshotChord() {
return false;
}
void PowerButtonScreenshotController::OnVolumeDownTimeout() {
Shell::Get()->accelerator_controller()->PerformActionIfEnabled(VOLUME_DOWN);
void PowerButtonScreenshotController::OnVolumeDownTimeout(
const ui::Accelerator& accelerator) {
Shell::Get()->accelerator_controller()->PerformActionIfEnabled(VOLUME_DOWN,
accelerator);
}
} // namespace ash
......@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event_handler.h"
namespace base {
......@@ -47,7 +48,7 @@ class ASH_EXPORT PowerButtonScreenshotController : public ui::EventHandler {
bool InterceptScreenshotChord();
// Called by |volume_down_timer_| to perform volume down accelerator.
void OnVolumeDownTimeout();
void OnVolumeDownTimeout(const ui::Accelerator& accelerator);
// True if volume down key is pressed.
bool volume_down_key_pressed_ = false;
......
......@@ -65,7 +65,8 @@ Accelerator::Accelerator(const KeyEvent& key_event)
// |modifiers_| may include the repeat flag.
modifiers_(key_event.flags() & kInterestingFlagsMask),
time_stamp_(key_event.time_stamp()),
interrupted_by_mouse_event_(false) {}
interrupted_by_mouse_event_(false),
source_device_id_(key_event.source_device_id()) {}
Accelerator::Accelerator(const Accelerator& accelerator) {
key_code_ = accelerator.key_code_;
......@@ -73,6 +74,7 @@ Accelerator::Accelerator(const Accelerator& accelerator) {
modifiers_ = accelerator.modifiers_;
time_stamp_ = accelerator.time_stamp_;
interrupted_by_mouse_event_ = accelerator.interrupted_by_mouse_event_;
source_device_id_ = accelerator.source_device_id_;
}
Accelerator::~Accelerator() {
......
......@@ -78,6 +78,8 @@ class UI_BASE_EXPORT Accelerator {
base::TimeTicks time_stamp() const { return time_stamp_; }
int source_device_id() const { return source_device_id_; }
bool IsShiftDown() const;
bool IsCtrlDown() const;
bool IsAltDown() const;
......@@ -121,6 +123,9 @@ class UI_BASE_EXPORT Accelerator {
// TOGGLE_APP_LIST and TOGGLE_APP_LIST_FULLSCREEN are disabled when mouse
// press/release occurs between search key down and up. See crbug.com/665897)
bool interrupted_by_mouse_event_;
// The |source_device_id_| of the KeyEvent.
int source_device_id_ = -1;
};
// An interface that classes that want to register for keyboard accelerators
......
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