Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8680,6 +8680,23 @@ WebLocksAPIEnabled:
sharedPreferenceForWebProcess: true
richJavaScript: true

WebPageSpatialBackdropEnabled:
type: bool
status: testable
category: html
condition: ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
humanReadableName: "Web Page Spatial Backdrop"
humanReadableDescription: "Enable Web Page Spatial Backdrop"
defaultValue:
WebKitLegacy:
default: false
WebKit:
default: false
WebCore:
default: false
disableInLockdownMode: true
sharedPreferenceForWebProcess: true

WebRTCAV1CodecEnabled:
type: bool
status: preview
Expand Down
4 changes: 4 additions & 0 deletions Source/WTF/wtf/PlatformEnableCocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,10 @@
#define ENABLE_SPATIAL_IMAGE_DETECTION 1
#endif

#if !defined(ENABLE_WEB_PAGE_SPATIAL_BACKDROP) && PLATFORM(VISION)
#define ENABLE_WEB_PAGE_SPATIAL_BACKDROP 1
#endif

#if !defined(ENABLE_SPEECH_SYNTHESIS) && !PLATFORM(MACCATALYST)
#define ENABLE_SPEECH_SYNTHESIS 1
#endif
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
dom/SimulatedClickOptions.h
dom/SlotAssignmentMode.h
dom/SpaceSplitString.h
dom/SpatialBackdropSource.h
dom/StartViewTransitionOptions.h
dom/StaticRange.h
dom/StyledElement.h
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,7 @@ dom/SimpleRange.cpp
dom/SimulatedClick.cpp
dom/SlotAssignment.cpp
dom/SpaceSplitString.cpp
dom/SpatialBackdropSource.cpp
dom/StaticNodeList.cpp
dom/StaticRange.cpp
dom/StringCallback.cpp
Expand Down
6 changes: 6 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5189,6 +5189,7 @@
C6F0900F14327B6100685849 /* MutationObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F0900614327B6100685849 /* MutationObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
C6F0902D14327D4F00685849 /* JSMutationObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F0902514327D4F00685849 /* JSMutationObserver.h */; };
C9D467051E60C465008195FB /* AutoplayEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = C9D467041E60C3EB008195FB /* AutoplayEvent.h */; settings = {ATTRIBUTES = (Private, ); }; };
CA3344082D16174C007473A1 /* SpatialBackdropSource.h in Headers */ = {isa = PBXBuildFile; fileRef = CA3344072D16174C007473A1 /* SpatialBackdropSource.h */; settings = {ATTRIBUTES = (Private, ); }; };
CA3A4AAF25416E40006CDAE2 /* ImageResolution.h in Headers */ = {isa = PBXBuildFile; fileRef = CA3A4AAD25416E3E006CDAE2 /* ImageResolution.h */; };
CA3BF67E10D99BAE00E6CE53 /* ScrollAnimator.h in Headers */ = {isa = PBXBuildFile; fileRef = CA3BF67D10D99BAE00E6CE53 /* ScrollAnimator.h */; settings = {ATTRIBUTES = (Private, ); }; };
CA6C1530220B98CC0055CBFC /* JSValueInWrappedObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 931AE3B81FB80EAE00F5EFB2 /* JSValueInWrappedObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -18859,6 +18860,8 @@
CA1635DC2072E76900E7D2CE /* ReferrerPolicy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReferrerPolicy.cpp; sourceTree = "<group>"; };
CA1933D52407D6400071241A /* PerformancePaintTiming.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PerformancePaintTiming.h; sourceTree = "<group>"; };
CA1933D82407EDCF0071241A /* PerformancePaintTiming.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PerformancePaintTiming.idl; sourceTree = "<group>"; };
CA3344072D16174C007473A1 /* SpatialBackdropSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpatialBackdropSource.h; sourceTree = "<group>"; };
CA3344092D1625B9007473A1 /* SpatialBackdropSource.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SpatialBackdropSource.cpp; sourceTree = "<group>"; };
CA3A4AAB25416E3C006CDAE2 /* ImageResolution.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageResolution.cpp; sourceTree = "<group>"; };
CA3A4AAD25416E3E006CDAE2 /* ImageResolution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageResolution.h; sourceTree = "<group>"; };
CA3BF67B10D99BAE00E6CE53 /* ScrollAnimator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollAnimator.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -38781,6 +38784,8 @@
9B4F0632289F2F08007831DB /* SlotAssignmentMode.idl */,
D01A27AB10C9BFD800026A42 /* SpaceSplitString.cpp */,
D01A27AC10C9BFD800026A42 /* SpaceSplitString.h */,
CA3344092D1625B9007473A1 /* SpatialBackdropSource.cpp */,
CA3344072D16174C007473A1 /* SpatialBackdropSource.h */,
EE7A169F2C607BFA0057B563 /* StartViewTransitionOptions.h */,
EE7A169E2C607AF00057B563 /* StartViewTransitionOptions.idl */,
BC7FA62C0D1F0EFF00DB22A9 /* StaticNodeList.cpp */,
Expand Down Expand Up @@ -44044,6 +44049,7 @@
72F7E746279B8F7500D82D2D /* SourceImage.h in Headers */,
D01A27AE10C9BFD800026A42 /* SpaceSplitString.h in Headers */,
46A877482D0D426800DE225E /* SpanCoreAudio.h in Headers */,
CA3344082D16174C007473A1 /* SpatialBackdropSource.h in Headers */,
B9CA3B402CAB1D3E00B2607C /* SpatialImageControls.h in Headers */,
626CDE0F1140424C001E5A68 /* SpatialNavigation.h in Headers */,
517C11D52C6DD6A100489490 /* SpatialVideoMetadata.h in Headers */,
Expand Down
45 changes: 45 additions & 0 deletions Source/WebCore/dom/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,47 @@ const Color& Document::themeColor()
return m_cachedThemeColor;
}

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
void Document::spatialBackdropLinkElementChanged()
{
spatialBackdropSourceChanged();
}

void Document::spatialBackdropSourceChanged()
{
if (!settings().webPageSpatialBackdropEnabled())
return;

auto newSpatialBackdropSource = determineActiveSpatialBackdropSource();
if (m_cachedSpatialBackdropSource == newSpatialBackdropSource)
return;
m_cachedSpatialBackdropSource = WTFMove(newSpatialBackdropSource);

if (RefPtr page = this->page())
page->chrome().client().spatialBackdropSourceChanged();
}

std::optional<SpatialBackdropSource> Document::determineActiveSpatialBackdropSource() const
{
auto sourceURL = m_url.url();
if (!sourceURL.isValid())
return std::nullopt;

for (auto& linkElement : descendantsOfType<HTMLLinkElement>(*this)) {
if (!linkElement.isSpatialBackdrop())
continue;

auto modelURL = linkElement.href();
if (!modelURL.isValid())
return std::nullopt;

return SpatialBackdropSource { WTFMove(sourceURL), WTFMove(modelURL), linkElement.environmentMap() };
}

return std::nullopt;
}
#endif

Color Document::linkColor(const RenderStyle& style) const
{
if (m_linkColor.isValid())
Expand Down Expand Up @@ -4213,6 +4254,10 @@ void Document::setURL(const URL& url)
m_documentURI = m_url.url();
m_adjustedURL = adjustedURL();
updateBaseURL();

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
spatialBackdropSourceChanged();
#endif
}

const URL& Document::urlForBindings()
Expand Down
18 changes: 18 additions & 0 deletions Source/WebCore/dom/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "RenderPtr.h"
#include "ReportingClient.h"
#include "ScriptExecutionContext.h"
#include "SpatialBackdropSource.h"
#include "StringWithDirection.h"
#include "Supplementable.h"
#include "TextIndicator.h"
Expand Down Expand Up @@ -917,6 +918,10 @@ class Document

const Color& themeColor();

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
const std::optional<SpatialBackdropSource>& spatialBackdropSource() const { return m_cachedSpatialBackdropSource; }
#endif

void setTextColor(const Color& color) { m_textColor = color; }
const Color& textColor() const { return m_textColor; }

Expand Down Expand Up @@ -1107,6 +1112,10 @@ class Document

void metaElementThemeColorChanged(HTMLMetaElement&);

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
void spatialBackdropLinkElementChanged();
#endif

#if ENABLE(DARK_MODE_CSS)
void processColorScheme(const String& colorScheme);
void metaElementColorSchemeChanged();
Expand Down Expand Up @@ -2069,6 +2078,11 @@ class Document
WeakPtr<HTMLMetaElement, WeakPtrImplWithEventTargetData> determineActiveThemeColorMetaElement();
void themeColorChanged();

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
std::optional<SpatialBackdropSource> determineActiveSpatialBackdropSource() const;
void spatialBackdropSourceChanged();
#endif

void invalidateAccessKeyCacheSlowCase();
void buildAccessKeyCache();

Expand Down Expand Up @@ -2230,6 +2244,10 @@ class Document
WeakPtr<HTMLMetaElement, WeakPtrImplWithEventTargetData> m_activeThemeColorMetaElement;
Color m_applicationManifestThemeColor;

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
std::optional<SpatialBackdropSource> m_cachedSpatialBackdropSource;
#endif

Color m_textColor { Color::black };
Color m_linkColor;
Color m_visitedLinkColor;
Expand Down
41 changes: 41 additions & 0 deletions Source/WebCore/dom/SpatialBackdropSource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2025 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
#include "config.h"
#include "SpatialBackdropSource.h"

namespace WebCore {

SpatialBackdropSource::SpatialBackdropSource(URL&& sourceURL, URL&& modelURL, std::optional<URL>&& environmentMapURL)
: m_sourceURL(WTFMove(sourceURL))
, m_modelURL(WTFMove(modelURL))
, m_environmentMapURL(WTFMove(environmentMapURL))
{
}

SpatialBackdropSource::SpatialBackdropSource(URL&& sourceURL, URL&& modelURL, URL&& environmentMapURL)
: m_sourceURL(WTFMove(sourceURL))
, m_modelURL(WTFMove(modelURL))
, m_environmentMapURL(environmentMapURL.isValid() ? std::make_optional(WTFMove(environmentMapURL)) : std::nullopt)
{
}

} // namespace WebCore
#endif
41 changes: 41 additions & 0 deletions Source/WebCore/dom/SpatialBackdropSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2025 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#pragma once

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)

#include <wtf/URL.h>

namespace WebCore {

struct SpatialBackdropSource {
public:
URL m_sourceURL;
URL m_modelURL;
std::optional<URL> m_environmentMapURL;

WEBCORE_EXPORT SpatialBackdropSource(URL&& sourceURL, URL&& modelURL, std::optional<URL>&& environmentMapURL);
SpatialBackdropSource(URL&& sourceURL, URL&& modelURL, URL&& environmentMapURL);

friend bool operator==(const SpatialBackdropSource&, const SpatialBackdropSource&) = default;
};

} // namespace WebCore
#endif
40 changes: 39 additions & 1 deletion Source/WebCore/html/HTMLLinkElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,18 @@ void HTMLLinkElement::attributeChanged(const QualifiedName& name, const AtomStri
case AttributeNames::relAttr: {
auto parsedRel = LinkRelAttribute(document(), newValue);
auto didMutateRel = parsedRel != m_relAttribute;
#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
auto wasSpatialBackdrop = m_relAttribute.isSpatialBackdrop;
#endif
m_relAttribute = WTFMove(parsedRel);
if (m_relList)
m_relList->associatedAttributeValueChanged();
if (didMutateRel)
process();
#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
if (wasSpatialBackdrop && !m_relAttribute.isSpatialBackdrop)
document().spatialBackdropLinkElementChanged();
#endif
break;
}
case AttributeNames::hrefAttr: {
Expand All @@ -212,6 +219,16 @@ void HTMLLinkElement::attributeChanged(const QualifiedName& name, const AtomStri
process();
break;
}
#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
case AttributeNames::environmentmapAttr: {
URL environmentMapURL = getNonEmptyURLAttribute(environmentmapAttr);
if (environmentMapURL == m_environmentMapURL)
return;
m_environmentMapURL = WTFMove(environmentMapURL);
process();
break;
}
#endif
case AttributeNames::typeAttr:
if (newValue == m_type)
return;
Expand Down Expand Up @@ -300,6 +317,11 @@ void HTMLLinkElement::process()
if (m_isHandlingBeforeLoad)
return;

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
if (m_relAttribute.isSpatialBackdrop)
document().spatialBackdropLinkElementChanged();
#endif

processInternalResourceLink();
if (m_relAttribute.isInternalResourceLink)
return;
Expand Down Expand Up @@ -528,6 +550,11 @@ void HTMLLinkElement::removedFromAncestor(RemovalType removalType, ContainerNode

bool wasLoading = styleSheetIsLoading();

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
if (m_relAttribute.isSpatialBackdrop)
oldParentOfRemovedTree.document().spatialBackdropLinkElementChanged();
#endif

if (m_sheet)
clearSheet();

Expand Down Expand Up @@ -728,7 +755,11 @@ void HTMLLinkElement::startLoadingDynamicSheet()

bool HTMLLinkElement::isURLAttribute(const Attribute& attribute) const
{
return attribute.name().localName() == hrefAttr || HTMLElement::isURLAttribute(attribute);
return attribute.name().localName() == hrefAttr
#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
|| attribute.name().localName() == environmentmapAttr
#endif
|| HTMLElement::isURLAttribute(attribute);
}

URL HTMLLinkElement::href() const
Expand All @@ -741,6 +772,13 @@ const AtomString& HTMLLinkElement::rel() const
return attributeWithoutSynchronization(relAttr);
}

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
URL HTMLLinkElement::environmentMap() const
{
return document().completeURL(attributeWithoutSynchronization(environmentmapAttr));
}
#endif

AtomString HTMLLinkElement::target() const
{
return attributeWithoutSynchronization(targetAttr);
Expand Down
8 changes: 8 additions & 0 deletions Source/WebCore/html/HTMLLinkElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class HTMLLinkElement final : public HTMLElement, public CachedStyleSheetClient,
URL href() const;
WEBCORE_EXPORT const AtomString& rel() const;

#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
URL environmentMap() const;
bool isSpatialBackdrop() const { return m_relAttribute.isSpatialBackdrop; }
#endif

AtomString target() const final;

const AtomString& type() const;
Expand Down Expand Up @@ -162,6 +167,9 @@ class HTMLLinkElement final : public HTMLElement, public CachedStyleSheetClient,
String m_media;
String m_integrityMetadataForPendingSheetRequest;
URL m_url;
#if ENABLE(WEB_PAGE_SPATIAL_BACKDROP)
URL m_environmentMapURL;
#endif
std::unique_ptr<DOMTokenList> m_sizes;
std::unique_ptr<DOMTokenList> m_relList;
std::unique_ptr<DOMTokenList> m_blockingList;
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/html/HTMLLinkElement.idl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
[Reflect] attribute boolean disabled;
[CEReactions=NotNeeded, Reflect] attribute DOMString charset;
[CEReactions=NotNeeded, Reflect, URL] attribute USVString href;
[CEReactions=NotNeeded, Conditional=WEB_PAGE_SPATIAL_BACKDROP, EnabledBySetting=WebPageSpatialBackdropEnabled, Reflect, URL] attribute USVString environmentMap;
[CEReactions=NotNeeded, Reflect] attribute DOMString hreflang;
[CEReactions=NotNeeded, Reflect] attribute DOMString media;
[CEReactions=NotNeeded, Reflect] attribute DOMString rel;
Expand Down
Loading