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

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

Issue 192453005: Merge MediaControlsAndroid into MediaControls (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: revert simplification Created 6 years, 9 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
« no previous file with comments | « Source/core/html/shadow/MediaControls.h ('k') | Source/core/html/shadow/MediaControlsAndroid.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if OS(ANDROID) 31 #include "core/events/MouseEvent.h"
32 #include "core/html/shadow/MediaControlsAndroid.h" 32 #include "core/rendering/RenderTheme.h"
33 #endif
34 33
35 namespace WebCore { 34 namespace WebCore {
36 35
36 #if OS(ANDROID)
37 static const bool alwaysHideFullscreenControls = true;
38 static const bool needOverlayPlayButton = true;
39 #else
40 static const bool alwaysHideFullscreenControls = false;
41 static const bool needOverlayPlayButton = false;
42 #endif
43
37 static const double timeWithoutMouseMovementBeforeHidingFullscreenControls = 3; 44 static const double timeWithoutMouseMovementBeforeHidingFullscreenControls = 3;
38 45
39 MediaControls::MediaControls(Document& document) 46 MediaControls::MediaControls(Document& document)
40 : HTMLDivElement(document) 47 : HTMLDivElement(document)
41 , m_mediaController(0) 48 , m_mediaController(0)
42 , m_panel(0) 49 , m_panel(0)
43 , m_textDisplayContainer(0) 50 , m_textDisplayContainer(0)
51 , m_overlayPlayButton(0)
52 , m_overlayEnclosure(0)
44 , m_playButton(0) 53 , m_playButton(0)
45 , m_currentTimeDisplay(0) 54 , m_currentTimeDisplay(0)
46 , m_timeline(0) 55 , m_timeline(0)
47 , m_muteButton(0) 56 , m_muteButton(0)
48 , m_volumeSlider(0) 57 , m_volumeSlider(0)
49 , m_toggleClosedCaptionsButton(0) 58 , m_toggleClosedCaptionsButton(0)
50 , m_fullScreenButton(0) 59 , m_fullScreenButton(0)
51 , m_durationDisplay(0) 60 , m_durationDisplay(0)
52 , m_enclosure(0) 61 , m_enclosure(0)
53 , m_hideFullscreenControlsTimer(this, &MediaControls::hideFullscreenControls TimerFired) 62 , m_hideFullscreenControlsTimer(this, &MediaControls::hideFullscreenControls TimerFired)
54 , m_isFullscreen(false) 63 , m_isFullscreen(false)
55 , m_isMouseOverControls(false) 64 , m_isMouseOverControls(false)
56 { 65 {
57 } 66 }
58 67
59 PassRefPtr<MediaControls> MediaControls::create(Document& document) 68 PassRefPtr<MediaControls> MediaControls::create(Document& document)
60 { 69 {
61 RefPtr<MediaControls> controls; 70 RefPtr<MediaControls> controls = adoptRef(new MediaControls(document));
62 #if OS(ANDROID)
63 controls = adoptRef(new MediaControlsAndroid(document));
64 #else
65 controls = adoptRef(new MediaControls(document));
66 #endif
67 71
68 if (controls->initializeControls(document)) 72 if (controls->initializeControls(document))
69 return controls.release(); 73 return controls.release();
70 74
71 return nullptr; 75 return nullptr;
72 } 76 }
73 77
74 bool MediaControls::initializeControls(Document& document) 78 bool MediaControls::initializeControls(Document& document)
75 { 79 {
80 TrackExceptionState exceptionState;
81
82 if (needOverlayPlayButton) {
83 RefPtr<MediaControlOverlayEnclosureElement> overlayEnclosure = MediaCont rolOverlayEnclosureElement::create(document);
84 RefPtr<MediaControlOverlayPlayButtonElement> overlayPlayButton = MediaCo ntrolOverlayPlayButtonElement::create(document);
85 m_overlayPlayButton = overlayPlayButton.get();
86 overlayEnclosure->appendChild(overlayPlayButton.release(), exceptionStat e);
87 if (exceptionState.hadException())
88 return false;
89
90 m_overlayEnclosure = overlayEnclosure.get();
91 appendChild(overlayEnclosure.release(), exceptionState);
92 if (exceptionState.hadException())
93 return false;
94 }
95
76 // Create an enclosing element for the panel so we can visually offset the c ontrols correctly. 96 // Create an enclosing element for the panel so we can visually offset the c ontrols correctly.
77 RefPtr<MediaControlPanelEnclosureElement> enclosure = MediaControlPanelEnclo sureElement::create(document); 97 RefPtr<MediaControlPanelEnclosureElement> enclosure = MediaControlPanelEnclo sureElement::create(document);
78 98
79 RefPtr<MediaControlPanelElement> panel = MediaControlPanelElement::create(do cument); 99 RefPtr<MediaControlPanelElement> panel = MediaControlPanelElement::create(do cument);
80 100
81 TrackExceptionState exceptionState;
82
83 RefPtr<MediaControlPlayButtonElement> playButton = MediaControlPlayButtonEle ment::create(document); 101 RefPtr<MediaControlPlayButtonElement> playButton = MediaControlPlayButtonEle ment::create(document);
84 m_playButton = playButton.get(); 102 m_playButton = playButton.get();
85 panel->appendChild(playButton.release(), exceptionState); 103 panel->appendChild(playButton.release(), exceptionState);
86 if (exceptionState.hadException()) 104 if (exceptionState.hadException())
87 return false; 105 return false;
88 106
89 RefPtr<MediaControlTimelineElement> timeline = MediaControlTimelineElement:: create(document, this); 107 RefPtr<MediaControlTimelineElement> timeline = MediaControlTimelineElement:: create(document, this);
90 m_timeline = timeline.get(); 108 m_timeline = timeline.get();
91 panel->appendChild(timeline.release(), exceptionState); 109 panel->appendChild(timeline.release(), exceptionState);
92 if (exceptionState.hadException()) 110 if (exceptionState.hadException())
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 162
145 void MediaControls::setMediaController(MediaControllerInterface* controller) 163 void MediaControls::setMediaController(MediaControllerInterface* controller)
146 { 164 {
147 if (m_mediaController == controller) 165 if (m_mediaController == controller)
148 return; 166 return;
149 m_mediaController = controller; 167 m_mediaController = controller;
150 168
151 m_panel->setMediaController(controller); 169 m_panel->setMediaController(controller);
152 if (m_textDisplayContainer) 170 if (m_textDisplayContainer)
153 m_textDisplayContainer->setMediaController(controller); 171 m_textDisplayContainer->setMediaController(controller);
172 if (m_overlayPlayButton)
173 m_overlayPlayButton->setMediaController(controller);
174 if (m_overlayEnclosure)
175 m_overlayEnclosure->setMediaController(controller);
154 m_playButton->setMediaController(controller); 176 m_playButton->setMediaController(controller);
155 m_currentTimeDisplay->setMediaController(controller); 177 m_currentTimeDisplay->setMediaController(controller);
156 m_timeline->setMediaController(controller); 178 m_timeline->setMediaController(controller);
157 m_muteButton->setMediaController(controller); 179 m_muteButton->setMediaController(controller);
158 m_volumeSlider->setMediaController(controller); 180 m_volumeSlider->setMediaController(controller);
159 m_toggleClosedCaptionsButton->setMediaController(controller); 181 m_toggleClosedCaptionsButton->setMediaController(controller);
160 m_fullScreenButton->setMediaController(controller); 182 m_fullScreenButton->setMediaController(controller);
161 m_durationDisplay->setMediaController(controller); 183 m_durationDisplay->setMediaController(controller);
162 m_enclosure->setMediaController(controller); 184 m_enclosure->setMediaController(controller);
163 } 185 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 void MediaControls::makeOpaque() 230 void MediaControls::makeOpaque()
209 { 231 {
210 m_panel->makeOpaque(); 232 m_panel->makeOpaque();
211 } 233 }
212 234
213 void MediaControls::makeTransparent() 235 void MediaControls::makeTransparent()
214 { 236 {
215 m_panel->makeTransparent(); 237 m_panel->makeTransparent();
216 } 238 }
217 239
218 bool MediaControls::shouldHideControls() 240 bool MediaControls::shouldHideFullscreenControls()
219 { 241 {
220 return !m_panel->hovered(); 242 return alwaysHideFullscreenControls || !m_panel->hovered();
221 } 243 }
222 244
223 void MediaControls::playbackStarted() 245 void MediaControls::playbackStarted()
224 { 246 {
225 m_currentTimeDisplay->show(); 247 m_currentTimeDisplay->show();
226 m_durationDisplay->hide(); 248 m_durationDisplay->hide();
227 249
250 if (m_overlayPlayButton)
251 m_overlayPlayButton->updateDisplayType();
228 m_playButton->updateDisplayType(); 252 m_playButton->updateDisplayType();
229 m_timeline->setPosition(m_mediaController->currentTime()); 253 m_timeline->setPosition(m_mediaController->currentTime());
230 updateCurrentTimeDisplay(); 254 updateCurrentTimeDisplay();
231 255
232 if (m_isFullscreen) 256 if (m_isFullscreen)
233 startHideFullscreenControlsTimer(); 257 startHideFullscreenControlsTimer();
234 } 258 }
235 259
236 void MediaControls::playbackProgressed() 260 void MediaControls::playbackProgressed()
237 { 261 {
238 m_timeline->setPosition(m_mediaController->currentTime()); 262 m_timeline->setPosition(m_mediaController->currentTime());
239 updateCurrentTimeDisplay(); 263 updateCurrentTimeDisplay();
240 264
241 if (!m_isMouseOverControls && m_mediaController->hasVideo()) 265 if (!m_isMouseOverControls && m_mediaController->hasVideo())
242 makeTransparent(); 266 makeTransparent();
243 } 267 }
244 268
245 void MediaControls::playbackStopped() 269 void MediaControls::playbackStopped()
246 { 270 {
271 if (m_overlayPlayButton)
272 m_overlayPlayButton->updateDisplayType();
247 m_playButton->updateDisplayType(); 273 m_playButton->updateDisplayType();
248 m_timeline->setPosition(m_mediaController->currentTime()); 274 m_timeline->setPosition(m_mediaController->currentTime());
249 updateCurrentTimeDisplay(); 275 updateCurrentTimeDisplay();
250 makeOpaque(); 276 makeOpaque();
251 277
252 stopHideFullscreenControlsTimer(); 278 stopHideFullscreenControlsTimer();
253 } 279 }
254 280
255 void MediaControls::updateCurrentTimeDisplay() 281 void MediaControls::updateCurrentTimeDisplay()
256 { 282 {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 345
320 void MediaControls::defaultEventHandler(Event* event) 346 void MediaControls::defaultEventHandler(Event* event)
321 { 347 {
322 HTMLDivElement::defaultEventHandler(event); 348 HTMLDivElement::defaultEventHandler(event);
323 349
324 if (event->type() == EventTypeNames::mouseover) { 350 if (event->type() == EventTypeNames::mouseover) {
325 if (!containsRelatedTarget(event)) { 351 if (!containsRelatedTarget(event)) {
326 m_isMouseOverControls = true; 352 m_isMouseOverControls = true;
327 if (!m_mediaController->canPlay()) { 353 if (!m_mediaController->canPlay()) {
328 makeOpaque(); 354 makeOpaque();
329 if (shouldHideControls()) 355 if (shouldHideFullscreenControls())
330 startHideFullscreenControlsTimer(); 356 startHideFullscreenControlsTimer();
331 } 357 }
332 } 358 }
333 return; 359 return;
334 } 360 }
335 361
336 if (event->type() == EventTypeNames::mouseout) { 362 if (event->type() == EventTypeNames::mouseout) {
337 if (!containsRelatedTarget(event)) { 363 if (!containsRelatedTarget(event)) {
338 m_isMouseOverControls = false; 364 m_isMouseOverControls = false;
339 stopHideFullscreenControlsTimer(); 365 stopHideFullscreenControlsTimer();
340 } 366 }
341 return; 367 return;
342 } 368 }
343 369
344 if (event->type() == EventTypeNames::mousemove) { 370 if (event->type() == EventTypeNames::mousemove) {
345 if (m_isFullscreen) { 371 if (m_isFullscreen) {
346 // When we get a mouse move in fullscreen mode, show the media contr ols, and start a timer 372 // When we get a mouse move in fullscreen mode, show the media contr ols, and start a timer
347 // that will hide the media controls after a 3 seconds without a mou se move. 373 // that will hide the media controls after a 3 seconds without a mou se move.
348 makeOpaque(); 374 makeOpaque();
349 if (shouldHideControls()) 375 if (shouldHideFullscreenControls())
350 startHideFullscreenControlsTimer(); 376 startHideFullscreenControlsTimer();
351 } 377 }
352 return; 378 return;
353 } 379 }
354 } 380 }
355 381
356 void MediaControls::hideFullscreenControlsTimerFired(Timer<MediaControls>*) 382 void MediaControls::hideFullscreenControlsTimerFired(Timer<MediaControls>*)
357 { 383 {
358 if (m_mediaController->paused()) 384 if (m_mediaController->paused())
359 return; 385 return;
360 386
361 if (!m_isFullscreen) 387 if (!m_isFullscreen)
362 return; 388 return;
363 389
364 if (!shouldHideControls()) 390 if (!shouldHideFullscreenControls())
365 return; 391 return;
366 392
367 makeTransparent(); 393 makeTransparent();
368 } 394 }
369 395
370 void MediaControls::startHideFullscreenControlsTimer() 396 void MediaControls::startHideFullscreenControlsTimer()
371 { 397 {
372 if (!m_isFullscreen) 398 if (!m_isFullscreen)
373 return; 399 return;
374 400
(...skipping 24 matching lines...) Expand all
399 void MediaControls::createTextTrackDisplay() 425 void MediaControls::createTextTrackDisplay()
400 { 426 {
401 if (m_textDisplayContainer) 427 if (m_textDisplayContainer)
402 return; 428 return;
403 429
404 RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaCo ntrolTextTrackContainerElement::create(document()); 430 RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaCo ntrolTextTrackContainerElement::create(document());
405 m_textDisplayContainer = textDisplayContainer.get(); 431 m_textDisplayContainer = textDisplayContainer.get();
406 432
407 m_textDisplayContainer->setMediaController(m_mediaController); 433 m_textDisplayContainer->setMediaController(m_mediaController);
408 434
409 insertTextTrackContainer(textDisplayContainer.release()); 435 // Insert it before (behind) all other control elements.
436 if (m_overlayEnclosure && m_overlayPlayButton)
437 m_overlayEnclosure->insertBefore(textDisplayContainer.release(), m_overl ayPlayButton);
438 else
439 insertBefore(textDisplayContainer.release(), m_enclosure);
410 } 440 }
411 441
412 void MediaControls::showTextTrackDisplay() 442 void MediaControls::showTextTrackDisplay()
413 { 443 {
414 if (!m_textDisplayContainer) 444 if (!m_textDisplayContainer)
415 createTextTrackDisplay(); 445 createTextTrackDisplay();
416 m_textDisplayContainer->show(); 446 m_textDisplayContainer->show();
417 } 447 }
418 448
419 void MediaControls::hideTextTrackDisplay() 449 void MediaControls::hideTextTrackDisplay()
420 { 450 {
421 if (!m_textDisplayContainer) 451 if (!m_textDisplayContainer)
422 createTextTrackDisplay(); 452 createTextTrackDisplay();
423 m_textDisplayContainer->hide(); 453 m_textDisplayContainer->hide();
424 } 454 }
425 455
426 void MediaControls::updateTextTrackDisplay() 456 void MediaControls::updateTextTrackDisplay()
427 { 457 {
428 if (!m_textDisplayContainer) 458 if (!m_textDisplayContainer)
429 createTextTrackDisplay(); 459 createTextTrackDisplay();
430 460
431 m_textDisplayContainer->updateDisplay(); 461 m_textDisplayContainer->updateDisplay();
432 } 462 }
433 463
434 void MediaControls::insertTextTrackContainer(PassRefPtr<MediaControlTextTrackCon tainerElement> textTrackContainer)
435 {
436 // Insert it before the first controller element so it always displays behin d the controls.
437 insertBefore(textTrackContainer, m_enclosure);
438 } 464 }
439
440 }
OLDNEW
« no previous file with comments | « Source/core/html/shadow/MediaControls.h ('k') | Source/core/html/shadow/MediaControlsAndroid.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698