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

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: Removed unused from the header 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 if (media_element.ControlsListInternal()->ShouldHideFullscreen()) { 106 if (media_element.ControlsListInternal()->ShouldHideFullscreen()) {
107 UseCounter::Count(media_element.GetDocument(), 107 UseCounter::Count(media_element.GetDocument(),
108 UseCounter::kHTMLMediaElementControlsListNoFullscreen); 108 UseCounter::kHTMLMediaElementControlsListNoFullscreen);
109 return false; 109 return false;
110 } 110 }
111 111
112 return true; 112 return true;
113 } 113 }
114 114
115 bool ShouldShowCastButton(HTMLMediaElement& media_element) {
116 if (media_element.FastHasAttribute(HTMLNames::disableremoteplaybackAttr))
117 return false;
118
119 // Explicitly do not show cast button when the mediaControlsEnabled setting is
120 // false to make sure the overlay does not appear.
121 Document& document = media_element.GetDocument();
122 if (document.GetSettings() &&
123 !document.GetSettings()->GetMediaControlsEnabled())
124 return false;
125
126 // The page disabled the button via the attribute.
127 if (media_element.ControlsListInternal()->ShouldHideRemotePlayback()) {
128 UseCounter::Count(
129 media_element.GetDocument(),
130 UseCounter::kHTMLMediaElementControlsListNoRemotePlayback);
131 return false;
132 }
133
134 return media_element.HasRemoteRoutes();
135 }
136
137 bool PreferHiddenVolumeControls(const Document& document) { 115 bool PreferHiddenVolumeControls(const Document& document) {
138 return !document.GetSettings() || 116 return !document.GetSettings() ||
139 document.GetSettings()->GetPreferHiddenVolumeControls(); 117 document.GetSettings()->GetPreferHiddenVolumeControls();
140 } 118 }
141 119
142 } // anonymous namespace 120 } // anonymous namespace
143 121
144 class MediaControlsImpl::BatchedControlUpdate { 122 class MediaControlsImpl::BatchedControlUpdate {
145 WTF_MAKE_NONCOPYABLE(BatchedControlUpdate); 123 WTF_MAKE_NONCOPYABLE(BatchedControlUpdate);
146 STACK_ALLOCATED(); 124 STACK_ALLOCATED();
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 LayoutObject* MediaControlsImpl::ContainerLayoutObject() { 465 LayoutObject* MediaControlsImpl::ContainerLayoutObject() {
488 return GetLayoutObject(); 466 return GetLayoutObject();
489 } 467 }
490 468
491 void MediaControlsImpl::Show() { 469 void MediaControlsImpl::Show() {
492 MakeOpaque(); 470 MakeOpaque();
493 panel_->SetIsWanted(true); 471 panel_->SetIsWanted(true);
494 panel_->SetIsDisplayed(true); 472 panel_->SetIsDisplayed(true);
495 if (overlay_play_button_) 473 if (overlay_play_button_)
496 overlay_play_button_->UpdateDisplayType(); 474 overlay_play_button_->UpdateDisplayType();
475 RefreshCastButtonVisibility();
497 } 476 }
498 477
499 void MediaControlsImpl::Hide() { 478 void MediaControlsImpl::Hide() {
500 panel_->SetIsWanted(false); 479 panel_->SetIsWanted(false);
501 panel_->SetIsDisplayed(false); 480 panel_->SetIsDisplayed(false);
502 if (overlay_play_button_) 481 if (overlay_play_button_)
503 overlay_play_button_->SetIsWanted(false); 482 overlay_play_button_->SetIsWanted(false);
504 } 483 }
505 484
506 bool MediaControlsImpl::IsVisible() const { 485 bool MediaControlsImpl::IsVisible() const {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 track->setMode(TextTrack::DisabledKeyword()); 602 track->setMode(TextTrack::DisabledKeyword());
624 } 603 }
625 } 604 }
626 605
627 void MediaControlsImpl::RefreshCastButtonVisibility() { 606 void MediaControlsImpl::RefreshCastButtonVisibility() {
628 RefreshCastButtonVisibilityWithoutUpdate(); 607 RefreshCastButtonVisibilityWithoutUpdate();
629 BatchedControlUpdate batch(this); 608 BatchedControlUpdate batch(this);
630 } 609 }
631 610
632 void MediaControlsImpl::RefreshCastButtonVisibilityWithoutUpdate() { 611 void MediaControlsImpl::RefreshCastButtonVisibilityWithoutUpdate() {
633 if (!ShouldShowCastButton(MediaElement())) { 612 MediaControlCastButtonElement* try_show_button = cast_button_.Get();
634 cast_button_->SetIsWanted(false); 613 MediaControlCastButtonElement* hide_button = overlay_cast_button_.Get();
635 overlay_cast_button_->SetIsWanted(false); 614 if (!MediaElement().ShouldShowControls()) {
636 return; 615 try_show_button = overlay_cast_button_.Get();
616 hide_button = cast_button_.Get();
637 } 617 }
638 618 hide_button->SetIsWanted(false);
639 // The reason for the autoplay test is that some pages (e.g. vimeo.com) have 619 try_show_button->SetIsWanted(try_show_button->ShouldShow());
640 // an autoplay background video, which doesn't autoplay on Chrome for Android 620 if (try_show_button->IsWanted())
641 // (we prevent it) so starts paused. In such cases we don't want to 621 try_show_button->UpdateDisplayType();
642 // automatically show the cast button, since it looks strange and is unlikely
643 // to correspond with anything the user wants to do. If a user does want to
644 // cast a paused autoplay video then they can still do so by touching or
645 // clicking on the video, which will cause the cast button to appear.
646 if (!MediaElement().ShouldShowControls() && !MediaElement().Autoplay() &&
647 MediaElement().paused()) {
648 // Note that this is a case where we add the overlay cast button
649 // without wanting the panel cast button. We depend on the fact
650 // that computeWhichControlsFit() won't change overlay cast button
651 // visibility in the case where the cast button isn't wanted.
652 // We don't call compute...() here, but it will be called as
653 // non-cast changes (e.g., resize) occur. If the panel button
654 // is shown, however, compute...() will take control of the
655 // overlay cast button if it needs to hide it from the panel.
656 overlay_cast_button_->TryShowOverlay();
657 cast_button_->SetIsWanted(false);
658 } else if (MediaElement().ShouldShowControls()) {
659 overlay_cast_button_->SetIsWanted(false);
660 cast_button_->SetIsWanted(true);
661 }
662 } 622 }
663 623
664 void MediaControlsImpl::ShowOverlayCastButtonIfNeeded() { 624 void MediaControlsImpl::ShowOverlayCastButtonIfNeeded() {
665 if (MediaElement().ShouldShowControls() || 625 if (MediaElement().ShouldShowControls() ||
666 !ShouldShowCastButton(MediaElement())) 626 !overlay_cast_button_->ShouldShow()) {
667 return; 627 return;
628 }
668 629
669 overlay_cast_button_->TryShowOverlay(); 630 overlay_cast_button_->SetIsWanted(true);
670 ResetHideMediaControlsTimer(); 631 ResetHideMediaControlsTimer();
671 } 632 }
672 633
673 void MediaControlsImpl::EnterFullscreen() { 634 void MediaControlsImpl::EnterFullscreen() {
674 Fullscreen::RequestFullscreen(MediaElement()); 635 Fullscreen::RequestFullscreen(MediaElement());
675 } 636 }
676 637
677 void MediaControlsImpl::ExitFullscreen() { 638 void MediaControlsImpl::ExitFullscreen() {
678 Fullscreen::ExitFullscreen(GetDocument()); 639 Fullscreen::ExitFullscreen(GetDocument());
679 } 640 }
680 641
681 void MediaControlsImpl::StartedCasting() {
682 cast_button_->SetIsPlayingRemotely(true);
683 overlay_cast_button_->SetIsPlayingRemotely(true);
684 }
685
686 void MediaControlsImpl::StoppedCasting() {
687 cast_button_->SetIsPlayingRemotely(false);
688 overlay_cast_button_->SetIsPlayingRemotely(false);
689 }
690
691 void MediaControlsImpl::DefaultEventHandler(Event* event) { 642 void MediaControlsImpl::DefaultEventHandler(Event* event) {
692 HTMLDivElement::DefaultEventHandler(event); 643 HTMLDivElement::DefaultEventHandler(event);
693 644
694 // Do not handle events to not interfere with the rest of the page if no 645 // Do not handle events to not interfere with the rest of the page if no
695 // controls should be visible. 646 // controls should be visible.
696 if (!MediaElement().ShouldShowControls()) 647 if (!MediaElement().ShouldShowControls())
697 return; 648 return;
698 649
699 // Add IgnoreControlsHover to m_hideTimerBehaviorFlags when we see a touch 650 // Add IgnoreControlsHover to m_hideTimerBehaviorFlags when we see a touch
700 // event, to allow the hide-timer to do the right thing when it fires. 651 // 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
1129 visitor->Trace(cast_button_); 1080 visitor->Trace(cast_button_);
1130 visitor->Trace(overlay_cast_button_); 1081 visitor->Trace(overlay_cast_button_);
1131 visitor->Trace(media_event_listener_); 1082 visitor->Trace(media_event_listener_);
1132 visitor->Trace(window_event_listener_); 1083 visitor->Trace(window_event_listener_);
1133 visitor->Trace(orientation_lock_delegate_); 1084 visitor->Trace(orientation_lock_delegate_);
1134 MediaControls::Trace(visitor); 1085 MediaControls::Trace(visitor);
1135 HTMLDivElement::Trace(visitor); 1086 HTMLDivElement::Trace(visitor);
1136 } 1087 }
1137 1088
1138 } // namespace blink 1089 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698