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

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: added more tests 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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 mediaElement().setMuted(!mediaElement().muted()); 293 mediaElement().setMuted(!mediaElement().muted());
294 event->setDefaultHandled(); 294 event->setDefaultHandled();
295 } 295 }
296 296
297 HTMLInputElement::defaultEventHandler(event); 297 HTMLInputElement::defaultEventHandler(event);
298 } 298 }
299 299
300 void MediaControlMuteButtonElement::updateDisplayType() 300 void MediaControlMuteButtonElement::updateDisplayType()
301 { 301 {
302 setDisplayType(mediaElement().muted() ? MediaUnMuteButton : MediaMuteButton) ; 302 setDisplayType(mediaElement().muted() ? MediaUnMuteButton : MediaMuteButton) ;
303 updateOverflowString();
liberato (no reviews please) 2016/09/01 18:05:19 would it make sense to call this in setShouldShowB
kdsilva 2016/09/05 14:39:35 That works much better!
304 }
305
306 WebLocalizedString::Name MediaControlMuteButtonElement::getOverflowStringName()
307 {
308 if (mediaElement().muted())
309 return WebLocalizedString::OverflowMenuUnmute;
310 return WebLocalizedString::OverflowMenuMute;
311 }
312
313 MediaControlInputElement* MediaControlMuteButtonElement::createOverflowButton(Me diaControls& mediaControls)
314 {
315 return MediaControlMuteButtonElement::create(mediaControls);
303 } 316 }
304 317
305 // ---------------------------- 318 // ----------------------------
306 319
307 MediaControlPlayButtonElement::MediaControlPlayButtonElement(MediaControls& medi aControls) 320 MediaControlPlayButtonElement::MediaControlPlayButtonElement(MediaControls& medi aControls)
308 : MediaControlInputElement(mediaControls, MediaPlayButton) 321 : MediaControlInputElement(mediaControls, MediaPlayButton)
309 { 322 {
310 } 323 }
311 324
312 MediaControlPlayButtonElement* MediaControlPlayButtonElement::create(MediaContro ls& mediaControls) 325 MediaControlPlayButtonElement* MediaControlPlayButtonElement::create(MediaContro ls& mediaControls)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 413
401 void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType() 414 void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType()
402 { 415 {
403 bool captionsVisible = mediaElement().textTracksVisible(); 416 bool captionsVisible = mediaElement().textTracksVisible();
404 setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowCl osedCaptionsButton); 417 setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowCl osedCaptionsButton);
405 } 418 }
406 419
407 void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* e vent) 420 void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* e vent)
408 { 421 {
409 if (event->type() == EventTypeNames::click) { 422 if (event->type() == EventTypeNames::click) {
423 if (mediaControls().overflowMenuVisible())
mlamouri (slow - plz ping) 2016/09/01 18:29:15 Can you add a comment explaining why you are doing
kdsilva 2016/09/05 14:39:35 Done.
424 mediaControls().toggleOverflowMenu();
410 mediaControls().toggleTextTrackList(); 425 mediaControls().toggleTextTrackList();
411 updateDisplayType(); 426 updateDisplayType();
412 event->setDefaultHandled(); 427 event->setDefaultHandled();
413 } 428 }
414 429
415 HTMLInputElement::defaultEventHandler(event); 430 HTMLInputElement::defaultEventHandler(event);
416 } 431 }
417 432
433 WebLocalizedString::Name MediaControlToggleClosedCaptionsButtonElement::getOverf lowStringName()
434 {
435 return WebLocalizedString::OverflowMenuCaptions;
436 }
437
438 MediaControlInputElement* MediaControlToggleClosedCaptionsButtonElement::createO verflowButton(MediaControls& mediaControls)
439 {
440 return MediaControlToggleClosedCaptionsButtonElement::create(mediaControls);
441 }
442
418 // ---------------------------- 443 // ----------------------------
419 444
420 MediaControlTextTrackListElement::MediaControlTextTrackListElement(MediaControls & mediaControls) 445 MediaControlTextTrackListElement::MediaControlTextTrackListElement(MediaControls & mediaControls)
421 : MediaControlDivElement(mediaControls, MediaTextTrackList) 446 : MediaControlDivElement(mediaControls, MediaTextTrackList)
422 { 447 {
423 } 448 }
424 449
425 MediaControlTextTrackListElement* MediaControlTextTrackListElement::create(Media Controls& mediaControls) 450 MediaControlTextTrackListElement* MediaControlTextTrackListElement::create(Media Controls& mediaControls)
426 { 451 {
427 MediaControlTextTrackListElement* element = new MediaControlTextTrackListEle ment(mediaControls); 452 MediaControlTextTrackListElement* element = new MediaControlTextTrackListEle ment(mediaControls);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 TextTrackList* trackList = mediaElement().textTracks(); 572 TextTrackList* trackList = mediaElement().textTracks();
548 for (unsigned i = 0; i < trackList->length(); i++) { 573 for (unsigned i = 0; i < trackList->length(); i++) {
549 TextTrack* track = trackList->anonymousIndexedGetter(i); 574 TextTrack* track = trackList->anonymousIndexedGetter(i);
550 if (!track->canBeRendered()) 575 if (!track->canBeRendered())
551 continue; 576 continue;
552 appendChild(createTextTrackListItem(track)); 577 appendChild(createTextTrackListItem(track));
553 } 578 }
554 } 579 }
555 580
556 // ---------------------------- 581 // ----------------------------
582 MediaControlOverflowMenuButtonElement::MediaControlOverflowMenuButtonElement(Med iaControls& mediaControls)
583 : MediaControlInputElement(mediaControls, MediaOverflowButton)
584 {
585 }
586
587 MediaControlOverflowMenuButtonElement* MediaControlOverflowMenuButtonElement::cr eate(MediaControls& mediaControls)
588 {
589 MediaControlOverflowMenuButtonElement* button = new MediaControlOverflowMenu ButtonElement(mediaControls);
590 button->ensureUserAgentShadowRoot();
591 button->setType(InputTypeNames::button);
592 button->setShadowPseudoId(AtomicString("-internal-overflow-menu-button"));
593 button->setIsWanted(false);
594 return button;
595 }
596
597 void MediaControlOverflowMenuButtonElement::defaultEventHandler(Event* event)
598 {
599 if (event->type() == EventTypeNames::click) {
600 mediaControls().toggleOverflowMenu();
601 event->setDefaultHandled();
602 }
603
604 HTMLInputElement::defaultEventHandler(event);
605 }
606
607 // ----------------------------
608 MediaControlOverflowMenuListElement::MediaControlOverflowMenuListElement(MediaCo ntrols& mediaControls)
609 : MediaControlDivElement(mediaControls, MediaOverflowList)
610 {
611 }
612
613 MediaControlOverflowMenuListElement* MediaControlOverflowMenuListElement::create (MediaControls& mediaControls)
614 {
615 MediaControlOverflowMenuListElement* element = new MediaControlOverflowMenuL istElement(mediaControls);
616 element->setIsWanted(false);
617 element->setShadowPseudoId(AtomicString("-internal-media-controls-overflow-m enu-list"));
618 return element;
619 }
620
621 void MediaControlOverflowMenuListElement::showOverflowMenu(bool visible)
622 {
623 setIsWanted(visible);
624 }
625
626 void MediaControlOverflowMenuListElement::defaultEventHandler(Event* event)
627 {
628 if (event->type() == EventTypeNames::click)
629 event->setDefaultHandled();
630
631 MediaControlDivElement::defaultEventHandler(event);
632 }
633
634 // ----------------------------
557 635
558 MediaControlTimelineElement::MediaControlTimelineElement(MediaControls& mediaCon trols) 636 MediaControlTimelineElement::MediaControlTimelineElement(MediaControls& mediaCon trols)
559 : MediaControlInputElement(mediaControls, MediaSlider) 637 : MediaControlInputElement(mediaControls, MediaSlider)
560 { 638 {
561 } 639 }
562 640
563 MediaControlTimelineElement* MediaControlTimelineElement::create(MediaControls& mediaControls) 641 MediaControlTimelineElement* MediaControlTimelineElement::create(MediaControls& mediaControls)
564 { 642 {
565 MediaControlTimelineElement* timeline = new MediaControlTimelineElement(medi aControls); 643 MediaControlTimelineElement* timeline = new MediaControlTimelineElement(medi aControls);
566 timeline->ensureUserAgentShadowRoot(); 644 timeline->ensureUserAgentShadowRoot();
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 event->setDefaultHandled(); 809 event->setDefaultHandled();
732 } 810 }
733 HTMLInputElement::defaultEventHandler(event); 811 HTMLInputElement::defaultEventHandler(event);
734 } 812 }
735 813
736 void MediaControlFullscreenButtonElement::setIsFullscreen(bool isFullscreen) 814 void MediaControlFullscreenButtonElement::setIsFullscreen(bool isFullscreen)
737 { 815 {
738 setDisplayType(isFullscreen ? MediaExitFullscreenButton : MediaEnterFullscre enButton); 816 setDisplayType(isFullscreen ? MediaExitFullscreenButton : MediaEnterFullscre enButton);
739 } 817 }
740 818
819 WebLocalizedString::Name MediaControlFullscreenButtonElement::getOverflowStringN ame()
820 {
821 return WebLocalizedString::OverflowMenuFullscreen;
822 }
823 MediaControlInputElement* MediaControlFullscreenButtonElement::createOverflowBut ton(MediaControls& mediaControls)
824 {
825 return MediaControlFullscreenButtonElement::create(mediaControls);
826 }
827
741 // ---------------------------- 828 // ----------------------------
742 829
743 MediaControlCastButtonElement::MediaControlCastButtonElement(MediaControls& medi aControls, bool isOverlayButton) 830 MediaControlCastButtonElement::MediaControlCastButtonElement(MediaControls& medi aControls, bool isOverlayButton)
744 : MediaControlInputElement(mediaControls, MediaCastOnButton), m_isOverlayBut ton(isOverlayButton) 831 : MediaControlInputElement(mediaControls, MediaCastOnButton), m_isOverlayBut ton(isOverlayButton)
745 { 832 {
746 if (m_isOverlayButton) 833 if (m_isOverlayButton)
747 recordMetrics(CastOverlayMetrics::Created); 834 recordMetrics(CastOverlayMetrics::Created);
748 setIsPlayingRemotely(false); 835 setIsPlayingRemotely(false);
749 } 836 }
750 837
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 } 881 }
795 } else { 882 } else {
796 if (m_isOverlayButton) { 883 if (m_isOverlayButton) {
797 setDisplayType(MediaOverlayCastOffButton); 884 setDisplayType(MediaOverlayCastOffButton);
798 } else { 885 } else {
799 setDisplayType(MediaCastOffButton); 886 setDisplayType(MediaCastOffButton);
800 } 887 }
801 } 888 }
802 } 889 }
803 890
891 WebLocalizedString::Name MediaControlCastButtonElement::getOverflowStringName()
892 {
893 if (mediaElement().isPlayingRemotely())
894 return WebLocalizedString::OverflowMenuStopCast;
895 return WebLocalizedString::OverflowMenuCast;
896 }
897
804 void MediaControlCastButtonElement::tryShowOverlay() 898 void MediaControlCastButtonElement::tryShowOverlay()
805 { 899 {
806 DCHECK(m_isOverlayButton); 900 DCHECK(m_isOverlayButton);
807 901
808 setIsWanted(true); 902 setIsWanted(true);
809 if (elementFromCenter(*this) != &mediaElement()) { 903 if (elementFromCenter(*this) != &mediaElement()) {
810 setIsWanted(false); 904 setIsWanted(false);
811 return; 905 return;
812 } 906 }
813 907
814 DCHECK(isWanted()); 908 DCHECK(isWanted());
815 if (!m_showUseCounted) { 909 if (!m_showUseCounted) {
816 m_showUseCounted = true; 910 m_showUseCounted = true;
817 recordMetrics(CastOverlayMetrics::Shown); 911 recordMetrics(CastOverlayMetrics::Shown);
818 } 912 }
819 } 913 }
820 914
821 bool MediaControlCastButtonElement::keepEventInNode(Event* event) 915 bool MediaControlCastButtonElement::keepEventInNode(Event* event)
822 { 916 {
823 return isUserInteractionEvent(event); 917 return isUserInteractionEvent(event);
824 } 918 }
825 919
826 void MediaControlCastButtonElement::recordMetrics(CastOverlayMetrics metric) 920 void MediaControlCastButtonElement::recordMetrics(CastOverlayMetrics metric)
827 { 921 {
828 DCHECK(m_isOverlayButton); 922 DCHECK(m_isOverlayButton);
829 DEFINE_STATIC_LOCAL(EnumerationHistogram, overlayHistogram, ("Cast.Sender.Ov erlay", static_cast<int>(CastOverlayMetrics::Count))); 923 DEFINE_STATIC_LOCAL(EnumerationHistogram, overlayHistogram, ("Cast.Sender.Ov erlay", static_cast<int>(CastOverlayMetrics::Count)));
830 overlayHistogram.count(static_cast<int>(metric)); 924 overlayHistogram.count(static_cast<int>(metric));
831 } 925 }
832 926
927 MediaControlInputElement* MediaControlCastButtonElement::createOverflowButton(Me diaControls& mediaControls)
928 {
929 return MediaControlCastButtonElement::create(mediaControls, false);
930 }
931
833 // ---------------------------- 932 // ----------------------------
834 933
835 MediaControlTimeRemainingDisplayElement::MediaControlTimeRemainingDisplayElement (MediaControls& mediaControls) 934 MediaControlTimeRemainingDisplayElement::MediaControlTimeRemainingDisplayElement (MediaControls& mediaControls)
836 : MediaControlTimeDisplayElement(mediaControls, MediaTimeRemainingDisplay) 935 : MediaControlTimeDisplayElement(mediaControls, MediaTimeRemainingDisplay)
837 { 936 {
838 } 937 }
839 938
840 MediaControlTimeRemainingDisplayElement* MediaControlTimeRemainingDisplayElement ::create(MediaControls& mediaControls) 939 MediaControlTimeRemainingDisplayElement* MediaControlTimeRemainingDisplayElement ::create(MediaControls& mediaControls)
841 { 940 {
842 MediaControlTimeRemainingDisplayElement* element = new MediaControlTimeRemai ningDisplayElement(mediaControls); 941 MediaControlTimeRemainingDisplayElement* element = new MediaControlTimeRemai ningDisplayElement(mediaControls);
843 element->setShadowPseudoId(AtomicString("-webkit-media-controls-time-remaini ng-display")); 942 element->setShadowPseudoId(AtomicString("-webkit-media-controls-time-remaini ng-display"));
844 return element; 943 return element;
845 } 944 }
846 945
847 // ---------------------------- 946 // ----------------------------
848 947
849 MediaControlCurrentTimeDisplayElement::MediaControlCurrentTimeDisplayElement(Med iaControls& mediaControls) 948 MediaControlCurrentTimeDisplayElement::MediaControlCurrentTimeDisplayElement(Med iaControls& mediaControls)
850 : MediaControlTimeDisplayElement(mediaControls, MediaCurrentTimeDisplay) 949 : MediaControlTimeDisplayElement(mediaControls, MediaCurrentTimeDisplay)
851 { 950 {
852 } 951 }
853 952
854 MediaControlCurrentTimeDisplayElement* MediaControlCurrentTimeDisplayElement::cr eate(MediaControls& mediaControls) 953 MediaControlCurrentTimeDisplayElement* MediaControlCurrentTimeDisplayElement::cr eate(MediaControls& mediaControls)
855 { 954 {
856 MediaControlCurrentTimeDisplayElement* element = new MediaControlCurrentTime DisplayElement(mediaControls); 955 MediaControlCurrentTimeDisplayElement* element = new MediaControlCurrentTime DisplayElement(mediaControls);
857 element->setShadowPseudoId(AtomicString("-webkit-media-controls-current-time -display")); 956 element->setShadowPseudoId(AtomicString("-webkit-media-controls-current-time -display"));
858 return element; 957 return element;
859 } 958 }
860 959
861 } // namespace blink 960 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698