Provide a way for web developers to draw a Theme-specific Wireless Playback icon
https://bugs.webkit.org/show_bug.cgi?id=146123
<rdar://problem/21119287>
Reviewed by Simon Fraser.
Source/WebCore:
Implement a -webkit-named-image() CSS <image> generator that allows a site to
request artwork by name and get the platform variant. At the moment
we only support "wireless-playback" which returns a generic image everywhere
but Cocoa platforms, where we render the AirPlay icon.
In order to do this I added a ThemeCocoa to share any Theme code between
Mac and iOS.
Test: fast/css/named-icons.html
- WebCore.xcodeproj/project.pbxproj: Add new files CSSNamedImageValue, NamedImageGeneratedImage and ThemeCocoa.
- css/CSSImageGeneratorValue.cpp: Handle the new NamedImageClass in the switch statements for downcasting.
(WebCore::CSSImageGeneratorValue::image):
(WebCore::CSSImageGeneratorValue::isFixedSize):
(WebCore::CSSImageGeneratorValue::isPending):
(WebCore::CSSImageGeneratorValue::knownToBeOpaque):
- css/CSSNamedImageValue.cpp: New class. Just holds a name String.
(WebCore::CSSNamedImageValue::customCSSText):
(WebCore::CSSNamedImageValue::image):
(WebCore::CSSNamedImageValue::equals):
- css/CSSNamedImageValue.h:
(WebCore::CSSNamedImageValue::create):
(WebCore::CSSNamedImageValue::isFixedSize):
(WebCore::CSSNamedImageValue::isPending):
(WebCore::CSSNamedImageValue::CSSNamedImageValue):
(WebCore::CSSParser::isGeneratedImageValue): Allow "-webkit-named-image(".
(WebCore::CSSParser::parseGeneratedImage): Call parseNamedImage if we hit named-icon.
(WebCore::CSSParser::parseNamedImage): Parse the function looking for a CSS ident.
- css/CSSValue.cpp: Handle NamedImageClass in the various switch statements.
(WebCore::CSSValue::equals):
(WebCore::CSSValue::cssText):
(WebCore::CSSValue::destroy):
(WebCore::CSSValue::isNamedImageValue): Helper to detect the correct CSSValue subclass.
(WebCore::Theme::drawNamedImage): Draw a generic wireless playback icon.
- platform/Theme.h: Add drawNamedImage.
- platform/cocoa/ThemeCocoa.cpp: New shared base class for ThemeMac and ThemeIOS.
(WebCore::fitContextToBox):
(WebCore::ThemeCocoa::drawNamedImage): Draw an AirPlay icon for wireless playback.
- platform/cocoa/ThemeCocoa.h:
- platform/graphics/CrossfadeGeneratedImage.h: Drive-by removal of unnecessary forward class definition.
- platform/graphics/ImageBuffer.h: Add NamedImageGeneratedImage as a friend class.
- platform/graphics/NamedImageGeneratedImage.cpp: New class. Calls into the Theme to render the artwork.
(WebCore::NamedImageGeneratedImage::NamedImageGeneratedImage):
(WebCore::NamedImageGeneratedImage::draw):
(WebCore::NamedImageGeneratedImage::drawPattern):
- platform/graphics/NamedImageGeneratedImage.h:
- platform/ios/ThemeIOS.h: Inherit from ThemeCocoa.
- platform/mac/ThemeMac.h: Ditto.
LayoutTests:
Test the new -webkit-named-image CSS generator. Only "wireless-playback"
is supported for now, and has platform-specific results for Cocoa.
- fast/css/named-images-expected.png: Added.
- fast/css/named-images.html: Added.
- platform/mac/fast/css/named-images-expected.png: Added.
- platform/mac/fast/css/named-images-expected.txt: Added.