OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/gtk/extension_installed_bubble_gtk.h" | 5 #include "chrome/browser/gtk/extension_installed_bubble_gtk.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 } | 50 } |
51 | 51 |
52 ExtensionInstalledBubbleGtk::ExtensionInstalledBubbleGtk( | 52 ExtensionInstalledBubbleGtk::ExtensionInstalledBubbleGtk( |
53 const Extension* extension, Browser *browser, SkBitmap icon) | 53 const Extension* extension, Browser *browser, SkBitmap icon) |
54 : extension_(extension), | 54 : extension_(extension), |
55 browser_(browser), | 55 browser_(browser), |
56 icon_(icon), | 56 icon_(icon), |
57 animation_wait_retries_(kAnimationWaitRetries) { | 57 animation_wait_retries_(kAnimationWaitRetries) { |
58 AddRef(); // Balanced in Close(). | 58 AddRef(); // Balanced in Close(). |
59 | 59 |
60 if (extension_->browser_action()) { | 60 if (!extension_->omnibox_keyword().empty()) { |
61 type_ = OMNIBOX_KEYWORD; | |
62 } else if (extension_->browser_action()) { | |
61 type_ = BROWSER_ACTION; | 63 type_ = BROWSER_ACTION; |
62 } else if (extension->page_action() && | 64 } else if (extension->page_action() && |
63 !extension->page_action()->default_icon_path().empty()) { | 65 !extension->page_action()->default_icon_path().empty()) { |
64 type_ = PAGE_ACTION; | 66 type_ = PAGE_ACTION; |
65 } else { | 67 } else { |
66 type_ = GENERIC; | 68 type_ = GENERIC; |
67 } | 69 } |
68 | 70 |
69 // |extension| has been initialized but not loaded at this point. We need | 71 // |extension| has been initialized but not loaded at this point. We need |
70 // to wait on showing the Bubble until not only the EXTENSION_LOADED gets | 72 // to wait on showing the Bubble until not only the EXTENSION_LOADED gets |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 browser_window->GetToolbar()->GetLocationBarView(); | 136 browser_window->GetToolbar()->GetLocationBarView(); |
135 location_bar_view->SetPreviewEnabledPageAction(extension_->page_action(), | 137 location_bar_view->SetPreviewEnabledPageAction(extension_->page_action(), |
136 true); // preview_enabled | 138 true); // preview_enabled |
137 reference_widget = location_bar_view->GetPageActionWidget( | 139 reference_widget = location_bar_view->GetPageActionWidget( |
138 extension_->page_action()); | 140 extension_->page_action()); |
139 // glib delays recalculating layout, but we need reference_widget to know | 141 // glib delays recalculating layout, but we need reference_widget to know |
140 // it's coordinates, so we force a check_resize here. | 142 // it's coordinates, so we force a check_resize here. |
141 gtk_container_check_resize(GTK_CONTAINER( | 143 gtk_container_check_resize(GTK_CONTAINER( |
142 browser_window->GetToolbar()->widget())); | 144 browser_window->GetToolbar()->widget())); |
143 DCHECK(reference_widget); | 145 DCHECK(reference_widget); |
146 } else if (type_ == OMNIBOX_KEYWORD) { | |
147 LocationBarViewGtk* location_bar_view = | |
148 browser_window->GetToolbar()->GetLocationBarView(); | |
149 reference_widget = location_bar_view->location_entry_widget(); | |
150 DCHECK(reference_widget); | |
144 } | 151 } |
152 | |
145 // Default case. | 153 // Default case. |
146 if (reference_widget == NULL) | 154 if (reference_widget == NULL) |
147 reference_widget = browser_window->GetToolbar()->GetAppMenuButton(); | 155 reference_widget = browser_window->GetToolbar()->GetAppMenuButton(); |
148 | 156 |
149 GtkThemeProvider* theme_provider = GtkThemeProvider::GetFrom( | 157 GtkThemeProvider* theme_provider = GtkThemeProvider::GetFrom( |
150 browser_->profile()); | 158 browser_->profile()); |
151 | 159 |
152 // Setup the InfoBubble content. | 160 // Setup the InfoBubble content. |
153 GtkWidget* bubble_content = gtk_hbox_new(FALSE, kHorizontalColumnSpacing); | 161 GtkWidget* bubble_content = gtk_hbox_new(FALSE, kHorizontalColumnSpacing); |
154 gtk_container_set_border_width(GTK_CONTAINER(bubble_content), kContentBorder); | 162 gtk_container_set_border_width(GTK_CONTAINER(bubble_content), kContentBorder); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 char* markup = g_markup_printf_escaped("<span size=\"larger\">%s</span>", | 202 char* markup = g_markup_printf_escaped("<span size=\"larger\">%s</span>", |
195 heading_text.c_str()); | 203 heading_text.c_str()); |
196 gtk_label_set_markup(GTK_LABEL(heading_label), markup); | 204 gtk_label_set_markup(GTK_LABEL(heading_label), markup); |
197 g_free(markup); | 205 g_free(markup); |
198 | 206 |
199 gtk_label_set_line_wrap(GTK_LABEL(heading_label), TRUE); | 207 gtk_label_set_line_wrap(GTK_LABEL(heading_label), TRUE); |
200 gtk_widget_set_size_request(heading_label, kTextColumnWidth, -1); | 208 gtk_widget_set_size_request(heading_label, kTextColumnWidth, -1); |
201 gtk_box_pack_start(GTK_BOX(text_column), heading_label, FALSE, FALSE, 0); | 209 gtk_box_pack_start(GTK_BOX(text_column), heading_label, FALSE, FALSE, 0); |
202 | 210 |
203 // Page action label | 211 // Page action label |
204 if (type_ == ExtensionInstalledBubbleGtk::PAGE_ACTION) { | 212 if (type_ == PAGE_ACTION) { |
205 GtkWidget* info_label = gtk_label_new(l10n_util::GetStringUTF8( | 213 GtkWidget* info_label = gtk_label_new(l10n_util::GetStringUTF8( |
206 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO).c_str()); | 214 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO).c_str()); |
207 gtk_label_set_line_wrap(GTK_LABEL(info_label), TRUE); | 215 gtk_label_set_line_wrap(GTK_LABEL(info_label), TRUE); |
208 gtk_widget_set_size_request(info_label, kTextColumnWidth, -1); | 216 gtk_widget_set_size_request(info_label, kTextColumnWidth, -1); |
209 gtk_box_pack_start(GTK_BOX(text_column), info_label, FALSE, FALSE, 0); | 217 gtk_box_pack_start(GTK_BOX(text_column), info_label, FALSE, FALSE, 0); |
218 } | |
219 | |
220 // Omnibox keyword label | |
221 if (type_ == OMNIBOX_KEYWORD) { | |
222 GtkWidget* info_label = gtk_label_new(l10n_util::GetStringFUTF8( | |
223 IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO, | |
224 UTF8ToUTF16(extension_->omnibox_keyword())).c_str()); | |
225 gtk_label_set_line_wrap(GTK_LABEL(info_label), TRUE); | |
226 gtk_widget_set_size_request(info_label, kTextColumnWidth, -1); | |
227 gtk_box_pack_start(GTK_BOX(text_column), info_label, FALSE, FALSE, 0); | |
210 } | 228 } |
211 | 229 |
212 // Manage label | 230 // Manage label |
213 GtkWidget* manage_label = gtk_label_new( | 231 GtkWidget* manage_label = gtk_label_new( |
214 l10n_util::GetStringUTF8(IDS_EXTENSION_INSTALLED_MANAGE_INFO).c_str()); | 232 l10n_util::GetStringUTF8(IDS_EXTENSION_INSTALLED_MANAGE_INFO).c_str()); |
215 gtk_label_set_line_wrap(GTK_LABEL(manage_label), TRUE); | 233 gtk_label_set_line_wrap(GTK_LABEL(manage_label), TRUE); |
216 gtk_widget_set_size_request(manage_label, kTextColumnWidth, -1); | 234 gtk_widget_set_size_request(manage_label, kTextColumnWidth, -1); |
217 gtk_box_pack_start(GTK_BOX(text_column), manage_label, FALSE, FALSE, 0); | 235 gtk_box_pack_start(GTK_BOX(text_column), manage_label, FALSE, FALSE, 0); |
218 | 236 |
219 // Create and pack the close button. | 237 // Create and pack the close button. |
220 GtkWidget* close_column = gtk_vbox_new(FALSE, 0); | 238 GtkWidget* close_column = gtk_vbox_new(FALSE, 0); |
221 gtk_box_pack_start(GTK_BOX(bubble_content), close_column, FALSE, FALSE, 0); | 239 gtk_box_pack_start(GTK_BOX(bubble_content), close_column, FALSE, FALSE, 0); |
222 close_button_.reset(CustomDrawButton::CloseButton(theme_provider)); | 240 close_button_.reset(CustomDrawButton::CloseButton(theme_provider)); |
223 g_signal_connect(close_button_->widget(), "clicked", | 241 g_signal_connect(close_button_->widget(), "clicked", |
224 G_CALLBACK(OnButtonClick), this); | 242 G_CALLBACK(OnButtonClick), this); |
225 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 243 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
226 close_button_->SetBackground( | 244 close_button_->SetBackground( |
227 theme_provider->GetColor(BrowserThemeProvider::COLOR_TAB_TEXT), | 245 theme_provider->GetColor(BrowserThemeProvider::COLOR_TAB_TEXT), |
228 rb.GetBitmapNamed(IDR_CLOSE_BAR), | 246 rb.GetBitmapNamed(IDR_CLOSE_BAR), |
229 rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK)); | 247 rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK)); |
230 gtk_box_pack_start(GTK_BOX(close_column), close_button_->widget(), | 248 gtk_box_pack_start(GTK_BOX(close_column), close_button_->widget(), |
231 FALSE, FALSE, 0); | 249 FALSE, FALSE, 0); |
232 | 250 |
233 InfoBubbleGtk::ArrowLocationGtk arrow_location = | 251 InfoBubbleGtk::ArrowLocationGtk arrow_location = |
234 !base::i18n::IsRTL() ? | 252 !base::i18n::IsRTL() ? |
235 InfoBubbleGtk::ARROW_LOCATION_TOP_RIGHT : | 253 InfoBubbleGtk::ARROW_LOCATION_TOP_RIGHT : |
236 InfoBubbleGtk::ARROW_LOCATION_TOP_LEFT; | 254 InfoBubbleGtk::ARROW_LOCATION_TOP_LEFT; |
255 | |
256 gfx::Rect bounds = gtk_util::WidgetBounds(reference_widget); | |
257 if (type_ == OMNIBOX_KEYWORD) { | |
258 // Reverse the arrow for omnibox keywords, since the bubble will be on the | |
259 // other side of the window. We also clear the width to avoid centering | |
260 // the popup on the URL bar. | |
261 arrow_location = | |
262 !base::i18n::IsRTL() ? | |
263 InfoBubbleGtk::ARROW_LOCATION_TOP_LEFT : | |
264 InfoBubbleGtk::ARROW_LOCATION_TOP_RIGHT; | |
265 bounds.set_width(0); | |
Aaron Boodman
2010/11/11 02:55:30
Do you have a screenshot of what this ends up look
Matt Perry
2010/11/12 07:20:25
I attached screenshots of the Windows UI to the bu
| |
266 } | |
267 | |
237 info_bubble_ = InfoBubbleGtk::Show(reference_widget, | 268 info_bubble_ = InfoBubbleGtk::Show(reference_widget, |
238 NULL, | 269 &bounds, |
239 bubble_content, | 270 bubble_content, |
240 arrow_location, | 271 arrow_location, |
241 true, // match_system_theme | 272 true, // match_system_theme |
242 true, // grab_input | 273 true, // grab_input |
243 theme_provider, | 274 theme_provider, |
244 this); | 275 this); |
245 } | 276 } |
246 | 277 |
247 // static | 278 // static |
248 void ExtensionInstalledBubbleGtk::OnButtonClick(GtkWidget* button, | 279 void ExtensionInstalledBubbleGtk::OnButtonClick(GtkWidget* button, |
(...skipping 22 matching lines...) Expand all Loading... | |
271 // the window before we call Release() because close_button_ depends | 302 // the window before we call Release() because close_button_ depends |
272 // on all references being cleared before it is destroyed. | 303 // on all references being cleared before it is destroyed. |
273 MessageLoopForUI::current()->PostTask(FROM_HERE, NewRunnableMethod(this, | 304 MessageLoopForUI::current()->PostTask(FROM_HERE, NewRunnableMethod(this, |
274 &ExtensionInstalledBubbleGtk::Close)); | 305 &ExtensionInstalledBubbleGtk::Close)); |
275 } | 306 } |
276 | 307 |
277 void ExtensionInstalledBubbleGtk::Close() { | 308 void ExtensionInstalledBubbleGtk::Close() { |
278 Release(); // Balanced in ctor. | 309 Release(); // Balanced in ctor. |
279 info_bubble_ = NULL; | 310 info_bubble_ = NULL; |
280 } | 311 } |
OLD | NEW |