diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-22 13:49:11 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-22 13:49:11 +0000 |
commit | 6af41783a8c4cca0bd846657aa0524c9b35f9bb3 (patch) | |
tree | b6b7634f33cf3b973e21926960268403f883d085 /chrome/browser/ui/browser_instant_controller.cc | |
parent | 17b9c748e2c155464f3d4ca89f267c75820cd00a (diff) | |
download | chromium_src-6af41783a8c4cca0bd846657aa0524c9b35f9bb3.zip chromium_src-6af41783a8c4cca0bd846657aa0524c9b35f9bb3.tar.gz chromium_src-6af41783a8c4cca0bd846657aa0524c9b35f9bb3.tar.bz2 |
Moved theme related state from BrowserInstantController to InstantService.
Created InstantServiceObserver to define an observer interface for InstantService. Registered InstantController as an InstantServiceObserver to get theme change events. We no longer send theme changed events on tab switch.
BUG=225760
TEST=Added an interactive ui test.
Review URL: https://chromiumcodereview.appspot.com/16413002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208023 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/browser_instant_controller.cc')
-rw-r--r-- | chrome/browser/ui/browser_instant_controller.cc | 121 |
1 files changed, 1 insertions, 120 deletions
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc index 0219145..30fcdec 100644 --- a/chrome/browser/ui/browser_instant_controller.cc +++ b/chrome/browser/ui/browser_instant_controller.cc @@ -15,9 +15,6 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/browser/themes/theme_properties.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_window.h" #include "chrome/browser/ui/omnibox/location_bar.h" @@ -26,17 +23,12 @@ #include "chrome/browser/ui/search/search_tab_helper.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" -#include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "components/user_prefs/pref_registry_syncable.h" -#include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/user_metrics.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" using content::UserMetricsAction; @@ -47,8 +39,7 @@ BrowserInstantController::BrowserInstantController(Browser* browser) : browser_(browser), instant_(this, chrome::IsInstantExtendedAPIEnabled()), - instant_unload_handler_(browser), - initialized_theme_info_(false) { + instant_unload_handler_(browser) { // TODO(sreeram): Perhaps this can be removed, if field trial info is // available before we need to register the pref. @@ -69,13 +60,6 @@ BrowserInstantController::BrowserInstantController(Browser* browser) base::Unretained(this))); ResetInstant(std::string()); 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(profile()))); -#endif // defined(ENABLE_THEMES) } BrowserInstantController::~BrowserInstantController() { @@ -234,15 +218,6 @@ void BrowserInstantController::TabDeactivated(content::WebContents* contents) { instant_.TabDeactivated(contents); } -void BrowserInstantController::UpdateThemeInfo() { - // Update theme background info. - // Initialize |theme_info| if necessary. - if (!initialized_theme_info_) - OnThemeChanged(ThemeServiceFactory::GetForProfile(profile())); - else - OnThemeChanged(NULL); -} - void BrowserInstantController::OpenURL( const GURL& url, content::PageTransition transition, @@ -289,10 +264,6 @@ void BrowserInstantController::ModelChanged( content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP")); } - // If mode is now |NTP|, send theme-related information to Instant. - if (new_mode.is_ntp()) - UpdateThemeInfo(); - instant_.SearchModeChanged(old_state.mode, new_mode); } @@ -300,96 +271,6 @@ void BrowserInstantController::ModelChanged( instant_.InstantSupportChanged(new_state.instant_support); } -//////////////////////////////////////////////////////////////////////////////// -// BrowserInstantController, content::NotificationObserver implementation: - -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::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(ThemeProperties::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 horizontal alignment. - int alignment = 0; - theme_service->GetDisplayProperty( - ThemeProperties::NTP_BACKGROUND_ALIGNMENT, &alignment); - if (alignment & ThemeProperties::ALIGN_LEFT) { - theme_info_.image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_LEFT; - } else if (alignment & ThemeProperties::ALIGN_RIGHT) { - theme_info_.image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_RIGHT; - } else { // ALIGN_CENTER - theme_info_.image_horizontal_alignment = - THEME_BKGRND_IMAGE_ALIGN_CENTER; - } - - // Set theme background image vertical alignment. - if (alignment & ThemeProperties::ALIGN_TOP) - theme_info_.image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_TOP; - else if (alignment & ThemeProperties::ALIGN_BOTTOM) - theme_info_.image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_BOTTOM; - else // ALIGN_CENTER - theme_info_.image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER; - - // Set theme background image tiling. - int tiling = 0; - theme_service->GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_TILING, - &tiling); - switch (tiling) { - case ThemeProperties::NO_REPEAT: - theme_info_.image_tiling = THEME_BKGRND_IMAGE_NO_REPEAT; - break; - case ThemeProperties::REPEAT_X: - theme_info_.image_tiling = THEME_BKGRND_IMAGE_REPEAT_X; - break; - case ThemeProperties::REPEAT_Y: - theme_info_.image_tiling = THEME_BKGRND_IMAGE_REPEAT_Y; - break; - case ThemeProperties::REPEAT: - theme_info_.image_tiling = THEME_BKGRND_IMAGE_REPEAT; - break; - } - - // Set theme background image height. - gfx::ImageSkia* image = theme_service->GetImageSkiaNamed( - IDR_THEME_NTP_BACKGROUND); - DCHECK(image); - theme_info_.image_height = image->height(); - - theme_info_.has_attribution = - theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); - } - - initialized_theme_info_ = true; - } - - DCHECK(initialized_theme_info_); - - if (browser_->search_model()->mode().is_ntp()) - instant_.ThemeChanged(theme_info_); -} - void BrowserInstantController::OnDefaultSearchProviderChanged( const std::string& pref_name) { DCHECK_EQ(pref_name, std::string(prefs::kDefaultSearchProviderID)); |