| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/infobar_gtk.h" | 5 #include "chrome/browser/ui/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/platform_util.h" | 10 #include "chrome/browser/platform_util.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 180 |
| 181 // Need to insert the link inside the display text. | 181 // Need to insert the link inside the display text. |
| 182 GtkWidget* initial_label = gtk_label_new( | 182 GtkWidget* initial_label = gtk_label_new( |
| 183 UTF16ToUTF8(display_text.substr(0, link_offset)).c_str()); | 183 UTF16ToUTF8(display_text.substr(0, link_offset)).c_str()); |
| 184 GtkWidget* trailing_label = gtk_label_new( | 184 GtkWidget* trailing_label = gtk_label_new( |
| 185 UTF16ToUTF8(display_text.substr(link_offset)).c_str()); | 185 UTF16ToUTF8(display_text.substr(link_offset)).c_str()); |
| 186 | 186 |
| 187 gtk_util::ForceFontSizePixels(initial_label, 13.4); | 187 gtk_util::ForceFontSizePixels(initial_label, 13.4); |
| 188 gtk_util::ForceFontSizePixels(trailing_label, 13.4); | 188 gtk_util::ForceFontSizePixels(trailing_label, 13.4); |
| 189 | 189 |
| 190 // TODO(joth): Unlike the AddLabelAndLink below, none of the label widgets | 190 // TODO(joth): None of the label widgets are set as shrinkable here, meaning |
| 191 // are set as shrinkable here, meaning the text will run under the close | 191 // the text will run under the close button etc. when the width is restricted, |
| 192 // button etc. when the width is restricted, rather than eliding. | 192 // rather than eliding. |
| 193 gtk_widget_modify_fg(initial_label, GTK_STATE_NORMAL, >k_util::kGdkBlack); | 193 gtk_widget_modify_fg(initial_label, GTK_STATE_NORMAL, >k_util::kGdkBlack); |
| 194 gtk_widget_modify_fg(trailing_label, GTK_STATE_NORMAL, >k_util::kGdkBlack); | 194 gtk_widget_modify_fg(trailing_label, GTK_STATE_NORMAL, >k_util::kGdkBlack); |
| 195 | 195 |
| 196 // We don't want any spacing between the elements, so we pack them into | 196 // We don't want any spacing between the elements, so we pack them into |
| 197 // this hbox that doesn't use kElementPadding. | 197 // this hbox that doesn't use kElementPadding. |
| 198 gtk_box_pack_start(GTK_BOX(hbox), initial_label, FALSE, FALSE, 0); | 198 gtk_box_pack_start(GTK_BOX(hbox), initial_label, FALSE, FALSE, 0); |
| 199 gtk_util::CenterWidgetInHBox(hbox, link_button, false, 0); | 199 gtk_util::CenterWidgetInHBox(hbox, link_button, false, 0); |
| 200 gtk_box_pack_start(GTK_BOX(hbox), trailing_label, FALSE, FALSE, 0); | 200 gtk_box_pack_start(GTK_BOX(hbox), trailing_label, FALSE, FALSE, 0); |
| 201 } | 201 } |
| 202 | 202 |
| 203 // TODO(joth): This method factors out some common functionality between the | |
| 204 // various derived infobar classes, however the class hierarchy itself could | |
| 205 // use refactoring to reduce this duplication. http://crbug.com/38924 | |
| 206 void InfoBar::AddLabelAndLink(const string16& display_text, | |
| 207 const string16& link_text, | |
| 208 GCallback callback) { | |
| 209 GtkWidget* link_button = NULL; | |
| 210 if (!link_text.empty()) { | |
| 211 // If we have some link text, create the link button. | |
| 212 link_button = gtk_chrome_link_button_new(UTF16ToUTF8(link_text).c_str()); | |
| 213 gtk_chrome_link_button_set_use_gtk_theme( | |
| 214 GTK_CHROME_LINK_BUTTON(link_button), FALSE); | |
| 215 DCHECK(callback); | |
| 216 g_signal_connect(link_button, "clicked", callback, this); | |
| 217 gtk_util::SetButtonTriggersNavigation(link_button); | |
| 218 } | |
| 219 | |
| 220 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); | |
| 221 // We want the link to be horizontally shrinkable, so that the Chrome | |
| 222 // window can be resized freely even with a very long link. | |
| 223 gtk_widget_set_size_request(hbox, 0, -1); | |
| 224 gtk_box_pack_start(GTK_BOX(hbox_), hbox, TRUE, TRUE, 0); | |
| 225 | |
| 226 if (link_button) | |
| 227 gtk_box_pack_end(GTK_BOX(hbox), link_button, FALSE, FALSE, 0); | |
| 228 GtkWidget* label = gtk_label_new(UTF16ToUTF8(display_text).c_str()); | |
| 229 gtk_util::ForceFontSizePixels(label, 13.4); | |
| 230 // In order to avoid the link_button and the label overlapping with each | |
| 231 // other, we make the label shrinkable. | |
| 232 gtk_widget_set_size_request(label, 0, -1); | |
| 233 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); | |
| 234 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 235 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, >k_util::kGdkBlack); | |
| 236 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | |
| 237 } | |
| 238 | |
| 239 void InfoBar::GetTopColor(InfoBarDelegate::Type type, | 203 void InfoBar::GetTopColor(InfoBarDelegate::Type type, |
| 240 double* r, double* g, double *b) { | 204 double* r, double* g, double *b) { |
| 241 // These constants are copied from corresponding skia constants from | 205 // These constants are copied from corresponding skia constants from |
| 242 // browser/ui/views/infobars/infobars.cc, and then changed into 0-1 ranged | 206 // browser/ui/views/infobars/infobars.cc, and then changed into 0-1 ranged |
| 243 // values for cairo. | 207 // values for cairo. |
| 244 switch (type) { | 208 switch (type) { |
| 245 case InfoBarDelegate::WARNING_TYPE: | 209 case InfoBarDelegate::WARNING_TYPE: |
| 246 *r = 255.0 / 255.0; | 210 *r = 255.0 / 255.0; |
| 247 *g = 242.0 / 255.0; | 211 *g = 242.0 / 255.0; |
| 248 *b = 183.0 / 255.0; | 212 *b = 183.0 / 255.0; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 BrowserWindowGtk* browser_window = | 287 BrowserWindowGtk* browser_window = |
| 324 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent); | 288 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent); |
| 325 int x = browser_window ? | 289 int x = browser_window ? |
| 326 browser_window->GetXPositionOfLocationIcon(sender) : 0; | 290 browser_window->GetXPositionOfLocationIcon(sender) : 0; |
| 327 | 291 |
| 328 arrow_model_.Paint(sender, event, gfx::Point(x, y), border_color); | 292 arrow_model_.Paint(sender, event, gfx::Point(x, y), border_color); |
| 329 | 293 |
| 330 return FALSE; | 294 return FALSE; |
| 331 } | 295 } |
| 332 | 296 |
| 333 // AlertInfoBar ---------------------------------------------------------------- | |
| 334 | |
| 335 class AlertInfoBar : public InfoBar { | |
| 336 public: | |
| 337 explicit AlertInfoBar(AlertInfoBarDelegate* delegate) | |
| 338 : InfoBar(delegate) { | |
| 339 AddLabelAndLink(delegate->GetMessageText(), string16(), NULL); | |
| 340 } | |
| 341 }; | |
| 342 | |
| 343 // LinkInfoBar ----------------------------------------------------------------- | 297 // LinkInfoBar ----------------------------------------------------------------- |
| 344 | 298 |
| 345 class LinkInfoBar : public InfoBar { | 299 class LinkInfoBar : public InfoBar { |
| 346 public: | 300 public: |
| 347 explicit LinkInfoBar(LinkInfoBarDelegate* delegate) | 301 explicit LinkInfoBar(LinkInfoBarDelegate* delegate) |
| 348 : InfoBar(delegate) { | 302 : InfoBar(delegate) { |
| 349 size_t link_offset; | 303 size_t link_offset; |
| 350 string16 display_text = delegate->GetMessageTextWithOffset(&link_offset); | 304 string16 display_text = delegate->GetMessageTextWithOffset(&link_offset); |
| 351 string16 link_text = delegate->GetLinkText(); | 305 string16 link_text = delegate->GetLinkText(); |
| 352 AddLabelWithInlineLink(display_text, link_text, link_offset, | 306 AddLabelWithInlineLink(display_text, link_text, link_offset, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 RemoveInfoBar(); | 397 RemoveInfoBar(); |
| 444 } | 398 } |
| 445 | 399 |
| 446 void ConfirmInfoBar::OnLinkClicked(GtkWidget* widget) { | 400 void ConfirmInfoBar::OnLinkClicked(GtkWidget* widget) { |
| 447 if (delegate_->AsConfirmInfoBarDelegate()->LinkClicked( | 401 if (delegate_->AsConfirmInfoBarDelegate()->LinkClicked( |
| 448 gtk_util::DispositionForCurrentButtonPressEvent())) { | 402 gtk_util::DispositionForCurrentButtonPressEvent())) { |
| 449 RemoveInfoBar(); | 403 RemoveInfoBar(); |
| 450 } | 404 } |
| 451 } | 405 } |
| 452 | 406 |
| 453 InfoBar* AlertInfoBarDelegate::CreateInfoBar() { | |
| 454 return new AlertInfoBar(this); | |
| 455 } | |
| 456 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { | 407 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { |
| 457 return new LinkInfoBar(this); | 408 return new LinkInfoBar(this); |
| 458 } | 409 } |
| 410 |
| 459 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { | 411 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { |
| 460 return new ConfirmInfoBar(this); | 412 return new ConfirmInfoBar(this); |
| 461 } | 413 } |
| OLD | NEW |