CaptionUserPreferences.h 3.87 KB
Newer Older
1
/*
2
 * Copyright (C) 2012, 2013  Apple Inc. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

#ifndef CaptionUserPreferences_h
#define CaptionUserPreferences_h

#if ENABLE(VIDEO_TRACK)

31
#include "Language.h"
32 33
#include "LocalizedStrings.h"
#include "TextTrack.h"
34
#include "Timer.h"
35 36 37 38 39
#include <wtf/PassOwnPtr.h>
#include <wtf/text/AtomicString.h>

namespace WebCore {

40
class HTMLMediaElement;
41
class PageGroup;
42
class TextTrackList;
43 44 45

class CaptionUserPreferences {
public:
46
    CaptionUserPreferences(PageGroup&);
47
    virtual ~CaptionUserPreferences();
48

49 50 51 52 53 54 55
    enum CaptionDisplayMode {
        Automatic,
        ForcedOnly,
        AlwaysOn
    };
    virtual CaptionDisplayMode captionDisplayMode() const;
    virtual void setCaptionDisplayMode(CaptionDisplayMode);
56

57
    virtual int textTrackSelectionScore(TextTrack*, HTMLMediaElement*) const;
58
    virtual int textTrackLanguageSelectionScore(TextTrack*, const Vector<String>&) const;
59

60 61 62 63 64 65 66 67 68
    virtual bool userPrefersCaptions() const;
    virtual void setUserPrefersCaptions(bool);

    virtual bool userPrefersSubtitles() const;
    virtual void setUserPrefersSubtitles(bool preference);
    
    virtual bool userPrefersTextDescriptions() const;
    virtual void setUserPrefersTextDescriptions(bool preference);

69 70 71 72
    virtual float captionFontSizeScaleAndImportance(bool& important) const { important = false; return 0.05f; }

    virtual String captionsStyleSheetOverride() const { return m_captionsStyleSheetOverride; }
    virtual void setCaptionsStyleSheetOverride(const String&);
73

74 75
    virtual void setInterestedInCaptionPreferenceChanges() { }

76
    virtual void captionPreferencesChanged();
77

78
    virtual void setPreferredLanguage(const String&);
79 80 81
    virtual Vector<String> preferredLanguages() const;

    virtual String displayNameForTrack(TextTrack*) const;
82
    virtual Vector<RefPtr<TextTrack>> sortedTrackListForMenu(TextTrackList*);
83

84 85 86
    void setPrimaryAudioTrackLanguageOverride(const String& language) { m_primaryAudioTrackLanguageOverride = language;  }
    String primaryAudioTrackLanguageOverride() const;

87 88
    virtual bool testingMode() const { return m_testingMode; }
    virtual void setTestingMode(bool override) { m_testingMode = override; }
89
    
90
    PageGroup& pageGroup() const { return m_pageGroup; }
91 92

protected:
93
    void updateCaptionStyleSheetOveride();
94 95

private:
96
    void timerFired(Timer<CaptionUserPreferences>&);
97 98
    void notify();

99
    PageGroup& m_pageGroup;
100
    CaptionDisplayMode m_displayMode;
101
    Timer<CaptionUserPreferences> m_timer;
102
    String m_userPreferredLanguage;
103
    String m_captionsStyleSheetOverride;
104
    String m_primaryAudioTrackLanguageOverride;
105
    bool m_testingMode;
106
    bool m_havePreferences;
107 108 109 110 111 112
};
    
}
#endif

#endif