Skip to content

Commit

Permalink
Flatten colorInputStyleSheet into html.css
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=286344

Reviewed by Sam Weinig.

html.css already contained some <input type=color> styles. Might as
well contain all of them for clarity and ease of ongoing maintenance.

While we are in UserAgentStyle we move all the rules that implicitly
are conditional upon is<HTMLElement> into that branch and remove some
redundant comments.

This ends up applying a couple more styles to <input type=color> in
WK1, but that reduction in differences seems acceptable, if not
worthwhile.

* LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/html/rendering/non-replaced-elements/form-controls/resets-expected.txt: Removed.
* Source/WebCore/css/html.css:
(#endif):
* Source/WebCore/rendering/RenderTheme.cpp:
(WebCore::RenderTheme::colorInputStyleSheet const): Deleted.
* Source/WebCore/rendering/RenderTheme.h:
* Source/WebCore/rendering/ios/RenderThemeIOS.h:
* Source/WebCore/rendering/ios/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::colorInputStyleSheet const): Deleted.
* Source/WebCore/style/InspectorCSSOMWrappers.cpp:
(WebCore::Style::InspectorCSSOMWrappers::collectDocumentWrappers):
* Source/WebCore/style/UserAgentStyle.cpp:
(WebCore::Style::UserAgentStyle::initDefaultStyleSheet):
(WebCore::Style::UserAgentStyle::ensureDefaultStyleSheetsForElement):
* Source/WebCore/style/UserAgentStyle.h:

Canonical link: https://commits.webkit.org/289278@main
  • Loading branch information
annevk committed Jan 23, 2025
1 parent 0ef0f9c commit 384d445
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 429 deletions.

This file was deleted.

16 changes: 13 additions & 3 deletions Source/WebCore/css/html.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* The default style sheet used to render HTML.
*
* Copyright (C) 2000 Lars Knoll (knoll@kde.org)
* Copyright (C) 2003-2024 Apple Inc. All rights reserved.
* Copyright (C) 2003-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
Expand Down Expand Up @@ -1051,11 +1051,21 @@ input:is([type="checkbox"], [type="radio"]):checked:disabled {
}
#endif

#if defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY
input[type="color"] {
appearance: auto;
box-sizing: border-box;
outline: none;
#if defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY
width: 28px;
height: 28px;
padding: 3px;
}
border: initial;
border-radius: 50%;
#else
inline-size: 44px;
block-size: 23px;
#endif
}

input[type="color"]::-webkit-color-swatch-wrapper {
display: flex;
Expand Down
7 changes: 1 addition & 6 deletions Source/WebCore/rendering/RenderTheme.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2023 Apple Inc. All rights reserved.
* Copyright (C) 2005-2025 Apple Inc. All rights reserved.
* Copyright (C) 2014 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -1368,11 +1368,6 @@ String RenderTheme::attachmentStyleSheet() const

#endif // ENABLE(ATTACHMENT_ELEMENT)

String RenderTheme::colorInputStyleSheet() const
{
return "input[type=\"color\"] { appearance: auto; inline-size: 44px; block-size: 23px; box-sizing: border-box; outline: none; } "_s;
}

void RenderTheme::paintSliderTicks(const RenderObject& renderer, const PaintInfo& paintInfo, const FloatRect& rect)
{
RefPtr input = dynamicDowncast<HTMLInputElement>(renderer.node());
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/rendering/RenderTheme.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2024 Apple Inc. All rights reserved.
* Copyright (C) 2005-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
Expand Down Expand Up @@ -99,7 +99,6 @@ class RenderTheme {
#if ENABLE(ATTACHMENT_ELEMENT)
virtual String attachmentStyleSheet() const;
#endif
virtual String colorInputStyleSheet() const;

virtual LayoutRect adjustedPaintRect(const RenderBox&, const LayoutRect& paintRect) const { return paintRect; }

Expand Down
4 changes: 1 addition & 3 deletions Source/WebCore/rendering/ios/RenderThemeIOS.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2024 Apple Inc. All rights reserved.
* Copyright (C) 2005-2025 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -135,8 +135,6 @@ class RenderThemeIOS final : public RenderThemeCocoa {

void paintSliderTicks(const RenderObject&, const PaintInfo&, const FloatRect&) final;

String colorInputStyleSheet() const final;

void paintColorWellDecorations(const RenderObject&, const PaintInfo&, const FloatRect&) final;

void adjustSearchFieldDecorationPartStyle(RenderStyle&, const Element*) const final;
Expand Down
7 changes: 1 addition & 6 deletions Source/WebCore/rendering/ios/RenderThemeIOS.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2023 Apple Inc. All rights reserved.
* Copyright (C) 2005-2025 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -1754,11 +1754,6 @@ static void paintAttachmentBorder(GraphicsContext& context, Path& borderPath)
}
}

String RenderThemeIOS::colorInputStyleSheet() const
{
return "input[type=\"color\"] { appearance: auto; width: 28px; height: 28px; box-sizing: border-box; outline: none; border: initial; border-radius: 50%; } "_s;
}

void RenderThemeIOS::paintColorWellDecorations(const RenderObject&, const PaintInfo& paintInfo, const FloatRect& rect)
{
constexpr int strokeThickness = 3;
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/style/InspectorCSSOMWrappers.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
* Copyright (C) 2005-2025 Apple Inc. All rights reserved.
* Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
* Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
* Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
* Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
* Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
Expand Down Expand Up @@ -131,7 +131,6 @@ void InspectorCSSOMWrappers::collectDocumentWrappers(ExtensionStyleSheets& exten
#if ENABLE(FULLSCREEN_API)
collectFromStyleSheetContents(UserAgentStyle::fullscreenStyleSheet);
#endif
collectFromStyleSheetContents(UserAgentStyle::colorInputStyleSheet);
collectFromStyleSheetContents(UserAgentStyle::mediaQueryStyleSheet);

collect(extensionStyleSheets.pageUserSheet());
Expand Down
39 changes: 15 additions & 24 deletions Source/WebCore/style/UserAgentStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
* Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
* Copyright (C) 2005-2017 Apple Inc. All rights reserved.
* Copyright (C) 2005-2025 Apple Inc. All rights reserved.
* Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
* Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
* Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
Expand Down Expand Up @@ -96,7 +96,6 @@ StyleSheetContents* UserAgentStyle::imageControlsStyleSheet;
#if ENABLE(ATTACHMENT_ELEMENT)
StyleSheetContents* UserAgentStyle::attachmentStyleSheet;
#endif
StyleSheetContents* UserAgentStyle::colorInputStyleSheet;

static const MQ::MediaQueryEvaluator& screenEval()
{
Expand Down Expand Up @@ -169,7 +168,6 @@ void UserAgentStyle::initDefaultStyleSheet()
defaultQuirksStyle = &RuleSet::create().leakRef();
mediaQueryStyleSheet = &StyleSheetContents::create(CSSParserContext(UASheetMode)).leakRef();

// Strict-mode rules.
String defaultRules;
auto extraDefaultStyleSheet = RenderTheme::singleton().extraDefaultStyleSheet();
if (extraDefaultStyleSheet.isEmpty())
Expand All @@ -179,11 +177,9 @@ void UserAgentStyle::initDefaultStyleSheet()
defaultStyleSheet = parseUASheet(defaultRules);
addToDefaultStyle(*defaultStyleSheet);

// Counter rules.
counterStylesStyleSheet = parseUASheet(StringImpl::createWithoutCopying(counterStylesUserAgentStyleSheet));
addToCounterStyleRegistry(*counterStylesStyleSheet);

// Quirks-mode rules.
quirksStyleSheet = parseUASheet(StringImpl::createWithoutCopying(quirksUserAgentStyleSheet));

RuleSetBuilder quirkBuilder(*defaultQuirksStyle, screenEval());
Expand All @@ -196,10 +192,7 @@ void UserAgentStyle::ensureDefaultStyleSheetsForElement(const Element& element)
{
if (is<HTMLElement>(element)) {
if (RefPtr input = dynamicDowncast<HTMLInputElement>(element)) {
if (!colorInputStyleSheet && input->isColorControl()) {
colorInputStyleSheet = parseUASheet(RenderTheme::singleton().colorInputStyleSheet());
addToDefaultStyle(*colorInputStyleSheet);
} else if (!htmlSwitchControlStyleSheet && input->isSwitch()) {
if (!htmlSwitchControlStyleSheet && input->isSwitch()) {
htmlSwitchControlStyleSheet = parseUASheet(StringImpl::createWithoutCopying(htmlSwitchControlUserAgentStyleSheet));
addToDefaultStyle(*htmlSwitchControlStyleSheet);
}
Expand All @@ -210,43 +203,41 @@ void UserAgentStyle::ensureDefaultStyleSheetsForElement(const Element& element)
addToDefaultStyle(*attachmentStyleSheet);
}
#endif // ENABLE(ATTACHMENT_ELEMENT)

if (!popoverStyleSheet && element.document().settings().popoverAttributeEnabled() && element.hasAttributeWithoutSynchronization(popoverAttr)) {
popoverStyleSheet = parseUASheet(StringImpl::createWithoutCopying(popoverUserAgentStyleSheet));
addToDefaultStyle(*popoverStyleSheet);
}

if ((is<HTMLFormControlElement>(element) || is<HTMLMeterElement>(element) || is<HTMLProgressElement>(element)) && !element.document().settings().verticalFormControlsEnabled()) {
if (!horizontalFormControlsStyleSheet) {
horizontalFormControlsStyleSheet = parseUASheet(StringImpl::createWithoutCopying(horizontalFormControlsUserAgentStyleSheet));
addToDefaultStyle(*horizontalFormControlsStyleSheet);
}
}

} else if (is<SVGElement>(element)) {
if (!svgStyleSheet) {
// SVG rules.
svgStyleSheet = parseUASheet(StringImpl::createWithoutCopying(svgUserAgentStyleSheet));
addToDefaultStyle(*svgStyleSheet);
}
}
#if ENABLE(MATHML)
else if (is<MathMLElement>(element)) {
if (!mathMLStyleSheet) {
// MathML rules.
mathMLStyleSheet = parseUASheet(StringImpl::createWithoutCopying(mathmlUserAgentStyleSheet));
addToDefaultStyle(*mathMLStyleSheet);
}
}
#endif // ENABLE(MATHML)

bool popoverAttributeEnabled = element.document().settings().popoverAttributeEnabled();
if (!popoverStyleSheet && popoverAttributeEnabled && element.hasAttributeWithoutSynchronization(popoverAttr)) {
popoverStyleSheet = parseUASheet(StringImpl::createWithoutCopying(popoverUserAgentStyleSheet));
addToDefaultStyle(*popoverStyleSheet);
}

#if ENABLE(FULLSCREEN_API)
if (CheckedPtr fullscreenManager = element.document().fullscreenManagerIfExists(); !fullscreenStyleSheet && fullscreenManager && fullscreenManager->isFullscreen()) {
fullscreenStyleSheet = parseUASheet(StringImpl::createWithoutCopying(fullscreenUserAgentStyleSheet));
addToDefaultStyle(*fullscreenStyleSheet);
}
#endif // ENABLE(FULLSCREEN_API)

if ((is<HTMLFormControlElement>(element) || is<HTMLMeterElement>(element) || is<HTMLProgressElement>(element)) && !element.document().settings().verticalFormControlsEnabled()) {
if (!horizontalFormControlsStyleSheet) {
horizontalFormControlsStyleSheet = parseUASheet(StringImpl::createWithoutCopying(horizontalFormControlsUserAgentStyleSheet));
addToDefaultStyle(*horizontalFormControlsStyleSheet);
}
}

if (!viewTransitionsStyleSheet && element.document().settings().viewTransitionsEnabled()) {
viewTransitionsStyleSheet = parseUASheet(StringImpl::createWithoutCopying(viewTransitionsUserAgentStyleSheet));
addToDefaultStyle(*viewTransitionsStyleSheet);
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/style/UserAgentStyle.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2003-2025 Apple Inc. All rights reserved.
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -57,7 +57,6 @@ class UserAgentStyle {
#if ENABLE(ATTACHMENT_ELEMENT)
static StyleSheetContents* attachmentStyleSheet;
#endif
static StyleSheetContents* colorInputStyleSheet;

static void initDefaultStyleSheet();
static void ensureDefaultStyleSheetsForElement(const Element&);
Expand Down

0 comments on commit 384d445

Please sign in to comment.