Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: chrome/browser/ui/gtk/extensions/bundle_installed_bubble_gtk.cc

Issue 9456019: Add GTK interface for installing bundles of extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/gtk/extensions/bundle_installed_bubble_gtk.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/message_loop.h"
12 #include "base/i18n/rtl.h"
13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h"
16 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
17 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
18 #include "chrome/browser/ui/gtk/gtk_util.h"
19 #include "grit/generated_resources.h"
20 #include "grit/theme_resources.h"
21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/gtk_util.h"
24
25 using extensions::BundleInstaller;
26
27 namespace {
28
29 // The horizontal spacing for the main content area.
30 const int kHorizontalColumnSpacing = 10;
31
32 // The vertical spacing for the text area.
33 const int kTextColumnVerticalSpacing = 7;
34
35 // The width of the content area.
36 const int kContentWidth = 350;
37
38 // The padding for list items.
39 const int kListItemPadding = 2;
40
41 // Padding between content and edge of bubble.
42 const int kContentPadding = 12;
43
44 } // namespace
45
46 // static
47 void BundleInstaller::ShowInstalledBubble(
48 const BundleInstaller* bundle, Browser* browser) {
49 new BundleInstalledBubbleGtk(bundle, browser);
50 }
51
52 BundleInstalledBubbleGtk::BundleInstalledBubbleGtk(
53 const BundleInstaller* bundle, Browser* browser)
54 : browser_(browser),
55 bubble_(NULL) {
56 AddRef(); // Balanced in Close().
57 ShowInternal(bundle);
58 }
59
60 BundleInstalledBubbleGtk::~BundleInstalledBubbleGtk() {}
61
62 void BundleInstalledBubbleGtk::ShowInternal(const BundleInstaller* bundle) {
63 BrowserWindowGtk* browser_window =
64 BrowserWindowGtk::GetBrowserWindowForNativeWindow(
65 browser_->window()->GetNativeHandle());
66
67 GtkThemeService* theme_provider = GtkThemeService::GetFrom(
68 browser_->profile());
69
70 // Anchor the bubble to the wrench menu.
71 GtkWidget* reference_widget =
72 browser_window->GetToolbar()->GetAppMenuButton();
73
74 GtkWidget* bubble_content = gtk_hbox_new(FALSE, kHorizontalColumnSpacing);
75 gtk_container_set_border_width(
76 GTK_CONTAINER(bubble_content), kContentPadding);
77
78 GtkWidget* text_column = gtk_vbox_new(FALSE, kTextColumnVerticalSpacing);
79 gtk_box_pack_start(GTK_BOX(bubble_content), text_column, FALSE, FALSE, 0);
80
81 InsertExtensionList(
82 text_column, bundle, BundleInstaller::Item::STATE_INSTALLED);
83 InsertExtensionList(text_column, bundle, BundleInstaller::Item::STATE_FAILED);
84
85 // Close button
86 GtkWidget* close_column = gtk_vbox_new(FALSE, 0);
87 gtk_box_pack_start(GTK_BOX(bubble_content), close_column, FALSE, FALSE, 0);
88 close_button_.reset(CustomDrawButton::CloseButton(theme_provider));
89 g_signal_connect(close_button_->widget(), "clicked",
90 G_CALLBACK(OnButtonClick), this);
91 gtk_box_pack_start(GTK_BOX(close_column), close_button_->widget(),
92 FALSE, FALSE, 0);
93
94 BubbleGtk::ArrowLocationGtk arrow_location =
95 !base::i18n::IsRTL() ? BubbleGtk::ARROW_LOCATION_TOP_RIGHT :
96 BubbleGtk::ARROW_LOCATION_TOP_LEFT;
97 gfx::Rect bounds = gtk_util::WidgetBounds(reference_widget);
98
99 bubble_ = BubbleGtk::Show(reference_widget,
100 &bounds,
101 bubble_content,
102 arrow_location,
103 true, // match_system_theme
104 true, // grab_input
105 theme_provider,
106 this);
107 }
108
109 void BundleInstalledBubbleGtk::InsertExtensionList(
110 GtkWidget* parent,
111 const BundleInstaller* bundle,
112 BundleInstaller::Item::State state) {
113 string16 heading = bundle->GetHeadingTextFor(state);
114 BundleInstaller::ItemList items = bundle->GetItemsWithState(state);
115 if (heading.empty() || items.empty())
116 return;
117
118 GtkWidget* heading_label = gtk_util::CreateBoldLabel(UTF16ToUTF8(heading));
119 gtk_util::SetLabelWidth(heading_label, kContentWidth);
120 gtk_box_pack_start(GTK_BOX(parent), heading_label, FALSE, FALSE, 0);
121
122 for (size_t i = 0; i < items.size(); ++i) {
123 string16 extension_name = UTF8ToUTF16(items[i].localized_name);
124 base::i18n::AdjustStringForLocaleDirection(&extension_name);
125
126 GtkWidget* extension_label = gtk_label_new(UTF16ToUTF8(
127 l10n_util::GetStringFUTF16(
128 IDS_EXTENSION_PERMISSION_LINE, extension_name)).c_str());
129 gtk_util::SetLabelWidth(extension_label, kContentWidth);
130 gtk_box_pack_start(GTK_BOX(parent), extension_label, false, false,
131 kListItemPadding);
132 }
133 }
134
135 void BundleInstalledBubbleGtk::BubbleClosing(BubbleGtk* bubble,
136 bool closed_by_escape) {
137 // We need to allow the bubble to close and remove the widgets from
138 // the window before we call Release() because close_button_ depends
139 // on all references being cleared before it is destroyed.
140 MessageLoopForUI::current()->PostTask(
141 FROM_HERE,
142 base::Bind(&BundleInstalledBubbleGtk::Close, this));
143 }
144
145 void BundleInstalledBubbleGtk::Close() {
146 bubble_ = NULL;
147
148 Release(); // Balanced in BundleInstalledBubbleGtk().
149 }
150
151 void BundleInstalledBubbleGtk::OnButtonClick(GtkWidget* button,
152 BundleInstalledBubbleGtk* bubble) {
153 if (button == bubble->close_button_->widget())
154 bubble->bubble_->Close();
155 else
156 NOTREACHED();
157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698