Files
react-native-devtools-frontend/front_end/screencast/InputModel.js
T
Blink Reformat 4c46d0969f The Great Blink mv for source files, part 2.
Move and rename files.

NOAUTOREVERT=true
NOPRESUBMIT=true
NOTREECHECKS=true
Bug: 768828
TBR=darin@chromium.org
NOTRY=true

Change-Id: I66d3b155808bc5bdbf237b80208e1e552bcf7f28
Reviewed-on: https://chromium-review.googlesource.com/1001153
Reviewed-by: Blink Reformat <blink-reformat@chromium.org>
Commit-Queue: Blink Reformat <blink-reformat@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#549061}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0aee4434a4dba42a42abaea9bfbc0cd196a63bc1
2018-04-07 15:32:37 +00:00

115 lines
3.1 KiB
JavaScript

// Copyright 2017 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.
Screencast.InputModel = class extends SDK.SDKModel {
/**
* @param {!SDK.Target} target
*/
constructor(target) {
super(target);
this._inputAgent = target.inputAgent();
/** @type {?number} */
this._activeTouchOffsetTop = null;
this._activeTouchParams = null;
}
/**
* @param {!Event} event
*/
emitKeyEvent(event) {
let type;
switch (event.type) {
case 'keydown':
type = 'keyDown';
break;
case 'keyup':
type = 'keyUp';
break;
case 'keypress':
type = 'char';
break;
default:
return;
}
const text = event.type === 'keypress' ? String.fromCharCode(event.charCode) : undefined;
this._inputAgent.invoke_dispatchKeyEvent({
type: type,
modifiers: this._modifiersForEvent(event),
text: text,
unmodifiedText: text ? text.toLowerCase() : undefined,
keyIdentifier: event.keyIdentifier,
code: event.code,
key: event.key,
windowsVirtualKeyCode: event.keyCode,
nativeVirtualKeyCode: event.keyCode,
autoRepeat: false,
isKeypad: false,
isSystemKey: false
});
}
/**
* @param {!Event} event
* @param {number} offsetTop
* @param {number} zoom
*/
emitTouchFromMouseEvent(event, offsetTop, zoom) {
const buttons = {0: 'none', 1: 'left', 2: 'middle', 3: 'right'};
const types = {
'mousedown': 'mousePressed',
'mouseup': 'mouseReleased',
'mousemove': 'mouseMoved',
'mousewheel': 'mouseWheel'
};
if (!(event.type in types) || !(event.which in buttons))
return;
if (event.type !== 'mousewheel' && buttons[event.which] === 'none')
return;
if (event.type === 'mousedown' || this._activeTouchOffsetTop === null)
this._activeTouchOffsetTop = offsetTop;
const x = Math.round(event.offsetX / zoom);
let y = Math.round(event.offsetY / zoom);
y = Math.round(y - this._activeTouchOffsetTop);
const params = {
type: types[event.type],
x: x,
y: y,
modifiers: this._modifiersForEvent(event),
button: buttons[event.which],
clickCount: 0
};
if (event.type === 'mousewheel') {
params.deltaX = event.wheelDeltaX / zoom;
params.deltaY = event.wheelDeltaY / zoom;
} else {
this._activeTouchParams = params;
}
if (event.type === 'mouseup')
this._activeTouchOffsetTop = null;
this._inputAgent.invoke_emulateTouchFromMouseEvent(params);
}
cancelTouch() {
if (this._activeTouchOffsetTop !== null) {
const params = this._activeTouchParams;
this._activeTouchParams = null;
params.type = 'mouseReleased';
this._inputAgent.invoke_emulateTouchFromMouseEvent(params);
}
}
/**
* @param {!Event} event
* @return {number}
*/
_modifiersForEvent(event) {
return (event.altKey ? 1 : 0) | (event.ctrlKey ? 2 : 0) | (event.metaKey ? 4 : 0) | (event.shiftKey ? 8 : 0);
}
};
SDK.SDKModel.register(Screencast.InputModel, SDK.Target.Capability.Input, false);