| 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/create_application_shortcuts_dialog_gtk.h" | 5 #include "chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/shell_integration.h" | 11 #include "chrome/browser/shell_integration.h" |
| 12 #include "chrome/browser/ui/gtk/gtk_util.h" | 12 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 14 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 14 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 15 #include "chrome/browser/ui/webui/extension_icon_source.h" | 15 #include "chrome/browser/ui/webui/extension_icon_source.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/extensions/extension_resource.h" | 17 #include "chrome/common/extensions/extension_resource.h" |
| 18 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
| 19 #include "content/browser/tab_contents/tab_contents.h" | 19 #include "content/browser/tab_contents/tab_contents.h" |
| 20 #include "content/browser/tab_contents/tab_contents_delegate.h" | 20 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 21 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
| 22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 23 #include "grit/locale_settings.h" | 23 #include "grit/locale_settings.h" |
| 24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 #include "ui/base/gtk/gtk_hig_constants.h" | |
| 26 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/gfx/gtk_util.h" | 26 #include "ui/gfx/gtk_util.h" |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 // Size (in pixels) of the icon preview. | 30 // Size (in pixels) of the icon preview. |
| 32 const int kIconPreviewSizePixels = 32; | 31 const int kIconPreviewSizePixels = 32; |
| 33 | 32 |
| 34 // Height (in lines) of the shortcut description label. | 33 // Height (in lines) of the shortcut description label. |
| 35 const int kDescriptionLabelHeightLines = 3; | 34 const int kDescriptionLabelHeightLines = 3; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 gtk_window_set_resizable(GTK_WINDOW(create_dialog_), false); | 95 gtk_window_set_resizable(GTK_WINDOW(create_dialog_), false); |
| 97 gtk_util::AddButtonToDialog(create_dialog_, | 96 gtk_util::AddButtonToDialog(create_dialog_, |
| 98 l10n_util::GetStringUTF8(IDS_CANCEL).c_str(), | 97 l10n_util::GetStringUTF8(IDS_CANCEL).c_str(), |
| 99 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT); | 98 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT); |
| 100 gtk_util::AddButtonToDialog(create_dialog_, | 99 gtk_util::AddButtonToDialog(create_dialog_, |
| 101 l10n_util::GetStringUTF8(IDS_CREATE_SHORTCUTS_COMMIT).c_str(), | 100 l10n_util::GetStringUTF8(IDS_CREATE_SHORTCUTS_COMMIT).c_str(), |
| 102 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); | 101 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); |
| 103 | 102 |
| 104 GtkWidget* content_area = | 103 GtkWidget* content_area = |
| 105 gtk_dialog_get_content_area(GTK_DIALOG(create_dialog_)); | 104 gtk_dialog_get_content_area(GTK_DIALOG(create_dialog_)); |
| 106 gtk_box_set_spacing(GTK_BOX(content_area), ui::kContentAreaSpacing); | 105 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); |
| 107 | 106 |
| 108 GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kControlSpacing); | 107 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
| 109 gtk_container_add(GTK_CONTAINER(content_area), vbox); | 108 gtk_container_add(GTK_CONTAINER(content_area), vbox); |
| 110 | 109 |
| 111 // Create a box containing basic information about the new shortcut: an image | 110 // Create a box containing basic information about the new shortcut: an image |
| 112 // on the left, and a description on the right. | 111 // on the left, and a description on the right. |
| 113 GtkWidget* hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); | 112 GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); |
| 114 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | 113 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
| 115 gtk_container_set_border_width(GTK_CONTAINER(hbox), | 114 gtk_container_set_border_width(GTK_CONTAINER(hbox), |
| 116 ui::kControlSpacing); | 115 gtk_util::kControlSpacing); |
| 117 | 116 |
| 118 // Put the icon preview in place. | 117 // Put the icon preview in place. |
| 119 GtkWidget* favicon_image = gtk_image_new_from_pixbuf(favicon_pixbuf_); | 118 GtkWidget* favicon_image = gtk_image_new_from_pixbuf(favicon_pixbuf_); |
| 120 gtk_box_pack_start(GTK_BOX(hbox), favicon_image, FALSE, FALSE, 0); | 119 gtk_box_pack_start(GTK_BOX(hbox), favicon_image, FALSE, FALSE, 0); |
| 121 | 120 |
| 122 // Create the label with application shortcut description. | 121 // Create the label with application shortcut description. |
| 123 GtkWidget* description_label = gtk_label_new(NULL); | 122 GtkWidget* description_label = gtk_label_new(NULL); |
| 124 gtk_box_pack_start(GTK_BOX(hbox), description_label, FALSE, FALSE, 0); | 123 gtk_box_pack_start(GTK_BOX(hbox), description_label, FALSE, FALSE, 0); |
| 125 gtk_label_set_line_wrap(GTK_LABEL(description_label), TRUE); | 124 gtk_label_set_line_wrap(GTK_LABEL(description_label), TRUE); |
| 126 gtk_widget_realize(description_label); | 125 gtk_widget_realize(description_label); |
| 127 | 126 |
| 128 // Set the size request on the label so it knows where to line wrap. The width | 127 // Set the size request on the label so it knows where to line wrap. The width |
| 129 // is the desired size of the dialog less the space reserved for padding and | 128 // is the desired size of the dialog less the space reserved for padding and |
| 130 // the image. | 129 // the image. |
| 131 int label_width; | 130 int label_width; |
| 132 gtk_util::GetWidgetSizeFromResources( | 131 gtk_util::GetWidgetSizeFromResources( |
| 133 description_label, | 132 description_label, |
| 134 IDS_CREATE_SHORTCUTS_DIALOG_WIDTH_CHARS, -1, &label_width, NULL); | 133 IDS_CREATE_SHORTCUTS_DIALOG_WIDTH_CHARS, -1, &label_width, NULL); |
| 135 label_width -= ui::kControlSpacing * 3 + | 134 label_width -= gtk_util::kControlSpacing * 3 + |
| 136 gdk_pixbuf_get_width(favicon_pixbuf_); | 135 gdk_pixbuf_get_width(favicon_pixbuf_); |
| 137 gtk_util::SetLabelWidth(description_label, label_width); | 136 gtk_util::SetLabelWidth(description_label, label_width); |
| 138 | 137 |
| 139 std::string description(UTF16ToUTF8(shortcut_info_.description)); | 138 std::string description(UTF16ToUTF8(shortcut_info_.description)); |
| 140 std::string title(UTF16ToUTF8(shortcut_info_.title)); | 139 std::string title(UTF16ToUTF8(shortcut_info_.title)); |
| 141 gtk_label_set_text(GTK_LABEL(description_label), | 140 gtk_label_set_text(GTK_LABEL(description_label), |
| 142 (description.empty() ? title : description).c_str()); | 141 (description.empty() ? title : description).c_str()); |
| 143 | 142 |
| 144 // Label on top of the checkboxes. | 143 // Label on top of the checkboxes. |
| 145 GtkWidget* checkboxes_label = gtk_label_new( | 144 GtkWidget* checkboxes_label = gtk_label_new( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 GTK_RESPONSE_ACCEPT, | 236 GTK_RESPONSE_ACCEPT, |
| 238 NULL); | 237 NULL); |
| 239 gtk_widget_realize(error_dialog_); | 238 gtk_widget_realize(error_dialog_); |
| 240 gtk_util::SetWindowSizeFromResources( | 239 gtk_util::SetWindowSizeFromResources( |
| 241 GTK_WINDOW(error_dialog_), | 240 GTK_WINDOW(error_dialog_), |
| 242 IDS_CREATE_SHORTCUTS_ERROR_DIALOG_WIDTH_CHARS, | 241 IDS_CREATE_SHORTCUTS_ERROR_DIALOG_WIDTH_CHARS, |
| 243 IDS_CREATE_SHORTCUTS_ERROR_DIALOG_HEIGHT_LINES, | 242 IDS_CREATE_SHORTCUTS_ERROR_DIALOG_HEIGHT_LINES, |
| 244 false); // resizable | 243 false); // resizable |
| 245 GtkWidget* content_area = | 244 GtkWidget* content_area = |
| 246 gtk_dialog_get_content_area(GTK_DIALOG(error_dialog_)); | 245 gtk_dialog_get_content_area(GTK_DIALOG(error_dialog_)); |
| 247 gtk_box_set_spacing(GTK_BOX(content_area), ui::kContentAreaSpacing); | 246 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); |
| 248 | 247 |
| 249 GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kControlSpacing); | 248 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
| 250 gtk_container_add(GTK_CONTAINER(content_area), vbox); | 249 gtk_container_add(GTK_CONTAINER(content_area), vbox); |
| 251 | 250 |
| 252 // Label on top of the checkboxes. | 251 // Label on top of the checkboxes. |
| 253 GtkWidget* description = gtk_label_new( | 252 GtkWidget* description = gtk_label_new( |
| 254 l10n_util::GetStringFUTF8( | 253 l10n_util::GetStringFUTF8( |
| 255 IDS_CREATE_SHORTCUTS_ERROR_LABEL, | 254 IDS_CREATE_SHORTCUTS_ERROR_LABEL, |
| 256 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)).c_str()); | 255 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)).c_str()); |
| 257 gtk_label_set_line_wrap(GTK_LABEL(description), TRUE); | 256 gtk_label_set_line_wrap(GTK_LABEL(description), TRUE); |
| 258 gtk_misc_set_alignment(GTK_MISC(description), 0, 0); | 257 gtk_misc_set_alignment(GTK_MISC(description), 0, 0); |
| 259 gtk_box_pack_start(GTK_BOX(vbox), description, FALSE, FALSE, 0); | 258 gtk_box_pack_start(GTK_BOX(vbox), description, FALSE, FALSE, 0); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 void CreateChromeApplicationShortcutsDialogGtk::OnImageLoaded( | 332 void CreateChromeApplicationShortcutsDialogGtk::OnImageLoaded( |
| 334 SkBitmap* image, const ExtensionResource& resource, int index) { | 333 SkBitmap* image, const ExtensionResource& resource, int index) { |
| 335 if (!image || image->isNull()) | 334 if (!image || image->isNull()) |
| 336 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); | 335 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); |
| 337 | 336 |
| 338 shortcut_info_.favicon = *image; | 337 shortcut_info_.favicon = *image; |
| 339 | 338 |
| 340 CreateIconPixBuf(*image); | 339 CreateIconPixBuf(*image); |
| 341 CreateDialogBox(parent_); | 340 CreateDialogBox(parent_); |
| 342 } | 341 } |
| OLD | NEW |