Skip to content

Commit

Permalink
Add input.SetFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf-2 committed Oct 10, 2023
1 parent 3bd59bb commit 241213b
Showing 1 changed file with 106 additions and 1 deletion.
107 changes: 106 additions & 1 deletion index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ spec: HTML; urlPrefix: https://html.spec.whatwg.org/multipage/
text: handled; url: webappapis.html#concept-error-handled
text: hidden; url: document-sequences.html#system-visibility-state
text: history handling behavior; url: browsing-the-web.html#history-handling-behavior
text: input type; url: input.html#dom-input-type
text: navigables; url: document-sequences.html#navigables
text: navigation id; url: browsing-the-web.html#navigation-id
text: origin-clean; url: canvas.html#concept-canvas-origin-clean
Expand All @@ -186,13 +187,16 @@ spec: HTML; urlPrefix: https://html.spec.whatwg.org/multipage/
text: report an error; url: webappapis.html#report-the-error
text: run the animation frame callbacks; url: imagebitmap-and-animations.html#run-the-animation-frame-callbacks
text: same origin domain; url: browsers.html#same-origin-domain
text: selected files; url: input.html#concept-input-type-file-selected
text: session history; url: history.html#session-history
text: set up a window environment settings object; url: window-object.html#set-up-a-window-environment-settings-object
text: set up a worker environment settings object; url: workers.html#set-up-a-worker-environment-settings-object
text: set up a worklet environment settings object; url: worklets.html#set-up-a-worklet-environment-settings-object
text: shared worker; url: workers.html#shared-workers
text: show the picker; url: input.html#show-the-picker,-if-applicable
text: system visibility state; url: document-sequences.html#system-visibility-state
text: traversable navigable; url:document-sequences.html#traversable-navigable
text: update the file selection; url: input.html#update-the-file-selection
text: visible; url: document-sequences.html#system-visibility-state
text: window open steps; url: window-object.html#window-open-steps
text: worker event loop; url: webappapis.html#worker-event-loop-2
Expand Down Expand Up @@ -509,6 +513,9 @@ with the following additional codes:

<dt><dfn>unable to close browser</dfn>
<dd>Tried to close the browser, but failed to do so.

<dt><dfn>unable to set file input</dfn>
<dd>Tried to set a file input, but failed to do so.
</dl>

<pre class="cddl local-cddl">
Expand Down Expand Up @@ -8745,7 +8752,8 @@ simulated user input.

InputCommand = (
input.PerformActions //
input.ReleaseActions
input.ReleaseActions //
input.SetFiles
)
</pre>

Expand Down Expand Up @@ -9036,6 +9044,98 @@ The [=remote end steps=] given |session|, and |command parameters| are:

</div>

#### The input.setFiles Command #### {#command-input-setFiles}

The <dfn export for=commands>input.setFiles</dfn> command sets a given file
input with a given set of file paths.

<dl>
<dt>Command Type</dt>
<dd>
<pre class="cddl remote-cddl">
input.SetFiles = (
method: "input.setFiles",
params: input.SetFilesParameters
)

input.SetFilesParameters = {
context: browsingContext.BrowsingContext,
files: [*text]
? element: script.SharedReference,
}
</pre>
</dd>
<dt>Return Type</dt>
<dd>
<pre class="cddl">
EmptyResult
</pre>
</dd>
</dl>

<div algorithm="remote end steps for input.setFiles">

The [=remote end steps=] given |session|, and |command parameters| are:

1. Let |context id| be the value of the <code>context</code> field of
|command parameters|.

1. Let |context| be the result of [=trying=] to [=get a browsing context=]
with |context id|.

1. Let |document| be |context|'s [=active document=].

1. Let |environment settings| be the [=environment settings object=] whose
[=relevant global object=]'s <a>associated <code>Document</code></a> is
|document|.

1. Let |realm| be |environment settings|'s [=realm execution context=]'s
Realm component.

1. Let |reference| be the value of the <code>element</code> field of
|command parameters|.

1. If |reference| is not null,

1. Let |element| be the result of [=trying=] to [=deserialize remote
reference=] with |reference|, |realm|, and |session|.

1. If |element| doesn't implement {{HTMLInputElement}} return [=error=] with
[=error code=] [=unable to set file input=].

1. If the [=input type=] of |element| doesn't match <code>"file"</code>
return [=error=] with [=error code=] [=unable to set file input=].

1. [=trying|Try=] [=show the picker|showing the picker=] with |element|.

1. Let |file dialogs| be |context|'s [=set of file dialogs=].

1. Assert: |file dialogs| [=contains=] |element|.

1. [=set/Remove=] |element| from |file dialogs|.

1. Let |files| be the value of the <code>files</code> field of |command
parameters|.

1. Let |selected files| be |element|'s [=selected files=].

1. If the [=set/size=] of the [=set/intersection=] of |files| and |selected files| is
equal to the [=set/size=] of |files|:

1. [=Queue an element task=] on the [=user interaction task source=] given
element to fire an event named <code>cancel</code> at |element|, with the
<code>bubbles</code> attribute initialized to true.

1. Return [=success=] with data null.

1. Otherwise, [=update the file selection=] for |element| with |files| as the
user's selection.

1. Return [=success=] with data null.

</div>


### Events ### {#module-input-events}

#### The input.fileDialogOpened Event #### {#event-input-fileDialogOpened}
Expand All @@ -9057,13 +9157,18 @@ The [=remote end steps=] given |session|, and |command parameters| are:
</dd>
</dl>

Each [=/browsing context=] has an associated <dfn>set of file dialogs</dfn>,
which is an [=ordered set=] of [=Attr/element|elements=].

<div algorithm>

The [=remote end event trigger=] is the <dfn export>WebDriver BiDi file dialog
opened</dfn> steps given |element|.

1. Let |context| be the |element|'s [=node document=]'s [=/browsing context=].

1. [=set/Append=] |element| to |context|'s [=set of file dialogs=].

1. Let |context id| be the [=browsing context id=] for |context|.

1. Let |related browsing contexts| be a [=/set=] containing |context|.
Expand Down

0 comments on commit 241213b

Please sign in to comment.