Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Unified Diff: chrome/browser/ui/views/wrench_menu.cc

Issue 10780010: Introduces ImageSkia::GetRepresentations() for Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/web_applications/web_app_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/wrench_menu.cc
diff --git a/chrome/browser/ui/views/wrench_menu.cc b/chrome/browser/ui/views/wrench_menu.cc
index fa5a5d0c4c2360c9018b505ae6405f9845828081..0f3cc71771a656bd88773f9419946b6b8dcd77d4 100644
--- a/chrome/browser/ui/views/wrench_menu.cc
+++ b/chrome/browser/ui/views/wrench_menu.cc
@@ -36,6 +36,7 @@
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/skia_util.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/image_button.h"
@@ -396,21 +397,29 @@ class ButtonContainerMenuItemView : public MenuItemView {
DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView);
};
-gfx::ImageSkia* TintImage(gfx::ImageSkia* image, SkColor tint_value) {
- // In case of touch, the menu needs to be brightened up a bit.
- // Create a new bitmap since we do not want to change the original image.
- SkBitmap bitmap_copy;
- image->bitmap()->copyTo(&bitmap_copy, SkBitmap::kARGB_8888_Config);
- SkCanvas canvas(bitmap_copy);
- SkPaint paint;
- // We leave the old alpha alone and add the new color multiplied
- // with the source alpha to the existing alpha. Thus: We brighten
- // the image up - but only the non transparent pixels.
- paint.setXfermodeMode(SkXfermode::kDstATop_Mode);
- paint.setColor(tint_value);
- canvas.drawPaint(paint);
- return new gfx::ImageSkia(bitmap_copy);
-}
+class TintedImageSource: public gfx::CanvasImageSource {
+ public:
+ TintedImageSource(gfx::ImageSkia& image, SkColor tint_value)
+ : CanvasImageSource(image.size(), false),
+ image_(image),
+ tint_value_(tint_value) {
+ }
+
+ virtual ~TintedImageSource() {
+ }
+
+ void Draw(gfx::Canvas* canvas) OVERRIDE {
+ canvas->DrawImageInt(image_, 0, 0);
+ SkPaint paint;
+ paint.setXfermodeMode(SkXfermode::kDstATop_Mode);
+ paint.setColor(tint_value_);
+ canvas->sk_canvas()->drawPaint(paint);
+ }
+
+ private:
+ const gfx::ImageSkia image_;
+ const SkColor tint_value_;
+};
} // namespace
@@ -539,10 +548,10 @@ class WrenchMenu::ZoomView : public WrenchMenuView,
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_FULLSCREEN_MENU_BUTTON);
if (is_touch) {
- tinted_fullscreen_image_.reset(TintImage(full_screen_image,
- kTouchImageBrighten));
+ tinted_fullscreen_image_ = gfx::ImageSkia(new TintedImageSource(
+ *full_screen_image, kTouchImageBrighten), full_screen_image->size());
fullscreen_button_->SetImage(ImageButton::BS_NORMAL,
- tinted_fullscreen_image_.get());
+ new gfx::ImageSkia(tinted_fullscreen_image_));
sadrul 2012/07/17 03:30:08 I think this is leaking ... you could just send &t
} else {
fullscreen_button_->SetImage(ImageButton::BS_NORMAL, full_screen_image);
}
@@ -709,7 +718,7 @@ class WrenchMenu::ZoomView : public WrenchMenuView,
ImageButton* fullscreen_button_;
// The tinted bitmap of the fullscreen button.
- scoped_ptr<gfx::ImageSkia> tinted_fullscreen_image_;
+ gfx::ImageSkia tinted_fullscreen_image_;
// Width given to |zoom_label_|. This is the width at 100%.
int zoom_label_width_;
« no previous file with comments | « no previous file | chrome/browser/web_applications/web_app_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698