Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[content-visibility] Support content-visibility for resize/intersection observer #6973

Conversation

rwlbuis
Copy link
Contributor

@rwlbuis rwlbuis commented Nov 30, 2022

56fda58

[content-visibility] Support content-visibility for resize/intersection observer
https://bugs.webkit.org/show_bug.cgi?id=245776

Reviewed by Darin Adler.

Implement restrictions to resize and intersection observers as specified in the specification:
https://w3c.github.io/csswg-drafts/css-contain/#cv-notes (Items 1 and 2)

* LayoutTests/imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-030-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-031-expected.txt:
* Source/WebCore/dom/Document.cpp:
(WebCore::computeIntersectionState):
* Source/WebCore/page/ResizeObservation.cpp:
(WebCore::ResizeObservation::computeObservedSizes const):
(WebCore::ResizeObservation::elementSizeChanged const):
* Source/WebCore/page/ResizeObservation.h:

Canonical link: https://commits.webkit.org/257256@main

30ba836

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  πŸ§ͺ win
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-debug βœ… πŸ›  gtk βœ… πŸ›  wincairo
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2 βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios   πŸ§ͺ api-mac   πŸ§ͺ api-gtk
βœ… πŸ›  tv   πŸ§ͺ mac-wk1
βœ… πŸ›  tv-sim   πŸ§ͺ mac-wk2
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch   πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  watch-sim βœ… πŸ§ͺ mac-wk2-stress

@rwlbuis rwlbuis self-assigned this Nov 30, 2022
@rwlbuis rwlbuis added the CSS Cascading Style Sheets implementation label Nov 30, 2022
@rwlbuis rwlbuis requested review from darinadler and removed request for rniwa and cdumez November 30, 2022 18:09
Copy link
Member

@darinadler darinadler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments about style, none of them important.

Comment on lines 8219 to 8222
if (targetRenderer->isSkippedContent())
intersectionState.isIntersecting = false;
else
intersectionState.isIntersecting = rootLocalTargetRect && rootLocalIntersectionRect.edgeInclusiveIntersect(*rootLocalTargetRect);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have just added to the boolean expression.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -52,24 +52,26 @@ void ResizeObservation::updateObservationSize(const BoxSizes& boxSizes)
m_lastObservationSizes = boxSizes;
}

auto ResizeObservation::computeObservedSizes() const -> BoxSizes
std::optional<ResizeObservation::BoxSizes> ResizeObservation::computeObservedSizes() const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write this for greater brevity:

auto ResizeObservation::computeObservedSizes() const -> std::optional<BoxSizes> 

I suppose it’s a matter of taste which one is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like that notation better.

{
if (m_target->isSVGElement()) {
if (auto svgRect = downcast<SVGElement>(*m_target).getBoundingBox()) {
auto size = LayoutSize(svgRect->width(), svgRect->height());
return { size, size, size };
return BoxSizes { size, size, size };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another alternative is:

return { { size, size, size } };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return {
if (box->isSkippedContent())
return std::nullopt;
return BoxSizes {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use the two sets of braces here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}
auto* box = m_target->renderBox();
if (box) {
return {
if (box->isSkippedContent())
return std::nullopt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Antti told me elsewhere that we use { } in cases like this. Of course, here it is subtle and risky to do that!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I kept it as-is.

adjustLayoutSizeForAbsoluteZoom(box->contentSize(), *box),
adjustLayoutSizeForAbsoluteZoom(box->contentLogicalSize(), *box),
adjustLayoutSizeForAbsoluteZoom(box->borderBoxLogicalSize(), *box)
};
}

return { };
return BoxSizes { };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably could even use the two sets of braces here, but probably not better!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept as-is.

Comment on lines 110 to 111
if (!currentSizes)
return currentSizes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it’s better to return { } or std::nullopt rather than currentSizes here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like std::nullopt best to make it clear what is happening.

if (m_lastObservationSizes.borderBoxLogicalSize != currentSizes.borderBoxLogicalSize)
return currentSizes;
if (m_lastObservationSizes.borderBoxLogicalSize != currentSizes->borderBoxLogicalSize)
return *currentSizes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change on this line isn’t needed.

if (m_lastObservationSizes.contentBoxLogicalSize != currentSizes.contentBoxLogicalSize)
return currentSizes;
if (m_lastObservationSizes.contentBoxLogicalSize != currentSizes->contentBoxLogicalSize)
return *currentSizes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change on this line isn’t needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have sworn it gave compile errors without the change at the time, but indeed now I try again it builds fine.

@rwlbuis rwlbuis force-pushed the eng/content-visibility-Support-content-visibility-for-resizeintersection-observer branch from 2d844de to 30ba836 Compare December 1, 2022 16:44
@rwlbuis rwlbuis added the merge-queue Applied to send a pull request to merge-queue label Dec 1, 2022
…on observer

https://bugs.webkit.org/show_bug.cgi?id=245776

Reviewed by Darin Adler.

Implement restrictions to resize and intersection observers as specified in the specification:
https://w3c.github.io/csswg-drafts/css-contain/#cv-notes (Items 1 and 2)

* LayoutTests/imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-030-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-031-expected.txt:
* Source/WebCore/dom/Document.cpp:
(WebCore::computeIntersectionState):
* Source/WebCore/page/ResizeObservation.cpp:
(WebCore::ResizeObservation::computeObservedSizes const):
(WebCore::ResizeObservation::elementSizeChanged const):
* Source/WebCore/page/ResizeObservation.h:

Canonical link: https://commits.webkit.org/257256@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/content-visibility-Support-content-visibility-for-resizeintersection-observer branch from 30ba836 to 56fda58 Compare December 1, 2022 22:53
@webkit-commit-queue
Copy link
Collaborator

Committed 257256@main (56fda58): https://commits.webkit.org/257256@main

Reviewed commits have been landed. Closing PR #6973 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 56fda58 into WebKit:main Dec 1, 2022
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Dec 1, 2022
@rwlbuis rwlbuis deleted the eng/content-visibility-Support-content-visibility-for-resizeintersection-observer branch February 16, 2023 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Cascading Style Sheets implementation
Projects
None yet
4 participants