Changeset 283858 in webkit


Ignore:
Timestamp:
Oct 8, 2021 6:39:28 PM (9 months ago)
Author:
Aditya Keerthi
Message:

Add support for '-webkit-appearance: auto'
https://bugs.webkit.org/show_bug.cgi?id=231203
rdar://83696133

Reviewed by Wenson Hsieh.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt:

Mark progression.

Source/WebCore:

The 'appearance' property allows authors to use the 'auto' keyword
to opt widgets (any element that can have a native appearance) into
a native appearance [1]. Elements other than widgets are rendered
as if none had been specified.

Since '-webkit-appearance' is a parse time alias of 'appearance',
support '-webkit-appearance: auto' prior to unprefixing.

The used-value for appearance (effectiveAppearance) is determined by
the element tag and type. In the case of elements in the UA shadow
tree, the pseudo id is used to determine the effective appearance. The
used-values when specifying 'auto' match the default specified values
in the UA style sheet.

Note that additional test coverage exists in the form of web platform
web platform tests, and is dependent on unprefixing.

[1] https://www.w3.org/TR/css-ui-4/#valdef-appearance-auto

  • css/CSSPrimitiveValueMappings.h:

(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::operator ControlPart const):

  • css/CSSProperties.json:
  • css/parser/CSSParserFastPaths.cpp:

(WebCore::CSSParserFastPaths::isValidKeywordPropertyAndValue):

  • platform/ThemeTypes.cpp:

(WebCore::operator<<):

  • platform/ThemeTypes.h:
  • rendering/RenderTheme.cpp:

(WebCore::RenderTheme::adjustStyle):
(WebCore::RenderTheme::autoAppearanceForElement const):

  • rendering/RenderTheme.h:

LayoutTests:

  • platform/gtk/imported/w3c/web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt:
  • platform/ios-wk2/imported/w3c/web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt:
  • platform/wpe/imported/w3c/web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt:
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r283836 r283858  
     12021-10-08  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        Add support for '-webkit-appearance: auto'
     4        https://bugs.webkit.org/show_bug.cgi?id=231203
     5        rdar://83696133
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * platform/gtk/imported/w3c/web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt:
     10        * platform/ios-wk2/imported/w3c/web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt:
     11        * platform/wpe/imported/w3c/web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt:
     12
    1132021-10-08  Ayumi Kojima  <ayumi_kojima@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r283825 r283858  
     12021-10-08  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        Add support for '-webkit-appearance: auto'
     4        https://bugs.webkit.org/show_bug.cgi?id=231203
     5        rdar://83696133
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt:
     10
     11        Mark progression.
     12
    1132021-10-08  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt

    r283269 r283858  
    22
    33PASS -webkit-appearance: none
    4 FAIL -webkit-appearance: auto assert_equals: style.WebkitAppearance (uppercase W) expected "auto" but got ""
     4PASS -webkit-appearance: auto
    55PASS -webkit-appearance: button
    66PASS -webkit-appearance: checkbox
  • trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt

    r283269 r283858  
    22
    33PASS -webkit-appearance: none
    4 FAIL -webkit-appearance: auto assert_equals: style.WebkitAppearance (uppercase W) expected "auto" but got ""
     4PASS -webkit-appearance: auto
    55PASS -webkit-appearance: button
    66PASS -webkit-appearance: checkbox
  • trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt

    r283269 r283858  
    22
    33PASS -webkit-appearance: none
    4 FAIL -webkit-appearance: auto assert_equals: style.WebkitAppearance (uppercase W) expected "auto" but got ""
     4PASS -webkit-appearance: auto
    55PASS -webkit-appearance: button
    66PASS -webkit-appearance: checkbox
  • trunk/LayoutTests/platform/wpe/imported/w3c/web-platform-tests/css/css-ui/appearance-cssom-001-expected.txt

    r283269 r283858  
    22
    33PASS -webkit-appearance: none
    4 FAIL -webkit-appearance: auto assert_equals: style.WebkitAppearance (uppercase W) expected "auto" but got ""
     4PASS -webkit-appearance: auto
    55PASS -webkit-appearance: button
    66PASS -webkit-appearance: checkbox
  • trunk/Source/WebCore/ChangeLog

    r283857 r283858  
     12021-10-08  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        Add support for '-webkit-appearance: auto'
     4        https://bugs.webkit.org/show_bug.cgi?id=231203
     5        rdar://83696133
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        The 'appearance' property allows authors to use the 'auto' keyword
     10        to opt widgets (any element that can have a native appearance) into
     11        a native appearance [1]. Elements other than widgets are rendered
     12        as if none had been specified.
     13
     14        Since '-webkit-appearance' is a parse time alias of 'appearance',
     15        support '-webkit-appearance: auto' prior to unprefixing.
     16
     17        The used-value for appearance (effectiveAppearance) is determined by
     18        the element tag and type. In the case of elements in the UA shadow
     19        tree, the pseudo id is used to determine the effective appearance. The
     20        used-values when specifying 'auto' match the default specified values
     21        in the UA style sheet.
     22
     23        Note that additional test coverage exists in the form of web platform
     24        web platform tests, and is dependent on unprefixing.
     25
     26        [1] https://www.w3.org/TR/css-ui-4/#valdef-appearance-auto
     27
     28        * css/CSSPrimitiveValueMappings.h:
     29        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
     30        (WebCore::CSSPrimitiveValue::operator ControlPart const):
     31        * css/CSSProperties.json:
     32        * css/parser/CSSParserFastPaths.cpp:
     33        (WebCore::CSSParserFastPaths::isValidKeywordPropertyAndValue):
     34        * platform/ThemeTypes.cpp:
     35        (WebCore::operator<<):
     36        * platform/ThemeTypes.h:
     37        * rendering/RenderTheme.cpp:
     38        (WebCore::RenderTheme::adjustStyle):
     39        (WebCore::RenderTheme::autoAppearanceForElement const):
     40        * rendering/RenderTheme.h:
     41
    1422021-10-08  BJ Burg  <bburg@apple.com>
    243
  • trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h

    r283279 r283858  
    424424        m_value.valueID = CSSValueNone;
    425425        break;
     426    case AutoPart:
     427        m_value.valueID = CSSValueAuto;
     428        break;
    426429    case CheckboxPart:
    427430        m_value.valueID = CSSValueCheckbox;
     
    630633    if (m_value.valueID == CSSValueNone)
    631634        return NoControlPart;
    632     return ControlPart(m_value.valueID - CSSValueCheckbox + 1);
     635
     636    if (m_value.valueID == CSSValueAuto)
     637        return AutoPart;
     638
     639    return ControlPart(m_value.valueID - CSSValueCheckbox + CheckboxPart);
    633640}
    634641
  • trunk/Source/WebCore/css/CSSProperties.json

    r283742 r283858  
    50045004                "color-well",
    50055005                "list-button",
     5006                "auto",
    50065007                "none"
    50075008            ],
  • trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp

    r283742 r283858  
    755755        return valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueCollapse;
    756756    case CSSPropertyWebkitAppearance:
    757         return (valueID >= CSSValueCheckbox && valueID <= CSSValueCapsLockIndicator) || valueID == CSSValueNone;
     757        return (valueID >= CSSValueCheckbox && valueID <= CSSValueCapsLockIndicator) || valueID == CSSValueNone || valueID == CSSValueAuto;
    758758    case CSSPropertyBackfaceVisibility:
    759759        return valueID == CSSValueVisible || valueID == CSSValueHidden;
  • trunk/Source/WebCore/platform/ThemeTypes.cpp

    r272117 r283858  
    3535    switch (controlPart) {
    3636    case NoControlPart: ts << "no-control-part"; break;
     37    case AutoPart: ts << "auto-part"; break;
    3738    case CheckboxPart: ts << "checkbox-part"; break;
    3839    case RadioPart: ts << "radio-part"; break;
  • trunk/Source/WebCore/platform/ThemeTypes.h

    r272117 r283858  
    3535enum ControlPart {
    3636    NoControlPart,
     37    AutoPart,
    3738    CheckboxPart,
    3839    RadioPart,
  • trunk/Source/WebCore/rendering/RenderTheme.cpp

    r283269 r283858  
    3535#include "FrameSelection.h"
    3636#include "GraphicsContext.h"
     37#include "HTMLAttachmentElement.h"
     38#include "HTMLButtonElement.h"
    3739#include "HTMLInputElement.h"
    3840#include "HTMLMeterElement.h"
    3941#include "HTMLNames.h"
     42#include "HTMLProgressElement.h"
     43#include "HTMLSelectElement.h"
     44#include "HTMLTextAreaElement.h"
    4045#include "LocalizedStrings.h"
    4146#include "Page.h"
     
    4550#include "RenderView.h"
    4651#include "RuntimeEnabledFeatures.h"
     52#include "ShadowPseudoIds.h"
    4753#include "SpinButtonElement.h"
    4854#include "StringTruncator.h"
     
    7884void RenderTheme::adjustStyle(RenderStyle& style, const Element* element, const RenderStyle* userAgentAppearanceStyle)
    7985{
     86    auto part = style.appearance();
     87    if (part == AutoPart) {
     88        part = autoAppearanceForElement(element);
     89        if (part == NoControlPart) {
     90            style.setEffectiveAppearance(NoControlPart);
     91            return;
     92        }
     93    }
     94
    8095    // Force inline and table display styles to be inline-block (except for table- which is block)
    81     ControlPart part = style.appearance();
    8296    if (style.display() == DisplayType::Inline || style.display() == DisplayType::InlineTable || style.display() == DisplayType::TableRowGroup
    8397        || style.display() == DisplayType::TableHeaderGroup || style.display() == DisplayType::TableFooterGroup
     
    91105        switch (part) {
    92106        case MenulistPart:
    93             style.setEffectiveAppearance(MenulistButtonPart);
    94107            part = MenulistButtonPart;
    95108            break;
    96109        default:
    97             style.setEffectiveAppearance(NoControlPart);
     110            part = NoControlPart;
    98111            break;
    99112        }
    100113    }
     114
     115    ASSERT(part != AutoPart);
     116    style.setEffectiveAppearance(part);
    101117
    102118    if (!style.hasEffectiveAppearance())
     
    192208
    193209    // Call the appropriate style adjustment method based off the appearance value.
    194     switch (style.effectiveAppearance()) {
     210    switch (part) {
    195211#if !USE(NEW_THEME)
    196212    case CheckboxPart:
     
    269285        break;
    270286    }
     287}
     288
     289ControlPart RenderTheme::autoAppearanceForElement(const Element* elementPtr) const
     290{
     291    if (!elementPtr)
     292        return NoControlPart;
     293
     294    Ref element = *elementPtr;
     295
     296    if (is<HTMLInputElement>(element)) {
     297        auto& input = downcast<HTMLInputElement>(element.get());
     298
     299        if (input.isTextButton() || input.isUploadButton())
     300            return PushButtonPart;
     301
     302        if (input.isCheckbox())
     303            return CheckboxPart;
     304
     305        if (input.isRadioButton())
     306            return RadioPart;
     307
     308        if (input.isSearchField())
     309            return SearchFieldPart;
     310
     311        if (input.isDateField() || input.isDateTimeLocalField() || input.isMonthField() || input.isTimeField() || input.isWeekField()) {
     312#if PLATFORM(IOS_FAMILY)
     313            return MenulistButtonPart;
     314#else
     315            return TextFieldPart;
     316#endif
     317        }
     318
     319#if ENABLE(INPUT_TYPE_COLOR)
     320        if (input.isColorControl())
     321            return ColorWellPart;
     322#endif
     323
     324        if (input.isRangeControl())
     325            return SliderHorizontalPart;
     326
     327        if (input.isTextField())
     328            return TextFieldPart;
     329
     330        // <input type=hidden|image|file>
     331        return NoControlPart;
     332    }
     333
     334    if (is<HTMLButtonElement>(element))
     335        return ButtonPart;
     336
     337    if (is<HTMLSelectElement>(element)) {
     338#if PLATFORM(IOS_FAMILY)
     339        return MenulistButtonPart;
     340#else
     341        auto& select = downcast<HTMLSelectElement>(element.get());
     342        return select.usesMenuList() ? MenulistPart : ListboxPart;
     343#endif
     344    }
     345
     346    if (is<HTMLTextAreaElement>(element))
     347        return TextAreaPart;
     348
     349    if (is<HTMLMeterElement>(element))
     350        return MeterPart;
     351
     352    if (is<HTMLProgressElement>(element))
     353        return ProgressBarPart;
     354
     355#if ENABLE(ATTACHMENT_ELEMENT)
     356    if (is<HTMLAttachmentElement>(element))
     357        return AttachmentPart;
     358#endif
     359
     360    if (element->isInUserAgentShadowTree()) {
     361        auto& pseudo = element->shadowPseudoId();
     362
     363#if ENABLE(DATALIST_ELEMENT)
     364        if (pseudo == ShadowPseudoIds::webkitListButton())
     365            return ListButtonPart;
     366#endif
     367
     368        if (pseudo == ShadowPseudoIds::webkitCapsLockIndicator())
     369            return CapsLockIndicatorPart;
     370
     371        if (pseudo == ShadowPseudoIds::webkitSearchCancelButton())
     372            return SearchFieldCancelButtonPart;
     373
     374        if (pseudo == ShadowPseudoIds::webkitSearchDecoration())
     375            return SearchFieldDecorationPart;
     376
     377        if (pseudo == ShadowPseudoIds::webkitSearchResultsDecoration())
     378            return SearchFieldResultsDecorationPart;
     379
     380        if (pseudo == ShadowPseudoIds::webkitSearchResultsButton())
     381            return SearchFieldResultsButtonPart;
     382
     383        if (pseudo == ShadowPseudoIds::webkitSliderThumb() || pseudo == ShadowPseudoIds::webkitMediaSliderThumb())
     384            return SliderThumbHorizontalPart;
     385
     386        if (pseudo == ShadowPseudoIds::webkitInnerSpinButton())
     387            return InnerSpinButtonPart;
     388    }
     389
     390    return NoControlPart;
    271391}
    272392
  • trunk/Source/WebCore/rendering/RenderTheme.h

    r279002 r283858  
    455455
    456456private:
     457    ControlPart autoAppearanceForElement(const Element*) const;
     458
    457459    void adjustSearchFieldDecorationStyle(RenderStyle&, const Element*) const;
    458460
Note: See TracChangeset for help on using the changeset viewer.