Skip to content

Commit

Permalink
VTTypes: Add the IDL syntax to support the VT types feature.
Browse files Browse the repository at this point in the history
This patch does several things:
- Loosens the restriction in IDL checker to allow distinguishing between
  callback types and dictionary like types. This implements the
  following PR: whatwg/webidl#1353

- Uses the loosened restriction to add a behind-the-flag overload of
  startViewTransition that takes a dictionary

- Adds a smoke test for the new syntax

Bug: 1466251
Change-Id: I7b82b49e993e8ad907804d772b4f2c6e0f1ab3e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4973315
Reviewed-by: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: David Bokan <bokan@chromium.org>
Commit-Queue: Vladimir Levin <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1216984}
  • Loading branch information
vmpstr authored and Chromium LUCI CQ committed Oct 30, 2023
1 parent 758e56a commit f6c287b
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 4 deletions.
2 changes: 2 additions & 0 deletions third_party/blink/renderer/bindings/generated_in_core.gni
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ generated_dictionary_sources_in_core = [
"$root_gen_dir/third_party/blink/renderer/bindings/core/v8/v8_validity_state_flags.h",
"$root_gen_dir/third_party/blink/renderer/bindings/core/v8/v8_view_timeline_options.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/core/v8/v8_view_timeline_options.h",
"$root_gen_dir/third_party/blink/renderer/bindings/core/v8/v8_view_transition_options.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/core/v8/v8_view_transition_options.h",
"$root_gen_dir/third_party/blink/renderer/bindings/core/v8/v8_wheel_event_init.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/core/v8/v8_wheel_event_init.h",
"$root_gen_dir/third_party/blink/renderer/bindings/core/v8/v8_window_post_message_options.cc",
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/bindings/idl_in_core.gni
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ static_idl_files_in_core = [
"//third_party/blink/renderer/core/view_transition/page_reveal_event.idl",
"//third_party/blink/renderer/core/view_transition/view_transition.idl",
"//third_party/blink/renderer/core/view_transition/view_transition_callback.idl",
"//third_party/blink/renderer/core/view_transition/view_transition_options.idl",
"//third_party/blink/renderer/core/view_transition/view_transition_supplement.idl",
"//third_party/blink/renderer/core/workers/abstract_worker.idl",
"//third_party/blink/renderer/core/workers/dedicated_worker_global_scope.idl",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
dictionary ViewTransitionOptions {
ViewTransitionCallback? update = null;
sequence<DOMString>? type = null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "cc/trees/layer_tree_host.h"
#include "cc/view_transition/view_transition_request.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_view_transition_callback.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_view_transition_options.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
Expand Down Expand Up @@ -90,6 +91,7 @@ DOMViewTransition* ViewTransitionSupplement::startViewTransition(
DCHECK(script_state);
DCHECK(ThreadScheduler::Current());
auto* supplement = From(document);

if (callback) {
auto* tracker = ThreadScheduler::Current()->GetTaskAttributionTracker();
// Set the parent task ID if we're not in an extension task (as extensions
Expand All @@ -101,11 +103,24 @@ DOMViewTransition* ViewTransitionSupplement::startViewTransition(
return supplement->StartTransition(document, callback, exception_state);
}

DOMViewTransition* ViewTransitionSupplement::startViewTransition(
ScriptState* script_state,
Document& document,
ViewTransitionOptions* options,
ExceptionState& exception_state) {
CHECK(!options || options->hasUpdate());
return startViewTransition(script_state, document,
options ? options->update() : nullptr,
exception_state);
}

DOMViewTransition* ViewTransitionSupplement::startViewTransition(
ScriptState* script_state,
Document& document,
ExceptionState& exception_state) {
return startViewTransition(script_state, document, nullptr, exception_state);
return startViewTransition(script_state, document,
static_cast<V8ViewTransitionCallback*>(nullptr),
exception_state);
}

DOMViewTransition* ViewTransitionSupplement::StartTransition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "third_party/blink/public/mojom/frame/frame.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_view_transition_callback.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_view_transition_options.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/view_transition/view_transition.h"
Expand All @@ -15,7 +16,6 @@

namespace blink {
class DOMViewTransition;
class V8ViewTransitionCallback;

class CORE_EXPORT ViewTransitionSupplement
: public GarbageCollected<ViewTransitionSupplement>,
Expand All @@ -36,7 +36,12 @@ class CORE_EXPORT ViewTransitionSupplement
Document&,
V8ViewTransitionCallback* callback,
ExceptionState&);
// Without callback:
// With options
static DOMViewTransition* startViewTransition(ScriptState*,
Document&,
ViewTransitionOptions* options,
ExceptionState&);
// Without callback or options:
static DOMViewTransition* startViewTransition(ScriptState*,
Document&,
ExceptionState&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
[
ImplementedAs=ViewTransitionSupplement
] partial interface Document {
[MeasureAs=ViewTransition, CallWith=ScriptState, RaisesException] ViewTransition startViewTransition(optional ViewTransitionCallback callback);
[MeasureAs=ViewTransition, CallWith=ScriptState, RaisesException] ViewTransition startViewTransition();
[MeasureAs=ViewTransition, CallWith=ScriptState, RaisesException] ViewTransition startViewTransition(ViewTransitionCallback update);
[MeasureAs=ViewTransition, CallWith=ScriptState, RaisesException, RuntimeEnabled=ViewTransitionTypes] ViewTransition startViewTransition(ViewTransitionOptions opts);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4070,6 +4070,10 @@
// See https://drafts.csswg.org/css-view-transitions-1/.
name: "ViewTransitionOnNavigation",
},
{
// https://chromestatus.com/feature/5089552511533056
name: "ViewTransitionTypes",
},
{
name: "VisibilityCollapseColumn",
base_feature: "none",
Expand Down
10 changes: 10 additions & 0 deletions third_party/blink/web_tests/VirtualTestSuites
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,16 @@
"--enable-blink-features=SerializeViewTransitionStateInSPA"],
"expires": "May 1, 2024"
},
{
"prefix": "view-transition-types",
"platforms": ["Linux", "Mac", "Win"],
"owners": ["view-transitions-api@chromium.org"],
"bases": ["wpt_internal/view-transition-types"],
"exclusive_tests": "ALL",
"args": ["--enable-threaded-compositing",
"--enable-blink-features=ViewTransitionTypes"],
"expires": "May 1, 2024"
},
{
"prefix": "mutation-events-disabled",
"platforms": ["Linux"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tests for the ViewTransitionTypes syntax.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tests for the ViewTransitionsTypes syntax.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<title>View transitions: use dictionary syntax smoketest (ref)</title>
<link rel="help" href="https://github.com/WICG/view-transitions">
<link rel="author" href="mailto:vmpstr@chromium.org">

<style>
div { contain: paint; }
#left {
background: blue;
width: 100px;
height: 100px;
position: absolute;
top: 50px;
left: 50px;
}
#right {
width: 50px;
height: 50px;
background: green;
position: absolute;
top: 50px;
left: 250px;
}
body { background: lightpink; }
</style>

<div id=left></div>
<div id=right></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html class=reftest-wait>
<title>View transitions: use dictionary syntax smoketest</title>
<link rel="help" href="https://github.com/WICG/view-transitions">
<link rel="author" href="mailto:vmpstr@chromium.org">
<link rel="match" href="shared-element-types-syntax-ref.html">

<script src="/common/reftest-wait.js"></script>
<style>
div { contain: paint; }
#left {
background: green;
width: 100px;
height: 100px;
position: absolute;
top: 50px;
left: 50px;
}
#right {
width: 50px;
height: 50px;
background: blue;
position: absolute;
top: 50px;
left: 250px;
}
.left-tag {
view-transition-name: left-element;
}
.right-tag {
view-transition-name: right-element;
}

.hidden {
background: pink;
width: 10px;
height: 10px;
view-transition-name: hidden;
}

html::view-transition-group(hidden) { animation-duration: 300s; }
html::view-transition-image-pair(hidden) { animation: unset; opacity: 0; }

html::view-transition-group(left-element),
html::view-transition-group(right-element) { animation-duration: 0s; }

html::view-transition-new(left-element),
html::view-transition-new(right-element) { animation: unset; opacity: 0; }

html::view-transition-old(left-element),
html::view-transition-old(right-element) { animation: unset; opacity: 1; }

html::view-transition-group(root) { animation: unset; opacity: 0; }
html::view-transition { background: lightpink; }

</style>

<div id=left class="left-tag"></div>
<div id=right class="right-tag"></div>

<div id=hidden class=hidden></div>

<script>
failIfNot(document.startViewTransition, "Missing document.startViewTransition");

async function runTest() {
document.startViewTransition({
update: () => {
left.classList.remove("left-tag");
left.classList.add("right-tag");

right.classList.remove("right-tag");
right.classList.add("left-tag");

requestAnimationFrame(() => requestAnimationFrame(takeScreenshot))
}
});
}
onload = () => requestAnimationFrame(() => requestAnimationFrame(runTest));
</script>

0 comments on commit f6c287b

Please sign in to comment.