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 10 matching lines...) Expand all Loading... |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #include "core/html/shadow/MediaControls.h" | 28 #include "core/html/shadow/MediaControls.h" |
29 | 29 |
30 #include "bindings/v8/ExceptionStatePlaceholder.h" | 30 #include "bindings/v8/ExceptionStatePlaceholder.h" |
| 31 #if OS(ANDROID) |
| 32 #include "core/html/shadow/MediaControlsChromiumAndroid.h" |
| 33 #endif |
31 | 34 |
32 namespace WebCore { | 35 namespace WebCore { |
33 | 36 |
34 static const double timeWithoutMouseMovementBeforeHidingFullscreenControls = 3; | 37 static const double timeWithoutMouseMovementBeforeHidingFullscreenControls = 3; |
35 | 38 |
36 MediaControls::MediaControls(Document& document) | 39 MediaControls::MediaControls(Document& document) |
37 : HTMLDivElement(document) | 40 : HTMLDivElement(document) |
38 , m_mediaController(0) | 41 , m_mediaController(0) |
39 , m_panel(0) | 42 , m_panel(0) |
40 , m_textDisplayContainer(0) | 43 , m_textDisplayContainer(0) |
41 , m_playButton(0) | 44 , m_playButton(0) |
42 , m_currentTimeDisplay(0) | 45 , m_currentTimeDisplay(0) |
43 , m_timeline(0) | 46 , m_timeline(0) |
44 , m_panelMuteButton(0) | 47 , m_panelMuteButton(0) |
45 , m_volumeSlider(0) | 48 , m_volumeSlider(0) |
46 , m_toggleClosedCaptionsButton(0) | 49 , m_toggleClosedCaptionsButton(0) |
47 , m_fullScreenButton(0) | 50 , m_fullScreenButton(0) |
48 , m_hideFullscreenControlsTimer(this, &MediaControls::hideFullscreenControls
TimerFired) | 51 , m_hideFullscreenControlsTimer(this, &MediaControls::hideFullscreenControls
TimerFired) |
49 , m_isFullscreen(false) | 52 , m_isFullscreen(false) |
50 , m_isMouseOverControls(false) | 53 , m_isMouseOverControls(false) |
| 54 , m_durationDisplay(0) |
| 55 , m_enclosure(0) |
51 { | 56 { |
52 } | 57 } |
53 | 58 |
| 59 PassRefPtr<MediaControls> MediaControls::create(Document& document) |
| 60 { |
| 61 if (!document.page()) |
| 62 return 0; |
| 63 |
| 64 RefPtr<MediaControls> controls; |
| 65 #if OS(ANDROID) |
| 66 controls = adoptRef(new MediaControlsChromiumAndroid(document)); |
| 67 #else |
| 68 controls = adoptRef(new MediaControls(document)); |
| 69 #endif |
| 70 |
| 71 if (controls->initializeControls(document)) |
| 72 return controls.release(); |
| 73 |
| 74 return 0; |
| 75 } |
| 76 |
| 77 bool MediaControls::initializeControls(Document& document) |
| 78 { |
| 79 // Create an enclosing element for the panel so we can visually offset the c
ontrols correctly. |
| 80 RefPtr<MediaControlPanelEnclosureElement> enclosure = MediaControlPanelEnclo
sureElement::create(document); |
| 81 |
| 82 RefPtr<MediaControlPanelElement> panel = MediaControlPanelElement::create(do
cument); |
| 83 |
| 84 TrackExceptionState exceptionState; |
| 85 |
| 86 RefPtr<MediaControlPlayButtonElement> playButton = MediaControlPlayButtonEle
ment::create(document); |
| 87 m_playButton = playButton.get(); |
| 88 panel->appendChild(playButton.release(), exceptionState); |
| 89 if (exceptionState.hadException()) |
| 90 return false; |
| 91 |
| 92 RefPtr<MediaControlTimelineElement> timeline = MediaControlTimelineElement::
create(document, this); |
| 93 m_timeline = timeline.get(); |
| 94 panel->appendChild(timeline.release(), exceptionState); |
| 95 if (exceptionState.hadException()) |
| 96 return false; |
| 97 |
| 98 RefPtr<MediaControlCurrentTimeDisplayElement> currentTimeDisplay = MediaCont
rolCurrentTimeDisplayElement::create(document); |
| 99 m_currentTimeDisplay = currentTimeDisplay.get(); |
| 100 m_currentTimeDisplay->hide(); |
| 101 panel->appendChild(currentTimeDisplay.release(), exceptionState); |
| 102 if (exceptionState.hadException()) |
| 103 return false; |
| 104 |
| 105 RefPtr<MediaControlTimeRemainingDisplayElement> durationDisplay = MediaContr
olTimeRemainingDisplayElement::create(document); |
| 106 m_durationDisplay = durationDisplay.get(); |
| 107 panel->appendChild(durationDisplay.release(), exceptionState); |
| 108 if (exceptionState.hadException()) |
| 109 return false; |
| 110 |
| 111 RefPtr<MediaControlPanelMuteButtonElement> panelMuteButton = MediaControlPan
elMuteButtonElement::create(document, this); |
| 112 m_panelMuteButton = panelMuteButton.get(); |
| 113 panel->appendChild(panelMuteButton.release(), exceptionState); |
| 114 if (exceptionState.hadException()) |
| 115 return false; |
| 116 |
| 117 RefPtr<MediaControlPanelVolumeSliderElement> slider = MediaControlPanelVolum
eSliderElement::create(document); |
| 118 m_volumeSlider = slider.get(); |
| 119 m_volumeSlider->setClearMutedOnUserInteraction(true); |
| 120 panel->appendChild(slider.release(), exceptionState); |
| 121 if (exceptionState.hadException()) |
| 122 return false; |
| 123 |
| 124 RefPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClosedCaptionsBu
tton = MediaControlToggleClosedCaptionsButtonElement::create(document, this); |
| 125 m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get(); |
| 126 panel->appendChild(toggleClosedCaptionsButton.release(), exceptionState); |
| 127 if (exceptionState.hadException()) |
| 128 return false; |
| 129 |
| 130 RefPtr<MediaControlFullscreenButtonElement> fullscreenButton = MediaControlF
ullscreenButtonElement::create(document); |
| 131 m_fullScreenButton = fullscreenButton.get(); |
| 132 panel->appendChild(fullscreenButton.release(), exceptionState); |
| 133 if (exceptionState.hadException()) |
| 134 return false; |
| 135 |
| 136 m_panel = panel.get(); |
| 137 enclosure->appendChild(panel.release(), exceptionState); |
| 138 if (exceptionState.hadException()) |
| 139 return false; |
| 140 |
| 141 m_enclosure = enclosure.get(); |
| 142 appendChild(enclosure.release(), exceptionState); |
| 143 if (exceptionState.hadException()) |
| 144 return false; |
| 145 |
| 146 return true; |
| 147 } |
| 148 |
54 void MediaControls::setMediaController(MediaControllerInterface* controller) | 149 void MediaControls::setMediaController(MediaControllerInterface* controller) |
55 { | 150 { |
56 if (m_mediaController == controller) | 151 if (m_mediaController == controller) |
57 return; | 152 return; |
58 m_mediaController = controller; | 153 m_mediaController = controller; |
59 | 154 |
60 if (m_panel) | 155 if (m_panel) |
61 m_panel->setMediaController(controller); | 156 m_panel->setMediaController(controller); |
62 if (m_textDisplayContainer) | 157 if (m_textDisplayContainer) |
63 m_textDisplayContainer->setMediaController(controller); | 158 m_textDisplayContainer->setMediaController(controller); |
64 if (m_playButton) | 159 if (m_playButton) |
65 m_playButton->setMediaController(controller); | 160 m_playButton->setMediaController(controller); |
66 if (m_currentTimeDisplay) | 161 if (m_currentTimeDisplay) |
67 m_currentTimeDisplay->setMediaController(controller); | 162 m_currentTimeDisplay->setMediaController(controller); |
68 if (m_timeline) | 163 if (m_timeline) |
69 m_timeline->setMediaController(controller); | 164 m_timeline->setMediaController(controller); |
70 if (m_panelMuteButton) | 165 if (m_panelMuteButton) |
71 m_panelMuteButton->setMediaController(controller); | 166 m_panelMuteButton->setMediaController(controller); |
72 if (m_volumeSlider) | 167 if (m_volumeSlider) |
73 m_volumeSlider->setMediaController(controller); | 168 m_volumeSlider->setMediaController(controller); |
74 if (m_toggleClosedCaptionsButton) | 169 if (m_toggleClosedCaptionsButton) |
75 m_toggleClosedCaptionsButton->setMediaController(controller); | 170 m_toggleClosedCaptionsButton->setMediaController(controller); |
76 if (m_fullScreenButton) | 171 if (m_fullScreenButton) |
77 m_fullScreenButton->setMediaController(controller); | 172 m_fullScreenButton->setMediaController(controller); |
| 173 if (m_durationDisplay) |
| 174 m_durationDisplay->setMediaController(controller); |
| 175 if (m_enclosure) |
| 176 m_enclosure->setMediaController(controller); |
78 } | 177 } |
79 | 178 |
80 void MediaControls::reset() | 179 void MediaControls::reset() |
81 { | 180 { |
82 Page* page = document().page(); | 181 Page* page = document().page(); |
83 if (!page) | 182 if (!page) |
84 return; | 183 return; |
85 | 184 |
| 185 double duration = m_mediaController->duration(); |
| 186 m_durationDisplay->setInnerText(RenderTheme::theme().formatMediaControlsTime
(duration), ASSERT_NO_EXCEPTION); |
| 187 m_durationDisplay->setCurrentValue(duration); |
| 188 |
86 m_playButton->updateDisplayType(); | 189 m_playButton->updateDisplayType(); |
87 | 190 |
88 updateCurrentTimeDisplay(); | 191 updateCurrentTimeDisplay(); |
89 | 192 |
90 m_timeline->setDuration(m_mediaController->duration()); | 193 m_timeline->setDuration(m_mediaController->duration()); |
91 m_timeline->setPosition(m_mediaController->currentTime()); | 194 m_timeline->setPosition(m_mediaController->currentTime()); |
92 | 195 |
93 m_panelMuteButton->show(); | 196 m_panelMuteButton->show(); |
94 | 197 |
95 if (m_volumeSlider) { | 198 if (m_volumeSlider) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 void MediaControls::bufferingProgressed() | 247 void MediaControls::bufferingProgressed() |
145 { | 248 { |
146 // We only need to update buffering progress when paused, during normal | 249 // We only need to update buffering progress when paused, during normal |
147 // playback playbackProgressed() will take care of it. | 250 // playback playbackProgressed() will take care of it. |
148 if (m_mediaController->paused()) | 251 if (m_mediaController->paused()) |
149 m_timeline->setPosition(m_mediaController->currentTime()); | 252 m_timeline->setPosition(m_mediaController->currentTime()); |
150 } | 253 } |
151 | 254 |
152 void MediaControls::playbackStarted() | 255 void MediaControls::playbackStarted() |
153 { | 256 { |
| 257 m_currentTimeDisplay->show(); |
| 258 m_durationDisplay->hide(); |
| 259 |
154 m_playButton->updateDisplayType(); | 260 m_playButton->updateDisplayType(); |
155 m_timeline->setPosition(m_mediaController->currentTime()); | 261 m_timeline->setPosition(m_mediaController->currentTime()); |
156 updateCurrentTimeDisplay(); | 262 updateCurrentTimeDisplay(); |
157 | 263 |
158 if (m_isFullscreen) | 264 if (m_isFullscreen) |
159 startHideFullscreenControlsTimer(); | 265 startHideFullscreenControlsTimer(); |
160 } | 266 } |
161 | 267 |
162 void MediaControls::playbackProgressed() | 268 void MediaControls::playbackProgressed() |
163 { | 269 { |
164 m_timeline->setPosition(m_mediaController->currentTime()); | 270 m_timeline->setPosition(m_mediaController->currentTime()); |
165 updateCurrentTimeDisplay(); | 271 updateCurrentTimeDisplay(); |
166 | 272 |
167 if (!m_isMouseOverControls && m_mediaController->hasVideo()) | 273 if (!m_isMouseOverControls && m_mediaController->hasVideo()) |
168 makeTransparent(); | 274 makeTransparent(); |
169 } | 275 } |
170 | 276 |
171 void MediaControls::playbackStopped() | 277 void MediaControls::playbackStopped() |
172 { | 278 { |
173 m_playButton->updateDisplayType(); | 279 m_playButton->updateDisplayType(); |
174 m_timeline->setPosition(m_mediaController->currentTime()); | 280 m_timeline->setPosition(m_mediaController->currentTime()); |
175 updateCurrentTimeDisplay(); | 281 updateCurrentTimeDisplay(); |
176 makeOpaque(); | 282 makeOpaque(); |
177 | 283 |
178 stopHideFullscreenControlsTimer(); | 284 stopHideFullscreenControlsTimer(); |
179 } | 285 } |
180 | 286 |
| 287 void MediaControls::updateCurrentTimeDisplay() |
| 288 { |
| 289 double now = m_mediaController->currentTime(); |
| 290 double duration = m_mediaController->duration(); |
| 291 |
| 292 Page* page = document().page(); |
| 293 if (!page) |
| 294 return; |
| 295 |
| 296 // After seek, hide duration display and show current time. |
| 297 if (now > 0) { |
| 298 m_currentTimeDisplay->show(); |
| 299 m_durationDisplay->hide(); |
| 300 } |
| 301 |
| 302 // Allow the theme to format the time. |
| 303 m_currentTimeDisplay->setInnerText(RenderTheme::theme().formatMediaControlsC
urrentTime(now, duration), IGNORE_EXCEPTION); |
| 304 m_currentTimeDisplay->setCurrentValue(now); |
| 305 } |
| 306 |
181 void MediaControls::showVolumeSlider() | 307 void MediaControls::showVolumeSlider() |
182 { | 308 { |
183 if (!m_mediaController->hasAudio()) | 309 if (!m_mediaController->hasAudio()) |
184 return; | 310 return; |
185 | 311 |
186 m_volumeSlider->show(); | 312 m_volumeSlider->show(); |
187 } | 313 } |
188 | 314 |
189 void MediaControls::changedMute() | 315 void MediaControls::changedMute() |
190 { | 316 { |
191 m_panelMuteButton->changedMute(); | 317 m_panelMuteButton->changedMute(); |
| 318 |
| 319 if (m_mediaController->muted()) |
| 320 m_volumeSlider->setVolume(0); |
| 321 else |
| 322 m_volumeSlider->setVolume(m_mediaController->volume()); |
192 } | 323 } |
193 | 324 |
194 void MediaControls::changedVolume() | 325 void MediaControls::changedVolume() |
195 { | 326 { |
196 if (m_volumeSlider) | 327 if (m_volumeSlider) |
197 m_volumeSlider->setVolume(m_mediaController->volume()); | 328 m_volumeSlider->setVolume(m_mediaController->volume()); |
198 if (m_panelMuteButton && m_panelMuteButton->renderer()) | 329 if (m_panelMuteButton && m_panelMuteButton->renderer()) |
199 m_panelMuteButton->renderer()->repaint(); | 330 m_panelMuteButton->renderer()->repaint(); |
200 } | 331 } |
201 | 332 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 { | 453 { |
323 if (m_textDisplayContainer) | 454 if (m_textDisplayContainer) |
324 return; | 455 return; |
325 | 456 |
326 RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaCo
ntrolTextTrackContainerElement::create(document()); | 457 RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaCo
ntrolTextTrackContainerElement::create(document()); |
327 m_textDisplayContainer = textDisplayContainer.get(); | 458 m_textDisplayContainer = textDisplayContainer.get(); |
328 | 459 |
329 if (m_mediaController) | 460 if (m_mediaController) |
330 m_textDisplayContainer->setMediaController(m_mediaController); | 461 m_textDisplayContainer->setMediaController(m_mediaController); |
331 | 462 |
332 // Insert it before the first controller element so it always displays behin
d the controls. | 463 insertTextTrackContainer(textDisplayContainer.release()); |
333 insertBefore(textDisplayContainer.release(), m_panel, IGNORE_EXCEPTION); | |
334 } | 464 } |
335 | 465 |
336 void MediaControls::showTextTrackDisplay() | 466 void MediaControls::showTextTrackDisplay() |
337 { | 467 { |
338 if (!m_textDisplayContainer) | 468 if (!m_textDisplayContainer) |
339 createTextTrackDisplay(); | 469 createTextTrackDisplay(); |
340 m_textDisplayContainer->show(); | 470 m_textDisplayContainer->show(); |
341 } | 471 } |
342 | 472 |
343 void MediaControls::hideTextTrackDisplay() | 473 void MediaControls::hideTextTrackDisplay() |
344 { | 474 { |
345 if (!m_textDisplayContainer) | 475 if (!m_textDisplayContainer) |
346 createTextTrackDisplay(); | 476 createTextTrackDisplay(); |
347 m_textDisplayContainer->hide(); | 477 m_textDisplayContainer->hide(); |
348 } | 478 } |
349 | 479 |
350 void MediaControls::updateTextTrackDisplay() | 480 void MediaControls::updateTextTrackDisplay() |
351 { | 481 { |
352 if (!m_textDisplayContainer) | 482 if (!m_textDisplayContainer) |
353 createTextTrackDisplay(); | 483 createTextTrackDisplay(); |
354 | 484 |
355 m_textDisplayContainer->updateDisplay(); | 485 m_textDisplayContainer->updateDisplay(); |
356 } | 486 } |
357 | 487 |
| 488 void MediaControls::insertTextTrackContainer(PassRefPtr<MediaControlTextTrackCon
tainerElement> textTrackContainer) |
| 489 { |
| 490 // Insert it before the first controller element so it always displays behin
d the controls. |
| 491 insertBefore(textTrackContainer, m_enclosure); |
358 } | 492 } |
| 493 |
| 494 } |
OLD | NEW |