-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for icon_variants in Web Extensions. #32970
Conversation
EWS run on previous version of this PR (hash cdc3104) |
EWS run on previous version of this PR (hash 1929400) |
EWS run on previous version of this PR (hash 7418be7) |
EWS run on previous version of this PR (hash 365ce56) |
// The returned image retains its link to the image asset and adapts to trait changes, | ||
// automatically displaying the correct variant based on the current traits. | ||
return [imageAsset imageWithTraitCollection:UITraitCollection.currentTraitCollection]; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// ! USE(APPKIT)
} | ||
|
||
#if ENABLE(WK_WEB_EXTENSIONS_ICON_VARIANTS) | ||
static OptionSet<WebExtension::ColorScheme> toColorSchemes(id value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not make the argument NSArray *
? are we expecting this method to be called with other types in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might not be an array, and that case is treated as invalid, per the proposal. Instead of type checking at the call site, I type check inside here.
Incorrectly typed
color_schemes
values will be ignored, with an optional warning.
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/xcshareddata/xcschemes/TestWebKitAPI.xcscheme
Show resolved
Hide resolved
EWS run on current version of this PR (hash 6efdad3) |
https://webkit.org/b/278818 rdar://problem/134885372 Reviewed by Brian Weinstein. Add support for `icon_variants` manifest parsing under the `WK_WEB_EXTENSIONS_ICON_VARIANTS` flag, with optimizations to ensure efficient icon loading. This change introduces `icon_variants` manifest parsing, explicitly supporting different icon sets, such as dark mode icons. To achieve this efficiently, icons are now cached by size, reducing disk I/O by avoiding repeated loads when the browser frequently requests the same icon. The cache is automatically invalidated when device scales change, such as when connecting or disconnecting a display with a different scale factor. Only the necessary icons are loaded based on the specific scale factor of all screens, halving the image loads compared to previous behavior. This ensures that even as more extensions adopt dark mode icons, typical image loads remain at two images (light and dark). Proposal: https://github.com/w3c/webextensions/blob/main/proposals/dark_mode_extension_icons.md WECG issue: w3c/webextensions#229 * Source/WTF/wtf/PlatformEnableCocoa.h: Added ENABLE_WK_WEB_EXTENSIONS_ICON_VARIANTS. * Source/WebCore/en.lproj/Localizable.strings: Updated. * Source/WebKit/Platform/cocoa/CocoaHelpers.h: * Source/WebKit/Platform/cocoa/CocoaHelpers.mm: (WebKit::availableScreenScales): Added. (WebKit::largestDisplayScale): Added. * Source/WebKit/Platform/spi/ios/UIKitSPI.h: * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionActionCocoa.mm: (WebKit::WebExtensionAction::icon): * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionCocoa.mm: (WebKit::WebExtension::icon): (WebKit::WebExtension::actionIcon): (WebKit::WebExtension::populateActionPropertiesIfNeeded): (WebKit::WebExtension::populateSidebarActionProperties): (WebKit::WebExtension::populateSidePanelProperties): (WebKit::WebExtension::imageForPath): (WebKit::WebExtension::bestSizeInIconsDictionary): Added. (WebKit::WebExtension::pathForBestImageInIconsDictionary): (WebKit::WebExtension::bestImageInIconsDictionary): (WebKit::WebExtension::bestImageForIconsDictionaryManifestKey): (WebKit::toColorSchemes): Added. (WebKit::WebExtension::iconsDictionaryForBestIconVariant): Added. (WebKit::WebExtension::bestImageForIconVariants): Added. (WebKit::WebExtension::bestImageForIconVariantsManifestKey): Added. * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionMenuItemCocoa.mm: (WebKit::WebExtensionMenuItem::icon const): * Source/WebKit/UIProcess/Extensions/WebExtension.h: * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtension.mm: (TestWebKitAPI::TEST(WKWebExtension, MultipleIconVariants)): Added. (TestWebKitAPI::TEST(WKWebExtension, SingleIconVariant)): Added. (TestWebKitAPI::TEST(WKWebExtension, AnySizeIconVariant)): Added. (TestWebKitAPI::TEST(WKWebExtension, NoIconVariants)): Added. (TestWebKitAPI::TEST(WKWebExtension, IconsAndIconVariantsSpecified)): Added. (TestWebKitAPI::TEST(WKWebExtension, ActionIconVariantsMultiple)): Added. (TestWebKitAPI::TEST(WKWebExtension, ActionIconSingleVariant)): Added. (TestWebKitAPI::TEST(WKWebExtension, ActionIconAnySizeVariant)): Added. (TestWebKitAPI::TEST(WKWebExtension, ActionNoIconVariants)): Added. (TestWebKitAPI::TEST(WKWebExtension, ActionIconsAndIconVariantsSpecified)): Added. * Tools/TestWebKitAPI/cocoa/WebExtensionUtilities.h: * Tools/TestWebKitAPI/cocoa/WebExtensionUtilities.mm: (TestWebKitAPI::Util::performWithAppearance): Added. (TestWebKitAPI::Util::pixelColor): Added. (TestWebKitAPI::Util::toSRGBColor): Added. (TestWebKitAPI::Util::compareColors): Added. Canonical link: https://commits.webkit.org/283118@main
6efdad3
to
56a9103
Compare
Committed 283118@main (56a9103): https://commits.webkit.org/283118@main Reviewed commits have been landed. Closing PR #32970 and removing active labels. |
56a9103
6efdad3
🛠 wpe🛠 wincairo🧪 wpe-wk2🧪 wincairo-tests🧪 ios-wk2🧪 api-mac🧪 api-wpe🧪 ios-wk2-wpt🧪 mac-wk1🛠 wpe-cairo🛠 🧪 jsc🧪 api-ios🧪 mac-wk2🛠 gtk🧪 mac-AS-debug-wk2🧪 gtk-wk2🧪 mac-wk2-stress🧪 api-gtk🧪 vision-wk2🧪 mac-intel-wk2🛠 tv🧪 jsc-armv7-tests🛠 tv-sim🛠 watch