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 <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/extensions/extension_install_dialog.h" | 9 #include "chrome/browser/extensions/extension_install_dialog.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 const int kLeftColumnMinWidth = 250; | 26 const int kLeftColumnMinWidth = 250; |
27 const int kImageSize = 69; | 27 const int kImageSize = 69; |
28 | 28 |
29 // Additional padding (beyond on ui::kControlSpacing) all sides of each | 29 // Additional padding (beyond on ui::kControlSpacing) all sides of each |
30 // permission in the permissions list. | 30 // permission in the permissions list. |
31 const int kPermissionsPadding = 2; | 31 const int kPermissionsPadding = 2; |
32 | 32 |
33 const double kRatingTextSize = 12.1; // 12.1px = 9pt @ 96dpi | 33 const double kRatingTextSize = 12.1; // 12.1px = 9pt @ 96dpi |
34 | 34 |
35 // Loads an image and adds it as an icon control to the given container. | 35 // Adds a Skia image as an icon control to the given container. |
36 GtkWidget* AddResourceIcon(int resource_id, GtkWidget* container) { | 36 void AddResourceIcon(const SkBitmap* icon, void* data) { |
37 const SkBitmap* icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 37 GtkWidget* container = static_cast<GtkWidget*>(data); |
38 resource_id); | |
39 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(icon); | 38 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(icon); |
40 GtkWidget* icon_widget = gtk_image_new_from_pixbuf(icon_pixbuf); | 39 GtkWidget* icon_widget = gtk_image_new_from_pixbuf(icon_pixbuf); |
41 g_object_unref(icon_pixbuf); | 40 g_object_unref(icon_pixbuf); |
42 gtk_box_pack_start(GTK_BOX(container), icon_widget, FALSE, FALSE, 0); | 41 gtk_box_pack_start(GTK_BOX(container), icon_widget, FALSE, FALSE, 0); |
43 return icon_widget; | |
44 } | 42 } |
45 | 43 |
46 // Displays the dialog when constructed, deletes itself when dialog is | 44 // Displays the dialog when constructed, deletes itself when dialog is |
47 // dismissed. Success/failure is passed back through the ExtensionInstallUI:: | 45 // dismissed. Success/failure is passed back through the ExtensionInstallUI:: |
48 // Delegate instance. | 46 // Delegate instance. |
49 class ExtensionInstallDialog { | 47 class ExtensionInstallDialog { |
50 public: | 48 public: |
51 ExtensionInstallDialog(GtkWindow* parent, | 49 ExtensionInstallDialog(GtkWindow* parent, |
52 ExtensionInstallUI::Delegate *delegate, | 50 ExtensionInstallUI::Delegate *delegate, |
53 const Extension* extension, | 51 const Extension* extension, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 UTF16ToUTF8(prompt.GetHeading(extension_->name())).c_str()); | 120 UTF16ToUTF8(prompt.GetHeading(extension_->name())).c_str()); |
123 gtk_label_set_line_wrap(GTK_LABEL(heading_label), true); | 121 gtk_label_set_line_wrap(GTK_LABEL(heading_label), true); |
124 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); | 122 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); |
125 gtk_box_pack_start(GTK_BOX(heading_vbox), heading_label, center_heading, | 123 gtk_box_pack_start(GTK_BOX(heading_vbox), heading_label, center_heading, |
126 center_heading, 0); | 124 center_heading, 0); |
127 | 125 |
128 if (is_inline_install) { | 126 if (is_inline_install) { |
129 // Average rating (as stars) and number of ratings | 127 // Average rating (as stars) and number of ratings |
130 GtkWidget* stars_hbox = gtk_hbox_new(FALSE, 0); | 128 GtkWidget* stars_hbox = gtk_hbox_new(FALSE, 0); |
131 gtk_box_pack_start(GTK_BOX(heading_vbox), stars_hbox, FALSE, FALSE, 0); | 129 gtk_box_pack_start(GTK_BOX(heading_vbox), stars_hbox, FALSE, FALSE, 0); |
132 prompt.AppendRatingStars( | 130 prompt.AppendRatingStars(AddResourceIcon, stars_hbox); |
133 reinterpret_cast<ExtensionInstallUI::Prompt::StarAppender>( | |
134 AddResourceIcon), | |
135 stars_hbox); | |
136 GtkWidget* rating_label = gtk_label_new(UTF16ToUTF8( | 131 GtkWidget* rating_label = gtk_label_new(UTF16ToUTF8( |
137 prompt.GetRatingCount()).c_str()); | 132 prompt.GetRatingCount()).c_str()); |
138 gtk_util::ForceFontSizePixels(rating_label, kRatingTextSize); | 133 gtk_util::ForceFontSizePixels(rating_label, kRatingTextSize); |
139 gtk_box_pack_start(GTK_BOX(stars_hbox), rating_label, | 134 gtk_box_pack_start(GTK_BOX(stars_hbox), rating_label, |
140 FALSE, FALSE, 3); | 135 FALSE, FALSE, 3); |
141 | 136 |
142 // User count | 137 // User count |
143 GtkWidget* users_label = gtk_label_new(UTF16ToUTF8( | 138 GtkWidget* users_label = gtk_label_new(UTF16ToUTF8( |
144 prompt.GetUserCount()).c_str()); | 139 prompt.GetUserCount()).c_str()); |
145 gtk_util::SetLabelWidth(users_label, kLeftColumnMinWidth); | 140 gtk_util::SetLabelWidth(users_label, kLeftColumnMinWidth); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 delegate->InstallUIAbort(false); | 250 delegate->InstallUIAbort(false); |
256 return; | 251 return; |
257 } | 252 } |
258 | 253 |
259 new ExtensionInstallDialog(browser_window->window(), | 254 new ExtensionInstallDialog(browser_window->window(), |
260 delegate, | 255 delegate, |
261 extension, | 256 extension, |
262 icon, | 257 icon, |
263 prompt); | 258 prompt); |
264 } | 259 } |
OLD | NEW |