~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/html/shadow/MediaControlsChromium.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
 
3
 * Copyright (C) 2011 Google Inc. All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 * 1. Redistributions of source code must retain the above copyright
 
9
 *    notice, this list of conditions and the following disclaimer.
 
10
 * 2. Redistributions in binary form must reproduce the above copyright
 
11
 *    notice, this list of conditions and the following disclaimer in the
 
12
 *    documentation and/or other materials provided with the distribution.
 
13
 *
 
14
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 
15
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
17
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 
18
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
19
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
20
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
21
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
22
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
24
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
25
 */
 
26
 
 
27
#include "config.h"
 
28
 
 
29
#if ENABLE(VIDEO)
 
30
#include "MediaControlsChromium.h"
 
31
 
 
32
using namespace std;
 
33
 
 
34
namespace WebCore {
 
35
 
 
36
MediaControlChromiumEnclosureElement::MediaControlChromiumEnclosureElement(Document* document)
 
37
    : MediaControlElement(document)
 
38
{
 
39
}
 
40
 
 
41
MediaControlElementType MediaControlChromiumEnclosureElement::displayType() const
 
42
{
 
43
    // Mapping onto same MediaControlElementType as panel element, since it has similar properties.
 
44
    return MediaControlsPanel;
 
45
}
 
46
 
 
47
MediaControlPanelEnclosureElement::MediaControlPanelEnclosureElement(Document* document)
 
48
    : MediaControlChromiumEnclosureElement(document)
 
49
{
 
50
}
 
51
 
 
52
PassRefPtr<MediaControlPanelEnclosureElement> MediaControlPanelEnclosureElement::create(Document* document)
 
53
{
 
54
    return adoptRef(new MediaControlPanelEnclosureElement(document));
 
55
}
 
56
 
 
57
const AtomicString& MediaControlPanelEnclosureElement::shadowPseudoId() const
 
58
{
 
59
    DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-enclosure"));
 
60
    return id;
 
61
}
 
62
 
 
63
MediaControlsChromium::MediaControlsChromium(Document* document)
 
64
    : MediaControls(document)
 
65
    , m_durationDisplay(0)
 
66
    , m_enclosure(0)
 
67
{
 
68
}
 
69
 
 
70
// MediaControls::create() for Android is defined in MediaControlsChromiumAndroid.cpp.
 
71
#if !OS(ANDROID)
 
72
PassRefPtr<MediaControls> MediaControls::create(Document* document)
 
73
{
 
74
    return MediaControlsChromium::createControls(document);
 
75
}
 
76
#endif
 
77
 
 
78
PassRefPtr<MediaControlsChromium> MediaControlsChromium::createControls(Document* document)
 
79
{
 
80
    if (!document->page())
 
81
        return 0;
 
82
 
 
83
    RefPtr<MediaControlsChromium> controls = adoptRef(new MediaControlsChromium(document));
 
84
 
 
85
    if (controls->initializeControls(document))
 
86
        return controls.release();
 
87
 
 
88
    return 0;
 
89
}
 
90
 
 
91
bool MediaControlsChromium::initializeControls(Document* document)
 
92
{
 
93
    // Create an enclosing element for the panel so we can visually offset the controls correctly.
 
94
    RefPtr<MediaControlPanelEnclosureElement> enclosure = MediaControlPanelEnclosureElement::create(document);
 
95
 
 
96
    RefPtr<MediaControlPanelElement> panel = MediaControlPanelElement::create(document);
 
97
 
 
98
    ExceptionCode ec;
 
99
 
 
100
    RefPtr<MediaControlPlayButtonElement> playButton = MediaControlPlayButtonElement::create(document);
 
101
    m_playButton = playButton.get();
 
102
    panel->appendChild(playButton.release(), ec, true);
 
103
    if (ec)
 
104
        return false;
 
105
 
 
106
    RefPtr<MediaControlTimelineElement> timeline = MediaControlTimelineElement::create(document, this);
 
107
    m_timeline = timeline.get();
 
108
    panel->appendChild(timeline.release(), ec, true);
 
109
    if (ec)
 
110
        return false;
 
111
 
 
112
    RefPtr<MediaControlCurrentTimeDisplayElement> currentTimeDisplay = MediaControlCurrentTimeDisplayElement::create(document);
 
113
    m_currentTimeDisplay = currentTimeDisplay.get();
 
114
    m_currentTimeDisplay->hide();
 
115
    panel->appendChild(currentTimeDisplay.release(), ec, true);
 
116
    if (ec)
 
117
        return false;
 
118
 
 
119
    RefPtr<MediaControlTimeRemainingDisplayElement> durationDisplay = MediaControlTimeRemainingDisplayElement::create(document);
 
120
    m_durationDisplay = durationDisplay.get();
 
121
    panel->appendChild(durationDisplay.release(), ec, true);
 
122
    if (ec)
 
123
        return false;
 
124
 
 
125
    RefPtr<MediaControlPanelMuteButtonElement> panelMuteButton = MediaControlPanelMuteButtonElement::create(document, this);
 
126
    m_panelMuteButton = panelMuteButton.get();
 
127
    panel->appendChild(panelMuteButton.release(), ec, true);
 
128
    if (ec)
 
129
        return false;
 
130
 
 
131
    RefPtr<MediaControlVolumeSliderElement> slider = MediaControlVolumeSliderElement::create(document);
 
132
    m_volumeSlider = slider.get();
 
133
    m_volumeSlider->setClearMutedOnUserInteraction(true);
 
134
    panel->appendChild(slider.release(), ec, true);
 
135
    if (ec)
 
136
        return false;
 
137
 
 
138
    if (document->page()->theme()->supportsClosedCaptioning()) {
 
139
        RefPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClosedCaptionsButton = MediaControlToggleClosedCaptionsButtonElement::create(document, this);
 
140
        m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get();
 
141
        panel->appendChild(toggleClosedCaptionsButton.release(), ec, true);
 
142
        if (ec)
 
143
            return false;
 
144
    }
 
145
 
 
146
    RefPtr<MediaControlFullscreenButtonElement> fullscreenButton = MediaControlFullscreenButtonElement::create(document, this);
 
147
    m_fullScreenButton = fullscreenButton.get();
 
148
    panel->appendChild(fullscreenButton.release(), ec, true);
 
149
    if (ec)
 
150
        return false;
 
151
 
 
152
    m_panel = panel.get();
 
153
    enclosure->appendChild(panel.release(), ec, true);
 
154
    if (ec)
 
155
        return false;
 
156
 
 
157
    m_enclosure = enclosure.get();
 
158
    appendChild(enclosure.release(), ec, true);
 
159
    if (ec)
 
160
        return false;
 
161
 
 
162
    return true;
 
163
}
 
164
 
 
165
void MediaControlsChromium::setMediaController(MediaControllerInterface* controller)
 
166
{
 
167
    if (m_mediaController == controller)
 
168
        return;
 
169
 
 
170
    MediaControls::setMediaController(controller);
 
171
 
 
172
    if (m_durationDisplay)
 
173
        m_durationDisplay->setMediaController(controller);
 
174
    if (m_enclosure)
 
175
        m_enclosure->setMediaController(controller);
 
176
}
 
177
 
 
178
void MediaControlsChromium::reset()
 
179
{
 
180
    Page* page = document()->page();
 
181
    if (!page)
 
182
        return;
 
183
 
 
184
    float duration = m_mediaController->duration();
 
185
    m_durationDisplay->setInnerText(page->theme()->formatMediaControlsTime(duration), ASSERT_NO_EXCEPTION);
 
186
    m_durationDisplay->setCurrentValue(duration);
 
187
 
 
188
    MediaControls::reset();
 
189
}
 
190
 
 
191
void MediaControlsChromium::playbackStarted()
 
192
{
 
193
    m_currentTimeDisplay->show();
 
194
    m_durationDisplay->hide();
 
195
 
 
196
    MediaControls::playbackStarted();
 
197
}
 
198
 
 
199
void MediaControlsChromium::updateCurrentTimeDisplay()
 
200
{
 
201
    float now = m_mediaController->currentTime();
 
202
    float duration = m_mediaController->duration();
 
203
 
 
204
    Page* page = document()->page();
 
205
    if (!page)
 
206
        return;
 
207
 
 
208
    // After seek, hide duration display and show current time.
 
209
    if (now > 0) {
 
210
        m_currentTimeDisplay->show();
 
211
        m_durationDisplay->hide();
 
212
    }
 
213
 
 
214
    // Allow the theme to format the time.
 
215
    ExceptionCode ec;
 
216
    m_currentTimeDisplay->setInnerText(page->theme()->formatMediaControlsCurrentTime(now, duration), ec);
 
217
    m_currentTimeDisplay->setCurrentValue(now);
 
218
}
 
219
 
 
220
void MediaControlsChromium::changedMute()
 
221
{
 
222
    MediaControls::changedMute();
 
223
 
 
224
    if (m_mediaController->muted())
 
225
        m_volumeSlider->setVolume(0);
 
226
    else
 
227
        m_volumeSlider->setVolume(m_mediaController->volume());
 
228
}
 
229
 
 
230
#if ENABLE(VIDEO_TRACK)
 
231
void MediaControlsChromium::createTextTrackDisplay()
 
232
{
 
233
    if (m_textDisplayContainer)
 
234
        return;
 
235
 
 
236
    RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaControlTextTrackContainerElement::create(document());
 
237
    m_textDisplayContainer = textDisplayContainer.get();
 
238
 
 
239
    if (m_mediaController)
 
240
        m_textDisplayContainer->setMediaController(m_mediaController);
 
241
 
 
242
    // Insert it before the first controller element so it always displays behind the controls.
 
243
    // In the Chromium case, that's the enclosure element.
 
244
    insertBefore(textDisplayContainer.release(), m_enclosure, ASSERT_NO_EXCEPTION, true);
 
245
}
 
246
#endif
 
247
 
 
248
}
 
249
 
 
250
#endif