mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-09 05:08:28 +08:00
[JSDOC2TS]: Migrate input
Bug: chromium:1158760 Change-Id: I750a19ecfdfc7ca59929cb3d178f06b33d8b084d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2630946 Commit-Queue: Jan Scheffler <janscheffler@chromium.org> Auto-Submit: Jan Scheffler <janscheffler@chromium.org> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
This commit is contained in:
committed by
Commit Bot
parent
5bba5fdb77
commit
86e4bd2600
@@ -431,31 +431,31 @@
|
||||
"help/ReleaseNoteView.ts | s": {
|
||||
"message": "{PH1}"
|
||||
},
|
||||
"input/InputTimeline.js | clearAll": {
|
||||
"input/InputTimeline.ts | clearAll": {
|
||||
"message": "Clear all"
|
||||
},
|
||||
"input/InputTimeline.js | loadProfile": {
|
||||
"input/InputTimeline.ts | loadProfile": {
|
||||
"message": "Load profile…"
|
||||
},
|
||||
"input/InputTimeline.js | saveProfile": {
|
||||
"input/InputTimeline.ts | saveProfile": {
|
||||
"message": "Save profile…"
|
||||
},
|
||||
"input/ModuleUIStrings.js | inputs": {
|
||||
"input/ModuleUIStrings.ts | inputs": {
|
||||
"message": "Inputs"
|
||||
},
|
||||
"input/ModuleUIStrings.js | pause": {
|
||||
"input/ModuleUIStrings.ts | pause": {
|
||||
"message": "Pause"
|
||||
},
|
||||
"input/ModuleUIStrings.js | resume": {
|
||||
"input/ModuleUIStrings.ts | resume": {
|
||||
"message": "Resume"
|
||||
},
|
||||
"input/ModuleUIStrings.js | startRecording": {
|
||||
"input/ModuleUIStrings.ts | startRecording": {
|
||||
"message": "Start recording"
|
||||
},
|
||||
"input/ModuleUIStrings.js | startReplaying": {
|
||||
"input/ModuleUIStrings.ts | startReplaying": {
|
||||
"message": "Start replaying"
|
||||
},
|
||||
"input/ModuleUIStrings.js | stopRecording": {
|
||||
"input/ModuleUIStrings.ts | stopRecording": {
|
||||
"message": "Stop recording"
|
||||
},
|
||||
"js_profiler/ModuleUIStrings.ts | profiler": {
|
||||
|
||||
@@ -7,9 +7,9 @@ import("../../scripts/build/ninja/devtools_module.gni")
|
||||
|
||||
devtools_module("input") {
|
||||
sources = [
|
||||
"InputModel.js",
|
||||
"InputTimeline.js",
|
||||
"ModuleUIStrings.js",
|
||||
"InputModel.ts",
|
||||
"InputTimeline.ts",
|
||||
"ModuleUIStrings.ts",
|
||||
]
|
||||
|
||||
deps = [
|
||||
@@ -30,7 +30,7 @@ devtools_entrypoint("bundle") {
|
||||
}
|
||||
|
||||
devtools_entrypoint("legacy") {
|
||||
entrypoint = "input-legacy.js"
|
||||
entrypoint = "input-legacy.ts"
|
||||
|
||||
deps = [ ":bundle" ]
|
||||
}
|
||||
|
||||
@@ -2,61 +2,50 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
/* eslint-disable rulesdir/no_underscored_properties */
|
||||
|
||||
import * as SDK from '../sdk/sdk.js';
|
||||
|
||||
export class InputModel extends SDK.SDKModel.SDKModel {
|
||||
/**
|
||||
* @param {!SDK.SDKModel.Target} target
|
||||
*/
|
||||
constructor(target) {
|
||||
_inputAgent: ProtocolProxyApi.InputApi;
|
||||
_eventDispatchTimer: number;
|
||||
_dispatchEventDataList: EventData[];
|
||||
_finishCallback: (() => void)|null;
|
||||
_dispatchingIndex!: number;
|
||||
_lastEventTime?: number|null;
|
||||
_replayPaused?: boolean;
|
||||
|
||||
constructor(target: SDK.SDKModel.Target) {
|
||||
super(target);
|
||||
this._inputAgent = target.inputAgent();
|
||||
/** @type {number} */
|
||||
this._eventDispatchTimer = 0;
|
||||
/** @type {!Array<!EventData>}*/
|
||||
this._dispatchEventDataList = [];
|
||||
/** @type {?function():void} */
|
||||
this._finishCallback = null;
|
||||
/** @type {number} */
|
||||
this._dispatchingIndex;
|
||||
|
||||
this._reset();
|
||||
}
|
||||
|
||||
_reset() {
|
||||
/** @type {?number} */
|
||||
_reset(): void {
|
||||
this._lastEventTime = null;
|
||||
/** @type {boolean} */
|
||||
this._replayPaused = false;
|
||||
/** @type {number} */
|
||||
this._dispatchingIndex = 0;
|
||||
window.clearTimeout(this._eventDispatchTimer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!SDK.TracingModel.TracingModel} tracingModel
|
||||
*/
|
||||
setEvents(tracingModel) {
|
||||
setEvents(tracingModel: SDK.TracingModel.TracingModel): void {
|
||||
this._dispatchEventDataList = [];
|
||||
for (const process of tracingModel.sortedProcesses()) {
|
||||
for (const thread of process.sortedThreads()) {
|
||||
this._processThreadEvents(tracingModel, thread);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param {!EventData} a
|
||||
* @param {!EventData} b
|
||||
*/
|
||||
function compareTimestamp(a, b) {
|
||||
function compareTimestamp(a: EventData, b: EventData): number {
|
||||
return a.timestamp - b.timestamp;
|
||||
}
|
||||
this._dispatchEventDataList.sort(compareTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?function():void} finishCallback
|
||||
*/
|
||||
startReplay(finishCallback) {
|
||||
startReplay(finishCallback: (() => void)|null): void {
|
||||
this._reset();
|
||||
this._finishCallback = finishCallback;
|
||||
if (this._dispatchEventDataList.length) {
|
||||
@@ -66,7 +55,7 @@ export class InputModel extends SDK.SDKModel.SDKModel {
|
||||
}
|
||||
}
|
||||
|
||||
pause() {
|
||||
pause(): void {
|
||||
window.clearTimeout(this._eventDispatchTimer);
|
||||
if (this._dispatchingIndex >= this._dispatchEventDataList.length) {
|
||||
this._replayStopped();
|
||||
@@ -75,18 +64,14 @@ export class InputModel extends SDK.SDKModel.SDKModel {
|
||||
}
|
||||
}
|
||||
|
||||
resume() {
|
||||
resume(): void {
|
||||
this._replayPaused = false;
|
||||
if (this._dispatchingIndex < this._dispatchEventDataList.length) {
|
||||
this._dispatchNextEvent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!SDK.TracingModel.TracingModel} tracingModel
|
||||
* @param {!SDK.TracingModel.Thread} thread
|
||||
*/
|
||||
_processThreadEvents(tracingModel, thread) {
|
||||
_processThreadEvents(_tracingModel: SDK.TracingModel.TracingModel, thread: SDK.TracingModel.Thread): void {
|
||||
for (const event of thread.events()) {
|
||||
if (event.name === 'EventDispatch' && this._isValidInputEvent(event.args.data)) {
|
||||
this._dispatchEventDataList.push(event.args.data);
|
||||
@@ -94,21 +79,11 @@ export class InputModel extends SDK.SDKModel.SDKModel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {!EventData} eventData
|
||||
* @return {boolean}
|
||||
*/
|
||||
_isValidInputEvent(eventData) {
|
||||
return this._isMouseEvent(/** @type {!MouseEventData} */ (eventData)) ||
|
||||
this._isKeyboardEvent(/** @type {!KeyboardEventData} */ (eventData));
|
||||
_isValidInputEvent(eventData: EventData): boolean {
|
||||
return this._isMouseEvent(eventData as MouseEventData) || this._isKeyboardEvent(eventData as KeyboardEventData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!MouseEventData} eventData
|
||||
* @return {boolean}
|
||||
*/
|
||||
_isMouseEvent(eventData) {
|
||||
_isMouseEvent(eventData: MouseEventData): boolean {
|
||||
if (!MOUSE_EVENT_TYPE_TO_REQUEST_TYPE.has(eventData.type)) {
|
||||
return false;
|
||||
}
|
||||
@@ -118,11 +93,7 @@ export class InputModel extends SDK.SDKModel.SDKModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!KeyboardEventData} eventData
|
||||
* @return {boolean}
|
||||
*/
|
||||
_isKeyboardEvent(eventData) {
|
||||
_isKeyboardEvent(eventData: KeyboardEventData): boolean {
|
||||
if (!KEYBOARD_EVENT_TYPE_TO_REQUEST_TYPE.has(eventData.type)) {
|
||||
return false;
|
||||
}
|
||||
@@ -132,13 +103,13 @@ export class InputModel extends SDK.SDKModel.SDKModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
_dispatchNextEvent() {
|
||||
_dispatchNextEvent(): void {
|
||||
const eventData = this._dispatchEventDataList[this._dispatchingIndex];
|
||||
this._lastEventTime = eventData.timestamp;
|
||||
if (MOUSE_EVENT_TYPE_TO_REQUEST_TYPE.has(eventData.type)) {
|
||||
this._dispatchMouseEvent(/** @type {!MouseEventData} */ (eventData));
|
||||
this._dispatchMouseEvent(eventData as MouseEventData);
|
||||
} else if (KEYBOARD_EVENT_TYPE_TO_REQUEST_TYPE.has(eventData.type)) {
|
||||
this._dispatchKeyEvent(/** @type {!KeyboardEventData} */ (eventData));
|
||||
this._dispatchKeyEvent(eventData as KeyboardEventData);
|
||||
}
|
||||
|
||||
++this._dispatchingIndex;
|
||||
@@ -150,10 +121,7 @@ export class InputModel extends SDK.SDKModel.SDKModel {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!MouseEventData} eventData
|
||||
*/
|
||||
async _dispatchMouseEvent(eventData) {
|
||||
async _dispatchMouseEvent(eventData: MouseEventData): Promise<void> {
|
||||
const type = MOUSE_EVENT_TYPE_TO_REQUEST_TYPE.get(eventData.type);
|
||||
if (!type) {
|
||||
throw new Error(`Could not find mouse event type for eventData ${eventData.type}`);
|
||||
@@ -169,15 +137,12 @@ export class InputModel extends SDK.SDKModel.SDKModel {
|
||||
buttons: eventData.buttons,
|
||||
clickCount: eventData.clickCount,
|
||||
deltaX: eventData.deltaX,
|
||||
deltaY: eventData.deltaY
|
||||
deltaY: eventData.deltaY,
|
||||
};
|
||||
await this._inputAgent.invoke_dispatchMouseEvent(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!KeyboardEventData} eventData
|
||||
*/
|
||||
async _dispatchKeyEvent(eventData) {
|
||||
async _dispatchKeyEvent(eventData: KeyboardEventData): Promise<void> {
|
||||
const type = KEYBOARD_EVENT_TYPE_TO_REQUEST_TYPE.get(eventData.type);
|
||||
if (!type) {
|
||||
throw new Error(`Could not find key event type for eventData ${eventData.type}`);
|
||||
@@ -189,12 +154,12 @@ export class InputModel extends SDK.SDKModel.SDKModel {
|
||||
text: text,
|
||||
unmodifiedText: text ? text.toLowerCase() : undefined,
|
||||
code: eventData.code,
|
||||
key: eventData.key
|
||||
key: eventData.key,
|
||||
};
|
||||
await this._inputAgent.invoke_dispatchKeyEvent(params);
|
||||
}
|
||||
|
||||
_replayStopped() {
|
||||
_replayStopped(): void {
|
||||
window.clearTimeout(this._eventDispatchTimer);
|
||||
this._reset();
|
||||
if (this._finishCallback) {
|
||||
@@ -203,37 +168,46 @@ export class InputModel extends SDK.SDKModel.SDKModel {
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {!Map<string, !Protocol.Input.DispatchMouseEventRequestType>} */
|
||||
const MOUSE_EVENT_TYPE_TO_REQUEST_TYPE = new Map([
|
||||
const MOUSE_EVENT_TYPE_TO_REQUEST_TYPE = new Map<string, Protocol.Input.DispatchMouseEventRequestType>([
|
||||
['mousedown', Protocol.Input.DispatchMouseEventRequestType.MousePressed],
|
||||
['mouseup', Protocol.Input.DispatchMouseEventRequestType.MouseReleased],
|
||||
['mousemove', Protocol.Input.DispatchMouseEventRequestType.MouseMoved],
|
||||
['wheel', Protocol.Input.DispatchMouseEventRequestType.MouseWheel],
|
||||
]);
|
||||
|
||||
/** @type {!Map<string, !Protocol.Input.DispatchKeyEventRequestType>} */
|
||||
const KEYBOARD_EVENT_TYPE_TO_REQUEST_TYPE = new Map([
|
||||
const KEYBOARD_EVENT_TYPE_TO_REQUEST_TYPE = new Map<string, Protocol.Input.DispatchKeyEventRequestType>([
|
||||
['keydown', Protocol.Input.DispatchKeyEventRequestType.KeyDown],
|
||||
['keyup', Protocol.Input.DispatchKeyEventRequestType.KeyUp],
|
||||
['keypress', Protocol.Input.DispatchKeyEventRequestType.Char],
|
||||
]);
|
||||
|
||||
/** @type {!Map<number, !Protocol.Input.MouseButton>} */
|
||||
const BUTTONID_TO_ACTION_NAME = new Map([
|
||||
[0, Protocol.Input.MouseButton.Left], [1, Protocol.Input.MouseButton.Middle], [2, Protocol.Input.MouseButton.Right],
|
||||
[3, Protocol.Input.MouseButton.Back], [4, Protocol.Input.MouseButton.Forward]
|
||||
const BUTTONID_TO_ACTION_NAME = new Map<number, Protocol.Input.MouseButton>([
|
||||
[0, Protocol.Input.MouseButton.Left],
|
||||
[1, Protocol.Input.MouseButton.Middle],
|
||||
[2, Protocol.Input.MouseButton.Right],
|
||||
[3, Protocol.Input.MouseButton.Back],
|
||||
[4, Protocol.Input.MouseButton.Forward],
|
||||
]);
|
||||
|
||||
SDK.SDKModel.SDKModel.register(InputModel, SDK.SDKModel.Capability.Input, false);
|
||||
export interface MouseEventData {
|
||||
type: string;
|
||||
modifiers: number;
|
||||
timestamp: number;
|
||||
x: number;
|
||||
y: number;
|
||||
button: number;
|
||||
buttons: number;
|
||||
clickCount: number;
|
||||
deltaX: number;
|
||||
deltaY: number;
|
||||
}
|
||||
export interface KeyboardEventData {
|
||||
type: string;
|
||||
modifiers: number;
|
||||
timestamp: number;
|
||||
code: string;
|
||||
key: string;
|
||||
}
|
||||
|
||||
/** @typedef {{type: string, modifiers: number, timestamp: number, x: number, y: number, button: number, buttons: number, clickCount: number, deltaX: number, deltaY: number}} */
|
||||
// @ts-ignore typedef
|
||||
export let MouseEventData;
|
||||
|
||||
/** @typedef {{type: string, modifiers: number, timestamp: number, code: string, key: string}} */
|
||||
// @ts-ignore typedef
|
||||
export let KeyboardEventData;
|
||||
|
||||
/** @typedef {(!MouseEventData|!KeyboardEventData)} */
|
||||
// @ts-ignore typedef
|
||||
export let EventData;
|
||||
export type EventData = MouseEventData|KeyboardEventData;
|
||||
@@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
/* eslint-disable rulesdir/no_underscored_properties */
|
||||
|
||||
import * as Bindings from '../bindings/bindings.js';
|
||||
import * as i18n from '../i18n/i18n.js';
|
||||
import * as Platform from '../platform/platform.js';
|
||||
@@ -26,19 +28,25 @@ export const UIStrings = {
|
||||
*/
|
||||
saveProfile: 'Save profile…',
|
||||
};
|
||||
const str_ = i18n.i18n.registerUIStrings('input/InputTimeline.js', UIStrings);
|
||||
const str_ = i18n.i18n.registerUIStrings('input/InputTimeline.ts', UIStrings);
|
||||
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
|
||||
|
||||
/** @type {!InputTimeline} */
|
||||
let inputTimelineInstance;
|
||||
let inputTimelineInstance: InputTimeline;
|
||||
export class InputTimeline extends UI.Widget.VBox implements Timeline.TimelineLoader.Client {
|
||||
_tracingClient: TracingClient|null;
|
||||
_tracingModel: SDK.TracingModel.TracingModel|null;
|
||||
_inputModel: InputModel|null;
|
||||
_state: State;
|
||||
_toggleRecordAction: UI.ActionRegistration.Action;
|
||||
_startReplayAction: UI.ActionRegistration.Action;
|
||||
_togglePauseAction: UI.ActionRegistration.Action;
|
||||
_panelToolbar: UI.Toolbar.Toolbar;
|
||||
_clearButton: UI.Toolbar.ToolbarButton;
|
||||
_loadButton: UI.Toolbar.ToolbarButton;
|
||||
_saveButton: UI.Toolbar.ToolbarButton;
|
||||
_fileSelectorElement?: HTMLInputElement;
|
||||
_loader?: Timeline.TimelineLoader.TimelineLoader;
|
||||
|
||||
/**
|
||||
* @implements {Timeline.TimelineLoader.Client}
|
||||
*/
|
||||
export class InputTimeline extends UI.Widget.VBox {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
constructor() {
|
||||
super(true);
|
||||
this.registerRequiredCSS('input/inputTimeline.css', {enableLegacyPatching: true});
|
||||
@@ -49,19 +57,12 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
this._inputModel = null;
|
||||
|
||||
this._state = State.Idle;
|
||||
|
||||
/** @type {!UI.ActionRegistration.Action}*/
|
||||
this._toggleRecordAction =
|
||||
/** @type {!UI.ActionRegistration.Action}*/ (
|
||||
UI.ActionRegistry.ActionRegistry.instance().action('input.toggle-recording'));
|
||||
/** @type {!UI.ActionRegistration.Action}*/
|
||||
UI.ActionRegistry.ActionRegistry.instance().action('input.toggle-recording') as UI.ActionRegistration.Action;
|
||||
this._startReplayAction =
|
||||
/** @type {!UI.ActionRegistration.Action}*/ (
|
||||
UI.ActionRegistry.ActionRegistry.instance().action('input.start-replaying'));
|
||||
/** @type {!UI.ActionRegistration.Action}*/
|
||||
UI.ActionRegistry.ActionRegistry.instance().action('input.start-replaying') as UI.ActionRegistration.Action;
|
||||
this._togglePauseAction =
|
||||
/** @type {!UI.ActionRegistration.Action}*/ (
|
||||
UI.ActionRegistry.ActionRegistry.instance().action('input.toggle-pause'));
|
||||
UI.ActionRegistry.ActionRegistry.instance().action('input.toggle-pause') as UI.ActionRegistration.Action;
|
||||
|
||||
const toolbarContainer = this.contentElement.createChild('div', 'input-timeline-toolbar-container');
|
||||
this._panelToolbar = new UI.Toolbar.Toolbar('input-timeline-toolbar', toolbarContainer);
|
||||
@@ -80,7 +81,7 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
this._loadButton = new UI.Toolbar.ToolbarButton(i18nString(UIStrings.loadProfile), 'largeicon-load');
|
||||
this._loadButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, () => this._selectFileToLoad());
|
||||
this._saveButton = new UI.Toolbar.ToolbarButton(i18nString(UIStrings.saveProfile), 'largeicon-download');
|
||||
this._saveButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, event => {
|
||||
this._saveButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, _event => {
|
||||
this._saveToFile();
|
||||
});
|
||||
this._panelToolbar.appendSeparator();
|
||||
@@ -92,10 +93,7 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
this._updateControls();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{forceNew: ?boolean}} opts
|
||||
*/
|
||||
static instance(opts = {forceNew: null}) {
|
||||
static instance(opts: {forceNew: boolean} = {forceNew: false}): InputTimeline {
|
||||
const {forceNew} = opts;
|
||||
if (!inputTimelineInstance || forceNew) {
|
||||
inputTimelineInstance = new InputTimeline();
|
||||
@@ -104,14 +102,14 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
return inputTimelineInstance;
|
||||
}
|
||||
|
||||
_reset() {
|
||||
_reset(): void {
|
||||
this._tracingClient = null;
|
||||
this._tracingModel = null;
|
||||
this._inputModel = null;
|
||||
this._setState(State.Idle);
|
||||
}
|
||||
|
||||
_createFileSelector() {
|
||||
_createFileSelector(): void {
|
||||
if (this._fileSelectorElement) {
|
||||
this._fileSelectorElement.remove();
|
||||
}
|
||||
@@ -119,34 +117,22 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
this.element.appendChild(this._fileSelectorElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
wasShown() {
|
||||
wasShown(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
willHide() {
|
||||
willHide(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!State} state
|
||||
*/
|
||||
_setState(state) {
|
||||
_setState(state: State): void {
|
||||
this._state = state;
|
||||
this._updateControls();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
_isAvailableState() {
|
||||
_isAvailableState(): boolean {
|
||||
return this._state === State.Idle || this._state === State.ReplayPaused;
|
||||
}
|
||||
|
||||
_updateControls() {
|
||||
_updateControls(): void {
|
||||
this._toggleRecordAction.setToggled(this._state === State.Recording);
|
||||
this._toggleRecordAction.setEnabled(this._isAvailableState() || this._state === State.Recording);
|
||||
this._startReplayAction.setEnabled(this._isAvailableState() && Boolean(this._tracingModel));
|
||||
@@ -157,7 +143,7 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
this._saveButton.setEnabled(this._isAvailableState() && Boolean(this._tracingModel));
|
||||
}
|
||||
|
||||
_toggleRecording() {
|
||||
_toggleRecording(): void {
|
||||
switch (this._state) {
|
||||
case State.Recording: {
|
||||
this._stopRecording();
|
||||
@@ -170,11 +156,11 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
}
|
||||
}
|
||||
|
||||
_startReplay() {
|
||||
_startReplay(): void {
|
||||
this._replayEvents();
|
||||
}
|
||||
|
||||
_toggleReplayPause() {
|
||||
_toggleReplayPause(): void {
|
||||
switch (this._state) {
|
||||
case State.Replaying: {
|
||||
this._pauseReplay();
|
||||
@@ -190,7 +176,7 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
/**
|
||||
* Saves all current events in a file (JSON format).
|
||||
*/
|
||||
async _saveToFile() {
|
||||
async _saveToFile(): Promise<void> {
|
||||
console.assert(this._state === State.Idle);
|
||||
if (!this._tracingModel) {
|
||||
return;
|
||||
@@ -204,23 +190,18 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
return;
|
||||
}
|
||||
|
||||
const backingStorage =
|
||||
/** @type {!Bindings.TempFile.TempFileBackingStorage} */ (this._tracingModel.backingStorage());
|
||||
const backingStorage = this._tracingModel.backingStorage() as Bindings.TempFile.TempFileBackingStorage;
|
||||
await backingStorage.writeToStream(stream);
|
||||
stream.close();
|
||||
}
|
||||
|
||||
|
||||
_selectFileToLoad() {
|
||||
_selectFileToLoad(): void {
|
||||
if (this._fileSelectorElement) {
|
||||
this._fileSelectorElement.click();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!File} file
|
||||
*/
|
||||
_loadFromFile(file) {
|
||||
_loadFromFile(file: File): void {
|
||||
console.assert(this._isAvailableState());
|
||||
|
||||
this._setState(State.Loading);
|
||||
@@ -229,11 +210,10 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
this._createFileSelector();
|
||||
}
|
||||
|
||||
async _startRecording() {
|
||||
async _startRecording(): Promise<void> {
|
||||
this._setState(State.StartPending);
|
||||
|
||||
this._tracingClient = new TracingClient(
|
||||
/** @type {!SDK.SDKModel.Target} */ (SDK.SDKModel.TargetManager.instance().mainTarget()), this);
|
||||
this._tracingClient =
|
||||
new TracingClient(SDK.SDKModel.TargetManager.instance().mainTarget() as SDK.SDKModel.Target, this);
|
||||
|
||||
const response = await this._tracingClient.startRecording();
|
||||
// @ts-ignore crbug.com/1011811 Fix tracing manager type once Closure is gone
|
||||
@@ -244,7 +224,7 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
}
|
||||
}
|
||||
|
||||
async _stopRecording() {
|
||||
async _stopRecording(): Promise<void> {
|
||||
if (!this._tracingClient) {
|
||||
return;
|
||||
}
|
||||
@@ -253,7 +233,7 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
this._tracingClient = null;
|
||||
}
|
||||
|
||||
async _replayEvents() {
|
||||
async _replayEvents(): Promise<void> {
|
||||
if (!this._inputModel) {
|
||||
return;
|
||||
}
|
||||
@@ -261,7 +241,7 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
await this._inputModel.startReplay(this.replayStopped.bind(this));
|
||||
}
|
||||
|
||||
_pauseReplay() {
|
||||
_pauseReplay(): void {
|
||||
if (!this._inputModel) {
|
||||
return;
|
||||
}
|
||||
@@ -269,7 +249,7 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
this._setState(State.ReplayPaused);
|
||||
}
|
||||
|
||||
_resumeReplay() {
|
||||
_resumeReplay(): void {
|
||||
if (!this._inputModel) {
|
||||
return;
|
||||
}
|
||||
@@ -277,92 +257,60 @@ export class InputTimeline extends UI.Widget.VBox {
|
||||
this._setState(State.Replaying);
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
loadingStarted() {
|
||||
loadingStarted(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {number=} progress
|
||||
*/
|
||||
loadingProgress(progress) {
|
||||
loadingProgress(_progress?: number): void {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
processingStarted() {
|
||||
processingStarted(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {?SDK.TracingModel.TracingModel} tracingModel
|
||||
*/
|
||||
loadingComplete(tracingModel) {
|
||||
loadingComplete(tracingModel: SDK.TracingModel.TracingModel|null): void {
|
||||
if (!tracingModel) {
|
||||
this._reset();
|
||||
return;
|
||||
}
|
||||
this._inputModel =
|
||||
new InputModel(/** @type {!SDK.SDKModel.Target} */ (SDK.SDKModel.TargetManager.instance().mainTarget()));
|
||||
this._inputModel = new InputModel(SDK.SDKModel.TargetManager.instance().mainTarget() as SDK.SDKModel.Target);
|
||||
this._tracingModel = tracingModel;
|
||||
this._inputModel.setEvents(tracingModel);
|
||||
|
||||
this._setState(State.Idle);
|
||||
}
|
||||
|
||||
_recordingFailed() {
|
||||
_recordingFailed(): void {
|
||||
this._tracingClient = null;
|
||||
this._setState(State.Idle);
|
||||
}
|
||||
|
||||
replayStopped() {
|
||||
replayStopped(): void {
|
||||
this._setState(State.Idle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @enum {symbol}
|
||||
*/
|
||||
export const State = {
|
||||
Idle: Symbol('Idle'),
|
||||
StartPending: Symbol('StartPending'),
|
||||
Recording: Symbol('Recording'),
|
||||
StopPending: Symbol('StopPending'),
|
||||
Replaying: Symbol('Replaying'),
|
||||
ReplayPaused: Symbol('ReplayPaused'),
|
||||
Loading: Symbol('Loading')
|
||||
};
|
||||
export const enum State {
|
||||
Idle = 'Idle',
|
||||
StartPending = 'StartPending',
|
||||
Recording = 'Recording',
|
||||
StopPending = 'StopPending',
|
||||
Replaying = 'Replaying',
|
||||
ReplayPaused = 'ReplayPaused',
|
||||
Loading = 'Loading'
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @implements {UI.ActionRegistration.ActionDelegate}
|
||||
*/
|
||||
export class ActionDelegate {
|
||||
/**
|
||||
* @override
|
||||
* @param {!UI.Context.Context} context
|
||||
* @param {string} actionId
|
||||
* @return {boolean}
|
||||
*/
|
||||
handleAction(context, actionId) {
|
||||
export class ActionDelegate implements UI.ActionRegistration.ActionDelegate {
|
||||
handleAction(context: UI.Context.Context, actionId: string): boolean {
|
||||
const inputViewId = 'Inputs';
|
||||
UI.ViewManager.ViewManager.instance()
|
||||
.showView(inputViewId)
|
||||
.then(() => /** @type {!UI.View.View} */ (UI.ViewManager.ViewManager.instance().view(inputViewId)).widget())
|
||||
.then(widget => this._innerHandleAction(/** @type {!InputTimeline} */ (widget), actionId));
|
||||
.then(() => (UI.ViewManager.ViewManager.instance().view(inputViewId) as UI.View.View).widget())
|
||||
.then(widget => this._innerHandleAction(widget as InputTimeline, actionId));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!InputTimeline} inputTimeline
|
||||
* @param {string} actionId
|
||||
*/
|
||||
_innerHandleAction(inputTimeline, actionId) {
|
||||
_innerHandleAction(inputTimeline: InputTimeline, actionId: string): void {
|
||||
switch (actionId) {
|
||||
case 'input.toggle-recording':
|
||||
inputTimeline._toggleRecording();
|
||||
@@ -379,15 +327,13 @@ export class ActionDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @implements {SDK.TracingManager.TracingManagerClient}
|
||||
*/
|
||||
export class TracingClient {
|
||||
/**
|
||||
* @param {!SDK.SDKModel.Target} target
|
||||
* @param {!InputTimeline} client
|
||||
*/
|
||||
constructor(target, client) {
|
||||
export class TracingClient implements SDK.TracingManager.TracingManagerClient {
|
||||
_target: SDK.SDKModel.Target;
|
||||
_tracingManager: SDK.TracingManager.TracingManager|null;
|
||||
_client: InputTimeline;
|
||||
_tracingModel: SDK.TracingModel.TracingModel;
|
||||
_tracingCompleteCallback: (() => void)|null;
|
||||
constructor(target: SDK.SDKModel.Target, client: InputTimeline) {
|
||||
this._target = target;
|
||||
this._tracingManager = target.model(SDK.TracingManager.TracingManager);
|
||||
this._client = client;
|
||||
@@ -395,14 +341,10 @@ export class TracingClient {
|
||||
const backingStorage = new Bindings.TempFile.TempFileBackingStorage();
|
||||
this._tracingModel = new SDK.TracingModel.TracingModel(backingStorage);
|
||||
|
||||
/** @type {?function():void} */
|
||||
this._tracingCompleteCallback = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Promise<!Object>}
|
||||
*/
|
||||
async startRecording() {
|
||||
async startRecording(): Promise<Object> {
|
||||
if (!this._tracingManager) {
|
||||
return {};
|
||||
}
|
||||
@@ -418,7 +360,7 @@ export class TracingClient {
|
||||
return response;
|
||||
}
|
||||
|
||||
async stopRecording() {
|
||||
async stopRecording(): Promise<void> {
|
||||
if (this._tracingManager) {
|
||||
this._tracingManager.stop();
|
||||
}
|
||||
@@ -428,43 +370,24 @@ export class TracingClient {
|
||||
this._tracingModel.tracingComplete();
|
||||
this._client.loadingComplete(this._tracingModel);
|
||||
}
|
||||
/**
|
||||
* @param {!Array.<!SDK.TracingManager.EventPayload>} events
|
||||
* @override
|
||||
*/
|
||||
traceEventsCollected(events) {
|
||||
traceEventsCollected(events: SDK.TracingManager.EventPayload[]): void {
|
||||
this._tracingModel.addEvents(events);
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
tracingComplete() {
|
||||
tracingComplete(): void {
|
||||
if (this._tracingCompleteCallback) {
|
||||
this._tracingCompleteCallback();
|
||||
}
|
||||
this._tracingCompleteCallback = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} usage
|
||||
* @override
|
||||
*/
|
||||
tracingBufferUsage(usage) {
|
||||
tracingBufferUsage(_usage: number): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} progress
|
||||
* @override
|
||||
*/
|
||||
eventsRetrievalProgress(progress) {
|
||||
eventsRetrievalProgress(_progress: number): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} awaitTracingCompleteCallback - Whether to wait for the _tracingCompleteCallback to happen
|
||||
* @return {!Promise<void>}
|
||||
*/
|
||||
_waitForTracingToStop(awaitTracingCompleteCallback) {
|
||||
_waitForTracingToStop(awaitTracingCompleteCallback: boolean): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
if (this._tracingManager && awaitTracingCompleteCallback) {
|
||||
this._tracingCompleteCallback = resolve;
|
||||
@@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
/* eslint-disable rulesdir/no_underscored_properties */
|
||||
|
||||
import * as i18n from '../i18n/i18n.js';
|
||||
export const UIStrings = {
|
||||
/**
|
||||
@@ -29,4 +31,4 @@ export const UIStrings = {
|
||||
*/
|
||||
resume: 'Resume',
|
||||
};
|
||||
i18n.i18n.registerUIStrings('input/ModuleUIStrings.js', UIStrings);
|
||||
i18n.i18n.registerUIStrings('input/ModuleUIStrings.ts', UIStrings);
|
||||
Reference in New Issue
Block a user