summaryrefslogtreecommitdiffstats
path: root/app/resource_bundle_linux.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 23:48:44 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 23:48:44 +0000
commitcd43e6e776b2283f555f1b59bef06d135504f66f (patch)
tree1d1a074deebfef562a534f79bd0128ed2aa48ba1 /app/resource_bundle_linux.cc
parent05d94e79f64a6562ea646e5b3f2e9c6e7b1cc011 (diff)
downloadchromium_src-cd43e6e776b2283f555f1b59bef06d135504f66f.zip
chromium_src-cd43e6e776b2283f555f1b59bef06d135504f66f.tar.gz
chromium_src-cd43e6e776b2283f555f1b59bef06d135504f66f.tar.bz2
Add a function to ResourceBundle to allow loading images that will mirror in RTL. Use this function for custom buttons and for the Off the Record avatar.
for reference, this will be a bit different than Views, which does it per class rather than per image: http://dev.chromium.org/developers/design-documents/ui-mirroring-infrastructure Review URL: http://codereview.chromium.org/147157 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19309 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/resource_bundle_linux.cc')
-rw-r--r--app/resource_bundle_linux.cc43
1 files changed, 30 insertions, 13 deletions
diff --git a/app/resource_bundle_linux.cc b/app/resource_bundle_linux.cc
index 9d46fb7..47d893d 100644
--- a/app/resource_bundle_linux.cc
+++ b/app/resource_bundle_linux.cc
@@ -25,7 +25,7 @@ namespace {
// Convert the raw image data into a GdkPixbuf. The GdkPixbuf that is returned
// has a ref count of 1 so the caller must call g_object_unref to free the
// memory.
-GdkPixbuf* LoadPixbuf(std::vector<unsigned char>& data) {
+GdkPixbuf* LoadPixbuf(std::vector<unsigned char>& data, bool rtl_enabled) {
ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new());
bool ok = gdk_pixbuf_loader_write(loader.get(),
static_cast<guint8*>(data.data()), data.size(), NULL);
@@ -40,12 +40,18 @@ GdkPixbuf* LoadPixbuf(std::vector<unsigned char>& data) {
if (!pixbuf)
return NULL;
- // The pixbuf is owned by the loader, so add a ref so when we delete the
- // loader (when the ScopedGObject goes out of scope), the pixbuf still
- // exists.
- g_object_ref(pixbuf);
-
- return pixbuf;
+ if ((l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) &&
+ rtl_enabled) {
+ // |pixbuf| will get unreffed and destroyed (see below). The returned value
+ // has ref count 1.
+ return gdk_pixbuf_flip(pixbuf, TRUE);
+ } else {
+ // The pixbuf is owned by the loader, so add a ref so when we delete the
+ // loader (when the ScopedGObject goes out of scope), the pixbuf still
+ // exists.
+ g_object_ref(pixbuf);
+ return pixbuf;
+ }
}
} // namespace
@@ -158,11 +164,14 @@ string16 ResourceBundle::GetLocalizedString(int message_id) {
return msg;
}
-GdkPixbuf* ResourceBundle::GetPixbufNamed(int resource_id) {
+GdkPixbuf* ResourceBundle::GetPixbufImpl(int resource_id, bool rtl_enabled) {
+ // Use the negative |resource_id| for the key for BIDI-aware images.
+ int key = rtl_enabled ? -resource_id : resource_id;
+
// Check to see if we already have the pixbuf in the cache.
{
AutoLock lock_scope(lock_);
- GdkPixbufMap::const_iterator found = gdk_pixbufs_.find(resource_id);
+ GdkPixbufMap::const_iterator found = gdk_pixbufs_.find(key);
if (found != gdk_pixbufs_.end())
return found->second;
}
@@ -170,19 +179,19 @@ GdkPixbuf* ResourceBundle::GetPixbufNamed(int resource_id) {
std::vector<unsigned char> data;
LoadImageResourceBytes(resource_id, &data);
- GdkPixbuf* pixbuf = LoadPixbuf(data);
+ GdkPixbuf* pixbuf = LoadPixbuf(data, rtl_enabled);
// We loaded successfully. Cache the pixbuf.
if (pixbuf) {
AutoLock lock_scope(lock_);
// Another thread raced us, and has already cached the pixbuf.
- if (gdk_pixbufs_.count(resource_id)) {
+ if (gdk_pixbufs_.count(key)) {
g_object_unref(pixbuf);
- return gdk_pixbufs_[resource_id];
+ return gdk_pixbufs_[key];
}
- gdk_pixbufs_[resource_id] = pixbuf;
+ gdk_pixbufs_[key] = pixbuf;
return pixbuf;
}
@@ -206,3 +215,11 @@ GdkPixbuf* ResourceBundle::GetPixbufNamed(int resource_id) {
return empty_bitmap;
}
}
+
+GdkPixbuf* ResourceBundle::GetPixbufNamed(int resource_id) {
+ return GetPixbufImpl(resource_id, false);
+}
+
+GdkPixbuf* ResourceBundle::GetRTLEnabledPixbufNamed(int resource_id) {
+ return GetPixbufImpl(resource_id, true);
+}