OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "ui/events/ozone/evdev/mouse_button_map_evdev.h" |
| 6 |
| 7 #include <linux/input.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 |
| 11 namespace ui { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // Defines the range of button codes that we support. |
| 16 // |
| 17 // Check linux/input.h for more info. |
| 18 const MouseButtonMapEvdev::Button kMinMouseButtonCode = BTN_MISC; |
| 19 const MouseButtonMapEvdev::Button kMaxMouseButtonCode = BTN_GEAR_UP; |
| 20 |
| 21 bool IsMouseButton(const MouseButtonMapEvdev::Button button) { |
| 22 return (button >= kMinMouseButtonCode && button <= kMaxMouseButtonCode); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 27 MouseButtonMapEvdev::MouseButtonMapEvdev() { |
| 28 ResetButtonMap(); |
| 29 } |
| 30 |
| 31 MouseButtonMapEvdev::~MouseButtonMapEvdev() { |
| 32 } |
| 33 |
| 34 void MouseButtonMapEvdev::UpdateButtonMap(Button button_from, |
| 35 Button button_to) { |
| 36 DCHECK(IsMouseButton(button_from) && IsMouseButton(button_to)); |
| 37 button_map_[button_from] = button_to; |
| 38 } |
| 39 |
| 40 void MouseButtonMapEvdev::ResetButtonMap() { |
| 41 button_map_.clear(); |
| 42 for (Button i = kMinMouseButtonCode; i <= kMaxMouseButtonCode; ++i) |
| 43 button_map_[i] = i; |
| 44 } |
| 45 |
| 46 int MouseButtonMapEvdev::GetMappedButton(const Button button) const { |
| 47 ButtonMap::const_iterator it = button_map_.find(button); |
| 48 DCHECK(it != button_map_.end()); |
| 49 return it->second; |
| 50 } |
| 51 |
| 52 } // namespace ui |
OLD | NEW |