forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[css-color-5] Implement light-dark() function for color values
https://bugs.webkit.org/show_bug.cgi?id=266889 rdar://120171629 Reviewed by Tim Nguyen. `light-dark()` allows authors to easily specify colors that adjust depending on an element's used color scheme. Spec: https://drafts.csswg.org/css-color-5/#light-dark * LayoutTests/TestExpectations: * LayoutTests/imported/w3c/web-platform-tests/css/css-color/light-dark-basic-expected.txt: * Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/css/CSSValueKeywords.in: * Source/WebCore/css/color/CSSUnresolvedColor.cpp: (WebCore::CSSUnresolvedColor::containsCurrentColor const): (WebCore::CSSUnresolvedColor::createStyleColor const): * Source/WebCore/css/color/CSSUnresolvedColor.h: * Source/WebCore/css/color/CSSUnresolvedLightDark.cpp: Added. (WebCore::serializationForCSS): (WebCore::operator==): (WebCore::createStyleColor): * Source/WebCore/css/color/CSSUnresolvedLightDark.h: Added. * Source/WebCore/css/parser/CSSParserContext.cpp: (WebCore::CSSParserContext::CSSParserContext): (WebCore::add): * Source/WebCore/css/parser/CSSParserContext.h: * Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp: (WebCore::CSSPropertyParserHelpers::parseLightDarkFunctionParameters): (WebCore::CSSPropertyParserHelpers::parseColorFunctionRaw): Similar to system colors, there is not an existing mechanism to resolve dynamic colors in workers. (WebCore::CSSPropertyParserHelpers::parseColorFunction): * Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js: Canonical link: https://commits.webkit.org/272560@main
- Loading branch information
Showing
14 changed files
with
189 additions
and
10 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
4 changes: 2 additions & 2 deletions
4
LayoutTests/imported/w3c/web-platform-tests/css/css-color/light-dark-basic-expected.txt
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
FAIL light-dark(white, black) assert_not_equals: Should be valid got disallowed value "" | ||
FAIL light-dark(light-dark(white, red), red) assert_not_equals: Should be valid got disallowed value "" | ||
PASS light-dark(white, black) | ||
PASS light-dark(light-dark(white, red), red) | ||
|
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
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
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
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,61 @@ | ||
/* | ||
* Copyright (C) 2023 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "CSSUnresolvedLightDark.h" | ||
|
||
#include "ColorFromPrimitiveValue.h" | ||
#include "ColorSerialization.h" | ||
#include "Document.h" | ||
#include "StyleBuilderState.h" | ||
|
||
namespace WebCore { | ||
|
||
void serializationForCSS(StringBuilder& builder, const CSSUnresolvedLightDark& lightDark) | ||
{ | ||
builder.append("light-dark("_s, lightDark.lightColor->customCSSText(), ", "_s, lightDark.darkColor->customCSSText(), ')'); | ||
} | ||
|
||
String serializationForCSS(const CSSUnresolvedLightDark& unresolved) | ||
{ | ||
StringBuilder builder; | ||
serializationForCSS(builder, unresolved); | ||
return builder.toString(); | ||
} | ||
|
||
bool operator==(const CSSUnresolvedLightDark& a, const CSSUnresolvedLightDark& b) | ||
{ | ||
return compareCSSValue(a.lightColor, b.lightColor) | ||
&& compareCSSValue(a.darkColor, b.darkColor); | ||
} | ||
|
||
StyleColor createStyleColor(const CSSUnresolvedLightDark& unresolved, const Document& document, RenderStyle& style, Style::ForVisitedLink forVisitedLink) | ||
{ | ||
if (document.useDarkAppearance(&style)) | ||
return colorFromPrimitiveValue(document, style, unresolved.darkColor.get(), forVisitedLink); | ||
return colorFromPrimitiveValue(document, style, unresolved.lightColor.get(), forVisitedLink); | ||
} | ||
|
||
} // namespace WebCore |
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,54 @@ | ||
/* | ||
* Copyright (C) 2023 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "CSSPrimitiveValue.h" | ||
#include "StyleColor.h" | ||
#include <wtf/Forward.h> | ||
#include <wtf/RefCounted.h> | ||
|
||
namespace WebCore { | ||
|
||
namespace Style { | ||
enum class ForVisitedLink : bool; | ||
} | ||
|
||
class Document; | ||
class RenderStyle; | ||
|
||
struct CSSUnresolvedLightDark { | ||
friend bool operator==(const CSSUnresolvedLightDark&, const CSSUnresolvedLightDark&); | ||
|
||
Ref<CSSPrimitiveValue> lightColor; | ||
Ref<CSSPrimitiveValue> darkColor; | ||
}; | ||
|
||
void serializationForCSS(StringBuilder&, const CSSUnresolvedLightDark&); | ||
String serializationForCSS(const CSSUnresolvedLightDark&); | ||
|
||
StyleColor createStyleColor(const CSSUnresolvedLightDark&, const Document&, RenderStyle&, Style::ForVisitedLink); | ||
|
||
} // namespace WebCore |
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
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