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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 bool copy = event.source_operations() == ui::DragDropTypes::DRAG_COPY; | 306 bool copy = event.source_operations() == ui::DragDropTypes::DRAG_COPY; |
307 return chrome::DropBookmarks(profile_, drop_data_, | 307 return chrome::DropBookmarks(profile_, drop_data_, |
308 drop_parent, index_to_drop_at, copy); | 308 drop_parent, index_to_drop_at, copy); |
309 } | 309 } |
310 | 310 |
311 bool BookmarkMenuDelegate::ShowContextMenu(MenuItemView* source, | 311 bool BookmarkMenuDelegate::ShowContextMenu(MenuItemView* source, |
312 int id, | 312 int id, |
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 std::vector<const BookmarkNode*> nodes; | 317 std::vector<const BookmarkNode*> nodes; |
317 nodes.push_back(menu_id_to_node_map_[id]); | 318 nodes.push_back(node); |
Devlin
2015/12/29 00:59:34
nit: I'd probably use std::vector<const BookmarkNo
sky
2015/12/29 17:11:27
I changed it to your first suggestion.
| |
318 bool close_on_delete = !parent_menu_item_ && | 319 // The 'other' bookmarks folder hides when it has no more items, so we need |
319 (nodes[0]->parent() == GetBookmarkModel()->other_node() && | 320 // to exit the menu when the last node is removed. |
320 nodes[0]->parent()->child_count() == 1); | 321 // If the parent is the bookmark bar, then the menu is showing for an item on |
321 context_menu_.reset( | 322 // the bookmark bar. When removing this item we need to close the menu (as |
322 new BookmarkContextMenu( | 323 // there is no longer anything to anchor the menu too). |
Devlin
2015/12/29 00:59:34
s/too/to
sky
2015/12/29 17:11:28
Done.
| |
323 parent_, | 324 const bool close_on_remove = |
324 browser_, | 325 !parent_menu_item_ && |
325 profile_, | 326 ((node->parent() == GetBookmarkModel()->other_node() && |
326 page_navigator_, | 327 node->parent()->child_count() == 1) || |
327 nodes[0]->parent(), | 328 node->parent() == GetBookmarkModel()->bookmark_bar_node()); |
Devlin
2015/12/29 00:59:34
I think this bool might be more readable if it wer
sky
2015/12/29 17:11:27
As part of adding test coverage I did this.
| |
328 nodes, | 329 context_menu_.reset(new BookmarkContextMenu(parent_, browser_, profile_, |
329 close_on_delete)); | 330 page_navigator_, node->parent(), |
331 nodes, close_on_remove)); | |
330 context_menu_->set_observer(this); | 332 context_menu_->set_observer(this); |
331 context_menu_->RunMenuAt(p, source_type); | 333 context_menu_->RunMenuAt(p, source_type); |
332 context_menu_.reset(NULL); | 334 context_menu_.reset(nullptr); |
333 return true; | 335 return true; |
334 } | 336 } |
335 | 337 |
336 bool BookmarkMenuDelegate::CanDrag(MenuItemView* menu) { | 338 bool BookmarkMenuDelegate::CanDrag(MenuItemView* menu) { |
337 const BookmarkNode* node = menu_id_to_node_map_[menu->GetCommand()]; | 339 const BookmarkNode* node = menu_id_to_node_map_[menu->GetCommand()]; |
338 // Don't let users drag the other folder. | 340 // Don't let users drag the other folder. |
339 return node->parent() != GetBookmarkModel()->root_node(); | 341 return node->parent() != GetBookmarkModel()->root_node(); |
340 } | 342 } |
341 | 343 |
342 void BookmarkMenuDelegate::WriteDragData(MenuItemView* sender, | 344 void BookmarkMenuDelegate::WriteDragData(MenuItemView* sender, |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 } | 533 } |
532 AddMenuToMaps(child_menu_item, node); | 534 AddMenuToMaps(child_menu_item, node); |
533 } | 535 } |
534 } | 536 } |
535 | 537 |
536 void BookmarkMenuDelegate::AddMenuToMaps(MenuItemView* menu, | 538 void BookmarkMenuDelegate::AddMenuToMaps(MenuItemView* menu, |
537 const BookmarkNode* node) { | 539 const BookmarkNode* node) { |
538 menu_id_to_node_map_[menu->GetCommand()] = node; | 540 menu_id_to_node_map_[menu->GetCommand()] = node; |
539 node_to_menu_map_[node] = menu; | 541 node_to_menu_map_[node] = menu; |
540 } | 542 } |
OLD | NEW |