diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-13 20:00:09 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-13 20:00:09 +0000 |
commit | b5d079536bcbf33c657fd96079bb7b2bd9644c0e (patch) | |
tree | b9f4a20f69bbd3252464cf96e13b21d3d5b5ca09 | |
parent | 89beb4c0dc72aeb590a8944bf2f24b95b9c90425 (diff) | |
download | chromium_src-b5d079536bcbf33c657fd96079bb7b2bd9644c0e.zip chromium_src-b5d079536bcbf33c657fd96079bb7b2bd9644c0e.tar.gz chromium_src-b5d079536bcbf33c657fd96079bb7b2bd9644c0e.tar.bz2 |
Make the ThemeProvider methods const.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/266037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28868 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | app/theme_provider.h | 23 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.cc | 140 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.h | 80 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider_mac.mm | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm | 18 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_theme_provider.cc | 10 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_theme_provider.h | 10 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_theme_provider_unittest.cc | 4 | ||||
-rw-r--r-- | views/widget/default_theme_provider.cc | 4 | ||||
-rw-r--r-- | views/widget/default_theme_provider.h | 12 |
11 files changed, 164 insertions, 151 deletions
diff --git a/app/theme_provider.h b/app/theme_provider.h index f9a9bb5..c3b8a9c 100644 --- a/app/theme_provider.h +++ b/app/theme_provider.h @@ -43,26 +43,27 @@ class ThemeProvider { // Get the bitmap specified by |id|. An implementation of ThemeProvider should // have its own source of ids (e.g. an enum, or external resource bundle). - virtual SkBitmap* GetBitmapNamed(int id) = 0; + virtual SkBitmap* GetBitmapNamed(int id) const = 0; // Get the color specified by |id|. - virtual SkColor GetColor(int id) = 0; + virtual SkColor GetColor(int id) const = 0; // Get the property (e.g. an alignment expressed in an enum, or a width or // height) specified by |id|. - virtual bool GetDisplayProperty(int id, int* result) = 0; + virtual bool GetDisplayProperty(int id, int* result) const = 0; // Whether we should use the native system frame (typically Aero glass) or // a custom frame. - virtual bool ShouldUseNativeFrame() = 0; + virtual bool ShouldUseNativeFrame() const = 0; // Whether or not we have a certain image. Used for when the default theme // doesn't provide a certain image, but custom themes might (badges, etc). - virtual bool HasCustomImage(int id) = 0; + virtual bool HasCustomImage(int id) const = 0; // Reads the image data from the theme file into the specified vector. Returns // true on success. - virtual bool GetRawData(int id, std::vector<unsigned char>* raw_data) = 0; + virtual bool GetRawData(int id, + std::vector<unsigned char>* raw_data) const = 0; #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) // Gets the GdkPixbuf with the specified |id|. Returns a pointer to a shared @@ -73,28 +74,28 @@ class ThemeProvider { // assert in debug mode if it does not. On failure, this will return a // pointer to a shared empty placeholder bitmap so it will be visible what // is missing. - virtual GdkPixbuf* GetPixbufNamed(int id) = 0; + virtual GdkPixbuf* GetPixbufNamed(int id) const = 0; // As above, but flips it in RTL locales. - virtual GdkPixbuf* GetRTLEnabledPixbufNamed(int id) = 0; + virtual GdkPixbuf* GetRTLEnabledPixbufNamed(int id) const = 0; #elif defined(OS_MACOSX) // Gets the NSImage with the specified |id|. // // The bitmap is not assumed to exist. If a theme does not provide an image, // this function will return nil. - virtual NSImage* GetNSImageNamed(int id) = 0; + virtual NSImage* GetNSImageNamed(int id) const = 0; // Gets the NSColor with the specified |id|. // // The color is not assumed to exist. If a theme does not provide an color, // this function will return nil. - virtual NSColor* GetNSColor(int id) = 0; + virtual NSColor* GetNSColor(int id) const = 0; // Gets the NSColor for tinting with the specified |id|. // // The tint is not assumed to exist. If a theme does not provide a tint with // that id, this function will return nil. - virtual NSColor* GetNSColorTint(int id) = 0; + virtual NSColor* GetNSColorTint(int id) const = 0; #endif }; diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc index f24b2b0..4e1562e 100644 --- a/chrome/browser/browser_theme_provider.cc +++ b/chrome/browser/browser_theme_provider.cc @@ -304,7 +304,7 @@ void BrowserThemeProvider::Init(Profile* profile) { LoadThemePrefs(); } -SkBitmap* BrowserThemeProvider::GetBitmapNamed(int id) { +SkBitmap* BrowserThemeProvider::GetBitmapNamed(int id) const { DCHECK(CalledOnValidThread()); // First check to see if the Skia image is in the themed cache. The themed @@ -346,41 +346,46 @@ SkBitmap* BrowserThemeProvider::GetBitmapNamed(int id) { } } -SkColor BrowserThemeProvider::GetColor(int id) { +SkColor BrowserThemeProvider::GetColor(int id) const { DCHECK(CalledOnValidThread()); // Special-case NTP header - if the color isn't provided, we fall back to // the section color. if (id == COLOR_NTP_HEADER) { - if (colors_.find(kColorNTPHeader) != colors_.end()) - return colors_[kColorNTPHeader]; - return (colors_.find(kColorNTPSection) == colors_.end()) ? - GetDefaultColor(id) : colors_[kColorNTPSection]; + ColorMap::const_iterator color_iter = colors_.find(kColorNTPHeader); + if (color_iter != colors_.end()) + return color_iter->second; + color_iter = colors_.find(kColorNTPSection); + return (color_iter == colors_.end()) ? + GetDefaultColor(id) : color_iter->second; } // Special case the underline colors to use semi transparent in case not // defined. if (id == COLOR_NTP_SECTION_LINK_UNDERLINE) { - if (colors_.find(kColorNTPSectionLinkUnderline) != colors_.end()) - return colors_[kColorNTPSectionLinkUnderline]; + ColorMap::const_iterator color_iter = + colors_.find(kColorNTPSectionLinkUnderline); + if (color_iter != colors_.end()) + return color_iter->second; SkColor color_section_link = GetColor(COLOR_NTP_SECTION_LINK); return SkColorSetA(color_section_link, SkColorGetA(color_section_link) / 3); } if (id == COLOR_NTP_LINK_UNDERLINE) { - if (colors_.find(kColorNTPLinkUnderline) != colors_.end()) - return colors_[kColorNTPLinkUnderline]; + ColorMap::const_iterator color_iter = colors_.find(kColorNTPLinkUnderline); + if (color_iter != colors_.end()) + return color_iter->second; SkColor color_link = GetColor(COLOR_NTP_LINK); return SkColorSetA(color_link, SkColorGetA(color_link) / 3); } // TODO(glen): Figure out if we need to tint these. http://crbug.com/11578 - ColorMap::iterator color_iter = colors_.find(GetColorKey(id)); + ColorMap::const_iterator color_iter = colors_.find(GetColorKey(id)); return (color_iter == colors_.end()) ? GetDefaultColor(id) : color_iter->second; } -bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) { +bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) const { switch (id) { case NTP_BACKGROUND_ALIGNMENT: { DisplayPropertyMap::const_iterator display_iter = @@ -409,7 +414,7 @@ bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) { return false; } -bool BrowserThemeProvider::ShouldUseNativeFrame() { +bool BrowserThemeProvider::ShouldUseNativeFrame() const { if (HasCustomImage(IDR_THEME_FRAME)) return false; #if defined(OS_WIN) @@ -419,30 +424,33 @@ bool BrowserThemeProvider::ShouldUseNativeFrame() { #endif } -bool BrowserThemeProvider::HasCustomImage(int id) { - if (!themeable_images[id]) +bool BrowserThemeProvider::HasCustomImage(int id) const { + if (!themeable_images.count(id)) return false; // A custom image = base name is NOT equal to resource name. See note in // SaveThemeBitmap describing the process by which an original image is // tagged. - if ((images_.find(id) == images_.end()) || - (resource_names_.find(id) == resource_names_.end())) + ImageMap::const_iterator images_iter = images_.find(id); + ResourceNameMap::const_iterator names_iter = resource_names_.find(id); + if ((images_iter == images_.end()) || (names_iter == resource_names_.end())) return false; - return !EndsWith(UTF8ToWide(images_[id]), - UTF8ToWide(resource_names_[id]), false); + return !EndsWith(UTF8ToWide(images_iter->second), + UTF8ToWide(names_iter->second), false); } -bool BrowserThemeProvider::GetRawData(int id, - std::vector<unsigned char>* raw_data) { +bool BrowserThemeProvider::GetRawData( + int id, + std::vector<unsigned char>* raw_data) const { // Check to see whether we should substitute some images. int ntp_alternate; GetDisplayProperty(NTP_LOGO_ALTERNATE, &ntp_alternate); if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) id = IDR_PRODUCT_LOGO_WHITE; - if (raw_data_.find(id) != raw_data_.end()) { - *raw_data = raw_data_[id]; + RawDataMap::const_iterator data_iter = raw_data_.find(id); + if (data_iter != raw_data_.end()) { + *raw_data = data_iter->second; return true; } @@ -494,20 +502,21 @@ void BrowserThemeProvider::UseDefaultTheme() { UserMetrics::RecordAction(L"Themes_Reset", profile_); } -std::string BrowserThemeProvider::GetThemeID() { +std::string BrowserThemeProvider::GetThemeID() const { std::wstring id = profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); return WideToUTF8(id); } bool BrowserThemeProvider::ReadThemeFileData( - int id, std::vector<unsigned char>* raw_data) { - if (images_.count(id)) { + int id, std::vector<unsigned char>* raw_data) const { + ImageMap::const_iterator images_iter = images_.find(id); + if (images_iter != images_.end()) { // First check to see if we have a registered theme extension and whether // it can handle this resource. #if defined(OS_WIN) - FilePath path = FilePath(UTF8ToWide(images_[id])); + FilePath path = FilePath(UTF8ToWide(images_iter->second)); #else - FilePath path = FilePath(images_[id]); + FilePath path = FilePath(images_iter->second); #endif if (!path.empty()) { net::FileStream file; @@ -610,10 +619,10 @@ void BrowserThemeProvider::SetTint(const char* key, tints_[key] = tint; } -color_utils::HSL BrowserThemeProvider::GetTint(int id) { +color_utils::HSL BrowserThemeProvider::GetTint(int id) const { DCHECK(CalledOnValidThread()); - TintMap::iterator tint_iter = tints_.find(GetTintKey(id)); + TintMap::const_iterator tint_iter = tints_.find(GetTintKey(id)); return (tint_iter == tints_.end()) ? GetDefaultTint(id) : tint_iter->second; } @@ -637,8 +646,8 @@ void BrowserThemeProvider::GenerateFrameColors() { } } -void BrowserThemeProvider::GenerateFrameImages() { - for (FrameTintMap::iterator iter(frame_tints.begin()); +void BrowserThemeProvider::GenerateFrameImages() const { + for (FrameTintMap::const_iterator iter(frame_tints.begin()); iter != frame_tints.end(); ++iter) { int id = iter->first; scoped_ptr<SkBitmap> frame; @@ -655,7 +664,7 @@ void BrowserThemeProvider::GenerateFrameImages() { if (frame.get()) themed_image_cache_[id] = new SkBitmap(*frame.get()); } else { - resource_name = resource_names_[id]; + resource_name = resource_names_.find(id)->second; if (id == IDR_THEME_FRAME_INCOGNITO_INACTIVE) { base_id = HasCustomImage(IDR_THEME_FRAME_INCOGNITO) ? IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME; @@ -695,7 +704,7 @@ void BrowserThemeProvider::GenerateFrameImages() { } } -void BrowserThemeProvider::GenerateTabImages() { +void BrowserThemeProvider::GenerateTabImages() const { GenerateTabBackgroundBitmap(IDR_THEME_TAB_BACKGROUND); GenerateTabBackgroundBitmap(IDR_THEME_TAB_BACKGROUND_INCOGNITO); } @@ -740,11 +749,12 @@ void BrowserThemeProvider::LoadThemePrefs() { // If we're not loading the frame from the cached image dir, we are using an // old preferences file, or the processed images were not saved correctly. // Force image reprocessing and caching. - if (images_.count(IDR_THEME_FRAME) > 0) { + ImageMap::const_iterator images_iter = images_.find(IDR_THEME_FRAME); + if (images_iter != images_.end()) { #if defined(OS_WIN) - FilePath cache_path = FilePath(UTF8ToWide(images_[IDR_THEME_FRAME])); + FilePath cache_path = FilePath(UTF8ToWide(images_iter->second)); #else - FilePath cache_path = FilePath(images_[IDR_THEME_FRAME]); + FilePath cache_path = FilePath(images_iter->second); #endif process_images_ = !file_util::ContainsPath(image_dir_, cache_path); } @@ -772,10 +782,10 @@ void BrowserThemeProvider::NotifyThemeChanged() { NotificationService::NoDetails()); } -SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { +SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) const { DCHECK(CalledOnValidThread()); - if (!themeable_images[id]) + if (!themeable_images.count(id)) return NULL; // Attempt to find the image in our theme bundle. @@ -803,10 +813,10 @@ SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { } } -void BrowserThemeProvider::SaveThemeBitmap( - std::string resource_name, int id) { +void BrowserThemeProvider::SaveThemeBitmap(std::string resource_name, + int id) const { DCHECK(CalledOnValidThread()); - if (!themed_image_cache_[id]) { + if (!themed_image_cache_.count(id)) { NOTREACHED(); return; } @@ -836,14 +846,14 @@ void BrowserThemeProvider::FreePlatformCaches() { } #endif -SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmapImpl(int id) { +SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmapImpl(int id) const { int base_id = (id == IDR_THEME_TAB_BACKGROUND) ? IDR_THEME_FRAME : IDR_THEME_FRAME_INCOGNITO; // According to Miranda, it is safe to read from the themed_image_cache_ here // because we only lock to write on the UI thread, and we only lock to read // on the cache writing thread. - ImageCache::iterator themed_iter = themed_image_cache_.find(base_id); - if (themed_iter != themed_image_cache_.end()) + ImageCache::const_iterator themed_iter = themed_image_cache_.find(base_id); + if (themed_iter == themed_image_cache_.end()) return NULL; SkBitmap bg_tint = TintBitmap(*(themed_iter->second), TINT_BACKGROUND_TAB); @@ -864,7 +874,7 @@ SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmapImpl(int id) { return bg_tab; } -const std::string BrowserThemeProvider::GetTintKey(int id) { +const std::string BrowserThemeProvider::GetTintKey(int id) const { switch (id) { case TINT_FRAME: return kTintFrame; @@ -884,7 +894,7 @@ const std::string BrowserThemeProvider::GetTintKey(int id) { } } -color_utils::HSL BrowserThemeProvider::GetDefaultTint(int id) { +color_utils::HSL BrowserThemeProvider::GetDefaultTint(int id) const { switch (id) { case TINT_FRAME: return kDefaultTintFrame; @@ -904,7 +914,7 @@ color_utils::HSL BrowserThemeProvider::GetDefaultTint(int id) { } } -const std::string BrowserThemeProvider::GetColorKey(int id) { +const std::string BrowserThemeProvider::GetColorKey(int id) const { switch (id) { case COLOR_FRAME: return kColorFrame; @@ -950,7 +960,7 @@ const std::string BrowserThemeProvider::GetColorKey(int id) { } } -SkColor BrowserThemeProvider::GetDefaultColor(int id) { +SkColor BrowserThemeProvider::GetDefaultColor(int id) const { switch (id) { case COLOR_FRAME: return kDefaultColorFrame; @@ -992,7 +1002,8 @@ SkColor BrowserThemeProvider::GetDefaultColor(int id) { } } -SkBitmap BrowserThemeProvider::TintBitmap(const SkBitmap& bitmap, int hsl_id) { +SkBitmap BrowserThemeProvider::TintBitmap(const SkBitmap& bitmap, + int hsl_id) const { return SkBitmapOperations::CreateHSLShiftedBitmap(bitmap, GetTint(hsl_id)); } @@ -1113,7 +1124,7 @@ void BrowserThemeProvider::SetDisplayPropertyData( } } -SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmap(int id) { +SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmap(int id) const { if (id == IDR_THEME_TAB_BACKGROUND || id == IDR_THEME_TAB_BACKGROUND_INCOGNITO) { // The requested image is a background tab. Get a frame to create the @@ -1140,7 +1151,7 @@ SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmap(int id) { return NULL; } -void BrowserThemeProvider::SaveImageData(DictionaryValue* images_value) { +void BrowserThemeProvider::SaveImageData(DictionaryValue* images_value) const { // Save our images data. DictionaryValue* pref_images = profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); @@ -1155,12 +1166,12 @@ void BrowserThemeProvider::SaveImageData(DictionaryValue* images_value) { if (images_value->GetString(*iter, &val)) { int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); if (id != -1) - pref_images->SetString(*iter, images_[id]); + pref_images->SetString(*iter, images_.find(id)->second); } } } -void BrowserThemeProvider::SaveColorData() { +void BrowserThemeProvider::SaveColorData() const { // Save our color data. DictionaryValue* pref_colors = profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeColors); @@ -1169,7 +1180,7 @@ void BrowserThemeProvider::SaveColorData() { if (colors_.empty()) return; - for (ColorMap::iterator iter(colors_.begin()); iter != colors_.end(); + for (ColorMap::const_iterator iter(colors_.begin()); iter != colors_.end(); ++iter) { SkColor rgba = iter->second; ListValue* rgb_list = new ListValue(); @@ -1182,7 +1193,7 @@ void BrowserThemeProvider::SaveColorData() { } } -void BrowserThemeProvider::SaveTintData() { +void BrowserThemeProvider::SaveTintData() const { // Save our tint data. DictionaryValue* pref_tints = profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeTints); @@ -1191,7 +1202,8 @@ void BrowserThemeProvider::SaveTintData() { if (tints_.empty()) return; - for (TintMap::iterator iter(tints_.begin()); iter != tints_.end(); ++iter) { + for (TintMap::const_iterator iter(tints_.begin()); iter != tints_.end(); + ++iter) { color_utils::HSL hsl = iter->second; ListValue* hsl_list = new ListValue(); hsl_list->Set(0, Value::CreateRealValue(hsl.h)); @@ -1201,7 +1213,7 @@ void BrowserThemeProvider::SaveTintData() { } } -void BrowserThemeProvider::SaveDisplayPropertyData() { +void BrowserThemeProvider::SaveDisplayPropertyData() const { // Save our display property data. DictionaryValue* pref_display_properties = profile_->GetPrefs()-> @@ -1211,7 +1223,7 @@ void BrowserThemeProvider::SaveDisplayPropertyData() { if (display_properties_.empty()) return; - for (DisplayPropertyMap::iterator iter(display_properties_.begin()); + for (DisplayPropertyMap::const_iterator iter(display_properties_.begin()); iter != display_properties_.end(); ++iter) { if (base::strcasecmp(iter->first.c_str(), kDisplayPropertyNTPAlignment) == 0) { @@ -1230,14 +1242,14 @@ void BrowserThemeProvider::SaveDisplayPropertyData() { } } -void BrowserThemeProvider::SaveCachedImageData() { +void BrowserThemeProvider::SaveCachedImageData() const { DictionaryValue* pref_images = profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); - for (ImagesDiskCache::iterator it(images_disk_cache_.begin()); + for (ImagesDiskCache::const_iterator it(images_disk_cache_.begin()); it != images_disk_cache_.end(); ++it) { std::wstring disk_path = it->first.ToWStringHack(); - std::string pref_name = resource_names_[it->second]; + std::string pref_name = resource_names_.find(it->second)->second; pref_images->SetString(UTF8ToWide(pref_name), WideToUTF8(disk_path)); } profile_->GetPrefs()->SavePersistentPrefs(); @@ -1260,13 +1272,13 @@ void BrowserThemeProvider::ClearCaches() { images_disk_cache_.clear(); } -void BrowserThemeProvider::WriteImagesToDisk() { +void BrowserThemeProvider::WriteImagesToDisk() const { g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, new WriteImagesToDiskTask(images_disk_cache_, themed_image_cache_)); SaveCachedImageData(); } -bool BrowserThemeProvider::ShouldTintFrames() { +bool BrowserThemeProvider::ShouldTintFrames() const { return (HasCustomImage(IDR_THEME_FRAME) || tints_.count(GetTintKey(TINT_BACKGROUND_TAB)) || tints_.count(GetTintKey(TINT_FRAME)) || diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h index 64eb871..02fec9b 100644 --- a/chrome/browser/browser_theme_provider.h +++ b/chrome/browser/browser_theme_provider.h @@ -157,19 +157,19 @@ class BrowserThemeProvider : public NonThreadSafe, // ThemeProvider implementation. virtual void Init(Profile* profile); - virtual SkBitmap* GetBitmapNamed(int id); - virtual SkColor GetColor(int id); - virtual bool GetDisplayProperty(int id, int* result); - virtual bool ShouldUseNativeFrame(); - virtual bool HasCustomImage(int id); - virtual bool GetRawData(int id, std::vector<unsigned char>* raw_data); + virtual SkBitmap* GetBitmapNamed(int id) const; + virtual SkColor GetColor(int id) const; + virtual bool GetDisplayProperty(int id, int* result) const; + virtual bool ShouldUseNativeFrame() const; + virtual bool HasCustomImage(int id) const; + virtual bool GetRawData(int id, std::vector<unsigned char>* raw_data) const; #if defined(OS_LINUX) - virtual GdkPixbuf* GetPixbufNamed(int id); - virtual GdkPixbuf* GetRTLEnabledPixbufNamed(int id); + virtual GdkPixbuf* GetPixbufNamed(int id) const; + virtual GdkPixbuf* GetRTLEnabledPixbufNamed(int id) const; #elif defined(OS_MACOSX) - virtual NSImage* GetNSImageNamed(int id); - virtual NSColor* GetNSColor(int id); - virtual NSColor* GetNSColorTint(int id); + virtual NSImage* GetNSImageNamed(int id) const; + virtual NSColor* GetNSColor(int id) const; + virtual NSColor* GetNSColorTint(int id) const; #endif // Set the current theme to the theme defined in |extension|. @@ -184,11 +184,11 @@ class BrowserThemeProvider : public NonThreadSafe, // Gets the id of the last installed theme. (The theme may have been further // locally customized.) - std::string GetThemeID(); + std::string GetThemeID() const; // Reads the image data from the theme file into the specified vector. Returns // true on success. - bool ReadThemeFileData(int id, std::vector<unsigned char>* raw_data); + bool ReadThemeFileData(int id, std::vector<unsigned char>* raw_data) const; // Convert a bitfield alignment into a string like "top left". Public so that // it can be used to generate CSS values. Takes a bitfield of AlignmentMasks. @@ -227,7 +227,7 @@ class BrowserThemeProvider : public NonThreadSafe, void SetTint(const char* id, const color_utils::HSL& tint); // Get the specified tint - |id| is one of the TINT_* enum values. - color_utils::HSL GetTint(int id); + color_utils::HSL GetTint(int id) const; // Generate any frame colors that weren't specified. void GenerateFrameColors(); @@ -235,11 +235,11 @@ class BrowserThemeProvider : public NonThreadSafe, // Generate any frame images that weren't specified. The resulting images // will be stored in our cache and written to disk. If images have already // been generated and cached, load them from disk. - void GenerateFrameImages(); + void GenerateFrameImages() const; // Generate any tab images that weren't specified. The resulting images // will be stored in our cache. - void GenerateTabImages(); + void GenerateTabImages() const; // Clears all the override fields and saves the dictionary. void ClearAllThemeData(); @@ -252,10 +252,10 @@ class BrowserThemeProvider : public NonThreadSafe, // Loads a bitmap from the theme, which may be tinted or // otherwise modified, or an application default. - virtual SkBitmap* LoadThemeBitmap(int id); + virtual SkBitmap* LoadThemeBitmap(int id) const; // Save the modified bitmap at image_cache_[id]. - virtual void SaveThemeBitmap(std::string resource_name, int id); + virtual void SaveThemeBitmap(std::string resource_name, int id) const; // Clears the platform-specific caches. Do not call directly; it's called // from ClearCaches(). @@ -264,7 +264,7 @@ class BrowserThemeProvider : public NonThreadSafe, // The implementation of GenerateTabBackgroundBitmap(). That function also // must be locked and touches caches; this function only deals with image // generation. - SkBitmap* GenerateTabBackgroundBitmapImpl(int id); + SkBitmap* GenerateTabBackgroundBitmapImpl(int id) const; Profile* profile() { return profile_; } @@ -281,19 +281,19 @@ class BrowserThemeProvider : public NonThreadSafe, typedef std::map<const int, std::string> ResourceNameMap; // Returns the string key for the given tint |id| TINT_* enum value. - const std::string GetTintKey(int id); + const std::string GetTintKey(int id) const; // Returns the default tint for the given tint |id| TINT_* enum value. - color_utils::HSL GetDefaultTint(int id); + color_utils::HSL GetDefaultTint(int id) const; // Returns the string key for the given color |id| COLOR_* enum value. - const std::string GetColorKey(int id); + const std::string GetColorKey(int id) const; // Returns the default color for the given color |id| COLOR_* enum value. - SkColor GetDefaultColor(int id); + SkColor GetDefaultColor(int id) const; // Tint |bitmap| with the tint specified by |hsl_id| - SkBitmap TintBitmap(const SkBitmap& bitmap, int hsl_id); + SkBitmap TintBitmap(const SkBitmap& bitmap, int hsl_id) const; // The following load data from specified dictionaries (either from // preferences or from an extension manifest) and update our theme @@ -318,17 +318,17 @@ class BrowserThemeProvider : public NonThreadSafe, void SetDisplayPropertyData(DictionaryValue* display_properties); // Create any images that aren't pregenerated (e.g. background tab images). - SkBitmap* GenerateTabBackgroundBitmap(int id); + SkBitmap* GenerateTabBackgroundBitmap(int id) const; // Save our data - when saving images we need the original dictionary // from the extension because it contains the text ids that we want to save. - void SaveImageData(DictionaryValue* images); - void SaveColorData(); - void SaveTintData(); - void SaveDisplayPropertyData(); + void SaveImageData(DictionaryValue* images) const; + void SaveColorData() const; + void SaveTintData() const; + void SaveDisplayPropertyData() const; // Save the paths of data we have written to disk in prefs. - void SaveCachedImageData(); + void SaveCachedImageData() const; // Save the id of the last theme installed. void SaveThemeID(const std::string& id); @@ -337,35 +337,35 @@ class BrowserThemeProvider : public NonThreadSafe, void ClearCaches(); // Encode image at image_cache_[id] as PNG and write to disk. - void WriteImagesToDisk(); + void WriteImagesToDisk() const; // Do we have a custom frame image or custom tints? - bool ShouldTintFrames(); + bool ShouldTintFrames() const; #if defined(OS_LINUX) // Loads an image and flips it horizontally if |rtl_enabled| is true. - GdkPixbuf* GetPixbufImpl(int id, bool rtl_enabled); + GdkPixbuf* GetPixbufImpl(int id, bool rtl_enabled) const; #endif - ImageCache image_cache_; + mutable ImageCache image_cache_; // Keep images generated for theme cache in their own place, so we can lock // them on WRITE from UI thread and READ from file thread. Read from UI // thread will be allowed unlocked, because no other thread has write // access to the cache. - ImageCache themed_image_cache_; + mutable ImageCache themed_image_cache_; #if defined(OS_LINUX) typedef std::map<int, GdkPixbuf*> GdkPixbufMap; - GdkPixbufMap gdk_pixbufs_; + mutable GdkPixbufMap gdk_pixbufs_; #elif defined(OS_MACOSX) typedef std::map<int, NSImage*> NSImageMap; - NSImageMap nsimage_cache_; + mutable NSImageMap nsimage_cache_; typedef std::map<int, NSColor*> NSColorMap; - NSColorMap nscolor_cache_; + mutable NSColorMap nscolor_cache_; #endif - ImagesDiskCache images_disk_cache_; + mutable ImagesDiskCache images_disk_cache_; ResourceBundle& rb_; Profile* profile_; @@ -373,7 +373,7 @@ class BrowserThemeProvider : public NonThreadSafe, ImageMap images_; ColorMap colors_; TintMap tints_; - RawDataMap raw_data_; + mutable RawDataMap raw_data_; DisplayPropertyMap display_properties_; // Reverse of theme_resources_map, so we can cache images properly. diff --git a/chrome/browser/browser_theme_provider_gtk.cc b/chrome/browser/browser_theme_provider_gtk.cc index 46b6ae9..3269c15 100644 --- a/chrome/browser/browser_theme_provider_gtk.cc +++ b/chrome/browser/browser_theme_provider_gtk.cc @@ -9,15 +9,15 @@ #include "base/logging.h" #include "third_party/skia/include/core/SkBitmap.h" -GdkPixbuf* BrowserThemeProvider::GetPixbufNamed(int id) { +GdkPixbuf* BrowserThemeProvider::GetPixbufNamed(int id) const { return GetPixbufImpl(id, false); } -GdkPixbuf* BrowserThemeProvider::GetRTLEnabledPixbufNamed(int id) { +GdkPixbuf* BrowserThemeProvider::GetRTLEnabledPixbufNamed(int id) const { return GetPixbufImpl(id, true); } -GdkPixbuf* BrowserThemeProvider::GetPixbufImpl(int id, bool rtl_enabled) { +GdkPixbuf* BrowserThemeProvider::GetPixbufImpl(int id, bool rtl_enabled) const { DCHECK(CalledOnValidThread()); // Use the negative |resource_id| for the key for BIDI-aware images. int key = rtl_enabled ? -id : id; diff --git a/chrome/browser/browser_theme_provider_mac.mm b/chrome/browser/browser_theme_provider_mac.mm index d47aa73..1b88aed 100644 --- a/chrome/browser/browser_theme_provider_mac.mm +++ b/chrome/browser/browser_theme_provider_mac.mm @@ -24,7 +24,7 @@ void HSLToHSB(const color_utils::HSL& hsl, CGFloat* h, CGFloat* s, CGFloat* b) { } -NSImage* BrowserThemeProvider::GetNSImageNamed(int id) { +NSImage* BrowserThemeProvider::GetNSImageNamed(int id) const { DCHECK(CalledOnValidThread()); if (!HasCustomImage(id)) @@ -67,7 +67,7 @@ NSImage* BrowserThemeProvider::GetNSImageNamed(int id) { return empty_image; } -NSColor* BrowserThemeProvider::GetNSColor(int id) { +NSColor* BrowserThemeProvider::GetNSColor(int id) const { DCHECK(CalledOnValidThread()); // Check to see if we already have the color in the cache. @@ -91,7 +91,7 @@ NSColor* BrowserThemeProvider::GetNSColor(int id) { return nil; } -NSColor* BrowserThemeProvider::GetNSColorTint(int id) { +NSColor* BrowserThemeProvider::GetNSColorTint(int id) const { DCHECK(CalledOnValidThread()); // Check to see if we already have the color in the cache. @@ -99,7 +99,7 @@ NSColor* BrowserThemeProvider::GetNSColorTint(int id) { if (nscolor_iter != nscolor_cache_.end()) return nscolor_iter->second; - TintMap::iterator tint_iter = tints_.find(GetTintKey(id)); + TintMap::const_iterator tint_iter = tints_.find(GetTintKey(id)); if (tint_iter != tints_.end()) { color_utils::HSL tint = tint_iter->second; CGFloat hue, saturation, brightness; diff --git a/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm b/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm index c2b83bf..37c61ae 100644 --- a/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm @@ -28,17 +28,17 @@ class MockThemeProvider : public ThemeProvider { public: // Cross platform methods MOCK_METHOD1(Init, void(Profile*)); - MOCK_METHOD1(GetBitmapNamed, SkBitmap*(int)); - MOCK_METHOD1(GetColor, SkColor(int)); - MOCK_METHOD2(GetDisplayProperty, bool(int, int*)); - MOCK_METHOD0(ShouldUseNativeFrame, bool()); - MOCK_METHOD1(HasCustomImage, bool(int)); - MOCK_METHOD2(GetRawData, bool(int, std::vector<unsigned char>*)); + MOCK_CONST_METHOD1(GetBitmapNamed, SkBitmap*(int)); + MOCK_CONST_METHOD1(GetColor, SkColor(int)); + MOCK_CONST_METHOD2(GetDisplayProperty, bool(int, int*)); + MOCK_CONST_METHOD0(ShouldUseNativeFrame, bool()); + MOCK_CONST_METHOD1(HasCustomImage, bool(int)); + MOCK_CONST_METHOD2(GetRawData, bool(int, std::vector<unsigned char>*)); // OSX stuff - MOCK_METHOD1(GetNSImageNamed, NSImage*(int)); - MOCK_METHOD1(GetNSColor, NSColor*(int)); - MOCK_METHOD1(GetNSColorTint, NSColor*(int)); + MOCK_CONST_METHOD1(GetNSImageNamed, NSImage*(int)); + MOCK_CONST_METHOD1(GetNSColor, NSColor*(int)); + MOCK_CONST_METHOD1(GetNSColorTint, NSColor*(int)); }; // Allows us to inject our fake controller below. diff --git a/chrome/browser/gtk/gtk_theme_provider.cc b/chrome/browser/gtk/gtk_theme_provider.cc index dc8b084..9155125 100644 --- a/chrome/browser/gtk/gtk_theme_provider.cc +++ b/chrome/browser/gtk/gtk_theme_provider.cc @@ -142,15 +142,15 @@ GtkWidget* GtkThemeProvider::BuildChromeButton() { return button; } -bool GtkThemeProvider::UseGtkTheme() { +bool GtkThemeProvider::UseGtkTheme() const { return use_gtk_; } -GdkColor GtkThemeProvider::GetGdkColor(int id) { +GdkColor GtkThemeProvider::GetGdkColor(int id) const { return skia::SkColorToGdkColor(GetColor(id)); } -GdkColor GtkThemeProvider::GetBorderColor() { +GdkColor GtkThemeProvider::GetBorderColor() const { GtkStyle* style = gtk_rc_get_style(fake_window_); GdkColor text; @@ -254,7 +254,7 @@ void GtkThemeProvider::NotifyThemeChanged() { } } -SkBitmap* GtkThemeProvider::LoadThemeBitmap(int id) { +SkBitmap* GtkThemeProvider::LoadThemeBitmap(int id) const { if (use_gtk_) { if (id == IDR_THEME_TOOLBAR) { GtkStyle* style = gtk_rc_get_style(fake_window_); @@ -275,7 +275,7 @@ SkBitmap* GtkThemeProvider::LoadThemeBitmap(int id) { } void GtkThemeProvider::SaveThemeBitmap(const std::string resource_name, - int id) { + int id) const { if (!use_gtk_) { // Prevent us from writing out our mostly unused resources in gtk theme // mode. Simply preventing us from writing this data out in gtk mode isn't diff --git a/chrome/browser/gtk/gtk_theme_provider.h b/chrome/browser/gtk/gtk_theme_provider.h index 70331ef..f39902e 100644 --- a/chrome/browser/gtk/gtk_theme_provider.h +++ b/chrome/browser/gtk/gtk_theme_provider.h @@ -55,15 +55,15 @@ class GtkThemeProvider : public BrowserThemeProvider, GtkWidget* BuildChromeButton(); // Whether we should use the GTK system theme. - bool UseGtkTheme(); + bool UseGtkTheme() const; // A wrapper around ThemeProvider::GetColor, transforming the result to a // GdkColor. - GdkColor GetGdkColor(int id); + GdkColor GetGdkColor(int id) const; // A weighted average between the text color and the background color of a // label. Used for borders between GTK stuff and the webcontent. - GdkColor GetBorderColor(); + GdkColor GetBorderColor() const; // Expose the inner label. Only used for testing. GtkWidget* fake_label() { return fake_label_.get(); } @@ -84,7 +84,7 @@ class GtkThemeProvider : public BrowserThemeProvider, // (minimally acceptable version right now, which is just a fill of the bg // color; this should instead invoke gtk_draw_box(...) for complex theme // engines.) - virtual SkBitmap* LoadThemeBitmap(int id); + virtual SkBitmap* LoadThemeBitmap(int id) const; private: // Load theme data from preferences, possibly picking colors from GTK. @@ -95,7 +95,7 @@ class GtkThemeProvider : public BrowserThemeProvider, // If use_gtk_ is true, completely ignores this call. Otherwise passes it to // the superclass. - virtual void SaveThemeBitmap(const std::string resource_name, int id); + virtual void SaveThemeBitmap(const std::string resource_name, int id) const; // Additionally frees the CairoCachedSurfaces. virtual void FreePlatformCaches(); diff --git a/chrome/browser/gtk/gtk_theme_provider_unittest.cc b/chrome/browser/gtk/gtk_theme_provider_unittest.cc index d479bc6..c3b85cb 100644 --- a/chrome/browser/gtk/gtk_theme_provider_unittest.cc +++ b/chrome/browser/gtk/gtk_theme_provider_unittest.cc @@ -110,14 +110,14 @@ class ImageVerifierGtkThemeProvider : public GtkThemeProvider { public: ImageVerifierGtkThemeProvider() : theme_toolbar_(NULL) { } - virtual SkBitmap* LoadThemeBitmap(int id) { + virtual SkBitmap* LoadThemeBitmap(int id) const { if (id != IDR_THEME_TOOLBAR) return GtkThemeProvider::LoadThemeBitmap(id); theme_toolbar_ = GtkThemeProvider::LoadThemeBitmap(id); return theme_toolbar_; } - SkBitmap* theme_toolbar_; + mutable SkBitmap* theme_toolbar_; }; TEST_F(GtkThemeProviderTest, InjectsToolbar) { diff --git a/views/widget/default_theme_provider.cc b/views/widget/default_theme_provider.cc index 9dba2c6..e6087e2 100644 --- a/views/widget/default_theme_provider.cc +++ b/views/widget/default_theme_provider.cc @@ -12,11 +12,11 @@ namespace views { -SkBitmap* DefaultThemeProvider::GetBitmapNamed(int id) { +SkBitmap* DefaultThemeProvider::GetBitmapNamed(int id) const { return ResourceBundle::GetSharedInstance().GetBitmapNamed(id); } -bool DefaultThemeProvider::ShouldUseNativeFrame() { +bool DefaultThemeProvider::ShouldUseNativeFrame() const { #if defined(OS_WIN) return win_util::ShouldUseVistaFrame(); #else diff --git a/views/widget/default_theme_provider.h b/views/widget/default_theme_provider.h index b344def..512b512 100644 --- a/views/widget/default_theme_provider.h +++ b/views/widget/default_theme_provider.h @@ -22,15 +22,15 @@ class DefaultThemeProvider : public ThemeProvider { // Overridden from ThemeProvider. virtual void Init(Profile* profile) { } - virtual SkBitmap* GetBitmapNamed(int id); - virtual SkColor GetColor(int id) { + virtual SkBitmap* GetBitmapNamed(int id) const; + virtual SkColor GetColor(int id) const { // Return debugging-blue. return 0xff0000ff; } - virtual bool GetDisplayProperty(int id, int* result) { return false; } - virtual bool ShouldUseNativeFrame(); - virtual bool HasCustomImage(int id) { return false; } - virtual bool GetRawData(int id, std::vector<unsigned char>* raw_data) { + virtual bool GetDisplayProperty(int id, int* result) const { return false; } + virtual bool ShouldUseNativeFrame() const; + virtual bool HasCustomImage(int id) const { return false; } + virtual bool GetRawData(int id, std::vector<unsigned char>* raw_data) const { return false; } |