OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/gtk/infobars/infobar_gtk.h" | 5 #include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; | 45 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; |
46 const int InfoBar::kMaximumArrowTargetHalfWidth = 14; | 46 const int InfoBar::kMaximumArrowTargetHalfWidth = 14; |
47 const int InfoBar::kDefaultBarTargetHeight = 36; | 47 const int InfoBar::kDefaultBarTargetHeight = 36; |
48 | 48 |
49 | 49 |
50 // InfoBarGtk ----------------------------------------------------------------- | 50 // InfoBarGtk ----------------------------------------------------------------- |
51 | 51 |
52 // static | 52 // static |
53 const int InfoBarGtk::kEndOfLabelSpacing = 6; | 53 const int InfoBarGtk::kEndOfLabelSpacing = 6; |
54 | 54 |
55 InfoBarGtk::InfoBarGtk(InfoBarService* owner, InfoBarDelegate* delegate) | 55 InfoBarGtk::InfoBarGtk(scoped_ptr<InfoBarDelegate> delegate) |
56 : InfoBar(owner, delegate), | 56 : InfoBar(delegate.Pass()), |
57 bg_box_(NULL), | 57 bg_box_(NULL), |
58 hbox_(NULL), | 58 hbox_(NULL), |
59 theme_service_(NULL), | 59 theme_service_(NULL), |
60 signals_(new ui::GtkSignalRegistrar) { | 60 signals_(new ui::GtkSignalRegistrar) { |
61 } | 61 } |
62 | 62 |
63 InfoBarGtk::~InfoBarGtk() { | 63 InfoBarGtk::~InfoBarGtk() { |
64 } | 64 } |
65 | 65 |
66 void InfoBarGtk::InitWidgets() { | 66 GdkColor InfoBarGtk::GetBorderColor() const { |
| 67 DCHECK(theme_service_); |
| 68 return theme_service_->GetBorderColor(); |
| 69 } |
| 70 |
| 71 int InfoBarGtk::AnimatingHeight() const { |
| 72 return animation().is_animating() ? bar_target_height() : 0; |
| 73 } |
| 74 |
| 75 SkColor InfoBarGtk::ConvertGetColor(ColorGetter getter) { |
| 76 double r, g, b; |
| 77 (this->*getter)(delegate()->GetInfoBarType(), &r, &g, &b); |
| 78 return SkColorSetARGB(255, 255 * r, 255 * g, 255 * b); |
| 79 } |
| 80 |
| 81 void InfoBarGtk::GetTopColor(InfoBarDelegate::Type type, |
| 82 double* r, double* g, double* b) { |
| 83 GetBackgroundColor(InfoBar::GetTopColor(type), r, g, b); |
| 84 } |
| 85 |
| 86 void InfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, |
| 87 double* r, double* g, double* b) { |
| 88 GetBackgroundColor(InfoBar::GetBottomColor(type), r, g, b); |
| 89 } |
| 90 |
| 91 void InfoBarGtk::PlatformSpecificSetOwner() { |
67 DCHECK(owner()); | 92 DCHECK(owner()); |
68 DCHECK(!theme_service_); | 93 DCHECK(!theme_service_); |
69 theme_service_ = GtkThemeService::GetFrom(Profile::FromBrowserContext( | 94 theme_service_ = GtkThemeService::GetFrom(Profile::FromBrowserContext( |
70 owner()->web_contents()->GetBrowserContext())); | 95 owner()->web_contents()->GetBrowserContext())); |
71 | 96 |
72 // Create |hbox_| and pad the sides. | 97 // Create |hbox_| and pad the sides. |
73 hbox_ = gtk_hbox_new(FALSE, kElementPadding); | 98 hbox_ = gtk_hbox_new(FALSE, kElementPadding); |
74 | 99 |
75 // Make the whole infor bar horizontally shrinkable. | 100 // Make the whole infor bar horizontally shrinkable. |
76 gtk_widget_set_size_request(hbox_, 0, -1); | 101 gtk_widget_set_size_request(hbox_, 0, -1); |
(...skipping 30 matching lines...) Expand all Loading... |
107 | 132 |
108 g_signal_connect(widget_.get(), "child-size-request", | 133 g_signal_connect(widget_.get(), "child-size-request", |
109 G_CALLBACK(OnChildSizeRequestThunk), | 134 G_CALLBACK(OnChildSizeRequestThunk), |
110 this); | 135 this); |
111 | 136 |
112 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 137 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
113 content::Source<ThemeService>(theme_service_)); | 138 content::Source<ThemeService>(theme_service_)); |
114 UpdateBorderColor(); | 139 UpdateBorderColor(); |
115 } | 140 } |
116 | 141 |
117 GdkColor InfoBarGtk::GetBorderColor() const { | |
118 DCHECK(theme_service_); | |
119 return theme_service_->GetBorderColor(); | |
120 } | |
121 | |
122 int InfoBarGtk::AnimatingHeight() const { | |
123 return animation().is_animating() ? bar_target_height() : 0; | |
124 } | |
125 | |
126 SkColor InfoBarGtk::ConvertGetColor(ColorGetter getter) { | |
127 double r, g, b; | |
128 (this->*getter)(delegate()->GetInfoBarType(), &r, &g, &b); | |
129 return SkColorSetARGB(255, 255 * r, 255 * g, 255 * b); | |
130 } | |
131 | |
132 void InfoBarGtk::GetTopColor(InfoBarDelegate::Type type, | |
133 double* r, double* g, double* b) { | |
134 GetBackgroundColor(InfoBar::GetTopColor(type), r, g, b); | |
135 } | |
136 | |
137 void InfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, | |
138 double* r, double* g, double* b) { | |
139 GetBackgroundColor(InfoBar::GetBottomColor(type), r, g, b); | |
140 } | |
141 | |
142 void InfoBarGtk::PlatformSpecificShow(bool animate) { | 142 void InfoBarGtk::PlatformSpecificShow(bool animate) { |
143 DCHECK(bg_box_); | 143 DCHECK(bg_box_); |
144 | 144 |
145 DCHECK(widget()); | 145 DCHECK(widget()); |
146 gtk_widget_show_all(widget()); | 146 gtk_widget_show_all(widget()); |
147 gtk_widget_set_size_request(widget(), -1, bar_height()); | 147 gtk_widget_set_size_request(widget(), -1, bar_height()); |
148 | 148 |
149 GdkWindow* gdk_window = gtk_widget_get_window(bg_box_); | 149 GdkWindow* gdk_window = gtk_widget_get_window(bg_box_); |
150 if (gdk_window) | 150 if (gdk_window) |
151 gdk_window_lower(gdk_window); | 151 gdk_window_lower(gdk_window); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 267 } |
268 | 268 |
269 void InfoBarGtk::UpdateBorderColor() { | 269 void InfoBarGtk::UpdateBorderColor() { |
270 DCHECK(widget()); | 270 DCHECK(widget()); |
271 gtk_widget_queue_draw(widget()); | 271 gtk_widget_queue_draw(widget()); |
272 } | 272 } |
273 | 273 |
274 void InfoBarGtk::OnCloseButton(GtkWidget* button) { | 274 void InfoBarGtk::OnCloseButton(GtkWidget* button) { |
275 // If we're not owned, we're already closing, so don't call | 275 // If we're not owned, we're already closing, so don't call |
276 // InfoBarDismissed(), since this can lead to us double-recording dismissals. | 276 // InfoBarDismissed(), since this can lead to us double-recording dismissals. |
277 if (delegate() && owner()) | 277 if (owner()) |
278 delegate()->InfoBarDismissed(); | 278 delegate()->InfoBarDismissed(); |
279 RemoveSelf(); | 279 RemoveSelf(); |
280 } | 280 } |
281 | 281 |
282 gboolean InfoBarGtk::OnBackgroundExpose(GtkWidget* sender, | 282 gboolean InfoBarGtk::OnBackgroundExpose(GtkWidget* sender, |
283 GdkEventExpose* event) { | 283 GdkEventExpose* event) { |
284 TRACE_EVENT0("ui::gtk", "InfoBarGtk::OnBackgroundExpose"); | 284 TRACE_EVENT0("ui::gtk", "InfoBarGtk::OnBackgroundExpose"); |
285 DCHECK(theme_service_); | 285 DCHECK(theme_service_); |
286 | 286 |
287 GtkAllocation allocation; | 287 GtkAllocation allocation; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 324 } |
325 | 325 |
326 return FALSE; | 326 return FALSE; |
327 } | 327 } |
328 | 328 |
329 void InfoBarGtk::OnChildSizeRequest(GtkWidget* expanded, | 329 void InfoBarGtk::OnChildSizeRequest(GtkWidget* expanded, |
330 GtkWidget* child, | 330 GtkWidget* child, |
331 GtkRequisition* requisition) { | 331 GtkRequisition* requisition) { |
332 requisition->height = -1; | 332 requisition->height = -1; |
333 } | 333 } |
OLD | NEW |