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

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaRemotingInterstitial.cpp

Issue 2825493005: Enable smooth transition when show/hide media remoting interstitial. (Closed)
Patch Set: Rebase only. 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 // 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 is_shown_(false),
25 toggle_insterstitial_timer_(
26 TaskRunnerHelper::Get(TaskType::kUnthrottled,
27 &videoElement.GetDocument()),
28 this,
29 &MediaRemotingInterstitial::ToggleInterstitialTimerFired),
16 video_element_(&videoElement) { 30 video_element_(&videoElement) {
17 SetShadowPseudoId(AtomicString("-internal-media-remoting-interstitial")); 31 SetShadowPseudoId(AtomicString("-internal-media-remoting-interstitial"));
18 background_image_ = HTMLImageElement::Create(videoElement.GetDocument()); 32 background_image_ = HTMLImageElement::Create(videoElement.GetDocument());
19 background_image_->SetShadowPseudoId( 33 background_image_->SetShadowPseudoId(
20 AtomicString("-internal-media-remoting-background-image")); 34 AtomicString("-internal-media-remoting-background-image"));
21 background_image_->SetSrc(videoElement.getAttribute(HTMLNames::posterAttr)); 35 background_image_->SetSrc(videoElement.getAttribute(HTMLNames::posterAttr));
22 AppendChild(background_image_); 36 AppendChild(background_image_);
23 37
24 cast_icon_ = new MediaRemotingCastIconElement(*this); 38 cast_icon_ = new MediaRemotingCastIconElement(*this);
25 AppendChild(cast_icon_); 39 AppendChild(cast_icon_);
26 40
27 cast_text_message_ = new MediaRemotingCastMessageElement(*this); 41 cast_text_message_ = new MediaRemotingCastMessageElement(*this);
28 AppendChild(cast_text_message_); 42 AppendChild(cast_text_message_);
29 43
30 exit_button_ = new MediaRemotingExitButtonElement(*this); 44 exit_button_ = new MediaRemotingExitButtonElement(*this);
31 AppendChild(exit_button_); 45 AppendChild(exit_button_);
32 } 46 }
33 47
34 void MediaRemotingInterstitial::Show() { 48 void MediaRemotingInterstitial::Show() {
49 if (is_shown_ && toggle_insterstitial_timer_.IsActive())
mlamouri (slow - plz ping) 2017/04/19 16:17:19 Why do you check if the timer is active? Actually,
xjz 2017/04/19 17:11:19 Done. Yes, the timer could be active. For example,
50 return;
51 if (toggle_insterstitial_timer_.IsActive())
52 toggle_insterstitial_timer_.Stop();
53 is_shown_ = true;
35 RemoveInlineStyleProperty(CSSPropertyDisplay); 54 RemoveInlineStyleProperty(CSSPropertyDisplay);
36 exit_button_->OnShown(); 55 toggle_insterstitial_timer_.StartOneShot(kStyleChangeTransSeconds,
56 BLINK_FROM_HERE);
37 } 57 }
38 58
39 void MediaRemotingInterstitial::Hide() { 59 void MediaRemotingInterstitial::Hide() {
40 SetInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); 60 if (!is_shown_ && toggle_insterstitial_timer_.IsActive())
61 return;
62 if (toggle_insterstitial_timer_.IsActive())
63 toggle_insterstitial_timer_.Stop();
64 is_shown_ = false;
41 exit_button_->OnHidden(); 65 exit_button_->OnHidden();
66 SetInlineStyleProperty(CSSPropertyOpacity, 0,
67 CSSPrimitiveValue::UnitType::kNumber);
68 toggle_insterstitial_timer_.StartOneShot(kHiddenAnimationSeconds,
69 BLINK_FROM_HERE);
70 }
71
72 void MediaRemotingInterstitial::ToggleInterstitialTimerFired(TimerBase*) {
73 toggle_insterstitial_timer_.Stop();
74 if (is_shown_) {
75 SetInlineStyleProperty(CSSPropertyOpacity, 1,
76 CSSPrimitiveValue::UnitType::kNumber);
77 exit_button_->OnShown();
mlamouri (slow - plz ping) 2017/04/19 16:17:19 Why are we not being consistent with onShown and o
xjz 2017/04/19 17:11:19 The initial thought was call onHidden() first to s
78 } else {
79 SetInlineStyleProperty(CSSPropertyDisplay, CSSValueNone);
80 }
81 }
82
83 void MediaRemotingInterstitial::DidMoveToNewDocument(Document& old_document) {
84 toggle_insterstitial_timer_.MoveToNewTaskRunner(
85 TaskRunnerHelper::Get(TaskType::kUnthrottled, &GetDocument()));
86
87 HTMLDivElement::DidMoveToNewDocument(old_document);
42 } 88 }
43 89
44 void MediaRemotingInterstitial::OnPosterImageChanged() { 90 void MediaRemotingInterstitial::OnPosterImageChanged() {
45 background_image_->SetSrc( 91 background_image_->SetSrc(
46 GetVideoElement().getAttribute(HTMLNames::posterAttr)); 92 GetVideoElement().getAttribute(HTMLNames::posterAttr));
47 } 93 }
48 94
49 DEFINE_TRACE(MediaRemotingInterstitial) { 95 DEFINE_TRACE(MediaRemotingInterstitial) {
50 visitor->Trace(video_element_); 96 visitor->Trace(video_element_);
51 visitor->Trace(background_image_); 97 visitor->Trace(background_image_);
52 visitor->Trace(exit_button_); 98 visitor->Trace(exit_button_);
53 visitor->Trace(cast_icon_); 99 visitor->Trace(cast_icon_);
54 visitor->Trace(cast_text_message_); 100 visitor->Trace(cast_text_message_);
55 HTMLDivElement::Trace(visitor); 101 HTMLDivElement::Trace(visitor);
56 } 102 }
57 103
58 } // namespace blink 104 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698