OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | |
3 * Copyright (C) 2011, 2012 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 #include "core/html/shadow/MediaControlsChromium.h" | |
29 | |
30 #include "bindings/v8/ExceptionState.h" | |
31 #include "bindings/v8/ExceptionStatePlaceholder.h" | |
32 | |
33 using namespace std; | |
34 | |
35 namespace WebCore { | |
36 | |
37 MediaControlsChromium::MediaControlsChromium(Document& document) | |
38 : MediaControls(document) | |
39 , m_durationDisplay(0) | |
40 , m_enclosure(0) | |
41 { | |
42 } | |
43 | |
44 // MediaControls::create() for Android is defined in MediaControlsChromiumAndroi
d.cpp. | |
45 #if !OS(ANDROID) | |
46 PassRefPtr<MediaControls> MediaControls::create(Document& document) | |
47 { | |
48 return MediaControlsChromium::createControls(document); | |
49 } | |
50 #endif | |
51 | |
52 PassRefPtr<MediaControlsChromium> MediaControlsChromium::createControls(Document
& document) | |
53 { | |
54 if (!document.page()) | |
55 return 0; | |
56 | |
57 RefPtr<MediaControlsChromium> controls = adoptRef(new MediaControlsChromium(
document)); | |
58 | |
59 if (controls->initializeControls(document)) | |
60 return controls.release(); | |
61 | |
62 return 0; | |
63 } | |
64 | |
65 bool MediaControlsChromium::initializeControls(Document& document) | |
66 { | |
67 // Create an enclosing element for the panel so we can visually offset the c
ontrols correctly. | |
68 RefPtr<MediaControlPanelEnclosureElement> enclosure = MediaControlPanelEnclo
sureElement::create(document); | |
69 | |
70 RefPtr<MediaControlPanelElement> panel = MediaControlPanelElement::create(do
cument); | |
71 | |
72 TrackExceptionState exceptionState; | |
73 | |
74 RefPtr<MediaControlPlayButtonElement> playButton = MediaControlPlayButtonEle
ment::create(document); | |
75 m_playButton = playButton.get(); | |
76 panel->appendChild(playButton.release(), exceptionState); | |
77 if (exceptionState.hadException()) | |
78 return false; | |
79 | |
80 RefPtr<MediaControlTimelineElement> timeline = MediaControlTimelineElement::
create(document, this); | |
81 m_timeline = timeline.get(); | |
82 panel->appendChild(timeline.release(), exceptionState); | |
83 if (exceptionState.hadException()) | |
84 return false; | |
85 | |
86 RefPtr<MediaControlCurrentTimeDisplayElement> currentTimeDisplay = MediaCont
rolCurrentTimeDisplayElement::create(document); | |
87 m_currentTimeDisplay = currentTimeDisplay.get(); | |
88 m_currentTimeDisplay->hide(); | |
89 panel->appendChild(currentTimeDisplay.release(), exceptionState); | |
90 if (exceptionState.hadException()) | |
91 return false; | |
92 | |
93 RefPtr<MediaControlTimeRemainingDisplayElement> durationDisplay = MediaContr
olTimeRemainingDisplayElement::create(document); | |
94 m_durationDisplay = durationDisplay.get(); | |
95 panel->appendChild(durationDisplay.release(), exceptionState); | |
96 if (exceptionState.hadException()) | |
97 return false; | |
98 | |
99 RefPtr<MediaControlPanelMuteButtonElement> panelMuteButton = MediaControlPan
elMuteButtonElement::create(document, this); | |
100 m_panelMuteButton = panelMuteButton.get(); | |
101 panel->appendChild(panelMuteButton.release(), exceptionState); | |
102 if (exceptionState.hadException()) | |
103 return false; | |
104 | |
105 RefPtr<MediaControlPanelVolumeSliderElement> slider = MediaControlPanelVolum
eSliderElement::create(document); | |
106 m_volumeSlider = slider.get(); | |
107 m_volumeSlider->setClearMutedOnUserInteraction(true); | |
108 panel->appendChild(slider.release(), exceptionState); | |
109 if (exceptionState.hadException()) | |
110 return false; | |
111 | |
112 RefPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClosedCaptionsBu
tton = MediaControlToggleClosedCaptionsButtonElement::create(document, this); | |
113 m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get(); | |
114 panel->appendChild(toggleClosedCaptionsButton.release(), exceptionState); | |
115 if (exceptionState.hadException()) | |
116 return false; | |
117 | |
118 RefPtr<MediaControlFullscreenButtonElement> fullscreenButton = MediaControlF
ullscreenButtonElement::create(document); | |
119 m_fullScreenButton = fullscreenButton.get(); | |
120 panel->appendChild(fullscreenButton.release(), exceptionState); | |
121 if (exceptionState.hadException()) | |
122 return false; | |
123 | |
124 m_panel = panel.get(); | |
125 enclosure->appendChild(panel.release(), exceptionState); | |
126 if (exceptionState.hadException()) | |
127 return false; | |
128 | |
129 m_enclosure = enclosure.get(); | |
130 appendChild(enclosure.release(), exceptionState); | |
131 if (exceptionState.hadException()) | |
132 return false; | |
133 | |
134 return true; | |
135 } | |
136 | |
137 void MediaControlsChromium::setMediaController(MediaControllerInterface* control
ler) | |
138 { | |
139 if (m_mediaController == controller) | |
140 return; | |
141 | |
142 MediaControls::setMediaController(controller); | |
143 | |
144 if (m_durationDisplay) | |
145 m_durationDisplay->setMediaController(controller); | |
146 if (m_enclosure) | |
147 m_enclosure->setMediaController(controller); | |
148 } | |
149 | |
150 void MediaControlsChromium::reset() | |
151 { | |
152 Page* page = document().page(); | |
153 if (!page) | |
154 return; | |
155 | |
156 double duration = m_mediaController->duration(); | |
157 m_durationDisplay->setInnerText(RenderTheme::theme().formatMediaControlsTime
(duration), ASSERT_NO_EXCEPTION); | |
158 m_durationDisplay->setCurrentValue(duration); | |
159 | |
160 MediaControls::reset(); | |
161 } | |
162 | |
163 void MediaControlsChromium::playbackStarted() | |
164 { | |
165 m_currentTimeDisplay->show(); | |
166 m_durationDisplay->hide(); | |
167 | |
168 MediaControls::playbackStarted(); | |
169 } | |
170 | |
171 void MediaControlsChromium::updateCurrentTimeDisplay() | |
172 { | |
173 double now = m_mediaController->currentTime(); | |
174 double duration = m_mediaController->duration(); | |
175 | |
176 Page* page = document().page(); | |
177 if (!page) | |
178 return; | |
179 | |
180 // After seek, hide duration display and show current time. | |
181 if (now > 0) { | |
182 m_currentTimeDisplay->show(); | |
183 m_durationDisplay->hide(); | |
184 } | |
185 | |
186 // Allow the theme to format the time. | |
187 m_currentTimeDisplay->setInnerText(RenderTheme::theme().formatMediaControlsC
urrentTime(now, duration), IGNORE_EXCEPTION); | |
188 m_currentTimeDisplay->setCurrentValue(now); | |
189 } | |
190 | |
191 void MediaControlsChromium::changedMute() | |
192 { | |
193 MediaControls::changedMute(); | |
194 | |
195 if (m_mediaController->muted()) | |
196 m_volumeSlider->setVolume(0); | |
197 else | |
198 m_volumeSlider->setVolume(m_mediaController->volume()); | |
199 } | |
200 | |
201 void MediaControlsChromium::createTextTrackDisplay() | |
202 { | |
203 if (m_textDisplayContainer) | |
204 return; | |
205 | |
206 RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaCo
ntrolTextTrackContainerElement::create(document()); | |
207 m_textDisplayContainer = textDisplayContainer.get(); | |
208 | |
209 if (m_mediaController) | |
210 m_textDisplayContainer->setMediaController(m_mediaController); | |
211 | |
212 insertTextTrackContainer(textDisplayContainer.release()); | |
213 } | |
214 | |
215 void MediaControlsChromium::insertTextTrackContainer(PassRefPtr<MediaControlText
TrackContainerElement> textTrackContainer) | |
216 { | |
217 // Insert it before the first controller element so it always displays behin
d the controls. | |
218 // In the Chromium case, that's the enclosure element. | |
219 insertBefore(textTrackContainer, m_enclosure); | |
220 } | |
221 | |
222 | |
223 } | |
OLD | NEW |