| 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/bookmarks/bookmark_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_editor.h" | 16 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_model.h" | 17 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 18 #include "chrome/browser/bookmarks/bookmark_utils.h" | 18 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 19 #include "chrome/browser/bookmarks/recently_used_folders_combo_model.h" | 19 #include "chrome/browser/bookmarks/recently_used_folders_combo_model.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 23 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 24 #include "chrome/browser/ui/gtk/gtk_util.h" | 24 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "content/browser/user_metrics.h" | |
| 27 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/user_metrics.h" |
| 28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 29 #include "ui/base/gtk/gtk_hig_constants.h" | 29 #include "ui/base/gtk/gtk_hig_constants.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 31 | 31 |
| 32 using content::UserMetricsAction; |
| 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 // We basically have a singleton, since a bubble is sort of app-modal. This | 36 // We basically have a singleton, since a bubble is sort of app-modal. This |
| 35 // keeps track of the currently open bubble, or NULL if none is open. | 37 // keeps track of the currently open bubble, or NULL if none is open. |
| 36 BookmarkBubbleGtk* g_bubble = NULL; | 38 BookmarkBubbleGtk* g_bubble = NULL; |
| 37 | 39 |
| 38 // Padding between content and edge of bubble. | 40 // Padding between content and edge of bubble. |
| 39 const int kContentBorder = 7; | 41 const int kContentBorder = 7; |
| 40 | 42 |
| 41 } // namespace | 43 } // namespace |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 delete this; | 219 delete this; |
| 218 } | 220 } |
| 219 | 221 |
| 220 void BookmarkBubbleGtk::OnNameActivate(GtkWidget* widget) { | 222 void BookmarkBubbleGtk::OnNameActivate(GtkWidget* widget) { |
| 221 bubble_->Close(); | 223 bubble_->Close(); |
| 222 } | 224 } |
| 223 | 225 |
| 224 void BookmarkBubbleGtk::OnFolderChanged(GtkWidget* widget) { | 226 void BookmarkBubbleGtk::OnFolderChanged(GtkWidget* widget) { |
| 225 int index = gtk_combo_box_get_active(GTK_COMBO_BOX(folder_combo_)); | 227 int index = gtk_combo_box_get_active(GTK_COMBO_BOX(folder_combo_)); |
| 226 if (index == folder_combo_model_->GetItemCount() - 1) { | 228 if (index == folder_combo_model_->GetItemCount() - 1) { |
| 227 UserMetrics::RecordAction( | 229 content::RecordAction( |
| 228 UserMetricsAction("BookmarkBubble_EditFromCombobox")); | 230 UserMetricsAction("BookmarkBubble_EditFromCombobox")); |
| 229 // GTK doesn't handle having the combo box destroyed from the changed | 231 // GTK doesn't handle having the combo box destroyed from the changed |
| 230 // signal. Since showing the editor also closes the bubble, delay this | 232 // signal. Since showing the editor also closes the bubble, delay this |
| 231 // so that GTK can unwind. Specifically gtk_menu_shell_button_release | 233 // so that GTK can unwind. Specifically gtk_menu_shell_button_release |
| 232 // will run, and we need to keep the combo box alive until then. | 234 // will run, and we need to keep the combo box alive until then. |
| 233 MessageLoop::current()->PostTask( | 235 MessageLoop::current()->PostTask( |
| 234 FROM_HERE, | 236 FROM_HERE, |
| 235 base::Bind(&BookmarkBubbleGtk::ShowEditor, factory_.GetWeakPtr())); | 237 base::Bind(&BookmarkBubbleGtk::ShowEditor, factory_.GetWeakPtr())); |
| 236 } | 238 } |
| 237 } | 239 } |
| 238 | 240 |
| 239 void BookmarkBubbleGtk::OnFolderPopupShown(GtkWidget* widget, | 241 void BookmarkBubbleGtk::OnFolderPopupShown(GtkWidget* widget, |
| 240 GParamSpec* property) { | 242 GParamSpec* property) { |
| 241 // GtkComboBox grabs the keyboard and pointer when it displays its popup, | 243 // GtkComboBox grabs the keyboard and pointer when it displays its popup, |
| 242 // which steals the grabs that BubbleGtk had installed. When the popup is | 244 // which steals the grabs that BubbleGtk had installed. When the popup is |
| 243 // hidden, we notify BubbleGtk so it can try to reacquire the grabs | 245 // hidden, we notify BubbleGtk so it can try to reacquire the grabs |
| 244 // (otherwise, GTK won't activate our widgets when the user clicks in them). | 246 // (otherwise, GTK won't activate our widgets when the user clicks in them). |
| 245 gboolean popup_shown = FALSE; | 247 gboolean popup_shown = FALSE; |
| 246 g_object_get(G_OBJECT(folder_combo_), "popup-shown", &popup_shown, NULL); | 248 g_object_get(G_OBJECT(folder_combo_), "popup-shown", &popup_shown, NULL); |
| 247 if (!popup_shown) | 249 if (!popup_shown) |
| 248 bubble_->HandlePointerAndKeyboardUngrabbedByContent(); | 250 bubble_->HandlePointerAndKeyboardUngrabbedByContent(); |
| 249 } | 251 } |
| 250 | 252 |
| 251 void BookmarkBubbleGtk::OnEditClicked(GtkWidget* widget) { | 253 void BookmarkBubbleGtk::OnEditClicked(GtkWidget* widget) { |
| 252 UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 254 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
| 253 ShowEditor(); | 255 ShowEditor(); |
| 254 } | 256 } |
| 255 | 257 |
| 256 void BookmarkBubbleGtk::OnCloseClicked(GtkWidget* widget) { | 258 void BookmarkBubbleGtk::OnCloseClicked(GtkWidget* widget) { |
| 257 bubble_->Close(); | 259 bubble_->Close(); |
| 258 } | 260 } |
| 259 | 261 |
| 260 void BookmarkBubbleGtk::OnRemoveClicked(GtkWidget* widget) { | 262 void BookmarkBubbleGtk::OnRemoveClicked(GtkWidget* widget) { |
| 261 UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | 263 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); |
| 262 | 264 |
| 263 apply_edits_ = false; | 265 apply_edits_ = false; |
| 264 remove_bookmark_ = true; | 266 remove_bookmark_ = true; |
| 265 bubble_->Close(); | 267 bubble_->Close(); |
| 266 } | 268 } |
| 267 | 269 |
| 268 void BookmarkBubbleGtk::ApplyEdits() { | 270 void BookmarkBubbleGtk::ApplyEdits() { |
| 269 // Set this to make sure we don't attempt to apply edits again. | 271 // Set this to make sure we don't attempt to apply edits again. |
| 270 apply_edits_ = false; | 272 apply_edits_ = false; |
| 271 | 273 |
| 272 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url_); | 274 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url_); |
| 273 if (node) { | 275 if (node) { |
| 274 const string16 new_title( | 276 const string16 new_title( |
| 275 UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(name_entry_)))); | 277 UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(name_entry_)))); |
| 276 | 278 |
| 277 if (new_title != node->GetTitle()) { | 279 if (new_title != node->GetTitle()) { |
| 278 model_->SetTitle(node, new_title); | 280 model_->SetTitle(node, new_title); |
| 279 UserMetrics::RecordAction( | 281 content::RecordAction( |
| 280 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 282 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
| 281 } | 283 } |
| 282 | 284 |
| 283 int index = gtk_combo_box_get_active(GTK_COMBO_BOX(folder_combo_)); | 285 int index = gtk_combo_box_get_active(GTK_COMBO_BOX(folder_combo_)); |
| 284 | 286 |
| 285 // Last index means 'Choose another folder...' | 287 // Last index means 'Choose another folder...' |
| 286 if (index < folder_combo_model_->GetItemCount() - 1) { | 288 if (index < folder_combo_model_->GetItemCount() - 1) { |
| 287 const BookmarkNode* new_parent = folder_combo_model_->GetNodeAt(index); | 289 const BookmarkNode* new_parent = folder_combo_model_->GetNodeAt(index); |
| 288 if (new_parent != node->parent()) { | 290 if (new_parent != node->parent()) { |
| 289 UserMetrics::RecordAction( | 291 content::RecordAction( |
| 290 UserMetricsAction("BookmarkBubble_ChangeParent")); | 292 UserMetricsAction("BookmarkBubble_ChangeParent")); |
| 291 model_->Move(node, new_parent, new_parent->child_count()); | 293 model_->Move(node, new_parent, new_parent->child_count()); |
| 292 } | 294 } |
| 293 } | 295 } |
| 294 } | 296 } |
| 295 } | 297 } |
| 296 | 298 |
| 297 std::string BookmarkBubbleGtk::GetTitle() { | 299 std::string BookmarkBubbleGtk::GetTitle() { |
| 298 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url_); | 300 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url_); |
| 299 if (!node) { | 301 if (!node) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 // We always have nodes + 1 entries in the combo. The last entry will be | 335 // We always have nodes + 1 entries in the combo. The last entry will be |
| 334 // the 'Select another folder...' entry that opens the bookmark editor. | 336 // the 'Select another folder...' entry that opens the bookmark editor. |
| 335 for (int i = 0; i < folder_combo_model_->GetItemCount(); ++i) { | 337 for (int i = 0; i < folder_combo_model_->GetItemCount(); ++i) { |
| 336 gtk_combo_box_append_text(GTK_COMBO_BOX(folder_combo_), | 338 gtk_combo_box_append_text(GTK_COMBO_BOX(folder_combo_), |
| 337 UTF16ToUTF8(folder_combo_model_->GetItemAt(i)).c_str()); | 339 UTF16ToUTF8(folder_combo_model_->GetItemAt(i)).c_str()); |
| 338 } | 340 } |
| 339 | 341 |
| 340 gtk_combo_box_set_active(GTK_COMBO_BOX(folder_combo_), | 342 gtk_combo_box_set_active(GTK_COMBO_BOX(folder_combo_), |
| 341 folder_combo_model_->node_parent_index()); | 343 folder_combo_model_->node_parent_index()); |
| 342 } | 344 } |
| OLD | NEW |