OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_menu_delegate.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
10 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 10 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 const gfx::Point& p, | 313 const gfx::Point& p, |
314 ui::MenuSourceType source_type) { | 314 ui::MenuSourceType source_type) { |
315 DCHECK(menu_id_to_node_map_.find(id) != menu_id_to_node_map_.end()); | 315 DCHECK(menu_id_to_node_map_.find(id) != menu_id_to_node_map_.end()); |
316 const BookmarkNode* node = menu_id_to_node_map_[id]; | 316 const BookmarkNode* node = menu_id_to_node_map_[id]; |
317 std::vector<const BookmarkNode*> nodes(1, node); | 317 std::vector<const BookmarkNode*> nodes(1, node); |
318 context_menu_.reset(new BookmarkContextMenu( | 318 context_menu_.reset(new BookmarkContextMenu( |
319 parent_, browser_, profile_, page_navigator_, node->parent(), nodes, | 319 parent_, browser_, profile_, page_navigator_, node->parent(), nodes, |
320 ShouldCloseOnRemove(node))); | 320 ShouldCloseOnRemove(node))); |
321 context_menu_->set_observer(this); | 321 context_menu_->set_observer(this); |
322 context_menu_->RunMenuAt(p, source_type); | 322 context_menu_->RunMenuAt(p, source_type); |
323 context_menu_.reset(nullptr); | |
324 return true; | 323 return true; |
325 } | 324 } |
326 | 325 |
327 bool BookmarkMenuDelegate::CanDrag(MenuItemView* menu) { | 326 bool BookmarkMenuDelegate::CanDrag(MenuItemView* menu) { |
328 const BookmarkNode* node = menu_id_to_node_map_[menu->GetCommand()]; | 327 const BookmarkNode* node = menu_id_to_node_map_[menu->GetCommand()]; |
329 // Don't let users drag the other folder. | 328 // Don't let users drag the other folder. |
330 return node->parent() != GetBookmarkModel()->root_node(); | 329 return node->parent() != GetBookmarkModel()->root_node(); |
331 } | 330 } |
332 | 331 |
333 void BookmarkMenuDelegate::WriteDragData(MenuItemView* sender, | 332 void BookmarkMenuDelegate::WriteDragData(MenuItemView* sender, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 (*i)->ChildrenChanged(); | 426 (*i)->ChildrenChanged(); |
428 } | 427 } |
429 | 428 |
430 void BookmarkMenuDelegate::DidRemoveBookmarks() { | 429 void BookmarkMenuDelegate::DidRemoveBookmarks() { |
431 // Balances remove in WillRemoveBookmarksImpl. | 430 // Balances remove in WillRemoveBookmarksImpl. |
432 GetBookmarkModel()->AddObserver(this); | 431 GetBookmarkModel()->AddObserver(this); |
433 DCHECK(is_mutating_model_); | 432 DCHECK(is_mutating_model_); |
434 is_mutating_model_ = false; | 433 is_mutating_model_ = false; |
435 } | 434 } |
436 | 435 |
| 436 void BookmarkMenuDelegate::OnContextMenuClosed() { |
| 437 context_menu_.reset(); |
| 438 } |
| 439 |
437 bool BookmarkMenuDelegate::ShouldCloseOnRemove(const BookmarkNode* node) const { | 440 bool BookmarkMenuDelegate::ShouldCloseOnRemove(const BookmarkNode* node) const { |
438 // We never need to close when embedded in the app menu. | 441 // We never need to close when embedded in the app menu. |
439 const bool is_shown_from_app_menu = parent_menu_item_ != nullptr; | 442 const bool is_shown_from_app_menu = parent_menu_item_ != nullptr; |
440 if (is_shown_from_app_menu) | 443 if (is_shown_from_app_menu) |
441 return false; | 444 return false; |
442 | 445 |
443 const bool is_only_child_of_other_folder = | 446 const bool is_only_child_of_other_folder = |
444 (node->parent() == GetBookmarkModel()->other_node() && | 447 (node->parent() == GetBookmarkModel()->other_node() && |
445 node->parent()->child_count() == 1); | 448 node->parent()->child_count() == 1); |
446 const bool is_child_of_bookmark_bar = | 449 const bool is_child_of_bookmark_bar = |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 } | 544 } |
542 AddMenuToMaps(child_menu_item, node); | 545 AddMenuToMaps(child_menu_item, node); |
543 } | 546 } |
544 } | 547 } |
545 | 548 |
546 void BookmarkMenuDelegate::AddMenuToMaps(MenuItemView* menu, | 549 void BookmarkMenuDelegate::AddMenuToMaps(MenuItemView* menu, |
547 const BookmarkNode* node) { | 550 const BookmarkNode* node) { |
548 menu_id_to_node_map_[menu->GetCommand()] = node; | 551 menu_id_to_node_map_[menu->GetCommand()] = node; |
549 node_to_menu_map_[node] = menu; | 552 node_to_menu_map_[node] = menu; |
550 } | 553 } |
OLD | NEW |