Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7095)

Unified Diff: chrome/browser/ui/views/ash/key_rewriter.h

Issue 9854025: Automatically remap Command key on an Apple keyboard to Control [part 2 of 2 - Chrome part] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/ash/key_rewriter.h
diff --git a/chrome/browser/ui/views/ash/key_rewriter.h b/chrome/browser/ui/views/ash/key_rewriter.h
new file mode 100644
index 0000000000000000000000000000000000000000..be9043501a2d8ed59aa29674d86f235304bc40f4
--- /dev/null
+++ b/chrome/browser/ui/views/ash/key_rewriter.h
@@ -0,0 +1,76 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_
+#define CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_
+#pragma once
+
+#include <map>
+#include <string>
+
+#include "ash/key_rewriter_delegate.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/device_hierarchy_observer.h"
+#endif
+
+class KeyRewriter : public ash::KeyRewriterDelegate
+#if defined(OS_CHROMEOS)
+ , public chromeos::DeviceHierarchyObserver
+#endif
+{
+ public:
+ enum DeviceType {
+ kDevicePcKeyboard = 0,
+ kDeviceAppleKeyboard,
+ };
+
+ KeyRewriter();
+ virtual ~KeyRewriter();
+
+ // Calls DeviceAddedInternal.
+ DeviceType DeviceAddedForTesting(int device_id,
+ const std::string& device_name);
+ // Calls RewriteCommandToControl.
+ void RewriteCommandToControlForTesting(aura::KeyEvent* event);
+
+ const std::map<int, DeviceType>& device_id_to_type_for_testing() const {
+ return device_id_to_type_;
+ }
+ void set_last_device_id_for_testing(int device_id) {
+ last_device_id_ = device_id;
+ }
+
+ // Gets DeviceType from the |device_name|.
+ static DeviceType GetDeviceType(const std::string& device_name);
+
+ private:
+ // ash::KeyRewriterDelegate overrides:
+ virtual ash::KeyRewriterDelegate::Action RewriteOrFilterKeyEvent(
+ aura::KeyEvent* event) OVERRIDE;
+
+#if defined(OS_CHROMEOS)
+ // chromeos::DeviceHierarchyObserver overrides:
+ virtual void DeviceHierarchyChanged() OVERRIDE {}
+ virtual void DeviceAdded(int device_id) OVERRIDE;
+ virtual void KeyPressedOrReleased(int device_id) OVERRIDE;
+#endif
+
+ // Rewrites Comment-L/R key presses on an Apple keyboard to Control-L/R. Only
+ // OS_CHROMEOS implementation is available at this point.
+ void RewriteCommandToControl(aura::KeyEvent* event);
+
+ // Checks the type of the |device_name|, and inserts a new entry to
+ // |device_id_to_type_|.
+ DeviceType DeviceAddedInternal(int device_id, const std::string& device_name);
+
+ std::map<int, DeviceType> device_id_to_type_;
+ int last_device_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(KeyRewriter);
+};
+
+#endif // CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_
« no previous file with comments | « chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.cc ('k') | chrome/browser/ui/views/ash/key_rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698