Changeset 182298 in webkit


Ignore:
Timestamp:
Apr 2, 2015 5:27:06 PM (9 years ago)
Author:
Brent Fulgham
Message:

REGRESSION: Caption Menus show language codes instead of display names.
https://bugs.webkit.org/show_bug.cgi?id=143350
<rdar://problem/20094145>

Reviewed by Jer Noble.

The generic caption/track label handling in CaptionUserPreferences does not convert language codes
(e.g. 'fr-CA') into display names (e.g., 'French (Canada)'). Because we did not have an AudioTrack
override to process these types of menu items, they were being handled using the generic code.

  • page/CaptionUserPreferencesMediaAF.cpp:

(WebCore::buildStringForTrackBase): Helper function to share code with the two flavors
of 'trackDisplayName'.
(WebCore::trackDisplayName): Add a version to support AudioTracks, and modify the TextTrack
version to use the new 'buildStringForTrackBase' function.
(WebCore::CaptionUserPreferencesMediaAF::displayNameForTrack): Add an AudioTrack override so
our AVFoundation tracks are processed in our CaptionUserPreferencesMediaAF implementation, not the
generic version.
(WebCore::CaptionUserPreferencesMediaAF::sortedTrackListForMenu): Add an AudioTrack override so
that the menu items are sorted in order of display name, not language code.

  • page/CaptionUserPreferencesMediaAF.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r182293 r182298  
     12015-04-02  Brent Fulgham  <bfulgham@apple.com>
     2
     3        REGRESSION: Caption Menus show language codes instead of display names.
     4        https://bugs.webkit.org/show_bug.cgi?id=143350
     5        <rdar://problem/20094145>
     6
     7        Reviewed by Jer Noble.
     8
     9        The generic caption/track label handling in CaptionUserPreferences does not convert language codes
     10        (e.g. 'fr-CA') into display names (e.g., 'French (Canada)'). Because we did not have an AudioTrack
     11        override to process these types of menu items, they were being handled using the generic code.
     12
     13        * page/CaptionUserPreferencesMediaAF.cpp:
     14        (WebCore::buildStringForTrackBase): Helper function to share code with the two flavors
     15        of 'trackDisplayName'.
     16        (WebCore::trackDisplayName): Add a version to support AudioTracks, and modify the TextTrack
     17        version to use the new 'buildStringForTrackBase' function.
     18        (WebCore::CaptionUserPreferencesMediaAF::displayNameForTrack): Add an AudioTrack override so
     19        our AVFoundation tracks are processed in our CaptionUserPreferencesMediaAF implementation, not the
     20        generic version.
     21        (WebCore::CaptionUserPreferencesMediaAF::sortedTrackListForMenu): Add an AudioTrack override so
     22        that the menu items are sorted in order of display name, not language code.
     23        * page/CaptionUserPreferencesMediaAF.h:
     24
    1252015-04-02  Brady Eidson  <beidson@apple.com>
    226
  • trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp

    r181190 r182298  
    11/*
    2  * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012-2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030#include "CaptionUserPreferencesMediaAF.h"
    3131
     32#include "AudioTrackList.h"
    3233#include "FloatConversion.h"
    3334#include "HTMLMediaElement.h"
     
    537538}
    538539
    539 static String trackDisplayName(TextTrack* track)
    540 {
    541     if (track == TextTrack::captionMenuOffItem())
    542         return textTrackOffMenuItemText();
    543     if (track == TextTrack::captionMenuAutomaticItem())
    544         return textTrackAutomaticMenuItemText();
    545 
    546     StringBuilder displayName;
    547     String label = track->label();
    548     String trackLanguageIdentifier = track->language();
     540static void buildDisplayStringForTrackBase(StringBuilder& displayName, const TrackBase& track)
     541{
     542    String label = track.label();
     543    String trackLanguageIdentifier = track.language();
    549544
    550545    RetainPtr<CFLocaleRef> currentLocale = adoptCF(CFLocaleCreate(kCFAllocatorDefault, defaultLanguage().createCFString().get()));
     
    552547    RetainPtr<CFStringRef> languageCF = adoptCF(CFLocaleCopyDisplayNameForPropertyValue(currentLocale.get(), kCFLocaleLanguageCode, localeIdentifier.get()));
    553548    String language = languageCF.get();
     549
    554550    if (!label.isEmpty()) {
    555551        if (language.isEmpty() || label.contains(language))
     
    582578            displayName.append(localeIdentifier.get());
    583579    }
    584    
     580}
     581
     582static String trackDisplayName(AudioTrack* track)
     583{
     584    StringBuilder displayName;
     585    buildDisplayStringForTrackBase(displayName, *track);
     586   
     587    if (displayName.isEmpty())
     588        displayName.append(audioTrackNoLabelText());
     589   
     590    return displayName.toString();
     591}
     592
     593String CaptionUserPreferencesMediaAF::displayNameForTrack(AudioTrack* track) const
     594{
     595    return trackDisplayName(track);
     596}
     597
     598static String trackDisplayName(TextTrack* track)
     599{
     600    if (track == TextTrack::captionMenuOffItem())
     601        return textTrackOffMenuItemText();
     602    if (track == TextTrack::captionMenuAutomaticItem())
     603        return textTrackAutomaticMenuItemText();
     604
     605    StringBuilder displayName;
     606    buildDisplayStringForTrackBase(displayName, *track);
     607
    585608    if (displayName.isEmpty())
    586609        displayName.append(textTrackNoLabelText());
     
    721744    // ... and tracks of the same type and language sort by the menu item text.
    722745    return codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0;
     746}
     747
     748Vector<RefPtr<AudioTrack>> CaptionUserPreferencesMediaAF::sortedTrackListForMenu(AudioTrackList* trackList)
     749{
     750    ASSERT(trackList);
     751   
     752    Vector<RefPtr<AudioTrack>> tracksForMenu;
     753   
     754    for (unsigned i = 0, length = trackList->length(); i < length; ++i) {
     755        AudioTrack* track = trackList->item(i);
     756        String language = displayNameForLanguageLocale(track->language());
     757        tracksForMenu.append(track);
     758    }
     759   
     760    std::sort(tracksForMenu.begin(), tracksForMenu.end(), [](const RefPtr<AudioTrack>& a, const RefPtr<AudioTrack>& b) {
     761        return codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0;
     762    });
     763   
     764    return tracksForMenu;
    723765}
    724766
  • trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h

    r182068 r182298  
    11/*
    2  * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012-2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6565    virtual String captionsStyleSheetOverride() const override;
    6666    virtual int textTrackSelectionScore(TextTrack*, HTMLMediaElement*) const override;
    67     virtual Vector<RefPtr<TextTrack>> sortedTrackListForMenu(TextTrackList*) override;
    68     virtual String displayNameForTrack(TextTrack*) const override;
     67    Vector<RefPtr<AudioTrack>> sortedTrackListForMenu(AudioTrackList*) override;
     68    Vector<RefPtr<TextTrack>> sortedTrackListForMenu(TextTrackList*) override;
     69    String displayNameForTrack(AudioTrack*) const override;
     70    String displayNameForTrack(TextTrack*) const override;
    6971
    7072private:
Note: See TracChangeset for help on using the changeset viewer.