Index: chrome/browser/ui/browser_instant_controller.cc |
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc |
index 89ae408be8f9084d72c09ad2ae08b4e70596a89a..c4ed8b200f23e3bea2ab8be0bf6bf8acbb70d556 100644 |
--- a/chrome/browser/ui/browser_instant_controller.cc |
+++ b/chrome/browser/ui/browser_instant_controller.cc |
@@ -9,6 +9,8 @@ |
#include "chrome/browser/instant/instant_controller.h" |
#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/themes/theme_service.h" |
+#include "chrome/browser/themes/theme_service_factory.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_tabstrip.h" |
#include "chrome/browser/ui/browser_window.h" |
@@ -22,6 +24,10 @@ |
#include "chrome/common/pref_names.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/web_contents.h" |
+#include "grit/theme_resources.h" |
+#include "ui/gfx/color_utils.h" |
+#include "ui/gfx/sys_color_change_listener.h" |
+ |
namespace { |
@@ -45,12 +51,21 @@ namespace chrome { |
BrowserInstantController::BrowserInstantController(Browser* browser) |
: browser_(browser), |
- instant_unload_handler_(browser) { |
+ instant_unload_handler_(browser), |
+ initialized_theme_info_(false), |
+ theme_area_height_(0) { |
profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); |
profile_pref_registrar_.Add(prefs::kInstantEnabled, this); |
ResetInstant(); |
browser_->tab_strip_model()->AddObserver(this); |
browser_->search_model()->AddObserver(this); |
+ |
+#if defined(ENABLE_THEMES) |
+ // Listen for theme installation. |
+ registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
+ content::Source<ThemeService>( |
+ ThemeServiceFactory::GetForProfile(browser_->profile()))); |
+#endif // defined(ENABLE_THEMES) |
} |
BrowserInstantController::~BrowserInstantController() { |
@@ -119,6 +134,20 @@ TabContents* BrowserInstantController::GetActiveTabContents() const { |
return chrome::GetActiveTabContents(browser_); |
} |
+void BrowserInstantController::SetContentHeight(int height) { |
+ OnThemeAreaHeightChanged(height); |
+} |
+ |
+void BrowserInstantController::UpdateThemeInfoForPreview() { |
+ // Update theme background info and theme area height. |
+ // Initialize |theme_info| if necessary. |
+ // |OnThemeChanged| also updates theme area height if necessary. |
+ if (!initialized_theme_info_) |
+ OnThemeChanged(ThemeServiceFactory::GetForProfile(browser_->profile())); |
+ else |
+ OnThemeChanged(NULL); |
+} |
+ |
//////////////////////////////////////////////////////////////////////////////// |
// BrowserInstantController, PrefObserver implementation: |
@@ -156,13 +185,28 @@ void BrowserInstantController::TabStripEmpty() { |
void BrowserInstantController::ModeChanged(const search::Mode& old_mode, |
const search::Mode& new_mode) { |
- if (instant()) |
+ if (instant()) { |
instant_->OnActiveTabModeChanged(new_mode); |
+ |
+ // If mode is now |NTP|, send theme-related information to instant. |
+ if (new_mode.is_ntp()) |
+ UpdateThemeInfoForPreview(); |
+ } |
} |
//////////////////////////////////////////////////////////////////////////////// |
// BrowserInstantController, private: |
+void BrowserInstantController::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+#if defined(ENABLE_THEMES) |
+ DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); |
+ OnThemeChanged(content::Source<ThemeService>(source).ptr()); |
+#endif // defined(ENABLE_THEMES) |
+} |
+ |
void BrowserInstantController::ResetInstant() { |
instant_.reset( |
!browser_shutdown::ShuttingDownWithoutClosingBrowsers() && |
@@ -176,4 +220,66 @@ void BrowserInstantController::ResetInstant() { |
content::NotificationService::NoDetails()); |
} |
+void BrowserInstantController::OnThemeChanged(ThemeService* theme_service) { |
+ if (theme_service) { // Get theme information from theme service. |
+ theme_info_ = ThemeBackgroundInfo(); |
+ |
+ // Set theme background color. |
+ SkColor background_color = |
+ theme_service->GetColor(ThemeService::COLOR_NTP_BACKGROUND); |
+ if (gfx::IsInvertedColorScheme()) |
+ background_color = color_utils::InvertColor(background_color); |
+ theme_info_.color_r = SkColorGetR(background_color); |
+ theme_info_.color_g = SkColorGetG(background_color); |
+ theme_info_.color_b = SkColorGetB(background_color); |
+ theme_info_.color_a = SkColorGetA(background_color); |
+ |
+ if (theme_service->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { |
+ // Set theme id for theme background image url. |
+ theme_info_.theme_id = theme_service->GetThemeID(); |
+ |
+ // Set theme background image alignment. |
+ theme_service->GetDisplayProperty(ThemeService::NTP_BACKGROUND_ALIGNMENT, |
+ &theme_info_.image_alignment); |
+ |
+ // Set theme background image tiling. |
+ theme_service->GetDisplayProperty(ThemeService::NTP_BACKGROUND_TILING, |
+ &theme_info_.image_tiling); |
+ |
+ // Set theme background image height. |
+ gfx::ImageSkia* image = theme_service->GetImageSkiaNamed( |
+ IDR_THEME_NTP_BACKGROUND); |
+ DCHECK(image); |
+ theme_info_.image_height = image->height(); |
+ } |
+ |
+ initialized_theme_info_ = true; |
+ } |
+ |
+ DCHECK(initialized_theme_info_); |
+ |
+ if (instant() && browser_->search_model()->mode().is_ntp()) { |
+ instant_->ThemeChanged(theme_info_); |
+ |
+ // Theme area height is only sent to preview for non-top-aligned images; |
+ // new theme may have a different alignment that requires preview to know |
+ // theme area height. |
+ OnThemeAreaHeightChanged(theme_area_height_); |
+ } |
+} |
+ |
+void BrowserInstantController::OnThemeAreaHeightChanged(int height) { |
+ theme_area_height_ = height; |
+ |
+ // Notify preview only if mode is |NTP| and theme background image is not top- |
+ // aligned; top-aligned images don't need theme area height to determine which |
+ // part of the image overlay should draw, 'cos the origin is top-left. |
+ if (!instant() || !browser_->search_model()->mode().is_ntp() || |
+ theme_info_.theme_id.empty() || |
+ theme_info_.image_alignment & ThemeService::ALIGN_TOP) { |
+ return; |
+ } |
+ instant_->ThemeAreaHeightChanged(theme_area_height_); |
+} |
+ |
} // namespace chrome |