| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 , m_textDisplayContainer(nullptr) | 52 , m_textDisplayContainer(nullptr) |
| 53 , m_overlayPlayButton(nullptr) | 53 , m_overlayPlayButton(nullptr) |
| 54 , m_overlayEnclosure(nullptr) | 54 , m_overlayEnclosure(nullptr) |
| 55 , m_playButton(nullptr) | 55 , m_playButton(nullptr) |
| 56 , m_currentTimeDisplay(nullptr) | 56 , m_currentTimeDisplay(nullptr) |
| 57 , m_timeline(nullptr) | 57 , m_timeline(nullptr) |
| 58 , m_muteButton(nullptr) | 58 , m_muteButton(nullptr) |
| 59 , m_volumeSlider(nullptr) | 59 , m_volumeSlider(nullptr) |
| 60 , m_toggleClosedCaptionsButton(nullptr) | 60 , m_toggleClosedCaptionsButton(nullptr) |
| 61 , m_fullScreenButton(nullptr) | 61 , m_fullScreenButton(nullptr) |
| 62 , m_castButton(nullptr) |
| 63 , m_overlayCastButton(nullptr) |
| 62 , m_durationDisplay(nullptr) | 64 , m_durationDisplay(nullptr) |
| 63 , m_enclosure(nullptr) | 65 , m_enclosure(nullptr) |
| 64 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired
) | 66 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired
) |
| 65 , m_isMouseOverControls(false) | 67 , m_isMouseOverControls(false) |
| 66 , m_isPausedForScrubbing(false) | 68 , m_isPausedForScrubbing(false) |
| 67 { | 69 { |
| 68 } | 70 } |
| 69 | 71 |
| 70 PassRefPtrWillBeRawPtr<MediaControls> MediaControls::create(HTMLMediaElement& me
diaElement) | 72 PassRefPtrWillBeRawPtr<MediaControls> MediaControls::create(HTMLMediaElement& me
diaElement) |
| 71 { | 73 { |
| 72 RefPtrWillBeRawPtr<MediaControls> controls = adoptRefWillBeNoop(new MediaCon
trols(mediaElement)); | 74 RefPtrWillBeRawPtr<MediaControls> controls = adoptRefWillBeNoop(new MediaCon
trols(mediaElement)); |
| 73 | 75 |
| 74 if (controls->initializeControls()) | 76 if (controls->initializeControls()) |
| 75 return controls.release(); | 77 return controls.release(); |
| 76 | 78 |
| 77 return nullptr; | 79 return nullptr; |
| 78 } | 80 } |
| 79 | 81 |
| 80 bool MediaControls::initializeControls() | 82 bool MediaControls::initializeControls() |
| 81 { | 83 { |
| 82 TrackExceptionState exceptionState; | 84 TrackExceptionState exceptionState; |
| 83 | 85 |
| 86 RefPtrWillBeRawPtr<MediaControlOverlayEnclosureElement> overlayEnclosure = M
ediaControlOverlayEnclosureElement::create(*this); |
| 87 |
| 84 if (document().settings() && document().settings()->mediaControlsOverlayPlay
ButtonEnabled()) { | 88 if (document().settings() && document().settings()->mediaControlsOverlayPlay
ButtonEnabled()) { |
| 85 RefPtrWillBeRawPtr<MediaControlOverlayEnclosureElement> overlayEnclosure
= MediaControlOverlayEnclosureElement::create(*this); | |
| 86 RefPtrWillBeRawPtr<MediaControlOverlayPlayButtonElement> overlayPlayButt
on = MediaControlOverlayPlayButtonElement::create(*this); | 89 RefPtrWillBeRawPtr<MediaControlOverlayPlayButtonElement> overlayPlayButt
on = MediaControlOverlayPlayButtonElement::create(*this); |
| 87 m_overlayPlayButton = overlayPlayButton.get(); | 90 m_overlayPlayButton = overlayPlayButton.get(); |
| 88 overlayEnclosure->appendChild(overlayPlayButton.release(), exceptionStat
e); | 91 overlayEnclosure->appendChild(overlayPlayButton.release(), exceptionStat
e); |
| 89 if (exceptionState.hadException()) | 92 if (exceptionState.hadException()) |
| 90 return false; | 93 return false; |
| 94 } |
| 91 | 95 |
| 92 m_overlayEnclosure = overlayEnclosure.get(); | 96 RefPtrWillBeRawPtr<MediaControlCastButtonElement> overlayCastButton = MediaC
ontrolCastButtonElement::create(*this, true); |
| 93 appendChild(overlayEnclosure.release(), exceptionState); | 97 m_overlayCastButton = overlayCastButton.get(); |
| 94 if (exceptionState.hadException()) | 98 overlayEnclosure->appendChild(overlayCastButton.release(), exceptionState); |
| 95 return false; | 99 if (exceptionState.hadException()) |
| 96 } | 100 return false; |
| 101 |
| 102 m_overlayEnclosure = overlayEnclosure.get(); |
| 103 appendChild(overlayEnclosure.release(), exceptionState); |
| 104 if (exceptionState.hadException()) |
| 105 return false; |
| 97 | 106 |
| 98 // Create an enclosing element for the panel so we can visually offset the c
ontrols correctly. | 107 // Create an enclosing element for the panel so we can visually offset the c
ontrols correctly. |
| 99 RefPtrWillBeRawPtr<MediaControlPanelEnclosureElement> enclosure = MediaContr
olPanelEnclosureElement::create(*this); | 108 RefPtrWillBeRawPtr<MediaControlPanelEnclosureElement> enclosure = MediaContr
olPanelEnclosureElement::create(*this); |
| 100 | 109 |
| 101 RefPtrWillBeRawPtr<MediaControlPanelElement> panel = MediaControlPanelElemen
t::create(*this); | 110 RefPtrWillBeRawPtr<MediaControlPanelElement> panel = MediaControlPanelElemen
t::create(*this); |
| 102 | 111 |
| 103 RefPtrWillBeRawPtr<MediaControlPlayButtonElement> playButton = MediaControlP
layButtonElement::create(*this); | 112 RefPtrWillBeRawPtr<MediaControlPlayButtonElement> playButton = MediaControlP
layButtonElement::create(*this); |
| 104 m_playButton = playButton.get(); | 113 m_playButton = playButton.get(); |
| 105 panel->appendChild(playButton.release(), exceptionState); | 114 panel->appendChild(playButton.release(), exceptionState); |
| 106 if (exceptionState.hadException()) | 115 if (exceptionState.hadException()) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 136 panel->appendChild(slider.release(), exceptionState); | 145 panel->appendChild(slider.release(), exceptionState); |
| 137 if (exceptionState.hadException()) | 146 if (exceptionState.hadException()) |
| 138 return false; | 147 return false; |
| 139 | 148 |
| 140 RefPtrWillBeRawPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClos
edCaptionsButton = MediaControlToggleClosedCaptionsButtonElement::create(*this); | 149 RefPtrWillBeRawPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClos
edCaptionsButton = MediaControlToggleClosedCaptionsButtonElement::create(*this); |
| 141 m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get(); | 150 m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get(); |
| 142 panel->appendChild(toggleClosedCaptionsButton.release(), exceptionState); | 151 panel->appendChild(toggleClosedCaptionsButton.release(), exceptionState); |
| 143 if (exceptionState.hadException()) | 152 if (exceptionState.hadException()) |
| 144 return false; | 153 return false; |
| 145 | 154 |
| 155 RefPtrWillBeRawPtr<MediaControlCastButtonElement> castButton = MediaControlC
astButtonElement::create(*this, false); |
| 156 m_castButton = castButton.get(); |
| 157 panel->appendChild(castButton.release(), exceptionState); |
| 158 if (exceptionState.hadException()) |
| 159 return false; |
| 160 |
| 146 RefPtrWillBeRawPtr<MediaControlFullscreenButtonElement> fullscreenButton = M
ediaControlFullscreenButtonElement::create(*this); | 161 RefPtrWillBeRawPtr<MediaControlFullscreenButtonElement> fullscreenButton = M
ediaControlFullscreenButtonElement::create(*this); |
| 147 m_fullScreenButton = fullscreenButton.get(); | 162 m_fullScreenButton = fullscreenButton.get(); |
| 148 panel->appendChild(fullscreenButton.release(), exceptionState); | 163 panel->appendChild(fullscreenButton.release(), exceptionState); |
| 149 if (exceptionState.hadException()) | 164 if (exceptionState.hadException()) |
| 150 return false; | 165 return false; |
| 151 | 166 |
| 152 m_panel = panel.get(); | 167 m_panel = panel.get(); |
| 153 enclosure->appendChild(panel.release(), exceptionState); | 168 enclosure->appendChild(panel.release(), exceptionState); |
| 154 if (exceptionState.hadException()) | 169 if (exceptionState.hadException()) |
| 155 return false; | 170 return false; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 181 m_volumeSlider->show(); | 196 m_volumeSlider->show(); |
| 182 updateVolume(); | 197 updateVolume(); |
| 183 | 198 |
| 184 refreshClosedCaptionsButtonVisibility(); | 199 refreshClosedCaptionsButtonVisibility(); |
| 185 | 200 |
| 186 if (mediaElement().hasVideo() && fullscreenIsSupported(document())) | 201 if (mediaElement().hasVideo() && fullscreenIsSupported(document())) |
| 187 m_fullScreenButton->show(); | 202 m_fullScreenButton->show(); |
| 188 else | 203 else |
| 189 m_fullScreenButton->hide(); | 204 m_fullScreenButton->hide(); |
| 190 | 205 |
| 206 refreshCastButtonVisibility(); |
| 191 makeOpaque(); | 207 makeOpaque(); |
| 192 } | 208 } |
| 193 | 209 |
| 194 void MediaControls::show() | 210 void MediaControls::show() |
| 195 { | 211 { |
| 196 makeOpaque(); | 212 makeOpaque(); |
| 197 m_panel->setIsDisplayed(true); | 213 m_panel->setIsDisplayed(true); |
| 198 m_panel->show(); | 214 m_panel->show(); |
| 199 if (m_overlayPlayButton) | 215 if (m_overlayPlayButton) |
| 200 m_overlayPlayButton->updateDisplayType(); | 216 m_overlayPlayButton->updateDisplayType(); |
| 201 } | 217 } |
| 202 | 218 |
| 203 void MediaControls::mediaElementFocused() | 219 void MediaControls::mediaElementFocused() |
| 204 { | 220 { |
| 205 show(); | 221 show(); |
| 206 stopHideMediaControlsTimer(); | 222 resetHideMediaControlsTimer(); |
| 207 } | 223 } |
| 208 | 224 |
| 209 void MediaControls::hide() | 225 void MediaControls::hide() |
| 210 { | 226 { |
| 211 m_panel->setIsDisplayed(false); | 227 m_panel->setIsDisplayed(false); |
| 212 m_panel->hide(); | 228 m_panel->hide(); |
| 213 if (m_overlayPlayButton) | 229 if (m_overlayPlayButton) |
| 214 m_overlayPlayButton->hide(); | 230 m_overlayPlayButton->hide(); |
| 215 } | 231 } |
| 216 | 232 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 m_toggleClosedCaptionsButton->show(); | 355 m_toggleClosedCaptionsButton->show(); |
| 340 else | 356 else |
| 341 m_toggleClosedCaptionsButton->hide(); | 357 m_toggleClosedCaptionsButton->hide(); |
| 342 } | 358 } |
| 343 | 359 |
| 344 void MediaControls::closedCaptionTracksChanged() | 360 void MediaControls::closedCaptionTracksChanged() |
| 345 { | 361 { |
| 346 refreshClosedCaptionsButtonVisibility(); | 362 refreshClosedCaptionsButtonVisibility(); |
| 347 } | 363 } |
| 348 | 364 |
| 365 void MediaControls::refreshCastButtonVisibility() |
| 366 { |
| 367 if (mediaElement().hasRemoteRoutes()) { |
| 368 if (!mediaElement().shouldShowControls() && !mediaElement().autoplay() &
& mediaElement().paused()) { |
| 369 showOverlayCastButton(); |
| 370 } else if (mediaElement().shouldShowControls()) { |
| 371 m_overlayCastButton->hide(); |
| 372 m_castButton->show(); |
| 373 } |
| 374 } else { |
| 375 m_castButton->hide(); |
| 376 m_overlayCastButton->hide(); |
| 377 } |
| 378 } |
| 379 |
| 380 void MediaControls::showOverlayCastButton() |
| 381 { |
| 382 m_overlayCastButton->show(); |
| 383 resetHideMediaControlsTimer(); |
| 384 } |
| 385 |
| 349 void MediaControls::enteredFullscreen() | 386 void MediaControls::enteredFullscreen() |
| 350 { | 387 { |
| 351 m_fullScreenButton->setIsFullscreen(true); | 388 m_fullScreenButton->setIsFullscreen(true); |
| 352 stopHideMediaControlsTimer(); | 389 stopHideMediaControlsTimer(); |
| 353 startHideMediaControlsTimer(); | 390 startHideMediaControlsTimer(); |
| 354 } | 391 } |
| 355 | 392 |
| 356 void MediaControls::exitedFullscreen() | 393 void MediaControls::exitedFullscreen() |
| 357 { | 394 { |
| 358 m_fullScreenButton->setIsFullscreen(false); | 395 m_fullScreenButton->setIsFullscreen(false); |
| 359 stopHideMediaControlsTimer(); | 396 stopHideMediaControlsTimer(); |
| 360 startHideMediaControlsTimer(); | 397 startHideMediaControlsTimer(); |
| 361 } | 398 } |
| 362 | 399 |
| 400 void MediaControls::startedCasting() |
| 401 { |
| 402 m_castButton->setIsPlayingRemotely(true); |
| 403 m_overlayCastButton->setIsPlayingRemotely(true); |
| 404 } |
| 405 |
| 406 void MediaControls::stoppedCasting() |
| 407 { |
| 408 m_castButton->setIsPlayingRemotely(false); |
| 409 m_overlayCastButton->setIsPlayingRemotely(false); |
| 410 } |
| 411 |
| 363 void MediaControls::defaultEventHandler(Event* event) | 412 void MediaControls::defaultEventHandler(Event* event) |
| 364 { | 413 { |
| 365 HTMLDivElement::defaultEventHandler(event); | 414 HTMLDivElement::defaultEventHandler(event); |
| 366 | 415 |
| 367 if (event->type() == EventTypeNames::mouseover) { | 416 if (event->type() == EventTypeNames::mouseover) { |
| 368 if (!containsRelatedTarget(event)) { | 417 if (!containsRelatedTarget(event)) { |
| 369 m_isMouseOverControls = true; | 418 m_isMouseOverControls = true; |
| 370 if (!mediaElement().togglePlayStateWillPlay()) { | 419 if (!mediaElement().togglePlayStateWillPlay()) { |
| 371 makeOpaque(); | 420 makeOpaque(); |
| 372 if (shouldHideMediaControls()) | 421 if (shouldHideMediaControls()) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 396 | 445 |
| 397 void MediaControls::hideMediaControlsTimerFired(Timer<MediaControls>*) | 446 void MediaControls::hideMediaControlsTimerFired(Timer<MediaControls>*) |
| 398 { | 447 { |
| 399 if (mediaElement().togglePlayStateWillPlay()) | 448 if (mediaElement().togglePlayStateWillPlay()) |
| 400 return; | 449 return; |
| 401 | 450 |
| 402 if (!shouldHideMediaControls(IgnoreFocus | IgnoreVideoHover)) | 451 if (!shouldHideMediaControls(IgnoreFocus | IgnoreVideoHover)) |
| 403 return; | 452 return; |
| 404 | 453 |
| 405 makeTransparent(); | 454 makeTransparent(); |
| 455 m_overlayCastButton->hide(); |
| 406 } | 456 } |
| 407 | 457 |
| 408 void MediaControls::startHideMediaControlsTimer() | 458 void MediaControls::startHideMediaControlsTimer() |
| 409 { | 459 { |
| 410 m_hideMediaControlsTimer.startOneShot(timeWithoutMouseMovementBeforeHidingMe
diaControls, FROM_HERE); | 460 m_hideMediaControlsTimer.startOneShot(timeWithoutMouseMovementBeforeHidingMe
diaControls, FROM_HERE); |
| 411 } | 461 } |
| 412 | 462 |
| 413 void MediaControls::stopHideMediaControlsTimer() | 463 void MediaControls::stopHideMediaControlsTimer() |
| 414 { | 464 { |
| 415 m_hideMediaControlsTimer.stop(); | 465 m_hideMediaControlsTimer.stop(); |
| 416 } | 466 } |
| 417 | 467 |
| 468 void MediaControls::resetHideMediaControlsTimer() |
| 469 { |
| 470 stopHideMediaControlsTimer(); |
| 471 if (!mediaElement().paused()) |
| 472 startHideMediaControlsTimer(); |
| 473 } |
| 474 |
| 475 |
| 418 const AtomicString& MediaControls::shadowPseudoId() const | 476 const AtomicString& MediaControls::shadowPseudoId() const |
| 419 { | 477 { |
| 420 DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls")); | 478 DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls")); |
| 421 return id; | 479 return id; |
| 422 } | 480 } |
| 423 | 481 |
| 424 bool MediaControls::containsRelatedTarget(Event* event) | 482 bool MediaControls::containsRelatedTarget(Event* event) |
| 425 { | 483 { |
| 426 if (!event->isMouseEvent()) | 484 if (!event->isMouseEvent()) |
| 427 return false; | 485 return false; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 visitor->trace(m_muteButton); | 539 visitor->trace(m_muteButton); |
| 482 visitor->trace(m_volumeSlider); | 540 visitor->trace(m_volumeSlider); |
| 483 visitor->trace(m_toggleClosedCaptionsButton); | 541 visitor->trace(m_toggleClosedCaptionsButton); |
| 484 visitor->trace(m_fullScreenButton); | 542 visitor->trace(m_fullScreenButton); |
| 485 visitor->trace(m_durationDisplay); | 543 visitor->trace(m_durationDisplay); |
| 486 visitor->trace(m_enclosure); | 544 visitor->trace(m_enclosure); |
| 487 HTMLDivElement::trace(visitor); | 545 HTMLDivElement::trace(visitor); |
| 488 } | 546 } |
| 489 | 547 |
| 490 } | 548 } |
| OLD | NEW |