summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/resource_bundle.cc11
-rw-r--r--app/resource_bundle.h7
-rw-r--r--chrome/browser/page_info_model.cc14
-rw-r--r--chrome/browser/page_info_model.h31
-rw-r--r--gfx/native_widget_types.h17
5 files changed, 45 insertions, 35 deletions
diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc
index ec28581..859f9a83 100644
--- a/app/resource_bundle.cc
+++ b/app/resource_bundle.cc
@@ -207,6 +207,17 @@ const gfx::Font& ResourceBundle::GetFont(FontStyle style) {
}
}
+gfx::NativeImage ResourceBundle::GetNativeImageNamed(int resource_id) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+#if defined(OS_MACOSX)
+ return rb.GetNSImageNamed(resource_id);
+#elif defined(USE_X11) && !defined(TOOLKIT_VIEWS)
+ return rb.GetPixbufNamed(resource_id);
+#else
+ return rb.GetBitmapNamed(resource_id);
+#endif
+}
+
// LoadedDataPack implementation
ResourceBundle::LoadedDataPack::LoadedDataPack(const FilePath& path)
: path_(path) {
diff --git a/app/resource_bundle.h b/app/resource_bundle.h
index 44237e2..8fc6447 100644
--- a/app/resource_bundle.h
+++ b/app/resource_bundle.h
@@ -21,6 +21,7 @@
#include "base/ref_counted_memory.h"
#include "base/scoped_ptr.h"
#include "base/string16.h"
+#include "gfx/native_widget_types.h"
namespace base {
class DataPack;
@@ -115,6 +116,12 @@ class ResourceBundle {
// Returns the font for the specified style.
const gfx::Font& GetFont(FontStyle style);
+ // Returns the gfx::NativeImage, the native platform type, named resource.
+ // Internally, this makes use of GetNSImageNamed(), GetPixbufNamed(), or
+ // GetBitmapNamed() depending on the platform (see gfx/native_widget_types.h).
+ // NOTE: On Mac the returned resource is autoreleased.
+ gfx::NativeImage GetNativeImageNamed(int resource_id);
+
#if defined(OS_WIN)
// Loads and returns an icon from the app module.
HICON LoadThemeIcon(int icon_id);
diff --git a/chrome/browser/page_info_model.cc b/chrome/browser/page_info_model.cc
index 2b2e8da..c4e76eb 100644
--- a/chrome/browser/page_info_model.cc
+++ b/chrome/browser/page_info_model.cc
@@ -264,7 +264,7 @@ PageInfoModel::PageInfoModel(Profile* profile,
PageInfoModel::~PageInfoModel() {
#if defined(OS_MACOSX)
// Release the NSImages.
- for (std::vector<ImageType>::iterator it = icons_.begin();
+ for (std::vector<gfx::NativeImage>::iterator it = icons_.begin();
it != icons_.end(); ++it) {
mac_util::NSObjectRelease(*it);
}
@@ -280,7 +280,7 @@ PageInfoModel::SectionInfo PageInfoModel::GetSectionInfo(int index) {
return sections_[index];
}
-PageInfoModel::ImageType PageInfoModel::GetIconImage(SectionStateIcon icon_id) {
+gfx::NativeImage PageInfoModel::GetIconImage(SectionStateIcon icon_id) {
if (icon_id == ICON_NONE)
return NULL;
// TODO(rsesek): Remove once the window is replaced with the bubble.
@@ -359,17 +359,13 @@ void PageInfoModel::Init() {
icons_.push_back(GetBitmapNamed(IDR_PAGEINFO_INFO));
}
-PageInfoModel::ImageType PageInfoModel::GetBitmapNamed(int resource_id) {
+gfx::NativeImage PageInfoModel::GetBitmapNamed(int resource_id) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ gfx::NativeImage image = rb.GetNativeImageNamed(resource_id);
#if defined(OS_MACOSX)
// Unlike other platforms, the Mac ResourceBundle does not keep a shared image
// cache. These are released in the dtor.
- ImageType image = rb.GetNSImageNamed(resource_id);
mac_util::NSObjectRetain(image);
- return image;
-#elif defined(USE_X11) && !defined(TOOLKIT_VIEWS)
- return rb.GetPixbufNamed(resource_id);
-#else
- return rb.GetBitmapNamed(resource_id);
#endif
+ return image;
}
diff --git a/chrome/browser/page_info_model.h b/chrome/browser/page_info_model.h
index 04a7a2d..3e6b962 100644
--- a/chrome/browser/page_info_model.h
+++ b/chrome/browser/page_info_model.h
@@ -8,24 +8,15 @@
#include <vector>
+#include "gfx/native_widget_types.h"
#include "base/string16.h"
#include "chrome/browser/cancelable_request.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "googleurl/src/gurl.h"
-#ifdef __OBJC__
-@class NSImage;
-#else
-class NSImage;
-#endif // __OBJC__
class PrefService;
class Profile;
-class SkBitmap;
-
-#if defined(USE_X11) && !defined(TOOLKIT_VIEWS)
-typedef struct _GdkPixbuf GdkPixbuf;
-#endif
// The model that provides the information that should be displayed in the page
// info dialog/bubble.
@@ -44,15 +35,6 @@ class PageInfoModel {
SECTION_INFO_FIRST_VISIT,
};
- // TODO(rsesek): Extract this information out to gfx::NativeImage.
-#if defined(OS_MACOSX)
- typedef NSImage* ImageType;
-#elif defined(USE_X11) && !defined(TOOLKIT_VIEWS)
- typedef GdkPixbuf* ImageType;
-#else
- typedef const SkBitmap* ImageType;
-#endif
-
enum SectionStateIcon {
// No icon.
ICON_NONE = -1,
@@ -109,7 +91,7 @@ class PageInfoModel {
SectionInfo GetSectionInfo(int index);
// Returns the native image type for an icon with the given id.
- ImageType GetIconImage(SectionStateIcon icon_id);
+ gfx::NativeImage GetIconImage(SectionStateIcon icon_id);
// Callback from history service with number of visits to url.
void OnGotVisitCountToHost(HistoryService::Handle handle,
@@ -126,17 +108,16 @@ class PageInfoModel {
// Shared initialization for default and testing constructor.
void Init();
- // Gets the native image resource of the given id from the ResourceBundle.
- // Mac only: image is owned by caller. On other platforms, the image is owned
- // by the shared ResourceBundle.
- ImageType GetBitmapNamed(int resource_id);
+ // Wrapper for ResourceBundle::GetNativeImage() so that Mac can retain its
+ // icons.
+ gfx::NativeImage GetBitmapNamed(int resource_id);
PageInfoModelObserver* observer_;
std::vector<SectionInfo> sections_;
// All possible icons that go next to the text descriptions to indicate state.
- std::vector<ImageType> icons_;
+ std::vector<gfx::NativeImage> icons_;
// Used to request number of visits.
CancelableRequestConsumer request_consumer_;
diff --git a/gfx/native_widget_types.h b/gfx/native_widget_types.h
index 729a9e9..b7ff4bb 100644
--- a/gfx/native_widget_types.h
+++ b/gfx/native_widget_types.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -29,6 +29,9 @@
// NativeEditView: a handle to a native edit-box. The Mac folks wanted this
// specific typedef.
//
+// NativeImage: The platform-specific image type used for drawing UI elements
+// in the browser.
+//
// The name 'View' here meshes with OS X where the UI elements are called
// 'views' and with our Chrome UI code where the elements are also called
// 'views'.
@@ -40,11 +43,13 @@ typedef struct HFONT__* HFONT;
struct CGContext;
#ifdef __OBJC__
@class NSFont;
+@class NSImage;
@class NSView;
@class NSWindow;
@class NSTextField;
#else
class NSFont;
+class NSImage;
class NSView;
class NSWindow;
class NSTextField;
@@ -52,11 +57,13 @@ class NSTextField;
#elif defined(TOOLKIT_USES_GTK)
typedef struct _PangoFontDescription PangoFontDescription;
typedef struct _GdkCursor GdkCursor;
+typedef struct _GdkPixbuf GdkPixbuf;
typedef struct _GdkRegion GdkRegion;
typedef struct _GtkWidget GtkWidget;
typedef struct _GtkWindow GtkWindow;
typedef struct _cairo cairo_t;
#endif
+class SkBitmap;
namespace gfx {
@@ -88,6 +95,14 @@ typedef GtkWidget* NativeMenu;
typedef GdkRegion* NativeRegion;
#endif
+#if defined(OS_MACOSX)
+typedef NSImage* NativeImage;
+#elif defined(USE_X11) && !defined(TOOLKIT_VIEWS)
+typedef GdkPixbuf* NativeImage;
+#else
+typedef const SkBitmap* NativeImage;
+#endif
+
// Note: for test_shell we're packing a pointer into the NativeViewId. So, if
// you make it a type which is smaller than a pointer, you have to fix
// test_shell.