Skip to content

Commit

Permalink
Initial Input module implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf-2 committed May 26, 2023
1 parent 3871396 commit 480ffc5
Show file tree
Hide file tree
Showing 12 changed files with 2,282 additions and 6 deletions.
65 changes: 59 additions & 6 deletions src/bidiMapper/domains/context/browsingContextProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {CdpClient, CdpConnection} from '../../CdpConnection.js';
import {IEventManager} from '../events/EventManager.js';
import {Realm} from '../script/realm.js';
import {RealmStorage} from '../script/realmStorage.js';
import {ActionOption} from '../input/ActionOption.js';
import {InputStateManager} from '../input/InputStateManager.js';
import {ActionDispatcher} from '../input/ActionDispatcher.js';

import {
BidiPreloadScript,
Expand All @@ -46,6 +49,7 @@ export class BrowsingContextProcessor {
readonly #realmStorage: RealmStorage;
readonly #selfTargetId: string;
readonly #preloadScriptStorage: PreloadScriptStorage;
readonly #inputStateManager = new InputStateManager();

constructor(
realmStorage: RealmStorage,
Expand Down Expand Up @@ -427,15 +431,64 @@ export class BrowsingContextProcessor {
return {result: {}};
}

process_input_performActions(
_params: Input.PerformActionsParameters
async process_input_performActions(
params: Input.PerformActionsParameters
): Promise<Message.EmptyResult> {
throw new Message.UnsupportedOperationException('Not implemented yet.');
const context = this.#browsingContextStorage.getContext(params.context);
const inputState = this.#inputStateManager.get(context.top);

const actionsByTick: ActionOption[][] = [];
for (const action of params.actions) {
switch (action.type) {
case Input.SourceActionsType.Pointer: {
action.parameters ??= {pointerType: Input.PointerType.Mouse};
action.parameters.pointerType ??= Input.PointerType.Mouse;

const source = inputState.getOrCreate(
action.id,
Input.SourceActionsType.Pointer,
action.parameters.pointerType
);
if (source.subtype !== action.parameters.pointerType) {
throw new Message.InvalidArgumentException(
`Expected input source ${action.id} to be ${source.subtype}; got ${action.parameters.pointerType}.`
);
}
break;
}
default:
inputState.getOrCreate(action.id, action.type);
}
const actions: ActionOption[] = [];
for (const item of action.actions) {
actions.push({
id: action.id,
action: item,
});
}
for (let i = 0; i < actions.length; i++) {
if (actionsByTick.length === i) {
actionsByTick.push([]);
}
actionsByTick[i]!.push(actions[i]!);
}
}

const dispatcher = new ActionDispatcher(inputState, context);
await dispatcher.dispatchActions(actionsByTick);

return {result: {}};
}
process_input_releaseActions(
_params: Input.ReleaseActionsParameters
async process_input_releaseActions(
params: Input.ReleaseActionsParameters
): Promise<Message.EmptyResult> {
throw new Message.UnsupportedOperationException('Not implemented yet.');
const context = this.#browsingContextStorage.getContext(params.context);
const topContext = context.top;
const inputState = this.#inputStateManager.get(topContext);
const dispatcher = new ActionDispatcher(inputState, context);
await dispatcher.dispatchTickActions(inputState.cancelList.reverse());
this.#inputStateManager.delete(topContext);
return {result: {}};
}

async process_browsingContext_close(
Expand Down
Loading

0 comments on commit 480ffc5

Please sign in to comment.