- Revision
- 277793
- Author
- drou...@apple.com
- Date
- 2021-05-20 10:28:39 -0700 (Thu, 20 May 2021)
Log Message
[Modern Media Controls] should not use `codePointCompare` as it doesn't take into account language specific sorting rules
https://bugs.webkit.org/show_bug.cgi?id=225993
Reviewed by Eric Carlson.
* page/CaptionUserPreferences.cpp:
(WebCore::CaptionUserPreferences::sortedTrackListForMenu):
* page/CaptionUserPreferencesMediaAF.cpp:
(WebCore::textTrackCompare):
(WebCore::CaptionUserPreferencesMediaAF::sortedTrackListForMenu):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (277792 => 277793)
--- trunk/Source/WebCore/ChangeLog 2021-05-20 17:08:30 UTC (rev 277792)
+++ trunk/Source/WebCore/ChangeLog 2021-05-20 17:28:39 UTC (rev 277793)
@@ -1,3 +1,16 @@
+2021-05-20 Devin Rousso <drou...@apple.com>
+
+ [Modern Media Controls] should not use `codePointCompare` as it doesn't take into account language specific sorting rules
+ https://bugs.webkit.org/show_bug.cgi?id=225993
+
+ Reviewed by Eric Carlson.
+
+ * page/CaptionUserPreferences.cpp:
+ (WebCore::CaptionUserPreferences::sortedTrackListForMenu):
+ * page/CaptionUserPreferencesMediaAF.cpp:
+ (WebCore::textTrackCompare):
+ (WebCore::CaptionUserPreferencesMediaAF::sortedTrackListForMenu):
+
2021-05-20 Geoffrey Garen <gga...@apple.com>
GraphicsLayer::setName() causes heap fragmentation
Modified: trunk/Source/WebCore/page/CaptionUserPreferences.cpp (277792 => 277793)
--- trunk/Source/WebCore/page/CaptionUserPreferences.cpp 2021-05-20 17:08:30 UTC (rev 277792)
+++ trunk/Source/WebCore/page/CaptionUserPreferences.cpp 2021-05-20 17:28:39 UTC (rev 277793)
@@ -45,6 +45,7 @@
#include <_javascript_Core/JSCellInlines.h>
#include <_javascript_Core/StructureInlines.h>
#include <wtf/Language.h>
+#include <wtf/unicode/Collator.h>
namespace WebCore {
@@ -237,8 +238,10 @@
tracksForMenu.append(track);
}
- std::sort(tracksForMenu.begin(), tracksForMenu.end(), [](auto& a, auto& b) {
- return codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0;
+ Collator collator;
+
+ std::sort(tracksForMenu.begin(), tracksForMenu.end(), [&] (auto& a, auto& b) {
+ return collator.collate(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0;
});
if (kinds.contains(TextTrack::Kind::Subtitles) || kinds.contains(TextTrack::Kind::Captions) || kinds.contains(TextTrack::Kind::Descriptions)) {
@@ -279,8 +282,10 @@
tracksForMenu.append(track);
}
- std::sort(tracksForMenu.begin(), tracksForMenu.end(), [](auto& a, auto& b) {
- return codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0;
+ Collator collator;
+
+ std::sort(tracksForMenu.begin(), tracksForMenu.end(), [&] (auto& a, auto& b) {
+ return collator.collate(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0;
});
return tracksForMenu;
Modified: trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp (277792 => 277793)
--- trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp 2021-05-20 17:08:30 UTC (rev 277792)
+++ trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp 2021-05-20 17:28:39 UTC (rev 277793)
@@ -49,6 +49,7 @@
#include <wtf/text/StringBuilder.h>
#include <wtf/text/StringConcatenateNumbers.h>
#include <wtf/text/cf/StringConcatenateCF.h>
+#include <wtf/unicode/Collator.h>
#if PLATFORM(IOS_FAMILY)
#import "WebCoreThreadRun.h"
@@ -681,13 +682,15 @@
String bLanguageDisplayName = displayNameForLanguageLocale(languageIdentifier(b->validBCP47Language()));
// Tracks in the user's preferred language are always at the top of the menu.
- bool aIsPreferredLanguage = !codePointCompare(aLanguageDisplayName, preferredLanguageDisplayName);
- bool bIsPreferredLanguage = !codePointCompare(bLanguageDisplayName, preferredLanguageDisplayName);
+ bool aIsPreferredLanguage = aLanguageDisplayName == preferredLanguageDisplayName;
+ bool bIsPreferredLanguage = bLanguageDisplayName == preferredLanguageDisplayName;
if (aIsPreferredLanguage != bIsPreferredLanguage)
return aIsPreferredLanguage;
+ Collator collator;
+
// Tracks not in the user's preferred language sort first by language ...
- if (auto languageDisplayNameComparison = codePointCompare(aLanguageDisplayName, bLanguageDisplayName))
+ if (auto languageDisplayNameComparison = collator.collate(aLanguageDisplayName, bLanguageDisplayName))
return languageDisplayNameComparison < 0;
// ... but when tracks have the same language, main program content sorts next highest ...
@@ -703,7 +706,7 @@
return aIsCC;
// ... and tracks of the same type and language sort by the menu item text.
- if (auto trackDisplayComparison = codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())))
+ if (auto trackDisplayComparison = collator.collate(trackDisplayName(a.get()), trackDisplayName(b.get())))
return trackDisplayComparison < 0;
// ... and if the menu item text is the same, compare the unique IDs
@@ -721,10 +724,11 @@
String language = displayNameForLanguageLocale(track->validBCP47Language());
tracksForMenu.append(track);
}
-
- std::sort(tracksForMenu.begin(), tracksForMenu.end(), [](auto& a, auto& b) {
- auto trackDisplayComparison = codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get()));
- if (trackDisplayComparison)
+
+ Collator collator;
+
+ std::sort(tracksForMenu.begin(), tracksForMenu.end(), [&] (auto& a, auto& b) {
+ if (auto trackDisplayComparison = collator.collate(trackDisplayName(a.get()), trackDisplayName(b.get())))
return trackDisplayComparison < 0;
return a->uniqueId() < b->uniqueId();