OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/html/shadow/MediaRemotingInterstitial.h" | 5 #include "core/html/shadow/MediaRemotingInterstitial.h" |
6 | 6 |
| 7 #include "core/dom/TaskRunnerHelper.h" |
7 #include "core/html/HTMLImageElement.h" | 8 #include "core/html/HTMLImageElement.h" |
8 #include "core/html/HTMLVideoElement.h" | 9 #include "core/html/HTMLVideoElement.h" |
9 #include "core/html/shadow/MediaRemotingElements.h" | 10 #include "core/html/shadow/MediaRemotingElements.h" |
10 | 11 |
| 12 namespace { |
| 13 |
| 14 constexpr double kStyleChangeTransSeconds = 0.2; |
| 15 constexpr double kHiddenAnimationSeconds = 0.3; |
| 16 |
| 17 } // namespace |
| 18 |
11 namespace blink { | 19 namespace blink { |
12 | 20 |
13 MediaRemotingInterstitial::MediaRemotingInterstitial( | 21 MediaRemotingInterstitial::MediaRemotingInterstitial( |
14 HTMLVideoElement& videoElement) | 22 HTMLVideoElement& videoElement) |
15 : HTMLDivElement(videoElement.GetDocument()), | 23 : HTMLDivElement(videoElement.GetDocument()), |
| 24 toggle_insterstitial_timer_( |
| 25 TaskRunnerHelper::Get(TaskType::kUnthrottled, |
| 26 &videoElement.GetDocument()), |
| 27 this, |
| 28 &MediaRemotingInterstitial::ToggleInterstitialTimerFired), |
16 video_element_(&videoElement) { | 29 video_element_(&videoElement) { |
17 SetShadowPseudoId(AtomicString("-internal-media-remoting-interstitial")); | 30 SetShadowPseudoId(AtomicString("-internal-media-remoting-interstitial")); |
18 background_image_ = HTMLImageElement::Create(videoElement.GetDocument()); | 31 background_image_ = HTMLImageElement::Create(videoElement.GetDocument()); |
19 background_image_->SetShadowPseudoId( | 32 background_image_->SetShadowPseudoId( |
20 AtomicString("-internal-media-remoting-background-image")); | 33 AtomicString("-internal-media-remoting-background-image")); |
21 background_image_->SetSrc(videoElement.getAttribute(HTMLNames::posterAttr)); | 34 background_image_->SetSrc(videoElement.getAttribute(HTMLNames::posterAttr)); |
22 AppendChild(background_image_); | 35 AppendChild(background_image_); |
23 | 36 |
24 cast_icon_ = new MediaRemotingCastIconElement(*this); | 37 cast_icon_ = new MediaRemotingCastIconElement(*this); |
25 AppendChild(cast_icon_); | 38 AppendChild(cast_icon_); |
26 | 39 |
27 cast_text_message_ = new MediaRemotingCastMessageElement(*this); | 40 cast_text_message_ = new MediaRemotingCastMessageElement(*this); |
28 AppendChild(cast_text_message_); | 41 AppendChild(cast_text_message_); |
29 | 42 |
30 exit_button_ = new MediaRemotingExitButtonElement(*this); | 43 exit_button_ = new MediaRemotingExitButtonElement(*this); |
31 AppendChild(exit_button_); | 44 AppendChild(exit_button_); |
32 } | 45 } |
33 | 46 |
34 void MediaRemotingInterstitial::Show() { | 47 void MediaRemotingInterstitial::Show() { |
| 48 DCHECK(!should_be_visible_); |
| 49 if (toggle_insterstitial_timer_.IsActive()) |
| 50 toggle_insterstitial_timer_.Stop(); |
| 51 should_be_visible_ = true; |
35 RemoveInlineStyleProperty(CSSPropertyDisplay); | 52 RemoveInlineStyleProperty(CSSPropertyDisplay); |
36 exit_button_->OnShown(); | 53 exit_button_->OnShown(); |
| 54 toggle_insterstitial_timer_.StartOneShot(kStyleChangeTransSeconds, |
| 55 BLINK_FROM_HERE); |
37 } | 56 } |
38 | 57 |
39 void MediaRemotingInterstitial::Hide() { | 58 void MediaRemotingInterstitial::Hide() { |
40 SetInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); | 59 DCHECK(should_be_visible_); |
| 60 if (toggle_insterstitial_timer_.IsActive()) |
| 61 toggle_insterstitial_timer_.Stop(); |
| 62 should_be_visible_ = false; |
| 63 SetInlineStyleProperty(CSSPropertyOpacity, 0, |
| 64 CSSPrimitiveValue::UnitType::kNumber); |
41 exit_button_->OnHidden(); | 65 exit_button_->OnHidden(); |
| 66 toggle_insterstitial_timer_.StartOneShot(kHiddenAnimationSeconds, |
| 67 BLINK_FROM_HERE); |
| 68 } |
| 69 |
| 70 void MediaRemotingInterstitial::ToggleInterstitialTimerFired(TimerBase*) { |
| 71 toggle_insterstitial_timer_.Stop(); |
| 72 if (should_be_visible_) { |
| 73 SetInlineStyleProperty(CSSPropertyOpacity, 1, |
| 74 CSSPrimitiveValue::UnitType::kNumber); |
| 75 } else { |
| 76 SetInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); |
| 77 } |
| 78 } |
| 79 |
| 80 void MediaRemotingInterstitial::DidMoveToNewDocument(Document& old_document) { |
| 81 toggle_insterstitial_timer_.MoveToNewTaskRunner( |
| 82 TaskRunnerHelper::Get(TaskType::kUnthrottled, &GetDocument())); |
| 83 |
| 84 HTMLDivElement::DidMoveToNewDocument(old_document); |
42 } | 85 } |
43 | 86 |
44 void MediaRemotingInterstitial::OnPosterImageChanged() { | 87 void MediaRemotingInterstitial::OnPosterImageChanged() { |
45 background_image_->SetSrc( | 88 background_image_->SetSrc( |
46 GetVideoElement().getAttribute(HTMLNames::posterAttr)); | 89 GetVideoElement().getAttribute(HTMLNames::posterAttr)); |
47 } | 90 } |
48 | 91 |
49 DEFINE_TRACE(MediaRemotingInterstitial) { | 92 DEFINE_TRACE(MediaRemotingInterstitial) { |
50 visitor->Trace(video_element_); | 93 visitor->Trace(video_element_); |
51 visitor->Trace(background_image_); | 94 visitor->Trace(background_image_); |
52 visitor->Trace(exit_button_); | 95 visitor->Trace(exit_button_); |
53 visitor->Trace(cast_icon_); | 96 visitor->Trace(cast_icon_); |
54 visitor->Trace(cast_text_message_); | 97 visitor->Trace(cast_text_message_); |
55 HTMLDivElement::Trace(visitor); | 98 HTMLDivElement::Trace(visitor); |
56 } | 99 } |
57 | 100 |
58 } // namespace blink | 101 } // namespace blink |
OLD | NEW |