| 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/views/bookmarks/bookmark_bubble_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/string16.h" | 7 #include "base/string16.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_editor.h" | 11 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_utils.h" | 13 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 14 #include "chrome/browser/metrics/user_metrics.h" | 14 #include "chrome/browser/metrics/user_metrics.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_list.h" |
| 16 #include "chrome/browser/ui/views/info_bubble.h" | 18 #include "chrome/browser/ui/views/info_bubble.h" |
| 17 #include "content/common/notification_service.h" | 19 #include "content/common/notification_service.h" |
| 18 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
| 20 #include "ui/base/keycodes/keyboard_codes.h" | 22 #include "ui/base/keycodes/keyboard_codes.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
| 24 #include "ui/gfx/color_utils.h" | 26 #include "ui/gfx/color_utils.h" |
| 25 #include "views/controls/button/native_button.h" | 27 #include "views/controls/button/native_button.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 187 |
| 186 initialized = true; | 188 initialized = true; |
| 187 } | 189 } |
| 188 | 190 |
| 189 remove_link_ = new Link(UTF16ToWide(l10n_util::GetStringUTF16( | 191 remove_link_ = new Link(UTF16ToWide(l10n_util::GetStringUTF16( |
| 190 IDS_BOOMARK_BUBBLE_REMOVE_BOOKMARK))); | 192 IDS_BOOMARK_BUBBLE_REMOVE_BOOKMARK))); |
| 191 remove_link_->SetController(this); | 193 remove_link_->SetController(this); |
| 192 | 194 |
| 193 edit_button_ = new NativeButton( | 195 edit_button_ = new NativeButton( |
| 194 this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_BUBBLE_OPTIONS))); | 196 this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_BUBBLE_OPTIONS))); |
| 195 #if defined(TOUCH_UI) | |
| 196 // TODO(saintlou): We need to disable the Edit button for touch since we are | |
| 197 // missing some of the controls for the dialog that would pop up next. | |
| 198 edit_button_->SetEnabled(false); | |
| 199 #endif | |
| 200 | 197 |
| 201 close_button_ = | 198 close_button_ = |
| 202 new NativeButton(this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_DONE))); | 199 new NativeButton(this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_DONE))); |
| 203 close_button_->SetIsDefault(true); | 200 close_button_->SetIsDefault(true); |
| 204 | 201 |
| 205 Label* combobox_label = new Label( | 202 Label* combobox_label = new Label( |
| 206 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_BUBBLE_FOLDER_TEXT))); | 203 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_BUBBLE_FOLDER_TEXT))); |
| 207 | 204 |
| 208 parent_combobox_ = new Combobox(&parent_model_); | 205 parent_combobox_ = new Combobox(&parent_model_); |
| 209 parent_combobox_->SetSelectedItem(parent_model_.node_parent_index()); | 206 parent_combobox_->SetSelectedItem(parent_model_.node_parent_index()); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 ShowEditor(); | 362 ShowEditor(); |
| 366 } else { | 363 } else { |
| 367 DCHECK(sender == close_button_); | 364 DCHECK(sender == close_button_); |
| 368 info_bubble_->set_fade_away_on_close(true); | 365 info_bubble_->set_fade_away_on_close(true); |
| 369 Close(); | 366 Close(); |
| 370 } | 367 } |
| 371 // WARNING: we've most likely been deleted when CloseWindow returns. | 368 // WARNING: we've most likely been deleted when CloseWindow returns. |
| 372 } | 369 } |
| 373 | 370 |
| 374 void BookmarkBubbleView::ShowEditor() { | 371 void BookmarkBubbleView::ShowEditor() { |
| 372 #if defined(TOUCH_UI) |
| 373 // Close the InfoBubble |
| 374 Close(); |
| 375 |
| 376 // Open the Bookmark Manager |
| 377 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| 378 DCHECK(browser); |
| 379 if (browser) |
| 380 browser->OpenBookmarkManager(); |
| 381 else |
| 382 NOTREACHED(); |
| 383 |
| 384 #else |
| 375 const BookmarkNode* node = | 385 const BookmarkNode* node = |
| 376 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); | 386 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); |
| 377 | 387 |
| 378 // Commit any edits now. | |
| 379 ApplyEdits(); | |
| 380 | |
| 381 #if defined(OS_WIN) | 388 #if defined(OS_WIN) |
| 382 // Parent the editor to our root ancestor (not the root we're in, as that | 389 // Parent the editor to our root ancestor (not the root we're in, as that |
| 383 // is the info bubble and will close shortly). | 390 // is the info bubble and will close shortly). |
| 384 HWND parent = GetAncestor(GetWidget()->GetNativeView(), GA_ROOTOWNER); | 391 HWND parent = GetAncestor(GetWidget()->GetNativeView(), GA_ROOTOWNER); |
| 385 | 392 |
| 386 // We're about to show the bookmark editor. When the bookmark editor closes | 393 // We're about to show the bookmark editor. When the bookmark editor closes |
| 387 // we want the browser to become active. WidgetWin::Hide() does a hide in | 394 // we want the browser to become active. WidgetWin::Hide() does a hide in |
| 388 // a such way that activation isn't changed, which means when we close | 395 // a such way that activation isn't changed, which means when we close |
| 389 // Windows gets confused as to who it should give active status to. We | 396 // Windows gets confused as to who it should give active status to. We |
| 390 // explicitly hide the bookmark bubble window in such a way that activation | 397 // explicitly hide the bookmark bubble window in such a way that activation |
| 391 // status changes. That way, when the editor closes, activation is properly | 398 // status changes. That way, when the editor closes, activation is properly |
| 392 // restored to the browser. | 399 // restored to the browser. |
| 393 ShowWindow(GetWidget()->GetNativeView(), SW_HIDE); | 400 ShowWindow(GetWidget()->GetNativeView(), SW_HIDE); |
| 394 #else | 401 #else |
| 395 gfx::NativeWindow parent = GTK_WINDOW( | 402 gfx::NativeWindow parent = GTK_WINDOW( |
| 396 static_cast<views::WidgetGtk*>(GetWidget())->GetTransientParent()); | 403 static_cast<views::WidgetGtk*>(GetWidget())->GetTransientParent()); |
| 397 #endif | 404 #endif |
| 398 | 405 |
| 399 // Even though we just hid the window, we need to invoke Close to schedule | 406 // Even though we just hid the window, we need to invoke Close to schedule |
| 400 // the delete and all that. | 407 // the delete and all that. |
| 401 Close(); | 408 Close(); |
| 402 | 409 |
| 403 if (node) { | 410 if (node) { |
| 404 BookmarkEditor::Show(parent, profile_, NULL, | 411 BookmarkEditor::Show(parent, profile_, NULL, |
| 405 BookmarkEditor::EditDetails(node), | 412 BookmarkEditor::EditDetails(node), |
| 406 BookmarkEditor::SHOW_TREE); | 413 BookmarkEditor::SHOW_TREE); |
| 407 } | 414 } |
| 415 #endif |
| 408 } | 416 } |
| 409 | 417 |
| 410 void BookmarkBubbleView::ApplyEdits() { | 418 void BookmarkBubbleView::ApplyEdits() { |
| 411 // Set this to make sure we don't attempt to apply edits again. | 419 // Set this to make sure we don't attempt to apply edits again. |
| 412 apply_edits_ = false; | 420 apply_edits_ = false; |
| 413 | 421 |
| 414 BookmarkModel* model = profile_->GetBookmarkModel(); | 422 BookmarkModel* model = profile_->GetBookmarkModel(); |
| 415 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); | 423 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); |
| 416 if (node) { | 424 if (node) { |
| 417 const string16 new_title = title_tf_->text(); | 425 const string16 new_title = title_tf_->text(); |
| 418 if (new_title != node->GetTitle()) { | 426 if (new_title != node->GetTitle()) { |
| 419 model->SetTitle(node, new_title); | 427 model->SetTitle(node, new_title); |
| 420 UserMetrics::RecordAction( | 428 UserMetrics::RecordAction( |
| 421 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"), | 429 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"), |
| 422 profile_); | 430 profile_); |
| 423 } | 431 } |
| 424 // Last index means 'Choose another folder...' | 432 // Last index means 'Choose another folder...' |
| 425 if (parent_combobox_->selected_item() < | 433 if (parent_combobox_->selected_item() < |
| 426 parent_model_.GetItemCount() - 1) { | 434 parent_model_.GetItemCount() - 1) { |
| 427 const BookmarkNode* new_parent = | 435 const BookmarkNode* new_parent = |
| 428 parent_model_.GetNodeAt(parent_combobox_->selected_item()); | 436 parent_model_.GetNodeAt(parent_combobox_->selected_item()); |
| 429 if (new_parent != node->parent()) { | 437 if (new_parent != node->parent()) { |
| 430 UserMetrics::RecordAction( | 438 UserMetrics::RecordAction( |
| 431 UserMetricsAction("BookmarkBubble_ChangeParent"), profile_); | 439 UserMetricsAction("BookmarkBubble_ChangeParent"), profile_); |
| 432 model->Move(node, new_parent, new_parent->child_count()); | 440 model->Move(node, new_parent, new_parent->child_count()); |
| 433 } | 441 } |
| 434 } | 442 } |
| 435 } | 443 } |
| 436 } | 444 } |
| OLD | NEW |