1/*
2 * Copyright (C) 2011 Google 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 are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "config.h"
32
33#if ENABLE(VIDEO_TRACK)
34
35#include "TextTrack.h"
36
37#include "TextTrackCueList.h"
38#include "TextTrackPrivate.h"
39
40namespace WebCore {
41
42class NullTextTrackPrivate : public TextTrackPrivateInterface {
43public:
44 NullTextTrackPrivate();
45 virtual ~NullTextTrackPrivate();
46
47 // TextTrackPrivateInterface methods
48 virtual String kind() const { return emptyString(); }
49 virtual String label() const { return emptyString(); }
50 virtual String language() const { return emptyString(); }
51 virtual TextTrack::ReadyState readyState() const { return TextTrack::NONE; }
52 virtual TextTrack::Mode mode() const { return TextTrack::OFF; }
53 virtual void setMode(TextTrack::Mode) { }
54 virtual PassRefPtr<TextTrackCueList> cues() const { return 0; }
55 virtual PassRefPtr<TextTrackCueList> activeCues() const { return 0; }
56 virtual void load(const String&) { }
57};
58
59static PassOwnPtr<NullTextTrackPrivate> createNullTextTrackPrivate()
60{
61 return adoptPtr(new NullTextTrackPrivate());
62}
63
64TextTrack::TextTrack()
65 : m_private(createNullTextTrackPrivate())
66{
67}
68
69TextTrack::~TextTrack()
70{
71}
72
73String TextTrack::kind() const
74{
75 return m_private->kind();
76}
77
78String TextTrack::label() const
79{
80 return m_private->label();
81}
82
83String TextTrack::language() const
84{
85 return m_private->language();
86}
87
88TextTrack::ReadyState TextTrack::readyState() const
89{
90 return m_private->readyState();
91}
92
93TextTrack::Mode TextTrack::mode() const
94{
95 return m_private->mode();
96}
97
98void TextTrack::setMode(unsigned short mode, ExceptionCode& ec)
99{
100 // 4.8.10.12.5 On setting the mode, if the new value is not either 0, 1, or 2,
101 // the user agent must throw an INVALID_ACCESS_ERR exception.
102 if (mode == TextTrack::OFF || mode == TextTrack::HIDDEN || mode == TextTrack::SHOWING)
103 m_private->setMode(static_cast<Mode>(mode));
104 else
105 ec = INVALID_ACCESS_ERR;
106}
107
108PassRefPtr<TextTrackCueList> TextTrack::cues() const
109{
110 return m_private->cues();
111}
112
113PassRefPtr<TextTrackCueList> TextTrack::activeCues() const
114{
115 return m_private->activeCues();
116}
117
118} // namespace WebCore
119
120#endif