forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SET: Allow an element to be specified multiple times as shared.
This patch allows an element to be specified as shared multiple times. This was already possible in the API, but we didn't plumb sufficient information to viz to let it take advantage of it. Also adds a (manual) test to exercise this behavior. R=wangxianzhu@chromium.org Bug: 1174141 Change-Id: I0e7da0889297e96d0ddafa66ae736055a987f5ec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2844997 Commit-Queue: vmpstr <vmpstr@chromium.org> Reviewed-by: Xianzhu Wang <wangxianzhu@chromium.org> Cr-Commit-Position: refs/heads/master@{#876233}
- Loading branch information
Showing
6 changed files
with
167 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
cc/document_transition/document_transition_shared_element_id.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "cc/document_transition/document_transition_shared_element_id.h" | ||
|
||
#include "base/check_op.h" | ||
#include "base/containers/flat_set.h" | ||
|
||
namespace cc { | ||
|
||
DocumentTransitionSharedElementId::DocumentTransitionSharedElementId() = | ||
default; | ||
|
||
DocumentTransitionSharedElementId::DocumentTransitionSharedElementId( | ||
uint32_t document_tag) | ||
: document_tag_(document_tag) {} | ||
|
||
DocumentTransitionSharedElementId::DocumentTransitionSharedElementId( | ||
DocumentTransitionSharedElementId&&) = default; | ||
|
||
DocumentTransitionSharedElementId::DocumentTransitionSharedElementId( | ||
const DocumentTransitionSharedElementId&) = default; | ||
|
||
DocumentTransitionSharedElementId::~DocumentTransitionSharedElementId() = | ||
default; | ||
|
||
void DocumentTransitionSharedElementId::AddIndex(uint32_t index) { | ||
DCHECK_NE(document_tag_, 0u); | ||
element_indices_.insert(index); | ||
} | ||
|
||
bool DocumentTransitionSharedElementId::Matches(uint32_t document_tag, | ||
uint32_t index) const { | ||
return document_tag_ == document_tag && element_indices_.count(index) != 0; | ||
} | ||
|
||
} // namespace cc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...eb_tests/wpt_internal/document-transition/shared-transition-repeated-elements.manual.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<title>Shared transitions: repeated elements (one -> two elements and back)</title> | ||
<link rel="help" href="https://github.com/vmpstr/shared-element-transitions"> | ||
<link rel="author" href="mailto:vmpstr@chromium.org"> | ||
|
||
<style> | ||
body { | ||
background: lightpink; | ||
} | ||
|
||
#container { | ||
width: max-content; | ||
position: relative; | ||
} | ||
|
||
.hidden { display: none; } | ||
|
||
.shape { | ||
width: 100px; | ||
height: 100px; | ||
border-radius: 50%; | ||
border: 1px solid black; | ||
position: absolute; | ||
contain: paint; | ||
} | ||
|
||
#yellow { | ||
background: yellow; | ||
left: 300px; | ||
top: 50px; | ||
} | ||
#green { | ||
background: green; | ||
left: 50px; | ||
top: 150px; | ||
} | ||
#blue { | ||
background: blue; | ||
left: 300px; | ||
top: 250px; | ||
} | ||
</style> | ||
|
||
<input id=toggle type=button value="Toggle!"></input> | ||
<span>One shape becomes two and vice versa</span> | ||
<div id=green class=shape></div> | ||
<div id=blue class="shape hidden"></div> | ||
<div id=yellow class="shape hidden"></div> | ||
|
||
<script> | ||
function visibleSharedElements() { | ||
if (green.classList.contains("hidden")) { | ||
return [blue, yellow]; | ||
} else { | ||
return [green, green]; | ||
} | ||
} | ||
|
||
async function runAnimation() { | ||
await document.documentTransition.prepare({ | ||
rootTransition: "none", | ||
sharedElements: visibleSharedElements() | ||
}); | ||
|
||
green.classList.toggle("hidden"); | ||
blue.classList.toggle("hidden"); | ||
yellow.classList.toggle("hidden"); | ||
|
||
await document.documentTransition.start({ | ||
sharedElements: visibleSharedElements() | ||
}); | ||
} | ||
|
||
function init() { | ||
toggle.addEventListener("click", runAnimation); | ||
} | ||
onload = init; | ||
</script> |