Files
react-native-devtools-frontend/front_end/ui/ForwardedInputEventHandler.js
T
Tim van der Lippe c02a97ca2c Fix imports for Common.Event typedef
All references now use the fully qualified
"Common.EventTarget.EventTargetEvent". It renames it to
"EventTargetEvent" to prevent a name-clash with the native "Event" type.

Bug: 1006759
Change-Id: I13fcdfd613041da146d741a0d1f785bfc905a7a8
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2056481
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
2020-02-14 15:21:06 +00:00

41 lines
1.3 KiB
JavaScript

// 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.
import * as Common from '../common/common.js'; // eslint-disable-line no-unused-vars
import * as Host from '../host/host.js';
import {KeyboardShortcut} from './KeyboardShortcut.js';
import {ForwardedShortcut} from './ShortcutRegistry.js';
/**
* @unrestricted
*/
export class ForwardedInputEventHandler {
constructor() {
Host.InspectorFrontendHost.InspectorFrontendHostInstance.events.addEventListener(
Host.InspectorFrontendHostAPI.Events.KeyEventUnhandled, this._onKeyEventUnhandled, this);
}
/**
* @param {!Common.EventTarget.EventTargetEvent} event
*/
_onKeyEventUnhandled(event) {
const data = event.data;
const type = /** @type {string} */ (data.type);
const key = /** @type {string} */ (data.key);
const keyCode = /** @type {number} */ (data.keyCode);
const modifiers = /** @type {number} */ (data.modifiers);
if (type !== 'keydown') {
return;
}
self.UI.context.setFlavor(ForwardedShortcut, ForwardedShortcut.instance);
self.UI.shortcutRegistry.handleKey(KeyboardShortcut.makeKey(keyCode, modifiers), key);
self.UI.context.setFlavor(ForwardedShortcut, null);
}
}
new ForwardedInputEventHandler();