| OLD | NEW |
| 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 Loading... |
| 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 LayoutObject* MediaControlsImpl::ContainerLayoutObject() { | 466 LayoutObject* MediaControlsImpl::ContainerLayoutObject() { |
| 489 return GetLayoutObject(); | 467 return GetLayoutObject(); |
| 490 } | 468 } |
| 491 | 469 |
| 492 void MediaControlsImpl::Show() { | 470 void MediaControlsImpl::Show() { |
| 493 MakeOpaque(); | 471 MakeOpaque(); |
| 494 panel_->SetIsWanted(true); | 472 panel_->SetIsWanted(true); |
| 495 panel_->SetIsDisplayed(true); | 473 panel_->SetIsDisplayed(true); |
| 496 if (overlay_play_button_) | 474 if (overlay_play_button_) |
| 497 overlay_play_button_->UpdateDisplayType(); | 475 overlay_play_button_->UpdateDisplayType(); |
| 476 RefreshCastButtonVisibility(); |
| 498 } | 477 } |
| 499 | 478 |
| 500 void MediaControlsImpl::Hide() { | 479 void MediaControlsImpl::Hide() { |
| 501 panel_->SetIsWanted(false); | 480 panel_->SetIsWanted(false); |
| 502 panel_->SetIsDisplayed(false); | 481 panel_->SetIsDisplayed(false); |
| 503 if (overlay_play_button_) | 482 if (overlay_play_button_) |
| 504 overlay_play_button_->SetIsWanted(false); | 483 overlay_play_button_->SetIsWanted(false); |
| 505 } | 484 } |
| 506 | 485 |
| 507 bool MediaControlsImpl::IsVisible() const { | 486 bool MediaControlsImpl::IsVisible() const { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 track->setMode(TextTrack::DisabledKeyword()); | 603 track->setMode(TextTrack::DisabledKeyword()); |
| 625 } | 604 } |
| 626 } | 605 } |
| 627 | 606 |
| 628 void MediaControlsImpl::RefreshCastButtonVisibility() { | 607 void MediaControlsImpl::RefreshCastButtonVisibility() { |
| 629 RefreshCastButtonVisibilityWithoutUpdate(); | 608 RefreshCastButtonVisibilityWithoutUpdate(); |
| 630 BatchedControlUpdate batch(this); | 609 BatchedControlUpdate batch(this); |
| 631 } | 610 } |
| 632 | 611 |
| 633 void MediaControlsImpl::RefreshCastButtonVisibilityWithoutUpdate() { | 612 void MediaControlsImpl::RefreshCastButtonVisibilityWithoutUpdate() { |
| 634 if (!ShouldShowCastButton(MediaElement())) { | 613 cast_button_->SetIsWanted(MediaElement().ShouldShowControls()); |
| 635 cast_button_->SetIsWanted(false); | 614 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 } | 615 } |
| 664 | 616 |
| 665 void MediaControlsImpl::ShowOverlayCastButtonIfNeeded() { | 617 void MediaControlsImpl::ShowOverlayCastButtonIfNeeded() { |
| 666 if (MediaElement().ShouldShowControls() || | 618 if (MediaElement().ShouldShowControls()) |
| 667 !ShouldShowCastButton(MediaElement())) | |
| 668 return; | 619 return; |
| 669 | 620 |
| 670 overlay_cast_button_->TryShowOverlay(); | 621 overlay_cast_button_->SetIsWanted(true); |
| 671 ResetHideMediaControlsTimer(); | 622 ResetHideMediaControlsTimer(); |
| 672 } | 623 } |
| 673 | 624 |
| 674 void MediaControlsImpl::EnterFullscreen() { | 625 void MediaControlsImpl::EnterFullscreen() { |
| 675 Fullscreen::RequestFullscreen(MediaElement()); | 626 Fullscreen::RequestFullscreen(MediaElement()); |
| 676 } | 627 } |
| 677 | 628 |
| 678 void MediaControlsImpl::ExitFullscreen() { | 629 void MediaControlsImpl::ExitFullscreen() { |
| 679 Fullscreen::ExitFullscreen(GetDocument()); | 630 Fullscreen::ExitFullscreen(GetDocument()); |
| 680 } | 631 } |
| 681 | 632 |
| 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) { | 633 void MediaControlsImpl::DefaultEventHandler(Event* event) { |
| 693 HTMLDivElement::DefaultEventHandler(event); | 634 HTMLDivElement::DefaultEventHandler(event); |
| 694 | 635 |
| 695 // Do not handle events to not interfere with the rest of the page if no | 636 // Do not handle events to not interfere with the rest of the page if no |
| 696 // controls should be visible. | 637 // controls should be visible. |
| 697 if (!MediaElement().ShouldShowControls()) | 638 if (!MediaElement().ShouldShowControls()) |
| 698 return; | 639 return; |
| 699 | 640 |
| 700 // Add IgnoreControlsHover to m_hideTimerBehaviorFlags when we see a touch | 641 // 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. | 642 // 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 Loading... |
| 1130 visitor->Trace(cast_button_); | 1071 visitor->Trace(cast_button_); |
| 1131 visitor->Trace(overlay_cast_button_); | 1072 visitor->Trace(overlay_cast_button_); |
| 1132 visitor->Trace(media_event_listener_); | 1073 visitor->Trace(media_event_listener_); |
| 1133 visitor->Trace(window_event_listener_); | 1074 visitor->Trace(window_event_listener_); |
| 1134 visitor->Trace(orientation_lock_delegate_); | 1075 visitor->Trace(orientation_lock_delegate_); |
| 1135 MediaControls::Trace(visitor); | 1076 MediaControls::Trace(visitor); |
| 1136 HTMLDivElement::Trace(visitor); | 1077 HTMLDivElement::Trace(visitor); |
| 1137 } | 1078 } |
| 1138 | 1079 |
| 1139 } // namespace blink | 1080 } // namespace blink |
| OLD | NEW |