blob: 8feea7da2d3d32466de8a0f3abf1627545031827 [file] [log] [blame]
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +00001/*
bfulgham@apple.com3137b822016-09-16 21:20:23 +00002 * Copyright (C) 2012-2016 Apple Inc. All rights reserved.
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
bfulgham@apple.com3137b822016-09-16 21:20:23 +000026#pragma once
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000027
28#if ENABLE(VIDEO_TRACK)
29
jer.noble@apple.com8cadb6f2014-10-07 19:11:53 +000030#include "AudioTrack.h"
eric.carlson@apple.comf02a61a2013-02-04 19:39:31 +000031#include "Language.h"
dino@apple.com53a29d42013-02-05 08:03:22 +000032#include "LocalizedStrings.h"
33#include "TextTrack.h"
eric.carlson@apple.com62bb7dc2013-03-20 20:13:36 +000034#include "Timer.h"
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000035#include <wtf/text/AtomicString.h>
36
37namespace WebCore {
38
eric.carlson@apple.com92907e12013-03-27 18:45:29 +000039class HTMLMediaElement;
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000040class PageGroup;
jer.noble@apple.com8cadb6f2014-10-07 19:11:53 +000041class AudioTrackList;
eric.carlson@apple.com62bb7dc2013-03-20 20:13:36 +000042class TextTrackList;
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000043
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000044class CaptionUserPreferences {
45public:
commit-queue@webkit.org88e62d52014-01-30 07:42:07 +000046 CaptionUserPreferences(PageGroup&);
eric.carlson@apple.com62bb7dc2013-03-20 20:13:36 +000047 virtual ~CaptionUserPreferences();
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000048
eric.carlson@apple.com44f8c682013-04-04 22:23:47 +000049 enum CaptionDisplayMode {
50 Automatic,
51 ForcedOnly,
eric.carlson@apple.com6fde4d42016-02-02 16:38:02 +000052 AlwaysOn,
53 Manual,
eric.carlson@apple.com44f8c682013-04-04 22:23:47 +000054 };
55 virtual CaptionDisplayMode captionDisplayMode() const;
56 virtual void setCaptionDisplayMode(CaptionDisplayMode);
eric.carlson@apple.com62bb7dc2013-03-20 20:13:36 +000057
eric.carlson@apple.com92907e12013-03-27 18:45:29 +000058 virtual int textTrackSelectionScore(TextTrack*, HTMLMediaElement*) const;
eric.carlson@apple.com44f8c682013-04-04 22:23:47 +000059 virtual int textTrackLanguageSelectionScore(TextTrack*, const Vector<String>&) const;
commit-queue@webkit.org88e62d52014-01-30 07:42:07 +000060
61 virtual bool userPrefersCaptions() const;
62 virtual void setUserPrefersCaptions(bool);
63
64 virtual bool userPrefersSubtitles() const;
65 virtual void setUserPrefersSubtitles(bool preference);
66
67 virtual bool userPrefersTextDescriptions() const;
68 virtual void setUserPrefersTextDescriptions(bool preference);
eric.carlson@apple.com62bb7dc2013-03-20 20:13:36 +000069
eric.carlson@apple.comc1ce91d2013-04-09 20:56:27 +000070 virtual float captionFontSizeScaleAndImportance(bool& important) const { important = false; return 0.05f; }
71
commit-queue@webkit.org88e62d52014-01-30 07:42:07 +000072 virtual String captionsStyleSheetOverride() const { return m_captionsStyleSheetOverride; }
73 virtual void setCaptionsStyleSheetOverride(const String&);
74
75 virtual void setInterestedInCaptionPreferenceChanges() { }
76
77 virtual void captionPreferencesChanged();
78
eric.carlson@apple.com44f8c682013-04-04 22:23:47 +000079 virtual void setPreferredLanguage(const String&);
eric.carlson@apple.com70109502013-02-13 22:57:11 +000080 virtual Vector<String> preferredLanguages() const;
81
jer.noble@apple.comaac38302015-05-22 23:15:37 +000082 virtual void setPreferredAudioCharacteristic(const String&);
83 virtual Vector<String> preferredAudioCharacteristics() const;
84
eric.carlson@apple.com70109502013-02-13 22:57:11 +000085 virtual String displayNameForTrack(TextTrack*) const;
andersca@apple.com64f1b5a2013-09-08 03:17:30 +000086 virtual Vector<RefPtr<TextTrack>> sortedTrackListForMenu(TextTrackList*);
dino@apple.com53a29d42013-02-05 08:03:22 +000087
jer.noble@apple.com8cadb6f2014-10-07 19:11:53 +000088 virtual String displayNameForTrack(AudioTrack*) const;
89 virtual Vector<RefPtr<AudioTrack>> sortedTrackListForMenu(AudioTrackList*);
90
eric.carlson@apple.com502400b2013-04-12 17:23:42 +000091 void setPrimaryAudioTrackLanguageOverride(const String& language) { m_primaryAudioTrackLanguageOverride = language; }
92 String primaryAudioTrackLanguageOverride() const;
commit-queue@webkit.org88e62d52014-01-30 07:42:07 +000093
94 virtual bool testingMode() const { return m_testingMode; }
darin@apple.com11ff47c2016-03-04 16:47:55 +000095 void setTestingMode(bool override) { m_testingMode = override; }
eric.carlson@apple.com44f8c682013-04-04 22:23:47 +000096
commit-queue@webkit.org88e62d52014-01-30 07:42:07 +000097 PageGroup& pageGroup() const { return m_pageGroup; }
98
99protected:
commit-queue@webkit.org54e3e402016-05-11 05:03:30 +0000100 void updateCaptionStyleSheetOverride();
eric.carlson@apple.com6fde4d42016-02-02 16:38:02 +0000101 void beginBlockingNotifications();
102 void endBlockingNotifications();
commit-queue@webkit.org88e62d52014-01-30 07:42:07 +0000103
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +0000104private:
andersca@apple.com574a7452014-11-21 20:10:13 +0000105 void timerFired();
eric.carlson@apple.com62bb7dc2013-03-20 20:13:36 +0000106 void notify();
bfulgham@apple.com3137b822016-09-16 21:20:23 +0000107 Page* currentPage() const;
eric.carlson@apple.com62bb7dc2013-03-20 20:13:36 +0000108
commit-queue@webkit.org88e62d52014-01-30 07:42:07 +0000109 PageGroup& m_pageGroup;
eric.carlson@apple.com6fde4d42016-02-02 16:38:02 +0000110 mutable CaptionDisplayMode m_displayMode;
jer.noble@apple.com50862fe2014-11-06 23:06:03 +0000111 Timer m_timer;
eric.carlson@apple.comb54d1c82013-02-12 06:30:19 +0000112 String m_userPreferredLanguage;
jer.noble@apple.comaac38302015-05-22 23:15:37 +0000113 String m_userPreferredAudioCharacteristic;
eric.carlson@apple.comc1ce91d2013-04-09 20:56:27 +0000114 String m_captionsStyleSheetOverride;
eric.carlson@apple.com502400b2013-04-12 17:23:42 +0000115 String m_primaryAudioTrackLanguageOverride;
eric.carlson@apple.com6fde4d42016-02-02 16:38:02 +0000116 unsigned m_blockNotificationsCounter { 0 };
bfulgham@apple.com3137b822016-09-16 21:20:23 +0000117 bool m_testingMode { false };
118 bool m_havePreferences { false };
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +0000119};
commit-queue@webkit.org88e62d52014-01-30 07:42:07 +0000120
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +0000121}
122#endif