Skip to content

Commit

Permalink
Update src/bidiMapper/domains/context/browsingContextProcessor.ts (#784)
Browse files Browse the repository at this point in the history
Co-authored-by: Maksim Sadym <[email protected]>
  • Loading branch information
jrandolf-2 and sadym-chromium authored May 26, 2023
1 parent bfab7b9 commit 1fa10ea
Show file tree
Hide file tree
Showing 20 changed files with 2,462 additions and 7 deletions.
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) {
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 = 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

0 comments on commit 1fa10ea

Please sign in to comment.