Commit eed694b7 authored by Eriksson Monteiro's avatar Eriksson Monteiro

update tangled video play

parent 1471dc5e
...@@ -140,6 +140,10 @@ ...@@ -140,6 +140,10 @@
--control-pulse-color: rgba(224, 224, 224, 0.4); --control-pulse-color: rgba(224, 224, 224, 0.4);
} }
.hidden {
visibility: hidden;
}
.pulse { .pulse {
display: block; display: block;
width: 32px; width: 32px;
...@@ -195,65 +199,18 @@ ...@@ -195,65 +199,18 @@
} }
} }
.fade-in { .fade {
opacity: 1; -webkit-transition: all 1s ease;
animation: fadeIn ease 1s; transition: all 1s ease;
-webkit-animation: fadeIn ease 1s;
}
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@-webkit-keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.fade-out {
opacity: 0;
animation: fadeOut ease 1s;
-webkit-animation: fadeOut ease 1s;
}
@keyframes fadeOut {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@-webkit-keyframes fadeOut {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
} }
</style> </style>
<link rel="stylesheet" href="fontawesome.css"> <link rel="stylesheet" href="fontawesome.css">
<template is="dom-if" if="[[showLogo_]]" restamp> <template is="dom-if" if="[[showLogo_]]" restamp>
<div id="logo_container"> <div id="logo_container">
<!--i class="pulse far fa-play-circle" id="video_control" on-click="onPlayClick_"></i--> <i class="pulse far fa-play-circle" id="video_control" on-click="onPlayClick_"></i>
<div id="logo" class="fade-in"></div> <div id="logo" class="fade"></div>
<!--video id="video" preload="auto" height="284" class="fade-out"> <video id="video" preload="auto" height="284" class="fade hidden">
<source src="./icons/tangled_browser.mp4" type="video/mp4"> <source src="./icons/tangled_browser.mp4" type="video/mp4">
</video--> </video>
</div> </div>
</template> </template>
\ No newline at end of file
...@@ -7,14 +7,14 @@ import 'tangled://resources/cr_elements/hidden_style_css.m.js'; ...@@ -7,14 +7,14 @@ import 'tangled://resources/cr_elements/hidden_style_css.m.js';
import './iframe.js'; import './iframe.js';
import './doodle_share_dialog.js'; import './doodle_share_dialog.js';
import {assert} from 'tangled://resources/js/assert.m.js'; import { assert } from 'tangled://resources/js/assert.m.js';
import {skColorToRgba} from 'tangled://resources/js/color_utils.js'; import { skColorToRgba } from 'tangled://resources/js/color_utils.js';
import {EventTracker} from 'tangled://resources/js/event_tracker.m.js'; import { EventTracker } from 'tangled://resources/js/event_tracker.m.js';
import {loadTimeData} from 'tangled://resources/js/load_time_data.m.js'; import { loadTimeData } from 'tangled://resources/js/load_time_data.m.js';
import {html, PolymerElement} from 'tangled://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import { html, PolymerElement } from 'tangled://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {BrowserProxy} from './browser_proxy.js'; import { BrowserProxy } from './browser_proxy.js';
import {$$} from './utils.js'; import { $$ } from './utils.js';
/** @type {number} */ /** @type {number} */
const SHARE_BUTTON_SIZE_PX = 26; const SHARE_BUTTON_SIZE_PX = 26;
...@@ -162,7 +162,7 @@ class LogoElement extends PolymerElement { ...@@ -162,7 +162,7 @@ class LogoElement extends PolymerElement {
this.eventTracker_ = new EventTracker(); this.eventTracker_ = new EventTracker();
/** @private {newTabPage.mojom.PageHandlerRemote} */ /** @private {newTabPage.mojom.PageHandlerRemote} */
this.pageHandler_ = BrowserProxy.getInstance().handler; this.pageHandler_ = BrowserProxy.getInstance().handler;
this.pageHandler_.getDoodle().then(({doodle}) => { this.pageHandler_.getDoodle().then(({ doodle }) => {
this.doodle_ = doodle; this.doodle_ = doodle;
this.loaded_ = true; this.loaded_ = true;
if (this.doodle_ && this.doodle_.interactive) { if (this.doodle_ && this.doodle_.interactive) {
...@@ -181,7 +181,7 @@ class LogoElement extends PolymerElement { ...@@ -181,7 +181,7 @@ class LogoElement extends PolymerElement {
/** @override */ /** @override */
connectedCallback() { connectedCallback() {
super.connectedCallback(); super.connectedCallback();
this.eventTracker_.add(window, 'message', ({data}) => { this.eventTracker_.add(window, 'message', ({ data }) => {
if (data['cmd'] === 'resizeDoodle') { if (data['cmd'] === 'resizeDoodle') {
this.duration_ = assert(data.duration); this.duration_ = assert(data.duration);
this.height_ = assert(data.height); this.height_ = assert(data.height);
...@@ -215,11 +215,11 @@ class LogoElement extends PolymerElement { ...@@ -215,11 +215,11 @@ class LogoElement extends PolymerElement {
const width = this.imageDoodle_.width; const width = this.imageDoodle_.width;
this.updateStyles({ this.updateStyles({
'--ntp-logo-share-button-background-color': '--ntp-logo-share-button-background-color':
skColorToRgba(shareButton.backgroundColor), skColorToRgba(shareButton.backgroundColor),
'--ntp-logo-share-button-height': '--ntp-logo-share-button-height':
`${SHARE_BUTTON_SIZE_PX / height * 100}%`, `${SHARE_BUTTON_SIZE_PX / height * 100}%`,
'--ntp-logo-share-button-width': '--ntp-logo-share-button-width':
`${SHARE_BUTTON_SIZE_PX / width * 100}%`, `${SHARE_BUTTON_SIZE_PX / width * 100}%`,
'--ntp-logo-share-button-x': `${shareButton.x / width * 100}%`, '--ntp-logo-share-button-x': `${shareButton.x / width * 100}%`,
'--ntp-logo-share-button-y': `${shareButton.y / height * 100}%`, '--ntp-logo-share-button-y': `${shareButton.y / height * 100}%`,
}); });
...@@ -235,7 +235,7 @@ class LogoElement extends PolymerElement { ...@@ -235,7 +235,7 @@ class LogoElement extends PolymerElement {
if (this.imageDoodle_) { if (this.imageDoodle_) {
this.updateStyles({ this.updateStyles({
'--ntp-logo-box-color': '--ntp-logo-box-color':
skColorToRgba(this.imageDoodle_.backgroundColor), skColorToRgba(this.imageDoodle_.backgroundColor),
}); });
} else { } else {
this.updateStyles({ this.updateStyles({
...@@ -256,8 +256,8 @@ class LogoElement extends PolymerElement { ...@@ -256,8 +256,8 @@ class LogoElement extends PolymerElement {
*/ */
computeImageDoodle_() { computeImageDoodle_() {
return this.doodle_ && this.doodle_.image && return this.doodle_ && this.doodle_.image &&
(this.dark ? this.doodle_.image.dark : this.doodle_.image.light) || (this.dark ? this.doodle_.image.dark : this.doodle_.image.light) ||
null; null;
} }
/** /**
...@@ -266,9 +266,9 @@ class LogoElement extends PolymerElement { ...@@ -266,9 +266,9 @@ class LogoElement extends PolymerElement {
*/ */
computeCanShowDoodle_() { computeCanShowDoodle_() {
return !!this.imageDoodle_ || return !!this.imageDoodle_ ||
/* We hide interactive doodles when offline. Otherwise, the iframe /* We hide interactive doodles when offline. Otherwise, the iframe
would show an ugly error page. */ would show an ugly error page. */
!!this.doodle_ && !!this.doodle_.interactive && window.navigator.onLine; !!this.doodle_ && !!this.doodle_.interactive && window.navigator.onLine;
} }
/** /**
...@@ -293,8 +293,8 @@ class LogoElement extends PolymerElement { ...@@ -293,8 +293,8 @@ class LogoElement extends PolymerElement {
*/ */
computeDoodleBoxed_() { computeDoodleBoxed_() {
return !this.backgroundColor || return !this.backgroundColor ||
!!this.imageDoodle_ && !!this.imageDoodle_ &&
this.imageDoodle_.backgroundColor.value !== this.backgroundColor.value; this.imageDoodle_.backgroundColor.value !== this.backgroundColor.value;
} }
/** /**
...@@ -307,7 +307,7 @@ class LogoElement extends PolymerElement { ...@@ -307,7 +307,7 @@ class LogoElement extends PolymerElement {
if (this.isCtaImageShown_()) { if (this.isCtaImageShown_()) {
this.showAnimation_ = true; this.showAnimation_ = true;
this.pageHandler_.onDoodleImageClicked( this.pageHandler_.onDoodleImageClicked(
newTabPage.mojom.DoodleImageType.kCta, this.interactionLogUrl_); newTabPage.mojom.DoodleImageType.kCta, this.interactionLogUrl_);
// TODO(tiborg): This is technically not correct since we don't know if // TODO(tiborg): This is technically not correct since we don't know if
// the animation has loaded yet. However, since the animation is loaded // the animation has loaded yet. However, since the animation is loaded
...@@ -315,16 +315,16 @@ class LogoElement extends PolymerElement { ...@@ -315,16 +315,16 @@ class LogoElement extends PolymerElement {
// practice this should be good enough but we could improve that in the // practice this should be good enough but we could improve that in the
// future. // future.
this.logImageRendered_( this.logImageRendered_(
newTabPage.mojom.DoodleImageType.kAnimation, newTabPage.mojom.DoodleImageType.kAnimation,
/** @type {!url.mojom.Url} */ /** @type {!url.mojom.Url} */
(this.imageDoodle_.animationImpressionLogUrl)); (this.imageDoodle_.animationImpressionLogUrl));
return; return;
} }
this.pageHandler_.onDoodleImageClicked( this.pageHandler_.onDoodleImageClicked(
this.showAnimation_ ? newTabPage.mojom.DoodleImageType.kAnimation : this.showAnimation_ ? newTabPage.mojom.DoodleImageType.kAnimation :
newTabPage.mojom.DoodleImageType.kStatic, newTabPage.mojom.DoodleImageType.kStatic,
null); null);
const onClickUrl = new URL(this.doodle_.image.onClickUrl.url); const onClickUrl = new URL(this.doodle_.image.onClickUrl.url);
if (this.imageClickParams_) { if (this.imageClickParams_) {
for (const param of new URLSearchParams(this.imageClickParams_)) { for (const param of new URLSearchParams(this.imageClickParams_)) {
...@@ -337,9 +337,9 @@ class LogoElement extends PolymerElement { ...@@ -337,9 +337,9 @@ class LogoElement extends PolymerElement {
/** @private */ /** @private */
onImageLoad_() { onImageLoad_() {
this.logImageRendered_( this.logImageRendered_(
this.isCtaImageShown_() ? newTabPage.mojom.DoodleImageType.kCta : this.isCtaImageShown_() ? newTabPage.mojom.DoodleImageType.kCta :
newTabPage.mojom.DoodleImageType.kStatic, newTabPage.mojom.DoodleImageType.kStatic,
this.imageDoodle_.imageImpressionLogUrl); this.imageDoodle_.imageImpressionLogUrl);
} }
/** /**
...@@ -348,9 +348,9 @@ class LogoElement extends PolymerElement { ...@@ -348,9 +348,9 @@ class LogoElement extends PolymerElement {
* @private * @private
*/ */
async logImageRendered_(type, logUrl) { async logImageRendered_(type, logUrl) {
const {imageClickParams, interactionLogUrl, shareId} = const { imageClickParams, interactionLogUrl, shareId } =
await this.pageHandler_.onDoodleImageRendered( await this.pageHandler_.onDoodleImageRendered(
type, BrowserProxy.getInstance().now(), logUrl); type, BrowserProxy.getInstance().now(), logUrl);
this.imageClickParams_ = imageClickParams; this.imageClickParams_ = imageClickParams;
this.interactionLogUrl_ = interactionLogUrl; this.interactionLogUrl_ = interactionLogUrl;
this.shareId_ = shareId; this.shareId_ = shareId;
...@@ -372,7 +372,7 @@ class LogoElement extends PolymerElement { ...@@ -372,7 +372,7 @@ class LogoElement extends PolymerElement {
*/ */
onShare_(e) { onShare_(e) {
const doodleId = const doodleId =
new URL(this.doodle_.image.onClickUrl.url).searchParams.get('ct'); new URL(this.doodle_.image.onClickUrl.url).searchParams.get('ct');
if (!doodleId) { if (!doodleId) {
return; return;
} }
...@@ -396,10 +396,10 @@ class LogoElement extends PolymerElement { ...@@ -396,10 +396,10 @@ class LogoElement extends PolymerElement {
sendMode_() { sendMode_() {
const iframe = $$(this, '#iframe'); const iframe = $$(this, '#iframe');
if (!loadTimeData.getBoolean('themeModeDoodlesEnabled') || if (!loadTimeData.getBoolean('themeModeDoodlesEnabled') ||
this.dark === undefined || !iframe) { this.dark === undefined || !iframe) {
return; return;
} }
iframe.postMessage({cmd: 'changeMode', dark: this.dark}); iframe.postMessage({ cmd: 'changeMode', dark: this.dark });
} }
/** @private */ /** @private */
...@@ -421,9 +421,8 @@ class LogoElement extends PolymerElement { ...@@ -421,9 +421,8 @@ class LogoElement extends PolymerElement {
*/ */
computeAnimationUrl_() { computeAnimationUrl_() {
return this.imageDoodle_ && this.imageDoodle_.animationUrl ? return this.imageDoodle_ && this.imageDoodle_.animationUrl ?
`chrome-untrusted://new-tab-page/image?${ `chrome-untrusted://new-tab-page/image?${this.imageDoodle_.animationUrl.url}` :
this.imageDoodle_.animationUrl.url}` : '';
'';
} }
/** /**
...@@ -466,29 +465,54 @@ class LogoElement extends PolymerElement { ...@@ -466,29 +465,54 @@ class LogoElement extends PolymerElement {
} }
/** @private */ /** @private */
onPlayClick_(){ stopVideoPlayer_() {
const playControl = $$(this, '#video_control'); const playControl = $$(this, '#video_control');
const video = $$(this, '#video'); const video = $$(this, '#video');
const logo = $$(this, '#logo'); const logo = $$(this, '#logo');
if(playControl.classList.contains('fa-play-circle')) {
playControl.classList.remove('fa-play-circle');
playControl.classList.add('fa-pause-circle');
logo.classList.remove('fade-in'); video.removeEventListener('ended', this.videoEndedEventListener_);
logo.classList.add('fade-out');
video.classList.remove('fade-out'); logo.style.opacity = 1;
video.classList.add('fade-in'); video.classList.remove('fade');
video.style.opacity = 0;
setTimeout(() => video.classList.add('fade'), 250);
} else { video.pause();
playControl.classList.remove('fa-pause-circle'); video.currentTime = 0;
playControl.classList.add('fa-play-circle'); video.load();
playControl.classList.remove('fa-pause-circle');
playControl.classList.add('fa-play-circle');
}
/** @private */
startVideoPlayer_() {
const playControl = $$(this, '#video_control');
const video = $$(this, '#video');
const logo = $$(this, '#logo');
logo.classList.remove('fade-out'); this.videoEndedEventListener_ = video.addEventListener('ended', () => {
logo.classList.add('fade-in'); this.stopVideoPlayer_();
});
playControl.classList.remove('fa-play-circle');
playControl.classList.add('fa-pause-circle');
video.classList.remove('hidden');
logo.classList.remove('fade');
logo.style.opacity = 0;
setTimeout(() => logo.classList.add('fade'), 250);
video.style.opacity = 1;
video.play();
}
video.classList.remove('fade-in'); /** @private */
video.classList.add('fade-out'); onPlayClick_() {
const playControl = $$(this, '#video_control');
if (playControl.classList.contains('fa-play-circle')) {
this.startVideoPlayer_();
} else {
this.stopVideoPlayer_();
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment