Author: Rahul Singh
As of Chromium 77, WebVTT closed caption styling is controlled by the website author. As such, if the user sets styling preferences on the Closed captions page in the Windows 10 Settings App, a Chromium based browser – like the new Microsoft Edge – won’t apply these preferences when styling WebVTT captions. This can lead to captions not being accessible to the user as the styling set by the author may not make allowances for an individual user’s needs.
This implementation overrides site styling for captions with any user preferences. This is supported on macOS as well.
The Windows 10 Settings app allows a user to set styling preferences for the following properties, all of which are supported in this implementation.
struct NATIVE_THEME_EXPORT CaptionStyle {
CaptionStyle();
CaptionStyle(const CaptionStyle& other);
~CaptionStyle();
// Returns a CaptionStyle parsed from a specification string, which is a
// serialized JSON object whose keys are strings and whose values are of
// variable types. See the body of this method for details. This is used to
// parse the value of the "--force-caption-style" command-line argument and
// for testing.
static base::Optional<CaptionStyle> FromSpec(const std::string& spec);
// Returns a CaptionStyle populated from the System's Settings.
static base::Optional<CaptionStyle> FromSystemSettings();
std::string text_color;
std::string background_color;
// Holds text size percentage as a css string.
std::string text_size;
std::string text_shadow;
std::string font_family;
std::string font_variant;
std::string window_color;
std::string window_padding; // macOS only
std::string window_radius; // macOS only
};
if (background_color != ClosedCaptionColor_Default) {
caption_style.background_color =
AddCSSImportant(GetCssColor(background_color));
}
ui::CaptionStyle style = ui::NativeTheme::GetInstanceForWeb()->
GetSystemCaptionStyle();
// NativeTheme implementation.
base::Optional<CaptionStyle> NativeTheme::GetSystemCaptionStyle() const {
return CaptionStyle::FromSystemSettings();
}
For web video content that uses the WebVTT standard to include a caption payload for HTML5 content, this change will apply the caption styling preferences the user explicitly sets in the OS Settings app on Windows 10 or macOS.
For videos that don’t use the WebVTT standard for closed captioning, no change in behavior should be observed with this change.
This change is behind a ui::base feature flag. This flag is enabled by default in Chromium.
COMPONENT_EXPORT(UI_BASE_FEATURES)
extern const base::Feature kSystemCaptionStyle;
// Allows system caption style for WebVTT Captions.
const base::Feature kSystemCaptionStyle{
"SystemCaptionStyle", base::FEATURE_ENABLED_BY_DEFAULT};
Lastly, you can find details about Native Styling Support for WebVTT Captions on other platforms in the Chromium design doc here.