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

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

Issue 4767001: Make TabContents own its infobar delegates.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 | Annotate | Revision Log
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 "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
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
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
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(cached_infobar_type_, &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
306 // Draw the bottom border. 306 // Draw the bottom border.
307 GdkColor border_color = theme_provider_->GetBorderColor(); 307 GdkColor border_color = theme_provider_->GetBorderColor();
308 cairo_set_source_rgb(cr, border_color.red / 65535.0, 308 cairo_set_source_rgb(cr, border_color.red / 65535.0,
309 border_color.green / 65535.0, 309 border_color.green / 65535.0,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()->
360 LinkClicked(gtk_util::DispositionForCurrentButtonPressEvent())) {
360 link_info_bar->RemoveInfoBar(); 361 link_info_bar->RemoveInfoBar();
361 } 362 }
362 } 363 }
363 }; 364 };
364 365
365 // ConfirmInfoBar -------------------------------------------------------------- 366 // ConfirmInfoBar --------------------------------------------------------------
366 367
367 class ConfirmInfoBar : public InfoBar { 368 class ConfirmInfoBar : public InfoBar {
368 public: 369 public:
369 explicit ConfirmInfoBar(ConfirmInfoBarDelegate* delegate); 370 explicit ConfirmInfoBar(ConfirmInfoBarDelegate* delegate);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 gtk_util::CenterWidgetInHBox(confirm_hbox_, button, false, 420 gtk_util::CenterWidgetInHBox(confirm_hbox_, button, false,
420 kButtonButtonSpacing); 421 kButtonButtonSpacing);
421 g_signal_connect(button, "clicked", 422 g_signal_connect(button, "clicked",
422 G_CALLBACK(type == ConfirmInfoBarDelegate::BUTTON_OK ? 423 G_CALLBACK(type == ConfirmInfoBarDelegate::BUTTON_OK ?
423 OnOkButtonThunk : OnCancelButtonThunk), 424 OnOkButtonThunk : OnCancelButtonThunk),
424 this); 425 this);
425 } 426 }
426 } 427 }
427 428
428 void ConfirmInfoBar::OnCancelButton(GtkWidget* widget) { 429 void ConfirmInfoBar::OnCancelButton(GtkWidget* widget) {
429 if (delegate_->AsConfirmInfoBarDelegate()->Cancel()) 430 if (delegate_ && delegate_->AsConfirmInfoBarDelegate()->Cancel())
430 RemoveInfoBar(); 431 RemoveInfoBar();
431 } 432 }
432 433
433 void ConfirmInfoBar::OnOkButton(GtkWidget* widget) { 434 void ConfirmInfoBar::OnOkButton(GtkWidget* widget) {
434 if (delegate_->AsConfirmInfoBarDelegate()->Accept()) 435 if (delegate_ && delegate_->AsConfirmInfoBarDelegate()->Accept())
435 RemoveInfoBar(); 436 RemoveInfoBar();
436 } 437 }
437 438
438 void ConfirmInfoBar::OnLinkClicked(GtkWidget* widget) { 439 void ConfirmInfoBar::OnLinkClicked(GtkWidget* widget) {
439 if (delegate_->AsConfirmInfoBarDelegate()->LinkClicked( 440 if (delegate_ && delegate_->AsConfirmInfoBarDelegate()->LinkClicked(
440 gtk_util::DispositionForCurrentButtonPressEvent())) { 441 gtk_util::DispositionForCurrentButtonPressEvent())) {
441 RemoveInfoBar(); 442 RemoveInfoBar();
442 } 443 }
443 } 444 }
444 445
445 InfoBar* AlertInfoBarDelegate::CreateInfoBar() { 446 InfoBar* AlertInfoBarDelegate::CreateInfoBar() {
446 return new AlertInfoBar(this); 447 return new AlertInfoBar(this);
447 } 448 }
448 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { 449 InfoBar* LinkInfoBarDelegate::CreateInfoBar() {
449 return new LinkInfoBar(this); 450 return new LinkInfoBar(this);
450 } 451 }
451 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { 452 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() {
452 return new ConfirmInfoBar(this); 453 return new ConfirmInfoBar(this);
453 } 454 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698