summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authorglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-02 20:53:50 +0000
committerglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-02 20:53:50 +0000
commit7895ea23e75075fd6f9fe5a6c3dfb17d3456b208 (patch)
treed9f36ade5222fbdab94c0b40f66b456f9eba308e /chrome/browser/dom_ui
parent77be37906a16c98612360a2e35c257aa5484cf2d (diff)
downloadchromium_src-7895ea23e75075fd6f9fe5a6c3dfb17d3456b208.zip
chromium_src-7895ea23e75075fd6f9fe5a6c3dfb17d3456b208.tar.gz
chromium_src-7895ea23e75075fd6f9fe5a6c3dfb17d3456b208.tar.bz2
Allow themes to change the background of the new tab page. Adds support for display properties to themes (stored internally as ints/enums, but parsed from text).
BUG=12768 TEST=Install a theme with an new tab page background and verify that the background appears on the new tab page. Review URL: http://codereview.chromium.org/115910 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17431 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/dom_ui_theme_source.cc36
-rw-r--r--chrome/browser/dom_ui/dom_ui_theme_source.h6
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc23
3 files changed, 61 insertions, 4 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc
index e00c4a8..41b3124 100644
--- a/chrome/browser/dom_ui/dom_ui_theme_source.cc
+++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc
@@ -20,6 +20,10 @@
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
+#if defined(OS_WIN)
+#include "chrome/browser/views/bookmark_bar_view.h"
+#endif
+
// Path for the New Tab CSS. When we get more than a few of these, we should
// use a resource map rather than hard-coded strings.
static const char* kNewTabCSSPath = "css/newtab.css";
@@ -85,6 +89,8 @@ void DOMUIThemeSource::SendNewTabCSS(int request_id) {
DCHECK(tp);
// Get our theme colors
+ SkColor color_background =
+ tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND);
SkColor color_text = tp->GetColor(BrowserThemeProvider::COLOR_NTP_TEXT);
SkColor color_link = tp->GetColor(BrowserThemeProvider::COLOR_NTP_LINK);
SkColor color_section =
@@ -98,6 +104,9 @@ void DOMUIThemeSource::SendNewTabCSS(int request_id) {
base::Time::Now().ToDoubleT()))));
// Colors.
+ subst.push_back(SkColorToRGBAString(color_background));
+ subst.push_back(UTF8ToUTF16(GetNewTabBackgroundCSS(false)));
+ subst.push_back(UTF8ToUTF16(GetNewTabBackgroundCSS(true)));
subst.push_back(SkColorToRGBAString(color_text));
subst.push_back(SkColorToRGBAString(color_link));
subst.push_back(SkColorToRGBAString(color_section));
@@ -134,3 +143,30 @@ void DOMUIThemeSource::SendThemeBitmap(int request_id, int resource_id) {
new RefCountedBytes(png_bytes);
SendResponse(request_id, image_data);
}
+
+std::string DOMUIThemeSource::GetNewTabBackgroundCSS(bool bar_attached) {
+ int alignment;
+ profile_->GetThemeProvider()->GetDisplayProperty(
+ BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT, &alignment);
+
+ if (bar_attached)
+ return BrowserThemeProvider::AlignmentToString(alignment);
+
+ // The bar is detached, so we must offset the background by the bar size
+ // if it's a top-aligned bar.
+#if defined(OS_WIN)
+ int offset = BookmarkBarView::kNewtabBarHeight;
+#else
+ int offset = 0;
+#endif
+
+ if (alignment & BrowserThemeProvider::ALIGN_TOP) {
+ if (alignment & BrowserThemeProvider::ALIGN_LEFT)
+ return "0% " + IntToString(-offset) + "px";
+ else if (alignment & BrowserThemeProvider::ALIGN_RIGHT)
+ return "100% " + IntToString(-offset) + "px";
+ return IntToString(-offset) + "px";
+ }
+ return BrowserThemeProvider::AlignmentToString(alignment);
+}
+
diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.h b/chrome/browser/dom_ui/dom_ui_theme_source.h
index 38eec59..e31e21b 100644
--- a/chrome/browser/dom_ui/dom_ui_theme_source.h
+++ b/chrome/browser/dom_ui/dom_ui_theme_source.h
@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_DOM_UI_DOM_UI_THEME_SOURCE_H_
#define CHROME_BROWSER_DOM_UI_DOM_UI_THEME_SOURCE_H_
+#include <string>
+
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
class Profile;
@@ -29,6 +31,10 @@ class DOMUIThemeSource : public ChromeURLDataManager::DataSource {
// Fetch and send the theme bitmap.
void SendThemeBitmap(int request_id, int resource_id);
+ // Get the CSS string for the background position on the new tab page for the
+ // states when the bar is attached or detached.
+ std::string GetNewTabBackgroundCSS(bool bar_attached);
+
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(DOMUIThemeSource);
};
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index 9765aa2..3ceca68 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -185,7 +185,7 @@ class PaintTimer : public RenderWidgetHost::PaintObserver {
class NewTabHTMLSource : public ChromeURLDataManager::DataSource {
public:
- NewTabHTMLSource();
+ explicit NewTabHTMLSource(Profile* profile);
// Called when the network layer has requested a resource underneath
// the path we registered.
@@ -209,13 +209,17 @@ class NewTabHTMLSource : public ChromeURLDataManager::DataSource {
// we think it is the user's startup page.
static bool first_view_;
+ // The user's profile.
+ Profile* profile_;
+
DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource);
};
bool NewTabHTMLSource::first_view_ = true;
-NewTabHTMLSource::NewTabHTMLSource()
- : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()) {
+NewTabHTMLSource::NewTabHTMLSource(Profile* profile)
+ : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()),
+ profile_(profile) {
}
void NewTabHTMLSource::StartDataRequest(const std::string& path,
@@ -245,6 +249,9 @@ void NewTabHTMLSource::StartDataRequest(const std::string& path,
profile_name);
}
DictionaryValue localized_strings;
+ localized_strings.SetString(L"bookmarkbarattached",
+ profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ?
+ "true" : "false");
localized_strings.SetString(L"title", title);
localized_strings.SetString(L"mostvisited", most_visited);
localized_strings.SetString(L"searches",
@@ -1226,7 +1233,7 @@ NewTabUI::NewTabUI(TabContents* contents)
&ChromeURLDataManager::AddDataSource,
new DOMUIThemeSource(GetProfile())));
- NewTabHTMLSource* html_source = new NewTabHTMLSource();
+ NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile());
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(&chrome_url_data_manager,
&ChromeURLDataManager::AddDataSource,
@@ -1237,6 +1244,9 @@ NewTabUI::NewTabUI(TabContents* contents)
// Listen for theme installation.
registrar_.Add(this, NotificationType::THEME_INSTALLED,
NotificationService::AllSources());
+ // Listen for bookmark bar visibility changes.
+ registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
+ NotificationService::AllSources());
}
NewTabUI::~NewTabUI() {
@@ -1247,6 +1257,11 @@ void NewTabUI::Observe(NotificationType type,
const NotificationDetails& details) {
if (NotificationType::THEME_INSTALLED == type) {
CallJavascriptFunction(L"themeChanged");
+ } else if (NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED) {
+ if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar))
+ CallJavascriptFunction(L"bookmarkBarAttached");
+ else
+ CallJavascriptFunction(L"bookmarkBarDetached");
}
}