Skip to content

Commit

Permalink
Add contextlost/restored to GlobalEventHandlers and OffscreenCanvas
Browse files Browse the repository at this point in the history
`contextlost` and `contextrestored` IDL attributes
are supported by GlobalEventHandlers[0] and OffscreenCanvas[1]

This new spec addition is not implemented
yet in Safari[2] and Firefox[3] but they are positive for it.

[0] https://html.spec.whatwg.org/multipage/indices.html#event-contextlost
[1] https://html.spec.whatwg.org/multipage/canvas.html#offscreencanvas
[2] whatwg/html#4809 (comment)
[3] whatwg/html#4809 (comment)

[email protected], [email protected]

Bug: 1267688
Change-Id: Ie18ffb93dee884d2daa195187196c3c41a512378
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3268684
Commit-Queue: Yi Xu <[email protected]>
Reviewed-by: Mike West <[email protected]>
Reviewed-by: Yi Xu <[email protected]>
Reviewed-by: Mason Freed <[email protected]>
Cr-Commit-Position: refs/heads/main@{#944599}
NOKEYCHECK=True
GitOrigin-RevId: 23a021a678d689dc00f71f3de56e67b2d09032b7
  • Loading branch information
Sonia Singla authored and copybara-github committed Nov 23, 2021
1 parent dd6cf86 commit 0bc9ff7
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 705 deletions.
2 changes: 2 additions & 0 deletions blink/renderer/core/dom/global_event_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class GlobalEventHandlers {
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(click, kClick)
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(close, kClose)
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(contextmenu, kContextmenu)
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(contextlost, kContextlost)
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(contextrestored, kContextrestored)
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(cuechange, kCuechange)
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(dblclick, kDblclick)
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(drag, kDrag)
Expand Down
2 changes: 2 additions & 0 deletions blink/renderer/core/dom/global_event_handlers.idl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
attribute EventHandler onchange;
attribute EventHandler onclick;
attribute EventHandler onclose;
[RuntimeEnabled=NewCanvas2DAPI] attribute EventHandler oncontextlost;
attribute EventHandler oncontextmenu;
[RuntimeEnabled=NewCanvas2DAPI] attribute EventHandler oncontextrestored;
attribute EventHandler oncuechange;
attribute EventHandler ondblclick;
attribute EventHandler ondrag;
Expand Down
2 changes: 2 additions & 0 deletions blink/renderer/core/html/html_attribute_names.json5
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@
"onchange",
"onclick",
"onclose",
"oncontextlost",
"oncontextmenu",
"oncontextrestored",
"oncopy",
"oncuechange",
"oncut",
Expand Down
4 changes: 4 additions & 0 deletions blink/renderer/core/html/html_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,12 @@ AttributeTriggers* HTMLElement::TriggersForAttributeName(
nullptr},
{html_names::kOncloseAttr, kNoWebFeature, event_type_names::kClose,
nullptr},
{html_names::kOncontextlostAttr, kNoWebFeature,
event_type_names::kContextlost, nullptr},
{html_names::kOncontextmenuAttr, kNoWebFeature,
event_type_names::kContextmenu, nullptr},
{html_names::kOncontextrestoredAttr, kNoWebFeature,
event_type_names::kContextrestored, nullptr},
{html_names::kOncopyAttr, kNoWebFeature, event_type_names::kCopy,
nullptr},
{html_names::kOncuechangeAttr, kNoWebFeature,
Expand Down
3 changes: 3 additions & 0 deletions blink/renderer/core/offscreencanvas/offscreen_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class CORE_EXPORT OffscreenCanvas final
allow_high_performance_power_preference_ = true;
}

DEFINE_ATTRIBUTE_EVENT_LISTENER(contextlost, kContextlost)
DEFINE_ATTRIBUTE_EVENT_LISTENER(contextrestored, kContextrestored)

// CanvasRenderingContextHost implementation.
void PreFinalizeFrame() override {}
void PostFinalizeFrame() override {}
Expand Down
5 changes: 4 additions & 1 deletion blink/renderer/core/offscreencanvas/offscreen_canvas.idl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

[
Exposed=(Window,Worker),
Transferable
Transferable
] interface OffscreenCanvas : EventTarget {
[CallWith=ExecutionContext, MeasureAs=OffscreenCanvas] constructor([EnforceRange] unsigned long width, [EnforceRange] unsigned long height);
attribute [EnforceRange] unsigned long width;
attribute [EnforceRange] unsigned long height;

[CallWith=ScriptState, HighEntropy, MeasureAs=OffscreenCanvasTransferToImageBitmap, RaisesException] ImageBitmap transferToImageBitmap();
[CallWith=ScriptState, HighEntropy, MeasureAs=OffscreenCanvasConvertToBlob, RaisesException] Promise<Blob> convertToBlob(optional ImageEncodeOptions options = {});

[RuntimeEnabled=NewCanvas2DAPI] attribute EventHandler oncontextlost;
[RuntimeEnabled=NewCanvas2DAPI] attribute EventHandler oncontextrestored;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This is a testharness.js-based test.
Found 1459 tests; 1420 PASS, 39 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 1459 tests; 1422 PASS, 37 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS idl_test setup
PASS idl_test validation
PASS Partial interface Document: original interface defined
Expand Down Expand Up @@ -1374,9 +1374,9 @@ PASS SVGElement interface: attribute oncanplaythrough
PASS SVGElement interface: attribute onchange
PASS SVGElement interface: attribute onclick
PASS SVGElement interface: attribute onclose
FAIL SVGElement interface: attribute oncontextlost assert_true: The prototype object must have a property "oncontextlost" expected true got false
PASS SVGElement interface: attribute oncontextlost
PASS SVGElement interface: attribute oncontextmenu
FAIL SVGElement interface: attribute oncontextrestored assert_true: The prototype object must have a property "oncontextrestored" expected true got false
PASS SVGElement interface: attribute oncontextrestored
PASS SVGElement interface: attribute oncuechange
PASS SVGElement interface: attribute ondblclick
PASS SVGElement interface: attribute ondrag
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This is a testharness.js-based test.
Found 984 tests; 968 PASS, 16 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 984 tests; 980 PASS, 4 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS idl_test setup
PASS idl_test validation
PASS Partial interface Document: original interface defined
Expand Down Expand Up @@ -227,9 +227,9 @@ PASS Window interface: attribute oncanplaythrough
PASS Window interface: attribute onchange
PASS Window interface: attribute onclick
PASS Window interface: attribute onclose
FAIL Window interface: attribute oncontextlost assert_own_property: The global object must have a property "oncontextlost" expected property "oncontextlost" missing
PASS Window interface: attribute oncontextlost
PASS Window interface: attribute oncontextmenu
FAIL Window interface: attribute oncontextrestored assert_own_property: The global object must have a property "oncontextrestored" expected property "oncontextrestored" missing
PASS Window interface: attribute oncontextrestored
PASS Window interface: attribute oncuechange
PASS Window interface: attribute ondblclick
PASS Window interface: attribute ondrag
Expand Down Expand Up @@ -382,9 +382,9 @@ PASS Window interface: window must inherit property "oncanplaythrough" with the
PASS Window interface: window must inherit property "onchange" with the proper type
PASS Window interface: window must inherit property "onclick" with the proper type
PASS Window interface: window must inherit property "onclose" with the proper type
FAIL Window interface: window must inherit property "oncontextlost" with the proper type assert_own_property: expected property "oncontextlost" missing
PASS Window interface: window must inherit property "oncontextlost" with the proper type
PASS Window interface: window must inherit property "oncontextmenu" with the proper type
FAIL Window interface: window must inherit property "oncontextrestored" with the proper type assert_own_property: expected property "oncontextrestored" missing
PASS Window interface: window must inherit property "oncontextrestored" with the proper type
PASS Window interface: window must inherit property "oncuechange" with the proper type
PASS Window interface: window must inherit property "ondblclick" with the proper type
PASS Window interface: window must inherit property "ondrag" with the proper type
Expand Down Expand Up @@ -540,9 +540,9 @@ PASS Document interface: attribute oncanplaythrough
PASS Document interface: attribute onchange
PASS Document interface: attribute onclick
PASS Document interface: attribute onclose
FAIL Document interface: attribute oncontextlost assert_true: The prototype object must have a property "oncontextlost" expected true got false
PASS Document interface: attribute oncontextlost
PASS Document interface: attribute oncontextmenu
FAIL Document interface: attribute oncontextrestored assert_true: The prototype object must have a property "oncontextrestored" expected true got false
PASS Document interface: attribute oncontextrestored
PASS Document interface: attribute oncuechange
PASS Document interface: attribute ondblclick
PASS Document interface: attribute ondrag
Expand Down Expand Up @@ -667,9 +667,9 @@ PASS Document interface: iframe.contentDocument must inherit property "oncanplay
PASS Document interface: iframe.contentDocument must inherit property "onchange" with the proper type
PASS Document interface: iframe.contentDocument must inherit property "onclick" with the proper type
PASS Document interface: iframe.contentDocument must inherit property "onclose" with the proper type
FAIL Document interface: iframe.contentDocument must inherit property "oncontextlost" with the proper type assert_inherits: property "oncontextlost" not found in prototype chain
PASS Document interface: iframe.contentDocument must inherit property "oncontextlost" with the proper type
PASS Document interface: iframe.contentDocument must inherit property "oncontextmenu" with the proper type
FAIL Document interface: iframe.contentDocument must inherit property "oncontextrestored" with the proper type assert_inherits: property "oncontextrestored" not found in prototype chain
PASS Document interface: iframe.contentDocument must inherit property "oncontextrestored" with the proper type
PASS Document interface: iframe.contentDocument must inherit property "oncuechange" with the proper type
PASS Document interface: iframe.contentDocument must inherit property "ondblclick" with the proper type
PASS Document interface: iframe.contentDocument must inherit property "ondrag" with the proper type
Expand Down Expand Up @@ -794,9 +794,9 @@ PASS Document interface: new Document() must inherit property "oncanplaythrough"
PASS Document interface: new Document() must inherit property "onchange" with the proper type
PASS Document interface: new Document() must inherit property "onclick" with the proper type
PASS Document interface: new Document() must inherit property "onclose" with the proper type
FAIL Document interface: new Document() must inherit property "oncontextlost" with the proper type assert_inherits: property "oncontextlost" not found in prototype chain
PASS Document interface: new Document() must inherit property "oncontextlost" with the proper type
PASS Document interface: new Document() must inherit property "oncontextmenu" with the proper type
FAIL Document interface: new Document() must inherit property "oncontextrestored" with the proper type assert_inherits: property "oncontextrestored" not found in prototype chain
PASS Document interface: new Document() must inherit property "oncontextrestored" with the proper type
PASS Document interface: new Document() must inherit property "oncuechange" with the proper type
PASS Document interface: new Document() must inherit property "ondblclick" with the proper type
PASS Document interface: new Document() must inherit property "ondrag" with the proper type
Expand Down Expand Up @@ -921,9 +921,9 @@ PASS Document interface: documentWithHandlers must inherit property "oncanplayth
PASS Document interface: documentWithHandlers must inherit property "onchange" with the proper type
PASS Document interface: documentWithHandlers must inherit property "onclick" with the proper type
PASS Document interface: documentWithHandlers must inherit property "onclose" with the proper type
FAIL Document interface: documentWithHandlers must inherit property "oncontextlost" with the proper type assert_inherits: property "oncontextlost" found on object expected in prototype chain
PASS Document interface: documentWithHandlers must inherit property "oncontextlost" with the proper type
PASS Document interface: documentWithHandlers must inherit property "oncontextmenu" with the proper type
FAIL Document interface: documentWithHandlers must inherit property "oncontextrestored" with the proper type assert_inherits: property "oncontextrestored" found on object expected in prototype chain
PASS Document interface: documentWithHandlers must inherit property "oncontextrestored" with the proper type
PASS Document interface: documentWithHandlers must inherit property "oncuechange" with the proper type
PASS Document interface: documentWithHandlers must inherit property "ondblclick" with the proper type
PASS Document interface: documentWithHandlers must inherit property "ondrag" with the proper type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This is a testharness.js-based test.
Found 816 tests; 804 PASS, 12 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 816 tests; 806 PASS, 10 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS idl_test setup
PASS idl_test validation
PASS Partial interface Document: original interface defined
Expand Down Expand Up @@ -332,8 +332,8 @@ PASS OffscreenCanvas interface: attribute height
PASS OffscreenCanvas interface: operation getContext(OffscreenRenderingContextId, optional any)
PASS OffscreenCanvas interface: operation transferToImageBitmap()
PASS OffscreenCanvas interface: operation convertToBlob(optional ImageEncodeOptions)
FAIL OffscreenCanvas interface: attribute oncontextlost assert_true: The prototype object must have a property "oncontextlost" expected true got false
FAIL OffscreenCanvas interface: attribute oncontextrestored assert_true: The prototype object must have a property "oncontextrestored" expected true got false
PASS OffscreenCanvas interface: attribute oncontextlost
PASS OffscreenCanvas interface: attribute oncontextrestored
PASS OffscreenCanvasRenderingContext2D interface: existence and properties of interface object
PASS OffscreenCanvasRenderingContext2D interface object length
PASS OffscreenCanvasRenderingContext2D interface object name
Expand Down
Loading

0 comments on commit 0bc9ff7

Please sign in to comment.