Title: [182298] trunk/Source/WebCore
- Revision
- 182298
- Author
- bfulg...@apple.com
- Date
- 2015-04-02 17:27:06 -0700 (Thu, 02 Apr 2015)
Log 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:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (182297 => 182298)
--- trunk/Source/WebCore/ChangeLog 2015-04-03 00:09:42 UTC (rev 182297)
+++ trunk/Source/WebCore/ChangeLog 2015-04-03 00:27:06 UTC (rev 182298)
@@ -1,3 +1,27 @@
+2015-04-02 Brent Fulgham <bfulg...@apple.com>
+
+ 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:
+
2015-04-02 Brady Eidson <beid...@apple.com>
Expose the "Share" menu for text selections on platforms where it's available.
Modified: trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp (182297 => 182298)
--- trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp 2015-04-03 00:09:42 UTC (rev 182297)
+++ trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp 2015-04-03 00:27:06 UTC (rev 182298)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,6 +29,7 @@
#include "CaptionUserPreferencesMediaAF.h"
+#include "AudioTrackList.h"
#include "FloatConversion.h"
#include "HTMLMediaElement.h"
#include "URL.h"
@@ -536,21 +537,16 @@
return lowercaseLanguageCode;
}
-static String trackDisplayName(TextTrack* track)
+static void buildDisplayStringForTrackBase(StringBuilder& displayName, const TrackBase& track)
{
- if (track == TextTrack::captionMenuOffItem())
- return textTrackOffMenuItemText();
- if (track == TextTrack::captionMenuAutomaticItem())
- return textTrackAutomaticMenuItemText();
+ String label = track.label();
+ String trackLanguageIdentifier = track.language();
- StringBuilder displayName;
- String label = track->label();
- String trackLanguageIdentifier = track->language();
-
RetainPtr<CFLocaleRef> currentLocale = adoptCF(CFLocaleCreate(kCFAllocatorDefault, defaultLanguage().createCFString().get()));
RetainPtr<CFStringRef> localeIdentifier = adoptCF(CFLocaleCreateCanonicalLocaleIdentifierFromString(kCFAllocatorDefault, trackLanguageIdentifier.createCFString().get()));
RetainPtr<CFStringRef> languageCF = adoptCF(CFLocaleCopyDisplayNameForPropertyValue(currentLocale.get(), kCFLocaleLanguageCode, localeIdentifier.get()));
String language = languageCF.get();
+
if (!label.isEmpty()) {
if (language.isEmpty() || label.contains(language))
displayName.append(label);
@@ -581,8 +577,35 @@
else
displayName.append(localeIdentifier.get());
}
+}
+
+static String trackDisplayName(AudioTrack* track)
+{
+ StringBuilder displayName;
+ buildDisplayStringForTrackBase(displayName, *track);
if (displayName.isEmpty())
+ displayName.append(audioTrackNoLabelText());
+
+ return displayName.toString();
+}
+
+String CaptionUserPreferencesMediaAF::displayNameForTrack(AudioTrack* track) const
+{
+ return trackDisplayName(track);
+}
+
+static String trackDisplayName(TextTrack* track)
+{
+ if (track == TextTrack::captionMenuOffItem())
+ return textTrackOffMenuItemText();
+ if (track == TextTrack::captionMenuAutomaticItem())
+ return textTrackAutomaticMenuItemText();
+
+ StringBuilder displayName;
+ buildDisplayStringForTrackBase(displayName, *track);
+
+ if (displayName.isEmpty())
displayName.append(textTrackNoLabelText());
if (track->isEasyToRead())
@@ -722,6 +745,25 @@
return codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0;
}
+Vector<RefPtr<AudioTrack>> CaptionUserPreferencesMediaAF::sortedTrackListForMenu(AudioTrackList* trackList)
+{
+ ASSERT(trackList);
+
+ Vector<RefPtr<AudioTrack>> tracksForMenu;
+
+ for (unsigned i = 0, length = trackList->length(); i < length; ++i) {
+ AudioTrack* track = trackList->item(i);
+ String language = displayNameForLanguageLocale(track->language());
+ tracksForMenu.append(track);
+ }
+
+ std::sort(tracksForMenu.begin(), tracksForMenu.end(), [](const RefPtr<AudioTrack>& a, const RefPtr<AudioTrack>& b) {
+ return codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0;
+ });
+
+ return tracksForMenu;
+}
+
Vector<RefPtr<TextTrack>> CaptionUserPreferencesMediaAF::sortedTrackListForMenu(TextTrackList* trackList)
{
ASSERT(trackList);
Modified: trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h (182297 => 182298)
--- trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h 2015-04-03 00:09:42 UTC (rev 182297)
+++ trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h 2015-04-03 00:27:06 UTC (rev 182298)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -64,8 +64,10 @@
virtual String captionsStyleSheetOverride() const override;
virtual int textTrackSelectionScore(TextTrack*, HTMLMediaElement*) const override;
- virtual Vector<RefPtr<TextTrack>> sortedTrackListForMenu(TextTrackList*) override;
- virtual String displayNameForTrack(TextTrack*) const override;
+ Vector<RefPtr<AudioTrack>> sortedTrackListForMenu(AudioTrackList*) override;
+ Vector<RefPtr<TextTrack>> sortedTrackListForMenu(TextTrackList*) override;
+ String displayNameForTrack(AudioTrack*) const override;
+ String displayNameForTrack(TextTrack*) const override;
private:
#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes