Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement automatic text track selection for 'metadata' tracks
https://bugs.webkit.org/show_bug.cgi?id=259581
rdar://problem/113004825

Reviewed by Eric Carlson.

This patch aligns WebKit with Gecko / Firefox and Blink / Chromium.

Merge: https://src.chromium.org/viewvc/blink?view=revision&revision=189185

Previously 'metadata' tracks were being configured using the "perform
automatic text track selection" algorithm from the the spec, while it
should only have applied step 4 of the "honor user preferences for
automatic text track selection" algorithm.

* Source/WebCore/html/HTMLMediaElement.cpp:
(HTMLMediaElement::configureMetadataTextTrackGroup): function to handle 'metadata' as per spec
(HTMLMediaElement::configureTextTrackGroup): for 'metadatatracks' use new function
* Source/WebCore/html/HTMLMediaElement.h: Add definition for new function
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/track-selection-metadata-expected.txt: Rebaselined

Canonical link: https://commits.webkit.org/266380@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Jul 28, 2023
1 parent ed55516 commit ec1a4f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
@@ -1,4 +1,4 @@


FAIL Multiple 'metadata' tracks with 'default' assert_equals: expected "hidden" but got "showing"
PASS Multiple 'metadata' tracks with 'default'

20 changes: 18 additions & 2 deletions Source/WebCore/html/HTMLMediaElement.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2007-2023 Apple Inc. All rights reserved.
* Copyright (C) 2014 Google Inc. All rights reserved.
* Copyright (C) 2014-2015 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -4825,6 +4825,22 @@ void HTMLMediaElement::didRemoveTextTrack(HTMLTrackElement& trackElement)
m_textTracksWhenResourceSelectionBegan.removeFirst(&textTrack);
}

void HTMLMediaElement::configureMetadataTextTrackGroup(const TrackGroup& group)
{
ASSERT(group.tracks.size());
// https://html.spec.whatwg.org/multipage/embedded-content.html#honor-user-preferences-for-automatic-text-track-selection
// 3. If there are any text tracks in the media element's list of text tracks whose text track kind is
// chapters or metadata that correspond to track elements with a default attribute set whose text track mode
// is set to disabled, then set the text track mode of all such tracks to hidden.
for (auto& textTrack : group.tracks) {
if (textTrack->mode() != TextTrack::Mode::Disabled)
continue;
if (!textTrack->isDefault())
continue;
textTrack->setMode(TextTrack::Mode::Hidden);
}
}

void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group)
{
ASSERT(group.tracks.size());
Expand Down Expand Up @@ -5179,7 +5195,7 @@ void HTMLMediaElement::configureTextTracks()
if (chapterTracks.tracks.size())
configureTextTrackGroup(chapterTracks);
if (metadataTracks.tracks.size())
configureTextTrackGroup(metadataTracks);
configureMetadataTextTrackGroup(metadataTracks);
if (otherTracks.tracks.size())
configureTextTrackGroup(otherTracks);

Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/html/HTMLMediaElement.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2007-2023 Apple Inc. All rights reserved.
* Copyright (C) 2015 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -403,6 +404,7 @@ class HTMLMediaElement
void scheduleConfigureTextTracks();
void configureTextTracks();
void configureTextTrackGroup(const TrackGroup&);
void configureMetadataTextTrackGroup(const TrackGroup&);

void setSelectedTextTrack(TextTrack*);

Expand Down

0 comments on commit ec1a4f3

Please sign in to comment.