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) |
51 { | 53 { |
52 } | 54 } |
53 | 55 |
| 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 |
54 void MediaControls::setMediaController(MediaControllerInterface* controller) | 144 void MediaControls::setMediaController(MediaControllerInterface* controller) |
55 { | 145 { |
56 if (m_mediaController == controller) | 146 if (m_mediaController == controller) |
57 return; | 147 return; |
58 m_mediaController = controller; | 148 m_mediaController = controller; |
59 | 149 |
60 if (m_panel) | 150 if (m_panel) |
61 m_panel->setMediaController(controller); | 151 m_panel->setMediaController(controller); |
62 if (m_textDisplayContainer) | 152 if (m_textDisplayContainer) |
63 m_textDisplayContainer->setMediaController(controller); | 153 m_textDisplayContainer->setMediaController(controller); |
64 if (m_playButton) | 154 if (m_playButton) |
65 m_playButton->setMediaController(controller); | 155 m_playButton->setMediaController(controller); |
66 if (m_currentTimeDisplay) | 156 if (m_currentTimeDisplay) |
67 m_currentTimeDisplay->setMediaController(controller); | 157 m_currentTimeDisplay->setMediaController(controller); |
68 if (m_timeline) | 158 if (m_timeline) |
69 m_timeline->setMediaController(controller); | 159 m_timeline->setMediaController(controller); |
70 if (m_panelMuteButton) | 160 if (m_panelMuteButton) |
71 m_panelMuteButton->setMediaController(controller); | 161 m_panelMuteButton->setMediaController(controller); |
72 if (m_volumeSlider) | 162 if (m_volumeSlider) |
73 m_volumeSlider->setMediaController(controller); | 163 m_volumeSlider->setMediaController(controller); |
74 if (m_toggleClosedCaptionsButton) | 164 if (m_toggleClosedCaptionsButton) |
75 m_toggleClosedCaptionsButton->setMediaController(controller); | 165 m_toggleClosedCaptionsButton->setMediaController(controller); |
76 if (m_fullScreenButton) | 166 if (m_fullScreenButton) |
77 m_fullScreenButton->setMediaController(controller); | 167 m_fullScreenButton->setMediaController(controller); |
| 168 if (m_durationDisplay) |
| 169 m_durationDisplay->setMediaController(controller); |
| 170 if (m_enclosure) |
| 171 m_enclosure->setMediaController(controller); |
78 } | 172 } |
79 | 173 |
80 void MediaControls::reset() | 174 void MediaControls::reset() |
81 { | 175 { |
82 Page* page = document().page(); | 176 Page* page = document().page(); |
83 if (!page) | 177 if (!page) |
84 return; | 178 return; |
85 | 179 |
| 180 double duration = m_mediaController->duration(); |
| 181 m_durationDisplay->setInnerText(RenderTheme::theme().formatMediaControlsTime
(duration), ASSERT_NO_EXCEPTION); |
| 182 m_durationDisplay->setCurrentValue(duration); |
| 183 |
86 m_playButton->updateDisplayType(); | 184 m_playButton->updateDisplayType(); |
87 | 185 |
88 updateCurrentTimeDisplay(); | 186 updateCurrentTimeDisplay(); |
89 | 187 |
90 m_timeline->setDuration(m_mediaController->duration()); | 188 m_timeline->setDuration(m_mediaController->duration()); |
91 m_timeline->setPosition(m_mediaController->currentTime()); | 189 m_timeline->setPosition(m_mediaController->currentTime()); |
92 | 190 |
93 m_panelMuteButton->show(); | 191 m_panelMuteButton->show(); |
94 | 192 |
95 if (m_volumeSlider) { | 193 if (m_volumeSlider) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 void MediaControls::bufferingProgressed() | 242 void MediaControls::bufferingProgressed() |
145 { | 243 { |
146 // We only need to update buffering progress when paused, during normal | 244 // We only need to update buffering progress when paused, during normal |
147 // playback playbackProgressed() will take care of it. | 245 // playback playbackProgressed() will take care of it. |
148 if (m_mediaController->paused()) | 246 if (m_mediaController->paused()) |
149 m_timeline->setPosition(m_mediaController->currentTime()); | 247 m_timeline->setPosition(m_mediaController->currentTime()); |
150 } | 248 } |
151 | 249 |
152 void MediaControls::playbackStarted() | 250 void MediaControls::playbackStarted() |
153 { | 251 { |
| 252 m_currentTimeDisplay->show(); |
| 253 m_durationDisplay->hide(); |
| 254 |
154 m_playButton->updateDisplayType(); | 255 m_playButton->updateDisplayType(); |
155 m_timeline->setPosition(m_mediaController->currentTime()); | 256 m_timeline->setPosition(m_mediaController->currentTime()); |
156 updateCurrentTimeDisplay(); | 257 updateCurrentTimeDisplay(); |
157 | 258 |
158 if (m_isFullscreen) | 259 if (m_isFullscreen) |
159 startHideFullscreenControlsTimer(); | 260 startHideFullscreenControlsTimer(); |
160 } | 261 } |
161 | 262 |
162 void MediaControls::playbackProgressed() | 263 void MediaControls::playbackProgressed() |
163 { | 264 { |
164 m_timeline->setPosition(m_mediaController->currentTime()); | 265 m_timeline->setPosition(m_mediaController->currentTime()); |
165 updateCurrentTimeDisplay(); | 266 updateCurrentTimeDisplay(); |
166 | 267 |
167 if (!m_isMouseOverControls && m_mediaController->hasVideo()) | 268 if (!m_isMouseOverControls && m_mediaController->hasVideo()) |
168 makeTransparent(); | 269 makeTransparent(); |
169 } | 270 } |
170 | 271 |
171 void MediaControls::playbackStopped() | 272 void MediaControls::playbackStopped() |
172 { | 273 { |
173 m_playButton->updateDisplayType(); | 274 m_playButton->updateDisplayType(); |
174 m_timeline->setPosition(m_mediaController->currentTime()); | 275 m_timeline->setPosition(m_mediaController->currentTime()); |
175 updateCurrentTimeDisplay(); | 276 updateCurrentTimeDisplay(); |
176 makeOpaque(); | 277 makeOpaque(); |
177 | 278 |
178 stopHideFullscreenControlsTimer(); | 279 stopHideFullscreenControlsTimer(); |
179 } | 280 } |
180 | 281 |
| 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 |
181 void MediaControls::showVolumeSlider() | 302 void MediaControls::showVolumeSlider() |
182 { | 303 { |
183 if (!m_mediaController->hasAudio()) | 304 if (!m_mediaController->hasAudio()) |
184 return; | 305 return; |
185 | 306 |
186 m_volumeSlider->show(); | 307 m_volumeSlider->show(); |
187 } | 308 } |
188 | 309 |
189 void MediaControls::changedMute() | 310 void MediaControls::changedMute() |
190 { | 311 { |
191 m_panelMuteButton->changedMute(); | 312 m_panelMuteButton->changedMute(); |
| 313 |
| 314 if (m_mediaController->muted()) |
| 315 m_volumeSlider->setVolume(0); |
| 316 else |
| 317 m_volumeSlider->setVolume(m_mediaController->volume()); |
192 } | 318 } |
193 | 319 |
194 void MediaControls::changedVolume() | 320 void MediaControls::changedVolume() |
195 { | 321 { |
196 if (m_volumeSlider) | 322 if (m_volumeSlider) |
197 m_volumeSlider->setVolume(m_mediaController->volume()); | 323 m_volumeSlider->setVolume(m_mediaController->volume()); |
198 if (m_panelMuteButton && m_panelMuteButton->renderer()) | 324 if (m_panelMuteButton && m_panelMuteButton->renderer()) |
199 m_panelMuteButton->renderer()->repaint(); | 325 m_panelMuteButton->renderer()->repaint(); |
200 } | 326 } |
201 | 327 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 { | 448 { |
323 if (m_textDisplayContainer) | 449 if (m_textDisplayContainer) |
324 return; | 450 return; |
325 | 451 |
326 RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaCo
ntrolTextTrackContainerElement::create(document()); | 452 RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaCo
ntrolTextTrackContainerElement::create(document()); |
327 m_textDisplayContainer = textDisplayContainer.get(); | 453 m_textDisplayContainer = textDisplayContainer.get(); |
328 | 454 |
329 if (m_mediaController) | 455 if (m_mediaController) |
330 m_textDisplayContainer->setMediaController(m_mediaController); | 456 m_textDisplayContainer->setMediaController(m_mediaController); |
331 | 457 |
332 // Insert it before the first controller element so it always displays behin
d the controls. | 458 insertTextTrackContainer(textDisplayContainer.release()); |
333 insertBefore(textDisplayContainer.release(), m_panel, IGNORE_EXCEPTION); | |
334 } | 459 } |
335 | 460 |
336 void MediaControls::showTextTrackDisplay() | 461 void MediaControls::showTextTrackDisplay() |
337 { | 462 { |
338 if (!m_textDisplayContainer) | 463 if (!m_textDisplayContainer) |
339 createTextTrackDisplay(); | 464 createTextTrackDisplay(); |
340 m_textDisplayContainer->show(); | 465 m_textDisplayContainer->show(); |
341 } | 466 } |
342 | 467 |
343 void MediaControls::hideTextTrackDisplay() | 468 void MediaControls::hideTextTrackDisplay() |
344 { | 469 { |
345 if (!m_textDisplayContainer) | 470 if (!m_textDisplayContainer) |
346 createTextTrackDisplay(); | 471 createTextTrackDisplay(); |
347 m_textDisplayContainer->hide(); | 472 m_textDisplayContainer->hide(); |
348 } | 473 } |
349 | 474 |
350 void MediaControls::updateTextTrackDisplay() | 475 void MediaControls::updateTextTrackDisplay() |
351 { | 476 { |
352 if (!m_textDisplayContainer) | 477 if (!m_textDisplayContainer) |
353 createTextTrackDisplay(); | 478 createTextTrackDisplay(); |
354 | 479 |
355 m_textDisplayContainer->updateDisplay(); | 480 m_textDisplayContainer->updateDisplay(); |
356 } | 481 } |
357 | 482 |
| 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); |
358 } | 487 } |
| 488 |
| 489 } |
OLD | NEW |