| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/gtk/gtk_util.h" | 5 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 6 | 6 |
| 7 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cstdarg> | 10 #include <cstdarg> |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 gtk_label_set_width_chars( | 126 gtk_label_set_width_chars( |
| 127 GTK_LABEL(label), | 127 GTK_LABEL(label), |
| 128 GetCharacterWidthForPixels(label, GPOINTER_TO_INT(pixel_width))); | 128 GetCharacterWidthForPixels(label, GPOINTER_TO_INT(pixel_width))); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // Ownership of |icon_list| is passed to the caller. | 131 // Ownership of |icon_list| is passed to the caller. |
| 132 GList* GetIconList() { | 132 GList* GetIconList() { |
| 133 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 133 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 134 GList* icon_list = NULL; | 134 GList* icon_list = NULL; |
| 135 icon_list = g_list_append(icon_list, | 135 icon_list = g_list_append(icon_list, |
| 136 rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32)); | 136 rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToGdkPixbuf()); |
| 137 icon_list = g_list_append(icon_list, | 137 icon_list = g_list_append(icon_list, |
| 138 rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_16)); | 138 rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_16).ToGdkPixbuf()); |
| 139 return icon_list; | 139 return icon_list; |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Returns the avatar icon for |profile|. | 142 // Returns the avatar icon for |profile|. |
| 143 // | 143 // |
| 144 // Returns NULL if there is only one profile; always returns an icon for | 144 // Returns NULL if there is only one profile; always returns an icon for |
| 145 // Incognito profiles. | 145 // Incognito profiles. |
| 146 // | 146 // |
| 147 // The returned pixbuf must not be unreferenced or freed because it's owned by | 147 // The returned pixbuf must not be unreferenced or freed because it's owned by |
| 148 // either the resource bundle or the profile info cache. | 148 // either the resource bundle or the profile info cache. |
| 149 GdkPixbuf* GetAvatarIcon(Profile* profile) { | 149 GdkPixbuf* GetAvatarIcon(Profile* profile) { |
| 150 if (profile->IsOffTheRecord()) { | 150 if (profile->IsOffTheRecord()) { |
| 151 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 151 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 152 return rb.GetNativeImageNamed(IDR_OTR_ICON); | 152 return rb.GetNativeImageNamed(IDR_OTR_ICON).ToGdkPixbuf(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 const ProfileInfoCache& cache = | 155 const ProfileInfoCache& cache = |
| 156 g_browser_process->profile_manager()->GetProfileInfoCache(); | 156 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 157 | 157 |
| 158 if (!ProfileManager::IsMultipleProfilesEnabled() || | 158 if (!ProfileManager::IsMultipleProfilesEnabled() || |
| 159 cache.GetNumberOfProfiles() < 2) | 159 cache.GetNumberOfProfiles() < 2) |
| 160 return NULL; | 160 return NULL; |
| 161 | 161 |
| 162 const size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 162 const size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 163 | 163 |
| 164 return (index != std::string::npos ? | 164 return (index != std::string::npos ? |
| 165 cache.GetAvatarIconOfProfileAtIndex(index) : | 165 cache.GetAvatarIconOfProfileAtIndex(index).ToGdkPixbuf() : |
| 166 static_cast<GdkPixbuf*>(NULL)); | 166 static_cast<GdkPixbuf*>(NULL)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Gets the Chrome product icon. | 169 // Gets the Chrome product icon. |
| 170 // | 170 // |
| 171 // If it doesn't find the icon in |theme|, it looks among the icons packaged | 171 // If it doesn't find the icon in |theme|, it looks among the icons packaged |
| 172 // with Chrome. | 172 // with Chrome. |
| 173 // | 173 // |
| 174 // Supported values of |size| are 16, 32, and 64. If the Chrome icon is found | 174 // Supported values of |size| are 16, 32, and 64. If the Chrome icon is found |
| 175 // in |theme|, the returned icon may not be of the requested size if |size| | 175 // in |theme|, the returned icon may not be of the requested size if |size| |
| (...skipping 19 matching lines...) Expand all Loading... |
| 195 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 195 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 196 int id = 0; | 196 int id = 0; |
| 197 | 197 |
| 198 switch (size) { | 198 switch (size) { |
| 199 case 16: id = IDR_PRODUCT_LOGO_16; break; | 199 case 16: id = IDR_PRODUCT_LOGO_16; break; |
| 200 case 32: id = IDR_PRODUCT_LOGO_32; break; | 200 case 32: id = IDR_PRODUCT_LOGO_32; break; |
| 201 case 64: id = IDR_PRODUCT_LOGO_64; break; | 201 case 64: id = IDR_PRODUCT_LOGO_64; break; |
| 202 default: CHECK(false); break; | 202 default: CHECK(false); break; |
| 203 } | 203 } |
| 204 | 204 |
| 205 return gdk_pixbuf_copy(rb.GetNativeImageNamed(id)); | 205 return gdk_pixbuf_copy(rb.GetNativeImageNamed(id).ToGdkPixbuf()); |
| 206 } | 206 } |
| 207 | 207 |
| 208 // Adds |emblem| to the bottom-right corner of |icon|. | 208 // Adds |emblem| to the bottom-right corner of |icon|. |
| 209 // | 209 // |
| 210 // Taking the ceiling of the scaled destination rect's dimensions (|dest_w| | 210 // Taking the ceiling of the scaled destination rect's dimensions (|dest_w| |
| 211 // and |dest_h|) because, if the destination rect is larger than the scaled | 211 // and |dest_h|) because, if the destination rect is larger than the scaled |
| 212 // emblem, gdk_pixbuf_composite() will replicate the edge pixels of the emblem | 212 // emblem, gdk_pixbuf_composite() will replicate the edge pixels of the emblem |
| 213 // to fill the gap, which is better than a cropped emblem, I think. | 213 // to fill the gap, which is better than a cropped emblem, I think. |
| 214 void AddEmblem(const GdkPixbuf* emblem, GdkPixbuf* icon) { | 214 void AddEmblem(const GdkPixbuf* emblem, GdkPixbuf* icon) { |
| 215 const int iw = gdk_pixbuf_get_width(icon); | 215 const int iw = gdk_pixbuf_get_width(icon); |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 | 1161 |
| 1162 void DoCopy(BrowserWindow* window) { | 1162 void DoCopy(BrowserWindow* window) { |
| 1163 DoCutCopyPaste(window, &RenderWidgetHost::Copy, "copy-clipboard"); | 1163 DoCutCopyPaste(window, &RenderWidgetHost::Copy, "copy-clipboard"); |
| 1164 } | 1164 } |
| 1165 | 1165 |
| 1166 void DoPaste(BrowserWindow* window) { | 1166 void DoPaste(BrowserWindow* window) { |
| 1167 DoCutCopyPaste(window, &RenderWidgetHost::Paste, "paste-clipboard"); | 1167 DoCutCopyPaste(window, &RenderWidgetHost::Paste, "paste-clipboard"); |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 } // namespace gtk_util | 1170 } // namespace gtk_util |
| OLD | NEW |