| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/certificate_viewer.h" | 11 #include "chrome/browser/certificate_viewer.h" |
| 12 #include "chrome/browser/google/google_util.h" | 12 #include "chrome/browser/google/google_util.h" |
| 13 #include "chrome/browser/page_info_model.h" | 13 #include "chrome/browser/page_info_model.h" |
| 14 #include "chrome/browser/page_info_model_observer.h" | 14 #include "chrome/browser/page_info_model_observer.h" |
| 15 #include "chrome/browser/page_info_window.h" | 15 #include "chrome/browser/page_info_window.h" |
| 16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
| 17 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" | 17 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" |
| 18 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 18 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 19 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" | 19 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" |
| 20 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 20 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
| 21 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 21 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 22 #include "chrome/browser/ui/gtk/gtk_util.h" | 22 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 23 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" | 23 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 27 #include "grit/locale_settings.h" | 27 #include "grit/locale_settings.h" |
| 28 #include "ui/base/gtk/gtk_hig_constants.h" | |
| 29 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 30 | 29 |
| 31 class Profile; | 30 class Profile; |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 class PageInfoBubbleGtk : public PageInfoModelObserver, | 34 class PageInfoBubbleGtk : public PageInfoModelObserver, |
| 36 public BubbleDelegateGtk { | 35 public BubbleDelegateGtk { |
| 37 public: | 36 public: |
| 38 PageInfoBubbleGtk(gfx::NativeWindow parent, | 37 PageInfoBubbleGtk(gfx::NativeWindow parent, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 InitContents(); | 128 InitContents(); |
| 130 } | 129 } |
| 131 | 130 |
| 132 void PageInfoBubbleGtk::BubbleClosing(BubbleGtk* bubble, | 131 void PageInfoBubbleGtk::BubbleClosing(BubbleGtk* bubble, |
| 133 bool closed_by_escape) { | 132 bool closed_by_escape) { |
| 134 delete this; | 133 delete this; |
| 135 } | 134 } |
| 136 | 135 |
| 137 void PageInfoBubbleGtk::InitContents() { | 136 void PageInfoBubbleGtk::InitContents() { |
| 138 if (!contents_) { | 137 if (!contents_) { |
| 139 contents_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing); | 138 contents_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing); |
| 140 gtk_container_set_border_width(GTK_CONTAINER(contents_), | 139 gtk_container_set_border_width(GTK_CONTAINER(contents_), |
| 141 ui::kContentAreaBorder); | 140 gtk_util::kContentAreaBorder); |
| 142 } else { | 141 } else { |
| 143 gtk_util::RemoveAllChildren(contents_); | 142 gtk_util::RemoveAllChildren(contents_); |
| 144 } | 143 } |
| 145 | 144 |
| 146 for (int i = 0; i < model_.GetSectionCount(); i++) { | 145 for (int i = 0; i < model_.GetSectionCount(); i++) { |
| 147 gtk_box_pack_start(GTK_BOX(contents_), | 146 gtk_box_pack_start(GTK_BOX(contents_), |
| 148 CreateSection(model_.GetSectionInfo(i)), | 147 CreateSection(model_.GetSectionInfo(i)), |
| 149 FALSE, FALSE, 0); | 148 FALSE, FALSE, 0); |
| 150 gtk_box_pack_start(GTK_BOX(contents_), | 149 gtk_box_pack_start(GTK_BOX(contents_), |
| 151 gtk_hseparator_new(), | 150 gtk_hseparator_new(), |
| 152 FALSE, FALSE, 0); | 151 FALSE, FALSE, 0); |
| 153 } | 152 } |
| 154 | 153 |
| 155 GtkWidget* help_link = theme_service_->BuildChromeLinkButton( | 154 GtkWidget* help_link = theme_service_->BuildChromeLinkButton( |
| 156 l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK)); | 155 l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK)); |
| 157 GtkWidget* help_link_hbox = gtk_hbox_new(FALSE, 0); | 156 GtkWidget* help_link_hbox = gtk_hbox_new(FALSE, 0); |
| 158 // Stick it in an hbox so it doesn't expand to the whole width. | 157 // Stick it in an hbox so it doesn't expand to the whole width. |
| 159 gtk_box_pack_start(GTK_BOX(help_link_hbox), help_link, FALSE, FALSE, 0); | 158 gtk_box_pack_start(GTK_BOX(help_link_hbox), help_link, FALSE, FALSE, 0); |
| 160 gtk_box_pack_start(GTK_BOX(contents_), help_link_hbox, FALSE, FALSE, 0); | 159 gtk_box_pack_start(GTK_BOX(contents_), help_link_hbox, FALSE, FALSE, 0); |
| 161 g_signal_connect(help_link, "clicked", | 160 g_signal_connect(help_link, "clicked", |
| 162 G_CALLBACK(OnHelpLinkClickedThunk), this); | 161 G_CALLBACK(OnHelpLinkClickedThunk), this); |
| 163 | 162 |
| 164 gtk_widget_show_all(contents_); | 163 gtk_widget_show_all(contents_); |
| 165 } | 164 } |
| 166 | 165 |
| 167 GtkWidget* PageInfoBubbleGtk::CreateSection( | 166 GtkWidget* PageInfoBubbleGtk::CreateSection( |
| 168 const PageInfoModel::SectionInfo& section) { | 167 const PageInfoModel::SectionInfo& section) { |
| 169 GtkWidget* section_box = gtk_hbox_new(FALSE, ui::kControlSpacing); | 168 GtkWidget* section_box = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); |
| 170 | 169 |
| 171 GdkPixbuf* pixbuf = *model_.GetIconImage(section.icon_id); | 170 GdkPixbuf* pixbuf = *model_.GetIconImage(section.icon_id); |
| 172 if (pixbuf) { | 171 if (pixbuf) { |
| 173 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); | 172 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
| 174 gtk_box_pack_start(GTK_BOX(section_box), image, FALSE, FALSE, 0); | 173 gtk_box_pack_start(GTK_BOX(section_box), image, FALSE, FALSE, 0); |
| 175 gtk_misc_set_alignment(GTK_MISC(image), 0, 0); | 174 gtk_misc_set_alignment(GTK_MISC(image), 0, 0); |
| 176 } | 175 } |
| 177 | 176 |
| 178 GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kControlSpacing); | 177 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
| 179 gtk_box_pack_start(GTK_BOX(section_box), vbox, TRUE, TRUE, 0); | 178 gtk_box_pack_start(GTK_BOX(section_box), vbox, TRUE, TRUE, 0); |
| 180 | 179 |
| 181 if (!section.headline.empty()) { | 180 if (!section.headline.empty()) { |
| 182 GtkWidget* label = theme_service_->BuildLabel( | 181 GtkWidget* label = theme_service_->BuildLabel( |
| 183 UTF16ToUTF8(section.headline), ui::kGdkBlack); | 182 UTF16ToUTF8(section.headline), gtk_util::kGdkBlack); |
| 184 gtk_label_set_selectable(GTK_LABEL(label), TRUE); | 183 gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
| 185 PangoAttrList* attributes = pango_attr_list_new(); | 184 PangoAttrList* attributes = pango_attr_list_new(); |
| 186 pango_attr_list_insert(attributes, | 185 pango_attr_list_insert(attributes, |
| 187 pango_attr_weight_new(PANGO_WEIGHT_BOLD)); | 186 pango_attr_weight_new(PANGO_WEIGHT_BOLD)); |
| 188 gtk_label_set_attributes(GTK_LABEL(label), attributes); | 187 gtk_label_set_attributes(GTK_LABEL(label), attributes); |
| 189 pango_attr_list_unref(attributes); | 188 pango_attr_list_unref(attributes); |
| 190 gtk_util::SetLabelWidth(label, 400); | 189 gtk_util::SetLabelWidth(label, 400); |
| 191 // Allow linebreaking in the middle of words if necessary, so that extremely | 190 // Allow linebreaking in the middle of words if necessary, so that extremely |
| 192 // long hostnames (longer than one line) will still be completely shown. | 191 // long hostnames (longer than one line) will still be completely shown. |
| 193 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); | 192 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); |
| 194 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | 193 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
| 195 } | 194 } |
| 196 GtkWidget* label = theme_service_->BuildLabel( | 195 GtkWidget* label = theme_service_->BuildLabel( |
| 197 UTF16ToUTF8(section.description), ui::kGdkBlack); | 196 UTF16ToUTF8(section.description), gtk_util::kGdkBlack); |
| 198 gtk_label_set_selectable(GTK_LABEL(label), TRUE); | 197 gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
| 199 gtk_util::SetLabelWidth(label, 400); | 198 gtk_util::SetLabelWidth(label, 400); |
| 200 // Allow linebreaking in the middle of words if necessary, so that extremely | 199 // Allow linebreaking in the middle of words if necessary, so that extremely |
| 201 // long hostnames (longer than one line) will still be completely shown. | 200 // long hostnames (longer than one line) will still be completely shown. |
| 202 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); | 201 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); |
| 203 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | 202 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
| 204 | 203 |
| 205 if (section.type == PageInfoModel::SECTION_INFO_IDENTITY && cert_id_ > 0) { | 204 if (section.type == PageInfoModel::SECTION_INFO_IDENTITY && cert_id_ > 0) { |
| 206 GtkWidget* view_cert_link = theme_service_->BuildChromeLinkButton( | 205 GtkWidget* view_cert_link = theme_service_->BuildChromeLinkButton( |
| 207 l10n_util::GetStringUTF8(IDS_PAGEINFO_CERT_INFO_BUTTON)); | 206 l10n_util::GetStringUTF8(IDS_PAGEINFO_CERT_INFO_BUTTON)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 236 | 235 |
| 237 void ShowPageInfoBubble(gfx::NativeWindow parent, | 236 void ShowPageInfoBubble(gfx::NativeWindow parent, |
| 238 Profile* profile, | 237 Profile* profile, |
| 239 const GURL& url, | 238 const GURL& url, |
| 240 const NavigationEntry::SSLStatus& ssl, | 239 const NavigationEntry::SSLStatus& ssl, |
| 241 bool show_history) { | 240 bool show_history) { |
| 242 new PageInfoBubbleGtk(parent, profile, url, ssl, show_history); | 241 new PageInfoBubbleGtk(parent, profile, url, ssl, show_history); |
| 243 } | 242 } |
| 244 | 243 |
| 245 } // namespace browser | 244 } // namespace browser |
| OLD | NEW |