diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-02 20:53:50 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-02 20:53:50 +0000 |
commit | 7895ea23e75075fd6f9fe5a6c3dfb17d3456b208 (patch) | |
tree | d9f36ade5222fbdab94c0b40f66b456f9eba308e | |
parent | 77be37906a16c98612360a2e35c257aa5484cf2d (diff) | |
download | chromium_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
-rw-r--r-- | app/theme_provider.h | 4 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.cc | 221 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.h | 30 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_theme_source.cc | 36 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_theme_source.h | 6 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 23 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 1 | ||||
-rw-r--r-- | chrome/browser/resources/new_tab.html | 14 | ||||
-rw-r--r-- | chrome/browser/resources/new_tab_theme.css | 20 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.cc | 30 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.h | 2 | ||||
-rw-r--r-- | chrome/common/extensions/extension.cc | 8 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 7 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 2 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 1 | ||||
-rw-r--r-- | views/widget/default_theme_provider.cc | 4 | ||||
-rw-r--r-- | views/widget/default_theme_provider.h | 1 |
17 files changed, 344 insertions, 66 deletions
diff --git a/app/theme_provider.h b/app/theme_provider.h index 132a121..70d374b 100644 --- a/app/theme_provider.h +++ b/app/theme_provider.h @@ -34,6 +34,10 @@ class ThemeProvider { // Get the color specified by |id|. virtual SkColor GetColor(int id) = 0; + // Get the property (e.g. an alignment expressed in an enum, or a width or + // height) specified by |id|. + virtual bool GetDisplayProperty(int id, int* result) = 0; + // Whether we should use the native system frame (typically Aero glass) or // a custom frame. virtual bool ShouldUseNativeFrame() = 0; diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc index 80fa7f2..ce59a42 100644 --- a/chrome/browser/browser_theme_provider.cc +++ b/chrome/browser/browser_theme_provider.cc @@ -36,6 +36,7 @@ static const char* kColorToolbar = "toolbar"; static const char* kColorTabText = "tab_text"; static const char* kColorBackgroundTabText = "background_tab_text"; static const char* kColorBookmarkText = "bookmark_text"; +static const char* kColorNTPBackground = "ntp_background"; static const char* kColorNTPText = "ntp_text"; static const char* kColorNTPLink = "ntp_link"; static const char* kColorNTPSection = "ntp_section"; @@ -51,6 +52,15 @@ static const char* kTintFrameIncognitoInactive = "frame_incognito_inactive"; static const char* kTintBackgroundTab = "background_tab"; +// Strings used by themes to identify miscellaneous numerical properties. +static const char* kDisplayPropertyNTPAlignment = "ntp_background_alignment"; + +// Strings used in alignment properties. +static const char* kAlignmentTop = "top"; +static const char* kAlignmentBottom = "bottom"; +static const char* kAlignmentLeft = "left"; +static const char* kAlignmentRight = "right"; + // Default colors. static const SkColor kDefaultColorFrame = SkColorSetRGB(77, 139, 217); static const SkColor kDefaultColorFrameInactive = SkColorSetRGB(152, 188, 233); @@ -61,6 +71,7 @@ static const SkColor kDefaultColorToolbar = SkColorSetRGB(210, 225, 246); static const SkColor kDefaultColorTabText = SkColorSetRGB(0, 0, 0); static const SkColor kDefaultColorBackgroundTabText = SkColorSetRGB(64, 64, 64); static const SkColor kDefaultColorBookmarkText = SkColorSetRGB(64, 64, 64); +static const SkColor kDefaultColorNTPBackground = SkColorSetRGB(255, 255, 255); static const SkColor kDefaultColorNTPText = SkColorSetRGB(0, 0, 0); static const SkColor kDefaultColorNTPLink = SkColorSetRGB(0, 0, 204); static const SkColor kDefaultColorNTPSection = SkColorSetRGB(225, 236, 254); @@ -73,6 +84,10 @@ static const skia::HSL kDefaultTintFrameIncognito = { -1, 0.2f, 0.35f }; static const skia::HSL kDefaultTintFrameIncognitoInactive = { -1, 0.3f, 0.6f }; static const skia::HSL kDefaultTintBackgroundTab = { -1, 0.5, 0.75 }; +// Default display properties. +static const int kDefaultDisplayPropertyNTPAlignment = + BrowserThemeProvider::ALIGN_BOTTOM; + // The image resources that will be tinted by the 'button' tint value. static const int kToolbarButtonIDs[] = { IDR_BACK, IDR_BACK_D, IDR_BACK_H, IDR_BACK_P, @@ -200,6 +215,10 @@ SkColor BrowserThemeProvider::GetColor(int id) { return (colors_.find(kColorBookmarkText) != colors_.end()) ? colors_[kColorBookmarkText] : kDefaultColorBookmarkText; + case COLOR_NTP_BACKGROUND: + return (colors_.find(kColorNTPBackground) != colors_.end()) ? + colors_[kColorNTPBackground] : + kDefaultColorNTPBackground; case COLOR_NTP_TEXT: return (colors_.find(kColorNTPText) != colors_.end()) ? colors_[kColorNTPText] : @@ -220,6 +239,22 @@ SkColor BrowserThemeProvider::GetColor(int id) { return 0xffff0000; } +bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) { + switch (id) { + case NTP_BACKGROUND_ALIGNMENT: + if (display_properties_.find(kDisplayPropertyNTPAlignment) != + display_properties_.end()) { + *result = display_properties_[kDisplayPropertyNTPAlignment]; + } else { + *result = kDefaultDisplayPropertyNTPAlignment; + } + return true; + default: + NOTREACHED() << "Unknown property requested"; + } + return false; +} + bool BrowserThemeProvider::ShouldUseNativeFrame() { if (images_.find(IDR_THEME_FRAME) != images_.end()) return false; @@ -240,12 +275,14 @@ void BrowserThemeProvider::SetTheme(Extension* extension) { extension->path()); SetColorData(extension->GetThemeColors()); SetTintData(extension->GetThemeTints()); + SetDisplayPropertyData(extension->GetThemeDisplayProperties()); GenerateFrameColors(); GenerateFrameImages(); SaveImageData(extension->GetThemeImages()); SaveColorData(); SaveTintData(); + SaveDisplayPropertyData(); NotifyThemeChanged(); UserMetrics::RecordAction(L"Themes_Installed", profile_); @@ -258,12 +295,15 @@ void BrowserThemeProvider::UseDefaultTheme() { images_.clear(); colors_.clear(); tints_.clear(); + display_properties_.clear(); SaveImageData(NULL); SaveColorData(); SaveTintData(); + SaveDisplayPropertyData(); NotifyThemeChanged(); + UserMetrics::RecordAction(L"Themes_Reset", profile_); } SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { @@ -355,67 +395,140 @@ void BrowserThemeProvider::SetImageData(DictionaryValue* images_value, FilePath images_path) { images_.clear(); - if (images_value) { - DictionaryValue::key_iterator iter = images_value->begin_keys(); - while (iter != images_value->end_keys()) { - std::string val; - if (images_value->GetString(*iter, &val)) { - int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); - if (id != -1) { - if (!images_path.empty()) { - images_[id] = WideToUTF8(images_path.AppendASCII(val) - .ToWStringHack()); - } else { - images_[id] = val; - } + if (!images_value) + return; + + DictionaryValue::key_iterator iter = images_value->begin_keys(); + while (iter != images_value->end_keys()) { + std::string val; + if (images_value->GetString(*iter, &val)) { + int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); + if (id != -1) { + if (!images_path.empty()) { + images_[id] = WideToUTF8(images_path.AppendASCII(val) + .ToWStringHack()); + } else { + images_[id] = val; } } - ++iter; } + ++iter; } } void BrowserThemeProvider::SetColorData(DictionaryValue* colors_value) { colors_.clear(); - if (colors_value) { - DictionaryValue::key_iterator iter = colors_value->begin_keys(); - while (iter != colors_value->end_keys()) { - ListValue* color_list; - if (colors_value->GetList(*iter, &color_list) && - color_list->GetSize() == 3) { - int r, g, b; - color_list->GetInteger(0, &r); - color_list->GetInteger(1, &g); - color_list->GetInteger(2, &b); - colors_[WideToUTF8(*iter)] = SkColorSetRGB(r, g, b); - } - ++iter; + if (!colors_value) + return; + + DictionaryValue::key_iterator iter = colors_value->begin_keys(); + while (iter != colors_value->end_keys()) { + ListValue* color_list; + if (colors_value->GetList(*iter, &color_list) && + color_list->GetSize() == 3) { + int r, g, b; + color_list->GetInteger(0, &r); + color_list->GetInteger(1, &g); + color_list->GetInteger(2, &b); + colors_[WideToUTF8(*iter)] = SkColorSetRGB(r, g, b); } + ++iter; } } void BrowserThemeProvider::SetTintData(DictionaryValue* tints_value) { tints_.clear(); - if (tints_value) { - DictionaryValue::key_iterator iter = tints_value->begin_keys(); - while (iter != tints_value->end_keys()) { - ListValue* tint_list; - if (tints_value->GetList(*iter, &tint_list) && - tint_list->GetSize() == 3) { - skia::HSL hsl = { -1, -1, -1 }; - // TODO(glen): Make this work with integer values. - tint_list->GetReal(0, &hsl.h); - tint_list->GetReal(1, &hsl.s); - tint_list->GetReal(2, &hsl.l); - tints_[WideToUTF8(*iter)] = hsl; - } - ++iter; + if (!tints_value) + return; + + DictionaryValue::key_iterator iter = tints_value->begin_keys(); + while (iter != tints_value->end_keys()) { + ListValue* tint_list; + if (tints_value->GetList(*iter, &tint_list) && + tint_list->GetSize() == 3) { + skia::HSL hsl = { -1, -1, -1 }; + // TODO(glen): Make this work with integer values. + tint_list->GetReal(0, &hsl.h); + tint_list->GetReal(1, &hsl.s); + tint_list->GetReal(2, &hsl.l); + tints_[WideToUTF8(*iter)] = hsl; + } + ++iter; + } +} + +void BrowserThemeProvider::SetDisplayPropertyData( + DictionaryValue* display_properties_value) { + display_properties_.clear(); + + if (!display_properties_value) + return; + + DictionaryValue::key_iterator iter = display_properties_value->begin_keys(); + while (iter != display_properties_value->end_keys()) { + // New tab page alignment. + if (base::strcasecmp(WideToUTF8(*iter).c_str(), + kDisplayPropertyNTPAlignment) == 0) { + std::string val; + if (display_properties_value->GetString(*iter, &val)) + display_properties_[kDisplayPropertyNTPAlignment] = + StringToAlignment(val); } + ++iter; } } +// static +int BrowserThemeProvider::StringToAlignment(const std::string& alignment) { + std::vector<std::wstring> split; + SplitStringAlongWhitespace(UTF8ToWide(alignment), &split); + + std::vector<std::wstring>::iterator alignments = split.begin(); + int alignment_mask = 0; + while (alignments != split.end()) { + std::string comp = WideToUTF8(*alignments); + const char* component = comp.c_str(); + + if (base::strcasecmp(component, kAlignmentTop) == 0) + alignment_mask |= BrowserThemeProvider::ALIGN_TOP; + else if (base::strcasecmp(component, kAlignmentBottom) == 0) + alignment_mask |= BrowserThemeProvider::ALIGN_BOTTOM; + + if (base::strcasecmp(component, kAlignmentLeft) == 0) + alignment_mask |= BrowserThemeProvider::ALIGN_LEFT; + else if (base::strcasecmp(component, kAlignmentRight) == 0) + alignment_mask |= BrowserThemeProvider::ALIGN_RIGHT; + alignments++; + } + return alignment_mask; +} + +// static +std::string BrowserThemeProvider::AlignmentToString(int alignment) { + // Convert from an AlignmentProperty back into a string. + std::string vertical_string; + std::string horizontal_string; + + if (alignment & BrowserThemeProvider::ALIGN_TOP) + vertical_string = kAlignmentTop; + else if (alignment & BrowserThemeProvider::ALIGN_BOTTOM) + vertical_string = kAlignmentBottom; + + if (alignment & BrowserThemeProvider::ALIGN_LEFT) + horizontal_string = kAlignmentLeft; + else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) + horizontal_string = kAlignmentRight; + + if (!vertical_string.empty() && !horizontal_string.empty()) + return vertical_string + " " + horizontal_string; + else if (vertical_string.empty()) + return horizontal_string; + else + return vertical_string; +} + void BrowserThemeProvider::GenerateFrameColors() { // Generate any secondary frame colors that weren't provided. skia::HSL frame_hsl = { 0, 0, 0 }; @@ -495,9 +608,6 @@ SkBitmap* BrowserThemeProvider::GenerateBitmap(int id) { } void BrowserThemeProvider::NotifyThemeChanged() { - // TODO(glen): If we're in glass and IDR_THEME_FRAME has been provided, - // swap us back to opaque frame. - // Redraw! for (BrowserList::const_iterator browser = BrowserList::begin(); browser != BrowserList::end(); ++browser) { @@ -519,6 +629,8 @@ void BrowserThemeProvider::LoadThemePrefs() { FilePath()); SetColorData(prefs->GetMutableDictionary(prefs::kCurrentThemeColors)); SetTintData(prefs->GetMutableDictionary(prefs::kCurrentThemeTints)); + SetDisplayPropertyData(prefs->GetMutableDictionary( + prefs::kCurrentThemeDisplayProperties)); GenerateFrameColors(); GenerateFrameImages(); UserMetrics::RecordAction(L"Themes_loaded", profile_); @@ -583,6 +695,27 @@ void BrowserThemeProvider::SaveTintData() { } } +void BrowserThemeProvider::SaveDisplayPropertyData() { + // Save our display property data. + DictionaryValue* pref_display_properties = + profile_->GetPrefs()-> + GetMutableDictionary(prefs::kCurrentThemeDisplayProperties); + pref_display_properties->Clear(); + + if (display_properties_.size()) { + DisplayPropertyMap::iterator iter = display_properties_.begin(); + while (iter != display_properties_.end()) { + if (base::strcasecmp((*iter).first.c_str(), + kDisplayPropertyNTPAlignment) == 0) { + pref_display_properties-> + SetString(UTF8ToWide((*iter).first), AlignmentToString( + (*iter).second)); + } + ++iter; + } + } +} + void BrowserThemeProvider::FreeImages() { for (std::vector<SkBitmap*>::iterator i = generated_images_.begin(); i != generated_images_.end(); i++) { diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h index 9565ad4..3280e1c 100644 --- a/chrome/browser/browser_theme_provider.h +++ b/chrome/browser/browser_theme_provider.h @@ -40,6 +40,7 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, COLOR_TAB_TEXT, COLOR_BACKGROUND_TAB_TEXT, COLOR_BOOKMARK_TEXT, + COLOR_NTP_BACKGROUND, COLOR_NTP_TEXT, COLOR_NTP_LINK, COLOR_NTP_SECTION, @@ -48,14 +49,25 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, TINT_FRAME_INACTIVE, TINT_FRAME_INCOGNITO, TINT_FRAME_INCOGNITO_INACTIVE, - TINT_BACKGROUND_TAB + TINT_BACKGROUND_TAB, + NTP_BACKGROUND_ALIGNMENT }; + // A bitfield mask for alignments. + typedef enum { + ALIGN_CENTER = 0x0, + ALIGN_LEFT = 0x1, + ALIGN_TOP = 0x2, + ALIGN_RIGHT = 0x4, + ALIGN_BOTTOM = 0x8, + } AlignmentMasks; + void Init(Profile* profile); // ThemeProvider implementation. virtual SkBitmap* GetBitmapNamed(int id); virtual SkColor GetColor(int id); + virtual bool GetDisplayProperty(int id, int* result); virtual bool ShouldUseNativeFrame(); #if defined(OS_LINUX) virtual GdkPixbuf* GetPixbufNamed(int id); @@ -67,10 +79,19 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, // Reset the theme to default. void UseDefaultTheme(); + // Convert a bitfield alignment into a string like "top left". Public so that + // it can be used to generate CSS values. Takes a bitfield of AlignmentMasks. + static std::string AlignmentToString(int alignment); + + // Parse alignments from something like "top left" into a bitfield of + // AlignmentMasks + static int StringToAlignment(const std::string &alignment); + private: typedef std::map<const int, std::string> ImageMap; typedef std::map<const std::string, SkColor> ColorMap; typedef std::map<const std::string, skia::HSL> TintMap; + typedef std::map<const std::string, int> DisplayPropertyMap; // Loads a bitmap from the theme, which may be tinted or // otherwise modified, or an application default. @@ -94,11 +115,16 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, // constants, and the values are a three-item list containing 8-bit // RGB values. void SetColorData(DictionaryValue* colors); + // Set tint data for our images and colors. The keys of |tints| are // any of the kTint* contstants, and the values are a three-item list // containing real numbers in the range 0-1 (and -1 for 'null'). void SetTintData(DictionaryValue* tints); + // Set miscellaneous display properties. While these can be defined as + // strings, they are currently stored as integers. + void SetDisplayPropertyData(DictionaryValue* display_properties); + // Generate any frame colors that weren't specified. void GenerateFrameColors(); @@ -114,6 +140,7 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, void SaveImageData(DictionaryValue* images); void SaveColorData(); void SaveTintData(); + void SaveDisplayPropertyData(); // Let all the browser views know that themes have changed. void NotifyThemeChanged(); @@ -143,6 +170,7 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, ImageMap images_; ColorMap colors_; TintMap tints_; + DisplayPropertyMap display_properties_; DISALLOW_COPY_AND_ASSIGN(BrowserThemeProvider); }; 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"); } } diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 6269d36..c859c02 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -75,6 +75,7 @@ void Profile::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages); prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors); prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints); + prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties); prefs->RegisterBooleanPref(prefs::kEnableExtensions, false); } diff --git a/chrome/browser/resources/new_tab.html b/chrome/browser/resources/new_tab.html index 7cc0204..8ee1e2f 100644 --- a/chrome/browser/resources/new_tab.html +++ b/chrome/browser/resources/new_tab.html @@ -1,5 +1,5 @@ <!DOCTYPE HTML> -<html id="t" jsvalues="dir:textdirection;firstview:firstview"> +<html id="t" jsvalues="dir:textdirection;firstview:firstview;bookmarkbarattached:bookmarkbarattached;"> <!-- This page is optimized for perceived performance. Our enemies are the time taken for the backend to generate our data, and the time taken to parse @@ -134,9 +134,7 @@ html { height:100%; } body { - background-color:white; margin:0px; - background-repeat:repeat-x; } html[firstview='true'] #main { opacity:0.0; @@ -440,7 +438,7 @@ document.addEventListener('DOMContentLoaded', handleDOMContentLoaded); <iframe id="p13n" frameborder="0" width="100%" scrolling="no" height="0" jsdisplay="p13nsrc" style="display:none;" jsvalues="src:p13nsrc"></iframe> - <div id="searches" class="sidebar"> + <div id="searches" class="sidebar themed"> <div class="section-title" jscontent="searches"></div> <form onsubmit="chrome.send('searchHistoryPage', [this.search.value]); return false;"> <input type="text" class="hint" @@ -937,6 +935,14 @@ function themeChanged() { $('themecss').href = 'chrome://theme/css/newtab.css?' + Date.now(); } +function bookmarkBarAttached() { + document.documentElement.setAttribute("bookmarkbarattached", "true"); +} + +function bookmarkBarDetached() { + document.documentElement.setAttribute("bookmarkbarattached", "false"); +} + function viewLog() { var lines = []; var start = log[0][1]; diff --git a/chrome/browser/resources/new_tab_theme.css b/chrome/browser/resources/new_tab_theme.css index 0c28c46..3776cfe 100644 --- a/chrome/browser/resources/new_tab_theme.css +++ b/chrome/browser/resources/new_tab_theme.css @@ -1,11 +1,21 @@ -body { +html { background-image:url(chrome://theme/theme_ntp_background?$1); - background-position:bottom; - color: $2; + background-color:$2; + background-position:$3; + background-repeat:no-repeat; + overflow:hidden; +} +html[bookmarkbarattached='true'] { + background-position:$4; +} +body { + color: $5; + height:100%; + overflow:auto; } a { - color: $3; + color: $6; } .sidebar.themed { - background-color: $4; + background-color: $7; }
\ No newline at end of file diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index 5621a83..f151625 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -68,7 +68,7 @@ static const int kRightMargin = 1; static const int kBarHeight = 29; // Preferred height of the bookmarks bar when only shown on the new tab page. -static const int kNewtabBarHeight = 57; +const int BookmarkBarView::kNewtabBarHeight = 57; // How inset the bookmarks bar is when displayed on the new tab page. This is // in addition to the margins above. @@ -90,11 +90,6 @@ static SkBitmap* kFolderIcon = NULL; // Border colors for the BookmarBarView. static const SkColor kTopBorderColor = SkColorSetRGB(222, 234, 248); -// Background color for when the bookmarks bar is only being displayed on the -// new tab page - this color should match the background color of the new tab -// page (white, most likely). -static const SkColor kNewtabBackgroundColor = SkColorSetRGB(255, 255, 255); - // Border color for the 'new tab' style bookmarks bar. static const SkColor kNewtabBorderColor = SkColorSetRGB(195, 206, 224); @@ -564,7 +559,28 @@ void BookmarkBarView::ViewHierarchyChanged(bool is_add, void BookmarkBarView::Paint(gfx::Canvas* canvas) { if (IsDetachedStyle()) { // Draw the background to match the new tab page. - canvas->FillRectInt(kNewtabBackgroundColor, 0, 0, width(), height()); + ThemeProvider* tp = GetThemeProvider(); + canvas->FillRectInt( + tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND), + 0, 0, width(), height()); + + int alignment; + if (tp->GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT, + &alignment)) { + if (alignment & BrowserThemeProvider::ALIGN_TOP) { + SkBitmap* ntp_background = tp->GetBitmapNamed(IDR_THEME_NTP_BACKGROUND); + + if (alignment & BrowserThemeProvider::ALIGN_LEFT) { + canvas->DrawBitmapInt(*ntp_background, 0, 0); + } else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) { + canvas->DrawBitmapInt(*ntp_background, width() - + ntp_background->width(), 0); + } else { + canvas->DrawBitmapInt(*ntp_background, width() / 2- + ntp_background->width() / 2, 0); + } + } + } // Draw the 'bottom' of the toolbar above our bubble. canvas->FillRectInt(ResourceBundle::toolbar_separator_color, diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h index c32951c..23f98e3 100644 --- a/chrome/browser/views/bookmark_bar_view.h +++ b/chrome/browser/views/bookmark_bar_view.h @@ -67,6 +67,8 @@ class BookmarkBarView : public views::View, virtual void ModelChanged() = 0; }; + static const int kNewtabBarHeight; + explicit BookmarkBarView(Profile* profile, Browser* browser); virtual ~BookmarkBarView(); diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index cdf484b..4c2914e 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -34,6 +34,7 @@ const wchar_t* Extension::kThemeKey = L"theme"; const wchar_t* Extension::kThemeImagesKey = L"images"; const wchar_t* Extension::kThemeColorsKey = L"colors"; const wchar_t* Extension::kThemeTintsKey = L"tints"; +const wchar_t* Extension::kThemeDisplayPropertiesKey = L"properties"; const wchar_t* Extension::kToolstripsKey = L"toolstrips"; const wchar_t* Extension::kTooltipKey = L"tooltip"; const wchar_t* Extension::kTypeKey = L"type"; @@ -577,6 +578,13 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, static_cast<DictionaryValue*>(tints_value->DeepCopy())); } + DictionaryValue* display_properties_value; + if (theme_value->GetDictionary(kThemeDisplayPropertiesKey, + &display_properties_value)) { + theme_display_properties_.reset( + static_cast<DictionaryValue*>(display_properties_value->DeepCopy())); + } + return true; } diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 1256b17f..782b823 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -51,6 +51,7 @@ class Extension { static const wchar_t* kThemeImagesKey; static const wchar_t* kThemeColorsKey; static const wchar_t* kThemeTintsKey; + static const wchar_t* kThemeDisplayPropertiesKey; static const wchar_t* kToolstripsKey; static const wchar_t* kTooltipKey; static const wchar_t* kTypeKey; @@ -161,6 +162,9 @@ class Extension { DictionaryValue* GetThemeImages() const { return theme_images_.get(); } DictionaryValue* GetThemeColors() const { return theme_colors_.get(); } DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } + DictionaryValue* GetThemeDisplayProperties() const { + return theme_display_properties_.get(); + } bool IsTheme() { return is_theme_; } private: @@ -238,6 +242,9 @@ class Extension { // A map of color names to colors. scoped_ptr<DictionaryValue> theme_tints_; + // A map of display properties. + scoped_ptr<DictionaryValue> theme_display_properties_; + // Whether the extension is a theme - if it is, certain things are disabled. bool is_theme_; diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 9dd08c8..3ef102c 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -250,6 +250,8 @@ const wchar_t kCurrentThemeID[] = L"extensions.theme.id"; const wchar_t kCurrentThemeImages[] = L"extensions.theme.images"; const wchar_t kCurrentThemeColors[] = L"extensions.theme.colors"; const wchar_t kCurrentThemeTints[] = L"extensions.theme.tints"; +const wchar_t kCurrentThemeDisplayProperties[] = + L"extensions.theme.display_properties"; // Boolean that indicates whether we should check if we are the default browser // on start-up. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 5979204..2114b0b 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -92,6 +92,7 @@ extern const wchar_t kCurrentThemeID[]; extern const wchar_t kCurrentThemeImages[]; extern const wchar_t kCurrentThemeColors[]; extern const wchar_t kCurrentThemeTints[]; +extern const wchar_t kCurrentThemeDisplayProperties[]; extern const wchar_t kCheckDefaultBrowser[]; // Local state diff --git a/views/widget/default_theme_provider.cc b/views/widget/default_theme_provider.cc index d5b8e3d..b9b0ddf 100644 --- a/views/widget/default_theme_provider.cc +++ b/views/widget/default_theme_provider.cc @@ -21,6 +21,9 @@ SkColor DefaultThemeProvider::GetColor(int id) { return 0xff0000ff; } +bool DefaultThemeProvider::GetDisplayProperty(int id, int* result) { + return false; +} bool DefaultThemeProvider::ShouldUseNativeFrame() { #if defined(OS_WIN) return win_util::ShouldUseVistaFrame(); @@ -28,5 +31,4 @@ bool DefaultThemeProvider::ShouldUseNativeFrame() { return false; #endif } - } // namespace views diff --git a/views/widget/default_theme_provider.h b/views/widget/default_theme_provider.h index 879034f..f576bc6 100644 --- a/views/widget/default_theme_provider.h +++ b/views/widget/default_theme_provider.h @@ -20,6 +20,7 @@ class DefaultThemeProvider : public ThemeProvider { // Overridden from ThemeProvider. virtual SkBitmap* GetBitmapNamed(int id); virtual SkColor GetColor(int id); + virtual bool GetDisplayProperty(int id, int* result); virtual bool ShouldUseNativeFrame(); private: |