eric.carlson@apple.com | 68e8da7 | 2012-10-24 14:24:43 +0000 | [diff] [blame] | 1 | /* |
| 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.com | f02a61a | 2013-02-04 19:39:31 +0000 | [diff] [blame] | 31 | #include "Language.h" |
dino@apple.com | 53a29d4 | 2013-02-05 08:03:22 +0000 | [diff] [blame] | 32 | #include "LocalizedStrings.h" |
| 33 | #include "TextTrack.h" |
eric.carlson@apple.com | 68e8da7 | 2012-10-24 14:24:43 +0000 | [diff] [blame] | 34 | #include <wtf/PassOwnPtr.h> |
| 35 | #include <wtf/text/AtomicString.h> |
| 36 | |
| 37 | namespace WebCore { |
| 38 | |
| 39 | class PageGroup; |
| 40 | |
| 41 | class CaptionPreferencesChangedListener { |
| 42 | public: |
| 43 | virtual void captionPreferencesChanged() = 0; |
| 44 | protected: |
| 45 | virtual ~CaptionPreferencesChangedListener() { } |
| 46 | }; |
| 47 | |
| 48 | class CaptionUserPreferences { |
| 49 | public: |
| 50 | static PassOwnPtr<CaptionUserPreferences> create(PageGroup* group) { return adoptPtr(new CaptionUserPreferences(group)); } |
| 51 | virtual ~CaptionUserPreferences() { } |
| 52 | |
eric.carlson@apple.com | 68e8da7 | 2012-10-24 14:24:43 +0000 | [diff] [blame] | 53 | virtual bool userHasCaptionPreferences() const { return false; } |
eric.carlson@apple.com | b54d1c8 | 2013-02-12 06:30:19 +0000 | [diff] [blame^] | 54 | virtual bool userPrefersCaptions() const { return m_testingMode ? m_userPrefersCaptions : false; } |
| 55 | virtual void setUserPrefersCaptions(bool preference) { m_userPrefersCaptions = preference; } |
eric.carlson@apple.com | f02a61a | 2013-02-04 19:39:31 +0000 | [diff] [blame] | 56 | virtual float captionFontSizeScale(bool& important) const { important = false; return 0.05f; } |
eric.carlson@apple.com | 68e8da7 | 2012-10-24 14:24:43 +0000 | [diff] [blame] | 57 | virtual String captionsStyleSheetOverride() const { return emptyString(); } |
eric.carlson@apple.com | b54d1c8 | 2013-02-12 06:30:19 +0000 | [diff] [blame^] | 58 | virtual void registerForPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { } |
| 59 | virtual void unregisterForPreferencesChangedCallbacks(CaptionPreferencesChangedListener*) { } |
eric.carlson@apple.com | 68e8da7 | 2012-10-24 14:24:43 +0000 | [diff] [blame] | 60 | |
eric.carlson@apple.com | b54d1c8 | 2013-02-12 06:30:19 +0000 | [diff] [blame^] | 61 | 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.com | f02a61a | 2013-02-04 19:39:31 +0000 | [diff] [blame] | 69 | |
dino@apple.com | 53a29d4 | 2013-02-05 08:03:22 +0000 | [diff] [blame] | 70 | 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.com | b54d1c8 | 2013-02-12 06:30:19 +0000 | [diff] [blame^] | 79 | virtual bool testingMode() const { return m_testingMode; } |
| 80 | virtual void setTestingMode(bool override) { m_testingMode = override; } |
| 81 | |
eric.carlson@apple.com | 68e8da7 | 2012-10-24 14:24:43 +0000 | [diff] [blame] | 82 | PageGroup* pageGroup() { return m_pageGroup; } |
| 83 | |
| 84 | protected: |
eric.carlson@apple.com | b54d1c8 | 2013-02-12 06:30:19 +0000 | [diff] [blame^] | 85 | CaptionUserPreferences(PageGroup* group) |
| 86 | : m_pageGroup(group) |
| 87 | , m_testingMode(false) |
| 88 | , m_userPrefersCaptions(false) |
| 89 | { |
| 90 | } |
eric.carlson@apple.com | 68e8da7 | 2012-10-24 14:24:43 +0000 | [diff] [blame] | 91 | |
| 92 | private: |
| 93 | PageGroup* m_pageGroup; |
eric.carlson@apple.com | b54d1c8 | 2013-02-12 06:30:19 +0000 | [diff] [blame^] | 94 | String m_userPreferredLanguage; |
| 95 | bool m_testingMode; |
| 96 | bool m_userPrefersCaptions; |
eric.carlson@apple.com | 68e8da7 | 2012-10-24 14:24:43 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | } |
| 100 | #endif |
| 101 | |
| 102 | #endif |