diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 02:31:02 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 02:31:02 +0000 |
commit | 6e853c3ad131fe6713ce8efbac2270fee26ab5b2 (patch) | |
tree | d0c9c8a5d1949cbdd108059add44b86b989514f4 /chrome/browser | |
parent | 26e99ffd2a4179aefe5dbf8cbd5da74c0bc7a76b (diff) | |
download | chromium_src-6e853c3ad131fe6713ce8efbac2270fee26ab5b2.zip chromium_src-6e853c3ad131fe6713ce8efbac2270fee26ab5b2.tar.gz chromium_src-6e853c3ad131fe6713ce8efbac2270fee26ab5b2.tar.bz2 |
Add ability to theme our buttons.
BUG=12762
TEST=Verify that buttons can be themed.
Review URL: http://codereview.chromium.org/119025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17586 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_theme_provider.cc | 125 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.h | 4 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.cc | 38 |
3 files changed, 97 insertions, 70 deletions
diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc index 86e0c3a..1fc1dea 100644 --- a/chrome/browser/browser_theme_provider.cc +++ b/chrome/browser/browser_theme_provider.cc @@ -41,6 +41,8 @@ static const char* kColorNTPBackground = "ntp_background"; static const char* kColorNTPText = "ntp_text"; static const char* kColorNTPLink = "ntp_link"; static const char* kColorNTPSection = "ntp_section"; +static const char* kColorControlBackground = "control_background"; +static const char* kColorButtonBackground = "button_background"; // Strings used by themes to identify tints to apply to different parts of // our UI. The frame tints apply to the frame color and produce the @@ -76,6 +78,8 @@ 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); +static const SkColor kDefaultColorControlBackground = NULL; +static const SkColor kDefaultColorButtonBackground = NULL; // Default tints. static const skia::HSL kDefaultTintButtons = { -1, -1, -1 }; @@ -190,48 +194,36 @@ SkColor BrowserThemeProvider::GetColor(int id) { // TODO(glen): Figure out if we need to tint these. http://crbug.com/11578 switch (id) { case COLOR_FRAME: - return (colors_.find(kColorFrame) != colors_.end()) ? - colors_[kColorFrame] : kDefaultColorFrame; + return FindColor(kColorFrame, kDefaultColorFrame); case COLOR_FRAME_INACTIVE: - return (colors_.find(kColorFrameInactive) != colors_.end()) ? - colors_[kColorFrameInactive] : kDefaultColorFrameInactive; + return FindColor(kColorFrameInactive, kDefaultColorFrameInactive); case COLOR_FRAME_INCOGNITO: - return (colors_.find(kColorFrameIncognito) != colors_.end()) ? - colors_[kColorFrameIncognito] : kDefaultColorFrameIncognito; + return FindColor(kColorFrameIncognito, kDefaultColorFrameIncognito); case COLOR_FRAME_INCOGNITO_INACTIVE: - return (colors_.find(kColorFrameIncognitoInactive) != colors_.end()) ? - colors_[kColorFrameIncognitoInactive] : - kDefaultColorFrameIncognitoInactive; + return FindColor(kColorFrameIncognitoInactive, + kDefaultColorFrameIncognitoInactive); case COLOR_TOOLBAR: - return (colors_.find(kColorToolbar) != colors_.end()) ? - colors_[kColorToolbar] : kDefaultColorToolbar; + return FindColor(kColorToolbar, kDefaultColorToolbar); case COLOR_TAB_TEXT: - return (colors_.find(kColorTabText) != colors_.end()) ? - colors_[kColorTabText] : kDefaultColorTabText; + return FindColor(kColorTabText, kDefaultColorTabText); case COLOR_BACKGROUND_TAB_TEXT: - return (colors_.find(kColorBackgroundTabText) != colors_.end()) ? - colors_[kColorBackgroundTabText] : - kDefaultColorBackgroundTabText; + return FindColor(kColorBackgroundTabText, kDefaultColorBackgroundTabText); case COLOR_BOOKMARK_TEXT: - return (colors_.find(kColorBookmarkText) != colors_.end()) ? - colors_[kColorBookmarkText] : - kDefaultColorBookmarkText; + return FindColor(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] : - kDefaultColorNTPText; + return FindColor(kColorNTPText, kDefaultColorNTPText); case COLOR_NTP_LINK: - return (colors_.find(kColorNTPLink) != colors_.end()) ? - colors_[kColorNTPLink] : - kDefaultColorNTPLink; + return FindColor(kColorNTPLink, kDefaultColorNTPLink); case COLOR_NTP_SECTION: - return (colors_.find(kColorNTPSection) != colors_.end()) ? - colors_[kColorNTPSection] : - kDefaultColorNTPSection; + return FindColor(kColorNTPSection, kDefaultColorNTPSection); + case COLOR_CONTROL_BACKGROUND: + return FindColor(kColorControlBackground, kDefaultColorControlBackground); + case COLOR_BUTTON_BACKGROUND: + return FindColor(kColorButtonBackground, kDefaultColorButtonBackground); default: NOTREACHED() << "Unknown color requested"; } @@ -427,12 +419,19 @@ void BrowserThemeProvider::SetColorData(DictionaryValue* colors_value) { while (iter != colors_value->end_keys()) { ListValue* color_list; if (colors_value->GetList(*iter, &color_list) && - color_list->GetSize() == 3) { + (color_list->GetSize() == 3 || color_list->GetSize() == 4)) { 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); + if (color_list->GetSize() == 4) { + double alpha; + color_list->GetReal(3, &alpha); + colors_[WideToUTF8(*iter)] = SkColorSetARGB( + static_cast<int>(alpha * 255), r, g, b); + } else { + colors_[WideToUTF8(*iter)] = SkColorSetRGB(r, g, b); + } } ++iter; } @@ -608,36 +607,6 @@ SkBitmap* BrowserThemeProvider::GenerateBitmap(int id) { return NULL; } -void BrowserThemeProvider::NotifyThemeChanged() { - // Redraw! - for (BrowserList::const_iterator browser = BrowserList::begin(); - browser != BrowserList::end(); ++browser) { - (*browser)->window()->UserChangedTheme(); - } -} - -void BrowserThemeProvider::LoadThemePrefs() { - PrefService* prefs = profile_->GetPrefs(); - - // TODO(glen): Figure out if any custom prefs were loaded, and if so - // UMA-log the fact that a theme was loaded. - if (prefs->HasPrefPath(prefs::kCurrentThemeImages) || - prefs->HasPrefPath(prefs::kCurrentThemeColors) || - prefs->HasPrefPath(prefs::kCurrentThemeTints)) { - // Our prefs already have the extension path baked in, so we don't need - // to provide it. - SetImageData(prefs->GetMutableDictionary(prefs::kCurrentThemeImages), - FilePath()); - SetColorData(prefs->GetMutableDictionary(prefs::kCurrentThemeColors)); - SetTintData(prefs->GetMutableDictionary(prefs::kCurrentThemeTints)); - SetDisplayPropertyData(prefs->GetMutableDictionary( - prefs::kCurrentThemeDisplayProperties)); - GenerateFrameColors(); - GenerateFrameImages(); - UserMetrics::RecordAction(L"Themes_loaded", profile_); - } -} - void BrowserThemeProvider::SaveImageData(DictionaryValue* images_value) { // Save our images data. DictionaryValue* pref_images = @@ -717,6 +686,42 @@ void BrowserThemeProvider::SaveDisplayPropertyData() { } } +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) { + (*browser)->window()->UserChangedTheme(); + } +} + +void BrowserThemeProvider::LoadThemePrefs() { + PrefService* prefs = profile_->GetPrefs(); + + // TODO(glen): Figure out if any custom prefs were loaded, and if so + // UMA-log the fact that a theme was loaded. + if (prefs->HasPrefPath(prefs::kCurrentThemeImages) || + prefs->HasPrefPath(prefs::kCurrentThemeColors) || + prefs->HasPrefPath(prefs::kCurrentThemeTints)) { + // Our prefs already have the extension path baked in, so we don't need + // to provide it. + SetImageData(prefs->GetMutableDictionary(prefs::kCurrentThemeImages), + FilePath()); + SetColorData(prefs->GetMutableDictionary(prefs::kCurrentThemeColors)); + SetTintData(prefs->GetMutableDictionary(prefs::kCurrentThemeTints)); + GenerateFrameColors(); + GenerateFrameImages(); + UserMetrics::RecordAction(L"Themes_loaded", profile_); + } +} + +SkColor BrowserThemeProvider::FindColor(const char* id, + SkColor default_color) { + return (colors_.find(id) != colors_.end()) ? colors_[id] : default_color; +} + 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 3280e1c..b905315 100644 --- a/chrome/browser/browser_theme_provider.h +++ b/chrome/browser/browser_theme_provider.h @@ -44,6 +44,8 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, COLOR_NTP_TEXT, COLOR_NTP_LINK, COLOR_NTP_SECTION, + COLOR_CONTROL_BACKGROUND, + COLOR_BUTTON_BACKGROUND, TINT_BUTTONS, TINT_FRAME, TINT_FRAME_INACTIVE, @@ -148,6 +150,8 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, // Load theme data from preferences. void LoadThemePrefs(); + SkColor FindColor(const char* id, SkColor default_color); + // Frees generated images and clears the image cache. void FreeImages(); diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index df6ecf4..fd29674 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -239,38 +239,52 @@ void BrowserToolbarView::CreateRightSideControls(Profile* profile) { void BrowserToolbarView::LoadLeftSideControlsImages() { ThemeProvider* tp = GetThemeProvider(); + SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); + SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); + back_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_BACK)); back_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_BACK_H)); back_->SetImage(views::CustomButton::BS_PUSHED, - tp->GetBitmapNamed(IDR_BACK_P)); + tp->GetBitmapNamed(IDR_BACK_P)); back_->SetImage(views::CustomButton::BS_DISABLED, - tp->GetBitmapNamed(IDR_BACK_D)); + tp->GetBitmapNamed(IDR_BACK_D)); + back_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_BACK_MASK)); forward_->SetImage(views::CustomButton::BS_NORMAL, - tp->GetBitmapNamed(IDR_FORWARD)); + tp->GetBitmapNamed(IDR_FORWARD)); forward_->SetImage(views::CustomButton::BS_HOT, - tp->GetBitmapNamed(IDR_FORWARD_H)); + tp->GetBitmapNamed(IDR_FORWARD_H)); forward_->SetImage(views::CustomButton::BS_PUSHED, - tp->GetBitmapNamed(IDR_FORWARD_P)); + tp->GetBitmapNamed(IDR_FORWARD_P)); forward_->SetImage(views::CustomButton::BS_DISABLED, - tp->GetBitmapNamed(IDR_FORWARD_D)); + tp->GetBitmapNamed(IDR_FORWARD_D)); + forward_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_FORWARD_MASK)); reload_->SetImage(views::CustomButton::BS_NORMAL, - tp->GetBitmapNamed(IDR_RELOAD)); + tp->GetBitmapNamed(IDR_RELOAD)); reload_->SetImage(views::CustomButton::BS_HOT, - tp->GetBitmapNamed(IDR_RELOAD_H)); + tp->GetBitmapNamed(IDR_RELOAD_H)); reload_->SetImage(views::CustomButton::BS_PUSHED, - tp->GetBitmapNamed(IDR_RELOAD_P)); + tp->GetBitmapNamed(IDR_RELOAD_P)); + reload_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_BUTTON_MASK)); home_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_HOME)); home_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_HOME_H)); home_->SetImage(views::CustomButton::BS_PUSHED, - tp->GetBitmapNamed(IDR_HOME_P)); + tp->GetBitmapNamed(IDR_HOME_P)); + home_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_BUTTON_MASK)); } void BrowserToolbarView::LoadCenterStackImages() { ThemeProvider* tp = GetThemeProvider(); + SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); + SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); + star_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_STAR)); star_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_STAR_H)); star_->SetImage(views::CustomButton::BS_PUSHED, @@ -283,6 +297,8 @@ void BrowserToolbarView::LoadCenterStackImages() { tp->GetBitmapNamed(IDR_STARRED_H)); star_->SetToggledImage(views::CustomButton::BS_PUSHED, tp->GetBitmapNamed(IDR_STARRED_P)); + star_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_STAR_MASK)); go_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_GO)); go_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_GO_H)); @@ -293,6 +309,8 @@ void BrowserToolbarView::LoadCenterStackImages() { tp->GetBitmapNamed(IDR_STOP_H)); go_->SetToggledImage(views::CustomButton::BS_PUSHED, tp->GetBitmapNamed(IDR_STOP_P)); + go_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_GO_MASK)); } void BrowserToolbarView::LoadRightSideControlsImages() { |