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