OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. |
3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 30 matching lines...) Expand all Loading... |
41 , m_playButton(0) | 41 , m_playButton(0) |
42 , m_currentTimeDisplay(0) | 42 , m_currentTimeDisplay(0) |
43 , m_timeline(0) | 43 , m_timeline(0) |
44 , m_panelMuteButton(0) | 44 , m_panelMuteButton(0) |
45 , m_volumeSlider(0) | 45 , m_volumeSlider(0) |
46 , m_toggleClosedCaptionsButton(0) | 46 , m_toggleClosedCaptionsButton(0) |
47 , m_fullScreenButton(0) | 47 , m_fullScreenButton(0) |
48 , m_hideFullscreenControlsTimer(this, &MediaControls::hideFullscreenControls
TimerFired) | 48 , m_hideFullscreenControlsTimer(this, &MediaControls::hideFullscreenControls
TimerFired) |
49 , m_isFullscreen(false) | 49 , m_isFullscreen(false) |
50 , m_isMouseOverControls(false) | 50 , m_isMouseOverControls(false) |
51 , m_durationDisplay(0) | |
52 , m_enclosure(0) | |
53 { | 51 { |
54 } | 52 } |
55 | 53 |
56 // MediaControls::create() for Android is defined in MediaControlsChromiumAndroi
d.cpp. | |
57 #if !OS(ANDROID) | |
58 PassRefPtr<MediaControls> MediaControls::create(Document& document) | |
59 { | |
60 if (!document.page()) | |
61 return 0; | |
62 | |
63 RefPtr<MediaControls> controls = adoptRef(new MediaControls(document)); | |
64 | |
65 if (controls->initializeControls(document)) | |
66 return controls.release(); | |
67 | |
68 return 0; | |
69 } | |
70 #endif | |
71 | |
72 bool MediaControls::initializeControls(Document& document) | |
73 { | |
74 // Create an enclosing element for the panel so we can visually offset the c
ontrols correctly. | |
75 RefPtr<MediaControlPanelEnclosureElement> enclosure = MediaControlPanelEnclo
sureElement::create(document); | |
76 | |
77 RefPtr<MediaControlPanelElement> panel = MediaControlPanelElement::create(do
cument); | |
78 | |
79 TrackExceptionState exceptionState; | |
80 | |
81 RefPtr<MediaControlPlayButtonElement> playButton = MediaControlPlayButtonEle
ment::create(document); | |
82 m_playButton = playButton.get(); | |
83 panel->appendChild(playButton.release(), exceptionState); | |
84 if (exceptionState.hadException()) | |
85 return false; | |
86 | |
87 RefPtr<MediaControlTimelineElement> timeline = MediaControlTimelineElement::
create(document, this); | |
88 m_timeline = timeline.get(); | |
89 panel->appendChild(timeline.release(), exceptionState); | |
90 if (exceptionState.hadException()) | |
91 return false; | |
92 | |
93 RefPtr<MediaControlCurrentTimeDisplayElement> currentTimeDisplay = MediaCont
rolCurrentTimeDisplayElement::create(document); | |
94 m_currentTimeDisplay = currentTimeDisplay.get(); | |
95 m_currentTimeDisplay->hide(); | |
96 panel->appendChild(currentTimeDisplay.release(), exceptionState); | |
97 if (exceptionState.hadException()) | |
98 return false; | |
99 | |
100 RefPtr<MediaControlTimeRemainingDisplayElement> durationDisplay = MediaContr
olTimeRemainingDisplayElement::create(document); | |
101 m_durationDisplay = durationDisplay.get(); | |
102 panel->appendChild(durationDisplay.release(), exceptionState); | |
103 if (exceptionState.hadException()) | |
104 return false; | |
105 | |
106 RefPtr<MediaControlPanelMuteButtonElement> panelMuteButton = MediaControlPan
elMuteButtonElement::create(document, this); | |
107 m_panelMuteButton = panelMuteButton.get(); | |
108 panel->appendChild(panelMuteButton.release(), exceptionState); | |
109 if (exceptionState.hadException()) | |
110 return false; | |
111 | |
112 RefPtr<MediaControlPanelVolumeSliderElement> slider = MediaControlPanelVolum
eSliderElement::create(document); | |
113 m_volumeSlider = slider.get(); | |
114 m_volumeSlider->setClearMutedOnUserInteraction(true); | |
115 panel->appendChild(slider.release(), exceptionState); | |
116 if (exceptionState.hadException()) | |
117 return false; | |
118 | |
119 RefPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClosedCaptionsBu
tton = MediaControlToggleClosedCaptionsButtonElement::create(document, this); | |
120 m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get(); | |
121 panel->appendChild(toggleClosedCaptionsButton.release(), exceptionState); | |
122 if (exceptionState.hadException()) | |
123 return false; | |
124 | |
125 RefPtr<MediaControlFullscreenButtonElement> fullscreenButton = MediaControlF
ullscreenButtonElement::create(document); | |
126 m_fullScreenButton = fullscreenButton.get(); | |
127 panel->appendChild(fullscreenButton.release(), exceptionState); | |
128 if (exceptionState.hadException()) | |
129 return false; | |
130 | |
131 m_panel = panel.get(); | |
132 enclosure->appendChild(panel.release(), exceptionState); | |
133 if (exceptionState.hadException()) | |
134 return false; | |
135 | |
136 m_enclosure = enclosure.get(); | |
137 appendChild(enclosure.release(), exceptionState); | |
138 if (exceptionState.hadException()) | |
139 return false; | |
140 | |
141 return true; | |
142 } | |
143 | |
144 void MediaControls::setMediaController(MediaControllerInterface* controller) | 54 void MediaControls::setMediaController(MediaControllerInterface* controller) |
145 { | 55 { |
146 if (m_mediaController == controller) | 56 if (m_mediaController == controller) |
147 return; | 57 return; |
148 m_mediaController = controller; | 58 m_mediaController = controller; |
149 | 59 |
150 if (m_panel) | 60 if (m_panel) |
151 m_panel->setMediaController(controller); | 61 m_panel->setMediaController(controller); |
152 if (m_textDisplayContainer) | 62 if (m_textDisplayContainer) |
153 m_textDisplayContainer->setMediaController(controller); | 63 m_textDisplayContainer->setMediaController(controller); |
154 if (m_playButton) | 64 if (m_playButton) |
155 m_playButton->setMediaController(controller); | 65 m_playButton->setMediaController(controller); |
156 if (m_currentTimeDisplay) | 66 if (m_currentTimeDisplay) |
157 m_currentTimeDisplay->setMediaController(controller); | 67 m_currentTimeDisplay->setMediaController(controller); |
158 if (m_timeline) | 68 if (m_timeline) |
159 m_timeline->setMediaController(controller); | 69 m_timeline->setMediaController(controller); |
160 if (m_panelMuteButton) | 70 if (m_panelMuteButton) |
161 m_panelMuteButton->setMediaController(controller); | 71 m_panelMuteButton->setMediaController(controller); |
162 if (m_volumeSlider) | 72 if (m_volumeSlider) |
163 m_volumeSlider->setMediaController(controller); | 73 m_volumeSlider->setMediaController(controller); |
164 if (m_toggleClosedCaptionsButton) | 74 if (m_toggleClosedCaptionsButton) |
165 m_toggleClosedCaptionsButton->setMediaController(controller); | 75 m_toggleClosedCaptionsButton->setMediaController(controller); |
166 if (m_fullScreenButton) | 76 if (m_fullScreenButton) |
167 m_fullScreenButton->setMediaController(controller); | 77 m_fullScreenButton->setMediaController(controller); |
168 if (m_durationDisplay) | |
169 m_durationDisplay->setMediaController(controller); | |
170 if (m_enclosure) | |
171 m_enclosure->setMediaController(controller); | |
172 } | 78 } |
173 | 79 |
174 void MediaControls::reset() | 80 void MediaControls::reset() |
175 { | 81 { |
176 Page* page = document().page(); | 82 Page* page = document().page(); |
177 if (!page) | 83 if (!page) |
178 return; | 84 return; |
179 | 85 |
180 double duration = m_mediaController->duration(); | |
181 m_durationDisplay->setInnerText(RenderTheme::theme().formatMediaControlsTime
(duration), ASSERT_NO_EXCEPTION); | |
182 m_durationDisplay->setCurrentValue(duration); | |
183 | |
184 m_playButton->updateDisplayType(); | 86 m_playButton->updateDisplayType(); |
185 | 87 |
186 updateCurrentTimeDisplay(); | 88 updateCurrentTimeDisplay(); |
187 | 89 |
188 m_timeline->setDuration(m_mediaController->duration()); | 90 m_timeline->setDuration(m_mediaController->duration()); |
189 m_timeline->setPosition(m_mediaController->currentTime()); | 91 m_timeline->setPosition(m_mediaController->currentTime()); |
190 | 92 |
191 m_panelMuteButton->show(); | 93 m_panelMuteButton->show(); |
192 | 94 |
193 if (m_volumeSlider) { | 95 if (m_volumeSlider) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 void MediaControls::bufferingProgressed() | 144 void MediaControls::bufferingProgressed() |
243 { | 145 { |
244 // We only need to update buffering progress when paused, during normal | 146 // We only need to update buffering progress when paused, during normal |
245 // playback playbackProgressed() will take care of it. | 147 // playback playbackProgressed() will take care of it. |
246 if (m_mediaController->paused()) | 148 if (m_mediaController->paused()) |
247 m_timeline->setPosition(m_mediaController->currentTime()); | 149 m_timeline->setPosition(m_mediaController->currentTime()); |
248 } | 150 } |
249 | 151 |
250 void MediaControls::playbackStarted() | 152 void MediaControls::playbackStarted() |
251 { | 153 { |
252 m_currentTimeDisplay->show(); | |
253 m_durationDisplay->hide(); | |
254 | |
255 m_playButton->updateDisplayType(); | 154 m_playButton->updateDisplayType(); |
256 m_timeline->setPosition(m_mediaController->currentTime()); | 155 m_timeline->setPosition(m_mediaController->currentTime()); |
257 updateCurrentTimeDisplay(); | 156 updateCurrentTimeDisplay(); |
258 | 157 |
259 if (m_isFullscreen) | 158 if (m_isFullscreen) |
260 startHideFullscreenControlsTimer(); | 159 startHideFullscreenControlsTimer(); |
261 } | 160 } |
262 | 161 |
263 void MediaControls::playbackProgressed() | 162 void MediaControls::playbackProgressed() |
264 { | 163 { |
265 m_timeline->setPosition(m_mediaController->currentTime()); | 164 m_timeline->setPosition(m_mediaController->currentTime()); |
266 updateCurrentTimeDisplay(); | 165 updateCurrentTimeDisplay(); |
267 | 166 |
268 if (!m_isMouseOverControls && m_mediaController->hasVideo()) | 167 if (!m_isMouseOverControls && m_mediaController->hasVideo()) |
269 makeTransparent(); | 168 makeTransparent(); |
270 } | 169 } |
271 | 170 |
272 void MediaControls::playbackStopped() | 171 void MediaControls::playbackStopped() |
273 { | 172 { |
274 m_playButton->updateDisplayType(); | 173 m_playButton->updateDisplayType(); |
275 m_timeline->setPosition(m_mediaController->currentTime()); | 174 m_timeline->setPosition(m_mediaController->currentTime()); |
276 updateCurrentTimeDisplay(); | 175 updateCurrentTimeDisplay(); |
277 makeOpaque(); | 176 makeOpaque(); |
278 | 177 |
279 stopHideFullscreenControlsTimer(); | 178 stopHideFullscreenControlsTimer(); |
280 } | 179 } |
281 | 180 |
282 void MediaControls::updateCurrentTimeDisplay() | |
283 { | |
284 double now = m_mediaController->currentTime(); | |
285 double duration = m_mediaController->duration(); | |
286 | |
287 Page* page = document().page(); | |
288 if (!page) | |
289 return; | |
290 | |
291 // After seek, hide duration display and show current time. | |
292 if (now > 0) { | |
293 m_currentTimeDisplay->show(); | |
294 m_durationDisplay->hide(); | |
295 } | |
296 | |
297 // Allow the theme to format the time. | |
298 m_currentTimeDisplay->setInnerText(RenderTheme::theme().formatMediaControlsC
urrentTime(now, duration), IGNORE_EXCEPTION); | |
299 m_currentTimeDisplay->setCurrentValue(now); | |
300 } | |
301 | |
302 void MediaControls::showVolumeSlider() | 181 void MediaControls::showVolumeSlider() |
303 { | 182 { |
304 if (!m_mediaController->hasAudio()) | 183 if (!m_mediaController->hasAudio()) |
305 return; | 184 return; |
306 | 185 |
307 m_volumeSlider->show(); | 186 m_volumeSlider->show(); |
308 } | 187 } |
309 | 188 |
310 void MediaControls::changedMute() | 189 void MediaControls::changedMute() |
311 { | 190 { |
312 m_panelMuteButton->changedMute(); | 191 m_panelMuteButton->changedMute(); |
313 | |
314 if (m_mediaController->muted()) | |
315 m_volumeSlider->setVolume(0); | |
316 else | |
317 m_volumeSlider->setVolume(m_mediaController->volume()); | |
318 } | 192 } |
319 | 193 |
320 void MediaControls::changedVolume() | 194 void MediaControls::changedVolume() |
321 { | 195 { |
322 if (m_volumeSlider) | 196 if (m_volumeSlider) |
323 m_volumeSlider->setVolume(m_mediaController->volume()); | 197 m_volumeSlider->setVolume(m_mediaController->volume()); |
324 if (m_panelMuteButton && m_panelMuteButton->renderer()) | 198 if (m_panelMuteButton && m_panelMuteButton->renderer()) |
325 m_panelMuteButton->renderer()->repaint(); | 199 m_panelMuteButton->renderer()->repaint(); |
326 } | 200 } |
327 | 201 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 { | 322 { |
449 if (m_textDisplayContainer) | 323 if (m_textDisplayContainer) |
450 return; | 324 return; |
451 | 325 |
452 RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaCo
ntrolTextTrackContainerElement::create(document()); | 326 RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaCo
ntrolTextTrackContainerElement::create(document()); |
453 m_textDisplayContainer = textDisplayContainer.get(); | 327 m_textDisplayContainer = textDisplayContainer.get(); |
454 | 328 |
455 if (m_mediaController) | 329 if (m_mediaController) |
456 m_textDisplayContainer->setMediaController(m_mediaController); | 330 m_textDisplayContainer->setMediaController(m_mediaController); |
457 | 331 |
458 insertTextTrackContainer(textDisplayContainer.release()); | 332 // Insert it before the first controller element so it always displays behin
d the controls. |
| 333 insertBefore(textDisplayContainer.release(), m_panel, IGNORE_EXCEPTION); |
459 } | 334 } |
460 | 335 |
461 void MediaControls::showTextTrackDisplay() | 336 void MediaControls::showTextTrackDisplay() |
462 { | 337 { |
463 if (!m_textDisplayContainer) | 338 if (!m_textDisplayContainer) |
464 createTextTrackDisplay(); | 339 createTextTrackDisplay(); |
465 m_textDisplayContainer->show(); | 340 m_textDisplayContainer->show(); |
466 } | 341 } |
467 | 342 |
468 void MediaControls::hideTextTrackDisplay() | 343 void MediaControls::hideTextTrackDisplay() |
469 { | 344 { |
470 if (!m_textDisplayContainer) | 345 if (!m_textDisplayContainer) |
471 createTextTrackDisplay(); | 346 createTextTrackDisplay(); |
472 m_textDisplayContainer->hide(); | 347 m_textDisplayContainer->hide(); |
473 } | 348 } |
474 | 349 |
475 void MediaControls::updateTextTrackDisplay() | 350 void MediaControls::updateTextTrackDisplay() |
476 { | 351 { |
477 if (!m_textDisplayContainer) | 352 if (!m_textDisplayContainer) |
478 createTextTrackDisplay(); | 353 createTextTrackDisplay(); |
479 | 354 |
480 m_textDisplayContainer->updateDisplay(); | 355 m_textDisplayContainer->updateDisplay(); |
481 } | 356 } |
482 | 357 |
483 void MediaControls::insertTextTrackContainer(PassRefPtr<MediaControlTextTrackCon
tainerElement> textTrackContainer) | |
484 { | |
485 // Insert it before the first controller element so it always displays behin
d the controls. | |
486 insertBefore(textTrackContainer, m_enclosure); | |
487 } | 358 } |
488 | |
489 } | |
OLD | NEW |