summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/theme/back_mask.pngbin0 -> 201 bytes
-rw-r--r--chrome/app/theme/button_mask.pngbin0 -> 225 bytes
-rw-r--r--chrome/app/theme/forward_mask.pngbin0 -> 203 bytes
-rw-r--r--chrome/app/theme/go_mask.pngbin0 -> 202 bytes
-rw-r--r--chrome/app/theme/notused.pngbin299 -> 140 bytes
-rw-r--r--chrome/app/theme/star_mask.pngbin0 -> 207 bytes
-rw-r--r--chrome/app/theme/theme_resources.grd13
-rw-r--r--chrome/browser/browser_theme_provider.cc125
-rw-r--r--chrome/browser/browser_theme_provider.h4
-rw-r--r--chrome/browser/views/toolbar_view.cc38
-rw-r--r--chrome/common/extensions/extension.cc27
-rw-r--r--skia/ext/image_operations.cc53
-rw-r--r--skia/ext/image_operations.h9
-rw-r--r--views/controls/button/image_button.cc15
-rw-r--r--views/controls/button/image_button.h6
15 files changed, 206 insertions, 84 deletions
diff --git a/chrome/app/theme/back_mask.png b/chrome/app/theme/back_mask.png
new file mode 100644
index 0000000..de63f2d
--- /dev/null
+++ b/chrome/app/theme/back_mask.png
Binary files differ
diff --git a/chrome/app/theme/button_mask.png b/chrome/app/theme/button_mask.png
new file mode 100644
index 0000000..9118830
--- /dev/null
+++ b/chrome/app/theme/button_mask.png
Binary files differ
diff --git a/chrome/app/theme/forward_mask.png b/chrome/app/theme/forward_mask.png
new file mode 100644
index 0000000..0fcfe61
--- /dev/null
+++ b/chrome/app/theme/forward_mask.png
Binary files differ
diff --git a/chrome/app/theme/go_mask.png b/chrome/app/theme/go_mask.png
new file mode 100644
index 0000000..32c47c2
--- /dev/null
+++ b/chrome/app/theme/go_mask.png
Binary files differ
diff --git a/chrome/app/theme/notused.png b/chrome/app/theme/notused.png
index 42ad610..ae51eb8 100644
--- a/chrome/app/theme/notused.png
+++ b/chrome/app/theme/notused.png
Binary files differ
diff --git a/chrome/app/theme/star_mask.png b/chrome/app/theme/star_mask.png
new file mode 100644
index 0000000..a04c2c6
--- /dev/null
+++ b/chrome/app/theme/star_mask.png
Binary files differ
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(
diff --git a/skia/ext/image_operations.cc b/skia/ext/image_operations.cc
index 561bd4e..c0ee3e0 100644
--- a/skia/ext/image_operations.cc
+++ b/skia/ext/image_operations.cc
@@ -407,6 +407,59 @@ SkBitmap ImageOperations::CreateMaskedBitmap(const SkBitmap& rgb,
return masked;
}
+// static
+SkBitmap ImageOperations::CreateButtonBackground(SkColor color,
+ const SkBitmap& image,
+ const SkBitmap& mask) {
+ DCHECK(image.config() == SkBitmap::kARGB_8888_Config);
+ DCHECK(mask.config() == SkBitmap::kARGB_8888_Config);
+
+ SkBitmap background;
+ background.setConfig(SkBitmap::kARGB_8888_Config,
+ mask.width(),
+ mask.height(), 0);
+ background.allocPixels();
+
+ int bg_a = SkColorGetA(color);
+ int bg_r = SkColorGetR(color);
+ int bg_g = SkColorGetG(color);
+ int bg_b = SkColorGetB(color);
+
+ SkAutoLockPixels lock_mask(mask);
+ SkAutoLockPixels lock_image(image);
+ SkAutoLockPixels lock_background(background);
+
+ for (int y = 0; y < mask.height(); y++) {
+ uint32* dst_row = background.getAddr32(0, y);
+ uint32* image_row = image.getAddr32(0, y % image.height());
+ uint32* mask_row = mask.getAddr32(0, y);
+
+ for (int x = 0; x < mask.width(); x++) {
+ uint32 mask_pixel = mask_row[x];
+ uint32 image_pixel = image_row[x % image.width()];
+
+ int img_a = SkColorGetA(image_pixel);
+ int img_r = SkColorGetR(image_pixel);
+ int img_g = SkColorGetG(image_pixel);
+ int img_b = SkColorGetB(image_pixel);
+
+ double img_alpha = static_cast<double>(img_a) / 255.0;
+ double img_inv = 1 - img_alpha;
+
+ double mask_a = static_cast<double>(SkColorGetA(mask_pixel)) / 255.0;
+
+ dst_row[x] = SkColorSetARGB(
+ static_cast<int>(std::min(255, bg_a + img_a) * mask_a),
+ static_cast<int>((bg_r * img_inv + img_r * img_alpha) * mask_a),
+ static_cast<int>((bg_g * img_inv + img_g * img_alpha) * mask_a),
+ static_cast<int>((bg_b * img_inv + img_b * img_alpha) * mask_a));
+ }
+ }
+
+ return background;
+}
+
+
SkBitmap ImageOperations::CreateBlurredBitmap(const SkBitmap& bitmap,
int blur_amount ) {
DCHECK(bitmap.config() == SkBitmap::kARGB_8888_Config);
diff --git a/skia/ext/image_operations.h b/skia/ext/image_operations.h
index 3086fab..4e3c93e 100644
--- a/skia/ext/image_operations.h
+++ b/skia/ext/image_operations.h
@@ -61,6 +61,15 @@ class ImageOperations {
static SkBitmap CreateMaskedBitmap(const SkBitmap& first,
const SkBitmap& alpha);
+ // We create a button background image by compositing the color and image
+ // together, then applying the mask. This is a highly specialized composite
+ // operation that is the equivalent of drawing a background in |color|,
+ // tiling |image| over the top, and then masking the result out with |mask|.
+ // The images must use kARGB_8888_Config config.
+ static SkBitmap CreateButtonBackground(SkColor color,
+ const SkBitmap& image,
+ const SkBitmap& mask);
+
// Blur a bitmap using an average-blur algorithm over the rectangle defined
// by |blur_amount|. The blur will wrap around image edges.
static SkBitmap CreateBlurredBitmap(const SkBitmap& bitmap, int blur_amount);
diff --git a/views/controls/button/image_button.cc b/views/controls/button/image_button.cc
index 087b4f0..a4f9123 100644
--- a/views/controls/button/image_button.cc
+++ b/views/controls/button/image_button.cc
@@ -19,7 +19,8 @@ static const int kDefaultHeight = 14; // Default button height if no theme.
ImageButton::ImageButton(ButtonListener* listener)
: CustomButton(listener),
h_alignment_(ALIGN_LEFT),
- v_alignment_(ALIGN_TOP) {
+ v_alignment_(ALIGN_TOP),
+ background_image_(NULL) {
// By default, we request that the gfx::Canvas passed to our View::Paint()
// implementation is flipped horizontally so that the button's bitmaps are
// mirrored when the UI directionality is right-to-left.
@@ -33,6 +34,16 @@ void ImageButton::SetImage(ButtonState aState, SkBitmap* anImage) {
images_[aState] = anImage ? *anImage : SkBitmap();
}
+void ImageButton::SetBackground(SkColor color,
+ SkBitmap* image,
+ SkBitmap* mask) {
+ if (!color && !image)
+ background_image_ = NULL;
+
+ background_image_ = new SkBitmap(
+ skia::ImageOperations::CreateButtonBackground(color, *image, *mask));
+}
+
void ImageButton::SetImageAlignment(HorizontalAlignment h_align,
VerticalAlignment v_align) {
h_alignment_ = h_align;
@@ -68,6 +79,8 @@ void ImageButton::Paint(gfx::Canvas* canvas) {
else if (v_alignment_ == ALIGN_BOTTOM)
y = height() - img.height();
+ if (background_image_)
+ canvas->DrawBitmapInt(*background_image_, x, y);
canvas->DrawBitmapInt(img, x, y);
}
PaintFocusBorder(canvas);
diff --git a/views/controls/button/image_button.h b/views/controls/button/image_button.h
index ec3b9ae..c3edceb 100644
--- a/views/controls/button/image_button.h
+++ b/views/controls/button/image_button.h
@@ -19,6 +19,9 @@ class ImageButton : public CustomButton {
// Set the image the button should use for the provided state.
virtual void SetImage(ButtonState aState, SkBitmap* anImage);
+ // Set the background details.
+ virtual void SetBackground(SkColor color, SkBitmap* image, SkBitmap* mask);
+
enum HorizontalAlignment { ALIGN_LEFT = 0,
ALIGN_CENTER,
ALIGN_RIGHT, };
@@ -43,6 +46,9 @@ class ImageButton : public CustomButton {
// The images used to render the different states of this button.
SkBitmap images_[BS_COUNT];
+ // The background image.
+ SkBitmap* background_image_;
+
private:
// Image alignment.
HorizontalAlignment h_alignment_;