Chromium Code Reviews| 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 // Commit any edits now. | |
| 374 ApplyEdits(); | |
|
sky
2011/04/08 17:48:44
Close applys the edits, so you shouldn't need to i
| |
| 375 | |
| 376 // Close the InfoBubble | |
| 377 Close(); | |
| 378 | |
| 379 // Open the Bookmark Manager | |
| 380 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | |
| 381 if (browser) | |
| 382 browser->OpenBookmarkManager(); | |
| 383 else | |
|
sky
2011/04/08 17:48:44
This should be a DCHECK before 381.
| |
| 384 NOTREACHED(); | |
| 385 | |
| 386 #else | |
| 375 const BookmarkNode* node = | 387 const BookmarkNode* node = |
| 376 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); | 388 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); |
| 377 | 389 |
| 378 // Commit any edits now. | 390 // Commit any edits now. |
| 379 ApplyEdits(); | 391 ApplyEdits(); |
| 380 | 392 |
| 381 #if defined(OS_WIN) | 393 #if defined(OS_WIN) |
| 382 // Parent the editor to our root ancestor (not the root we're in, as that | 394 // Parent the editor to our root ancestor (not the root we're in, as that |
| 383 // is the info bubble and will close shortly). | 395 // is the info bubble and will close shortly). |
| 384 HWND parent = GetAncestor(GetWidget()->GetNativeView(), GA_ROOTOWNER); | 396 HWND parent = GetAncestor(GetWidget()->GetNativeView(), GA_ROOTOWNER); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 398 | 410 |
| 399 // Even though we just hid the window, we need to invoke Close to schedule | 411 // Even though we just hid the window, we need to invoke Close to schedule |
| 400 // the delete and all that. | 412 // the delete and all that. |
| 401 Close(); | 413 Close(); |
| 402 | 414 |
| 403 if (node) { | 415 if (node) { |
| 404 BookmarkEditor::Show(parent, profile_, NULL, | 416 BookmarkEditor::Show(parent, profile_, NULL, |
| 405 BookmarkEditor::EditDetails(node), | 417 BookmarkEditor::EditDetails(node), |
| 406 BookmarkEditor::SHOW_TREE); | 418 BookmarkEditor::SHOW_TREE); |
| 407 } | 419 } |
| 420 #endif | |
| 408 } | 421 } |
| 409 | 422 |
| 410 void BookmarkBubbleView::ApplyEdits() { | 423 void BookmarkBubbleView::ApplyEdits() { |
| 411 // Set this to make sure we don't attempt to apply edits again. | 424 // Set this to make sure we don't attempt to apply edits again. |
| 412 apply_edits_ = false; | 425 apply_edits_ = false; |
| 413 | 426 |
| 414 BookmarkModel* model = profile_->GetBookmarkModel(); | 427 BookmarkModel* model = profile_->GetBookmarkModel(); |
| 415 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); | 428 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); |
| 416 if (node) { | 429 if (node) { |
| 417 const string16 new_title = title_tf_->text(); | 430 const string16 new_title = title_tf_->text(); |
| 418 if (new_title != node->GetTitle()) { | 431 if (new_title != node->GetTitle()) { |
| 419 model->SetTitle(node, new_title); | 432 model->SetTitle(node, new_title); |
| 420 UserMetrics::RecordAction( | 433 UserMetrics::RecordAction( |
| 421 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"), | 434 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"), |
| 422 profile_); | 435 profile_); |
| 423 } | 436 } |
| 424 // Last index means 'Choose another folder...' | 437 // Last index means 'Choose another folder...' |
| 425 if (parent_combobox_->selected_item() < | 438 if (parent_combobox_->selected_item() < |
| 426 parent_model_.GetItemCount() - 1) { | 439 parent_model_.GetItemCount() - 1) { |
| 427 const BookmarkNode* new_parent = | 440 const BookmarkNode* new_parent = |
| 428 parent_model_.GetNodeAt(parent_combobox_->selected_item()); | 441 parent_model_.GetNodeAt(parent_combobox_->selected_item()); |
| 429 if (new_parent != node->parent()) { | 442 if (new_parent != node->parent()) { |
| 430 UserMetrics::RecordAction( | 443 UserMetrics::RecordAction( |
| 431 UserMetricsAction("BookmarkBubble_ChangeParent"), profile_); | 444 UserMetricsAction("BookmarkBubble_ChangeParent"), profile_); |
| 432 model->Move(node, new_parent, new_parent->child_count()); | 445 model->Move(node, new_parent, new_parent->child_count()); |
| 433 } | 446 } |
| 434 } | 447 } |
| 435 } | 448 } |
| 436 } | 449 } |
| OLD | NEW |