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 | |
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')
-rw-r--r-- | chrome/app/theme/back_mask.png | bin | 0 -> 201 bytes | |||
-rw-r--r-- | chrome/app/theme/button_mask.png | bin | 0 -> 225 bytes | |||
-rw-r--r-- | chrome/app/theme/forward_mask.png | bin | 0 -> 203 bytes | |||
-rw-r--r-- | chrome/app/theme/go_mask.png | bin | 0 -> 202 bytes | |||
-rw-r--r-- | chrome/app/theme/notused.png | bin | 299 -> 140 bytes | |||
-rw-r--r-- | chrome/app/theme/star_mask.png | bin | 0 -> 207 bytes | |||
-rw-r--r-- | chrome/app/theme/theme_resources.grd | 13 | ||||
-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 | ||||
-rw-r--r-- | chrome/common/extensions/extension.cc | 27 |
11 files changed, 124 insertions, 83 deletions
diff --git a/chrome/app/theme/back_mask.png b/chrome/app/theme/back_mask.png Binary files differnew file mode 100644 index 0000000..de63f2d --- /dev/null +++ b/chrome/app/theme/back_mask.png diff --git a/chrome/app/theme/button_mask.png b/chrome/app/theme/button_mask.png Binary files differnew file mode 100644 index 0000000..9118830 --- /dev/null +++ b/chrome/app/theme/button_mask.png diff --git a/chrome/app/theme/forward_mask.png b/chrome/app/theme/forward_mask.png Binary files differnew file mode 100644 index 0000000..0fcfe61 --- /dev/null +++ b/chrome/app/theme/forward_mask.png diff --git a/chrome/app/theme/go_mask.png b/chrome/app/theme/go_mask.png Binary files differnew file mode 100644 index 0000000..32c47c2 --- /dev/null +++ b/chrome/app/theme/go_mask.png diff --git a/chrome/app/theme/notused.png b/chrome/app/theme/notused.png Binary files differindex 42ad610..ae51eb8 100644 --- a/chrome/app/theme/notused.png +++ b/chrome/app/theme/notused.png diff --git a/chrome/app/theme/star_mask.png b/chrome/app/theme/star_mask.png Binary files differnew file mode 100644 index 0000000..a04c2c6 --- /dev/null +++ b/chrome/app/theme/star_mask.png diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd index 626a045..3d0e421 100644 --- a/chrome/app/theme/theme_resources.grd +++ b/chrome/app/theme/theme_resources.grd @@ -257,6 +257,13 @@ <include name="IDR_THEME_TAB_BACKGROUND_INCOGNITO" file="theme_tab_background_incognito.png" type="BINDATA" /> <include name="IDR_THEME_TAB_BACKGROUND_V" file="theme_tab_background_glass.png" type="BINDATA" /> <include name="IDR_THEME_NTP_BACKGROUND" file="ntp_background.png" type="BINDATA" /> + <include name="IDR_THEME_BUTTON_BACKGROUND" file="notused.png" type="BINDATA" /> + + <include name="IDR_FORWARD_MASK" file="forward_mask.png" type="BINDATA" /> + <include name="IDR_BACK_MASK" file="back_mask.png" type="BINDATA" /> + <include name="IDR_BUTTON_MASK" file="button_mask.png" type="BINDATA" /> + <include name="IDR_STAR_MASK" file="star_mask.png" type="BINDATA" /> + <include name="IDR_GO_MASK" file="go_mask.png" type="BINDATA" /> <if expr="pp_ifdef('_google_chrome')"> <include name="IDR_ABOUT_BACKGROUND" file="google_chrome/about_background.png" type="BINDATA" /> @@ -282,11 +289,5 @@ <include name="IDR_PRODUCT_ICON_32" file="chromium/chromium_icon_32.png" type="BINDATA" /> </if> </includes> - <messages> - <message name="IDS_COLOR_FRAME" use_name_for_id="true">frame</message> - <message name="IDS_COLOR_TOOLBAR" use_name_for_id="true">toolbar</message> - <message name="IDS_COLOR_TEXT_TAB" use_name_for_id="true">text_tab</message> - <message name="IDS_TINT_BUTTONS" use_name_for_id="true">buttons</message> - </messages> </release> </grit> 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() { diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 5c55341..f6a579b 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -549,14 +549,27 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, std::string val; int color = 0; ListValue* color_list; - if (!colors_value->GetList(*iter, &color_list) || - color_list->GetSize() != 3 || - !color_list->GetInteger(0, &color) || - !color_list->GetInteger(1, &color) || - !color_list->GetInteger(2, &color)) { - *error = kInvalidThemeColorsError; - return false; + if (colors_value->GetList(*iter, &color_list)) { + if (color_list->GetSize() == 3 || + color_list->GetSize() == 4) { + if (color_list->GetInteger(0, &color) && + color_list->GetInteger(1, &color) && + color_list->GetInteger(2, &color)) { + if (color_list->GetSize() == 4) { + double alpha; + if (color_list->GetReal(3, &alpha)) { + ++iter; + continue; + } + } else { + ++iter; + continue; + } + } + } } + *error = kInvalidThemeColorsError; + return false; ++iter; } theme_colors_.reset( |