OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/browser_theme_provider.h" | 5 #include "chrome/browser/browser_theme_provider.h" |
6 | 6 |
7 #include <gdk-pixbuf/gdk-pixbuf.h> | 7 #include <gdk-pixbuf/gdk-pixbuf.h> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "gfx/gtk_util.h" | 11 #include "gfx/gtk_util.h" |
12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
13 | 13 |
14 GdkPixbuf* BrowserThemeProvider::GetPixbufNamed(int id) const { | 14 GdkPixbuf* BrowserThemeProvider::GetPixbufNamed(int id) const { |
15 return GetPixbufImpl(id, false); | 15 return GetPixbufImpl(id, false); |
16 } | 16 } |
17 | 17 |
18 GdkPixbuf* BrowserThemeProvider::GetRTLEnabledPixbufNamed(int id) const { | 18 GdkPixbuf* BrowserThemeProvider::GetRTLEnabledPixbufNamed(int id) const { |
19 return GetPixbufImpl(id, true); | 19 return GetPixbufImpl(id, true); |
20 } | 20 } |
21 | 21 |
22 GdkPixbuf* BrowserThemeProvider::GetPixbufImpl(int id, bool rtl_enabled) const { | 22 GdkPixbuf* BrowserThemeProvider::GetPixbufImpl(int id, bool rtl_enabled) const { |
23 DCHECK(CalledOnValidThread()); | 23 DCHECK(CalledOnValidThread()); |
24 // Use the negative |resource_id| for the key for BIDI-aware images. | 24 // Use the negative |resource_id| for the key for BIDI-aware images. |
25 int key = rtl_enabled ? -id : id; | 25 int key = rtl_enabled ? -id : id; |
26 | 26 |
27 // Check to see if we already have the pixbuf in the cache. | 27 // Check to see if we already have the pixbuf in the cache. |
28 GdkPixbufMap::const_iterator pixbufs_iter = gdk_pixbufs_.find(key); | 28 GdkPixbufMap::const_iterator pixbufs_iter = gdk_pixbufs_.find(key); |
29 if (pixbufs_iter != gdk_pixbufs_.end()) | 29 if (pixbufs_iter != gdk_pixbufs_.end()) |
30 return pixbufs_iter->second; | 30 return pixbufs_iter->second; |
31 | 31 |
32 SkBitmap* bitmap = GetBitmapNamed(id); | 32 SkBitmap* bitmap = GetBitmapNamed(id); |
33 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bitmap); | 33 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bitmap); |
34 | 34 |
35 // We loaded successfully. Cache the pixbuf. | 35 // We loaded successfully. Cache the pixbuf. |
36 if (pixbuf) { | 36 if (pixbuf) { |
37 if ((l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) && | 37 if (base::i18n::IsRTL() && rtl_enabled) { |
38 rtl_enabled) { | |
39 GdkPixbuf* original_pixbuf = pixbuf; | 38 GdkPixbuf* original_pixbuf = pixbuf; |
40 pixbuf = gdk_pixbuf_flip(pixbuf, TRUE); | 39 pixbuf = gdk_pixbuf_flip(pixbuf, TRUE); |
41 g_object_unref(original_pixbuf); | 40 g_object_unref(original_pixbuf); |
42 } | 41 } |
43 | 42 |
44 gdk_pixbufs_[key] = pixbuf; | 43 gdk_pixbufs_[key] = pixbuf; |
45 return pixbuf; | 44 return pixbuf; |
46 } | 45 } |
47 | 46 |
48 // We failed to retrieve the bitmap, show a debugging red square. | 47 // We failed to retrieve the bitmap, show a debugging red square. |
(...skipping 16 matching lines...) Expand all Loading... |
65 void BrowserThemeProvider::FreePlatformCaches() { | 64 void BrowserThemeProvider::FreePlatformCaches() { |
66 DCHECK(CalledOnValidThread()); | 65 DCHECK(CalledOnValidThread()); |
67 | 66 |
68 // Free GdkPixbufs. | 67 // Free GdkPixbufs. |
69 for (GdkPixbufMap::iterator i = gdk_pixbufs_.begin(); | 68 for (GdkPixbufMap::iterator i = gdk_pixbufs_.begin(); |
70 i != gdk_pixbufs_.end(); i++) { | 69 i != gdk_pixbufs_.end(); i++) { |
71 g_object_unref(i->second); | 70 g_object_unref(i->second); |
72 } | 71 } |
73 gdk_pixbufs_.clear(); | 72 gdk_pixbufs_.clear(); |
74 } | 73 } |
OLD | NEW |