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