blob: 134890c88f4f79901350259f747d0d60c7fd6312 [file] [log] [blame]
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +00001/*
2 * Copyright (C) 2012 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#ifndef CaptionUserPreferences_h
27#define CaptionUserPreferences_h
28
29#if ENABLE(VIDEO_TRACK)
30
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.com68e8da72012-10-24 14:24:43 +000034#include <wtf/PassOwnPtr.h>
35#include <wtf/text/AtomicString.h>
36
37namespace WebCore {
38
39class PageGroup;
40
41class CaptionPreferencesChangedListener {
42public:
43 virtual void captionPreferencesChanged() = 0;
44protected:
45 virtual ~CaptionPreferencesChangedListener() { }
46};
47
48class CaptionUserPreferences {
49public:
50 static PassOwnPtr<CaptionUserPreferences> create(PageGroup* group) { return adoptPtr(new CaptionUserPreferences(group)); }
51 virtual ~CaptionUserPreferences() { }
52
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000053 virtual bool userHasCaptionPreferences() const { return false; }
eric.carlson@apple.comb54d1c82013-02-12 06:30:19 +000054 virtual bool userPrefersCaptions() const { return m_testingMode ? m_userPrefersCaptions : false; }
55 virtual void setUserPrefersCaptions(bool preference) { m_userPrefersCaptions = preference; }
eric.carlson@apple.comf02a61a2013-02-04 19:39:31 +000056 virtual float captionFontSizeScale(bool& important) const { important = false; return 0.05f; }
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000057 virtual String captionsStyleSheetOverride() const { return emptyString(); }
eric.carlson@apple.comb54d1c82013-02-12 06:30:19 +000058 virtual void registerForPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { }
59 virtual void unregisterForPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { }
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000060
eric.carlson@apple.comb54d1c82013-02-12 06:30:19 +000061 virtual void setPreferredLanguage(String language) { m_userPreferredLanguage = language; }
62 virtual Vector<String> preferredLanguages() const
63 {
64 Vector<String> languages = userPreferredLanguages();
65 if (m_testingMode && !m_userPreferredLanguage.isEmpty())
66 languages.insert(0, m_userPreferredLanguage);
67 return languages;
68 }
eric.carlson@apple.comf02a61a2013-02-04 19:39:31 +000069
dino@apple.com53a29d42013-02-05 08:03:22 +000070 virtual String displayNameForTrack(TextTrack* track) const
71 {
72 if (track->label().isEmpty() && track->language().isEmpty())
73 return textTrackNoLabelText();
74 if (!track->label().isEmpty())
75 return track->label();
76 return track->language();
77 }
78
eric.carlson@apple.comb54d1c82013-02-12 06:30:19 +000079 virtual bool testingMode() const { return m_testingMode; }
80 virtual void setTestingMode(bool override) { m_testingMode = override; }
81
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000082 PageGroup* pageGroup() { return m_pageGroup; }
83
84protected:
eric.carlson@apple.comb54d1c82013-02-12 06:30:19 +000085 CaptionUserPreferences(PageGroup* group)
86 : m_pageGroup(group)
87 , m_testingMode(false)
88 , m_userPrefersCaptions(false)
89 {
90 }
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000091
92private:
93 PageGroup* m_pageGroup;
eric.carlson@apple.comb54d1c82013-02-12 06:30:19 +000094 String m_userPreferredLanguage;
95 bool m_testingMode;
96 bool m_userPrefersCaptions;
eric.carlson@apple.com68e8da72012-10-24 14:24:43 +000097};
98
99}
100#endif
101
102#endif