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

Side by Side Diff: third_party/WebKit/Source/modules/media_controls/MediaControlsImpl.cpp

Issue 2782373002: Remove MediaControls methods needed for the Cast button (Closed)
Patch Set: Rebased Created 3 years, 8 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) 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 if (media_element.ControlsListInternal()->ShouldHideFullscreen()) { 105 if (media_element.ControlsListInternal()->ShouldHideFullscreen()) {
106 UseCounter::Count(media_element.GetDocument(), 106 UseCounter::Count(media_element.GetDocument(),
107 UseCounter::kHTMLMediaElementControlsListNoFullscreen); 107 UseCounter::kHTMLMediaElementControlsListNoFullscreen);
108 return false; 108 return false;
109 } 109 }
110 110
111 return true; 111 return true;
112 } 112 }
113 113
114 bool ShouldShowCastButton(HTMLMediaElement& media_element) {
115 if (media_element.FastHasAttribute(HTMLNames::disableremoteplaybackAttr))
116 return false;
117
118 // Explicitly do not show cast button when the mediaControlsEnabled setting is
119 // false to make sure the overlay does not appear.
120 Document& document = media_element.GetDocument();
121 if (document.GetSettings() &&
122 !document.GetSettings()->GetMediaControlsEnabled())
123 return false;
124
125 // The page disabled the button via the attribute.
126 if (media_element.ControlsListInternal()->ShouldHideRemotePlayback()) {
127 UseCounter::Count(
128 media_element.GetDocument(),
129 UseCounter::kHTMLMediaElementControlsListNoRemotePlayback);
130 return false;
131 }
132
133 return media_element.HasRemoteRoutes();
134 }
135
136 bool PreferHiddenVolumeControls(const Document& document) { 114 bool PreferHiddenVolumeControls(const Document& document) {
137 return !document.GetSettings() || 115 return !document.GetSettings() ||
138 document.GetSettings()->GetPreferHiddenVolumeControls(); 116 document.GetSettings()->GetPreferHiddenVolumeControls();
139 } 117 }
140 118
141 } // anonymous namespace 119 } // anonymous namespace
142 120
143 class MediaControlsImpl::BatchedControlUpdate { 121 class MediaControlsImpl::BatchedControlUpdate {
144 WTF_MAKE_NONCOPYABLE(BatchedControlUpdate); 122 WTF_MAKE_NONCOPYABLE(BatchedControlUpdate);
145 STACK_ALLOCATED(); 123 STACK_ALLOCATED();
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 track->setMode(TextTrack::DisabledKeyword()); 602 track->setMode(TextTrack::DisabledKeyword());
625 } 603 }
626 } 604 }
627 605
628 void MediaControlsImpl::RefreshCastButtonVisibility() { 606 void MediaControlsImpl::RefreshCastButtonVisibility() {
629 RefreshCastButtonVisibilityWithoutUpdate(); 607 RefreshCastButtonVisibilityWithoutUpdate();
630 BatchedControlUpdate batch(this); 608 BatchedControlUpdate batch(this);
631 } 609 }
632 610
633 void MediaControlsImpl::RefreshCastButtonVisibilityWithoutUpdate() { 611 void MediaControlsImpl::RefreshCastButtonVisibilityWithoutUpdate() {
634 if (!ShouldShowCastButton(MediaElement())) { 612 cast_button_->SetIsWanted(MediaElement().ShouldShowControls());
635 cast_button_->SetIsWanted(false); 613 overlay_cast_button_->SetIsWanted(!MediaElement().ShouldShowControls());
636 overlay_cast_button_->SetIsWanted(false);
637 return;
638 }
639
640 // The reason for the autoplay test is that some pages (e.g. vimeo.com) have
641 // an autoplay background video, which doesn't autoplay on Chrome for Android
642 // (we prevent it) so starts paused. In such cases we don't want to
643 // automatically show the cast button, since it looks strange and is unlikely
644 // to correspond with anything the user wants to do. If a user does want to
645 // cast a paused autoplay video then they can still do so by touching or
646 // clicking on the video, which will cause the cast button to appear.
647 if (!MediaElement().ShouldShowControls() && !MediaElement().Autoplay() &&
648 MediaElement().paused()) {
649 // Note that this is a case where we add the overlay cast button
650 // without wanting the panel cast button. We depend on the fact
651 // that computeWhichControlsFit() won't change overlay cast button
652 // visibility in the case where the cast button isn't wanted.
653 // We don't call compute...() here, but it will be called as
654 // non-cast changes (e.g., resize) occur. If the panel button
655 // is shown, however, compute...() will take control of the
656 // overlay cast button if it needs to hide it from the panel.
657 overlay_cast_button_->TryShowOverlay();
658 cast_button_->SetIsWanted(false);
659 } else if (MediaElement().ShouldShowControls()) {
660 overlay_cast_button_->SetIsWanted(false);
661 cast_button_->SetIsWanted(true);
662 }
663 } 614 }
664 615
665 void MediaControlsImpl::ShowOverlayCastButtonIfNeeded() { 616 void MediaControlsImpl::ShowOverlayCastButtonIfNeeded() {
666 if (MediaElement().ShouldShowControls() || 617 if (MediaElement().ShouldShowControls())
667 !ShouldShowCastButton(MediaElement()))
668 return; 618 return;
669 619
670 overlay_cast_button_->TryShowOverlay(); 620 overlay_cast_button_->SetIsWanted(true);
671 ResetHideMediaControlsTimer(); 621 ResetHideMediaControlsTimer();
672 } 622 }
673 623
674 void MediaControlsImpl::EnterFullscreen() { 624 void MediaControlsImpl::EnterFullscreen() {
675 Fullscreen::RequestFullscreen(MediaElement()); 625 Fullscreen::RequestFullscreen(MediaElement());
676 } 626 }
677 627
678 void MediaControlsImpl::ExitFullscreen() { 628 void MediaControlsImpl::ExitFullscreen() {
679 Fullscreen::ExitFullscreen(GetDocument()); 629 Fullscreen::ExitFullscreen(GetDocument());
680 } 630 }
681 631
682 void MediaControlsImpl::StartedCasting() {
683 cast_button_->SetIsPlayingRemotely(true);
684 overlay_cast_button_->SetIsPlayingRemotely(true);
685 }
686
687 void MediaControlsImpl::StoppedCasting() {
688 cast_button_->SetIsPlayingRemotely(false);
689 overlay_cast_button_->SetIsPlayingRemotely(false);
690 }
691
692 void MediaControlsImpl::DefaultEventHandler(Event* event) { 632 void MediaControlsImpl::DefaultEventHandler(Event* event) {
693 HTMLDivElement::DefaultEventHandler(event); 633 HTMLDivElement::DefaultEventHandler(event);
694 634
695 // Do not handle events to not interfere with the rest of the page if no 635 // Do not handle events to not interfere with the rest of the page if no
696 // controls should be visible. 636 // controls should be visible.
697 if (!MediaElement().ShouldShowControls()) 637 if (!MediaElement().ShouldShowControls())
698 return; 638 return;
699 639
700 // Add IgnoreControlsHover to m_hideTimerBehaviorFlags when we see a touch 640 // Add IgnoreControlsHover to m_hideTimerBehaviorFlags when we see a touch
701 // event, to allow the hide-timer to do the right thing when it fires. 641 // event, to allow the hide-timer to do the right thing when it fires.
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 visitor->Trace(cast_button_); 1070 visitor->Trace(cast_button_);
1131 visitor->Trace(overlay_cast_button_); 1071 visitor->Trace(overlay_cast_button_);
1132 visitor->Trace(media_event_listener_); 1072 visitor->Trace(media_event_listener_);
1133 visitor->Trace(window_event_listener_); 1073 visitor->Trace(window_event_listener_);
1134 visitor->Trace(orientation_lock_delegate_); 1074 visitor->Trace(orientation_lock_delegate_);
1135 MediaControls::Trace(visitor); 1075 MediaControls::Trace(visitor);
1136 HTMLDivElement::Trace(visitor); 1076 HTMLDivElement::Trace(visitor);
1137 } 1077 }
1138 1078
1139 } // namespace blink 1079 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698