1/* 2 * Copyright (C) 2013, 2014 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. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef PlatformTextTrack_h 27#define PlatformTextTrack_h 28 29#if USE(PLATFORM_TEXT_TRACK_MENU) || ENABLE(AVF_CAPTIONS) 30 31#include <wtf/RefCounted.h> 32#include <wtf/text/WTFString.h> 33 34namespace WebCore { 35 36class TextTrack; 37class InbandTextTrackPrivate; 38 39class PlatformTextTrackClient { 40public: 41 virtual ~PlatformTextTrackClient() { } 42 43 virtual TextTrack* publicTrack() = 0; 44 virtual InbandTextTrackPrivate* privateTrack() { return 0; } 45}; 46 47class PlatformTextTrack : public RefCounted<PlatformTextTrack> { 48public: 49 enum TrackKind { 50 Subtitle = 0, 51 Caption = 1, 52 Description = 2, 53 Chapter = 3, 54 MetaData = 4, 55 Forced = 5, 56 }; 57 enum TrackType { 58 InBand = 0, 59 OutOfBand = 1, 60 Script = 2 61 }; 62 enum TrackMode { 63 Disabled, 64 Hidden, 65 Showing 66 }; 67 68 static PassRefPtr<PlatformTextTrack> create(PlatformTextTrackClient* client, const String& label, const String& language, TrackMode mode, TrackKind kind, TrackType type, int uniqueId) 69 { 70 return adoptRef(new PlatformTextTrack(client, label, language, String(), mode, kind, type, uniqueId, false)); 71 } 72 73 static PassRefPtr<PlatformTextTrack> createOutOfBand(const String& label, const String& language, const String& url, TrackMode mode, TrackKind kind, int uniqueId, bool isDefault) 74 { 75 return adoptRef(new PlatformTextTrack(nullptr, label, language, url, mode, kind, OutOfBand, uniqueId, isDefault)); 76 } 77 78 virtual ~PlatformTextTrack() { } 79 80 TrackType type() const { return m_type; } 81 TrackKind kind() const { return m_kind; } 82 TrackMode mode() const { return m_mode; } 83 const String& label() const { return m_label; } 84 const String& language() const { return m_language; } 85 const String& url() const { return m_url; } 86 PlatformTextTrackClient* client() const { return m_client; } 87 int uniqueId() const { return m_uniqueId; } 88 bool isDefault() const { return m_isDefault; } 89 90 static PlatformTextTrack* captionMenuOffItem() 91 { 92 static PlatformTextTrack* off = PlatformTextTrack::create(nullptr, "off menu item", "", Showing, Subtitle, InBand, 0).leakRef(); 93 return off; 94 } 95 96 static PlatformTextTrack* captionMenuAutomaticItem() 97 { 98 static PlatformTextTrack* automatic = PlatformTextTrack::create(nullptr, "automatic menu item", "", Showing, Subtitle, InBand, 0).leakRef(); 99 return automatic; 100 } 101 102protected: 103 PlatformTextTrack(PlatformTextTrackClient* client, const String& label, const String& language, const String& url, TrackMode mode, TrackKind kind, TrackType type, int uniqueId, bool isDefault) 104 : m_label(label) 105 , m_language(language) 106 , m_url(url) 107 , m_mode(mode) 108 , m_kind(kind) 109 , m_type(type) 110 , m_client(client) 111 , m_uniqueId(uniqueId) 112 , m_isDefault(isDefault) 113 { 114 } 115 116 String m_label; 117 String m_language; 118 String m_url; 119 TrackMode m_mode; 120 TrackKind m_kind; 121 TrackType m_type; 122 PlatformTextTrackClient* m_client; 123 int m_uniqueId; 124 bool m_isDefault; 125}; 126 127} 128 129#endif 130 131#endif // PlatformTextTrack_h 132