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

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, 4 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 return mediaElement().muted() ? "Unmute" : "Mute";
307 }
308
305 // ---------------------------- 309 // ----------------------------
306 310
307 MediaControlPlayButtonElement::MediaControlPlayButtonElement(MediaControls& medi aControls) 311 MediaControlPlayButtonElement::MediaControlPlayButtonElement(MediaControls& medi aControls)
308 : MediaControlInputElement(mediaControls, MediaPlayButton) 312 : MediaControlInputElement(mediaControls, MediaPlayButton)
309 { 313 {
310 } 314 }
311 315
312 MediaControlPlayButtonElement* MediaControlPlayButtonElement::create(MediaContro ls& mediaControls) 316 MediaControlPlayButtonElement* MediaControlPlayButtonElement::create(MediaContro ls& mediaControls)
313 { 317 {
314 MediaControlPlayButtonElement* button = new MediaControlPlayButtonElement(me diaControls); 318 MediaControlPlayButtonElement* button = new MediaControlPlayButtonElement(me diaControls);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 404
401 void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType() 405 void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType()
402 { 406 {
403 bool captionsVisible = mediaElement().textTracksVisible(); 407 bool captionsVisible = mediaElement().textTracksVisible();
404 setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowCl osedCaptionsButton); 408 setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowCl osedCaptionsButton);
405 } 409 }
406 410
407 void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* e vent) 411 void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* e vent)
408 { 412 {
409 if (event->type() == EventTypeNames::click) { 413 if (event->type() == EventTypeNames::click) {
414 if (mediaControls().overflowMenuVisible())
415 mediaControls().toggleOverflowMenu();
410 mediaControls().toggleTextTrackList(); 416 mediaControls().toggleTextTrackList();
411 updateDisplayType(); 417 updateDisplayType();
412 event->setDefaultHandled(); 418 event->setDefaultHandled();
413 } 419 }
414 420
415 HTMLInputElement::defaultEventHandler(event); 421 HTMLInputElement::defaultEventHandler(event);
416 } 422 }
417 423
418 // ---------------------------- 424 // ----------------------------
419 425
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 TextTrackList* trackList = mediaElement().textTracks(); 553 TextTrackList* trackList = mediaElement().textTracks();
548 for (unsigned i = 0; i < trackList->length(); i++) { 554 for (unsigned i = 0; i < trackList->length(); i++) {
549 TextTrack* track = trackList->anonymousIndexedGetter(i); 555 TextTrack* track = trackList->anonymousIndexedGetter(i);
550 if (!track->canBeRendered()) 556 if (!track->canBeRendered())
551 continue; 557 continue;
552 appendChild(createTextTrackListItem(track)); 558 appendChild(createTextTrackListItem(track));
553 } 559 }
554 } 560 }
555 561
556 // ---------------------------- 562 // ----------------------------
563 MediaControlOverflowMenu::MediaControlOverflowMenu(MediaControls& mediaControls)
564 : MediaControlInputElement(mediaControls, MediaShowClosedCaptionsButton)
565 {
566 }
567
568 MediaControlOverflowMenu* MediaControlOverflowMenu::create(MediaControls& mediaC ontrols)
569 {
570 MediaControlOverflowMenu* button = new MediaControlOverflowMenu(mediaControl s);
571 button->ensureUserAgentShadowRoot();
572 button->setType(InputTypeNames::button);
573 button->setShadowPseudoId(AtomicString("-webkit-overflow-menu-button"));
574 button->setIsWanted(false);
575 return button;
576 }
577
578 void MediaControlOverflowMenu::defaultEventHandler(Event* event)
579 {
580 if (event->type() == EventTypeNames::click) {
581 mediaControls().toggleOverflowMenu();
582 event->setDefaultHandled();
583 }
584
585 HTMLInputElement::defaultEventHandler(event);
586 }
587
588 // ----------------------------
589 MediaControlOverflowMenuListElement::MediaControlOverflowMenuListElement(MediaCo ntrols& mediaControls)
590 : MediaControlDivElement(mediaControls, MediaShowClosedCaptionsButton)
591 {
592 }
593
594 MediaControlOverflowMenuListElement* MediaControlOverflowMenuListElement::create (MediaControls& mediaControls)
595 {
596 MediaControlOverflowMenuListElement* element = new MediaControlOverflowMenuL istElement(mediaControls);
597 element->setIsWanted(false);
598 element->setShadowPseudoId(AtomicString("-internal-media-controls-overflow-m enu-list"));
599 return element;
600 }
601
602 void MediaControlOverflowMenuListElement::setOverflowMenuControls(std::set<Media ControlElementType> controls)
603 {
604 removeChildren(OmitSubtreeModifiedEvent);
605 // A list of all buttons that can appear in the overflow menu.
606 std::vector<MediaControlInputElement*> potentialControls = mediaControls().g etOverflowMenuButtons();
607
608 for (unsigned i = 0; i < potentialControls.size(); i++) {
609 MediaControlInputElement* element = potentialControls.at(i);
610 // Of all of the possible buttons that can be shown in the overflow menu ,
611 // we include only the buttons that didn't fit within the media player.
612 if (controls.count(element->displayType())) {
613 HTMLLabelElement* item = HTMLLabelElement::create(document());
614 item->setShadowPseudoId(AtomicString("-internal-media-controls-overf low-menu-list-item"));
615 item->appendChild(element);
616 item->appendChild(Text::create(document(), element->getText()));
617 appendChild(item);
618 }
619 }
620 }
621
622 void MediaControlOverflowMenuListElement::setVisible(bool visible)
623 {
624 setIsWanted(visible);
625 }
626
627 void MediaControlOverflowMenuListElement::defaultEventHandler(Event* event)
628 {
629 if (event->type() == EventTypeNames::click)
630 event->setDefaultHandled();
631
632 MediaControlDivElement::defaultEventHandler(event);
633 }
634
635 // ----------------------------
557 636
558 MediaControlTimelineElement::MediaControlTimelineElement(MediaControls& mediaCon trols) 637 MediaControlTimelineElement::MediaControlTimelineElement(MediaControls& mediaCon trols)
559 : MediaControlInputElement(mediaControls, MediaSlider) 638 : MediaControlInputElement(mediaControls, MediaSlider)
560 { 639 {
561 } 640 }
562 641
563 MediaControlTimelineElement* MediaControlTimelineElement::create(MediaControls& mediaControls) 642 MediaControlTimelineElement* MediaControlTimelineElement::create(MediaControls& mediaControls)
564 { 643 {
565 MediaControlTimelineElement* timeline = new MediaControlTimelineElement(medi aControls); 644 MediaControlTimelineElement* timeline = new MediaControlTimelineElement(medi aControls);
566 timeline->ensureUserAgentShadowRoot(); 645 timeline->ensureUserAgentShadowRoot();
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 } 873 }
795 } else { 874 } else {
796 if (m_isOverlayButton) { 875 if (m_isOverlayButton) {
797 setDisplayType(MediaOverlayCastOffButton); 876 setDisplayType(MediaOverlayCastOffButton);
798 } else { 877 } else {
799 setDisplayType(MediaCastOffButton); 878 setDisplayType(MediaCastOffButton);
800 } 879 }
801 } 880 }
802 } 881 }
803 882
883 String MediaControlCastButtonElement::getText()
884 {
885 return mediaElement().isPlayingRemotely() ? "Stop casting" : "Cast";
whywhat 2016/08/19 23:56:55 hm, it's not only "Stop casting", one could contro
kdsilva 2016/08/24 05:33:26 Acknowledged. I'll reach out to Rachel about this.
886 }
887
804 void MediaControlCastButtonElement::tryShowOverlay() 888 void MediaControlCastButtonElement::tryShowOverlay()
805 { 889 {
806 DCHECK(m_isOverlayButton); 890 DCHECK(m_isOverlayButton);
807 891
808 setIsWanted(true); 892 setIsWanted(true);
809 if (elementFromCenter(*this) != &mediaElement()) { 893 if (elementFromCenter(*this) != &mediaElement()) {
810 setIsWanted(false); 894 setIsWanted(false);
811 return; 895 return;
812 } 896 }
813 897
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 } 936 }
853 937
854 MediaControlCurrentTimeDisplayElement* MediaControlCurrentTimeDisplayElement::cr eate(MediaControls& mediaControls) 938 MediaControlCurrentTimeDisplayElement* MediaControlCurrentTimeDisplayElement::cr eate(MediaControls& mediaControls)
855 { 939 {
856 MediaControlCurrentTimeDisplayElement* element = new MediaControlCurrentTime DisplayElement(mediaControls); 940 MediaControlCurrentTimeDisplayElement* element = new MediaControlCurrentTime DisplayElement(mediaControls);
857 element->setShadowPseudoId(AtomicString("-webkit-media-controls-current-time -display")); 941 element->setShadowPseudoId(AtomicString("-webkit-media-controls-current-time -display"));
858 return element; 942 return element;
859 } 943 }
860 944
861 } // namespace blink 945 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698