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

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaControlElements.cpp

Issue 2243473002: Adding overflow menu to media player (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 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 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 return button; 282 return button;
283 } 283 }
284 284
285 void MediaControlMuteButtonElement::defaultEventHandler(Event* event) 285 void MediaControlMuteButtonElement::defaultEventHandler(Event* event)
286 { 286 {
287 if (event->type() == EventTypeNames::click) { 287 if (event->type() == EventTypeNames::click) {
288 if (mediaElement().muted()) 288 if (mediaElement().muted())
289 Platform::current()->recordAction(UserMetricsAction("Media.Controls. Unmute")); 289 Platform::current()->recordAction(UserMetricsAction("Media.Controls. Unmute"));
290 else 290 else
291 Platform::current()->recordAction(UserMetricsAction("Media.Controls. Mute")); 291 Platform::current()->recordAction(UserMetricsAction("Media.Controls. Mute"));
292
293 mediaElement().setMuted(!mediaElement().muted()); 292 mediaElement().setMuted(!mediaElement().muted());
294 event->setDefaultHandled(); 293 event->setDefaultHandled();
295 } 294 }
296 295
297 HTMLInputElement::defaultEventHandler(event); 296 HTMLInputElement::defaultEventHandler(event);
298 } 297 }
299 298
300 void MediaControlMuteButtonElement::updateDisplayType() 299 void MediaControlMuteButtonElement::updateDisplayType()
301 { 300 {
302 setDisplayType(mediaElement().muted() ? MediaUnMuteButton : MediaMuteButton) ; 301 setDisplayType(mediaElement().muted() ? MediaUnMuteButton : MediaMuteButton) ;
303 } 302 }
304 303
304 String MediaControlMuteButtonElement::getText()
305 {
306 if (mediaElement().muted())
307 return mediaElement().locale().queryString(WebLocalizedString::OverflowM enuUnmute);
liberato (no reviews please) 2016/08/24 16:44:22 you might consider folding all of the queryString(
kdsilva 2016/08/26 18:11:02 Done. Although I'm not sure what the default retur
308 return mediaElement().locale().queryString(WebLocalizedString::OverflowMenuM ute);
309 }
310
305 // ---------------------------- 311 // ----------------------------
306 312
307 MediaControlPlayButtonElement::MediaControlPlayButtonElement(MediaControls& medi aControls) 313 MediaControlPlayButtonElement::MediaControlPlayButtonElement(MediaControls& medi aControls)
308 : MediaControlInputElement(mediaControls, MediaPlayButton) 314 : MediaControlInputElement(mediaControls, MediaPlayButton)
309 { 315 {
310 } 316 }
311 317
312 MediaControlPlayButtonElement* MediaControlPlayButtonElement::create(MediaContro ls& mediaControls) 318 MediaControlPlayButtonElement* MediaControlPlayButtonElement::create(MediaContro ls& mediaControls)
313 { 319 {
314 MediaControlPlayButtonElement* button = new MediaControlPlayButtonElement(me diaControls); 320 MediaControlPlayButtonElement* button = new MediaControlPlayButtonElement(me diaControls);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 406
401 void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType() 407 void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType()
402 { 408 {
403 bool captionsVisible = mediaElement().textTracksVisible(); 409 bool captionsVisible = mediaElement().textTracksVisible();
404 setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowCl osedCaptionsButton); 410 setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowCl osedCaptionsButton);
405 } 411 }
406 412
407 void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* e vent) 413 void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* e vent)
408 { 414 {
409 if (event->type() == EventTypeNames::click) { 415 if (event->type() == EventTypeNames::click) {
416 if (mediaControls().overflowMenuVisible())
417 mediaControls().toggleOverflowMenu();
410 mediaControls().toggleTextTrackList(); 418 mediaControls().toggleTextTrackList();
411 updateDisplayType(); 419 updateDisplayType();
412 event->setDefaultHandled(); 420 event->setDefaultHandled();
413 } 421 }
414 422
415 HTMLInputElement::defaultEventHandler(event); 423 HTMLInputElement::defaultEventHandler(event);
416 } 424 }
417 425
426 String MediaControlToggleClosedCaptionsButtonElement::getText()
427 {
428 return mediaElement().locale().queryString(WebLocalizedString::OverflowMenuC aptions);
429 }
430
418 // ---------------------------- 431 // ----------------------------
419 432
420 MediaControlTextTrackListElement::MediaControlTextTrackListElement(MediaControls & mediaControls) 433 MediaControlTextTrackListElement::MediaControlTextTrackListElement(MediaControls & mediaControls)
421 : MediaControlDivElement(mediaControls, MediaTextTrackList) 434 : MediaControlDivElement(mediaControls, MediaTextTrackList)
422 { 435 {
423 } 436 }
424 437
425 MediaControlTextTrackListElement* MediaControlTextTrackListElement::create(Media Controls& mediaControls) 438 MediaControlTextTrackListElement* MediaControlTextTrackListElement::create(Media Controls& mediaControls)
426 { 439 {
427 MediaControlTextTrackListElement* element = new MediaControlTextTrackListEle ment(mediaControls); 440 MediaControlTextTrackListElement* element = new MediaControlTextTrackListEle ment(mediaControls);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 TextTrackList* trackList = mediaElement().textTracks(); 560 TextTrackList* trackList = mediaElement().textTracks();
548 for (unsigned i = 0; i < trackList->length(); i++) { 561 for (unsigned i = 0; i < trackList->length(); i++) {
549 TextTrack* track = trackList->anonymousIndexedGetter(i); 562 TextTrack* track = trackList->anonymousIndexedGetter(i);
550 if (!track->canBeRendered()) 563 if (!track->canBeRendered())
551 continue; 564 continue;
552 appendChild(createTextTrackListItem(track)); 565 appendChild(createTextTrackListItem(track));
553 } 566 }
554 } 567 }
555 568
556 // ---------------------------- 569 // ----------------------------
570 MediaControlOverflowMenu::MediaControlOverflowMenu(MediaControls& mediaControls)
571 : MediaControlInputElement(mediaControls, MediaShowClosedCaptionsButton)
572 {
573 }
574
575 MediaControlOverflowMenu* MediaControlOverflowMenu::create(MediaControls& mediaC ontrols)
576 {
577 MediaControlOverflowMenu* button = new MediaControlOverflowMenu(mediaControl s);
578 button->ensureUserAgentShadowRoot();
579 button->setType(InputTypeNames::button);
580 button->setShadowPseudoId(AtomicString("-webkit-overflow-menu-button"));
581 button->setIsWanted(false);
582 return button;
583 }
584
585 void MediaControlOverflowMenu::defaultEventHandler(Event* event)
586 {
587 if (event->type() == EventTypeNames::click) {
588 mediaControls().toggleOverflowMenu();
589 event->setDefaultHandled();
590 }
591
592 HTMLInputElement::defaultEventHandler(event);
593 }
594
595 // ----------------------------
596 MediaControlOverflowMenuListElement::MediaControlOverflowMenuListElement(MediaCo ntrols& mediaControls)
597 : MediaControlDivElement(mediaControls, MediaShowClosedCaptionsButton)
598 {
599 }
600
601 MediaControlOverflowMenuListElement* MediaControlOverflowMenuListElement::create (MediaControls& mediaControls)
602 {
603 MediaControlOverflowMenuListElement* element = new MediaControlOverflowMenuL istElement(mediaControls);
604 element->setIsWanted(false);
605 element->setShadowPseudoId(AtomicString("-internal-media-controls-overflow-m enu-list"));
606 return element;
607 }
608
609 void MediaControlOverflowMenuListElement::setOverflowMenuControls(const std::set <MediaControlElementType>* controls)
610 {
611 removeChildren(OmitSubtreeModifiedEvent);
liberato (no reviews please) 2016/08/24 16:44:22 if you choose to go the route of pre-allocating ev
kdsilva 2016/08/26 18:11:02 Done. Although I couldn't find a simple of changin
612 // A list of all buttons that can appear in the overflow menu.
613 std::vector<MediaControlInputElement*> potentialControls = mediaControls().g etOverflowMenuButtons();
614
615 for (unsigned i = 0; i < potentialControls.size(); i++) {
616 MediaControlInputElement* element = potentialControls.at(i);
617 // Of all of the possible buttons that can be shown in the overflow menu ,
618 // we include only the buttons that didn't fit within the media player.
619 if (controls->count(element->displayType())) {
liberato (no reviews please) 2016/08/24 16:44:22 if the original element handles providing its own
kdsilva 2016/08/26 18:11:03 Done.
620 HTMLLabelElement* item = HTMLLabelElement::create(document());
621 item->setShadowPseudoId(AtomicString("-internal-media-controls-overf low-menu-list-item"));
622 item->appendChild(element);
623 item->appendChild(Text::create(document(), element->getText()));
liberato (no reviews please) 2016/08/24 16:44:22 does clicking on the label do anything? is it sup
kdsilva 2016/08/26 18:11:02 Clicking on the label should perform the action th
624 appendChild(item);
625 }
626 }
627 }
628
629 void MediaControlOverflowMenuListElement::showOverflowMenu(bool visible)
630 {
631 setIsWanted(visible);
632 }
633
634 void MediaControlOverflowMenuListElement::defaultEventHandler(Event* event)
635 {
636 if (event->type() == EventTypeNames::click)
637 event->setDefaultHandled();
638
639 MediaControlDivElement::defaultEventHandler(event);
640 }
641
642 // ----------------------------
557 643
558 MediaControlTimelineElement::MediaControlTimelineElement(MediaControls& mediaCon trols) 644 MediaControlTimelineElement::MediaControlTimelineElement(MediaControls& mediaCon trols)
559 : MediaControlInputElement(mediaControls, MediaSlider) 645 : MediaControlInputElement(mediaControls, MediaSlider)
560 { 646 {
561 } 647 }
562 648
563 MediaControlTimelineElement* MediaControlTimelineElement::create(MediaControls& mediaControls) 649 MediaControlTimelineElement* MediaControlTimelineElement::create(MediaControls& mediaControls)
564 { 650 {
565 MediaControlTimelineElement* timeline = new MediaControlTimelineElement(medi aControls); 651 MediaControlTimelineElement* timeline = new MediaControlTimelineElement(medi aControls);
566 timeline->ensureUserAgentShadowRoot(); 652 timeline->ensureUserAgentShadowRoot();
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 event->setDefaultHandled(); 817 event->setDefaultHandled();
732 } 818 }
733 HTMLInputElement::defaultEventHandler(event); 819 HTMLInputElement::defaultEventHandler(event);
734 } 820 }
735 821
736 void MediaControlFullscreenButtonElement::setIsFullscreen(bool isFullscreen) 822 void MediaControlFullscreenButtonElement::setIsFullscreen(bool isFullscreen)
737 { 823 {
738 setDisplayType(isFullscreen ? MediaExitFullscreenButton : MediaEnterFullscre enButton); 824 setDisplayType(isFullscreen ? MediaExitFullscreenButton : MediaEnterFullscre enButton);
739 } 825 }
740 826
827 String MediaControlFullscreenButtonElement::getText()
828 {
829 return mediaElement().locale().queryString(WebLocalizedString::OverflowMenuF ullscreen);
830 }
831
741 // ---------------------------- 832 // ----------------------------
742 833
743 MediaControlCastButtonElement::MediaControlCastButtonElement(MediaControls& medi aControls, bool isOverlayButton) 834 MediaControlCastButtonElement::MediaControlCastButtonElement(MediaControls& medi aControls, bool isOverlayButton)
744 : MediaControlInputElement(mediaControls, MediaCastOnButton), m_isOverlayBut ton(isOverlayButton) 835 : MediaControlInputElement(mediaControls, MediaCastOnButton), m_isOverlayBut ton(isOverlayButton)
745 { 836 {
746 if (m_isOverlayButton) 837 if (m_isOverlayButton)
747 recordMetrics(CastOverlayMetrics::Created); 838 recordMetrics(CastOverlayMetrics::Created);
748 setIsPlayingRemotely(false); 839 setIsPlayingRemotely(false);
749 } 840 }
750 841
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 } 885 }
795 } else { 886 } else {
796 if (m_isOverlayButton) { 887 if (m_isOverlayButton) {
797 setDisplayType(MediaOverlayCastOffButton); 888 setDisplayType(MediaOverlayCastOffButton);
798 } else { 889 } else {
799 setDisplayType(MediaCastOffButton); 890 setDisplayType(MediaCastOffButton);
800 } 891 }
801 } 892 }
802 } 893 }
803 894
895 String MediaControlCastButtonElement::getText()
896 {
897 if (mediaElement().isPlayingRemotely())
898 return mediaElement().locale().queryString(WebLocalizedString::OverflowM enuStopCast);
899 return mediaElement().locale().queryString(WebLocalizedString::OverflowMenuC ast);
900 }
901
804 void MediaControlCastButtonElement::tryShowOverlay() 902 void MediaControlCastButtonElement::tryShowOverlay()
805 { 903 {
806 DCHECK(m_isOverlayButton); 904 DCHECK(m_isOverlayButton);
807 905
808 setIsWanted(true); 906 setIsWanted(true);
809 if (elementFromCenter(*this) != &mediaElement()) { 907 if (elementFromCenter(*this) != &mediaElement()) {
810 setIsWanted(false); 908 setIsWanted(false);
811 return; 909 return;
812 } 910 }
813 911
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 } 950 }
853 951
854 MediaControlCurrentTimeDisplayElement* MediaControlCurrentTimeDisplayElement::cr eate(MediaControls& mediaControls) 952 MediaControlCurrentTimeDisplayElement* MediaControlCurrentTimeDisplayElement::cr eate(MediaControls& mediaControls)
855 { 953 {
856 MediaControlCurrentTimeDisplayElement* element = new MediaControlCurrentTime DisplayElement(mediaControls); 954 MediaControlCurrentTimeDisplayElement* element = new MediaControlCurrentTime DisplayElement(mediaControls);
857 element->setShadowPseudoId(AtomicString("-webkit-media-controls-current-time -display")); 955 element->setShadowPseudoId(AtomicString("-webkit-media-controls-current-time -display"));
858 return element; 956 return element;
859 } 957 }
860 958
861 } // namespace blink 959 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698