Commit 59723ccf authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Crop images from custom themes before storing them into the theme pack.

BUG=176857
Test=None
R=erg
TBR=sky (For ui/linux_ui/linux_ui.h)

Review URL: https://chromiumcodereview.appspot.com/13497002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192595 0039d316-1c4b-4281-b951-d872f2087c98
parent 931d1047
This diff is collapsed.
......@@ -18,6 +18,7 @@
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/layout.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/image/image.h"
namespace base {
class DictionaryValue;
......@@ -29,10 +30,6 @@ namespace extensions {
class Extensions;
}
namespace gfx {
class Image;
}
namespace ui {
class DataPack;
}
......@@ -84,8 +81,9 @@ class BrowserThemePack : public base::RefCountedThreadSafe<
bool GetColor(int id, SkColor* color) const;
bool GetDisplayProperty(int id, int* result) const;
// Returns an image if we have a custom image for |id|, otherwise NULL.
const gfx::Image* GetImageNamed(int id) const;
// Returns the theme pack image for |id|. Returns an empty image if an image
// is not found.
gfx::Image GetImageNamed(int id);
// Returns the raw PNG encoded data for IDR_THEME_NTP_*. This method is only
// supposed to work for the NTP attribution and background resources.
......@@ -105,10 +103,8 @@ class BrowserThemePack : public base::RefCountedThreadSafe<
friend class base::DeleteHelper<BrowserThemePack>;
friend class BrowserThemePackTest;
// Cached images. We cache all retrieved and generated images and keep
// track of the pointers. We own these and will delete them when we're done
// using them.
typedef std::map<int, const gfx::Image*> ImageCache;
// Cached images.
typedef std::map<int, gfx::Image> ImageCache;
// The raw PNG memory associated with a certain id.
typedef std::map<int, scoped_refptr<base::RefCountedMemory> > RawImages;
......@@ -161,6 +157,11 @@ class BrowserThemePack : public base::RefCountedThreadSafe<
// Source and destination is |images|.
void CreateImages(ImageCache* images) const;
// Crops images down to a size such that most of the cropped image will be
// displayed in the UI. Cropping is useful because images from custom themes
// can be of any size. Source and destination is |images|.
void CropImages(ImageCache* images) const;
// Creates tinted and composited frame images. Source and destination is
// |images|.
void CreateFrameImages(ImageCache* images) const;
......@@ -256,7 +257,7 @@ class BrowserThemePack : public base::RefCountedThreadSafe<
// Loaded images. These are loaded from |image_memory_|, from |data_pack_|,
// and by BuildFromExtension(). These images should only be accessed on the UI
// thread.
mutable ImageCache images_on_ui_thread_;
ImageCache images_on_ui_thread_;
// Cache of images created in BuildFromExtension(). Once the theme pack is
// created, this cache should only be accessed on the file thread. There
......
......@@ -108,21 +108,20 @@ void ThemeService::Init(Profile* profile) {
gfx::Image ThemeService::GetImageNamed(int id) const {
DCHECK(CalledOnValidThread());
const gfx::Image* image = NULL;
gfx::Image image;
if (theme_pack_.get())
image = theme_pack_->GetImageNamed(id);
#if defined(USE_AURA) && !defined(USE_ASH) && defined(OS_LINUX)
const ui::LinuxUI* linux_ui = ui::LinuxUI::instance();
if (!image && linux_ui)
if (image.IsEmpty() && linux_ui)
image = linux_ui->GetThemeImageNamed(id);
#endif
if (!image)
image = &rb_.GetNativeImageNamed(id);
if (image.IsEmpty())
image = rb_.GetNativeImageNamed(id);
return image ? *image : gfx::Image();
return image;
}
gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const {
......
......@@ -52,9 +52,9 @@ NSImage* ThemeService::GetNSImageNamed(int id, bool allow_default) const {
// - To get the generated tinted images.
NSImage* nsimage = nil;
if (theme_pack_.get()) {
const gfx::Image* image = theme_pack_->GetImageNamed(id);
if (image)
nsimage = image->ToNSImage();
gfx::Image image = theme_pack_->GetImageNamed(id);
if (!image.IsEmpty())
nsimage = image.ToNSImage();
}
// If the theme didn't override this image then load it from the resource
......
......@@ -309,20 +309,20 @@ bool Gtk2UI::UseNativeTheme() const {
return true;
}
gfx::Image* Gtk2UI::GetThemeImageNamed(int id) const {
gfx::Image Gtk2UI::GetThemeImageNamed(int id) const {
// Try to get our cached version:
ImageCache::const_iterator it = gtk_images_.find(id);
if (it != gtk_images_.end())
return it->second;
if (/*use_gtk_ && */ IsOverridableImage(id)) {
gfx::Image* image = new gfx::Image(
gfx::Image image = gfx::Image(
gfx::ImageSkia::CreateFrom1xBitmap(GenerateGtkThemeBitmap(id)));
gtk_images_[id] = image;
return image;
}
return NULL;
return gfx::Image();
}
bool Gtk2UI::GetColor(int id, SkColor* color) const {
......@@ -795,7 +795,7 @@ SkBitmap Gtk2UI::GenerateFrameImage(
}
SkBitmap Gtk2UI::GenerateTabImage(int base_id) const {
const SkBitmap* base_image = GetThemeImageNamed(base_id)->ToSkBitmap();
const SkBitmap* base_image = GetThemeImageNamed(base_id).ToSkBitmap();
SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap(
*base_image, GetDefaultTint(ThemeProperties::TINT_BACKGROUND_TAB));
return SkBitmapOperations::CreateTiledBitmap(
......@@ -973,7 +973,7 @@ SkBitmap Gtk2UI::DrawGtkButtonBorder(int gtk_state,
}
void Gtk2UI::ClearAllThemeData() {
STLDeleteValues(&gtk_images_);
gtk_images_.clear();
}
} // namespace libgtk2ui
......
......@@ -40,14 +40,14 @@ class Gtk2UI : public ui::LinuxUI {
// ui::LinuxUI:
virtual bool UseNativeTheme() const OVERRIDE;
virtual gfx::Image* GetThemeImageNamed(int id) const OVERRIDE;
virtual gfx::Image GetThemeImageNamed(int id) const OVERRIDE;
virtual bool GetColor(int id, SkColor* color) const OVERRIDE;
virtual ui::NativeTheme* GetNativeTheme() const OVERRIDE;
private:
typedef std::map<int, SkColor> ColorMap;
typedef std::map<int, color_utils::HSL> TintMap;
typedef std::map<int, gfx::Image*> ImageCache;
typedef std::map<int, gfx::Image> ImageCache;
// This method returns the colors webkit will use for the scrollbars. When no
// colors are specified by the GTK+ theme, this function averages of the
......
......@@ -45,7 +45,7 @@ class LINUX_UI_EXPORT LinuxUI : public LinuxShellDialog {
// Returns an themed image per theme_provider.h
virtual bool UseNativeTheme() const = 0;
virtual gfx::Image* GetThemeImageNamed(int id) const = 0;
virtual gfx::Image GetThemeImageNamed(int id) const = 0;
virtual bool GetColor(int id, SkColor* color) const = 0;
// Returns a NativeTheme that will provide system colors and draw system
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment