summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-27 21:39:03 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-27 21:39:03 +0000
commite15283df626c56c57b1588f3ece9c7d5a7fdae12 (patch)
treecb34db4be24cc795812acce0c6c135aaf77d2b3f /chrome
parentfc3df9349b1af8cdebfdd79f281cb743c66ee593 (diff)
downloadchromium_src-e15283df626c56c57b1588f3ece9c7d5a7fdae12.zip
chromium_src-e15283df626c56c57b1588f3ece9c7d5a7fdae12.tar.gz
chromium_src-e15283df626c56c57b1588f3ece9c7d5a7fdae12.tar.bz2
ntp theme fixes
1. fix where the theme background is displayed for default (0) alignment -- it should be center center. This matches what the bookmark bar does. This may break some themes that rely on the default being top-left alignment. I can't see a way around this. 2. Fix the bookmark bar for vertical center alignment. 3. update the ntp background when the bookmark bar is attached/detached. TODO: transition (3) so that it looks good on windows and mac. BUG=115594 TEST=manual Review URL: https://chromiumcodereview.appspot.com/9467027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123804 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/ntp_background_util.cc15
-rw-r--r--chrome/browser/resources/chromeos/guest_session_tab.html4
-rw-r--r--chrome/browser/resources/incognito_tab.html4
-rw-r--r--chrome/browser/resources/ntp4/new_tab.html3
-rw-r--r--chrome/browser/resources/ntp4/new_tab.js18
-rw-r--r--chrome/browser/resources/ntp4/new_tab_theme.css7
-rw-r--r--chrome/browser/themes/theme_service.cc11
-rw-r--r--chrome/browser/themes/theme_service.h1
-rw-r--r--chrome/browser/ui/webui/ntp/new_tab_ui.cc18
-rw-r--r--chrome/browser/ui/webui/ntp/new_tab_ui.h3
-rw-r--r--chrome/browser/ui/webui/ntp/ntp_resource_cache.cc4
-rw-r--r--chrome/browser/ui/webui/theme_source.cc4
12 files changed, 60 insertions, 32 deletions
diff --git a/chrome/browser/ntp_background_util.cc b/chrome/browser/ntp_background_util.cc
index c6682d0..297a0f0 100644
--- a/chrome/browser/ntp_background_util.cc
+++ b/chrome/browser/ntp_background_util.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/ntp_background_util.h"
+#include <cmath>
+
#include "base/logging.h"
#include "chrome/browser/themes/theme_service.h"
#include "grit/theme_resources.h"
@@ -22,15 +24,22 @@ void PaintThemeBackground(
int width = area.width() + ntp_background->width();
int height = area.height() + ntp_background->height();
- if (alignment & ThemeService::ALIGN_BOTTOM)
+ if (alignment & ThemeService::ALIGN_BOTTOM) {
y_pos += area.height() + tab_contents_height - ntp_background->height();
+ } else if (alignment & ThemeService::ALIGN_TOP) {
+ // no op
+ } else { // ALIGN_CENTER
+ y_pos += std::floor(area.height() + tab_contents_height / 2.0 -
+ ntp_background->height() / 2.0 + 0.5);
+ }
if (alignment & ThemeService::ALIGN_RIGHT) {
x_pos += area.width() - ntp_background->width();
} else if (alignment & ThemeService::ALIGN_LEFT) {
// no op
} else { // ALIGN_CENTER
- x_pos += area.width() / 2 - ntp_background->width() / 2;
+ x_pos +=
+ std::floor(area.width() / 2.0 - ntp_background->width() / 2.0 + 0.5);
}
if (tiling != ThemeService::REPEAT &&
@@ -68,7 +77,7 @@ void NtpBackgroundUtil::PaintBackgroundDetachedMode(ui::ThemeProvider* tp,
tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_TILING, &tiling);
int alignment;
if (tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_ALIGNMENT,
- &alignment)) {
+ &alignment)) {
SkBitmap* ntp_background = tp->GetBitmapNamed(IDR_THEME_NTP_BACKGROUND);
PaintThemeBackground(
diff --git a/chrome/browser/resources/chromeos/guest_session_tab.html b/chrome/browser/resources/chromeos/guest_session_tab.html
index 5915b22..4eaa4f6 100644
--- a/chrome/browser/resources/chromeos/guest_session_tab.html
+++ b/chrome/browser/resources/chromeos/guest_session_tab.html
@@ -6,7 +6,7 @@
<script>
// Until themes can clear the cache, force-reload the theme stylesheet.
document.write('<link id="incognitothemecss" rel="stylesheet" ' +
- 'href="chrome://theme/css/newincognitotab.css?' +
+ 'href="chrome://theme/css/incognito_new_tab_theme.css?' +
Date.now() + '">');
</script>
</head>
@@ -19,7 +19,7 @@ document.write('<link id="incognitothemecss" rel="stylesheet" ' +
<script>
function themeChanged() {
document.getElementById('incognitothemecss').href =
- 'chrome://theme/css/newincognitotab.css?' + Date.now();
+ 'chrome://theme/css/incognito_new_tab_theme.css?' + Date.now();
}
</script>
</html>
diff --git a/chrome/browser/resources/incognito_tab.html b/chrome/browser/resources/incognito_tab.html
index 03dad1d..d2230e0 100644
--- a/chrome/browser/resources/incognito_tab.html
+++ b/chrome/browser/resources/incognito_tab.html
@@ -6,7 +6,7 @@
<script>
// Until themes can clear the cache, force-reload the theme stylesheet.
document.write('<link id="incognitothemecss" rel="stylesheet" ' +
- 'href="chrome://theme/css/newincognitotab.css?' +
+ 'href="chrome://theme/css/incognito_new_tab_theme.css?' +
Date.now() + '">');
</script>
</head>
@@ -23,7 +23,7 @@ document.write('<link id="incognitothemecss" rel="stylesheet" ' +
<script>
function themeChanged() {
document.getElementById('incognitothemecss').href =
- 'chrome://theme/css/newincognitotab.css?' + Date.now();
+ 'chrome://theme/css/incognito_new_tab_theme.css?' + Date.now();
}
function bookmarkBarAttached() {
diff --git a/chrome/browser/resources/ntp4/new_tab.html b/chrome/browser/resources/ntp4/new_tab.html
index 6730222..2bb06dd 100644
--- a/chrome/browser/resources/ntp4/new_tab.html
+++ b/chrome/browser/resources/ntp4/new_tab.html
@@ -3,7 +3,8 @@
dir:textdirection;
hasattribution:hasattribution;
customlogo:customlogo;
- themegravity:themegravity;"
+ themegravity:themegravity;
+ bookmarkbarattached:bookmarkbarattached;"
class="starting-up">
<head>
<meta charset="utf-8">
diff --git a/chrome/browser/resources/ntp4/new_tab.js b/chrome/browser/resources/ntp4/new_tab.js
index 621157e..4cdd44e 100644
--- a/chrome/browser/resources/ntp4/new_tab.js
+++ b/chrome/browser/resources/ntp4/new_tab.js
@@ -261,15 +261,22 @@ cr.define('ntp4', function() {
document.querySelector('head').appendChild(styleElement);
}
- // TODO(estade): rename newtab.css to new_tab_theme.css
- function themeChanged(hasAttribution) {
- $('themecss').href = 'chrome://theme/css/newtab.css?' + Date.now();
- if (typeof hasAttribution != 'undefined')
- document.documentElement.setAttribute('hasattribution', hasAttribution);
+ function themeChanged(opt_hasAttribution) {
+ $('themecss').href = 'chrome://theme/css/new_tab_theme.css?' + Date.now();
+
+ if (typeof opt_hasAttribution != 'undefined') {
+ document.documentElement.setAttribute('hasattribution',
+ opt_hasAttribution);
+ }
+
updateLogo();
updateAttribution();
}
+ function setBookmarkBarAttached(attached) {
+ document.documentElement.setAttribute('bookmarkbarattached', attached);
+ }
+
/**
* Sets the proper image for the logo at the bottom left.
*/
@@ -539,6 +546,7 @@ cr.define('ntp4', function() {
leaveRearrangeMode: leaveRearrangeMode,
saveAppPageName: saveAppPageName,
setAppToBeHighlighted: setAppToBeHighlighted,
+ setBookmarkBarAttached: setBookmarkBarAttached,
setMostVisitedPages: setMostVisitedPages,
setRecentlyClosedTabs: setRecentlyClosedTabs,
setStripeColor: setStripeColor,
diff --git a/chrome/browser/resources/ntp4/new_tab_theme.css b/chrome/browser/resources/ntp4/new_tab_theme.css
index cb0ab0f..cedbc3e 100644
--- a/chrome/browser/resources/ntp4/new_tab_theme.css
+++ b/chrome/browser/resources/ntp4/new_tab_theme.css
@@ -2,8 +2,7 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */
-html,
-#most-visited-settings {
+html {
background-attachment: fixed;
background-color: $2; /* COLOR_NTP_BACKGROUND */
background-image: url(chrome://theme/IDR_THEME_NTP_BACKGROUND?$1);
@@ -11,6 +10,10 @@ html,
background-repeat: $5;
}
+html[bookmarkbarattached='true'] {
+ background-position: $4;
+}
+
body {
color: $8; /* COLOR_NTP_TEXT */
height: 100%;
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc
index e0f8f15..910d176 100644
--- a/chrome/browser/themes/theme_service.cc
+++ b/chrome/browser/themes/theme_service.cc
@@ -29,6 +29,7 @@ using content::BrowserThread;
using content::UserMetricsAction;
// Strings used in alignment properties.
+const char* ThemeService::kAlignmentCenter = "center";
const char* ThemeService::kAlignmentTop = "top";
const char* ThemeService::kAlignmentBottom = "bottom";
const char* ThemeService::kAlignmentLeft = "left";
@@ -377,8 +378,8 @@ std::string ThemeService::GetThemeID() const {
// static
std::string ThemeService::AlignmentToString(int alignment) {
// Convert from an AlignmentProperty back into a string.
- std::string vertical_string;
- std::string horizontal_string;
+ std::string vertical_string(kAlignmentCenter);
+ std::string horizontal_string(kAlignmentCenter);
if (alignment & ThemeService::ALIGN_TOP)
vertical_string = kAlignmentTop;
@@ -390,11 +391,7 @@ std::string ThemeService::AlignmentToString(int alignment) {
else if (alignment & ThemeService::ALIGN_RIGHT)
horizontal_string = kAlignmentRight;
- if (vertical_string.empty())
- return horizontal_string;
- if (horizontal_string.empty())
- return vertical_string;
- return vertical_string + " " + horizontal_string;
+ return horizontal_string + " " + vertical_string;
}
// static
diff --git a/chrome/browser/themes/theme_service.h b/chrome/browser/themes/theme_service.h
index 4ecde66..12964cf 100644
--- a/chrome/browser/themes/theme_service.h
+++ b/chrome/browser/themes/theme_service.h
@@ -52,6 +52,7 @@ class ThemeService : public base::NonThreadSafe,
// Public constants used in ThemeService and its subclasses:
// Strings used in alignment properties.
+ static const char* kAlignmentCenter;
static const char* kAlignmentTop;
static const char* kAlignmentBottom;
static const char* kAlignmentLeft;
diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc
index fe80f87..2a5e295 100644
--- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc
+++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc
@@ -133,6 +133,8 @@ NewTabUI::NewTabUI(content::WebUI* web_ui)
new NewTabHTMLSource(GetProfile()->GetOriginalProfile());
GetProfile()->GetChromeURLDataManager()->AddDataSource(html_source);
+ pref_change_registrar_.Init(GetProfile()->GetPrefs());
+ pref_change_registrar_.Add(prefs::kShowBookmarkBar, this);
// Listen for theme installation.
registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
content::Source<ThemeService>(
@@ -197,14 +199,19 @@ void NewTabUI::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
+ case chrome::NOTIFICATION_PREF_CHANGED: { // kShowBookmarkBar
+ StringValue attached(
+ GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ?
+ "true" : "false");
+ web_ui()->CallJavascriptFunction("ntp4.setBookmarkBarAttached", attached);
+ break;
+ }
case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: {
InitializeCSSCaches();
- ListValue args;
- args.Append(Value::CreateStringValue(
+ StringValue attribution(
ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage(
- IDR_THEME_NTP_ATTRIBUTION) ?
- "true" : "false"));
- web_ui()->CallJavascriptFunction("themeChanged", args);
+ IDR_THEME_NTP_ATTRIBUTION) ? "true" : "false");
+ web_ui()->CallJavascriptFunction("themeChanged", attribution);
break;
}
case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: {
@@ -244,7 +251,6 @@ void NewTabUI::SetupFieldTrials() {
g_hint_group = trial->AppendGroup("PlusIcon", 40);
}
-
// static
bool NewTabUI::ShouldShowWebStoreFooterLink() {
const CommandLine* cli = CommandLine::ForCurrentProcess();
diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.h b/chrome/browser/ui/webui/ntp/new_tab_ui.h
index 885e271..9cd11b5 100644
--- a/chrome/browser/ui/webui/ntp/new_tab_ui.h
+++ b/chrome/browser/ui/webui/ntp/new_tab_ui.h
@@ -11,6 +11,7 @@
#include "base/gtest_prod_util.h"
#include "base/time.h"
#include "base/timer.h"
+#include "chrome/browser/prefs/pref_change_registrar.h"
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "content/public/browser/notification_observer.h"
@@ -116,6 +117,8 @@ class NewTabUI : public content::WebUIController,
// If the sync promo NTP bubble is being shown.
bool showing_sync_bubble_;
+ PrefChangeRegistrar pref_change_registrar_;
+
DISALLOW_COPY_AND_ASSIGN(NewTabUI);
};
diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc
index 724ed32..7d18d9c 100644
--- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc
+++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc
@@ -141,9 +141,9 @@ std::string GetNewTabBackgroundCSS(const ui::ThemeProvider* theme_provider,
if (alignment & ThemeService::ALIGN_TOP) {
if (alignment & ThemeService::ALIGN_LEFT)
- return "0% " + base::IntToString(-offset) + "px";
+ return "left " + base::IntToString(-offset) + "px";
else if (alignment & ThemeService::ALIGN_RIGHT)
- return "100% " + base::IntToString(-offset) + "px";
+ return "right " + base::IntToString(-offset) + "px";
return "center " + base::IntToString(-offset) + "px";
}
return ThemeService::AlignmentToString(alignment);
diff --git a/chrome/browser/ui/webui/theme_source.cc b/chrome/browser/ui/webui/theme_source.cc
index bc07fff..1dda6ff 100644
--- a/chrome/browser/ui/webui/theme_source.cc
+++ b/chrome/browser/ui/webui/theme_source.cc
@@ -21,8 +21,8 @@
using content::BrowserThread;
// use a resource map rather than hard-coded strings.
-static const char* kNewTabCSSPath = "css/newtab.css";
-static const char* kNewIncognitoTabCSSPath = "css/newincognitotab.css";
+static const char* kNewTabCSSPath = "css/new_tab_theme.css";
+static const char* kNewIncognitoTabCSSPath = "css/incognito_new_tab_theme.css";
static std::string StripQueryParams(const std::string& path) {
GURL path_url = GURL(std::string(chrome::kChromeUIScheme) + "://" +