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

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

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 months 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) 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; 48 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight;
49 const int InfoBar::kMaximumArrowTargetHalfWidth = 14; 49 const int InfoBar::kMaximumArrowTargetHalfWidth = 14;
50 const int InfoBar::kDefaultBarTargetHeight = 36; 50 const int InfoBar::kDefaultBarTargetHeight = 36;
51 51
52 52
53 // InfoBarGtk ----------------------------------------------------------------- 53 // InfoBarGtk -----------------------------------------------------------------
54 54
55 // static 55 // static
56 const int InfoBarGtk::kEndOfLabelSpacing = 6; 56 const int InfoBarGtk::kEndOfLabelSpacing = 6;
57 57
58 InfoBarGtk::InfoBarGtk(InfoBarService* owner, InfoBarDelegate* delegate) 58 InfoBarGtk::InfoBarGtk(scoped_ptr<InfoBarDelegate> delegate)
59 : InfoBar(owner, delegate), 59 : InfoBar(delegate.Pass()),
60 bg_box_(NULL), 60 bg_box_(NULL),
61 hbox_(NULL), 61 hbox_(NULL),
62 theme_service_(NULL), 62 theme_service_(NULL),
63 signals_(new ui::GtkSignalRegistrar) { 63 signals_(new ui::GtkSignalRegistrar) {
64 } 64 }
65 65
66 InfoBarGtk::~InfoBarGtk() { 66 InfoBarGtk::~InfoBarGtk() {
67 } 67 }
68 68
69 void InfoBarGtk::InitWidgets() { 69 GdkColor InfoBarGtk::GetBorderColor() const {
70 DCHECK(theme_service_);
71 return theme_service_->GetBorderColor();
72 }
73
74 int InfoBarGtk::AnimatingHeight() const {
75 return animation().is_animating() ? bar_target_height() : 0;
76 }
77
78 SkColor InfoBarGtk::ConvertGetColor(ColorGetter getter) {
79 double r, g, b;
80 (this->*getter)(delegate()->GetInfoBarType(), &r, &g, &b);
81 return SkColorSetARGB(255, 255 * r, 255 * g, 255 * b);
82 }
83
84 void InfoBarGtk::GetTopColor(InfoBarDelegate::Type type,
85 double* r, double* g, double* b) {
86 GetBackgroundColor(InfoBar::GetTopColor(type), r, g, b);
87 }
88
89 void InfoBarGtk::GetBottomColor(InfoBarDelegate::Type type,
90 double* r, double* g, double* b) {
91 GetBackgroundColor(InfoBar::GetBottomColor(type), r, g, b);
92 }
93
94 void InfoBarGtk::PlatformSpecificSetOwner() {
70 DCHECK(owner()); 95 DCHECK(owner());
71 DCHECK(!theme_service_); 96 DCHECK(!theme_service_);
72 theme_service_ = GtkThemeService::GetFrom(Profile::FromBrowserContext( 97 theme_service_ = GtkThemeService::GetFrom(Profile::FromBrowserContext(
73 owner()->web_contents()->GetBrowserContext())); 98 owner()->web_contents()->GetBrowserContext()));
74 99
75 // Create |hbox_| and pad the sides. 100 // Create |hbox_| and pad the sides.
76 hbox_ = gtk_hbox_new(FALSE, kElementPadding); 101 hbox_ = gtk_hbox_new(FALSE, kElementPadding);
77 102
78 // Make the whole infor bar horizontally shrinkable. 103 // Make the whole infor bar horizontally shrinkable.
79 gtk_widget_set_size_request(hbox_, 0, -1); 104 gtk_widget_set_size_request(hbox_, 0, -1);
(...skipping 30 matching lines...) Expand all
110 135
111 g_signal_connect(widget_.get(), "child-size-request", 136 g_signal_connect(widget_.get(), "child-size-request",
112 G_CALLBACK(OnChildSizeRequestThunk), 137 G_CALLBACK(OnChildSizeRequestThunk),
113 this); 138 this);
114 139
115 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 140 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
116 content::Source<ThemeService>(theme_service_)); 141 content::Source<ThemeService>(theme_service_));
117 UpdateBorderColor(); 142 UpdateBorderColor();
118 } 143 }
119 144
120 GdkColor InfoBarGtk::GetBorderColor() const {
121 DCHECK(theme_service_);
122 return theme_service_->GetBorderColor();
123 }
124
125 int InfoBarGtk::AnimatingHeight() const {
126 return animation().is_animating() ? bar_target_height() : 0;
127 }
128
129 SkColor InfoBarGtk::ConvertGetColor(ColorGetter getter) {
130 double r, g, b;
131 (this->*getter)(delegate()->GetInfoBarType(), &r, &g, &b);
132 return SkColorSetARGB(255, 255 * r, 255 * g, 255 * b);
133 }
134
135 void InfoBarGtk::GetTopColor(InfoBarDelegate::Type type,
136 double* r, double* g, double* b) {
137 GetBackgroundColor(GetInfoBarTopColor(type), r, g, b);
138 }
139
140 void InfoBarGtk::GetBottomColor(InfoBarDelegate::Type type,
141 double* r, double* g, double* b) {
142 GetBackgroundColor(GetInfoBarBottomColor(type), r, g, b);
143 }
144
145 void InfoBarGtk::PlatformSpecificShow(bool animate) { 145 void InfoBarGtk::PlatformSpecificShow(bool animate) {
146 DCHECK(bg_box_); 146 DCHECK(bg_box_);
147 147
148 DCHECK(widget()); 148 DCHECK(widget());
149 gtk_widget_show_all(widget()); 149 gtk_widget_show_all(widget());
150 gtk_widget_set_size_request(widget(), -1, bar_height()); 150 gtk_widget_set_size_request(widget(), -1, bar_height());
151 151
152 GdkWindow* gdk_window = gtk_widget_get_window(bg_box_); 152 GdkWindow* gdk_window = gtk_widget_get_window(bg_box_);
153 if (gdk_window) 153 if (gdk_window)
154 gdk_window_lower(gdk_window); 154 gdk_window_lower(gdk_window);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 270 }
271 271
272 void InfoBarGtk::UpdateBorderColor() { 272 void InfoBarGtk::UpdateBorderColor() {
273 DCHECK(widget()); 273 DCHECK(widget());
274 gtk_widget_queue_draw(widget()); 274 gtk_widget_queue_draw(widget());
275 } 275 }
276 276
277 void InfoBarGtk::OnCloseButton(GtkWidget* button) { 277 void InfoBarGtk::OnCloseButton(GtkWidget* button) {
278 // If we're not owned, we're already closing, so don't call 278 // If we're not owned, we're already closing, so don't call
279 // InfoBarDismissed(), since this can lead to us double-recording dismissals. 279 // InfoBarDismissed(), since this can lead to us double-recording dismissals.
280 if (delegate() && owner()) 280 if (owner())
281 delegate()->InfoBarDismissed(); 281 delegate()->InfoBarDismissed();
282 RemoveSelf(); 282 RemoveSelf();
283 } 283 }
284 284
285 gboolean InfoBarGtk::OnBackgroundExpose(GtkWidget* sender, 285 gboolean InfoBarGtk::OnBackgroundExpose(GtkWidget* sender,
286 GdkEventExpose* event) { 286 GdkEventExpose* event) {
287 TRACE_EVENT0("ui::gtk", "InfoBarGtk::OnBackgroundExpose"); 287 TRACE_EVENT0("ui::gtk", "InfoBarGtk::OnBackgroundExpose");
288 DCHECK(theme_service_); 288 DCHECK(theme_service_);
289 289
290 GtkAllocation allocation; 290 GtkAllocation allocation;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 327 }
328 328
329 return FALSE; 329 return FALSE;
330 } 330 }
331 331
332 void InfoBarGtk::OnChildSizeRequest(GtkWidget* expanded, 332 void InfoBarGtk::OnChildSizeRequest(GtkWidget* expanded,
333 GtkWidget* child, 333 GtkWidget* child,
334 GtkRequisition* requisition) { 334 GtkRequisition* requisition) {
335 requisition->height = -1; 335 requisition->height = -1;
336 } 336 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698