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 "base/gfx/gtk_util.h" | 9 #include "base/gfx/gtk_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "chrome/browser/gtk/custom_button.h" | 11 #include "chrome/browser/gtk/custom_button.h" |
12 #include "chrome/browser/gtk/gtk_chrome_link_button.h" | 12 #include "chrome/browser/gtk/gtk_chrome_link_button.h" |
13 #include "chrome/browser/gtk/infobar_container_gtk.h" | 13 #include "chrome/browser/gtk/infobar_container_gtk.h" |
14 #include "chrome/browser/tab_contents/infobar_delegate.h" | 14 #include "chrome/browser/tab_contents/infobar_delegate.h" |
15 #include "chrome/common/gtk_util.h" | 15 #include "chrome/common/gtk_util.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // TODO(estade): The background should be a gradient. For now we just use this | 19 const double kBackgroundColorTop[3] = |
20 // solid color. | 20 {255.0 / 255.0, 242.0 / 255.0, 183.0 / 255.0}; |
21 const GdkColor kBackgroundColor = GDK_COLOR_RGB(250, 230, 145); | 21 const double kBackgroundColorBottom[3] = |
| 22 {250.0 / 255.0, 230.0 / 255.0, 145.0 / 255.0}; |
22 | 23 |
23 // Border color (the top pixel of the infobar). | 24 // Border color (the top pixel of the infobar). |
24 const GdkColor kBorderColor = GDK_COLOR_RGB(0xbe, 0xc8, 0xd4); | 25 const GdkColor kBorderColor = GDK_COLOR_RGB(0xbe, 0xc8, 0xd4); |
25 | 26 |
26 // The total height of the info bar. | 27 // The total height of the info bar. |
27 const int kInfoBarHeight = 37; | 28 const int kInfoBarHeight = 37; |
28 | 29 |
29 // Pixels between infobar elements. | 30 // Pixels between infobar elements. |
30 const int kElementPadding = 5; | 31 const int kElementPadding = 5; |
31 | 32 |
32 // Extra padding on either end of info bar. | 33 // Extra padding on either end of info bar. |
33 const int kLeftPadding = 5; | 34 const int kLeftPadding = 5; |
34 const int kRightPadding = 5; | 35 const int kRightPadding = 5; |
35 | 36 |
| 37 static gboolean OnBackgroundExpose(GtkWidget* widget, GdkEventExpose* event, |
| 38 gpointer unused) { |
| 39 const int height = widget->allocation.height; |
| 40 |
| 41 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
| 42 cairo_rectangle(cr, event->area.x, event->area.y, |
| 43 event->area.width, event->area.height); |
| 44 cairo_clip(cr); |
| 45 |
| 46 cairo_pattern_t* pattern = cairo_pattern_create_linear(0, 0, 0, height); |
| 47 cairo_pattern_add_color_stop_rgb( |
| 48 pattern, 0.0, |
| 49 kBackgroundColorTop[0], kBackgroundColorTop[1], kBackgroundColorTop[2]); |
| 50 cairo_pattern_add_color_stop_rgb( |
| 51 pattern, 1.0, |
| 52 kBackgroundColorBottom[0], kBackgroundColorBottom[1], |
| 53 kBackgroundColorBottom[2]); |
| 54 cairo_set_source(cr, pattern); |
| 55 cairo_paint(cr); |
| 56 cairo_pattern_destroy(pattern); |
| 57 |
| 58 cairo_destroy(cr); |
| 59 |
| 60 return FALSE; |
| 61 } |
| 62 |
36 } // namespace | 63 } // namespace |
37 | 64 |
38 InfoBar::InfoBar(InfoBarDelegate* delegate) | 65 InfoBar::InfoBar(InfoBarDelegate* delegate) |
39 : container_(NULL), | 66 : container_(NULL), |
40 delegate_(delegate) { | 67 delegate_(delegate) { |
41 // Create |hbox_| and pad the sides. | 68 // Create |hbox_| and pad the sides. |
42 hbox_ = gtk_hbox_new(FALSE, kElementPadding); | 69 hbox_ = gtk_hbox_new(FALSE, kElementPadding); |
43 GtkWidget* padding = gtk_alignment_new(0, 0, 1, 1); | 70 GtkWidget* padding = gtk_alignment_new(0, 0, 1, 1); |
44 gtk_alignment_set_padding(GTK_ALIGNMENT(padding), | 71 gtk_alignment_set_padding(GTK_ALIGNMENT(padding), |
45 0, 0, kLeftPadding, kRightPadding); | 72 0, 0, kLeftPadding, kRightPadding); |
46 | 73 |
47 GtkWidget* bg_box = gtk_event_box_new(); | 74 GtkWidget* bg_box = gtk_event_box_new(); |
| 75 gtk_widget_set_app_paintable(bg_box, TRUE); |
| 76 g_signal_connect(bg_box, "expose-event", |
| 77 G_CALLBACK(OnBackgroundExpose), NULL); |
48 gtk_container_add(GTK_CONTAINER(padding), hbox_); | 78 gtk_container_add(GTK_CONTAINER(padding), hbox_); |
49 gtk_container_add(GTK_CONTAINER(bg_box), padding); | 79 gtk_container_add(GTK_CONTAINER(bg_box), padding); |
50 | 80 |
51 // Set the top border and background color. | |
52 gtk_widget_modify_bg(bg_box, GTK_STATE_NORMAL, &kBackgroundColor); | |
53 border_bin_.Own(gtk_util::CreateGtkBorderBin(bg_box, &kBorderColor, | 81 border_bin_.Own(gtk_util::CreateGtkBorderBin(bg_box, &kBorderColor, |
54 0, 1, 0, 0)); | 82 0, 1, 0, 0)); |
55 gtk_widget_set_size_request(border_bin_.get(), -1, kInfoBarHeight); | 83 gtk_widget_set_size_request(border_bin_.get(), -1, kInfoBarHeight); |
56 | 84 |
57 // Add the icon on the left, if any. | 85 // Add the icon on the left, if any. |
58 SkBitmap* icon = delegate->GetIcon(); | 86 SkBitmap* icon = delegate->GetIcon(); |
59 if (icon) { | 87 if (icon) { |
60 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(icon); | 88 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(icon); |
61 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); | 89 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
62 g_object_unref(pixbuf); | 90 g_object_unref(pixbuf); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 275 |
248 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { | 276 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { |
249 return new LinkInfoBar(this); | 277 return new LinkInfoBar(this); |
250 } | 278 } |
251 | 279 |
252 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- | 280 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- |
253 | 281 |
254 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { | 282 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { |
255 return new ConfirmInfoBar(this); | 283 return new ConfirmInfoBar(this); |
256 } | 284 } |
OLD | NEW |