OLD | NEW |
---|---|
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 "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 "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/gtk/browser_window_gtk.h" | 10 #include "chrome/browser/gtk/browser_window_gtk.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 // Extra padding on either end of info bar. | 33 // Extra padding on either end of info bar. |
34 const int kLeftPadding = 5; | 34 const int kLeftPadding = 5; |
35 const int kRightPadding = 5; | 35 const int kRightPadding = 5; |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 InfoBar::InfoBar(InfoBarDelegate* delegate) | 39 InfoBar::InfoBar(InfoBarDelegate* delegate) |
40 : container_(NULL), | 40 : container_(NULL), |
41 delegate_(delegate), | 41 delegate_(delegate), |
42 theme_provider_(NULL), | 42 theme_provider_(NULL), |
43 arrow_model_(this) { | 43 arrow_model_(this), |
44 cached_infobar_type_(delegate->GetInfoBarType()) { | |
44 // Create |hbox_| and pad the sides. | 45 // Create |hbox_| and pad the sides. |
45 hbox_ = gtk_hbox_new(FALSE, kElementPadding); | 46 hbox_ = gtk_hbox_new(FALSE, kElementPadding); |
46 | 47 |
47 // Make the whole infor bar horizontally shrinkable. | 48 // Make the whole infor bar horizontally shrinkable. |
48 gtk_widget_set_size_request(hbox_, 0, -1); | 49 gtk_widget_set_size_request(hbox_, 0, -1); |
49 | 50 |
50 GtkWidget* padding = gtk_alignment_new(0, 0, 1, 1); | 51 GtkWidget* padding = gtk_alignment_new(0, 0, 1, 1); |
51 gtk_alignment_set_padding(GTK_ALIGNMENT(padding), | 52 gtk_alignment_set_padding(GTK_ALIGNMENT(padding), |
52 0, 0, kLeftPadding, kRightPadding); | 53 0, 0, kLeftPadding, kRightPadding); |
53 | 54 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 | 99 |
99 void InfoBar::Open() { | 100 void InfoBar::Open() { |
100 slide_widget_->OpenWithoutAnimation(); | 101 slide_widget_->OpenWithoutAnimation(); |
101 | 102 |
102 gtk_widget_show_all(bg_box_); | 103 gtk_widget_show_all(bg_box_); |
103 if (bg_box_->window) | 104 if (bg_box_->window) |
104 gdk_window_lower(bg_box_->window); | 105 gdk_window_lower(bg_box_->window); |
105 } | 106 } |
106 | 107 |
107 void InfoBar::AnimateClose() { | 108 void InfoBar::AnimateClose() { |
109 delegate_ = NULL; | |
108 slide_widget_->Close(); | 110 slide_widget_->Close(); |
109 } | 111 } |
110 | 112 |
111 void InfoBar::Close() { | 113 void InfoBar::Close() { |
112 if (delegate_) { | 114 delegate_ = NULL; |
113 delegate_->InfoBarClosed(); | |
114 delegate_ = NULL; | |
115 } | |
116 delete this; | 115 delete this; |
117 } | 116 } |
118 | 117 |
119 bool InfoBar::IsAnimating() { | 118 bool InfoBar::IsAnimating() { |
120 return slide_widget_->IsAnimating(); | 119 return slide_widget_->IsAnimating(); |
121 } | 120 } |
122 | 121 |
123 bool InfoBar::IsClosing() { | 122 bool InfoBar::IsClosing() { |
124 return slide_widget_->IsClosing(); | 123 return slide_widget_->IsClosing(); |
125 } | 124 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 *b = 231.0 / 255.0; | 268 *b = 231.0 / 255.0; |
270 break; | 269 break; |
271 } | 270 } |
272 } | 271 } |
273 | 272 |
274 void InfoBar::UpdateBorderColor() { | 273 void InfoBar::UpdateBorderColor() { |
275 gtk_widget_queue_draw(widget()); | 274 gtk_widget_queue_draw(widget()); |
276 } | 275 } |
277 | 276 |
278 void InfoBar::OnCloseButton(GtkWidget* button) { | 277 void InfoBar::OnCloseButton(GtkWidget* button) { |
279 if (delegate_) | 278 if (delegate_) { |
280 delegate_->InfoBarDismissed(); | 279 delegate_->InfoBarDismissed(); |
281 RemoveInfoBar(); | 280 RemoveInfoBar(); |
281 } | |
282 } | 282 } |
283 | 283 |
284 gboolean InfoBar::OnBackgroundExpose(GtkWidget* sender, | 284 gboolean InfoBar::OnBackgroundExpose(GtkWidget* sender, |
285 GdkEventExpose* event) { | 285 GdkEventExpose* event) { |
286 const int height = sender->allocation.height; | 286 const int height = sender->allocation.height; |
287 | 287 |
288 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(sender->window)); | 288 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(sender->window)); |
289 gdk_cairo_rectangle(cr, &event->area); | 289 gdk_cairo_rectangle(cr, &event->area); |
290 cairo_clip(cr); | 290 cairo_clip(cr); |
291 | 291 |
292 cairo_pattern_t* pattern = cairo_pattern_create_linear(0, 0, 0, height); | 292 cairo_pattern_t* pattern = cairo_pattern_create_linear(0, 0, 0, height); |
293 | 293 |
294 double top_r, top_g, top_b; | 294 double top_r, top_g, top_b; |
295 GetTopColor(delegate_->GetInfoBarType(), &top_r, &top_g, &top_b); | 295 GetTopColor(cached_infobar_type_, &top_r, &top_g, &top_b); |
296 cairo_pattern_add_color_stop_rgb(pattern, 0.0, top_r, top_g, top_b); | 296 cairo_pattern_add_color_stop_rgb(pattern, 0.0, top_r, top_g, top_b); |
297 | 297 |
298 double bottom_r, bottom_g, bottom_b; | 298 double bottom_r, bottom_g, bottom_b; |
299 GetBottomColor(delegate_->GetInfoBarType(), &bottom_r, &bottom_g, &bottom_b); | 299 GetBottomColor(delegate_->GetInfoBarType(), &bottom_r, &bottom_g, &bottom_b); |
300 cairo_pattern_add_color_stop_rgb( | 300 cairo_pattern_add_color_stop_rgb( |
301 pattern, 1.0, bottom_r, bottom_g, bottom_b); | 301 pattern, 1.0, bottom_r, bottom_g, bottom_b); |
302 cairo_set_source(cr, pattern); | 302 cairo_set_source(cr, pattern); |
303 cairo_paint(cr); | 303 cairo_paint(cr); |
304 cairo_pattern_destroy(pattern); | 304 cairo_pattern_destroy(pattern); |
305 | 305 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 : InfoBar(delegate) { | 348 : InfoBar(delegate) { |
349 size_t link_offset; | 349 size_t link_offset; |
350 string16 display_text = delegate->GetMessageTextWithOffset(&link_offset); | 350 string16 display_text = delegate->GetMessageTextWithOffset(&link_offset); |
351 string16 link_text = delegate->GetLinkText(); | 351 string16 link_text = delegate->GetLinkText(); |
352 AddLabelWithInlineLink(display_text, link_text, link_offset, | 352 AddLabelWithInlineLink(display_text, link_text, link_offset, |
353 G_CALLBACK(OnLinkClick)); | 353 G_CALLBACK(OnLinkClick)); |
354 } | 354 } |
355 | 355 |
356 private: | 356 private: |
357 static void OnLinkClick(GtkWidget* button, LinkInfoBar* link_info_bar) { | 357 static void OnLinkClick(GtkWidget* button, LinkInfoBar* link_info_bar) { |
358 if (link_info_bar->delegate_->AsLinkInfoBarDelegate()-> | 358 if (link_info_bar->delegate_ && |
359 LinkClicked(gtk_util::DispositionForCurrentButtonPressEvent())) { | 359 link_info_bar->delegate_->AsLinkInfoBarDelegate()-> |
Evan Stade
2010/11/11 22:39:47
I understand that leaving off the {} in this case
Peter Kasting
2010/11/11 22:47:58
Sorry! Reverted here and below.
| |
360 LinkClicked(gtk_util::DispositionForCurrentButtonPressEvent())) | |
360 link_info_bar->RemoveInfoBar(); | 361 link_info_bar->RemoveInfoBar(); |
361 } | |
362 } | 362 } |
363 }; | 363 }; |
364 | 364 |
365 // ConfirmInfoBar -------------------------------------------------------------- | 365 // ConfirmInfoBar -------------------------------------------------------------- |
366 | 366 |
367 class ConfirmInfoBar : public InfoBar { | 367 class ConfirmInfoBar : public InfoBar { |
368 public: | 368 public: |
369 explicit ConfirmInfoBar(ConfirmInfoBarDelegate* delegate); | 369 explicit ConfirmInfoBar(ConfirmInfoBarDelegate* delegate); |
370 | 370 |
371 private: | 371 private: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 gtk_util::CenterWidgetInHBox(confirm_hbox_, button, false, | 419 gtk_util::CenterWidgetInHBox(confirm_hbox_, button, false, |
420 kButtonButtonSpacing); | 420 kButtonButtonSpacing); |
421 g_signal_connect(button, "clicked", | 421 g_signal_connect(button, "clicked", |
422 G_CALLBACK(type == ConfirmInfoBarDelegate::BUTTON_OK ? | 422 G_CALLBACK(type == ConfirmInfoBarDelegate::BUTTON_OK ? |
423 OnOkButtonThunk : OnCancelButtonThunk), | 423 OnOkButtonThunk : OnCancelButtonThunk), |
424 this); | 424 this); |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 void ConfirmInfoBar::OnCancelButton(GtkWidget* widget) { | 428 void ConfirmInfoBar::OnCancelButton(GtkWidget* widget) { |
429 if (delegate_->AsConfirmInfoBarDelegate()->Cancel()) | 429 if (delegate_ && delegate_->AsConfirmInfoBarDelegate()->Cancel()) |
430 RemoveInfoBar(); | 430 RemoveInfoBar(); |
431 } | 431 } |
432 | 432 |
433 void ConfirmInfoBar::OnOkButton(GtkWidget* widget) { | 433 void ConfirmInfoBar::OnOkButton(GtkWidget* widget) { |
434 if (delegate_->AsConfirmInfoBarDelegate()->Accept()) | 434 if (delegate_ && delegate_->AsConfirmInfoBarDelegate()->Accept()) |
435 RemoveInfoBar(); | 435 RemoveInfoBar(); |
436 } | 436 } |
437 | 437 |
438 void ConfirmInfoBar::OnLinkClicked(GtkWidget* widget) { | 438 void ConfirmInfoBar::OnLinkClicked(GtkWidget* widget) { |
439 if (delegate_->AsConfirmInfoBarDelegate()->LinkClicked( | 439 if (delegate_ && delegate_->AsConfirmInfoBarDelegate()->LinkClicked( |
440 gtk_util::DispositionForCurrentButtonPressEvent())) { | 440 gtk_util::DispositionForCurrentButtonPressEvent())) |
441 RemoveInfoBar(); | 441 RemoveInfoBar(); |
442 } | |
443 } | 442 } |
444 | 443 |
445 InfoBar* AlertInfoBarDelegate::CreateInfoBar() { | 444 InfoBar* AlertInfoBarDelegate::CreateInfoBar() { |
446 return new AlertInfoBar(this); | 445 return new AlertInfoBar(this); |
447 } | 446 } |
448 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { | 447 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { |
449 return new LinkInfoBar(this); | 448 return new LinkInfoBar(this); |
450 } | 449 } |
451 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { | 450 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { |
452 return new ConfirmInfoBar(this); | 451 return new ConfirmInfoBar(this); |
453 } | 452 } |
OLD | NEW |