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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 this, | 125 this, |
126 WTF::bind(&MediaControls::hideAllMenus, wrapWeakPersistent(this)))), | 126 WTF::bind(&MediaControls::hideAllMenus, wrapWeakPersistent(this)))), |
127 m_hideMediaControlsTimer(this, | 127 m_hideMediaControlsTimer(this, |
128 &MediaControls::hideMediaControlsTimerFired), | 128 &MediaControls::hideMediaControlsTimerFired), |
129 m_hideTimerBehaviorFlags(IgnoreNone), | 129 m_hideTimerBehaviorFlags(IgnoreNone), |
130 m_isMouseOverControls(false), | 130 m_isMouseOverControls(false), |
131 m_isPausedForScrubbing(false), | 131 m_isPausedForScrubbing(false), |
132 m_panelWidthChangedTimer(this, | 132 m_panelWidthChangedTimer(this, |
133 &MediaControls::panelWidthChangedTimerFired), | 133 &MediaControls::panelWidthChangedTimerFired), |
134 m_panelWidth(0), | 134 m_panelWidth(0), |
135 m_allowHiddenVolumeControls( | |
136 RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()), | |
137 m_keepShowingUntilTimerFires(false) {} | 135 m_keepShowingUntilTimerFires(false) {} |
138 | 136 |
139 MediaControls* MediaControls::create(HTMLMediaElement& mediaElement) { | 137 MediaControls* MediaControls::create(HTMLMediaElement& mediaElement) { |
140 MediaControls* controls = new MediaControls(mediaElement); | 138 MediaControls* controls = new MediaControls(mediaElement); |
141 controls->setShadowPseudoId(AtomicString("-webkit-media-controls")); | 139 controls->setShadowPseudoId(AtomicString("-webkit-media-controls")); |
142 controls->initializeControls(); | 140 controls->initializeControls(); |
143 return controls; | 141 return controls; |
144 } | 142 } |
145 | 143 |
146 // The media controls DOM structure looks like: | 144 // The media controls DOM structure looks like: |
147 // | 145 // |
148 // MediaControls | 146 // MediaControls |
149 // (-webkit-media-controls) | 147 // (-webkit-media-controls) |
150 // +-MediaControlOverlayEnclosureElement | 148 // +-MediaControlOverlayEnclosureElement |
151 // | (-webkit-media-controls-overlay-enclosure) | 149 // | (-webkit-media-controls-overlay-enclosure) |
152 // | +-MediaControlOverlayPlayButtonElement | 150 // | +-MediaControlOverlayPlayButtonElement |
153 // | | (-webkit-media-controls-overlay-play-button) | 151 // | | (-webkit-media-controls-overlay-play-button) |
154 // | | {if mediaControlsOverlayPlayButtonEnabled} | 152 // | | {if mediaControlsOverlayPlayButtonEnabled} |
155 // | \-MediaControlCastButtonElement | 153 // | \-MediaControlCastButtonElement |
156 // | (-internal-media-controls-overlay-cast-button) | 154 // | (-internal-media-controls-overlay-cast-button) |
157 // \-MediaControlPanelEnclosureElement | 155 // \-MediaControlPanelEnclosureElement |
158 // | (-webkit-media-controls-enclosure) | 156 // | (-webkit-media-controls-enclosure) |
159 // \-MediaControlPanelElement | 157 // \-MediaControlPanelElement |
160 // | (-webkit-media-controls-panel) | 158 // | (-webkit-media-controls-panel) |
161 // +-MediaControlPlayButtonElement | 159 // +-MediaControlPlayButtonElement |
162 // | (-webkit-media-controls-play-button) | 160 // | (-webkit-media-controls-play-button) |
163 // | {if !RTE::newMediaPlaybackUi()} | |
164 // +-MediaControlTimelineElement | |
165 // | (-webkit-media-controls-timeline) | |
166 // +-MediaControlCurrentTimeDisplayElement | 161 // +-MediaControlCurrentTimeDisplayElement |
167 // | (-webkit-media-controls-current-time-display) | 162 // | (-webkit-media-controls-current-time-display) |
168 // +-MediaControlTimeRemainingDisplayElement | 163 // +-MediaControlTimeRemainingDisplayElement |
169 // | (-webkit-media-controls-time-remaining-display) | 164 // | (-webkit-media-controls-time-remaining-display) |
170 // | {if RTE::newMediaPlaybackUi()} | |
171 // +-MediaControlTimelineElement | 165 // +-MediaControlTimelineElement |
172 // | (-webkit-media-controls-timeline) | 166 // | (-webkit-media-controls-timeline) |
173 // +-MediaControlMuteButtonElement | 167 // +-MediaControlMuteButtonElement |
174 // | (-webkit-media-controls-mute-button) | 168 // | (-webkit-media-controls-mute-button) |
175 // +-MediaControlVolumeSliderElement | 169 // +-MediaControlVolumeSliderElement |
176 // | (-webkit-media-controls-volume-slider) | 170 // | (-webkit-media-controls-volume-slider) |
177 // +-MediaControlFullscreenButtonElement | 171 // +-MediaControlFullscreenButtonElement |
178 // | (-webkit-media-controls-fullscreen-button) | 172 // | (-webkit-media-controls-fullscreen-button) |
179 // +-MediaControlDownloadButtonElement | 173 // +-MediaControlDownloadButtonElement |
180 // | (-internal-media-controls-download-button) | 174 // | (-internal-media-controls-download-button) |
181 // +-MediaControlToggleClosedCaptionsButtonElement | 175 // +-MediaControlToggleClosedCaptionsButtonElement |
182 // | (-webkit-media-controls-toggle-closed-captions-button) | 176 // | (-webkit-media-controls-toggle-closed-captions-button) |
183 // \-MediaControlCastButtonElement | 177 // \-MediaControlCastButtonElement |
184 // (-internal-media-controls-cast-button) | 178 // (-internal-media-controls-cast-button) |
185 // +-MediaControlTextTrackListElement | 179 // +-MediaControlTextTrackListElement |
186 // | (-internal-media-controls-text-track-list) | 180 // | (-internal-media-controls-text-track-list) |
187 // | {for each renderable text track} | 181 // | {for each renderable text track} |
188 // \-MediaControlTextTrackListItem | 182 // \-MediaControlTextTrackListItem |
189 // | (-internal-media-controls-text-track-list-item) | 183 // | (-internal-media-controls-text-track-list-item) |
190 // +-MediaControlTextTrackListItemInput | 184 // +-MediaControlTextTrackListItemInput |
191 // | (-internal-media-controls-text-track-list-item-input) | 185 // | (-internal-media-controls-text-track-list-item-input) |
192 // +-MediaControlTextTrackListItemCaptions | 186 // +-MediaControlTextTrackListItemCaptions |
193 // | (-internal-media-controls-text-track-list-kind-captions) | 187 // | (-internal-media-controls-text-track-list-kind-captions) |
194 // +-MediaControlTextTrackListItemSubtitles | 188 // +-MediaControlTextTrackListItemSubtitles |
195 // (-internal-media-controls-text-track-list-kind-subtitles) | 189 // (-internal-media-controls-text-track-list-kind-subtitles) |
196 void MediaControls::initializeControls() { | 190 void MediaControls::initializeControls() { |
197 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled(); | |
198 MediaControlOverlayEnclosureElement* overlayEnclosure = | 191 MediaControlOverlayEnclosureElement* overlayEnclosure = |
199 MediaControlOverlayEnclosureElement::create(*this); | 192 MediaControlOverlayEnclosureElement::create(*this); |
200 | 193 |
201 if (document().settings() && | 194 if (document().settings() && |
202 document().settings()->mediaControlsOverlayPlayButtonEnabled()) { | 195 document().settings()->mediaControlsOverlayPlayButtonEnabled()) { |
203 MediaControlOverlayPlayButtonElement* overlayPlayButton = | 196 MediaControlOverlayPlayButtonElement* overlayPlayButton = |
204 MediaControlOverlayPlayButtonElement::create(*this); | 197 MediaControlOverlayPlayButtonElement::create(*this); |
205 m_overlayPlayButton = overlayPlayButton; | 198 m_overlayPlayButton = overlayPlayButton; |
206 overlayEnclosure->appendChild(overlayPlayButton); | 199 overlayEnclosure->appendChild(overlayPlayButton); |
207 } | 200 } |
(...skipping 11 matching lines...) Expand all Loading... |
219 MediaControlPanelEnclosureElement* enclosure = | 212 MediaControlPanelEnclosureElement* enclosure = |
220 MediaControlPanelEnclosureElement::create(*this); | 213 MediaControlPanelEnclosureElement::create(*this); |
221 | 214 |
222 MediaControlPanelElement* panel = MediaControlPanelElement::create(*this); | 215 MediaControlPanelElement* panel = MediaControlPanelElement::create(*this); |
223 | 216 |
224 MediaControlPlayButtonElement* playButton = | 217 MediaControlPlayButtonElement* playButton = |
225 MediaControlPlayButtonElement::create(*this); | 218 MediaControlPlayButtonElement::create(*this); |
226 m_playButton = playButton; | 219 m_playButton = playButton; |
227 panel->appendChild(playButton); | 220 panel->appendChild(playButton); |
228 | 221 |
229 MediaControlTimelineElement* timeline = | |
230 MediaControlTimelineElement::create(*this); | |
231 m_timeline = timeline; | |
232 // In old UX, timeline is before the time / duration text. | |
233 if (!useNewUi) | |
234 panel->appendChild(timeline); | |
235 // else we will attach it later. | |
236 | |
237 MediaControlCurrentTimeDisplayElement* currentTimeDisplay = | 222 MediaControlCurrentTimeDisplayElement* currentTimeDisplay = |
238 MediaControlCurrentTimeDisplayElement::create(*this); | 223 MediaControlCurrentTimeDisplayElement::create(*this); |
239 m_currentTimeDisplay = currentTimeDisplay; | 224 m_currentTimeDisplay = currentTimeDisplay; |
240 m_currentTimeDisplay->setIsWanted(useNewUi); | 225 m_currentTimeDisplay->setIsWanted(true); |
241 panel->appendChild(currentTimeDisplay); | 226 panel->appendChild(currentTimeDisplay); |
242 | 227 |
243 MediaControlTimeRemainingDisplayElement* durationDisplay = | 228 MediaControlTimeRemainingDisplayElement* durationDisplay = |
244 MediaControlTimeRemainingDisplayElement::create(*this); | 229 MediaControlTimeRemainingDisplayElement::create(*this); |
245 m_durationDisplay = durationDisplay; | 230 m_durationDisplay = durationDisplay; |
246 panel->appendChild(durationDisplay); | 231 panel->appendChild(durationDisplay); |
247 | 232 |
248 // Timeline is after the time / duration text if newMediaPlaybackUiEnabled. | 233 MediaControlTimelineElement* timeline = |
249 if (useNewUi) | 234 MediaControlTimelineElement::create(*this); |
250 panel->appendChild(timeline); | 235 m_timeline = timeline; |
| 236 panel->appendChild(timeline); |
251 | 237 |
252 MediaControlMuteButtonElement* muteButton = | 238 MediaControlMuteButtonElement* muteButton = |
253 MediaControlMuteButtonElement::create(*this); | 239 MediaControlMuteButtonElement::create(*this); |
254 m_muteButton = muteButton; | 240 m_muteButton = muteButton; |
255 panel->appendChild(muteButton); | 241 panel->appendChild(muteButton); |
256 | 242 |
257 MediaControlVolumeSliderElement* slider = | 243 MediaControlVolumeSliderElement* slider = |
258 MediaControlVolumeSliderElement::create(*this); | 244 MediaControlVolumeSliderElement::create(*this); |
259 m_volumeSlider = slider; | 245 m_volumeSlider = slider; |
260 panel->appendChild(slider); | 246 panel->appendChild(slider); |
261 if (m_allowHiddenVolumeControls && preferHiddenVolumeControls(document())) | 247 if (preferHiddenVolumeControls(document())) |
262 m_volumeSlider->setIsWanted(false); | 248 m_volumeSlider->setIsWanted(false); |
263 | 249 |
264 MediaControlFullscreenButtonElement* fullscreenButton = | 250 MediaControlFullscreenButtonElement* fullscreenButton = |
265 MediaControlFullscreenButtonElement::create(*this); | 251 MediaControlFullscreenButtonElement::create(*this); |
266 m_fullscreenButton = fullscreenButton; | 252 m_fullscreenButton = fullscreenButton; |
267 panel->appendChild(fullscreenButton); | 253 panel->appendChild(fullscreenButton); |
268 | 254 |
269 MediaControlDownloadButtonElement* downloadButton = | 255 MediaControlDownloadButtonElement* downloadButton = |
270 MediaControlDownloadButtonElement::create(*this); | 256 MediaControlDownloadButtonElement::create(*this); |
271 m_downloadButton = downloadButton; | 257 m_downloadButton = downloadButton; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 *this, MediaControlMuteButtonElement::create(*this))); | 302 *this, MediaControlMuteButtonElement::create(*this))); |
317 m_overflowList->appendChild(m_castButton->createOverflowElement( | 303 m_overflowList->appendChild(m_castButton->createOverflowElement( |
318 *this, MediaControlCastButtonElement::create(*this, false))); | 304 *this, MediaControlCastButtonElement::create(*this, false))); |
319 m_overflowList->appendChild( | 305 m_overflowList->appendChild( |
320 m_toggleClosedCaptionsButton->createOverflowElement( | 306 m_toggleClosedCaptionsButton->createOverflowElement( |
321 *this, MediaControlToggleClosedCaptionsButtonElement::create(*this))); | 307 *this, MediaControlToggleClosedCaptionsButtonElement::create(*this))); |
322 } | 308 } |
323 | 309 |
324 void MediaControls::reset() { | 310 void MediaControls::reset() { |
325 EventDispatchForbiddenScope::AllowUserAgentEvents allowEventsInShadow; | 311 EventDispatchForbiddenScope::AllowUserAgentEvents allowEventsInShadow; |
326 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled(); | |
327 BatchedControlUpdate batch(this); | 312 BatchedControlUpdate batch(this); |
328 | 313 |
329 m_allowHiddenVolumeControls = useNewUi; | |
330 | |
331 const double duration = mediaElement().duration(); | 314 const double duration = mediaElement().duration(); |
332 m_durationDisplay->setTextContent( | 315 m_durationDisplay->setTextContent( |
333 LayoutTheme::theme().formatMediaControlsTime(duration)); | 316 LayoutTheme::theme().formatMediaControlsTime(duration)); |
334 m_durationDisplay->setCurrentValue(duration); | 317 m_durationDisplay->setCurrentValue(duration); |
335 | 318 |
336 if (useNewUi) { | 319 // Show everything that we might hide. |
337 // Show everything that we might hide. | 320 // If we don't have a duration, then mark it to be hidden. For the |
338 // If we don't have a duration, then mark it to be hidden. For the | 321 // old UI case, want / don't want is the same as show / hide since |
339 // old UI case, want / don't want is the same as show / hide since | 322 // it is never marked as not fitting. |
340 // it is never marked as not fitting. | 323 m_durationDisplay->setIsWanted(std::isfinite(duration)); |
341 m_durationDisplay->setIsWanted(std::isfinite(duration)); | 324 m_currentTimeDisplay->setIsWanted(true); |
342 m_currentTimeDisplay->setIsWanted(true); | 325 m_timeline->setIsWanted(true); |
343 m_timeline->setIsWanted(true); | |
344 } | |
345 | 326 |
346 // If the player has entered an error state, force it into the paused state. | 327 // If the player has entered an error state, force it into the paused state. |
347 if (mediaElement().error()) | 328 if (mediaElement().error()) |
348 mediaElement().pause(); | 329 mediaElement().pause(); |
349 | 330 |
350 updatePlayState(); | 331 updatePlayState(); |
351 | 332 |
352 updateCurrentTimeDisplay(); | 333 updateCurrentTimeDisplay(); |
353 | 334 |
354 m_timeline->setDuration(duration); | 335 m_timeline->setDuration(duration); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 | 418 |
438 // Don't hide the media controls when a panel is showing. | 419 // Don't hide the media controls when a panel is showing. |
439 if (m_textTrackList->isWanted() || m_overflowList->isWanted()) | 420 if (m_textTrackList->isWanted() || m_overflowList->isWanted()) |
440 return false; | 421 return false; |
441 | 422 |
442 return true; | 423 return true; |
443 } | 424 } |
444 | 425 |
445 void MediaControls::playbackStarted() { | 426 void MediaControls::playbackStarted() { |
446 BatchedControlUpdate batch(this); | 427 BatchedControlUpdate batch(this); |
447 | |
448 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { | |
449 m_currentTimeDisplay->setIsWanted(true); | |
450 m_durationDisplay->setIsWanted(false); | |
451 } | |
452 | |
453 updatePlayState(); | 428 updatePlayState(); |
454 m_timeline->setPosition(mediaElement().currentTime()); | 429 m_timeline->setPosition(mediaElement().currentTime()); |
455 updateCurrentTimeDisplay(); | 430 updateCurrentTimeDisplay(); |
456 | 431 |
457 startHideMediaControlsTimer(); | 432 startHideMediaControlsTimer(); |
458 } | 433 } |
459 | 434 |
460 void MediaControls::playbackProgressed() { | 435 void MediaControls::playbackProgressed() { |
461 m_timeline->setPosition(mediaElement().currentTime()); | 436 m_timeline->setPosition(mediaElement().currentTime()); |
462 updateCurrentTimeDisplay(); | 437 updateCurrentTimeDisplay(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 m_isPausedForScrubbing = false; | 470 m_isPausedForScrubbing = false; |
496 if (mediaElement().paused()) | 471 if (mediaElement().paused()) |
497 mediaElement().play(); | 472 mediaElement().play(); |
498 } | 473 } |
499 } | 474 } |
500 | 475 |
501 void MediaControls::updateCurrentTimeDisplay() { | 476 void MediaControls::updateCurrentTimeDisplay() { |
502 double now = mediaElement().currentTime(); | 477 double now = mediaElement().currentTime(); |
503 double duration = mediaElement().duration(); | 478 double duration = mediaElement().duration(); |
504 | 479 |
505 // After seek, hide duration display and show current time. | |
506 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled() && now > 0) { | |
507 BatchedControlUpdate batch(this); | |
508 m_currentTimeDisplay->setIsWanted(true); | |
509 m_durationDisplay->setIsWanted(false); | |
510 } | |
511 | |
512 // Allow the theme to format the time. | 480 // Allow the theme to format the time. |
513 m_currentTimeDisplay->setInnerText( | 481 m_currentTimeDisplay->setInnerText( |
514 LayoutTheme::theme().formatMediaControlsCurrentTime(now, duration), | 482 LayoutTheme::theme().formatMediaControlsCurrentTime(now, duration), |
515 IGNORE_EXCEPTION); | 483 IGNORE_EXCEPTION); |
516 m_currentTimeDisplay->setCurrentValue(now); | 484 m_currentTimeDisplay->setCurrentValue(now); |
517 } | 485 } |
518 | 486 |
519 void MediaControls::updateVolume() { | 487 void MediaControls::updateVolume() { |
520 m_muteButton->updateDisplayType(); | 488 m_muteButton->updateDisplayType(); |
521 // Invalidate the mute button because it paints differently according to | 489 // Invalidate the mute button because it paints differently according to |
522 // volume. | 490 // volume. |
523 invalidate(m_muteButton); | 491 invalidate(m_muteButton); |
524 | 492 |
525 if (mediaElement().muted()) | 493 if (mediaElement().muted()) |
526 m_volumeSlider->setVolume(0); | 494 m_volumeSlider->setVolume(0); |
527 else | 495 else |
528 m_volumeSlider->setVolume(mediaElement().volume()); | 496 m_volumeSlider->setVolume(mediaElement().volume()); |
529 | 497 |
530 // Update the visibility of our audio elements. | 498 // Update the visibility of our audio elements. |
531 // We never want the volume slider if there's no audio. | 499 // We never want the volume slider if there's no audio. |
532 // If there is audio, then we want it unless hiding audio is enabled and | 500 // If there is audio, then we want it unless we prefer to hide it. |
533 // we prefer to hide it. | |
534 BatchedControlUpdate batch(this); | 501 BatchedControlUpdate batch(this); |
535 m_volumeSlider->setIsWanted( | 502 m_volumeSlider->setIsWanted(mediaElement().hasAudio() && |
536 mediaElement().hasAudio() && | 503 !preferHiddenVolumeControls(document())); |
537 !(m_allowHiddenVolumeControls && preferHiddenVolumeControls(document()))); | |
538 | 504 |
539 // The mute button is a little more complicated. If enableNewMediaPlaybackUi | 505 // If there is no audio track, then hide the mute button. |
540 // is true, then we choose to hide or show the mute button to save space. | 506 m_muteButton->setIsWanted(mediaElement().hasAudio()); |
541 // If enableNew* is not set, then we never touch the mute button, and | |
542 // instead leave it to the CSS. | |
543 // Note that this is why m_allowHiddenVolumeControls isn't rolled into | |
544 // prefer...(). | |
545 if (m_allowHiddenVolumeControls) { | |
546 // If there is no audio track, then hide the mute button. | |
547 m_muteButton->setIsWanted(mediaElement().hasAudio()); | |
548 } | |
549 | 507 |
550 // Invalidate the volume slider because it paints differently according to | 508 // Invalidate the volume slider because it paints differently according to |
551 // volume. | 509 // volume. |
552 invalidate(m_volumeSlider); | 510 invalidate(m_volumeSlider); |
553 } | 511 } |
554 | 512 |
555 void MediaControls::changedClosedCaptionsVisibility() { | 513 void MediaControls::changedClosedCaptionsVisibility() { |
556 m_toggleClosedCaptionsButton->updateDisplayType(); | 514 m_toggleClosedCaptionsButton->updateDisplayType(); |
557 } | 515 } |
558 | 516 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 // visibility in the case where the cast button isn't wanted. | 558 // visibility in the case where the cast button isn't wanted. |
601 // We don't call compute...() here, but it will be called as | 559 // We don't call compute...() here, but it will be called as |
602 // non-cast changes (e.g., resize) occur. If the panel button | 560 // non-cast changes (e.g., resize) occur. If the panel button |
603 // is shown, however, compute...() will take control of the | 561 // is shown, however, compute...() will take control of the |
604 // overlay cast button if it needs to hide it from the panel. | 562 // overlay cast button if it needs to hide it from the panel. |
605 m_overlayCastButton->tryShowOverlay(); | 563 m_overlayCastButton->tryShowOverlay(); |
606 m_castButton->setIsWanted(false); | 564 m_castButton->setIsWanted(false); |
607 } else if (mediaElement().shouldShowControls()) { | 565 } else if (mediaElement().shouldShowControls()) { |
608 m_overlayCastButton->setIsWanted(false); | 566 m_overlayCastButton->setIsWanted(false); |
609 m_castButton->setIsWanted(true); | 567 m_castButton->setIsWanted(true); |
610 // Check that the cast button actually fits on the bar. For the | |
611 // newMediaPlaybackUiEnabled case, we let computeWhichControlsFit() | |
612 // handle this. | |
613 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled() && | |
614 m_fullscreenButton->getBoundingClientRect()->right() > | |
615 m_panel->getBoundingClientRect()->right()) { | |
616 m_castButton->setIsWanted(false); | |
617 m_overlayCastButton->tryShowOverlay(); | |
618 } | |
619 } | 568 } |
620 } | 569 } |
621 | 570 |
622 void MediaControls::showOverlayCastButtonIfNeeded() { | 571 void MediaControls::showOverlayCastButtonIfNeeded() { |
623 if (mediaElement().shouldShowControls() || | 572 if (mediaElement().shouldShowControls() || |
624 !shouldShowCastButton(mediaElement())) | 573 !shouldShowCastButton(mediaElement())) |
625 return; | 574 return; |
626 | 575 |
627 m_overlayCastButton->tryShowOverlay(); | 576 m_overlayCastButton->tryShowOverlay(); |
628 resetHideMediaControlsTimer(); | 577 resetHideMediaControlsTimer(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 return contains(relatedTarget->toNode()); | 708 return contains(relatedTarget->toNode()); |
760 } | 709 } |
761 | 710 |
762 void MediaControls::notifyPanelWidthChanged(const LayoutUnit& newWidth) { | 711 void MediaControls::notifyPanelWidthChanged(const LayoutUnit& newWidth) { |
763 // Don't bother to do any work if this matches the most recent panel | 712 // Don't bother to do any work if this matches the most recent panel |
764 // width, since we're called after layout. | 713 // width, since we're called after layout. |
765 // Note that this code permits a bad frame on resize, since it is | 714 // Note that this code permits a bad frame on resize, since it is |
766 // run after the relayout / paint happens. It would be great to improve | 715 // run after the relayout / paint happens. It would be great to improve |
767 // this, but it would be even greater to move this code entirely to | 716 // this, but it would be even greater to move this code entirely to |
768 // JS and fix it there. | 717 // JS and fix it there. |
769 const int panelWidth = newWidth.toInt(); | 718 m_panelWidth = newWidth.toInt(); |
770 | |
771 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | |
772 return; | |
773 | |
774 m_panelWidth = panelWidth; | |
775 | 719 |
776 // Adjust for effective zoom. | 720 // Adjust for effective zoom. |
777 if (!m_panel->layoutObject() || !m_panel->layoutObject()->style()) | 721 if (!m_panel->layoutObject() || !m_panel->layoutObject()->style()) |
778 return; | 722 return; |
779 m_panelWidth = | 723 m_panelWidth = |
780 ceil(m_panelWidth / m_panel->layoutObject()->style()->effectiveZoom()); | 724 ceil(m_panelWidth / m_panel->layoutObject()->style()->effectiveZoom()); |
781 | 725 |
782 m_panelWidthChangedTimer.startOneShot(0, BLINK_FROM_HERE); | 726 m_panelWidthChangedTimer.startOneShot(0, BLINK_FROM_HERE); |
783 } | 727 } |
784 | 728 |
785 void MediaControls::panelWidthChangedTimerFired(TimerBase*) { | 729 void MediaControls::panelWidthChangedTimerFired(TimerBase*) { |
786 computeWhichControlsFit(); | 730 computeWhichControlsFit(); |
787 } | 731 } |
788 | 732 |
789 void MediaControls::computeWhichControlsFit() { | 733 void MediaControls::computeWhichControlsFit() { |
790 // Hide all controls that don't fit, and show the ones that do. | 734 // Hide all controls that don't fit, and show the ones that do. |
791 // This might be better suited for a layout, but since JS media controls | 735 // This might be better suited for a layout, but since JS media controls |
792 // won't benefit from that anwyay, we just do it here like JS will. | 736 // won't benefit from that anwyay, we just do it here like JS will. |
793 | 737 |
794 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | |
795 return; | |
796 | |
797 // Controls that we'll hide / show, in order of decreasing priority. | 738 // Controls that we'll hide / show, in order of decreasing priority. |
798 MediaControlElement* elements[] = { | 739 MediaControlElement* elements[] = { |
799 // Exclude m_overflowMenu; we handle it specially. | 740 // Exclude m_overflowMenu; we handle it specially. |
800 m_playButton.get(), | 741 m_playButton.get(), |
801 m_fullscreenButton.get(), | 742 m_fullscreenButton.get(), |
802 m_downloadButton.get(), | 743 m_downloadButton.get(), |
803 m_timeline.get(), | 744 m_timeline.get(), |
804 m_muteButton.get(), | 745 m_muteButton.get(), |
805 m_volumeSlider.get(), | 746 m_volumeSlider.get(), |
806 m_toggleClosedCaptionsButton.get(), | 747 m_toggleClosedCaptionsButton.get(), |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 width += sliderMargin; | 832 width += sliderMargin; |
892 if (usedWidth + width <= m_panelWidth) | 833 if (usedWidth + width <= m_panelWidth) |
893 firstDisplacedElement->setDoesFit(true); | 834 firstDisplacedElement->setDoesFit(true); |
894 } | 835 } |
895 } else if (overflowElements.size() == 1) { | 836 } else if (overflowElements.size() == 1) { |
896 m_overflowMenu->setIsWanted(false); | 837 m_overflowMenu->setIsWanted(false); |
897 overflowElements.front()->setDoesFit(true); | 838 overflowElements.front()->setDoesFit(true); |
898 } | 839 } |
899 } | 840 } |
900 | 841 |
901 void MediaControls::setAllowHiddenVolumeControls(bool allow) { | |
902 m_allowHiddenVolumeControls = allow; | |
903 // Update the controls visibility. | |
904 updateVolume(); | |
905 } | |
906 | |
907 void MediaControls::invalidate(Element* element) { | 842 void MediaControls::invalidate(Element* element) { |
908 if (!element) | 843 if (!element) |
909 return; | 844 return; |
910 | 845 |
911 if (LayoutObject* layoutObject = element->layoutObject()) | 846 if (LayoutObject* layoutObject = element->layoutObject()) |
912 layoutObject | 847 layoutObject |
913 ->setShouldDoFullPaintInvalidationIncludingNonCompositingDescendants(); | 848 ->setShouldDoFullPaintInvalidationIncludingNonCompositingDescendants(); |
914 } | 849 } |
915 | 850 |
916 void MediaControls::networkStateChanged() { | 851 void MediaControls::networkStateChanged() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 visitor->trace(m_textTrackList); | 897 visitor->trace(m_textTrackList); |
963 visitor->trace(m_overflowMenu); | 898 visitor->trace(m_overflowMenu); |
964 visitor->trace(m_overflowList); | 899 visitor->trace(m_overflowList); |
965 visitor->trace(m_castButton); | 900 visitor->trace(m_castButton); |
966 visitor->trace(m_overlayCastButton); | 901 visitor->trace(m_overlayCastButton); |
967 visitor->trace(m_windowEventListener); | 902 visitor->trace(m_windowEventListener); |
968 HTMLDivElement::trace(visitor); | 903 HTMLDivElement::trace(visitor); |
969 } | 904 } |
970 | 905 |
971 } // namespace blink | 906 } // namespace blink |
OLD | NEW |