From 751867e77af05d1760ed3cf725b65112a95c90aa Mon Sep 17 00:00:00 2001 From: Alexandra Borovova Date: Tue, 11 Feb 2025 15:17:58 +0100 Subject: [PATCH 1/3] Add support for "userContexts" argument to "browsingContext.setViewport" command. --- index.bs | 171 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 131 insertions(+), 40 deletions(-) diff --git a/index.bs b/index.bs index 014e8de8..31d37230 100644 --- a/index.bs +++ b/index.bs @@ -2966,6 +2966,13 @@ between [=navigables=] and device pixel ratio overrides. It is initially empty. Note: this map is not cleared when the final session ends i.e. device pixel ratio overrides outlive any WebDriver session. +A [=remote end=] has a viewport overrides map which is a weak map +between [=user contexts=] and [=structs=], with an [=struct/item=] named viewport +and an [=struct/item=] named devicePixelRatio, which is a float or null. +An [=struct/item=] viewport is a [=struct=] or null, with an [=struct/item=] +named height, which is an integer, and an [=struct/item=] named width, +which is an integer. + ### Types ### {#module-browsingcontext-types} #### The browsingContext.BrowsingContext Type #### {#type-browsingContext-Browsingcontext} @@ -4629,9 +4636,10 @@ The browsingContext.setViewport command modifies ) browsingContext.SetViewportParameters = { - context: browsingContext.BrowsingContext, + ? context: browsingContext.BrowsingContext, ? viewport: browsingContext.Viewport / null, ? devicePixelRatio: (float .gt 0.0) / null, + ? userContexts: [+browser.UserContext], } browsingContext.Viewport = { @@ -4648,71 +4656,154 @@ The browsingContext.setViewport command modifies +
+To set device pixel ratio override given |navigable| and |device pixel ratio|: + +1. Let |navigable| be the [=/navigable=] whose [=navigable/active document=] is + |navigable|'s [=navigable/active document=]. + +1. If |device pixel ratio| is not null: + + 1. When the [=select an image source from a source set=] are run, act as if + the implementation's pixel density was set to |device pixel ratio| when selecting an image. + + 1. For the purposes of the [=resolution media feature=], act as if + the implementation's resolution is |device pixel ratio| dppx scaled by the page zoom. + + 1. [=map/Set=] [=device pixel ratio overrides=][|navigable|] to |device pixel ratio|. + + Note: This will take an effect because of the patch of [[#patchs-determine-the-device-pixel-ratio]]. + +1. Otherwise: + + 1. When the [=select an image source from a source set=] steps are run, use the implementation's default behavior, + without any changes made by previous invocations of these steps. + + 1. For the purposes of the [=resolution media feature=], use the implementation's default behavior, + without any changes made by previous invocations of these steps. + + 1. [=map/Remove=] |navigable| from [=device pixel ratio overrides=]. + +1. Run [=evaluate media queries and report changes=] for [=/document=] currently loaded + in a specified |navigable|. + +
+ + +
+To set viewport given |navigable| and |viewport|: + +1. If |viewport| is not null, set the width of |navigable|'s [=layout + viewport=] to be the width of |viewport| in CSS pixels and + set the height of the |navigable|'s [=layout viewport=] to be the + height of |viewport| in CSS pixels. + +1. Otherwise, set the |navigable|'s [=layout viewport=] to the + implementation-defined default. + +
+ +
+ +When the [=set up a window environment settings object=] +algorithm is invoked, immediately prior to returning the settings +object: + +1. Let |environment settings| be the newly created [=environment settings + object=]. + +1. Let |related navigables| be the result of [=get related navigables=] given |environment settings|. + +1. For each |navigable| of |related navigables|: + + 1. If |navigable| is not a [=/top-level traversable=], continue. + + 1. Let |user context| be |navigable|'s [=associated user context=]. + + 1. If [=viewport overrides map=] [=map/contains=] |user context|: + + 1. If |viewport overrides map|[|user context|] [=map/contains=] the viewport field: + + 1. [=Set viewport=] with |navigable| and |viewport overrides map|[|user context|]["viewport"]. + + 1. If |viewport overrides map|[|user context|] [=map/contains=] the devicePixelRatio field: + + 1. For the |navigable| and all [=descendant navigables=]: + + 1. [=Set device pixel ratio override=] with |navigable| and |viewport overrides map|[|user context|]["devicePixelRatio""]. +
The [=remote end steps=] with |command parameters| are: -1. Let |navigable id| be the value of the context field of |command - parameters|. +1. If |command parameters| [=map/contains=] "userContexts" + and |command parameters| [=map/contains=] "context", + return [=error=] with [=error code=] [=invalid argument=]. -1. Let |navigable| be the result of [=trying=] to [=get a navigable=] with - |navigable id|. +1. Let |navigables| be a [=/set=]. -1. If |navigable| is not a [=/top-level traversable=], return [=error=] with - [=error code=] [=invalid argument=]. +1. If the context field of |command parameters| is present: -1. If the implementation is unable to adjust the |navigable|'s [=layout viewport=] - parameters with the given |command parameters| for any reason, return - [=error=] with [=error code=] [=unsupported operation=]. + 1. Let |navigable id| be the value of the context field of |command + parameters|. -1. If |command parameters| [=map/contains=] the viewport field: + 1. Let |navigable| be the result of [=trying=] to [=get a navigable=] with + |navigable id|. - 1. Let |viewport| be the |command parameters|["viewport"]. + 1. If |navigable| is not a [=/top-level traversable=], return [=error=] with + [=error code=] [=invalid argument=]. - 1. If |viewport| is not null, set the width of |navigable|'s [=layout - viewport=] to be the width of |viewport| in CSS pixels and - set the height of the |navigable|'s [=layout viewport=] to be the - height of |viewport| in CSS pixels. + 1. If the implementation is unable to adjust the |navigable|'s [=layout viewport=] + parameters with the given |command parameters| for any reason, return + [=error=] with [=error code=] [=unsupported operation=]. - 1. Otherwise, set the |navigable|'s [=layout viewport=] to the - implementation-defined default. + 1. [=set/Append=] |navigable| to |navigables|. -1. Run the [[cssom-view-1#resizing-viewports]] steps. +1. Otherwise, if the userContexts field of |command parameters| is present: -1. If |command parameters| [=map/contains=] the devicePixelRatio field: + 1. For each |user context id| of |command parameters|["userContexts"]: - 1. Let |device pixel ratio| be the |command - parameters|["devicePixelRatio"]. + 1. Set |user context| to [=get user context=] with |user context id|. - 1. For the |navigable| and all [=descendant navigables=]: + 1. If |user context| is null, return [=error=] with [=error code=] [=no such user context=]. - 1. Let |navigable| be the [=/navigable=] whose [=navigable/active document=] is - |navigable|'s [=navigable/active document=]. + 1. [=map/Set=] [=viewport overrides map=][|user context|] to a new [=/map=]. - 1. If |device pixel ratio| is not null: + 1. If |command parameters| [=map/contains=] the viewport field: - 1. When the [=select an image source from a source set=] are run, act as if - the implementation's pixel density was set to |device pixel ratio| when selecting an image. + 1. Set |viewport overrides map|[|user context|]["viewport"] + to |command parameters|["viewport"]. - 1. For the purposes of the [=resolution media feature=], act as if - the implementation's resolution is |device pixel ratio| dppx scaled by the page zoom. + 1. If |command parameters| [=map/contains=] the devicePixelRatio field: - 1. [=map/Set=] [=device pixel ratio overrides=][|navigable|] to |device pixel ratio|. + 1. Set |viewport overrides map|[|user context|]["devicePixelRatio"] + to |command parameters|["devicePixelRatio"]. - Note: This will take an effect because of the patch of [[#patchs-determine-the-device-pixel-ratio]]. + 1. [=list/For each=] |top-level traversable| in the list of all [=/top-level traversables=] + whose [=associated user context=] is |user context|: - 1. Otherwise: + 1. [=list/Append=] |top-level traversable| to |navigables|. + +1. If |command parameters| [=map/contains=] the viewport field: + + 1. Let |viewport| be the |command parameters|["viewport"]. - 1. When the [=select an image source from a source set=] steps are run, use the implementation's default behavior, - without any changes made by previous invocations of these steps. + 1. For each |navigable| of |navigables|: + + 1. [=Set viewport=] with |navigable| and |viewport|. + +1. Run the [[cssom-view-1#resizing-viewports]] steps. + +1. If |command parameters| [=map/contains=] the devicePixelRatio field: + + 1. Let |device pixel ratio| be the |command + parameters|["devicePixelRatio"]. - 1. For the purposes of the [=resolution media feature=], use the implementation's default behavior, - without any changes made by previous invocations of these steps. + 1. For each |navigable| of |navigables|: - 1. [=map/Remove=] |navigable| from [=device pixel ratio overrides=]. + 1. For the |navigable| and all [=descendant navigables=]: - 1. Run [=evaluate media queries and report changes=] for [=/document=] currently loaded - in a specified |navigable|. + 1. [=Set device pixel ratio override=] with |navigable| and |device pixel ratio|. 1. Return [=success=] with data null. From 404847d98b859923bd2d1ad92e7a51e7833e68f2 Mon Sep 17 00:00:00 2001 From: Alexandra Borovova Date: Mon, 17 Feb 2025 18:37:03 +0100 Subject: [PATCH 2/3] Address review feedback --- index.bs | 57 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/index.bs b/index.bs index 31d37230..d1fa8793 100644 --- a/index.bs +++ b/index.bs @@ -2966,12 +2966,15 @@ between [=navigables=] and device pixel ratio overrides. It is initially empty. Note: this map is not cleared when the final session ends i.e. device pixel ratio overrides outlive any WebDriver session. -A [=remote end=] has a viewport overrides map which is a weak map -between [=user contexts=] and [=structs=], with an [=struct/item=] named viewport -and an [=struct/item=] named devicePixelRatio, which is a float or null. -An [=struct/item=] viewport is a [=struct=] or null, with an [=struct/item=] -named height, which is an integer, and an [=struct/item=] named width, -which is an integer. +A viewport dimensions is a [=struct=] with an [=struct/item=] named +height which is an integer and +a [=struct/item=] named width which is an integer. + +A viewport configuration is a [=struct=] with an [=struct/item=] named +viewport which is a [=viewport-configuration/viewport dimensions=] +or null and an [=struct/item=] named devicePixelRatio which is a float or null. + +A [=remote end=] has a viewport overrides map which is a weak map between [=user contexts=] and [=viewport configuration=]. ### Types ### {#module-browsingcontext-types} @@ -4705,37 +4708,33 @@ To set viewport given |navigable| and |viewport|:
-When the [=set up a window environment settings object=] -algorithm is invoked, immediately prior to returning the settings -object: - -1. Let |environment settings| be the newly created [=environment settings - object=]. - -1. Let |related navigables| be the result of [=get related navigables=] given |environment settings|. - -1. For each |navigable| of |related navigables|: +After creating a document in a new [=navigable/top-level traversable=] |navigable| and +before the [=run WebDriver BiDi preload scripts=] algorithm is invoked: - 1. If |navigable| is not a [=/top-level traversable=], continue. +1. Let |user context| be |navigable|'s [=associated user context=]. - 1. Let |user context| be |navigable|'s [=associated user context=]. +1. If [=viewport overrides map=] [=map/contains=] |user context|: - 1. If [=viewport overrides map=] [=map/contains=] |user context|: + 1. If |viewport overrides map|[|user context|] [=map/contains=] the viewport field: - 1. If |viewport overrides map|[|user context|] [=map/contains=] the viewport field: + 1. [=Set viewport=] with |navigable| and |viewport overrides map|[|user context|]["viewport"]. - 1. [=Set viewport=] with |navigable| and |viewport overrides map|[|user context|]["viewport"]. + 1. If |viewport overrides map|[|user context|] [=map/contains=] the devicePixelRatio field: - 1. If |viewport overrides map|[|user context|] [=map/contains=] the devicePixelRatio field: + 1. For the |navigable| and all [=descendant navigables=]: - 1. For the |navigable| and all [=descendant navigables=]: + 1. [=Set device pixel ratio override=] with |navigable| and |viewport overrides map|[|user context|]["devicePixelRatio""]. - 1. [=Set device pixel ratio override=] with |navigable| and |viewport overrides map|[|user context|]["devicePixelRatio""]. +
The [=remote end steps=] with |command parameters| are: +1. If the implementation is unable to adjust the [=layout viewport=] + parameters with the given |command parameters| for any reason, return + [=error=] with [=error code=] [=unsupported operation=]. + 1. If |command parameters| [=map/contains=] "userContexts" and |command parameters| [=map/contains=] "context", return [=error=] with [=error code=] [=invalid argument=]. @@ -4753,20 +4752,22 @@ The [=remote end steps=] with |command parameters| are: 1. If |navigable| is not a [=/top-level traversable=], return [=error=] with [=error code=] [=invalid argument=]. - 1. If the implementation is unable to adjust the |navigable|'s [=layout viewport=] - parameters with the given |command parameters| for any reason, return - [=error=] with [=error code=] [=unsupported operation=]. - 1. [=set/Append=] |navigable| to |navigables|. 1. Otherwise, if the userContexts field of |command parameters| is present: + 1. Let |user contexts| be a [=/set=]. + 1. For each |user context id| of |command parameters|["userContexts"]: 1. Set |user context| to [=get user context=] with |user context id|. 1. If |user context| is null, return [=error=] with [=error code=] [=no such user context=]. + 1. [=set/Append=] |user context| to |user contexts|. + + 1. For each |user context| of |user contexts|: + 1. [=map/Set=] [=viewport overrides map=][|user context|] to a new [=/map=]. 1. If |command parameters| [=map/contains=] the viewport field: From d11c34ab17947648ce3a0f0ce8fb37655fa16207 Mon Sep 17 00:00:00 2001 From: Alexandra Borovova Date: Wed, 19 Feb 2025 11:05:17 +0100 Subject: [PATCH 3/3] Address review feedback --- index.bs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index d1fa8793..fa966214 100644 --- a/index.bs +++ b/index.bs @@ -4667,7 +4667,7 @@ To set device pixel ratio override given |navigable| and |device pixe 1. If |device pixel ratio| is not null: - 1. When the [=select an image source from a source set=] are run, act as if + 1. When the [=select an image source from a source set=] steps are run, act as if the implementation's pixel density was set to |device pixel ratio| when selecting an image. 1. For the purposes of the [=resolution media feature=], act as if @@ -4785,6 +4785,8 @@ The [=remote end steps=] with |command parameters| are: 1. [=list/Append=] |top-level traversable| to |navigables|. +1. Otherwise, return [=error=] with [=error code=] [=invalid argument=]. + 1. If |command parameters| [=map/contains=] the viewport field: 1. Let |viewport| be the |command parameters|["viewport"]. @@ -4793,7 +4795,7 @@ The [=remote end steps=] with |command parameters| are: 1. [=Set viewport=] with |navigable| and |viewport|. -1. Run the [[cssom-view-1#resizing-viewports]] steps. + 1. Run the [[cssom-view-1#resizing-viewports]] steps with |navigable|'s [=active document=]. 1. If |command parameters| [=map/contains=] the devicePixelRatio field: