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( ...@@ -1089,9 +1089,11 @@ bool AcceleratorController::IsDeprecated(
return deprecated_accelerators_.count(accelerator) != 0; return deprecated_accelerators_.count(accelerator) != 0;
} }
bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action) { bool AcceleratorController::PerformActionIfEnabled(
if (CanPerformAction(action, ui::Accelerator())) { AcceleratorAction action,
PerformAction(action, ui::Accelerator()); const ui::Accelerator& accelerator) {
if (CanPerformAction(action, accelerator)) {
PerformAction(action, accelerator);
return true; return true;
} }
return false; return false;
...@@ -1407,6 +1409,12 @@ void AcceleratorController::PerformAction(AcceleratorAction action, ...@@ -1407,6 +1409,12 @@ void AcceleratorController::PerformAction(AcceleratorAction action,
if (restriction != RESTRICTION_NONE) if (restriction != RESTRICTION_NONE)
return; 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 // 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() // implement it in your module's controller code or pull it into a HandleFoo()
// function above. // function above.
......
...@@ -105,7 +105,9 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget, ...@@ -105,7 +105,9 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget,
// Performs the specified action if it is enabled. Returns whether the action // Performs the specified action if it is enabled. Returns whether the action
// was performed successfully. // was performed successfully.
bool PerformActionIfEnabled(AcceleratorAction action); bool PerformActionIfEnabled(
AcceleratorAction action,
const ui::Accelerator& accelerator = ui::Accelerator());
// Returns the restriction for the current context. // Returns the restriction for the current context.
AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction(); AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction();
......
...@@ -108,8 +108,10 @@ void PowerButtonScreenshotController::OnKeyEvent(ui::KeyEvent* event) { ...@@ -108,8 +108,10 @@ void PowerButtonScreenshotController::OnKeyEvent(ui::KeyEvent* event) {
if (!volume_down_timer_.IsRunning()) { if (!volume_down_timer_.IsRunning()) {
volume_down_timer_.Start( volume_down_timer_.Start(
FROM_HERE, kScreenshotChordDelay, this, FROM_HERE, kScreenshotChordDelay,
&PowerButtonScreenshotController::OnVolumeDownTimeout); base::BindOnce(
&PowerButtonScreenshotController::OnVolumeDownTimeout,
base::Unretained(this), ui::Accelerator(*event)));
} }
} }
} }
...@@ -140,8 +142,10 @@ bool PowerButtonScreenshotController::InterceptScreenshotChord() { ...@@ -140,8 +142,10 @@ bool PowerButtonScreenshotController::InterceptScreenshotChord() {
return false; return false;
} }
void PowerButtonScreenshotController::OnVolumeDownTimeout() { void PowerButtonScreenshotController::OnVolumeDownTimeout(
Shell::Get()->accelerator_controller()->PerformActionIfEnabled(VOLUME_DOWN); const ui::Accelerator& accelerator) {
Shell::Get()->accelerator_controller()->PerformActionIfEnabled(VOLUME_DOWN,
accelerator);
} }
} // namespace ash } // namespace ash
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event_handler.h" #include "ui/events/event_handler.h"
namespace base { namespace base {
...@@ -47,7 +48,7 @@ class ASH_EXPORT PowerButtonScreenshotController : public ui::EventHandler { ...@@ -47,7 +48,7 @@ class ASH_EXPORT PowerButtonScreenshotController : public ui::EventHandler {
bool InterceptScreenshotChord(); bool InterceptScreenshotChord();
// Called by |volume_down_timer_| to perform volume down accelerator. // 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. // True if volume down key is pressed.
bool volume_down_key_pressed_ = false; bool volume_down_key_pressed_ = false;
......
...@@ -65,7 +65,8 @@ Accelerator::Accelerator(const KeyEvent& key_event) ...@@ -65,7 +65,8 @@ Accelerator::Accelerator(const KeyEvent& key_event)
// |modifiers_| may include the repeat flag. // |modifiers_| may include the repeat flag.
modifiers_(key_event.flags() & kInterestingFlagsMask), modifiers_(key_event.flags() & kInterestingFlagsMask),
time_stamp_(key_event.time_stamp()), 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) { Accelerator::Accelerator(const Accelerator& accelerator) {
key_code_ = accelerator.key_code_; key_code_ = accelerator.key_code_;
...@@ -73,6 +74,7 @@ Accelerator::Accelerator(const Accelerator& accelerator) { ...@@ -73,6 +74,7 @@ Accelerator::Accelerator(const Accelerator& accelerator) {
modifiers_ = accelerator.modifiers_; modifiers_ = accelerator.modifiers_;
time_stamp_ = accelerator.time_stamp_; time_stamp_ = accelerator.time_stamp_;
interrupted_by_mouse_event_ = accelerator.interrupted_by_mouse_event_; interrupted_by_mouse_event_ = accelerator.interrupted_by_mouse_event_;
source_device_id_ = accelerator.source_device_id_;
} }
Accelerator::~Accelerator() { Accelerator::~Accelerator() {
......
...@@ -78,6 +78,8 @@ class UI_BASE_EXPORT Accelerator { ...@@ -78,6 +78,8 @@ class UI_BASE_EXPORT Accelerator {
base::TimeTicks time_stamp() const { return time_stamp_; } base::TimeTicks time_stamp() const { return time_stamp_; }
int source_device_id() const { return source_device_id_; }
bool IsShiftDown() const; bool IsShiftDown() const;
bool IsCtrlDown() const; bool IsCtrlDown() const;
bool IsAltDown() const; bool IsAltDown() const;
...@@ -121,6 +123,9 @@ class UI_BASE_EXPORT Accelerator { ...@@ -121,6 +123,9 @@ class UI_BASE_EXPORT Accelerator {
// TOGGLE_APP_LIST and TOGGLE_APP_LIST_FULLSCREEN are disabled when mouse // 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) // press/release occurs between search key down and up. See crbug.com/665897)
bool interrupted_by_mouse_event_; 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 // 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