Commit 004f26fd authored by huangs@chromium.org's avatar huangs@chromium.org

[Local NTP] Implementing Material Design styling

We also want the "classical" NTP to coexist with the new design, and
switchable via Finch. Key changes:
- Adding classes to #ntp-content, then using CSS to control styling.
  - .classical for old NTP
  - .md for Material Design
  - .default-theme for values that will be overriden by themes. This is
    needed so dynamic CSS changes in setCustomThemeStyle() are not
    subsumed by specialized .classical and .md.
  - .dark: for dark background.
- The .mv-mask <div> is promoted to handle tile effects, including
  border, shadow, and background. Borders are drawn differently now.
  This lead to fix of 1px offset of .mv-title .

Some new designs are still in flux. Our goal is to get a reasonable bulk
committed for m38, then worry about some tune-ups later.

TEST=Run "chrome.exe --force-fieldtrials=MaterialDesignNTP/Enabled/",
visit chrome-search://local-ntp/local-ntp.html . If chrome.exe is run
without the switch, the local NTP should be identical to before, except
for 1px .mv-title shift.

BUG=400332

Review URL: https://codereview.chromium.org/473583002

Cr-Commit-Position: refs/heads/master@{#289682}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289682 0039d316-1c4b-4281-b951-d872f2087c98
parent cf44ce93
...@@ -4,26 +4,33 @@ ...@@ -4,26 +4,33 @@
/** /**
* @fileoverview Specifications for the NTP design, and an accessor to presets. * @fileoverview Specifications for NTP design, and an accessor to presets.
*/ */
var THUMBNAIL_FALLBACK = {
DOT: 'dot' // Draw single dot.
};
/** /**
* Specifications for an NTP design (not comprehensive). * Specifications for an NTP design (not comprehensive).
* *
* name: A unique identifier for the style. * name: A unique identifier for the style.
* appropriate CSS will take effect.
* fontFamily: Font family to use for title and thumbnail <iframe>s. * fontFamily: Font family to use for title and thumbnail <iframe>s.
* fontSize: Font size to use for the <iframe>s, in px. * fontSize: Font size to use for the <iframe>s, in px.
* tileWidth: The width of each suggestion tile, in px. * tileWidth: The width of each suggestion tile, in px.
* tileMargin: Spacing between successive tiles, in px. * tileMargin: Spacing between successive tiles, in px.
* titleColor: The RRGGBB color of title text. * titleColor: The RRGGBB color of title text.
* titleColorAgainstDark: The RRGGBB color of title text against a dark theme.
* titleTextAlign: (Optional) The alignment of title text. If unspecified, the * titleTextAlign: (Optional) The alignment of title text. If unspecified, the
* default value is 'center'. * default value is 'center'.
* titleTextFade: (Optional) The number of pixels beyond which title * titleTextFade: (Optional) The number of pixels beyond which title
* text begins to fade. This overrides the default ellipsis style. * text begins to fade. This overrides the default ellipsis style.
* thumbnailTextColor: The RRGGBB color that thumbnail <iframe> may use to * thumbnailTextColor: The RRGGBB color that thumbnail <iframe> may use to
* display text message in place of missing thumbnail. * display text message in place of missing thumbnail.
* thumbnailFallback: (Optional) A value in THUMBNAIL_FALLBACK to specify the
* thumbnail fallback strategy. If unassigned, then the thumbnail.html
* <iframe> would handle the fallback.
* showFakeboxHint: Whether to display text in the fakebox.
* *
* @typedef {{ * @typedef {{
* name: string, * name: string,
...@@ -32,9 +39,12 @@ ...@@ -32,9 +39,12 @@
* tileWidth: number, * tileWidth: number,
* tileMargin: number, * tileMargin: number,
* titleColor: string, * titleColor: string,
* titleColorAgainstDark: string,
* titleTextAlign: string|null|undefined, * titleTextAlign: string|null|undefined,
* titleTextFade: string|null|undefined, * titleTextFade: string|null|undefined,
* thumbnailTextColor: string * thumbnailTextColor: string,
* thumbnailFallback: string|null|undefined
* showFakeboxHint: string|null|undefined
* }} * }}
*/ */
var NtpDesign; var NtpDesign;
...@@ -46,16 +56,38 @@ var NtpDesign; ...@@ -46,16 +56,38 @@ var NtpDesign;
* @return {NtpDesign} The NTP design corresponding to name. * @return {NtpDesign} The NTP design corresponding to name.
*/ */
function getNtpDesign(opt_name) { function getNtpDesign(opt_name) {
// TODO(huangs): Add new style. var ntpDesign = null;
return {
name: 'classical', if (opt_name === 'md') {
fontFamily: 'arial, sans-serif', ntpDesign = {
fontSize: 11, name: opt_name,
tileWidth: 140, fontFamily: 'arial, sans-serif',
tileMargin: 20, fontSize: 12,
titleColor: '777777', tileWidth: 146,
// No titleTextAlign: defaults to 'center'. tileMargin: 12,
// No titleTextFade: by default we have ellipsis. titleColor: '000000',
thumbnailTextColor: '777777' titleColorAgainstDark: 'd2d2d2',
}; titleTextAlign: 'inherit',
titleTextFade: 112 - 24, // 112px wide title with 24 pixel fade at end.
thumbnailTextColor: '777777',
thumbnailFallback: THUMBNAIL_FALLBACK.DOT,
showFakeboxHint: true
};
} else {
ntpDesign = {
name: 'classical',
fontFamily: 'arial, sans-serif',
fontSize: 11,
tileWidth: 140,
tileMargin: 20,
titleColor: '777777',
titleColorAgainstDark: '777777',
titleTextAlign: 'center',
titleTextFade: null, // Default to ellipsis.
thumbnailTextColor: '777777',
thumbnailFallback: null, // Default to false.
showFakeboxHint: false
};
}
return ntpDesign;
} }
...@@ -23,14 +23,7 @@ div { ...@@ -23,14 +23,7 @@ div {
width: 90%; width: 90%;
} }
img, img {
.shadow {
border-radius: 2px;
height: 100%; height: 100%;
width: 100%; width: 100%;
} }
.shadow {
box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.09);
position: absolute;
}
\ No newline at end of file
...@@ -42,17 +42,15 @@ window.addEventListener('DOMContentLoaded', function() { ...@@ -42,17 +42,15 @@ window.addEventListener('DOMContentLoaded', function() {
function createThumbnail(src) { function createThumbnail(src) {
var image = document.createElement('img'); var image = document.createElement('img');
image.onload = function() { image.onload = function() {
var shadow = document.createElement('span');
shadow.className = 'shadow';
var link = createMostVisitedLink( var link = createMostVisitedLink(
params, data.url, data.title, undefined, data.direction, params, data.url, data.title, undefined, data.direction,
data.provider); data.provider);
link.appendChild(shadow);
link.appendChild(image); link.appendChild(image);
displayLink(link); displayLink(link);
}; };
image.onerror = function() { image.onerror = function() {
if (data.domain) { // If no external thumbnail fallback (etfb), and have domain.
if (!params.etfb && data.domain) {
showDomainElement(); showDomainElement();
logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE_FALLBACK); logEvent(NTP_LOGGING_EVENT_TYPE.NTP_GRAY_TILE_FALLBACK);
} else { } else {
......
...@@ -156,6 +156,9 @@ function createMostVisitedLink(params, href, title, text, direction, provider) { ...@@ -156,6 +156,9 @@ function createMostVisitedLink(params, href, title, text, direction, provider) {
} }
// Else follow <a> normally, so transition type would be LINK. // Else follow <a> normally, so transition type would be LINK.
}); });
link.addEventListener('mousedown', function(e) {
e.preventDefault(); // Prevent drag-select.
});
return link; return link;
} }
...@@ -163,11 +166,11 @@ function createMostVisitedLink(params, href, title, text, direction, provider) { ...@@ -163,11 +166,11 @@ function createMostVisitedLink(params, href, title, text, direction, provider) {
/** /**
* Decodes most visited styles from URL parameters. * Decodes most visited styles from URL parameters.
* - c: A hexadecimal number interpreted as a hex color code.
* - f: font-family. * - f: font-family.
* - fs: font-size as a number in pixels. * - fs: font-size as a number in pixels.
* - ta: text-align property, as a string. * - ta: text-align property, as a string.
* - tf: specifying a text fade starting position, in pixels. * - tf: specifying a text fade starting position, in pixels.
* - c: A hexadecimal number interpreted as a hex color code.
* @param {Object.<string, string>} params URL parameters specifying style. * @param {Object.<string, string>} params URL parameters specifying style.
* @param {boolean} isTitle if the style is for the Most Visited Title. * @param {boolean} isTitle if the style is for the Most Visited Title.
* @return {Object} Styles suitable for CSS interpolation. * @return {Object} Styles suitable for CSS interpolation.
......
...@@ -36,7 +36,8 @@ namespace { ...@@ -36,7 +36,8 @@ namespace {
const char kMaterialDesignNTPFieldTrialName[] = "MaterialDesignNTP"; const char kMaterialDesignNTPFieldTrialName[] = "MaterialDesignNTP";
const char kMaterialDesignNTPFieldTrialEnabledPrefix[] = "Enabled"; const char kMaterialDesignNTPFieldTrialEnabledPrefix[] = "Enabled";
// Name to be used for the new design in local resources. // Names of NTP designs in local resources, also used in CSS.
const char kClassicalNTPName[] = "classical";
const char kMaterialDesignNTPName[] = "md"; const char kMaterialDesignNTPName[] = "md";
// Signifies a locally constructed resource, i.e. not from grit/. // Signifies a locally constructed resource, i.e. not from grit/.
...@@ -188,7 +189,7 @@ void LocalNtpSource::StartDataRequest( ...@@ -188,7 +189,7 @@ void LocalNtpSource::StartDataRequest(
if (stripped_path == kLocalNTPFilename) { if (stripped_path == kLocalNTPFilename) {
SendResourceWithClass( SendResourceWithClass(
IDR_LOCAL_NTP_HTML, IDR_LOCAL_NTP_HTML,
IsMaterialDesignEnabled() ? kMaterialDesignNTPName : "", IsMaterialDesignEnabled() ? kMaterialDesignNTPName : kClassicalNTPName,
callback); callback);
return; return;
} }
......
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