| 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/global_error_bubble.h" | 5 #include "chrome/browser/ui/gtk/global_error_bubble.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/global_error/global_error.h" | 12 #include "chrome/browser/ui/global_error/global_error.h" |
| 13 #include "chrome/browser/ui/global_error/global_error_service.h" | 13 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 14 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 14 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 15 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" | 15 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" |
| 16 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 16 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 17 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 17 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 18 #include "chrome/browser/ui/gtk/gtk_util.h" | 18 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 19 #include "ui/base/gtk/gtk_hig_constants.h" | 19 #include "ui/base/gtk/gtk_hig_constants.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/gtk_util.h" | 21 #include "ui/gfx/gtk_util.h" |
| 22 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Padding between content and edge of bubble. | |
| 27 const int kContentBorder = 7; | |
| 28 | |
| 29 // Horizontal spacing between the image view and the label. | |
| 30 const int kImageViewSpacing = 5; | |
| 31 | |
| 32 // Vertical spacing between labels. | |
| 33 const int kInterLineSpacing = 5; | |
| 34 | |
| 35 // Text size of the message label. 12.1px = 9pt @ 96dpi. | 26 // Text size of the message label. 12.1px = 9pt @ 96dpi. |
| 36 const double kMessageTextSize = 12.1; | 27 const double kMessageTextSize = 12.1; |
| 37 | 28 |
| 38 // Minimum width of the message label. | 29 // Minimum width of the message label. |
| 39 const int kMinMessageLabelWidth = 250; | 30 const int kMinMessageLabelWidth = 250; |
| 40 | 31 |
| 41 } // namespace | 32 } // namespace |
| 42 | 33 |
| 43 GlobalErrorBubble::GlobalErrorBubble(Browser* browser, | 34 GlobalErrorBubble::GlobalErrorBubble(Browser* browser, |
| 44 const base::WeakPtr<GlobalError>& error, | 35 const base::WeakPtr<GlobalError>& error, |
| 45 GtkWidget* anchor) | 36 GtkWidget* anchor) |
| 46 : browser_(browser), | 37 : browser_(browser), |
| 47 bubble_(NULL), | 38 bubble_(NULL), |
| 48 error_(error) { | 39 error_(error) { |
| 49 DCHECK(browser_); | 40 DCHECK(browser_); |
| 50 DCHECK(error_); | 41 DCHECK(error_); |
| 51 GtkWidget* content = gtk_vbox_new(FALSE, kInterLineSpacing); | 42 GtkWidget* content = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 52 gtk_container_set_border_width(GTK_CONTAINER(content), kContentBorder); | 43 gtk_container_set_border_width(GTK_CONTAINER(content), |
| 44 ui::kContentAreaBorder); |
| 53 g_signal_connect(content, "destroy", G_CALLBACK(OnDestroyThunk), this); | 45 g_signal_connect(content, "destroy", G_CALLBACK(OnDestroyThunk), this); |
| 54 | 46 |
| 55 GtkThemeService* theme_service = | 47 GtkThemeService* theme_service = |
| 56 GtkThemeService::GetFrom(browser_->profile()); | 48 GtkThemeService::GetFrom(browser_->profile()); |
| 57 | 49 |
| 58 int resource_id = error_->GetBubbleViewIconResourceID(); | 50 int resource_id = error_->GetBubbleViewIconResourceID(); |
| 59 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 51 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 60 GdkPixbuf* pixbuf = rb.GetNativeImageNamed(resource_id).ToGdkPixbuf(); | 52 GdkPixbuf* pixbuf = rb.GetNativeImageNamed(resource_id).ToGdkPixbuf(); |
| 61 GtkWidget* image_view = gtk_image_new_from_pixbuf(pixbuf); | 53 GtkWidget* image_view = gtk_image_new_from_pixbuf(pixbuf); |
| 62 | 54 |
| 63 GtkWidget* title_label = theme_service->BuildLabel( | 55 GtkWidget* title_label = theme_service->BuildLabel( |
| 64 UTF16ToUTF8(error_->GetBubbleViewTitle()), | 56 UTF16ToUTF8(error_->GetBubbleViewTitle()), |
| 65 ui::kGdkBlack); | 57 ui::kGdkBlack); |
| 66 message_label_ = theme_service->BuildLabel( | 58 message_label_ = theme_service->BuildLabel( |
| 67 UTF16ToUTF8(error_->GetBubbleViewMessage()), | 59 UTF16ToUTF8(error_->GetBubbleViewMessage()), |
| 68 ui::kGdkBlack); | 60 ui::kGdkBlack); |
| 69 gtk_util::ForceFontSizePixels(message_label_, kMessageTextSize); | 61 gtk_util::ForceFontSizePixels(message_label_, kMessageTextSize); |
| 70 // Message label will be sized later in "realize" callback because we need | 62 // Message label will be sized later in "realize" callback because we need |
| 71 // to now the width of buttons group. | 63 // to now the width of buttons group. |
| 72 GtkWidget* accept_button = gtk_button_new_with_label( | 64 GtkWidget* accept_button = gtk_button_new_with_label( |
| 73 UTF16ToUTF8(error_->GetBubbleViewAcceptButtonLabel()).c_str()); | 65 UTF16ToUTF8(error_->GetBubbleViewAcceptButtonLabel()).c_str()); |
| 74 string16 cancel_string = error_->GetBubbleViewCancelButtonLabel(); | 66 string16 cancel_string = error_->GetBubbleViewCancelButtonLabel(); |
| 75 GtkWidget* cancel_button = NULL; | 67 GtkWidget* cancel_button = NULL; |
| 76 if (!cancel_string.empty()) { | 68 if (!cancel_string.empty()) { |
| 77 cancel_button = | 69 cancel_button = |
| 78 gtk_button_new_with_label(UTF16ToUTF8(cancel_string).c_str()); | 70 gtk_button_new_with_label(UTF16ToUTF8(cancel_string).c_str()); |
| 79 } | 71 } |
| 80 | 72 |
| 81 // Top, icon and title. | 73 // Top, icon and title. |
| 82 GtkWidget* top = gtk_hbox_new(FALSE, kImageViewSpacing); | 74 GtkWidget* top = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| 83 gtk_box_pack_start(GTK_BOX(top), image_view, FALSE, FALSE, 0); | 75 gtk_box_pack_start(GTK_BOX(top), image_view, FALSE, FALSE, 0); |
| 84 gtk_box_pack_start(GTK_BOX(top), title_label, FALSE, FALSE, 0); | 76 gtk_box_pack_start(GTK_BOX(top), title_label, FALSE, FALSE, 0); |
| 85 gtk_box_pack_start(GTK_BOX(content), top, FALSE, FALSE, 0); | 77 gtk_box_pack_start(GTK_BOX(content), top, FALSE, FALSE, 0); |
| 86 | 78 |
| 87 // Middle, message. | 79 // Middle, message. |
| 88 gtk_box_pack_start(GTK_BOX(content), message_label_, FALSE, FALSE, 0); | 80 gtk_box_pack_start(GTK_BOX(content), message_label_, FALSE, FALSE, 0); |
| 89 gtk_box_pack_start(GTK_BOX(content), gtk_hbox_new(FALSE, 0), FALSE, FALSE, 0); | 81 gtk_box_pack_start(GTK_BOX(content), gtk_hbox_new(FALSE, 0), FALSE, FALSE, 0); |
| 90 | 82 |
| 91 // Bottom, accept and cancel button. | 83 // Bottom, accept and cancel button. |
| 92 // We want the buttons on the right, so just use an expanding label to fill | 84 // We want the buttons on the right, so just use an expanding label to fill |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 Browser* browser, | 155 Browser* browser, |
| 164 const base::WeakPtr<GlobalError>& error) { | 156 const base::WeakPtr<GlobalError>& error) { |
| 165 BrowserWindowGtk* browser_window = | 157 BrowserWindowGtk* browser_window = |
| 166 BrowserWindowGtk::GetBrowserWindowForNativeWindow( | 158 BrowserWindowGtk::GetBrowserWindowForNativeWindow( |
| 167 browser->window()->GetNativeWindow()); | 159 browser->window()->GetNativeWindow()); |
| 168 GtkWidget* anchor = browser_window->GetToolbar()->GetAppMenuButton(); | 160 GtkWidget* anchor = browser_window->GetToolbar()->GetAppMenuButton(); |
| 169 | 161 |
| 170 // The bubble will be automatically deleted when it's closed. | 162 // The bubble will be automatically deleted when it's closed. |
| 171 return new GlobalErrorBubble(browser, error, anchor); | 163 return new GlobalErrorBubble(browser, error, anchor); |
| 172 } | 164 } |
| OLD | NEW |