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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 | 137 |
138 MediaControls* MediaControls::create(HTMLMediaElement& mediaElement) { | 138 MediaControls* MediaControls::create(HTMLMediaElement& mediaElement) { |
139 MediaControls* controls = new MediaControls(mediaElement); | 139 MediaControls* controls = new MediaControls(mediaElement); |
140 controls->setShadowPseudoId(AtomicString("-webkit-media-controls")); | 140 controls->setShadowPseudoId(AtomicString("-webkit-media-controls")); |
141 controls->initializeControls(); | 141 controls->initializeControls(); |
142 return controls; | 142 return controls; |
143 } | 143 } |
144 | 144 |
145 // The media controls DOM structure looks like: | 145 // The media controls DOM structure looks like: |
146 // | 146 // |
147 // MediaControls (-webkit-media-controls) | 147 // MediaControls |
148 // +-MediaControlOverlayEnclosureElement (-webkit-media-controls-o verlay-enclosure) | 148 // (-webkit-media-controls) |
149 // | +-MediaControlOverlayPlayButtonElement (-webkit-media-controls-o verlay-play-button) | 149 // +-MediaControlOverlayEnclosureElement |
150 // | (-webkit-media-controls-overlay-enclosure) | |
151 // | +-MediaControlOverlayPlayButtonElement | |
152 // | | (-webkit-media-controls-overlay-play-button) | |
150 // | | {if mediaControlsOverlayPlayButtonEnabled} | 153 // | | {if mediaControlsOverlayPlayButtonEnabled} |
151 // | \-MediaControlCastButtonElement (-internal-media-controls -overlay-cast-button) | 154 // | \-MediaControlCastButtonElement |
152 // \-MediaControlPanelEnclosureElement (-webkit-media-controls-e nclosure) | 155 // | (-internal-media-controls-overlay-cast-button) |
153 // \-MediaControlPanelElement (-webkit-media-controls-p anel) | 156 // \-MediaControlPanelEnclosureElement |
154 // +-MediaControlPlayButtonElement (-webkit-media-controls-p lay-button) | 157 // | (-webkit-media-controls-enclosure) |
158 // \-MediaControlPanelElement | |
159 // | (-webkit-media-controls-panel) | |
160 // +-MediaControlPlayButtonElement | |
161 // | (-webkit-media-controls-play-button) | |
155 // | {if !RTE::newMediaPlaybackUi()} | 162 // | {if !RTE::newMediaPlaybackUi()} |
156 // +-MediaControlTimelineElement (-webkit-media-controls-t imeline) | 163 // +-MediaControlTimelineElement |
157 // +-MediaControlCurrentTimeDisplayElement (-webkit-media-controls-c urrent-time-display) | 164 // | (-webkit-media-controls-timeline) |
158 // +-MediaControlTimeRemainingDisplayElement (-webkit-media-controls-t ime-remaining-display) | 165 // +-MediaControlCurrentTimeDisplayElement |
166 // | (-webkit-media-controls-current-time-display) | |
167 // +-MediaControlTimeRemainingDisplayElement | |
168 // | (-webkit-media-controls-time-remaining-display) | |
159 // | {if RTE::newMediaPlaybackUi()} | 169 // | {if RTE::newMediaPlaybackUi()} |
160 // +-MediaControlTimelineElement (-webkit-media-controls-t imeline) | 170 // +-MediaControlTimelineElement |
161 // +-MediaControlMuteButtonElement (-webkit-media-controls-m ute-button) | 171 // | (-webkit-media-controls-timeline) |
162 // +-MediaControlVolumeSliderElement (-webkit-media-controls-v olume-slider) | 172 // +-MediaControlMuteButtonElement |
163 // +-MediaControlFullscreenButtonElement (-webkit-media-controls-f ullscreen-button) | 173 // | (-webkit-media-controls-mute-button) |
164 // +-MediaControlDownloadButtonElement (-internal-media-controls -download-button) | 174 // +-MediaControlVolumeSliderElement |
165 // +-MediaControlToggleClosedCaptionsButtonElement (-webkit-media-controls-t oggle-closed-captions-button) | 175 // | (-webkit-media-controls-volume-slider) |
166 // \-MediaControlCastButtonElement (-internal-media-controls -cast-button) | 176 // +-MediaControlFullscreenButtonElement |
167 // +-MediaControlTextTrackListElement (-internal-media-controls-t ext-track-list) | 177 // | (-webkit-media-controls-fullscreen-button) |
178 // +-MediaControlDownloadButtonElement | |
179 // | (-internal-media-controls-download-button) | |
180 // +-MediaControlToggleClosedCaptionsButtonElement | |
181 // | (-webkit-media-controls-toggle-closed-captions-button) | |
182 // \-MediaControlCastButtonElement | |
183 // (-internal-media-controls-cast-button) | |
184 // +-MediaControlTextTrackListElement | |
185 // | (-internal-media-controls-text-track-list) | |
168 // | {for each renderable text track} | 186 // | {for each renderable text track} |
169 // \-MediaControlTextTrackListItem (-internal-media-controls-te xt-track-list-item) | 187 // \-MediaControlTextTrackListItem |
170 // +-MediaControlTextTrackListItemInput (-internal-media-controls-te xt-track-list-item-input) | 188 // | (-internal-media-controls-text-track-list-item) |
171 // +-MediaControlTextTrackListItemCaptions (-internal-media-controls-te xt-track-list-kind-captions) | 189 // +-MediaControlTextTrackListItemInput |
172 // +-MediaControlTextTrackListItemSubtitles (-internal-media-controls-te xt-track-list-kind-subtitles) | 190 // | (-internal-media-controls-text-track-list-item-input) |
191 // +-MediaControlTextTrackListItemCaptions | |
192 // | (-internal-media-controls-text-track-list-kind-captions) | |
193 // +-MediaControlTextTrackListItemSubtitles | |
194 // | (-internal-media-controls-text-track-list-kind-subtitles) | |
fs
2016/10/05 20:52:08
uNit: Could drop this pipe
Nico
2016/10/05 21:19:10
Done.
| |
173 void MediaControls::initializeControls() { | 195 void MediaControls::initializeControls() { |
174 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled(); | 196 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled(); |
175 MediaControlOverlayEnclosureElement* overlayEnclosure = | 197 MediaControlOverlayEnclosureElement* overlayEnclosure = |
176 MediaControlOverlayEnclosureElement::create(*this); | 198 MediaControlOverlayEnclosureElement::create(*this); |
177 | 199 |
178 if (document().settings() && | 200 if (document().settings() && |
179 document().settings()->mediaControlsOverlayPlayButtonEnabled()) { | 201 document().settings()->mediaControlsOverlayPlayButtonEnabled()) { |
180 MediaControlOverlayPlayButtonElement* overlayPlayButton = | 202 MediaControlOverlayPlayButtonElement* overlayPlayButton = |
181 MediaControlOverlayPlayButtonElement::create(*this); | 203 MediaControlOverlayPlayButtonElement::create(*this); |
182 m_overlayPlayButton = overlayPlayButton; | 204 m_overlayPlayButton = overlayPlayButton; |
183 overlayEnclosure->appendChild(overlayPlayButton); | 205 overlayEnclosure->appendChild(overlayPlayButton); |
184 } | 206 } |
185 | 207 |
186 MediaControlCastButtonElement* overlayCastButton = | 208 MediaControlCastButtonElement* overlayCastButton = |
187 MediaControlCastButtonElement::create(*this, true); | 209 MediaControlCastButtonElement::create(*this, true); |
188 m_overlayCastButton = overlayCastButton; | 210 m_overlayCastButton = overlayCastButton; |
189 overlayEnclosure->appendChild(overlayCastButton); | 211 overlayEnclosure->appendChild(overlayCastButton); |
190 | 212 |
191 m_overlayEnclosure = overlayEnclosure; | 213 m_overlayEnclosure = overlayEnclosure; |
192 appendChild(overlayEnclosure); | 214 appendChild(overlayEnclosure); |
193 | 215 |
194 // Create an enclosing element for the panel so we can visually offset the con trols correctly. | 216 // Create an enclosing element for the panel so we can visually offset the |
217 // controls correctly. | |
195 MediaControlPanelEnclosureElement* enclosure = | 218 MediaControlPanelEnclosureElement* enclosure = |
196 MediaControlPanelEnclosureElement::create(*this); | 219 MediaControlPanelEnclosureElement::create(*this); |
197 | 220 |
198 MediaControlPanelElement* panel = MediaControlPanelElement::create(*this); | 221 MediaControlPanelElement* panel = MediaControlPanelElement::create(*this); |
199 | 222 |
200 MediaControlPlayButtonElement* playButton = | 223 MediaControlPlayButtonElement* playButton = |
201 MediaControlPlayButtonElement::create(*this); | 224 MediaControlPlayButtonElement::create(*this); |
202 m_playButton = playButton; | 225 m_playButton = playButton; |
203 panel->appendChild(playButton); | 226 panel->appendChild(playButton); |
204 | 227 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 MediaControlOverflowMenuButtonElement::create(*this); | 295 MediaControlOverflowMenuButtonElement::create(*this); |
273 m_overflowMenu = overflowMenu; | 296 m_overflowMenu = overflowMenu; |
274 panel->appendChild(overflowMenu); | 297 panel->appendChild(overflowMenu); |
275 | 298 |
276 MediaControlOverflowMenuListElement* overflowList = | 299 MediaControlOverflowMenuListElement* overflowList = |
277 MediaControlOverflowMenuListElement::create(*this); | 300 MediaControlOverflowMenuListElement::create(*this); |
278 m_overflowList = overflowList; | 301 m_overflowList = overflowList; |
279 appendChild(overflowList); | 302 appendChild(overflowList); |
280 | 303 |
281 // The order in which we append elements to the overflow list is significant | 304 // The order in which we append elements to the overflow list is significant |
282 // because it determines how the elements show up in the overflow menu relativ e to each other. | 305 // because it determines how the elements show up in the overflow menu |
283 // The first item appended appears at the top of the overflow menu. | 306 // relative to each other. The first item appended appears at the top of the |
307 // overflow menu. | |
284 m_overflowList->appendChild(m_playButton->createOverflowElement( | 308 m_overflowList->appendChild(m_playButton->createOverflowElement( |
285 *this, MediaControlPlayButtonElement::create(*this))); | 309 *this, MediaControlPlayButtonElement::create(*this))); |
286 m_overflowList->appendChild(m_fullscreenButton->createOverflowElement( | 310 m_overflowList->appendChild(m_fullscreenButton->createOverflowElement( |
287 *this, MediaControlFullscreenButtonElement::create(*this))); | 311 *this, MediaControlFullscreenButtonElement::create(*this))); |
288 m_overflowList->appendChild(m_downloadButton->createOverflowElement( | 312 m_overflowList->appendChild(m_downloadButton->createOverflowElement( |
289 *this, MediaControlDownloadButtonElement::create(*this))); | 313 *this, MediaControlDownloadButtonElement::create(*this))); |
290 m_overflowList->appendChild(m_muteButton->createOverflowElement( | 314 m_overflowList->appendChild(m_muteButton->createOverflowElement( |
291 *this, MediaControlMuteButtonElement::create(*this))); | 315 *this, MediaControlMuteButtonElement::create(*this))); |
292 m_overflowList->appendChild(m_castButton->createOverflowElement( | 316 m_overflowList->appendChild(m_castButton->createOverflowElement( |
293 *this, MediaControlCastButtonElement::create(*this, false))); | 317 *this, MediaControlCastButtonElement::create(*this, false))); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 | 494 |
471 // Allow the theme to format the time. | 495 // Allow the theme to format the time. |
472 m_currentTimeDisplay->setInnerText( | 496 m_currentTimeDisplay->setInnerText( |
473 LayoutTheme::theme().formatMediaControlsCurrentTime(now, duration), | 497 LayoutTheme::theme().formatMediaControlsCurrentTime(now, duration), |
474 IGNORE_EXCEPTION); | 498 IGNORE_EXCEPTION); |
475 m_currentTimeDisplay->setCurrentValue(now); | 499 m_currentTimeDisplay->setCurrentValue(now); |
476 } | 500 } |
477 | 501 |
478 void MediaControls::updateVolume() { | 502 void MediaControls::updateVolume() { |
479 m_muteButton->updateDisplayType(); | 503 m_muteButton->updateDisplayType(); |
480 // Invalidate the mute button because it paints differently according to volum e. | 504 // Invalidate the mute button because it paints differently according to |
505 // volume. | |
481 invalidate(m_muteButton); | 506 invalidate(m_muteButton); |
482 | 507 |
483 if (mediaElement().muted()) | 508 if (mediaElement().muted()) |
484 m_volumeSlider->setVolume(0); | 509 m_volumeSlider->setVolume(0); |
485 else | 510 else |
486 m_volumeSlider->setVolume(mediaElement().volume()); | 511 m_volumeSlider->setVolume(mediaElement().volume()); |
487 | 512 |
488 // Update the visibility of our audio elements. | 513 // Update the visibility of our audio elements. |
489 // We never want the volume slider if there's no audio. | 514 // We never want the volume slider if there's no audio. |
490 // If there is audio, then we want it unless hiding audio is enabled and | 515 // If there is audio, then we want it unless hiding audio is enabled and |
491 // we prefer to hide it. | 516 // we prefer to hide it. |
492 BatchedControlUpdate batch(this); | 517 BatchedControlUpdate batch(this); |
493 m_volumeSlider->setIsWanted( | 518 m_volumeSlider->setIsWanted( |
494 mediaElement().hasAudio() && | 519 mediaElement().hasAudio() && |
495 !(m_allowHiddenVolumeControls && preferHiddenVolumeControls(document()))); | 520 !(m_allowHiddenVolumeControls && preferHiddenVolumeControls(document()))); |
496 | 521 |
497 // The mute button is a little more complicated. If enableNewMediaPlaybackUi | 522 // The mute button is a little more complicated. If enableNewMediaPlaybackUi |
498 // is true, then we choose to hide or show the mute button to save space. | 523 // is true, then we choose to hide or show the mute button to save space. |
499 // If enableNew* is not set, then we never touch the mute button, and | 524 // If enableNew* is not set, then we never touch the mute button, and |
500 // instead leave it to the CSS. | 525 // instead leave it to the CSS. |
501 // Note that this is why m_allowHiddenVolumeControls isn't rolled into prefer. ..(). | 526 // Note that this is why m_allowHiddenVolumeControls isn't rolled into |
527 // prefer...(). | |
502 if (m_allowHiddenVolumeControls) { | 528 if (m_allowHiddenVolumeControls) { |
503 // If there is no audio track, then hide the mute button. | 529 // If there is no audio track, then hide the mute button. |
504 m_muteButton->setIsWanted(mediaElement().hasAudio()); | 530 m_muteButton->setIsWanted(mediaElement().hasAudio()); |
505 } | 531 } |
506 | 532 |
507 // Invalidate the volume slider because it paints differently according to vol ume. | 533 // Invalidate the volume slider because it paints differently according to |
534 // volume. | |
508 invalidate(m_volumeSlider); | 535 invalidate(m_volumeSlider); |
509 } | 536 } |
510 | 537 |
511 void MediaControls::changedClosedCaptionsVisibility() { | 538 void MediaControls::changedClosedCaptionsVisibility() { |
512 m_toggleClosedCaptionsButton->updateDisplayType(); | 539 m_toggleClosedCaptionsButton->updateDisplayType(); |
513 } | 540 } |
514 | 541 |
515 void MediaControls::refreshClosedCaptionsButtonVisibility() { | 542 void MediaControls::refreshClosedCaptionsButtonVisibility() { |
516 m_toggleClosedCaptionsButton->setIsWanted(mediaElement().hasClosedCaptions()); | 543 m_toggleClosedCaptionsButton->setIsWanted(mediaElement().hasClosedCaptions()); |
517 BatchedControlUpdate batch(this); | 544 BatchedControlUpdate batch(this); |
(...skipping 16 matching lines...) Expand all Loading... | |
534 BatchedControlUpdate batch(this); | 561 BatchedControlUpdate batch(this); |
535 } | 562 } |
536 | 563 |
537 void MediaControls::refreshCastButtonVisibilityWithoutUpdate() { | 564 void MediaControls::refreshCastButtonVisibilityWithoutUpdate() { |
538 if (!shouldShowCastButton(mediaElement())) { | 565 if (!shouldShowCastButton(mediaElement())) { |
539 m_castButton->setIsWanted(false); | 566 m_castButton->setIsWanted(false); |
540 m_overlayCastButton->setIsWanted(false); | 567 m_overlayCastButton->setIsWanted(false); |
541 return; | 568 return; |
542 } | 569 } |
543 | 570 |
544 // The reason for the autoplay test is that some pages (e.g. vimeo.com) have a n autoplay background video, which | 571 // The reason for the autoplay test is that some pages (e.g. vimeo.com) have |
545 // doesn't autoplay on Chrome for Android (we prevent it) so starts paused. In such cases we don't want to automatically | 572 // an autoplay background video, which doesn't autoplay on Chrome for Android |
546 // show the cast button, since it looks strange and is unlikely to correspond with anything the user wants to do. | 573 // (we prevent it) so starts paused. In such cases we don't want to |
547 // If a user does want to cast a paused autoplay video then they can still do so by touching or clicking on the | 574 // automatically show the cast button, since it looks strange and is unlikely |
548 // video, which will cause the cast button to appear. | 575 // to correspond with anything the user wants to do. If a user does want to |
576 // cast a paused autoplay video then they can still do so by touching or | |
577 // clicking on the video, which will cause the cast button to appear. | |
549 if (!mediaElement().shouldShowControls() && !mediaElement().autoplay() && | 578 if (!mediaElement().shouldShowControls() && !mediaElement().autoplay() && |
550 mediaElement().paused()) { | 579 mediaElement().paused()) { |
551 // Note that this is a case where we add the overlay cast button | 580 // Note that this is a case where we add the overlay cast button |
552 // without wanting the panel cast button. We depend on the fact | 581 // without wanting the panel cast button. We depend on the fact |
553 // that computeWhichControlsFit() won't change overlay cast button | 582 // that computeWhichControlsFit() won't change overlay cast button |
554 // visibility in the case where the cast button isn't wanted. | 583 // visibility in the case where the cast button isn't wanted. |
555 // We don't call compute...() here, but it will be called as | 584 // We don't call compute...() here, but it will be called as |
556 // non-cast changes (e.g., resize) occur. If the panel button | 585 // non-cast changes (e.g., resize) occur. If the panel button |
557 // is shown, however, compute...() will take control of the | 586 // is shown, however, compute...() will take control of the |
558 // overlay cast button if it needs to hide it from the panel. | 587 // overlay cast button if it needs to hide it from the panel. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
600 } | 629 } |
601 | 630 |
602 void MediaControls::stoppedCasting() { | 631 void MediaControls::stoppedCasting() { |
603 m_castButton->setIsPlayingRemotely(false); | 632 m_castButton->setIsPlayingRemotely(false); |
604 m_overlayCastButton->setIsPlayingRemotely(false); | 633 m_overlayCastButton->setIsPlayingRemotely(false); |
605 } | 634 } |
606 | 635 |
607 void MediaControls::defaultEventHandler(Event* event) { | 636 void MediaControls::defaultEventHandler(Event* event) { |
608 HTMLDivElement::defaultEventHandler(event); | 637 HTMLDivElement::defaultEventHandler(event); |
609 | 638 |
610 // Add IgnoreControlsHover to m_hideTimerBehaviorFlags when we see a touch eve nt, | 639 // Add IgnoreControlsHover to m_hideTimerBehaviorFlags when we see a touch |
611 // to allow the hide-timer to do the right thing when it fires. | 640 // event, to allow the hide-timer to do the right thing when it fires. |
612 // FIXME: Preferably we would only do this when we're actually handling the ev ent | 641 // FIXME: Preferably we would only do this when we're actually handling the |
613 // here ourselves. | 642 // event here ourselves. |
614 bool wasLastEventTouch = | 643 bool wasLastEventTouch = |
615 event->isTouchEvent() || event->isGestureEvent() || | 644 event->isTouchEvent() || event->isGestureEvent() || |
616 (event->isMouseEvent() && toMouseEvent(event)->fromTouch()); | 645 (event->isMouseEvent() && toMouseEvent(event)->fromTouch()); |
617 m_hideTimerBehaviorFlags |= | 646 m_hideTimerBehaviorFlags |= |
618 wasLastEventTouch ? IgnoreControlsHover : IgnoreNone; | 647 wasLastEventTouch ? IgnoreControlsHover : IgnoreNone; |
619 | 648 |
620 if (event->type() == EventTypeNames::mouseover) { | 649 if (event->type() == EventTypeNames::mouseover) { |
621 if (!containsRelatedTarget(event)) { | 650 if (!containsRelatedTarget(event)) { |
622 m_isMouseOverControls = true; | 651 m_isMouseOverControls = true; |
623 if (!mediaElement().paused()) { | 652 if (!mediaElement().paused()) { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
890 visitor->trace(m_textTrackList); | 919 visitor->trace(m_textTrackList); |
891 visitor->trace(m_overflowMenu); | 920 visitor->trace(m_overflowMenu); |
892 visitor->trace(m_overflowList); | 921 visitor->trace(m_overflowList); |
893 visitor->trace(m_castButton); | 922 visitor->trace(m_castButton); |
894 visitor->trace(m_overlayCastButton); | 923 visitor->trace(m_overlayCastButton); |
895 visitor->trace(m_windowEventListener); | 924 visitor->trace(m_windowEventListener); |
896 HTMLDivElement::trace(visitor); | 925 HTMLDivElement::trace(visitor); |
897 } | 926 } |
898 | 927 |
899 } // namespace blink | 928 } // namespace blink |
OLD | NEW |