| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/media_controls/elements/MediaControlPanelElement.h" |
| 6 |
| 7 #include "core/dom/TaskRunnerHelper.h" |
| 8 #include "core/events/Event.h" |
| 9 #include "core/html/HTMLMediaElement.h" |
| 10 #include "modules/media_controls/MediaControlsImpl.h" |
| 11 #include "modules/media_controls/elements/MediaControlElementsHelper.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 namespace { |
| 16 |
| 17 // This is matching the `transition` property from mediaControls.css |
| 18 const double kFadeOutDuration = 0.3; |
| 19 |
| 20 } // anonymous namespace |
| 21 |
| 22 MediaControlPanelElement::MediaControlPanelElement( |
| 23 MediaControlsImpl& media_controls) |
| 24 : MediaControlDivElement(media_controls, kMediaControlsPanel), |
| 25 transition_timer_(TaskRunnerHelper::Get(TaskType::kUnspecedTimer, |
| 26 &media_controls.GetDocument()), |
| 27 this, |
| 28 &MediaControlPanelElement::TransitionTimerFired) { |
| 29 SetShadowPseudoId(AtomicString("-webkit-media-controls-panel")); |
| 30 } |
| 31 |
| 32 void MediaControlPanelElement::SetIsDisplayed(bool is_displayed) { |
| 33 if (is_displayed_ == is_displayed) |
| 34 return; |
| 35 |
| 36 is_displayed_ = is_displayed; |
| 37 if (is_displayed_ && opaque_) |
| 38 DidBecomeVisible(); |
| 39 } |
| 40 |
| 41 bool MediaControlPanelElement::IsOpaque() const { |
| 42 return opaque_; |
| 43 } |
| 44 |
| 45 void MediaControlPanelElement::MakeOpaque() { |
| 46 if (opaque_) |
| 47 return; |
| 48 |
| 49 SetInlineStyleProperty(CSSPropertyOpacity, 1.0, |
| 50 CSSPrimitiveValue::UnitType::kNumber); |
| 51 opaque_ = true; |
| 52 |
| 53 if (is_displayed_) { |
| 54 SetIsWanted(true); |
| 55 DidBecomeVisible(); |
| 56 } |
| 57 } |
| 58 |
| 59 void MediaControlPanelElement::MakeTransparent() { |
| 60 if (!opaque_) |
| 61 return; |
| 62 |
| 63 SetInlineStyleProperty(CSSPropertyOpacity, 0.0, |
| 64 CSSPrimitiveValue::UnitType::kNumber); |
| 65 |
| 66 opaque_ = false; |
| 67 StartTimer(); |
| 68 } |
| 69 |
| 70 void MediaControlPanelElement::DefaultEventHandler(Event* event) { |
| 71 // Suppress the media element activation behavior (toggle play/pause) when |
| 72 // any part of the control panel is clicked. |
| 73 if (event->type() == EventTypeNames::click) { |
| 74 event->SetDefaultHandled(); |
| 75 return; |
| 76 } |
| 77 HTMLDivElement::DefaultEventHandler(event); |
| 78 } |
| 79 |
| 80 bool MediaControlPanelElement::KeepEventInNode(Event* event) { |
| 81 return MediaControlElementsHelper::IsUserInteractionEvent(event); |
| 82 } |
| 83 |
| 84 void MediaControlPanelElement::StartTimer() { |
| 85 StopTimer(); |
| 86 |
| 87 // The timer is required to set the property display:'none' on the panel, |
| 88 // such that captions are correctly displayed at the bottom of the video |
| 89 // at the end of the fadeout transition. |
| 90 // FIXME: Racing a transition with a setTimeout like this is wrong. |
| 91 transition_timer_.StartOneShot(kFadeOutDuration, BLINK_FROM_HERE); |
| 92 } |
| 93 |
| 94 void MediaControlPanelElement::StopTimer() { |
| 95 transition_timer_.Stop(); |
| 96 } |
| 97 |
| 98 void MediaControlPanelElement::TransitionTimerFired(TimerBase*) { |
| 99 if (!opaque_) |
| 100 SetIsWanted(false); |
| 101 |
| 102 StopTimer(); |
| 103 } |
| 104 |
| 105 void MediaControlPanelElement::DidBecomeVisible() { |
| 106 DCHECK(is_displayed_ && opaque_); |
| 107 MediaElement().MediaControlsDidBecomeVisible(); |
| 108 } |
| 109 |
| 110 } // namespace blink |
| OLD | NEW |