Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / events / ozone / evdev / mouse_button_map_evdev.cc
blobc8f8e1f48bb423a290586efb90dd9ac8474bd69d
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.
5 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h"
7 #include <linux/input.h>
9 #include "base/logging.h"
11 namespace ui {
13 namespace {
15 // Defines the range of button codes that we support.
17 // Check linux/input.h for more info.
18 const MouseButtonMapEvdev::Button kMinMouseButtonCode = BTN_MISC;
19 const MouseButtonMapEvdev::Button kMaxMouseButtonCode = BTN_GEAR_UP;
21 bool IsMouseButton(const MouseButtonMapEvdev::Button button) {
22 return (button >= kMinMouseButtonCode && button <= kMaxMouseButtonCode);
25 } // namespace
27 MouseButtonMapEvdev::MouseButtonMapEvdev() {
28 ResetButtonMap();
31 MouseButtonMapEvdev::~MouseButtonMapEvdev() {
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;
40 void MouseButtonMapEvdev::ResetButtonMap() {
41 button_map_.clear();
42 for (Button i = kMinMouseButtonCode; i <= kMaxMouseButtonCode; ++i)
43 button_map_[i] = i;
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;
52 } // namespace ui