Mikolaj Walczak | 297ece6 | 2019-10-11 02:55:40 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 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 | |
| 7 | namespace exo { |
| 8 | |
| 9 | ClientControlledAcceleratorTarget::ClientControlledAcceleratorTarget( |
| 10 | ClientControlledShellSurface* surface) |
| 11 | : surface_(surface) {} |
| 12 | |
| 13 | ClientControlledAcceleratorTarget::~ClientControlledAcceleratorTarget() = |
| 14 | default; |
| 15 | |
| 16 | void ClientControlledAcceleratorTarget::RegisterAccelerator( |
| 17 | const ui::Accelerator& accelerator, |
| 18 | ClientControlledAcceleratorAction action) { |
| 19 | accelerators_.insert(std::make_pair(ui::Accelerator{accelerator}, action)); |
| 20 | } |
| 21 | |
| 22 | void ClientControlledAcceleratorTarget::RegisterAccelerator( |
| 23 | ui::Accelerator&& accelerator, |
| 24 | ClientControlledAcceleratorAction action) { |
| 25 | accelerators_.insert(std::make_pair(std::move(accelerator), action)); |
| 26 | } |
| 27 | |
| 28 | bool ClientControlledAcceleratorTarget::AcceleratorPressed( |
| 29 | const ui::Accelerator& accelerator) { |
| 30 | auto it = accelerators_.find(accelerator); |
| 31 | DCHECK(it != accelerators_.end()); |
| 32 | ClientControlledAcceleratorAction action = it->second; |
| 33 | |
| 34 | switch (action) { |
| 35 | case ClientControlledAcceleratorAction::ZOOM_IN: |
| 36 | surface_->ChangeZoomLevel(ZoomChange::IN); |
| 37 | break; |
| 38 | case ClientControlledAcceleratorAction::ZOOM_OUT: |
| 39 | surface_->ChangeZoomLevel(ZoomChange::OUT); |
| 40 | break; |
| 41 | case ClientControlledAcceleratorAction::ZOOM_RESET: |
| 42 | surface_->ChangeZoomLevel(ZoomChange::RESET); |
| 43 | break; |
| 44 | } |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | bool ClientControlledAcceleratorTarget::CanHandleAccelerators() const { |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | } // namespace exo |