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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 #include "core/html/track/TextTrackList.h" | 45 #include "core/html/track/TextTrackList.h" |
46 #include "core/layout/LayoutObject.h" | 46 #include "core/layout/LayoutObject.h" |
47 #include "core/layout/LayoutTheme.h" | 47 #include "core/layout/LayoutTheme.h" |
48 #include "core/page/SpatialNavigation.h" | 48 #include "core/page/SpatialNavigation.h" |
49 #include "core/resize_observer/ResizeObserver.h" | 49 #include "core/resize_observer/ResizeObserver.h" |
50 #include "core/resize_observer/ResizeObserverEntry.h" | 50 #include "core/resize_observer/ResizeObserverEntry.h" |
51 #include "modules/media_controls/MediaControlsMediaEventListener.h" | 51 #include "modules/media_controls/MediaControlsMediaEventListener.h" |
52 #include "modules/media_controls/MediaControlsOrientationLockDelegate.h" | 52 #include "modules/media_controls/MediaControlsOrientationLockDelegate.h" |
53 #include "modules/media_controls/MediaControlsRotateToFullscreenDelegate.h" | 53 #include "modules/media_controls/MediaControlsRotateToFullscreenDelegate.h" |
54 #include "modules/media_controls/MediaControlsWindowEventListener.h" | 54 #include "modules/media_controls/MediaControlsWindowEventListener.h" |
55 #include "modules/media_controls/MediaDownloadInProductHelpManager.h" | |
55 #include "modules/media_controls/elements/MediaControlCastButtonElement.h" | 56 #include "modules/media_controls/elements/MediaControlCastButtonElement.h" |
56 #include "modules/media_controls/elements/MediaControlCurrentTimeDisplayElement. h" | 57 #include "modules/media_controls/elements/MediaControlCurrentTimeDisplayElement. h" |
57 #include "modules/media_controls/elements/MediaControlDownloadButtonElement.h" | 58 #include "modules/media_controls/elements/MediaControlDownloadButtonElement.h" |
58 #include "modules/media_controls/elements/MediaControlFullscreenButtonElement.h" | 59 #include "modules/media_controls/elements/MediaControlFullscreenButtonElement.h" |
59 #include "modules/media_controls/elements/MediaControlMuteButtonElement.h" | 60 #include "modules/media_controls/elements/MediaControlMuteButtonElement.h" |
60 #include "modules/media_controls/elements/MediaControlOverflowMenuButtonElement. h" | 61 #include "modules/media_controls/elements/MediaControlOverflowMenuButtonElement. h" |
61 #include "modules/media_controls/elements/MediaControlOverflowMenuListElement.h" | 62 #include "modules/media_controls/elements/MediaControlOverflowMenuListElement.h" |
62 #include "modules/media_controls/elements/MediaControlOverlayEnclosureElement.h" | 63 #include "modules/media_controls/elements/MediaControlOverlayEnclosureElement.h" |
63 #include "modules/media_controls/elements/MediaControlOverlayPlayButtonElement.h " | 64 #include "modules/media_controls/elements/MediaControlOverlayPlayButtonElement.h " |
64 #include "modules/media_controls/elements/MediaControlPanelElement.h" | 65 #include "modules/media_controls/elements/MediaControlPanelElement.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 resize_observer_(ResizeObserver::Create( | 291 resize_observer_(ResizeObserver::Create( |
291 media_element.GetDocument(), | 292 media_element.GetDocument(), |
292 new MediaControlsResizeObserverDelegate(this))), | 293 new MediaControlsResizeObserverDelegate(this))), |
293 element_size_changed_timer_( | 294 element_size_changed_timer_( |
294 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, | 295 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, |
295 &media_element.GetDocument()), | 296 &media_element.GetDocument()), |
296 this, | 297 this, |
297 &MediaControlsImpl::ElementSizeChangedTimerFired), | 298 &MediaControlsImpl::ElementSizeChangedTimerFired), |
298 keep_showing_until_timer_fires_(false) { | 299 keep_showing_until_timer_fires_(false) { |
299 resize_observer_->observe(&media_element); | 300 resize_observer_->observe(&media_element); |
301 CreateDownloadInProductHelp(); | |
mlamouri (slow - plz ping)
2017/08/16 13:09:30
Can you move this in ::Create()?
Khushal
2017/08/16 19:01:22
Done.
| |
300 } | 302 } |
301 | 303 |
302 MediaControlsImpl* MediaControlsImpl::Create(HTMLMediaElement& media_element, | 304 MediaControlsImpl* MediaControlsImpl::Create(HTMLMediaElement& media_element, |
303 ShadowRoot& shadow_root) { | 305 ShadowRoot& shadow_root) { |
304 MediaControlsImpl* controls = new MediaControlsImpl(media_element); | 306 MediaControlsImpl* controls = new MediaControlsImpl(media_element); |
305 controls->SetShadowPseudoId(AtomicString("-webkit-media-controls")); | 307 controls->SetShadowPseudoId(AtomicString("-webkit-media-controls")); |
306 controls->InitializeControls(); | 308 controls->InitializeControls(); |
307 controls->Reset(); | 309 controls->Reset(); |
308 | 310 |
309 if (RuntimeEnabledFeatures::VideoFullscreenOrientationLockEnabled() && | 311 if (RuntimeEnabledFeatures::VideoFullscreenOrientationLockEnabled() && |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 } | 566 } |
565 | 567 |
566 void MediaControlsImpl::MaybeShow() { | 568 void MediaControlsImpl::MaybeShow() { |
567 panel_->SetIsWanted(true); | 569 panel_->SetIsWanted(true); |
568 panel_->SetIsDisplayed(true); | 570 panel_->SetIsDisplayed(true); |
569 if (overlay_play_button_) | 571 if (overlay_play_button_) |
570 overlay_play_button_->UpdateDisplayType(); | 572 overlay_play_button_->UpdateDisplayType(); |
571 // Only make the controls visible if they won't get hidden by OnTimeUpdate. | 573 // Only make the controls visible if they won't get hidden by OnTimeUpdate. |
572 if (MediaElement().paused() || !ShouldHideMediaControls()) | 574 if (MediaElement().paused() || !ShouldHideMediaControls()) |
573 MakeOpaque(); | 575 MakeOpaque(); |
576 if (download_iph_manager_) | |
577 download_iph_manager_->SetControlsState(true); | |
mlamouri (slow - plz ping)
2017/08/16 13:09:30
Similar to the download button "state", could this
Khushal
2017/08/16 19:01:22
I wasn't sure if I should call it SetControlsVisib
| |
574 } | 578 } |
575 | 579 |
576 void MediaControlsImpl::Hide() { | 580 void MediaControlsImpl::Hide() { |
577 panel_->SetIsWanted(false); | 581 panel_->SetIsWanted(false); |
578 panel_->SetIsDisplayed(false); | 582 panel_->SetIsDisplayed(false); |
579 if (overlay_play_button_) | 583 if (overlay_play_button_) |
580 overlay_play_button_->SetIsWanted(false); | 584 overlay_play_button_->SetIsWanted(false); |
585 if (download_iph_manager_) | |
586 download_iph_manager_->SetControlsState(false); | |
581 } | 587 } |
582 | 588 |
583 bool MediaControlsImpl::IsVisible() const { | 589 bool MediaControlsImpl::IsVisible() const { |
584 return panel_->IsOpaque(); | 590 return panel_->IsOpaque(); |
585 } | 591 } |
586 | 592 |
587 void MediaControlsImpl::MakeOpaque() { | 593 void MediaControlsImpl::MakeOpaque() { |
588 panel_->MakeOpaque(); | 594 panel_->MakeOpaque(); |
589 } | 595 } |
590 | 596 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 const bool ignore_focus = behavior_flags & kIgnoreFocus; | 632 const bool ignore_focus = behavior_flags & kIgnoreFocus; |
627 if (!ignore_focus && (MediaElement().IsFocused() || | 633 if (!ignore_focus && (MediaElement().IsFocused() || |
628 contains(GetDocument().FocusedElement()))) { | 634 contains(GetDocument().FocusedElement()))) { |
629 return false; | 635 return false; |
630 } | 636 } |
631 | 637 |
632 // Don't hide the media controls when a panel is showing. | 638 // Don't hide the media controls when a panel is showing. |
633 if (text_track_list_->IsWanted() || overflow_list_->IsWanted()) | 639 if (text_track_list_->IsWanted() || overflow_list_->IsWanted()) |
634 return false; | 640 return false; |
635 | 641 |
642 // Don't hide the media controls while the in product help is showing. | |
643 if (download_iph_manager_ && download_iph_manager_->IsShowingInProductHelp()) | |
644 return false; | |
645 | |
636 return true; | 646 return true; |
637 } | 647 } |
638 | 648 |
639 void MediaControlsImpl::UpdatePlayState() { | 649 void MediaControlsImpl::UpdatePlayState() { |
640 if (is_paused_for_scrubbing_) | 650 if (is_paused_for_scrubbing_) |
641 return; | 651 return; |
642 | 652 |
643 if (overlay_play_button_) | 653 if (overlay_play_button_) |
644 overlay_play_button_->UpdateDisplayType(); | 654 overlay_play_button_->UpdateDisplayType(); |
645 play_button_->UpdateDisplayType(); | 655 play_button_->UpdateDisplayType(); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 } | 819 } |
810 | 820 |
811 return; | 821 return; |
812 } | 822 } |
813 | 823 |
814 if (event->type() == EventTypeNames::pointerover) { | 824 if (event->type() == EventTypeNames::pointerover) { |
815 if (!ContainsRelatedTarget(event)) { | 825 if (!ContainsRelatedTarget(event)) { |
816 is_mouse_over_controls_ = true; | 826 is_mouse_over_controls_ = true; |
817 if (!MediaElement().paused()) { | 827 if (!MediaElement().paused()) { |
818 MakeOpaque(); | 828 MakeOpaque(); |
819 if (ShouldHideMediaControls()) | 829 StartHideMediaControlsIfNecessary(); |
820 StartHideMediaControlsTimer(); | |
821 } | 830 } |
822 } | 831 } |
823 return; | 832 return; |
824 } | 833 } |
825 | 834 |
826 if (event->type() == EventTypeNames::pointerout) { | 835 if (event->type() == EventTypeNames::pointerout) { |
827 if (!ContainsRelatedTarget(event)) { | 836 if (!ContainsRelatedTarget(event)) { |
828 is_mouse_over_controls_ = false; | 837 is_mouse_over_controls_ = false; |
829 StopHideMediaControlsTimer(); | 838 StopHideMediaControlsTimer(); |
830 } | 839 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
955 UpdateCurrentTimeDisplay(); | 964 UpdateCurrentTimeDisplay(); |
956 | 965 |
957 // Update the timeline (the UI with the seek marker). | 966 // Update the timeline (the UI with the seek marker). |
958 timeline_->SetDuration(duration); | 967 timeline_->SetDuration(duration); |
959 } | 968 } |
960 | 969 |
961 void MediaControlsImpl::OnPlay() { | 970 void MediaControlsImpl::OnPlay() { |
962 UpdatePlayState(); | 971 UpdatePlayState(); |
963 timeline_->SetPosition(MediaElement().currentTime()); | 972 timeline_->SetPosition(MediaElement().currentTime()); |
964 UpdateCurrentTimeDisplay(); | 973 UpdateCurrentTimeDisplay(); |
974 | |
975 if (download_iph_manager_) | |
976 download_iph_manager_->SetPlayState(true); | |
mlamouri (slow - plz ping)
2017/08/16 13:09:30
This should probably be called "Playback" instead
Khushal
2017/08/16 19:01:22
Done.
| |
965 } | 977 } |
966 | 978 |
967 void MediaControlsImpl::OnPlaying() { | 979 void MediaControlsImpl::OnPlaying() { |
968 timeline_->OnPlaying(); | 980 timeline_->OnPlaying(); |
969 | 981 |
970 StartHideMediaControlsTimer(); | 982 StartHideMediaControlsTimer(); |
971 } | 983 } |
972 | 984 |
973 void MediaControlsImpl::OnPause() { | 985 void MediaControlsImpl::OnPause() { |
974 UpdatePlayState(); | 986 UpdatePlayState(); |
975 timeline_->SetPosition(MediaElement().currentTime()); | 987 timeline_->SetPosition(MediaElement().currentTime()); |
976 UpdateCurrentTimeDisplay(); | 988 UpdateCurrentTimeDisplay(); |
977 MakeOpaque(); | 989 MakeOpaque(); |
978 | 990 |
979 StopHideMediaControlsTimer(); | 991 StopHideMediaControlsTimer(); |
992 | |
993 if (download_iph_manager_) | |
994 download_iph_manager_->SetPlayState(false); | |
980 } | 995 } |
981 | 996 |
982 void MediaControlsImpl::OnTextTracksAddedOrRemoved() { | 997 void MediaControlsImpl::OnTextTracksAddedOrRemoved() { |
983 toggle_closed_captions_button_->SetIsWanted( | 998 toggle_closed_captions_button_->SetIsWanted( |
984 MediaElement().HasClosedCaptions()); | 999 MediaElement().HasClosedCaptions()); |
985 BatchedControlUpdate batch(this); | 1000 BatchedControlUpdate batch(this); |
986 } | 1001 } |
987 | 1002 |
988 void MediaControlsImpl::OnTextTracksChanged() { | 1003 void MediaControlsImpl::OnTextTracksChanged() { |
989 toggle_closed_captions_button_->UpdateDisplayType(); | 1004 toggle_closed_captions_button_->UpdateDisplayType(); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1213 | 1228 |
1214 void MediaControlsImpl::HideAllMenus() { | 1229 void MediaControlsImpl::HideAllMenus() { |
1215 window_event_listener_->Stop(); | 1230 window_event_listener_->Stop(); |
1216 | 1231 |
1217 if (overflow_list_->IsWanted()) | 1232 if (overflow_list_->IsWanted()) |
1218 overflow_list_->SetIsWanted(false); | 1233 overflow_list_->SetIsWanted(false); |
1219 if (text_track_list_->IsWanted()) | 1234 if (text_track_list_->IsWanted()) |
1220 text_track_list_->SetVisible(false); | 1235 text_track_list_->SetVisible(false); |
1221 } | 1236 } |
1222 | 1237 |
1238 void MediaControlsImpl::StartHideMediaControlsIfNecessary() { | |
1239 if (ShouldHideMediaControls()) | |
1240 StartHideMediaControlsTimer(); | |
1241 } | |
1242 | |
1243 const MediaControlDownloadButtonElement& MediaControlsImpl::DownloadButton() | |
1244 const { | |
1245 return *download_button_; | |
1246 } | |
1247 | |
1248 void MediaControlsImpl::DidDismissDownloadInProductHelp() { | |
1249 StartHideMediaControlsIfNecessary(); | |
1250 } | |
1251 | |
1252 MediaDownloadInProductHelpManager* MediaControlsImpl::DownloadInProductHelp() { | |
1253 return download_iph_manager_; | |
1254 } | |
1255 | |
1256 void MediaControlsImpl::CreateDownloadInProductHelp() { | |
1257 // Is showing in-product help enabled? | |
1258 if (!MediaElement().GetDocument().GetSettings() || | |
1259 !MediaElement() | |
1260 .GetDocument() | |
1261 .GetSettings() | |
1262 ->GetMediaDownloadInProductHelpEnabled()) { | |
1263 return; | |
1264 } | |
1265 | |
1266 // Download in-product-help is only shown for videos. | |
1267 if (!MediaElement().IsHTMLVideoElement()) | |
1268 return; | |
1269 | |
1270 download_iph_manager_ = new MediaDownloadInProductHelpManager(*this); | |
1271 } | |
1272 | |
1223 DEFINE_TRACE(MediaControlsImpl) { | 1273 DEFINE_TRACE(MediaControlsImpl) { |
1224 visitor->Trace(element_mutation_callback_); | 1274 visitor->Trace(element_mutation_callback_); |
1225 visitor->Trace(resize_observer_); | 1275 visitor->Trace(resize_observer_); |
1226 visitor->Trace(panel_); | 1276 visitor->Trace(panel_); |
1227 visitor->Trace(overlay_play_button_); | 1277 visitor->Trace(overlay_play_button_); |
1228 visitor->Trace(overlay_enclosure_); | 1278 visitor->Trace(overlay_enclosure_); |
1229 visitor->Trace(play_button_); | 1279 visitor->Trace(play_button_); |
1230 visitor->Trace(current_time_display_); | 1280 visitor->Trace(current_time_display_); |
1231 visitor->Trace(timeline_); | 1281 visitor->Trace(timeline_); |
1232 visitor->Trace(mute_button_); | 1282 visitor->Trace(mute_button_); |
1233 visitor->Trace(volume_slider_); | 1283 visitor->Trace(volume_slider_); |
1234 visitor->Trace(toggle_closed_captions_button_); | 1284 visitor->Trace(toggle_closed_captions_button_); |
1235 visitor->Trace(fullscreen_button_); | 1285 visitor->Trace(fullscreen_button_); |
1236 visitor->Trace(download_button_); | 1286 visitor->Trace(download_button_); |
1237 visitor->Trace(duration_display_); | 1287 visitor->Trace(duration_display_); |
1238 visitor->Trace(enclosure_); | 1288 visitor->Trace(enclosure_); |
1239 visitor->Trace(text_track_list_); | 1289 visitor->Trace(text_track_list_); |
1240 visitor->Trace(overflow_menu_); | 1290 visitor->Trace(overflow_menu_); |
1241 visitor->Trace(overflow_list_); | 1291 visitor->Trace(overflow_list_); |
1242 visitor->Trace(cast_button_); | 1292 visitor->Trace(cast_button_); |
1243 visitor->Trace(overlay_cast_button_); | 1293 visitor->Trace(overlay_cast_button_); |
1244 visitor->Trace(media_event_listener_); | 1294 visitor->Trace(media_event_listener_); |
1245 visitor->Trace(window_event_listener_); | 1295 visitor->Trace(window_event_listener_); |
1246 visitor->Trace(orientation_lock_delegate_); | 1296 visitor->Trace(orientation_lock_delegate_); |
1247 visitor->Trace(rotate_to_fullscreen_delegate_); | 1297 visitor->Trace(rotate_to_fullscreen_delegate_); |
1298 visitor->Trace(download_iph_manager_); | |
1248 MediaControls::Trace(visitor); | 1299 MediaControls::Trace(visitor); |
1249 HTMLDivElement::Trace(visitor); | 1300 HTMLDivElement::Trace(visitor); |
1250 } | 1301 } |
1251 | 1302 |
1252 } // namespace blink | 1303 } // namespace blink |
OLD | NEW |