| 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/gtk/infobar_gtk.h" | 5 #include "chrome/browser/gtk/infobar_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "app/gfx/gtk_util.h" | 9 #include "app/gfx/gtk_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 | 182 |
| 183 // AlertInfoBar ---------------------------------------------------------------- | 183 // AlertInfoBar ---------------------------------------------------------------- |
| 184 | 184 |
| 185 class AlertInfoBar : public InfoBar { | 185 class AlertInfoBar : public InfoBar { |
| 186 public: | 186 public: |
| 187 explicit AlertInfoBar(AlertInfoBarDelegate* delegate) | 187 explicit AlertInfoBar(AlertInfoBarDelegate* delegate) |
| 188 : InfoBar(delegate) { | 188 : InfoBar(delegate) { |
| 189 std::wstring text = delegate->GetMessageText(); | 189 std::wstring text = delegate->GetMessageText(); |
| 190 GtkWidget* label = gtk_label_new(WideToUTF8(text).c_str()); | 190 GtkWidget* label = gtk_label_new(WideToUTF8(text).c_str()); |
| 191 // We want the label to be horizontally shrinkable, so that the Chrome | |
| 192 // window can be resized freely even with a very long message. | |
| 193 gtk_widget_set_size_request(label, 0, -1); | |
| 194 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); | |
| 195 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 196 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gfx::kGdkBlack); | 191 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gfx::kGdkBlack); |
| 197 gtk_box_pack_start(GTK_BOX(hbox_), label, TRUE, TRUE, 0); | 192 gtk_box_pack_start(GTK_BOX(hbox_), label, FALSE, FALSE, 0); |
| 198 | 193 |
| 199 gtk_widget_show_all(border_bin_.get()); | 194 gtk_widget_show_all(border_bin_.get()); |
| 200 } | 195 } |
| 201 }; | 196 }; |
| 202 | 197 |
| 203 // LinkInfoBar ----------------------------------------------------------------- | 198 // LinkInfoBar ----------------------------------------------------------------- |
| 204 | 199 |
| 205 class LinkInfoBar : public InfoBar { | 200 class LinkInfoBar : public InfoBar { |
| 206 public: | 201 public: |
| 207 explicit LinkInfoBar(LinkInfoBarDelegate* delegate) | 202 explicit LinkInfoBar(LinkInfoBarDelegate* delegate) |
| 208 : InfoBar(delegate) { | 203 : InfoBar(delegate) { |
| 209 size_t link_offset; | 204 size_t link_offset; |
| 210 std::wstring display_text = | 205 std::wstring display_text = |
| 211 delegate->GetMessageTextWithOffset(&link_offset); | 206 delegate->GetMessageTextWithOffset(&link_offset); |
| 212 std::wstring link_text = delegate->GetLinkText(); | 207 std::wstring link_text = delegate->GetLinkText(); |
| 213 | 208 |
| 214 // Create the link button. | 209 // Create the link button. |
| 215 GtkWidget* link_button = | 210 GtkWidget* link_button = |
| 216 gtk_chrome_link_button_new(WideToUTF8(link_text).c_str()); | 211 gtk_chrome_link_button_new(WideToUTF8(link_text).c_str()); |
| 217 gtk_chrome_link_button_set_use_gtk_theme( | 212 gtk_chrome_link_button_set_use_gtk_theme( |
| 218 GTK_CHROME_LINK_BUTTON(link_button), FALSE); | 213 GTK_CHROME_LINK_BUTTON(link_button), FALSE); |
| 219 g_signal_connect(link_button, "clicked", | 214 g_signal_connect(link_button, "clicked", |
| 220 G_CALLBACK(OnLinkClick), this); | 215 G_CALLBACK(OnLinkClick), this); |
| 221 gtk_util::SetButtonTriggersNavigation(link_button); | 216 gtk_util::SetButtonTriggersNavigation(link_button); |
| 222 | 217 |
| 223 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); | |
| 224 // We want the link to be horizontally shrinkable, so that the Chrome | |
| 225 // window can be resized freely even with a very long link. | |
| 226 gtk_widget_set_size_request(hbox, 0, -1); | |
| 227 gtk_box_pack_start(GTK_BOX(hbox_), hbox, TRUE, TRUE, 0); | |
| 228 // If link_offset is npos, we right-align the link instead of embedding it | 218 // If link_offset is npos, we right-align the link instead of embedding it |
| 229 // in the text. | 219 // in the text. |
| 230 if (link_offset == std::wstring::npos) { | 220 if (link_offset == std::wstring::npos) { |
| 231 gtk_box_pack_end(GTK_BOX(hbox), link_button, FALSE, FALSE, 0); | 221 gtk_box_pack_end(GTK_BOX(hbox_), link_button, FALSE, FALSE, 0); |
| 232 GtkWidget* label = gtk_label_new(WideToUTF8(display_text).c_str()); | 222 GtkWidget* label = gtk_label_new(WideToUTF8(display_text).c_str()); |
| 233 // In order to avoid the link_button and the label overlapping with each | |
| 234 // other, we make the label shrinkable. | |
| 235 gtk_widget_set_size_request(label, 0, -1); | |
| 236 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); | |
| 237 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 238 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gfx::kGdkBlack); | 223 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gfx::kGdkBlack); |
| 239 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | 224 gtk_box_pack_start(GTK_BOX(hbox_), label, FALSE, FALSE, 0); |
| 240 } else { | 225 } else { |
| 241 GtkWidget* initial_label = gtk_label_new( | 226 GtkWidget* initial_label = gtk_label_new( |
| 242 WideToUTF8(display_text.substr(0, link_offset)).c_str()); | 227 WideToUTF8(display_text.substr(0, link_offset)).c_str()); |
| 243 GtkWidget* trailing_label = gtk_label_new( | 228 GtkWidget* trailing_label = gtk_label_new( |
| 244 WideToUTF8(display_text.substr(link_offset)).c_str()); | 229 WideToUTF8(display_text.substr(link_offset)).c_str()); |
| 245 | 230 |
| 246 gtk_widget_modify_fg(initial_label, GTK_STATE_NORMAL, &gfx::kGdkBlack); | 231 gtk_widget_modify_fg(initial_label, GTK_STATE_NORMAL, &gfx::kGdkBlack); |
| 247 gtk_widget_modify_fg(trailing_label, GTK_STATE_NORMAL, &gfx::kGdkBlack); | 232 gtk_widget_modify_fg(trailing_label, GTK_STATE_NORMAL, &gfx::kGdkBlack); |
| 248 | 233 |
| 249 // We don't want any spacing between the elements, so we pack them into | 234 // We don't want any spacing between the elements, so we pack them into |
| 250 // this hbox that doesn't use kElementPadding. | 235 // this hbox that doesn't use kElementPadding. |
| 236 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); |
| 251 gtk_box_pack_start(GTK_BOX(hbox), initial_label, FALSE, FALSE, 0); | 237 gtk_box_pack_start(GTK_BOX(hbox), initial_label, FALSE, FALSE, 0); |
| 252 gtk_util::CenterWidgetInHBox(hbox, link_button, false, 0); | 238 gtk_util::CenterWidgetInHBox(hbox, link_button, false, 0); |
| 253 gtk_box_pack_start(GTK_BOX(hbox), trailing_label, FALSE, FALSE, 0); | 239 gtk_box_pack_start(GTK_BOX(hbox), trailing_label, FALSE, FALSE, 0); |
| 240 gtk_box_pack_start(GTK_BOX(hbox_), hbox, FALSE, FALSE, 0); |
| 254 } | 241 } |
| 255 | 242 |
| 256 gtk_widget_show_all(border_bin_.get()); | 243 gtk_widget_show_all(border_bin_.get()); |
| 257 } | 244 } |
| 258 | 245 |
| 259 private: | 246 private: |
| 260 static void OnLinkClick(GtkWidget* button, LinkInfoBar* link_info_bar) { | 247 static void OnLinkClick(GtkWidget* button, LinkInfoBar* link_info_bar) { |
| 261 const GdkEventButton* button_click_event = | 248 const GdkEventButton* button_click_event = |
| 262 reinterpret_cast<GdkEventButton*>(gtk_get_current_event()); | 249 reinterpret_cast<GdkEventButton*>(gtk_get_current_event()); |
| 263 WindowOpenDisposition disposition = CURRENT_TAB; | 250 WindowOpenDisposition disposition = CURRENT_TAB; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 308 |
| 322 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { | 309 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { |
| 323 return new LinkInfoBar(this); | 310 return new LinkInfoBar(this); |
| 324 } | 311 } |
| 325 | 312 |
| 326 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- | 313 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- |
| 327 | 314 |
| 328 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { | 315 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { |
| 329 return new ConfirmInfoBar(this); | 316 return new ConfirmInfoBar(this); |
| 330 } | 317 } |
| OLD | NEW |