Commit 9ea64714 authored by Chris Pickel's avatar Chris Pickel Committed by Commit Bot

Local NTP: implement Doodle resize API

A postMessage call from the doodle resizes the iframe. The event data
supports these parameters.
  cmd (required): must be "resizeDoodle".
  width (optional): a CSS width (with units) or null. Because the doodle
    cannot know the size of the outer page, only "100%" (full page
    width) and null (default width) are recommended.
  height (optional): a CSS height (with units) or null for the default
    (200px). Must not be a percentage, but otherwise any units are OK.
  duration (optional): a CSS duration, such as 130ms or 1s. If null or
    absent, 0s (no transition) is assumed.

If a second resize is requested while a first resize is in in
transition, the doodle will eventually reach the size from the second
call, but the interpretation of the duration is not defined.

Bug: 761994
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I9f6afe956e710001a45a9b327748a74eab36ea01
Reviewed-on: https://chromium-review.googlesource.com/804034
Commit-Queue: Chris Pickel <sfiera@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521700}
parent bfc43c93
...@@ -11,6 +11,11 @@ html { ...@@ -11,6 +11,11 @@ html {
/* We add an extra pixel because rounding errors on different zooms can /* We add an extra pixel because rounding errors on different zooms can
* make the width shorter than it should be. */ * make the width shorter than it should be. */
+ 1px); + 1px);
--logo-height: 200px; /* Normal height of a doodle. */
--logo-margin-top: 56px; /* Expected OGB height, so logo doesn't overlap. */
--logo-margin-bottom: 24px; /* Between logo and fakebox. */
--tile-height: 128px; --tile-height: 128px;
--tile-margin: 16px; --tile-margin: 16px;
--tile-width: 154px; --tile-width: 154px;
...@@ -69,9 +74,11 @@ button { ...@@ -69,9 +74,11 @@ button {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100%; height: 100%;
margin: 0 auto; }
text-align: -webkit-center;
width: var(--content-width); #logo,
#fakebox-container {
flex-shrink: 0;
} }
.non-google-page #ntp-contents { .non-google-page #ntp-contents {
...@@ -83,14 +90,10 @@ body.hide-fakebox-logo #fakebox { ...@@ -83,14 +90,10 @@ body.hide-fakebox-logo #fakebox {
visibility: hidden; visibility: hidden;
} }
#search {
margin: 0 calc(var(--tile-margin) / 2);
width: calc(100% - var(--tile-margin));
}
#logo { #logo {
height: 249px; height: calc(var(--logo-height) + var(--logo-margin-bottom));
margin-bottom: 24px; margin-top: var(--logo-margin-top);
min-height: fit-content;
position: relative; position: relative;
} }
...@@ -98,12 +101,6 @@ body.hide-fakebox-logo #fakebox { ...@@ -98,12 +101,6 @@ body.hide-fakebox-logo #fakebox {
display: none; display: none;
} }
#logo-default,
#logo-non-white,
#logo-doodle {
position: absolute;
}
#logo-default, #logo-default,
#logo-doodle { #logo-doodle {
opacity: 0; opacity: 0;
...@@ -135,9 +132,10 @@ body.hide-fakebox-logo #fakebox { ...@@ -135,9 +132,10 @@ body.hide-fakebox-logo #fakebox {
#logo-non-white { #logo-non-white {
background-image: url(../../../../ui/webui/resources/images/google_logo.svg); background-image: url(../../../../ui/webui/resources/images/google_logo.svg);
background-repeat: no-repeat; background-repeat: no-repeat;
bottom: var(--logo-margin-bottom);
height: 92px; height: 92px;
left: calc(50% - 272px/2); left: calc(50% - 272px/2);
top: 157px; position: absolute;
width: 272px; width: 272px;
} }
...@@ -159,19 +157,13 @@ body.alternate-logo #logo-non-white { ...@@ -159,19 +157,13 @@ body.alternate-logo #logo-non-white {
display: none; display: none;
} }
#logo-doodle {
/* Normally, logos are aligned with tiles and bounded to their left and right
* edges. Doodles may be larger than this. In order that they are centered and
* cropped, instead of left-aligned, give them 100px of extra space on the
* left and the right side.
*/
left: -100px;
right: -100px;
top: 44px;
}
#logo-doodle-button { #logo-doodle-button {
/* An image logo is allowed to spill into the margin below, so it's not a
* real bottom margin. If the image extends further than that margin, it
* is cropped. */
margin: 0 auto; margin: 0 auto;
max-height: calc(var(--logo-height) + var(--logo-margin-bottom));
overflow: hidden;
} }
.non-white-bg #logo-doodle-button, .non-white-bg #logo-doodle-button,
...@@ -181,8 +173,9 @@ body.alternate-logo #logo-non-white { ...@@ -181,8 +173,9 @@ body.alternate-logo #logo-non-white {
#logo-doodle-iframe { #logo-doodle-iframe {
border: 0; border: 0;
height: 228px; height: var(--logo-height);
width: 100%; margin: 0 auto var(--logo-margin-bottom) auto;
width: var(--content-width);
} }
#logo-doodle-notifier { #logo-doodle-notifier {
...@@ -194,9 +187,9 @@ body.alternate-logo #logo-non-white { ...@@ -194,9 +187,9 @@ body.alternate-logo #logo-non-white {
cursor: pointer; cursor: pointer;
display: inline-block; display: inline-block;
height: 24px; height: 24px;
left: 148px; left: calc(50% + 148px);
padding: 0; padding: 0;
position: relative; position: absolute;
top: 100px; top: 100px;
width: 24px; width: 24px;
} }
...@@ -259,6 +252,11 @@ body.alternate-logo #logo-non-white { ...@@ -259,6 +252,11 @@ body.alternate-logo #logo-non-white {
0deg, rgb(255, 170, 51), rgb(255, 204, 0), rgb(255, 221, 102)); 0deg, rgb(255, 170, 51), rgb(255, 204, 0), rgb(255, 221, 102));
} }
#fakebox-container {
margin: 0 auto 8px auto;
width: var(--content-width);
}
#fakebox { #fakebox {
background-color: #fff; background-color: #fff;
border-radius: 2px; border-radius: 2px;
...@@ -267,14 +265,13 @@ body.alternate-logo #logo-non-white { ...@@ -267,14 +265,13 @@ body.alternate-logo #logo-non-white {
font-size: 18px; font-size: 18px;
height: 44px; height: 44px;
line-height: 36px; line-height: 36px;
margin-bottom: 8px; margin: 0 calc(var(--tile-margin) / 2 + 1px) 0 calc(var(--tile-margin) / 2);
max-width: 672px;
outline: none; outline: none;
position: relative; position: relative;
transition: box-shadow 200ms cubic-bezier(0.4, 0, 0.2, 1); transition: box-shadow 200ms cubic-bezier(0.4, 0, 0.2, 1);
} }
.non-google-page #fakebox { .non-google-page #fakebox-container {
display: none; display: none;
} }
...@@ -400,6 +397,7 @@ body.fakebox-focused #fakebox-cursor { ...@@ -400,6 +397,7 @@ body.fakebox-focused #fakebox-cursor {
max-height: calc(100% - var(--mv-notice-height)); max-height: calc(100% - var(--mv-notice-height));
position: relative; position: relative;
text-align: -webkit-auto; text-align: -webkit-auto;
width: var(--content-width);
} }
#mv-notice-x { #mv-notice-x {
......
...@@ -23,28 +23,28 @@ ...@@ -23,28 +23,28 @@
<div id="one-google" class="hidden"></div> <div id="one-google" class="hidden"></div>
<div id="ntp-contents"> <div id="ntp-contents">
<div id="search"> <div id="logo">
<!-- Container for the logo, whether default or doodle. --> <!-- The logo that is displayed in the absence of a doodle. -->
<div id="logo"> <div id="logo-default" title="Google"></div>
<!-- The logo that is displayed in the absence of a doodle. --> <!-- Logo displayed when theme prevents doodles. Doesn't fade. -->
<div id="logo-default" title="Google"></div> <div id="logo-non-white" title="Google"></div>
<!-- Logo displayed when theme prevents doodles. Doesn't fade. --> <!-- A doodle, if any: its link and image. -->
<div id="logo-non-white" title="Google"></div> <div id="logo-doodle">
<!-- A doodle, if any: its link and image. --> <button id="logo-doodle-button">
<div id="logo-doodle"> <img id="logo-doodle-image"></img>
<button id="logo-doodle-button"> </button>
<img id="logo-doodle-image"></img> <iframe id="logo-doodle-iframe"></iframe>
</button> <!-- A spinner, visible on dark-themed NTPs, prompting the doodle -->
<iframe id="logo-doodle-iframe"></iframe> <button id="logo-doodle-notifier">
<!-- A spinner, visible on dark-themed NTPs, prompting the doodle --> <div class="outer ball0"><div class="inner"></div></div>
<button id="logo-doodle-notifier"> <div class="outer ball1"><div class="inner"></div></div>
<div class="outer ball0"><div class="inner"></div></div> <div class="outer ball2"><div class="inner"></div></div>
<div class="outer ball1"><div class="inner"></div></div> <div class="outer ball3"><div class="inner"></div></div>
<div class="outer ball2"><div class="inner"></div></div> </button>
<div class="outer ball3"><div class="inner"></div></div>
</button>
</div>
</div> </div>
</div>
<div id="fakebox-container">
<div id="fakebox"> <div id="fakebox">
<div id="fakebox-text"></div> <div id="fakebox-text"></div>
<input id="fakebox-input" autocomplete="off" tabindex="-1" type="url" <input id="fakebox-input" autocomplete="off" tabindex="-1" type="url"
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
<button id="fakebox-microphone" hidden></button> <button id="fakebox-microphone" hidden></button>
</div> </div>
</div> </div>
<div id="most-visited"> <div id="most-visited">
<!-- The container for the tiles. The MV iframe goes in here. --> <!-- The container for the tiles. The MV iframe goes in here. -->
<div id="mv-tiles"></div> <div id="mv-tiles"></div>
......
...@@ -535,7 +535,7 @@ function registerKeyHandler(element, keycode, handler) { ...@@ -535,7 +535,7 @@ function registerKeyHandler(element, keycode, handler) {
function handlePostMessage(event) { function handlePostMessage(event) {
var cmd = event.data.cmd; var cmd = event.data.cmd;
var args = event.data; var args = event.data;
if (cmd == 'loaded') { if (cmd === 'loaded') {
tilesAreLoaded = true; tilesAreLoaded = true;
if (configData.isGooglePage && !$('one-google-loader')) { if (configData.isGooglePage && !$('one-google-loader')) {
// Load the OneGoogleBar script. It'll create a global variable name "og" // Load the OneGoogleBar script. It'll create a global variable name "og"
...@@ -550,11 +550,19 @@ function handlePostMessage(event) { ...@@ -550,11 +550,19 @@ function handlePostMessage(event) {
injectOneGoogleBar(og); injectOneGoogleBar(og);
}; };
} }
} else if (cmd == 'tileBlacklisted') { } else if (cmd === 'tileBlacklisted') {
showNotification(); showNotification();
lastBlacklistedTile = args.tid; lastBlacklistedTile = args.tid;
ntpApiHandle.deleteMostVisitedItem(args.tid); ntpApiHandle.deleteMostVisitedItem(args.tid);
} else if (cmd === 'resizeDoodle') {
let width = args.width || null;
let height = args.height || null;
let duration = args.duration || '0s';
let iframe = $(IDS.LOGO_DOODLE_IFRAME);
iframe.style.transition = 'width ' + duration + ', height ' + duration;
iframe.style.width = width;
iframe.style.height = height;
} }
} }
......
...@@ -14,36 +14,37 @@ ...@@ -14,36 +14,37 @@
<script src="local_ntp_browsertest.js" charset="utf-8"></script> <script src="local_ntp_browsertest.js" charset="utf-8"></script>
<template id="local-ntp-template"> <template id="local-ntp-template">
<div id="ntp-contents"> <div id="ntp-contents">
<div id="search"> <div id="logo">
<!-- Container for the logo, whether default or doodle. --> <!-- The logo that is displayed in the absence of a doodle. -->
<div id="logo"> <div id="logo-default" title="Google"></div>
<!-- The logo that is displayed in the absence of a doodle. --> <!-- Logo displayed when theme prevents doodles. Doesn't fade. -->
<div id="logo-default" title="Google"></div> <div id="logo-non-white" title="Google"></div>
<!-- Logo displayed when theme prevents doodles. Doesn't fade. --> <!-- A doodle, if any: its link and image. -->
<div id="logo-non-white" title="Google"></div> <div id="logo-doodle">
<!-- A doodle, if any: its link and image. --> <button id="logo-doodle-button">
<div id="logo-doodle"> <img id="logo-doodle-image"></img>
<button id="logo-doodle-button"> </button>
<img id="logo-doodle-image"></img> <iframe id="logo-doodle-iframe"></iframe>
</button> <!-- A spinner, visible on dark-themed NTPs, prompting the doodle -->
<iframe id="logo-doodle-iframe"></iframe> <button id="logo-doodle-notifier">
<!-- A spinner, visible on dark-themed NTPs, prompting the doodle --> <div class="outer ball0"><div class="inner"></div></div>
<button id="logo-doodle-notifier"> <div class="outer ball1"><div class="inner"></div></div>
<div class="outer ball0"><div class="inner"></div></div> <div class="outer ball2"><div class="inner"></div></div>
<div class="outer ball1"><div class="inner"></div></div> <div class="outer ball3"><div class="inner"></div></div>
<div class="outer ball2"><div class="inner"></div></div> </button>
<div class="outer ball3"><div class="inner"></div></div>
</button>
</div>
</div> </div>
</div>
<div id="fakebox-container">
<div id="fakebox"> <div id="fakebox">
<div id="fakebox-text"></div> <div id="fakebox-text"></div>
<input id="fakebox-input" autocomplete="off" tabIndex="-1" type="url" <input id="fakebox-input" autocomplete="off" tabindex="-1" type="url"
aria-hidden="true"> aria-hidden="true">
<div id="fakebox-cursor"></div> <div id="fakebox-cursor"></div>
<button id="fakebox-microphone" hidden></button> <button id="fakebox-microphone" hidden></button>
</div> </div>
</div> </div>
<div id="most-visited"> <div id="most-visited">
<!-- The container for the tiles. The MV iframe goes in here. --> <!-- The container for the tiles. The MV iframe goes in here. -->
<div id="mv-tiles"></div> <div id="mv-tiles"></div>
......
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
</template> </template>
<template id="voice-speech-template"> <template id="voice-speech-template">
<div id="ntp-contents"> <div id="ntp-contents">
<div id="search"> <div id="fakebox-container">
<div id="fakebox"> <div id="fakebox">
<div id="fakebox-text"></div> <div id="fakebox-text"></div>
<input id="fakebox-input" autocomplete="off" tabIndex="-1" type="url" <input id="fakebox-input" autocomplete="off" tabIndex="-1" type="url"
......
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