Diff
Modified: trunk/LayoutTests/ChangeLog (237186 => 237187)
--- trunk/LayoutTests/ChangeLog 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/LayoutTests/ChangeLog 2018-10-16 17:29:34 UTC (rev 237187)
@@ -1,3 +1,15 @@
+2018-10-16 Per Arne Vollan <pvol...@apple.com>
+
+ [WebVTT] Support inline WebVTT styles
+ https://bugs.webkit.org/show_bug.cgi?id=190369
+
+ Reviewed by Eric Carlson.
+
+ * media/track/captions-webvtt/css-styling.vtt: Added.
+ * media/track/captions-webvtt/no-css-styling.vtt: Added.
+ * media/track/track-cue-css-expected.html: Added.
+ * media/track/track-cue-css.html: Added.
+
2018-10-16 Chris Dumez <cdu...@apple.com>
window.navigator should not become null after the window loses its browsing context
Added: trunk/LayoutTests/media/track/captions-webvtt/css-styling.vtt (0 => 237187)
--- trunk/LayoutTests/media/track/captions-webvtt/css-styling.vtt (rev 0)
+++ trunk/LayoutTests/media/track/captions-webvtt/css-styling.vtt 2018-10-16 17:29:34 UTC (rev 237187)
@@ -0,0 +1,16 @@
+WEBVTT
+
+STYLE
+::cue {
+background-image: linear-gradient(to bottom, dimgray, lightgray);
+}
+
+STYLE
+::cue(b) {
+color: red;
+font-size: 15px;
+}
+
+hello
+00:00:00.000 --> 00:00:10.000
+<b>Hello</b>.
Added: trunk/LayoutTests/media/track/captions-webvtt/no-css-styling.vtt (0 => 237187)
--- trunk/LayoutTests/media/track/captions-webvtt/no-css-styling.vtt (rev 0)
+++ trunk/LayoutTests/media/track/captions-webvtt/no-css-styling.vtt 2018-10-16 17:29:34 UTC (rev 237187)
@@ -0,0 +1,5 @@
+WEBVTT
+
+hello
+00:00:00.000 --> 00:00:10.000
+<b>Hello</b>.
Added: trunk/LayoutTests/media/track/track-cue-css-expected.html (0 => 237187)
--- trunk/LayoutTests/media/track/track-cue-css-expected.html (rev 0)
+++ trunk/LayoutTests/media/track/track-cue-css-expected.html 2018-10-16 17:29:34 UTC (rev 237187)
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script>var requirePixelDump = true;</script>
+ <script src=""
+ <script src=""
+ <script src=""
+
+ <style>
+ video::cue {
+ background-image: linear-gradient(to bottom, dimgray, lightgray);
+ }
+ video::cue(b) {
+ color: red;
+ font-size: 15px;
+ }
+ </style>
+ <script>
+ function loaded()
+ {
+ consoleWrite("Test that CSS in VTT file is applied correctly.");
+ findMediaElement();
+ video.src = "" '../content/test');
+ waitForEvent('seeked', endTest);
+ waitForEvent('canplaythrough', function() { video.currentTime = .5; });
+ }
+
+ setCaptionDisplayMode('Automatic');
+ </script>
+ </head>
+ <body _onload_="loaded()">
+ <video controls >
+ <track src="" kind="captions" default>
+ </video>
+ </body>
+</html>
Added: trunk/LayoutTests/media/track/track-cue-css.html (0 => 237187)
--- trunk/LayoutTests/media/track/track-cue-css.html (rev 0)
+++ trunk/LayoutTests/media/track/track-cue-css.html 2018-10-16 17:29:34 UTC (rev 237187)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script>var requirePixelDump = true;</script>
+ <script src=""
+ <script src=""
+ <script src=""
+ <script>
+ function loaded()
+ {
+ consoleWrite("Test that CSS in VTT file is applied correctly.");
+ findMediaElement();
+ video.src = "" '../content/test');
+ waitForEvent('seeked', endTest);
+ waitForEvent('canplaythrough', function() { video.currentTime = .5; });
+ }
+
+ setCaptionDisplayMode('Automatic');
+ </script>
+ </head>
+ <body _onload_="loaded()">
+ <video controls >
+ <track src="" kind="captions" default>
+ </video>
+ </body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (237186 => 237187)
--- trunk/Source/WebCore/ChangeLog 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/ChangeLog 2018-10-16 17:29:34 UTC (rev 237187)
@@ -1,3 +1,44 @@
+2018-10-16 Per Arne Vollan <pvol...@apple.com>
+
+ [WebVTT] Support inline WebVTT styles
+ https://bugs.webkit.org/show_bug.cgi?id=190369
+
+ Reviewed by Eric Carlson.
+
+ Add support for inline WebVTT styles, see https://w3c.github.io/webvtt/#styling. The parsed
+ style strings from the VTT file are added to an optional vector of style strings in the
+ TextTrack class. These styles are then added as HTMLStyleElement children to the parent of
+ the cue span element.
+
+ Test: media/track/track-cue-css.html
+
+ * html/track/InbandGenericTextTrack.cpp:
+ (WebCore::InbandGenericTextTrack::newStyleSheetsParsed):
+ * html/track/InbandGenericTextTrack.h:
+ * html/track/InbandWebVTTTextTrack.cpp:
+ (WebCore::InbandWebVTTTextTrack::newStyleSheetsParsed):
+ * html/track/InbandWebVTTTextTrack.h:
+ * html/track/LoadableTextTrack.cpp:
+ (WebCore::LoadableTextTrack::newStyleSheetsAvailable):
+ * html/track/LoadableTextTrack.h:
+ * html/track/TextTrack.h:
+ (WebCore::TextTrack::styleSheets const):
+ * html/track/VTTCue.cpp:
+ (WebCore::VTTCue::getDisplayTree):
+ * html/track/WebVTTParser.cpp:
+ (WebCore::WebVTTParser::getNewCues):
+ (WebCore::WebVTTParser::getStyleSheets):
+ (WebCore::WebVTTParser::parse):
+ (WebCore::WebVTTParser::collectWebVTTBlock):
+ (WebCore::WebVTTParser::collectStyleSheet):
+ (WebCore::WebVTTParser::checkStyleSheet):
+ (WebCore::WebVTTParser::checkAndStoreStyleSheet):
+ * html/track/WebVTTParser.h:
+ * loader/TextTrackLoader.cpp:
+ (WebCore::TextTrackLoader::newStyleSheetsParsed):
+ (WebCore::TextTrackLoader::getNewStyleSheets):
+ * loader/TextTrackLoader.h:
+
2018-10-16 Chris Dumez <cdu...@apple.com>
window.navigator should not become null after the window loses its browsing context
Modified: trunk/Source/WebCore/html/track/InbandGenericTextTrack.cpp (237186 => 237187)
--- trunk/Source/WebCore/html/track/InbandGenericTextTrack.cpp 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/html/track/InbandGenericTextTrack.cpp 2018-10-16 17:29:34 UTC (rev 237187)
@@ -215,6 +215,10 @@
}
}
+void InbandGenericTextTrack::newStyleSheetsParsed()
+{
+}
+
void InbandGenericTextTrack::fileFailedToParse()
{
ERROR_LOG(LOGIDENTIFIER);
Modified: trunk/Source/WebCore/html/track/InbandGenericTextTrack.h (237186 => 237187)
--- trunk/Source/WebCore/html/track/InbandGenericTextTrack.h 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/html/track/InbandGenericTextTrack.h 2018-10-16 17:29:34 UTC (rev 237187)
@@ -72,6 +72,7 @@
void newCuesParsed() final;
void newRegionsParsed() final;
+ void newStyleSheetsParsed() final;
void fileFailedToParse() final;
#if !RELEASE_LOG_DISABLED
Modified: trunk/Source/WebCore/html/track/InbandWebVTTTextTrack.cpp (237186 => 237187)
--- trunk/Source/WebCore/html/track/InbandWebVTTTextTrack.cpp 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/html/track/InbandWebVTTTextTrack.cpp 2018-10-16 17:29:34 UTC (rev 237187)
@@ -92,6 +92,10 @@
}
}
+void InbandWebVTTTextTrack::newStyleSheetsParsed()
+{
+}
+
void InbandWebVTTTextTrack::fileFailedToParse()
{
ERROR_LOG(LOGIDENTIFIER, "Error parsing WebVTT stream.");
Modified: trunk/Source/WebCore/html/track/InbandWebVTTTextTrack.h (237186 => 237187)
--- trunk/Source/WebCore/html/track/InbandWebVTTTextTrack.h 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/html/track/InbandWebVTTTextTrack.h 2018-10-16 17:29:34 UTC (rev 237187)
@@ -47,6 +47,7 @@
void newCuesParsed() final;
void newRegionsParsed() final;
+ void newStyleSheetsParsed() final;
void fileFailedToParse() final;
#if !RELEASE_LOG_DISABLED
Modified: trunk/Source/WebCore/html/track/LoadableTextTrack.cpp (237186 => 237187)
--- trunk/Source/WebCore/html/track/LoadableTextTrack.cpp 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/html/track/LoadableTextTrack.cpp 2018-10-16 17:29:34 UTC (rev 237187)
@@ -131,6 +131,12 @@
}
}
+void LoadableTextTrack::newStyleSheetsAvailable(TextTrackLoader& loader)
+{
+ ASSERT_UNUSED(loader, m_loader.get() == &loader);
+ m_styleSheets = m_loader->getNewStyleSheets();
+}
+
AtomicString LoadableTextTrack::id() const
{
if (!m_trackElement)
Modified: trunk/Source/WebCore/html/track/LoadableTextTrack.h (237186 => 237187)
--- trunk/Source/WebCore/html/track/LoadableTextTrack.h 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/html/track/LoadableTextTrack.h 2018-10-16 17:29:34 UTC (rev 237187)
@@ -56,6 +56,7 @@
void newCuesAvailable(TextTrackLoader*) final;
void cueLoadingCompleted(TextTrackLoader*, bool loadingFailed) final;
void newRegionsAvailable(TextTrackLoader*) final;
+ void newStyleSheetsAvailable(TextTrackLoader&) final;
AtomicString id() const final;
bool isDefault() const final { return m_isDefault; }
Modified: trunk/Source/WebCore/html/track/TextTrack.h (237186 => 237187)
--- trunk/Source/WebCore/html/track/TextTrack.h 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/html/track/TextTrack.h 2018-10-16 17:29:34 UTC (rev 237187)
@@ -144,6 +144,8 @@
using RefCounted<TrackBase>::ref;
using RefCounted<TrackBase>::deref;
+ const std::optional<Vector<String>>& styleSheets() const { return m_styleSheets; }
+
protected:
TextTrack(ScriptExecutionContext*, TextTrackClient*, const AtomicString& kind, const AtomicString& id, const AtomicString& label, const AtomicString& language, TextTrackType);
@@ -152,6 +154,7 @@
#endif
RefPtr<TextTrackCueList> m_cues;
+ std::optional<Vector<String>> m_styleSheets;
private:
bool enabled() const override;
Modified: trunk/Source/WebCore/html/track/VTTCue.cpp (237186 => 237187)
--- trunk/Source/WebCore/html/track/VTTCue.cpp 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/html/track/VTTCue.cpp 2018-10-16 17:29:34 UTC (rev 237187)
@@ -40,6 +40,7 @@
#include "Event.h"
#include "HTMLDivElement.h"
#include "HTMLSpanElement.h"
+#include "HTMLStyleElement.h"
#include "Logging.h"
#include "NodeTraversal.h"
#include "RenderVTTCue.h"
@@ -893,6 +894,15 @@
displayTree->setFontSizeFromCaptionUserPrefs(fontSize);
displayTree->applyCSSProperties(videoSize);
+ const auto& styleSheets = track()->styleSheets();
+ if (styleSheets) {
+ for (const auto& cssString : *styleSheets) {
+ auto style = HTMLStyleElement::create(HTMLNames::styleTag, m_cueBackdropBox->document(), false);
+ style->setTextContent(cssString);
+ m_cueBackdropBox->appendChild(style);
+ }
+ }
+
m_displayTreeShouldChange = false;
// 10.15. Let cue's text track cue display state have the CSS boxes in
Modified: trunk/Source/WebCore/html/track/WebVTTParser.cpp (237186 => 237187)
--- trunk/Source/WebCore/html/track/WebVTTParser.cpp 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/html/track/WebVTTParser.cpp 2018-10-16 17:29:34 UTC (rev 237187)
@@ -52,6 +52,7 @@
const char* fileIdentifier = "WEBVTT";
const unsigned fileIdentifierLength = 6;
const unsigned regionIdentifierLength = 6;
+const unsigned styleIdentifierLength = 5;
bool WebVTTParser::parseFloatPercentageValue(VTTScanner& valueScanner, float& percentage)
{
@@ -96,8 +97,7 @@
void WebVTTParser::getNewCues(Vector<RefPtr<WebVTTCueData>>& outputCues)
{
- outputCues = m_cuelist;
- m_cuelist.clear();
+ outputCues = WTFMove(m_cuelist);
}
void WebVTTParser::getNewRegions(Vector<RefPtr<VTTRegion>>& outputRegions)
@@ -105,6 +105,11 @@
outputRegions = WTFMove(m_regionList);
}
+Vector<String> WebVTTParser::getStyleSheets()
+{
+ return WTFMove(m_styleSheets);
+}
+
void WebVTTParser::parseFileHeader(String&& data)
{
m_state = Initial;
@@ -174,6 +179,10 @@
m_state = collectRegionSettings(*line);
break;
+ case Style:
+ m_state = collectStyleSheet(*line);
+ break;
+
case Id:
// Steps 17 - 20 - Allow any number of line terminators, then initialize new cue values.
if (line->isEmpty())
@@ -258,11 +267,18 @@
if (checkAndCreateRegion(line))
return Region;
+ if (checkStyleSheet(line))
+ return Style;
+
// Handle cue block.
ParseState state = checkAndRecoverCue(line);
if (state != Header) {
- if (m_client && !m_regionList.isEmpty())
- m_client->newRegionsParsed();
+ if (m_client) {
+ if (!m_regionList.isEmpty())
+ m_client->newRegionsParsed();
+ if (!m_styleSheets.isEmpty())
+ m_client->newStyleSheetsParsed();
+ }
if (!m_previousLine.isEmpty() && !m_previousLine.contains("-->"))
m_currentId = m_previousLine;
@@ -290,6 +306,16 @@
return Header;
}
+WebVTTParser::ParseState WebVTTParser::collectStyleSheet(const String& line)
+{
+ // End of style block
+ if (checkAndStoreStyleSheet(line))
+ return checkAndRecoverCue(line);
+
+ m_currentStyleSheet.append(line);
+ return Style;
+}
+
bool WebVTTParser::checkAndCreateRegion(const String& line)
{
if (m_previousLine.contains("-->"))
@@ -323,7 +349,29 @@
m_currentRegion = nullptr;
return true;
}
+
+bool WebVTTParser::checkStyleSheet(const String& line)
+{
+ if (m_previousLine.contains("-->"))
+ return false;
+ // line starts with the substring "STYLE" and remaining characters
+ // zero or more U+0020 SPACE characters or U+0009 CHARACTER TABULATION
+ // (tab) characters expected other than these charecters it is invalid.
+ if (line.startsWith("STYLE") && line.substring(styleIdentifierLength).isAllSpecialCharacters<isASpace>())
+ return true;
+
+ return false;
+}
+
+bool WebVTTParser::checkAndStoreStyleSheet(const String& line)
+{
+ if (!line.isEmpty() && !line.contains("-->"))
+ return false;
+ m_styleSheets.append(WTFMove(m_currentStyleSheet));
+ return true;
+}
+
WebVTTParser::ParseState WebVTTParser::collectCueId(const String& line)
{
if (line.contains("-->"))
Modified: trunk/Source/WebCore/html/track/WebVTTParser.h (237186 => 237187)
--- trunk/Source/WebCore/html/track/WebVTTParser.h 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/html/track/WebVTTParser.h 2018-10-16 17:29:34 UTC (rev 237187)
@@ -57,6 +57,7 @@
virtual void newCuesParsed() = 0;
virtual void newRegionsParsed() = 0;
+ virtual void newStyleSheetsParsed() = 0;
virtual void fileFailedToParse() = 0;
};
@@ -104,6 +105,7 @@
TimingsAndSettings,
CueText,
Region,
+ Style,
BadCue,
Finished
};
@@ -150,6 +152,8 @@
void getNewCues(Vector<RefPtr<WebVTTCueData>>&);
void getNewRegions(Vector<RefPtr<VTTRegion>>&);
+ Vector<String> getStyleSheets();
+
// Create the DocumentFragment representation of the WebVTT cue text.
static Ref<DocumentFragment> createDocumentFragmentFromCueText(Document&, const String&);
@@ -169,9 +173,12 @@
ParseState collectRegionSettings(const String&);
ParseState collectWebVTTBlock(const String&);
ParseState checkAndRecoverCue(const String& line);
+ ParseState collectStyleSheet(const String&);
bool checkAndCreateRegion(const String& line);
bool checkAndStoreRegion(const String& line);
-
+ bool checkStyleSheet(const String& line);
+ bool checkAndStoreStyleSheet(const String& line);
+
void createNewCue();
void resetCueValues();
@@ -186,11 +193,13 @@
String m_previousLine;
String m_currentSettings;
RefPtr<VTTRegion> m_currentRegion;
+ String m_currentStyleSheet;
WebVTTParserClient* m_client;
Vector<RefPtr<WebVTTCueData>> m_cuelist;
Vector<RefPtr<VTTRegion>> m_regionList;
+ Vector<String> m_styleSheets;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/loader/TextTrackLoader.cpp (237186 => 237187)
--- trunk/Source/WebCore/loader/TextTrackLoader.cpp 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/loader/TextTrackLoader.cpp 2018-10-16 17:29:34 UTC (rev 237187)
@@ -181,6 +181,11 @@
m_client.newRegionsAvailable(this);
}
+void TextTrackLoader::newStyleSheetsParsed()
+{
+ m_client.newStyleSheetsAvailable(*this);
+}
+
void TextTrackLoader::fileFailedToParse()
{
LOG(Media, "TextTrackLoader::fileFailedToParse");
@@ -212,6 +217,14 @@
m_cueParser->getNewRegions(outputRegions);
}
+Vector<String> TextTrackLoader::getNewStyleSheets()
+{
+ ASSERT(m_cueParser);
+ if (m_cueParser)
+ return m_cueParser->getStyleSheets();
+ return Vector<String>();
}
+}
+
#endif
Modified: trunk/Source/WebCore/loader/TextTrackLoader.h (237186 => 237187)
--- trunk/Source/WebCore/loader/TextTrackLoader.h 2018-10-16 16:47:07 UTC (rev 237186)
+++ trunk/Source/WebCore/loader/TextTrackLoader.h 2018-10-16 17:29:34 UTC (rev 237187)
@@ -48,6 +48,7 @@
virtual void newCuesAvailable(TextTrackLoader*) = 0;
virtual void cueLoadingCompleted(TextTrackLoader*, bool loadingFailed) = 0;
virtual void newRegionsAvailable(TextTrackLoader*) = 0;
+ virtual void newStyleSheetsAvailable(TextTrackLoader&) = 0;
};
class TextTrackLoader : public CachedResourceClient, private WebVTTParserClient {
@@ -61,6 +62,7 @@
void cancelLoad();
void getNewCues(Vector<RefPtr<TextTrackCue>>& outputCues);
void getNewRegions(Vector<RefPtr<VTTRegion>>& outputRegions);
+ Vector<String> getNewStyleSheets();
private:
// CachedResourceClient
@@ -70,6 +72,7 @@
// WebVTTParserClient
void newCuesParsed() override;
void newRegionsParsed() override;
+ void newStyleSheetsParsed() final;
void fileFailedToParse() override;
void processNewCueData(CachedResource&);