Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Mikolaj Walczak | 297ece6 | 2019-10-11 02:55:40 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "components/exo/client_controlled_accelerators.h" |
| 6 | |
Sara Kato | 4fbf82268 | 2020-04-02 21:16:57 | [diff] [blame] | 7 | #include "base/metrics/user_metrics.h" |
| 8 | #include "base/metrics/user_metrics_action.h" |
| 9 | |
Mikolaj Walczak | 297ece6 | 2019-10-11 02:55:40 | [diff] [blame] | 10 | namespace exo { |
| 11 | |
| 12 | ClientControlledAcceleratorTarget::ClientControlledAcceleratorTarget( |
| 13 | ClientControlledShellSurface* surface) |
| 14 | : surface_(surface) {} |
| 15 | |
| 16 | ClientControlledAcceleratorTarget::~ClientControlledAcceleratorTarget() = |
| 17 | default; |
| 18 | |
| 19 | void ClientControlledAcceleratorTarget::RegisterAccelerator( |
| 20 | const ui::Accelerator& accelerator, |
| 21 | ClientControlledAcceleratorAction action) { |
| 22 | accelerators_.insert(std::make_pair(ui::Accelerator{accelerator}, action)); |
| 23 | } |
| 24 | |
| 25 | void ClientControlledAcceleratorTarget::RegisterAccelerator( |
| 26 | ui::Accelerator&& accelerator, |
| 27 | ClientControlledAcceleratorAction action) { |
| 28 | accelerators_.insert(std::make_pair(std::move(accelerator), action)); |
| 29 | } |
| 30 | |
| 31 | bool ClientControlledAcceleratorTarget::AcceleratorPressed( |
| 32 | const ui::Accelerator& accelerator) { |
| 33 | auto it = accelerators_.find(accelerator); |
| 34 | DCHECK(it != accelerators_.end()); |
| 35 | ClientControlledAcceleratorAction action = it->second; |
| 36 | |
| 37 | switch (action) { |
| 38 | case ClientControlledAcceleratorAction::ZOOM_IN: |
| 39 | surface_->ChangeZoomLevel(ZoomChange::IN); |
Sara Kato | 4fbf82268 | 2020-04-02 21:16:57 | [diff] [blame] | 40 | base::RecordAction(base::UserMetricsAction("Accel_ARC_Zoom_Ui_In")); |
Mikolaj Walczak | 297ece6 | 2019-10-11 02:55:40 | [diff] [blame] | 41 | break; |
| 42 | case ClientControlledAcceleratorAction::ZOOM_OUT: |
| 43 | surface_->ChangeZoomLevel(ZoomChange::OUT); |
Sara Kato | 4fbf82268 | 2020-04-02 21:16:57 | [diff] [blame] | 44 | base::RecordAction(base::UserMetricsAction("Accel_ARC_Zoom_Ui_Out")); |
Mikolaj Walczak | 297ece6 | 2019-10-11 02:55:40 | [diff] [blame] | 45 | break; |
| 46 | case ClientControlledAcceleratorAction::ZOOM_RESET: |
| 47 | surface_->ChangeZoomLevel(ZoomChange::RESET); |
Sara Kato | 4fbf82268 | 2020-04-02 21:16:57 | [diff] [blame] | 48 | base::RecordAction(base::UserMetricsAction("Accel_ARC_Zoom_Ui_Reset")); |
Mikolaj Walczak | 297ece6 | 2019-10-11 02:55:40 | [diff] [blame] | 49 | break; |
| 50 | } |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | bool ClientControlledAcceleratorTarget::CanHandleAccelerators() const { |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | } // namespace exo |