Diff
Modified: trunk/LayoutTests/media/modern-media-controls/icon-service/icon-service-expected.txt (207422 => 207423)
--- trunk/LayoutTests/media/modern-media-controls/icon-service/icon-service-expected.txt 2016-10-17 19:17:36 UTC (rev 207422)
+++ trunk/LayoutTests/media/modern-media-controls/icon-service/icon-service-expected.txt 2016-10-17 19:54:04 UTC (rev 207423)
@@ -4,9 +4,9 @@
Checking path to images is computed according to traits
-PASS iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS).includes("macOS/pause") is true
-PASS iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.iOS).includes("iOS/pause") is true
-PASS iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS | LayoutTraits.Fullscreen).includes("macOS/pause-fullscreen") is true
+PASS iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS).src.includes("macOS/pause@") is true
+PASS iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.iOS).src.includes("iOS/pause@") is true
+PASS iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS | LayoutTraits.Fullscreen).src.includes("macOS/pause-fullscreen@") is true
Checking requested images are cached
PASS iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS) === iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS) is true
Modified: trunk/LayoutTests/media/modern-media-controls/icon-service/icon-service.html (207422 => 207423)
--- trunk/LayoutTests/media/modern-media-controls/icon-service/icon-service.html 2016-10-17 19:17:36 UTC (rev 207422)
+++ trunk/LayoutTests/media/modern-media-controls/icon-service/icon-service.html 2016-10-17 19:54:04 UTC (rev 207423)
@@ -10,9 +10,9 @@
iconService.directoryPath = "../../../../Source/WebCore/Modules/modern-media-controls/images";
debug("Checking path to images is computed according to traits");
-shouldBeTrue('iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS).includes("macOS/pause")');
-shouldBeTrue('iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.iOS).includes("iOS/pause")');
-shouldBeTrue('iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS | LayoutTraits.Fullscreen).includes("macOS/pause-fullscreen")');
+shouldBeTrue('iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS).src.includes("macOS/pause@")');
+shouldBeTrue('iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.iOS).src.includes("iOS/pause@")');
+shouldBeTrue('iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS | LayoutTraits.Fullscreen).src.includes("macOS/pause-fullscreen@")');
debug("");
debug("Checking requested images are cached");
Modified: trunk/Source/WebCore/ChangeLog (207422 => 207423)
--- trunk/Source/WebCore/ChangeLog 2016-10-17 19:17:36 UTC (rev 207422)
+++ trunk/Source/WebCore/ChangeLog 2016-10-17 19:54:04 UTC (rev 207423)
@@ -1,5 +1,32 @@
2016-10-17 Antoine Quint <grao...@apple.com>
+ [Modern Media Controls] Add a MediaControlsHost API to retrieve images as base64
+ https://bugs.webkit.org/show_bug.cgi?id=163502
+ <rdar://problem/28792017>
+
+ Reviewed by Darin Adler.
+
+ Add a new `base64StringForIconAndPlatform()` method to MediaControlsHost such that we
+ may load images from the modern-media-controls directory in the WebCore.framework bundle.
+ We use this new method in the iconService singleton when a `mediaControlsHost` is set,
+ which will be set in a later patch.
+
+ * Modules/mediacontrols/MediaControlsHost.cpp:
+ (WebCore::MediaControlsHost::base64StringForIconAndPlatform):
+ * Modules/mediacontrols/MediaControlsHost.h:
+ * Modules/mediacontrols/MediaControlsHost.idl:
+ * Modules/modern-media-controls/controls/icon-service.js:
+ (const.iconService.new.IconService.prototype.urlForIconNameAndLayoutTraits):
+ (const.iconService.new.IconService):
+ * rendering/RenderTheme.h:
+ (WebCore::RenderTheme::mediaControlsBase64StringForIconAndPlatform):
+ (WebCore::RenderTheme::mediaControlsScript): Deleted.
+ * rendering/RenderThemeMac.h:
+ * rendering/RenderThemeMac.mm:
+ (WebCore::RenderThemeMac::mediaControlsBase64StringForIconAndPlatform):
+
+2016-10-17 Antoine Quint <grao...@apple.com>
+
[Modern Media Controls] Add a MediaControlsHost API to retrieve the shadow root CSS
https://bugs.webkit.org/show_bug.cgi?id=163501
<rdar://problem/28792014>
Modified: trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp (207422 => 207423)
--- trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp 2016-10-17 19:17:36 UTC (rev 207422)
+++ trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp 2016-10-17 19:54:04 UTC (rev 207423)
@@ -292,6 +292,14 @@
return RenderTheme::themeForPage(page)->mediaControlsStyleSheet();
}
+String MediaControlsHost::base64StringForIconAndPlatform(const String& iconName, const String& platform) const
+{
+ Page* page = m_mediaElement->document().page();
+ if (!page)
+ return emptyString();
+ return RenderTheme::themeForPage(page)->mediaControlsBase64StringForIconAndPlatform(iconName, platform);
}
+}
+
#endif
Modified: trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h (207422 => 207423)
--- trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h 2016-10-17 19:17:36 UTC (rev 207422)
+++ trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h 2016-10-17 19:54:04 UTC (rev 207423)
@@ -83,6 +83,7 @@
String generateUUID() const;
String shadowRootCSSText() const;
+ String base64StringForIconAndPlatform(const String& iconName, const String& platform) const;
private:
MediaControlsHost(HTMLMediaElement*);
Modified: trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl (207422 => 207423)
--- trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl 2016-10-17 19:17:36 UTC (rev 207422)
+++ trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl 2016-10-17 19:54:04 UTC (rev 207423)
@@ -61,4 +61,5 @@
DOMString generateUUID();
[EnabledAtRuntime=ModernMediaControls] readonly attribute DOMString shadowRootCSSText;
+ [EnabledAtRuntime=ModernMediaControls] DOMString base64StringForIconAndPlatform(DOMString iconName, DOMString platform);
};
Modified: trunk/Source/WebCore/Modules/modern-media-controls/controls/icon-service.js (207422 => 207423)
--- trunk/Source/WebCore/Modules/modern-media-controls/controls/icon-service.js 2016-10-17 19:17:36 UTC (rev 207422)
+++ trunk/Source/WebCore/Modules/modern-media-controls/controls/icon-service.js 2016-10-17 19:54:04 UTC (rev 207423)
@@ -52,20 +52,30 @@
this.images = {};
}
+ // Public
+
imageForIconNameAndLayoutTraits(iconName, layoutTraits)
{
- const path = this.urlForIconNameAndLayoutTraits(iconName, layoutTraits);
-
+ const [fileName, platform] = this._fileNameAndPlatformForIconNameAndLayoutTraits(iconName, layoutTraits);
+ const path = `${platform}/${fileName}.png`;
+
let image = this.images[path];
if (image)
return image;
image = this.images[path] = new Image;
- image.src = ""
+
+ if (this.mediaControlsHost)
+ image.src = "" + this.mediaControlsHost.base64StringForIconAndPlatform(fileName, platform);
+ else
+ image.src = ""
+
return image;
}
- urlForIconNameAndLayoutTraits(iconName, layoutTraits)
+ // Private
+
+ _fileNameAndPlatformForIconNameAndLayoutTraits(iconName, layoutTraits)
{
let platform;
if (layoutTraits & LayoutTraits.macOS)
@@ -78,7 +88,9 @@
if (layoutTraits & LayoutTraits.Fullscreen && IconsWithFullScreenVariants.includes(iconName))
iconName += "-fullscreen";
- return `${this.directoryPath}/${platform}/${iconName}@${window.devicePixelRatio}x.png`;
+ const fileName = `${iconName}@${window.devicePixelRatio}x`;
+
+ return [fileName, platform];
}
};
Modified: trunk/Source/WebCore/Modules/modern-media-controls/controls/start-button.js (207422 => 207423)
--- trunk/Source/WebCore/Modules/modern-media-controls/controls/start-button.js 2016-10-17 19:17:36 UTC (rev 207422)
+++ trunk/Source/WebCore/Modules/modern-media-controls/controls/start-button.js 2016-10-17 19:54:04 UTC (rev 207423)
@@ -36,7 +36,7 @@
background.className = "background";
const image = this.element.appendChild(new Image);
- image.src = "" this.layoutTraits);
+ image.src = "" this.layoutTraits).src;
}
}
Modified: trunk/Source/WebCore/rendering/RenderTheme.h (207422 => 207423)
--- trunk/Source/WebCore/rendering/RenderTheme.h 2016-10-17 19:17:36 UTC (rev 207422)
+++ trunk/Source/WebCore/rendering/RenderTheme.h 2016-10-17 19:54:04 UTC (rev 207423)
@@ -101,6 +101,7 @@
virtual String mediaControlsStyleSheet() { return String(); }
virtual String extraMediaControlsStyleSheet() { return String(); }
virtual String mediaControlsScript() { return String(); }
+ virtual String mediaControlsBase64StringForIconAndPlatform(const String&, const String&) { return String(); }
#endif
#if ENABLE(FULLSCREEN_API)
virtual String extraFullScreenStyleSheet() { return String(); }
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.h (207422 => 207423)
--- trunk/Source/WebCore/rendering/RenderThemeMac.h 2016-10-17 19:17:36 UTC (rev 207422)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.h 2016-10-17 19:54:04 UTC (rev 207423)
@@ -108,6 +108,7 @@
// Media controls
String mediaControlsStyleSheet() override;
String mediaControlsScript() override;
+ String mediaControlsBase64StringForIconAndPlatform(const String&, const String&) override;
#endif
#if ENABLE(SERVICE_CONTROLS)
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (207422 => 207423)
--- trunk/Source/WebCore/rendering/RenderThemeMac.mm 2016-10-17 19:17:36 UTC (rev 207422)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm 2016-10-17 19:54:04 UTC (rev 207423)
@@ -272,6 +272,20 @@
#endif
}
+String RenderThemeMac::mediaControlsBase64StringForIconAndPlatform(const String& iconName, const String& platform)
+{
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+ if (!RuntimeEnabledFeatures::sharedFeatures().modernMediaControlsEnabled())
+ return emptyString();
+
+ String directory = "modern-media-controls/images/" + platform;
+ NSBundle *bundle = [NSBundle bundleForClass:[WebCoreRenderThemeBundle class]];
+ return [[NSData dataWithContentsOfFile:[bundle pathForResource:iconName ofType:@"png" inDirectory:directory]] base64EncodedStringWithOptions:0];
+#else
+ return emptyString();
+#endif
+}
+
#endif // ENABLE(VIDEO)