Skip to content

Commit

Permalink
Add document screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Oct 6, 2023
1 parent d8df062 commit c09b525
Showing 1 changed file with 57 additions and 36 deletions.
93 changes: 57 additions & 36 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ spec: HTML; urlPrefix: https://html.spec.whatwg.org/multipage/
text: create a classic script; url: webappapis.html#creating-a-classic-script
text: create a new browsing context; url: browsers.html#creating-a-new-browsing-context
text: default classic script fetch options; url: webappapis.html#default-classic-script-fetch-options
text: default view; url: nav-history-apis.html#dom-document-defaultview
text: environment settings object's Realm; url: webappapis.html#environment-settings-object's-realm
text: focused area of the document; url: document-sequences.html#focused-area-of-the-document
text: handled; url: webappapis.html#concept-error-handled
Expand Down Expand Up @@ -211,8 +212,15 @@ spec: CSS-VALUES-3; urlPrefix: https://drafts.csswg.org/css-values-3/
text: absolute lengths; url: #absolute-lengths
spec: CSSOM-VIEW; urlPrefix: https://drafts.csswg.org/cssom-view/
type: dfn
text: visual viewport; url: #visual-viewport
text: layout viewport; url: #layout-viewport
text: scroll height; url: #dom-element-scrollheight
text: scroll width; url: #dom-element-scrollwidth
text: visual viewport page left; url: #dom-visualviewport-pageleft
text: visual viewport page top; url: #dom-visualviewport-pagetop
text: visual viewport; url: #visual-viewport
spec: DOM; urlPrefix: https://dom.spec.whatwg.org/
type: dfn
text: document element; url: #ref-for-dom-document-documentelement
</pre>

<pre class="biblio">
Expand Down Expand Up @@ -2222,6 +2230,7 @@ Base64-encoded string.

browsingContext.CaptureScreenshotParameters = {
context: browsingContext.BrowsingContext,
? origin: ("viewport" / "document") .default "viewport",
? format: browsingContext.ImageFormat,
? clip: browsingContext.ClipRectangle,
}
Expand All @@ -2243,7 +2252,7 @@ Base64-encoded string.
}

browsingContext.BoxClipRectangle = {
type: "viewport",
type: "box",
x: float,
y: float,
width: float,
Expand All @@ -2261,8 +2270,6 @@ Base64-encoded string.
</dd>
</dl>

TODO: Full page screenshots

<div algorithm>
To <dfn>normalize rect</dfn> given |rect|:

Expand Down Expand Up @@ -2331,26 +2338,16 @@ To <dfn>rectangle intersection</dfn> given |rect1| and |rect2|
</div>

<div algorithm>
To <dfn>render viewport to a canvas</dfn> given |viewport| and |rect|:

1. Assert: |rect| is normalized and represents a non-empty sub-region of |viewport|,
i.e. all the following hold:
* |rect|'s [=x coordinate=] is greater than or equal to 0.
* |rect|'s [=width dimension=] is greater than 0.
* |rect|'s [=y coordinate=] is greater than or equal to 0.
* |rect|'s [=height dimension=] is greater than 0.
* |rect|'s [=x coordinate=] plus |rect|'s [=width dimension=] is less than
or equal to |viewport|'s width.
* |rect|'s [=y coordinate=] plus |rect|'s [=height dimension=] is less than
or equal to |viewport|'s height.

1. Let |scale| be [=determine the device pixel ratio=] for the output device of |viewport|.

1. Let |paint width| be |rect|'s [=width dimension=] multiplied by |scale|,
To <dfn>render document to a canvas</dfn> given |document| and |rect|:

1. Let |ratio| be [=determine the device pixel ratio=] given |document|'s
[=default view=].

1. Let |paint width| be |rect|'s [=width dimension=] multiplied by |ratio|,
rounded to the nearest integer, so it matches the width of |rect| in device
pixels.

1. Let |paint height| be |rect|'s [=height dimension=] multiplied by |scale|,
1. Let |paint height| be |rect|'s [=height dimension=] multiplied by |ratio|,
rounded to the nearest integer, so it matches the height of |rect| in device
pixels.

Expand All @@ -2363,7 +2360,7 @@ To <dfn>render viewport to a canvas</dfn> given |viewport| and |rect|:
1. Set |canvas|'s [=context mode=] to [=2D=].

1. Complete implementation specific steps equivalent to drawing the region of
the framebuffer representing the region of |viewport| covered by |rect| to
the framebuffer representing the region of |document| covered by |rect| to
|context|, such that each pixel in the framebuffer corresponds to a pixel in
|context| with (|rect|'s [=x coordinate=], |rect|'s [=y coordinate=]) in
viewport coordinates corresponding to (0,0) in |context| and (|rect|'s
Expand Down Expand Up @@ -2392,31 +2389,55 @@ To <dfn>encode a canvas as Base64</dfn> given |canvas| and |format|:

</div>

The [=remote end steps=] with <var ignore>session</var> and |command parameters| are:
<div algorithm>
To <dfn>get the origin rectangle</dfn> given |document| and |origin|:

1. Let |context id| be |command parameters|["<code>context</code>"].
1. If |origin| is <code>"viewport"</code>:

1. Let |context| be the result of [=trying=] to [=get a browsing context=]
with |context id|.
1. Let |viewport| be |document|'s [=visual viewport=].

1. Let |viewport rect| be a {{DOMRectReadOnly}} with [=x coordinate=]
|viewport| [=visual viewport page left|page left=], [=y coordinate=]
|viewport| [=visual viewport page top|page top=], [=width dimension=]
|viewport| width, and [=height dimension=] |viewport| height.

1. Return [=success=] with data |viewport rect|.

1. Assert: |origin| is <code>"document"</code>.

1. Let |document element| be the [=document element=] for |document|.

1. Let |document rect| be a {{DOMRectReadOnly}} with [=x coordinate=] 0, [=y
coordinate=] 0, [=width dimension=] |document element| [=scroll height=],
and [=height dimension=] |document element| [=scroll width=].

1. Return [=success=] with data |document rect|.

</div>

The [=remote end steps=] with <var ignore>session</var> and |command parameters| are:

1. Let |context id| be the value of the <code>context</code> field of
|command parameters| if present, or null otherwise.

1. If the implementation is unable to capture a screenshot of |context| for any
reason then return [=error=] with [=error code=] [=unsupported operation=].

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

1. Let |viewport| be |document|'s [=visual viewport=].

1. Immediately after the next invocation of the [=run the animation frame
callbacks=] algorithm for |document|:

Issue: This ought to be integrated into the update rendering algorithm
in some more explicit way.
Issue: This ought to be integrated into the update rendering algorithm in
some more explicit way.

1. Let |origin| be the value of the <code>context</code> field of |command
parameters| if present, or "viewport" otherwise.

1. Let |viewport rect| be a {{DOMRectReadOnly}} with [=x coordinate=] 0, [=y
coordinate=] 0, [=width dimension=] |viewport| width, and [=height
dimension=] |viewport| height.
1. Let |origin rect| be the result of [=trying=] to [=get the origin rectangle=]
given |origin| and |document|.

1. Let |clip rect| be |viewport rect|.
1. Let |clip rect| be |origin rect|.

1. If |command parameters| contains "<code>clip</code>":

Expand Down Expand Up @@ -2457,12 +2478,12 @@ The [=remote end steps=] with <var ignore>session</var> and |command parameters|
and height |clip|["<code>height</code>"].
</dl>

1. Let |rect| be the [=rectangle intersection=] of |viewport rect| and |clip rect|.
1. Let |rect| be the [=rectangle intersection=] of |origin rect| and |clip rect|.

1. If |rect|'s [=width dimension=] is 0 or |rect|'s [=height dimension=] is 0,
return [=error=] with error code [=unable to capture screen=].

1. Let |canvas| be [=render viewport to a canvas=] with |viewport| and |rect|.
1. Let |canvas| be [=render document to a canvas=] with |document| and |rect|.

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

Expand Down

0 comments on commit c09b525

Please sign in to comment.