Changeset 284626 in webkit


Ignore:
Timestamp:
Oct 21, 2021 11:05:21 AM (9 months ago)
Author:
Aditya Keerthi
Message:

[macOS] Update appearance of <datalist> indicator
https://bugs.webkit.org/show_bug.cgi?id=232031
rdar://84474135

Reviewed by Wenson Hsieh.

Source/WebCore:

  • rendering/RenderThemeMac.mm:

(WebCore::RenderThemeMac::paintListButtonForInput):

Use CoreUI to paint the indicator on Big Sur and Monterey.

Source/WebCore/PAL:

  • pal/spi/mac/CoreUISPI.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r284624 r284626  
     12021-10-21  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        [macOS] Update appearance of <datalist> indicator
     4        https://bugs.webkit.org/show_bug.cgi?id=232031
     5        rdar://84474135
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * rendering/RenderThemeMac.mm:
     10        (WebCore::RenderThemeMac::paintListButtonForInput):
     11
     12        Use CoreUI to paint the indicator on Big Sur and Monterey.
     13
    1142021-10-21  Devin Rousso  <drousso@apple.com>
    215
  • trunk/Source/WebCore/PAL/ChangeLog

    r284544 r284626  
     12021-10-21  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        [macOS] Update appearance of <datalist> indicator
     4        https://bugs.webkit.org/show_bug.cgi?id=232031
     5        rdar://84474135
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * pal/spi/mac/CoreUISPI.h:
     10
    1112021-10-20  Ross Kirsling  <ross.kirsling@sony.com>
    212
  • trunk/Source/WebCore/PAL/pal/spi/mac/CoreUISPI.h

    r265860 r284626  
    6969extern const CFStringRef kCUIWidgetProgressBar;
    7070extern const CFStringRef kCUIWidgetScrollBarTrackCorner;
     71#if HAVE(LARGE_CONTROL_SIZE)
     72extern const CFStringRef kCUIWidgetButtonComboBox;
     73#endif
    7174
    7275#endif
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r284453 r284626  
    989989    // We can't paint an NSComboBoxCell since they are not height-resizable.
    990990    const auto& input = downcast<HTMLInputElement>(*(o.generatingNode()));
     991
     992#if HAVE(LARGE_CONTROL_SIZE)
     993    LocalDefaultSystemAppearance localAppearance(o.useDarkAppearance(), o.style().effectiveAccentColor());
     994
     995    const FloatSize comboBoxSize { 40, 19 };
     996    const FloatSize comboBoxButtonSize { 16, 16 };
     997    const FloatPoint comboBoxButtonInset { 5, 1 };
     998    constexpr auto comboBoxButtonCornerRadii = 4;
     999
     1000    const FloatSize desiredComboBoxButtonSize { 12, 12 };
     1001    constexpr auto desiredComboBoxInset = 2;
     1002
     1003    float deviceScaleFactor = o.document().deviceScaleFactor();
     1004
     1005    auto comboBoxImageBuffer = ImageBuffer::createCompatibleBuffer(comboBoxSize, deviceScaleFactor, DestinationColorSpace::SRGB(), context);
     1006    if (!comboBoxImageBuffer)
     1007        return;
     1008
     1009    ContextContainer cgContextContainer(comboBoxImageBuffer->context());
     1010    CGContextRef cgContext = cgContextContainer.context();
     1011
     1012    NSString *coreUIState;
     1013    if (input.isPresentingAttachedView())
     1014        coreUIState = (__bridge NSString *)kCUIStatePressed;
     1015    else if (auto* buttonElement = input.dataListButtonElement())
     1016        coreUIState = (__bridge NSString *)(buttonElement->active() ? kCUIStatePressed : kCUIStateActive);
     1017    else
     1018        coreUIState = (__bridge NSString *)kCUIStateActive;
     1019
     1020    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     1021    [[NSAppearance currentAppearance] _drawInRect:NSMakeRect(0, 0, comboBoxSize.width(), comboBoxSize.height()) context:cgContext options:@{
     1022    ALLOW_DEPRECATED_DECLARATIONS_END
     1023        (__bridge NSString *)kCUIWidgetKey : (__bridge NSString *)kCUIWidgetButtonComboBox,
     1024        (__bridge NSString *)kCUISizeKey : (__bridge NSString *)kCUISizeRegular,
     1025        (__bridge NSString *)kCUIStateKey : coreUIState,
     1026        (__bridge NSString *)kCUIUserInterfaceLayoutDirectionKey : (__bridge NSString *)kCUIUserInterfaceLayoutDirectionLeftToRight,
     1027    }];
     1028
     1029    auto comboBoxButtonImageBuffer = ImageBuffer::createCompatibleBuffer(desiredComboBoxButtonSize, deviceScaleFactor, DestinationColorSpace::SRGB(), context);
     1030    if (!comboBoxButtonImageBuffer)
     1031        return;
     1032
     1033    auto& comboBoxButtonContext = comboBoxButtonImageBuffer->context();
     1034
     1035    comboBoxButtonContext.scale(desiredComboBoxButtonSize.width() / comboBoxButtonSize.width());
     1036    comboBoxButtonContext.clipRoundedRect(FloatRoundedRect(FloatRect(FloatPoint::zero(), comboBoxButtonSize), FloatRoundedRect::Radii(comboBoxButtonCornerRadii)));
     1037    comboBoxButtonContext.translate(comboBoxButtonInset.scaled(-1));
     1038    comboBoxButtonContext.drawConsumingImageBuffer(WTFMove(comboBoxImageBuffer), FloatPoint::zero(), ImagePaintingOptions { ImageOrientation::OriginBottomRight });
     1039
     1040    FloatPoint listButtonLocation;
     1041    float listButtonY = r.center().y() - desiredComboBoxButtonSize.height() / 2;
     1042    if (o.style().isLeftToRightDirection())
     1043        listButtonLocation = { r.maxX() - desiredComboBoxButtonSize.width() - desiredComboBoxInset, listButtonY };
     1044    else
     1045        listButtonLocation = { r.x() + desiredComboBoxInset, listButtonY };
     1046
     1047    GraphicsContextStateSaver stateSaver(context);
     1048    context.drawConsumingImageBuffer(WTFMove(comboBoxButtonImageBuffer), listButtonLocation);
     1049#else
    9911050    NSCell *listButton = this->listButton();
    9921051
     
    10211080
    10221081    context.drawImage(*image, imageRect);
     1082#endif // HAVE(LARGE_CONTROL_SIZE)
    10231083}
    10241084
Note: See TracChangeset for help on using the changeset viewer.