Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: chrome/browser/gtk/page_info_bubble_gtk.cc

Issue 3560004: Refactor the code for loading icons into the PageInfoModel. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: cleanup Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <gtk/gtk.h> 5 #include <gtk/gtk.h>
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h"
11 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
12 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/browser_list.h" 12 #include "chrome/browser/browser_list.h"
14 #include "chrome/browser/certificate_viewer.h" 13 #include "chrome/browser/certificate_viewer.h"
15 #include "chrome/browser/gtk/browser_toolbar_gtk.h" 14 #include "chrome/browser/gtk/browser_toolbar_gtk.h"
16 #include "chrome/browser/gtk/browser_window_gtk.h" 15 #include "chrome/browser/gtk/browser_window_gtk.h"
17 #include "chrome/browser/gtk/gtk_chrome_link_button.h" 16 #include "chrome/browser/gtk/gtk_chrome_link_button.h"
18 #include "chrome/browser/gtk/gtk_theme_provider.h" 17 #include "chrome/browser/gtk/gtk_theme_provider.h"
19 #include "chrome/browser/gtk/gtk_util.h" 18 #include "chrome/browser/gtk/gtk_util.h"
20 #include "chrome/browser/gtk/info_bubble_gtk.h" 19 #include "chrome/browser/gtk/info_bubble_gtk.h"
21 #include "chrome/browser/gtk/location_bar_view_gtk.h" 20 #include "chrome/browser/gtk/location_bar_view_gtk.h"
22 #include "chrome/browser/page_info_model.h" 21 #include "chrome/browser/page_info_model.h"
23 #include "chrome/browser/page_info_window.h" 22 #include "chrome/browser/page_info_window.h"
24 #include "chrome/common/notification_observer.h" 23 #include "chrome/common/notification_observer.h"
25 #include "chrome/common/notification_registrar.h" 24 #include "chrome/common/notification_registrar.h"
26 #include "chrome/common/notification_service.h" 25 #include "chrome/common/notification_service.h"
27 #include "gfx/gtk_util.h" 26 #include "gfx/gtk_util.h"
28 #include "googleurl/src/gurl.h" 27 #include "googleurl/src/gurl.h"
29 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
30 #include "grit/locale_settings.h" 29 #include "grit/locale_settings.h"
31 #include "grit/theme_resources.h"
32 30
33 class Profile; 31 class Profile;
34 32
35 namespace { 33 namespace {
36 34
37 class PageInfoBubbleGtk : public PageInfoModel::PageInfoModelObserver, 35 class PageInfoBubbleGtk : public PageInfoModel::PageInfoModelObserver,
38 public InfoBubbleGtkDelegate, 36 public InfoBubbleGtkDelegate,
39 public NotificationObserver { 37 public NotificationObserver {
40 public: 38 public:
41 PageInfoBubbleGtk(gfx::NativeWindow parent, 39 PageInfoBubbleGtk(gfx::NativeWindow parent,
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 G_CALLBACK(OnHelpLinkClickedThunk), this); 206 G_CALLBACK(OnHelpLinkClickedThunk), this);
209 207
210 theme_provider_->InitThemesFor(this); 208 theme_provider_->InitThemesFor(this);
211 gtk_widget_show_all(contents_); 209 gtk_widget_show_all(contents_);
212 } 210 }
213 211
214 GtkWidget* PageInfoBubbleGtk::CreateSection( 212 GtkWidget* PageInfoBubbleGtk::CreateSection(
215 const PageInfoModel::SectionInfo& section) { 213 const PageInfoModel::SectionInfo& section) {
216 GtkWidget* section_box = gtk_hbox_new(FALSE, 0); 214 GtkWidget* section_box = gtk_hbox_new(FALSE, 0);
217 215
218 if (section.type == PageInfoModel::SECTION_INFO_IDENTITY || 216 GdkPixbuf* pixbuf = model_.GetIconImage(section.icon_id);
219 section.type == PageInfoModel::SECTION_INFO_CONNECTION) { 217 if (pixbuf) {
220 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
221 GdkPixbuf* pixbuf = NULL;
222 switch (section.state) {
223 case PageInfoModel::SECTION_STATE_OK:
224 pixbuf = rb.GetPixbufNamed(IDR_PAGEINFO_GOOD);
225 break;
226 case PageInfoModel::SECTION_STATE_WARNING_MINOR:
227 DCHECK(section.type == PageInfoModel::SECTION_INFO_CONNECTION);
228 pixbuf = rb.GetPixbufNamed(IDR_PAGEINFO_WARNING_MINOR);
229 break;
230 case PageInfoModel::SECTION_STATE_WARNING_MAJOR:
231 pixbuf = rb.GetPixbufNamed(IDR_PAGEINFO_WARNING_MAJOR);
232 break;
233 case PageInfoModel::SECTION_STATE_ERROR:
234 pixbuf = rb.GetPixbufNamed(IDR_PAGEINFO_BAD);
235 break;
236 default:
237 NOTREACHED();
238 }
239 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); 218 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf);
240 gtk_box_pack_start(GTK_BOX(section_box), image, FALSE, FALSE, 219 gtk_box_pack_start(GTK_BOX(section_box), image, FALSE, FALSE,
241 gtk_util::kControlSpacing); 220 gtk_util::kControlSpacing);
242 gtk_misc_set_alignment(GTK_MISC(image), 0, 0);
243 } else if (section.type == PageInfoModel::SECTION_INFO_FIRST_VISIT) {
244 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
245 GdkPixbuf* pixbuf = section.state == PageInfoModel::SECTION_STATE_OK ?
246 rb.GetPixbufNamed(IDR_PAGEINFO_INFO) :
247 rb.GetPixbufNamed(IDR_PAGEINFO_WARNING_MAJOR);
248 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf);
249 gtk_box_pack_start(GTK_BOX(section_box), image, FALSE, FALSE,
250 gtk_util::kControlSpacing);
251 gtk_misc_set_alignment(GTK_MISC(image), 0, 0); 221 gtk_misc_set_alignment(GTK_MISC(image), 0, 0);
252 } 222 }
253 223
254 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); 224 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
255 gtk_box_pack_start(GTK_BOX(section_box), vbox, TRUE, TRUE, 0); 225 gtk_box_pack_start(GTK_BOX(section_box), vbox, TRUE, TRUE, 0);
256 226
257 if (!section.headline.empty()) { 227 if (!section.headline.empty()) {
258 GtkWidget* label = gtk_label_new(UTF16ToUTF8(section.headline).c_str()); 228 GtkWidget* label = gtk_label_new(UTF16ToUTF8(section.headline).c_str());
259 labels_.push_back(label); 229 labels_.push_back(label);
260 PangoAttrList* attributes = pango_attr_list_new(); 230 PangoAttrList* attributes = pango_attr_list_new();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 284
315 void ShowPageInfoBubble(gfx::NativeWindow parent, 285 void ShowPageInfoBubble(gfx::NativeWindow parent,
316 Profile* profile, 286 Profile* profile,
317 const GURL& url, 287 const GURL& url,
318 const NavigationEntry::SSLStatus& ssl, 288 const NavigationEntry::SSLStatus& ssl,
319 bool show_history) { 289 bool show_history) {
320 new PageInfoBubbleGtk(parent, profile, url, ssl, show_history); 290 new PageInfoBubbleGtk(parent, profile, url, ssl, show_history);
321 } 291 }
322 292
323 } // namespace browser 293 } // namespace browser
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/page_info_window_mac_unittest.mm ('k') | chrome/browser/gtk/page_info_window_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698