[Mac] Track language selection should be sticky

https://bugs.webkit.org/show_bug.cgi?id=109466

Reviewed by Dean Jackson.

.: 

* Source/autotools/symbols.filter: Export PageGroup::captionPreferences and Page::initGroup.

Source/WebCore: 

Choosing a text track from the caption menu should make that track's language the
preferred caption language. Turning captions off from the menu should disable captions
in videos loaded subsequently.

OS X has system support for these settings, so changes made by DRT should not change the
settings on the user's system. Add support for all other ports in DRT only.

Test: media/track/track-user-preferences.html

* WebCore.exp.in: Export PageGroup::captionPreferences().

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): Use page()->group().captionPreferences().
(WebCore::HTMLMediaElement::attach): Ditto.
(WebCore::HTMLMediaElement::detach): Ditto.
(WebCore::HTMLMediaElement::userPrefersCaptions): Ditto.
(WebCore::HTMLMediaElement::configureTextTrackGroup): Ditto. Update for 
    preferredLanguageFromList change.
(WebCore::HTMLMediaElement::toggleTrackAtIndex): Set user prefs for captions visible and
    caption language as appropriate.

* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler): Remove unneeded comment.
(WebCore::MediaControlTextTrackContainerElement::updateSizes):  Use page()->group().captionPreferences().

* html/shadow/MediaControlsApple.cpp:
(WebCore::MediaControlsApple::closedCaptionTracksChanged): Update caption menu button visibility.

* page/CaptionUserPreferences.h:
(WebCore::CaptionUserPreferences::userPrefersCaptions): Support "testing" mode.
(WebCore::CaptionUserPreferences::setUserPrefersCaptions): Ditto.
(WebCore::CaptionUserPreferences::registerForPreferencesChangedCallbacks): Ditto.
(WebCore::CaptionUserPreferences::unregisterForPreferencesChangedCallbacks): Ditto.
(WebCore::CaptionUserPreferences::setPreferredLanguage): Ditto.
(WebCore::CaptionUserPreferences::preferredLanguages): Ditto.
(WebCore::CaptionUserPreferences::testingMode): Ditto.
(WebCore::CaptionUserPreferences::setTestingMode): Ditto.
(WebCore::CaptionUserPreferences::CaptionUserPreferences): Ditto.

* page/CaptionUserPreferencesMac.h:
* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::userPrefersCaptions): Support "testing" mode.
(WebCore::CaptionUserPreferencesMac::setUserPrefersCaptions): Ditto.
(WebCore::CaptionUserPreferencesMac::userHasCaptionPreferences): Ditto.
(WebCore::CaptionUserPreferencesMac::registerForPreferencesChangedCallbacks): Change name from
    registerForCaptionPreferencesChangedCallbacks. Support "testing" mode.
(WebCore::CaptionUserPreferencesMac::unregisterForPreferencesChangedCallbacks):  Change name from
    unregisterForCaptionPreferencesChangedCallbacks. Support "testing" mode.
(WebCore::CaptionUserPreferencesMac::captionsStyleSheetOverride): Support "testing" mode.
(WebCore::CaptionUserPreferencesMac::captionFontSizeScale): Ditto.
(WebCore::CaptionUserPreferencesMac::setPreferredLanguage): Ditto.
(WebCore::CaptionUserPreferencesMac::preferredLanguages): Ditto. Return the platform override when set.

* page/PageGroup.cpp:
(WebCore::PageGroup::registerForCaptionPreferencesChangedCallbacks): Remove because it is already
    available from the caption preference object.
(WebCore::PageGroup::unregisterForCaptionPreferencesChangedCallbacks): Ditto.
(WebCore::PageGroup::userPrefersCaptions): Ditto.
(WebCore::PageGroup::userHasCaptionPreferences): Ditto.
(WebCore::PageGroup::captionFontSizeScale): Ditto.
* page/PageGroup.h:

* platform/Language.cpp:
(WebCore::preferredLanguageFromList): Take the list of preferred languages instead of assuming
    the system list.
* platform/Language.h:

* testing/Internals.cpp:
(WebCore::Internals::resetToConsistentState): Disable caption testing mode.
(WebCore::Internals::Internals): Enable caption testing mode so the user's system
    preferences are not modified.

LayoutTests: 

* media/track/track-user-preferences-expected.txt: Added.
* media/track/track-user-preferences.html: Added.

* platform/chromium/TestExpectations: Skip new test, it depends on the track menu.
* platform/efl/TestExpectations: Ditto.
* platform/gtk/TestExpectations: Ditto.
* platform/qt/TestExpectations: Ditto.
* platform/win/TestExpectations: Ditto.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@142580 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7eecf1a2
2013-02-11 Eric Carlson <eric.carlson@apple.com>
[Mac] Track language selection should be sticky
https://bugs.webkit.org/show_bug.cgi?id=109466
Reviewed by Dean Jackson.
* Source/autotools/symbols.filter: Export PageGroup::captionPreferences and Page::initGroup.
2013-02-11 Benjamin Poulain <benjamin@webkit.org>
Kill TestRunner::setMinimumTimerInterval; implement the feature with InternalSettings
......
2013-02-11 Eric Carlson <eric.carlson@apple.com>
[Mac] Track language selection should be sticky
https://bugs.webkit.org/show_bug.cgi?id=109466
Reviewed by Dean Jackson.
* media/track/track-user-preferences-expected.txt: Added.
* media/track/track-user-preferences.html: Added.
* platform/chromium/TestExpectations: Skip new test, it depends on the track menu.
* platform/efl/TestExpectations: Ditto.
* platform/gtk/TestExpectations: Ditto.
* platform/qt/TestExpectations: Ditto.
* platform/win/TestExpectations: Ditto.
2013-02-11 Keishi Hattori <keishi@webkit.org>
REGRESSION (r140778):Calendar Picker buttons are wrong when rtl
Test track user preferences.
Set user languages to: ['no', 'es-ES', 'en', 'fr'].
Test 1: track selected because of 'default' attribute
- creating tracks for: [en,fr,no].
EVENT(load)
EXPECTED (event.target.srclang == 'fr') OK
EXPECTED (event.target.readyState == '2') OK
Test 2: track selected because of original user preferred language
- creating tracks for: [fr,en,no].
EVENT(load)
EXPECTED (event.target.srclang == 'no') OK
EXPECTED (event.target.readyState == '2') OK
Test 3: preferred language changed by selecting track from menu
- show captions menu.
- click on menu item 2.
EXPECTED (video.textTracks[0].mode == 'showing') OK
EXPECTED (video.textTracks[0].language == 'fr') OK
- creating tracks for: [no,fr,en].
EVENT(load)
EXPECTED (event.target.srclang == 'fr') OK
EXPECTED (event.target.readyState == '2') OK
Test 4: turning captions off from menu disables captions
- show captions menu.
- click on menu item 0.
- creating tracks for: [ru,jp,en].
EXPECTED (video.textTracks[0].mode == 'disabled') OK
EXPECTED (video.textTracks[1].mode == 'disabled') OK
EXPECTED (video.textTracks[2].mode == 'disabled') OK
END OF TEST
<!DOCTYPE html>
<html>
<head>
<title>Selecting from a list of tracks</title>
<script src="../media-controls.js"></script>
<script src="../media-file.js"></script>
<script src="../video-test.js"></script>
<script src="../trackmenu-test.js"></script>
<script>
var timer = null;
var expectedLanguage;
var testStage = 0;
var captionsButtonCoordinates;
function showCaptionMenu()
{
captionsButtonCoordinates = mediaControlsButtonCoordinates(video, "toggle-closed-captions-button");
consoleWrite("- show captions menu.");
eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]);
eventSender.mouseDown();
eventSender.mouseUp();
timer = setTimeout(nextStep, 100);
}
function trackMenuList()
{
var trackListElement = getTrackListElement();
if (!trackListElement)
return;
// Track list should have a <ul> with <li> children (One of them is "Off").
var trackList = trackListElement.querySelector("ul");
if (!trackList) {
failTest("Could not find a child ul element in track list menu");
return;
}
var trackListItems = trackList.querySelectorAll("li");
if (!trackListItems) {
failTest("Could not find child li elements in track list menu");
return;
}
return trackListItems;
}
function selectCaptionMenuItem(index)
{
consoleWrite("- click on menu item " + index + ".");
var trackListItems = trackMenuList();
var selectedTrackItem = trackListItems[index];
var boundingRect = selectedTrackItem.getBoundingClientRect();
var x = boundingRect.left + boundingRect.width / 2;
var y = boundingRect.top + boundingRect.height / 2;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
eventSender.mouseUp();
}
function trackLoaded()
{
consoleWrite("EVENT(load)");
testExpected("event.target.srclang", expectedLanguage);
testExpected("event.target.readyState", HTMLTrackElement.LOADED);
timer = setTimeout(nextStep, 200);
}
function createTrackElement(language, isDefault)
{
var track = document.createElement('track');
track.setAttribute('kind', "captions");
track.src = 'data:text/vtt,'+encodeURIComponent("WEBVTT\n\n00:00:00.000 --> 00:00:01.000\nCaption 1\n");
track.setAttribute('srclang', language);
track.setAttribute('onload', 'trackLoaded()');
if (isDefault)
track.setAttribute('default', 'default');
video.appendChild(track);
}
function createTrackElements(languages, defaultIndex)
{
var tracks = document.querySelectorAll('track');
for (var ndx = 0; ndx < tracks.length; ++ndx)
video.removeChild(tracks[ndx]);
consoleWrite("- creating tracks for: [" + languages + "].");
for (var ndx = 0; ndx < languages.length; ++ndx)
createTrackElement(languages[ndx], ndx == defaultIndex);
}
function nextStep()
{
++testStage;
switch (testStage) {
case 1:
consoleWrite("<br>Test 1: track selected because of 'default' attribute");
createTrackElements(['en', 'fr', 'no'], 1);
expectedLanguage = 'fr';
break;
case 2:
consoleWrite("<br>Test 2: track selected because of original user preferred language");
createTrackElements(['fr', 'en', 'no']);
expectedLanguage = 'no';
break;
case 3:
consoleWrite("<br>Test 3: preferred language changed by selecting track from menu");
showCaptionMenu();
break;
case 4:
selectCaptionMenuItem(2);
testExpected("video.textTracks[0].mode", "showing");
testExpected("video.textTracks[0].language", "fr");
expectedLanguage = 'fr';
createTrackElements([ 'no', 'fr', 'en']);
break;
case 5:
consoleWrite("<br>Test 4: turning captions off from menu disables captions");
showCaptionMenu();
break;
case 6:
selectCaptionMenuItem(0);
createTrackElements([ 'ru', 'jp', 'en']);
timer = setTimeout(nextStep, 250);
break;
case 7:
for (var ndx = 0; ndx < video.textTracks.length; ++ndx)
testExpected("video.textTracks[" + ndx + "].mode", "disabled");
consoleWrite("");
endTest();
return;
}
}
function start()
{
findMediaElement();
video.src = findMediaFile('video', '../content/test');
video.addEventListener('canplaythrough', nextStep);
consoleWrite("<br>Set user languages to: ['no', 'es-ES', 'en', 'fr'].");
internals.setUserPreferredLanguages(['no', 'es-ES', 'en', 'fr']);
}
</script>
</head>
<body onload="start()">
<p>Test track user preferences.</p>
<video width="500" height="300" controls>
</video>
</body>
</html>
......@@ -3605,6 +3605,7 @@ webkit.org/b/108429 svg/repaint/svgsvgelement-repaint-children.html [ Pass Failu
webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
webkit.org/b/101670 media/video-controls-captions-trackmenu-sorted.html [ Skip ]
webkit.org/b/101670 media/video-controls-captions-trackmenu-localized.html [ Skip ]
webkit.org/b/101670 media/track/track-user-preferences.html [ Skip ]
webkit.org/b/92835 [ Android Mac Win Debug ] svg/as-background-image/svg-as-background-5.html [ Pass Slow ]
......
......@@ -1722,6 +1722,7 @@ webkit.org/b/102493 fast/events/mouse-cursor.html [ Failure ]
webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
webkit.org/b/101670 media/video-controls-captions-trackmenu-sorted.html [ Skip ]
webkit.org/b/101670 media/video-controls-captions-trackmenu-localized.html [ Skip ]
webkit.org/b/101670 media/track/track-user-preferences.html [ Skip ]
# Fails until we enable the Resource Timing API.
webkit.org/b/61138 http/tests/w3c/webperf/submission/resource-timing [ Skip ]
......
......@@ -779,6 +779,7 @@ Bug(GTK) fast/media/print-restores-previous-mediatype.html [ Timeout ]
webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
webkit.org/b/101670 media/video-controls-captions-trackmenu-sorted.html [ Skip ]
webkit.org/b/101670 media/video-controls-captions-trackmenu-localized.html [ Skip ]
webkit.org/b/101670 media/track/track-user-preferences.html [ Skip ]
webkit.org/b/107194 storage/indexeddb/database-quota.html [ Timeout ]
webkit.org/b/107194 storage/indexeddb/pending-activity-workers.html [ Timeout ]
......
......@@ -2531,6 +2531,7 @@ webkit.org/b/100846 inspector-protocol/debugger-terminate-dedicated-worker-while
webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
webkit.org/b/101670 media/video-controls-captions-trackmenu-sorted.html [ Skip ]
webkit.org/b/101670 media/video-controls-captions-trackmenu-localized.html [ Skip ]
webkit.org/b/101670 media/track/track-user-preferences.html [ Skip ]
# New, but failing test
webkit.org/b/101035 fast/images/exif-orientation-image-document.html
......
......@@ -2523,6 +2523,7 @@ media/track/track-cue-rendering-snap-to-lines-not-set.html
media/track/track-cue-rendering-vertical.html
# https://bugs.webkit.org/show_bug.cgi?id=106477
media/track/track-user-preferences.html
media/video-controls-captions-trackmenu-localized.html
media/video-controls-captions-trackmenu-sorted.html
media/video-controls-captions-trackmenu.html
......
2013-02-11 Eric Carlson <eric.carlson@apple.com>
[Mac] Track language selection should be sticky
https://bugs.webkit.org/show_bug.cgi?id=109466
Reviewed by Dean Jackson.
Choosing a text track from the caption menu should make that track's language the
preferred caption language. Turning captions off from the menu should disable captions
in videos loaded subsequently.
OS X has system support for these settings, so changes made by DRT should not change the
settings on the user's system. Add support for all other ports in DRT only.
Test: media/track/track-user-preferences.html
* WebCore.exp.in: Export PageGroup::captionPreferences().
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): Use page()->group().captionPreferences().
(WebCore::HTMLMediaElement::attach): Ditto.
(WebCore::HTMLMediaElement::detach): Ditto.
(WebCore::HTMLMediaElement::userPrefersCaptions): Ditto.
(WebCore::HTMLMediaElement::configureTextTrackGroup): Ditto. Update for
preferredLanguageFromList change.
(WebCore::HTMLMediaElement::toggleTrackAtIndex): Set user prefs for captions visible and
caption language as appropriate.
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler): Remove unneeded comment.
(WebCore::MediaControlTextTrackContainerElement::updateSizes): Use page()->group().captionPreferences().
* html/shadow/MediaControlsApple.cpp:
(WebCore::MediaControlsApple::closedCaptionTracksChanged): Update caption menu button visibility.
* page/CaptionUserPreferences.h:
(WebCore::CaptionUserPreferences::userPrefersCaptions): Support "testing" mode.
(WebCore::CaptionUserPreferences::setUserPrefersCaptions): Ditto.
(WebCore::CaptionUserPreferences::registerForPreferencesChangedCallbacks): Ditto.
(WebCore::CaptionUserPreferences::unregisterForPreferencesChangedCallbacks): Ditto.
(WebCore::CaptionUserPreferences::setPreferredLanguage): Ditto.
(WebCore::CaptionUserPreferences::preferredLanguages): Ditto.
(WebCore::CaptionUserPreferences::testingMode): Ditto.
(WebCore::CaptionUserPreferences::setTestingMode): Ditto.
(WebCore::CaptionUserPreferences::CaptionUserPreferences): Ditto.
* page/CaptionUserPreferencesMac.h:
* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::userPrefersCaptions): Support "testing" mode.
(WebCore::CaptionUserPreferencesMac::setUserPrefersCaptions): Ditto.
(WebCore::CaptionUserPreferencesMac::userHasCaptionPreferences): Ditto.
(WebCore::CaptionUserPreferencesMac::registerForPreferencesChangedCallbacks): Change name from
registerForCaptionPreferencesChangedCallbacks. Support "testing" mode.
(WebCore::CaptionUserPreferencesMac::unregisterForPreferencesChangedCallbacks): Change name from
unregisterForCaptionPreferencesChangedCallbacks. Support "testing" mode.
(WebCore::CaptionUserPreferencesMac::captionsStyleSheetOverride): Support "testing" mode.
(WebCore::CaptionUserPreferencesMac::captionFontSizeScale): Ditto.
(WebCore::CaptionUserPreferencesMac::setPreferredLanguage): Ditto.
(WebCore::CaptionUserPreferencesMac::preferredLanguages): Ditto. Return the platform override when set.
* page/PageGroup.cpp:
(WebCore::PageGroup::registerForCaptionPreferencesChangedCallbacks): Remove because it is already
available from the caption preference object.
(WebCore::PageGroup::unregisterForCaptionPreferencesChangedCallbacks): Ditto.
(WebCore::PageGroup::userPrefersCaptions): Ditto.
(WebCore::PageGroup::userHasCaptionPreferences): Ditto.
(WebCore::PageGroup::captionFontSizeScale): Ditto.
* page/PageGroup.h:
* platform/Language.cpp:
(WebCore::preferredLanguageFromList): Take the list of preferred languages instead of assuming
the system list.
* platform/Language.h:
* testing/Internals.cpp:
(WebCore::Internals::resetToConsistentState): Disable caption testing mode.
(WebCore::Internals::Internals): Enable caption testing mode so the user's system
preferences are not modified.
2013-02-11 Huang Dongsung <luxtella@company100.net>
Coordinated Graphics: Make CoordinatedGraphicsScene not know contents size.
......@@ -2772,3 +2772,7 @@ __ZN7WebCore22RuntimeEnabledFeatures25areSeamlessIFramesEnabledE
#if ENABLE(ENCRYPTED_MEDIA_V2)
__ZN7WebCore3CDM18registerCDMFactoryEPFN3WTF10PassOwnPtrINS_19CDMPrivateInterfaceEEEPS0_EPFbRKNS1_6StringEE
#endif
#if ENABLE(VIDEO_TRACK)
__ZN7WebCore9PageGroup18captionPreferencesEv
#endif
......@@ -317,9 +317,9 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
#if ENABLE(VIDEO_TRACK)
if (document->page()) {
PageGroup& group = document->page()->group();
if (group.userHasCaptionPreferences())
m_disableCaptions = !group.userPrefersCaptions();
CaptionUserPreferences* captionPreferences = document->page()->group().captionPreferences();
if (captionPreferences->userHasCaptionPreferences())
m_disableCaptions = !captionPreferences->userPrefersCaptions();
}
#endif
}
......@@ -591,7 +591,7 @@ void HTMLMediaElement::attach()
#if ENABLE(VIDEO_TRACK)
if (document()->page())
document()->page()->group().registerForCaptionPreferencesChangedCallbacks(this);
document()->page()->group().captionPreferences()->registerForPreferencesChangedCallbacks(this);
#endif
}
......@@ -599,7 +599,7 @@ void HTMLMediaElement::detach()
{
#if ENABLE(VIDEO_TRACK)
if (document()->page())
document()->page()->group().unregisterForCaptionPreferencesChangedCallbacks(this);
document()->page()->group().captionPreferences()->unregisterForPreferencesChangedCallbacks(this);
#endif
HTMLElement::detach();
}
......@@ -2992,8 +2992,8 @@ bool HTMLMediaElement::userPrefersCaptions() const
if (!page)
return false;
PageGroup& group = page->group();
return group.userHasCaptionPreferences() && group.userPrefersCaptions();
CaptionUserPreferences* captionPreferences = page->group().captionPreferences();
return captionPreferences->userHasCaptionPreferences() && captionPreferences->userPrefersCaptions();
}
bool HTMLMediaElement::userIsInterestedInThisTrackKind(String kind) const
......@@ -3019,15 +3019,15 @@ void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group) const
ASSERT(group.tracks.size());
String bestMatchingLanguage;
if (group.hasSrcLang) {
Vector<String> languages;
languages.reserveInitialCapacity(group.tracks.size());
if (group.hasSrcLang && document()->page()) {
Vector<String> trackLanguages;
trackLanguages.reserveInitialCapacity(group.tracks.size());
for (size_t i = 0; i < group.tracks.size(); ++i) {
String srcLanguage = group.tracks[i]->language();
if (srcLanguage.length())
languages.append(srcLanguage);
trackLanguages.append(srcLanguage);
}
bestMatchingLanguage = preferredLanguageFromList(languages);
bestMatchingLanguage = preferredLanguageFromList(trackLanguages, document()->page()->group().captionPreferences()->preferredLanguages());
}
// First, find the track in the group that should be enabled (if any).
......@@ -3085,10 +3085,17 @@ void HTMLMediaElement::toggleTrackAtIndex(int index, bool exclusive)
if (!trackList || !trackList->length())
return;
CaptionUserPreferences* captionPreferences = document()->page() ? document()->page()->group().captionPreferences() : 0;
if (captionPreferences)
captionPreferences->setUserPrefersCaptions(index != textTracksOffIndex());
for (int i = 0, length = trackList->length(); i < length; ++i) {
TextTrack* track = trackList->item(i);
if (i == index)
if (i == index) {
track->setMode(TextTrack::showingKeyword());
if (captionPreferences && track->language().length())
captionPreferences->setPreferredLanguage(track->language());
}
else if (exclusive || index == HTMLMediaElement::textTracksOffIndex())
track->setMode(TextTrack::disabledKeyword());
}
......
......@@ -742,9 +742,6 @@ void MediaControlClosedCaptionsTrackListElement::defaultEventHandler(Event* even
{
#if ENABLE(VIDEO_TRACK)
if (event->type() == eventNames().clickEvent) {
// FIXME: Add modifier key for exclusivity override.
// http://webkit.org/b/103361
Node* target = event->target()->toNode();
if (!target || !target->isElementNode())
return;
......@@ -1329,7 +1326,7 @@ void MediaControlTextTrackContainerElement::updateSizes(bool forceUpdate)
float smallestDimension = std::min(m_videoDisplaySize.size().height(), m_videoDisplaySize.size().width());
bool important;
float fontSize = smallestDimension * (document()->page()->group().captionFontSizeScale(important));
float fontSize = smallestDimension * (document()->page()->group().captionPreferences()->captionFontSizeScale(important));
if (fontSize != m_fontSize) {
m_fontSize = fontSize;
setInlineStyleProperty(CSSPropertyFontSize, String::number(fontSize) + "px", important);
......
......@@ -500,6 +500,12 @@ void MediaControlsApple::closedCaptionTracksChanged()
{
if (m_closedCaptionsTrackList)
m_closedCaptionsTrackList->resetTrackListMenu();
if (m_toggleClosedCaptionsButton) {
if (m_mediaController->hasClosedCaptions())
m_toggleClosedCaptionsButton->show();
else
m_toggleClosedCaptionsButton->hide();
}
}
}
......
......@@ -50,16 +50,22 @@ public:
static PassOwnPtr<CaptionUserPreferences> create(PageGroup* group) { return adoptPtr(new CaptionUserPreferences(group)); }
virtual ~CaptionUserPreferences() { }
virtual bool userPrefersCaptions() const { return false; }
virtual void setUserPrefersCaptions(bool) { }
virtual bool userHasCaptionPreferences() const { return false; }
virtual bool userPrefersCaptions() const { return m_testingMode ? m_userPrefersCaptions : false; }
virtual void setUserPrefersCaptions(bool preference) { m_userPrefersCaptions = preference; }
virtual float captionFontSizeScale(bool& important) const { important = false; return 0.05f; }
virtual String captionsStyleSheetOverride() const { return emptyString(); }
virtual void registerForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { }
virtual void unregisterForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { }
virtual void registerForPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { }
virtual void unregisterForPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { }
virtual void setPreferredLanguage(String) const { }
virtual Vector<String> preferredLanguages() const { return platformUserPreferredLanguages(); }
virtual void setPreferredLanguage(String language) { m_userPreferredLanguage = language; }
virtual Vector<String> preferredLanguages() const
{
Vector<String> languages = userPreferredLanguages();
if (m_testingMode && !m_userPreferredLanguage.isEmpty())
languages.insert(0, m_userPreferredLanguage);
return languages;
}
virtual String displayNameForTrack(TextTrack* track) const
{
......@@ -70,13 +76,24 @@ public:
return track->language();
}
virtual bool testingMode() const { return m_testingMode; }
virtual void setTestingMode(bool override) { m_testingMode = override; }
PageGroup* pageGroup() { return m_pageGroup; }
protected:
CaptionUserPreferences(PageGroup* group) : m_pageGroup(group) { }
CaptionUserPreferences(PageGroup* group)
: m_pageGroup(group)
, m_testingMode(false)
, m_userPrefersCaptions(false)
{
}
private:
PageGroup* m_pageGroup;
String m_userPreferredLanguage;
bool m_testingMode;
bool m_userPrefersCaptions;
};
}
......
......@@ -41,15 +41,15 @@ public:
virtual ~CaptionUserPreferencesMac();
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
virtual bool userHasCaptionPreferences() const OVERRIDE;
virtual bool userPrefersCaptions() const OVERRIDE;
virtual void setUserPrefersCaptions(bool) OVERRIDE;
virtual bool userHasCaptionPreferences() const OVERRIDE;
virtual float captionFontSizeScale(bool&) const OVERRIDE;
virtual String captionsStyleSheetOverride() const OVERRIDE;
virtual void registerForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) OVERRIDE;
virtual void unregisterForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) OVERRIDE;
virtual void registerForPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) OVERRIDE;
virtual void unregisterForPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) OVERRIDE;
virtual void setPreferredLanguage(String) const OVERRIDE;
virtual void setPreferredLanguage(String) OVERRIDE;
virtual Vector<String> preferredLanguages() const OVERRIDE;
void captionPreferencesChanged();
......
......@@ -102,7 +102,7 @@ CaptionUserPreferencesMac::~CaptionUserPreferencesMac()
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
bool CaptionUserPreferencesMac::userPrefersCaptions() const
{
if (!MediaAccessibilityLibrary())
if (testingMode() || !MediaAccessibilityLibrary())
return CaptionUserPreferences::userPrefersCaptions();
return MACaptionAppearanceGetShowCaptions(kMACaptionAppearanceDomainUser);
......@@ -110,7 +110,7 @@ bool CaptionUserPreferencesMac::userPrefersCaptions() const
void CaptionUserPreferencesMac::setUserPrefersCaptions(bool preference)
{
if (!MediaAccessibilityLibrary()) {
if (testingMode() || !MediaAccessibilityLibrary()) {
CaptionUserPreferences::setUserPrefersCaptions(preference);
return;
}
......@@ -120,16 +120,16 @@ void CaptionUserPreferencesMac::setUserPrefersCaptions(bool preference)
bool CaptionUserPreferencesMac::userHasCaptionPreferences() const
{
if (!MediaAccessibilityLibrary())
if (testingMode() || !MediaAccessibilityLibrary())
return CaptionUserPreferences::userHasCaptionPreferences();
return !MediaAccessibilityLibrary();
return true;
}
void CaptionUserPreferencesMac::registerForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener* listener)
void CaptionUserPreferencesMac::registerForPreferencesChangedCallbacks(CaptionPreferencesChangedListener* listener)
{
if (!MediaAccessibilityLibrary()) {
CaptionUserPreferences::registerForCaptionPreferencesChangedCallbacks(listener);
CaptionUserPreferences::registerForPreferencesChangedCallbacks(listener);
return;
}
......@@ -147,10 +147,10 @@ void CaptionUserPreferencesMac::registerForCaptionPreferencesChangedCallbacks(Ca
m_captionPreferenceChangeListeners.add(listener);
}
void CaptionUserPreferencesMac::unregisterForCaptionPreferencesChangedCallbacks(CaptionPreferencesChangedListener* listener)
void CaptionUserPreferencesMac::unregisterForPreferencesChangedCallbacks(CaptionPreferencesChangedListener* listener)
{
if (!MediaAccessibilityLibrary()) {
CaptionUserPreferences::unregisterForCaptionPreferencesChangedCallbacks(listener);
CaptionUserPreferences::unregisterForPreferencesChangedCallbacks(listener);
return;
}
......@@ -358,7 +358,7 @@ String CaptionUserPreferencesMac::captionsDefaultFontCSS() const
String CaptionUserPreferencesMac::captionsStyleSheetOverride() const
{
if (!MediaAccessibilityLibrary())
if (testingMode() || !MediaAccessibilityLibrary())
return CaptionUserPreferences::captionsStyleSheetOverride();
StringBuilder captionsOverrideStyleSheet;
......@@ -403,7 +403,7 @@ String CaptionUserPreferencesMac::captionsStyleSheetOverride() const
float CaptionUserPreferencesMac::captionFontSizeScale(bool& important) const
{
if (!MediaAccessibilityLibrary())
if (testingMode() || !MediaAccessibilityLibrary())
return CaptionUserPreferences::captionFontSizeScale(important);
MACaptionAppearanceBehavior behavior;
......@@ -447,9 +447,9 @@ void CaptionUserPreferencesMac::updateCaptionStyleSheetOveride()
Vector<String>(), InjectInAllFrames, UserStyleAuthorLevel, InjectInExistingDocuments);
}
void CaptionUserPreferencesMac::setPreferredLanguage(String language) const
void CaptionUserPreferencesMac::setPreferredLanguage(String language)
{
if (!MediaAccessibilityLibrary()) {
if (testingMode() || !MediaAccessibilityLibrary()) {
CaptionUserPreferences::setPreferredLanguage(language);
return;
}
......@@ -459,23 +459,33 @@ void CaptionUserPreferencesMac::setPreferredLanguage(String language) const
Vector<String> CaptionUserPreferencesMac::preferredLanguages() const
{
Vector<String> override = userPreferredLanguagesOverride();
if (!override.isEmpty())
return override;
if (!MediaAccessibilityLibrary())
if (testingMode() || !MediaAccessibilityLibrary())
return CaptionUserPreferences::preferredLanguages();
Vector<String> platformLanguages = platformUserPreferredLanguages();
Vector<String> override = userPreferredLanguagesOverride();
if (!override.isEmpty()) {
if (platformLanguages.size() != override.size())
return override;
for (size_t i = 0; i < override.size(); i++) {
if (override[i] != platformLanguages[i])
return override;
}
}
RetainPtr<CFArrayRef> languages(AdoptCF, MACaptionAppearanceCopySelectedLanguages(kMACaptionAppearanceDomainUser));