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

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: 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 const int kHorizontalColumnSpacing = 10;
30 const int kTextColumnVerticalSpacing = 7;
31
32 // The width of the content area.
33 const int kContentWidth = 350;
34
35 // The padding for list items.
36 const int kListItemPadding = 2;
37
38 // Padding between content and edge of bubble.
39 const int kContentPadding = 12;
40
41 } // namespace
42
43 // static
44 void BundleInstaller::ShowInstalledBubble(
45 const BundleInstaller* bundle, Browser* browser) {
46 new BundleInstalledBubbleGtk(bundle, browser);
47 }
48
49 BundleInstalledBubbleGtk::BundleInstalledBubbleGtk(
50 const BundleInstaller* bundle, Browser* browser)
51 : browser_(browser),
52 bubble_(NULL) {
53 AddRef(); // Balanced in Close().
54 ShowInternal(bundle);
55 }
56
57 BundleInstalledBubbleGtk::~BundleInstalledBubbleGtk() {}
58
59 void BundleInstalledBubbleGtk::ShowInternal(const BundleInstaller* bundle) {
60 BrowserWindowGtk* browser_window =
61 BrowserWindowGtk::GetBrowserWindowForNativeWindow(
62 browser_->window()->GetNativeHandle());
63
64 GtkThemeService* theme_provider = GtkThemeService::GetFrom(
65 browser_->profile());
66
67 // Anchor the bubble to the wrench menu.
68 GtkWidget* reference_widget =
69 browser_window->GetToolbar()->GetAppMenuButton();
70
71 GtkWidget* bubble_content = gtk_hbox_new(FALSE, kHorizontalColumnSpacing);
72 gtk_container_set_border_width(
73 GTK_CONTAINER(bubble_content), kContentPadding);
74
75 GtkWidget* text_column = gtk_vbox_new(FALSE, kTextColumnVerticalSpacing);
76 gtk_box_pack_start(GTK_BOX(bubble_content), text_column, FALSE, FALSE, 0);
77
78
79 InsertExtensionList(
80 text_column, bundle, BundleInstaller::Item::STATE_INSTALLED);
81 InsertExtensionList(text_column, bundle, BundleInstaller::Item::STATE_FAILED);
82
83 // Close button
84 GtkWidget* close_column = gtk_vbox_new(FALSE, 0);
85 gtk_box_pack_start(GTK_BOX(bubble_content), close_column, FALSE, FALSE, 0);
86 close_button_.reset(CustomDrawButton::CloseButton(theme_provider));
87 g_signal_connect(close_button_->widget(), "clicked",
88 G_CALLBACK(OnButtonClick), this);
89 gtk_box_pack_start(GTK_BOX(close_column), close_button_->widget(),
90 FALSE, FALSE, 0);
91
92 BubbleGtk::ArrowLocationGtk arrow_location =
93 !base::i18n::IsRTL() ?
94 BubbleGtk::ARROW_LOCATION_TOP_RIGHT :
95 BubbleGtk::ARROW_LOCATION_TOP_LEFT;
96 gfx::Rect bounds = gtk_util::WidgetBounds(reference_widget);
97
98 bubble_ = BubbleGtk::Show(reference_widget,
99 &bounds,
100 bubble_content,
101 arrow_location,
102 true, // match_system_theme
103 true, // grab_input
104 theme_provider,
105 this);
106 }
107
108 void BundleInstalledBubbleGtk::InsertExtensionList(
109 GtkWidget* parent,
110 const BundleInstaller* bundle,
111 BundleInstaller::Item::State state) {
112 string16 heading = bundle->GetHeadingTextFor(state);
113 BundleInstaller::ItemList items = bundle->GetItemsWithState(state);
114 if (heading.empty() || items.empty())
115 return;
116
117 GtkWidget* heading_label = gtk_util::CreateBoldLabel(UTF16ToUTF8(heading));
118 gtk_util::SetLabelWidth(heading_label, kContentWidth);
119 gtk_box_pack_start(GTK_BOX(parent), heading_label, FALSE, FALSE, 0);
120
121 for (size_t i = 0; i < items.size(); ++i) {
122 string16 extension_name = UTF8ToUTF16(items[i].localized_name);
123 base::i18n::AdjustStringForLocaleDirection(&extension_name);
124
125 GtkWidget* extension_label = gtk_label_new(UTF16ToUTF8(
126 l10n_util::GetStringFUTF16(
127 IDS_EXTENSION_PERMISSION_LINE, extension_name)).c_str());
128 gtk_util::SetLabelWidth(extension_label, kContentWidth);
129 gtk_box_pack_start(GTK_BOX(parent), extension_label, false, false,
130 kListItemPadding);
131 }
132 }
133
134 void BundleInstalledBubbleGtk::BubbleClosing(BubbleGtk* bubble,
135 bool closed_by_escape) {
136 // We need to allow the bubble to close and remove the widgets from
137 // the window before we call Release() because close_button_ depends
138 // on all references being cleared before it is destroyed.
139 MessageLoopForUI::current()->PostTask(
140 FROM_HERE,
141 base::Bind(&BundleInstalledBubbleGtk::Close, this));
142 }
143
144 void BundleInstalledBubbleGtk::Close() {
145 bubble_ = NULL;
146
147 Release(); // Balanced in BundleInstalledBubbleGtk().
148 }
149
150 void BundleInstalledBubbleGtk::OnButtonClick(GtkWidget* button,
151 BundleInstalledBubbleGtk* bubble) {
152 if (button == bubble->close_button_->widget())
153 bubble->bubble_->Close();
154 else
155 NOTREACHED();
156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698