1/*
2 * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
3 *
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
26#pragma once
27
28#if ENABLE(VIDEO_TRACK)
29
30#include "AudioTrack.h"
31#include "TextTrack.h"
32#include "Timer.h"
33
34namespace WebCore {
35
36class HTMLMediaElement;
37class PageGroup;
38class AudioTrackList;
39class TextTrackList;
40struct MediaSelectionOption;
41
42class CaptionUserPreferences {
43public:
44 CaptionUserPreferences(PageGroup&);
45 virtual ~CaptionUserPreferences();
46
47 enum CaptionDisplayMode {
48 Automatic,
49 ForcedOnly,
50 AlwaysOn,
51 Manual,
52 };
53 virtual CaptionDisplayMode captionDisplayMode() const;
54 virtual void setCaptionDisplayMode(CaptionDisplayMode);
55
56 virtual int textTrackSelectionScore(TextTrack*, HTMLMediaElement*) const;
57 virtual int textTrackLanguageSelectionScore(TextTrack*, const Vector<String>&) const;
58
59 virtual bool userPrefersCaptions() const;
60 virtual void setUserPrefersCaptions(bool);
61
62 virtual bool userPrefersSubtitles() const;
63 virtual void setUserPrefersSubtitles(bool preference);
64
65 virtual bool userPrefersTextDescriptions() const;
66 virtual void setUserPrefersTextDescriptions(bool preference);
67
68 virtual float captionFontSizeScaleAndImportance(bool& important) const { important = false; return 0.05f; }
69
70 virtual bool captionStrokeWidthForFont(float, const String&, float&, bool&) const { return false; }
71
72 virtual String captionsStyleSheetOverride() const { return m_captionsStyleSheetOverride; }
73 virtual void setCaptionsStyleSheetOverride(const String&);
74
75 virtual void setInterestedInCaptionPreferenceChanges() { }
76
77 virtual void captionPreferencesChanged();
78
79 virtual void setPreferredLanguage(const String&);
80 virtual Vector<String> preferredLanguages() const;
81
82 virtual void setPreferredAudioCharacteristic(const String&);
83 virtual Vector<String> preferredAudioCharacteristics() const;
84
85 virtual String displayNameForTrack(TextTrack*) const;
86 MediaSelectionOption mediaSelectionOptionForTrack(TextTrack*) const;
87 virtual Vector<RefPtr<TextTrack>> sortedTrackListForMenu(TextTrackList*);
88
89 virtual String displayNameForTrack(AudioTrack*) const;
90 MediaSelectionOption mediaSelectionOptionForTrack(AudioTrack*) const;
91 virtual Vector<RefPtr<AudioTrack>> sortedTrackListForMenu(AudioTrackList*);
92
93 void setPrimaryAudioTrackLanguageOverride(const String& language) { m_primaryAudioTrackLanguageOverride = language; }
94 String primaryAudioTrackLanguageOverride() const;
95
96 virtual bool testingMode() const { return m_testingMode; }
97 void setTestingMode(bool override) { m_testingMode = override; }
98
99 PageGroup& pageGroup() const { return m_pageGroup; }
100
101protected:
102 void updateCaptionStyleSheetOverride();
103 void beginBlockingNotifications();
104 void endBlockingNotifications();
105
106private:
107 void timerFired();
108 void notify();
109 Page* currentPage() const;
110
111 PageGroup& m_pageGroup;
112 mutable CaptionDisplayMode m_displayMode;
113 Timer m_timer;
114 String m_userPreferredLanguage;
115 String m_userPreferredAudioCharacteristic;
116 String m_captionsStyleSheetOverride;
117 String m_primaryAudioTrackLanguageOverride;
118 unsigned m_blockNotificationsCounter { 0 };
119 bool m_testingMode { false };
120 bool m_havePreferences { false };
121};
122
123}
124#endif
125