Skip to content

Commit

Permalink
view-transition: Ensure only-child excludes ::view-transition.
Browse files Browse the repository at this point in the history
The :only-child pseudo-class is supported for all view transition pseudo
elements except ::view-transition. Fix the selector checking code to
ensure this.

Bug: 1407399
Change-Id: I244b372afd3b418de134a1422b10b203f6d83a43
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4181497
Commit-Queue: Khushal Sagar <khushalsagar@chromium.org>
Auto-Submit: Khushal Sagar <khushalsagar@chromium.org>
Reviewed-by: Vladimir Levin <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1096955}
  • Loading branch information
khushalsagar authored and Chromium LUCI CQ committed Jan 25, 2023
1 parent fe97863 commit d588494
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 11 deletions.
1 change: 0 additions & 1 deletion third_party/blink/renderer/core/css/selector_checker.cc
Expand Up @@ -1333,7 +1333,6 @@ bool SelectorChecker::CheckPseudoClass(const SelectorCheckingContext& context,
case CSSSelector::kPseudoOnlyChild: {
if (IsTransitionPseudoElement(context.pseudo_id)) {
DCHECK(element.IsDocumentElement());
DCHECK_NE(context.pseudo_id, kPseudoIdViewTransition);
DCHECK(context.pseudo_argument);

auto* transition =
Expand Down
Expand Up @@ -685,7 +685,7 @@ void ViewTransition::Trace(Visitor* visitor) const {

bool ViewTransition::MatchForOnlyChild(
PseudoId pseudo_id,
AtomicString view_transition_name) const {
const AtomicString& view_transition_name) const {
if (!style_tracker_)
return false;
return style_tracker_->MatchForOnlyChild(pseudo_id, view_transition_name);
Expand Down
Expand Up @@ -97,7 +97,7 @@ class CORE_EXPORT ViewTransition : public ScriptWrappable,
// Returns true if the pseudo element corresponding to the given id and name
// is the only child.
bool MatchForOnlyChild(PseudoId pseudo_id,
AtomicString view_transition_name) const;
const AtomicString& view_transition_name) const;

// ExecutionContextLifecycleObserver implementation.
void ContextDestroyed() override;
Expand Down
Expand Up @@ -246,11 +246,13 @@ void ViewTransitionStyleTracker::AddTransitionElement(

bool ViewTransitionStyleTracker::MatchForOnlyChild(
PseudoId pseudo_id,
AtomicString view_transition_name) const {
DCHECK(view_transition_name);

const AtomicString& view_transition_name) const {
switch (pseudo_id) {
case kPseudoIdViewTransition:
DCHECK(!view_transition_name);
return false;
case kPseudoIdViewTransitionGroup: {
DCHECK(view_transition_name);
const bool has_root = old_root_data_ || new_root_data_;
if (has_root) {
return element_data_map_.empty();
Expand All @@ -260,8 +262,10 @@ bool ViewTransitionStyleTracker::MatchForOnlyChild(
}
}
case kPseudoIdViewTransitionImagePair:
DCHECK(view_transition_name);
return true;
case kPseudoIdViewTransitionOld: {
DCHECK(view_transition_name);
if (new_root_data_ &&
new_root_data_->names.Contains(view_transition_name)) {
return false;
Expand All @@ -278,6 +282,7 @@ bool ViewTransitionStyleTracker::MatchForOnlyChild(
return !element_data->new_snapshot_id.IsValid();
}
case kPseudoIdViewTransitionNew: {
DCHECK(view_transition_name);
if (old_root_data_ &&
old_root_data_->names.Contains(view_transition_name)) {
return false;
Expand Down
Expand Up @@ -72,7 +72,7 @@ class ViewTransitionStyleTracker
// Returns true if the pseudo element corresponding to the given id and name
// is the only child.
bool MatchForOnlyChild(PseudoId pseudo_id,
AtomicString view_transition_name) const;
const AtomicString& view_transition_name) const;

// Indicate that capture was requested. This verifies that the combination of
// set elements and names is valid. Returns true if capture phase started, and
Expand Down
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class=reftest-wait>
<html class="reftest-wait foo">
<title>View transitions: ensure :only-child is supported on view-transition-group</title>
<link rel="help" href="https://github.com/WICG/view-transitions">
<link rel="author" href="mailto:khushalsagar@chromium.org">
Expand All @@ -8,6 +8,22 @@
<script src="/resources/testharnessreport.js"></script>

<style>
::view-transition {
background-color: black;
}
html:only-child {
background-color: black;
}
:root:only-child {
background-color: black;
}
:only-child {
background-color: black;
}
.foo:only-child {
background-color: black;
}

::view-transition-group(root) {
background-color: blue;
}
Expand Down
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class=reftest-wait>
<html class="reftest-wait foo">
<title>View transitions: ensure :only-child is supported on view-transition-image-pair</title>
<link rel="help" href="https://github.com/WICG/view-transitions">
<link rel="author" href="mailto:khushalsagar@chromium.org">
Expand All @@ -8,6 +8,22 @@
<script src="/resources/testharnessreport.js"></script>

<style>
::view-transition {
background-color: black;
}
html:only-child {
background-color: black;
}
:root:only-child {
background-color: black;
}
:only-child {
background-color: black;
}
.foo:only-child {
background-color: black;
}

::view-transition-image-pair(root):only-child {
background-color: red;
}
Expand Down
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class=reftest-wait>
<html class="reftest-wait foo">
<title>View transitions: ensure :only-child is supported on view-transition-new</title>
<link rel="help" href="https://github.com/WICG/view-transitions">
<link rel="author" href="mailto:khushalsagar@chromium.org">
Expand All @@ -8,6 +8,22 @@
<script src="/resources/testharnessreport.js"></script>

<style>
::view-transition {
background-color: black;
}
html:only-child {
background-color: black;
}
:root:only-child {
background-color: black;
}
:only-child {
background-color: black;
}
.foo:only-child {
background-color: black;
}

::view-transition-new(root) {
background-color: blue;
}
Expand Down
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class=reftest-wait>
<html class="reftest-wait foo">
<title>View transitions: ensure :only-child is supported on view-transition-old</title>
<link rel="help" href="https://github.com/WICG/view-transitions">
<link rel="author" href="mailto:khushalsagar@chromium.org">
Expand All @@ -8,6 +8,22 @@
<script src="/resources/testharnessreport.js"></script>

<style>
::view-transition {
background-color: black;
}
html:only-child {
background-color: black;
}
:root:only-child {
background-color: black;
}
:only-child {
background-color: black;
}
.foo:only-child {
background-color: black;
}

::view-transition-old(root) {
background-color: blue;
}
Expand Down
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html class="reftest-wait foo">
<title>View transitions: ensure :only-child is supported on view-transition</title>
<link rel="help" href="https://github.com/WICG/view-transitions">
<link rel="author" href="mailto:khushalsagar@chromium.org">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style>
::view-transition {
background-color: red;
}

html:only-child {
background-color: blue;
}

:root:only-child {
background-color: blue;
}

:only-child {
background-color: blue;
}

.foo:only-child {
background-color: blue;
}
</style>

<script>
promise_test(() => {
return new Promise(async (resolve, reject) => {
let transition = document.startViewTransition();
transition.ready.then(() => {
let style = getComputedStyle(
document.documentElement, ":view-transition");
if (style.backgroundColor == "rgb(255, 0, 0)")
resolve();
else
reject(style.backgroundColor);
});
});
}, ":only-child is not supported on view-transition");
</script>

0 comments on commit d588494

Please sign in to comment.