Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: Source/core/html/shadow/MediaControls.cpp

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

Powered by Google App Engine
This is Rietveld 408576698