Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Input module implementation #784

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 63 additions & 6 deletions src/bidiMapper/domains/context/browsingContextProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ 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 {InputState} from '../input/InputState.js';

import {
BidiPreloadScript,
Expand All @@ -46,6 +50,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 +432,67 @@ 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 = this.#getActionsByTick(params, inputState);
const dispatcher = new ActionDispatcher(inputState, context);
await dispatcher.dispatchActions(actionsByTick);
return {result: {}};
}

#getActionsByTick(
params: Input.PerformActionsParameters,
inputState: InputState
): ActionOption[][] {
const actionsByTick: ActionOption[][] = [];
for (const action of params.actions) {
jrandolf-2 marked this conversation as resolved.
Show resolved Hide resolved
switch (action.type) {
case Input.SourceActionsType.Pointer: {
action.parameters ??= {pointerType: Input.PointerType.Mouse};
action.parameters.pointerType ??= Input.PointerType.Mouse;
OrKoN marked this conversation as resolved.
Show resolved Hide resolved

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 = action.actions.map((item) => ({
id: action.id,
action: item,
}));
for (let i = 0; i < actions.length; i++) {
if (actionsByTick.length === i) {
actionsByTick.push([]);
}
actionsByTick[i]!.push(actions[i]!);
}
}
return actionsByTick;
}
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