| Index: chrome/browser/chromeos/events/new_event_rewriter.h
|
| diff --git a/chrome/browser/chromeos/events/new_event_rewriter.h b/chrome/browser/chromeos/events/new_event_rewriter.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c6d6e4ee5f39a998c914519939f3fbefce22a2c3
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/events/new_event_rewriter.h
|
| @@ -0,0 +1,115 @@
|
| +// Copyright 2014 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_CHROMEOS_EVENTS_NEW_EVENT_REWRITER_H_
|
| +#define CHROME_BROWSER_CHROMEOS_EVENTS_NEW_EVENT_REWRITER_H_
|
| +
|
| +#include <map>
|
| +#include <set>
|
| +#include <string>
|
| +
|
| +#include "ui/events/event_rewriter.h"
|
| +
|
| +class PrefService;
|
| +
|
| +namespace chromeos {
|
| +namespace input_method {
|
| +class ImeKeyboard;
|
| +}
|
| +}
|
| +
|
| +namespace chromeos {
|
| +
|
| +// KeyboardEventRewriter makes various changes to keyboard-related events,
|
| +// including KeyEvents and some other events with keyboard modifier flags:
|
| +// - maps modifiers keys (Control, Alt, Search, Caps, Diamond) according
|
| +// to user preferences;
|
| +// - maps Command to Control on Apple keyboards;
|
| +// - converts numeric pad editing keys to their numeric forms;
|
| +// - converts top-row function keys to special keys where necessary;
|
| +// - handles various key combinations like Search+Backspace -> Delete
|
| +// and Search+number to Fnumber;
|
| +// - handles key/pointer combinations like Alt+Button1 -> Button3.
|
| +class KeyboardEventRewriter : public ui::EventRewriter {
|
| + public:
|
| + enum DeviceType {
|
| + kDeviceUnknown = 0,
|
| + kDeviceAppleKeyboard,
|
| + };
|
| +
|
| + KeyboardEventRewriter();
|
| + virtual ~KeyboardEventRewriter();
|
| +
|
| + // Calls DeviceAddedInternal.
|
| + DeviceType DeviceAddedForTesting(int device_id,
|
| + const std::string& device_name);
|
| +
|
| + // Calls RewriteLocatedEvent().
|
| + bool RewriteLocatedEventForTesting(ui::Event* event);
|
| +
|
| + void set_last_device_id_for_testing(int device_id) {
|
| + last_device_id_ = device_id;
|
| + }
|
| + void set_pref_service_for_testing(const PrefService* pref_service) {
|
| + pref_service_for_testing_ = pref_service;
|
| + }
|
| + void set_ime_keyboard_for_testing(
|
| + chromeos::input_method::ImeKeyboard* ime_keyboard) {
|
| + ime_keyboard_for_testing_ = ime_keyboard;
|
| + }
|
| +
|
| + // EventRewriter overrides:
|
| + virtual ui::EventRewriteStatus RewriteEvent(
|
| + ui::Event* event,
|
| + scoped_ptr<ui::Event>* new_event) OVERRIDE;
|
| + virtual ui::EventRewriteStatus NextDispatchEvent(
|
| + const ui::Event& last_event,
|
| + scoped_ptr<ui::Event>* new_event) OVERRIDE;
|
| +
|
| + private:
|
| + // Returns the PrefService that should be used.
|
| + const PrefService* GetPrefService() const;
|
| +
|
| + // 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);
|
| +
|
| + // Returns true if |last_device_id_| is Apple's.
|
| + bool IsAppleKeyboard(const ui::Event& event) const;
|
| +
|
| + // Returns true if the event comes from an Chrome keyboard with a Diamond key.
|
| + bool HasDiamondKey(const ui::Event& event) const;
|
| +
|
| + // Returns true if the target for |event| would prefer to receive raw function
|
| + // keys instead of having them rewritten into back, forward, brightness,
|
| + // volume, etc. or if the user has specified that they desire top-row keys to
|
| + // be treated as function keys globally.
|
| + bool TopRowKeysAreFunctionKeys(const ui::Event& event) const;
|
| +
|
| + int GetRemappedModifierMasks(const PrefService& pref_service,
|
| + const ui::Event& event,
|
| + int original_flags) const;
|
| +
|
| + bool RewriteModifierKeys(ui::Event* event);
|
| + bool RewriteNumPadKeys(ui::Event* event);
|
| + bool RewriteExtendedKeys(ui::Event* event);
|
| + bool RewriteFunctionKeys(ui::Event* event);
|
| + bool RewriteLocatedEvent(ui::Event* event);
|
| +
|
| + // A set of device IDs whose press event has been rewritten.
|
| + std::set<int> pressed_device_ids_;
|
| +
|
| + std::map<int, DeviceType> device_id_to_type_;
|
| + int last_device_id_;
|
| +
|
| + chromeos::input_method::ImeKeyboard* ime_keyboard_for_testing_;
|
| + const PrefService* pref_service_for_testing_;
|
| + bool top_rows_are_function_keys_for_testing_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(KeyboardEventRewriter);
|
| +};
|
| +
|
| +} // namespace chromeos
|
| +
|
| +#endif // CHROME_BROWSER_CHROMEOS_EVENTS_NEW_EVENT_REWRITER_H_
|
|
|