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/browser/bookmarks/bookmark_model_factory.h" | 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
10 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | 10 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 real_delegate_ = real_delegate; | 71 real_delegate_ = real_delegate; |
72 location_ = location; | 72 location_ = location; |
73 if (parent) { | 73 if (parent) { |
74 parent_menu_item_ = parent; | 74 parent_menu_item_ = parent; |
75 | 75 |
76 // Add a separator if there are existing items in the menu, and if the | 76 // Add a separator if there are existing items in the menu, and if the |
77 // current node has children. If |node| is the bookmark bar then the | 77 // current node has children. If |node| is the bookmark bar then the |
78 // managed node is shown as its first child, if it's not empty. | 78 // managed node is shown as its first child, if it's not empty. |
79 BookmarkModel* model = GetBookmarkModel(); | 79 BookmarkModel* model = GetBookmarkModel(); |
80 ChromeBookmarkClient* client = GetChromeBookmarkClient(); | 80 ChromeBookmarkClient* client = GetChromeBookmarkClient(); |
81 bool show_managed = show_options == SHOW_PERMANENT_FOLDERS && | 81 bool show_pushed = show_options == SHOW_PERMANENT_FOLDERS && |
82 node == model->bookmark_bar_node() && | 82 node == model->bookmark_bar_node(); |
83 !client->managed_node()->empty(); | 83 bool show_managed = show_pushed && !client->managed_node()->empty(); |
84 bool has_children = | 84 bool show_supervised = show_pushed && !client->supervised_node()->empty(); |
85 (start_child_index < node->child_count()) || show_managed; | 85 bool has_children = (start_child_index < node->child_count()) || |
| 86 show_managed || show_supervised; |
86 int initial_count = parent->GetSubmenu() ? | 87 int initial_count = parent->GetSubmenu() ? |
87 parent->GetSubmenu()->GetMenuItemCount() : 0; | 88 parent->GetSubmenu()->GetMenuItemCount() : 0; |
88 if (has_children && initial_count > 0) | 89 if (has_children && initial_count > 0) |
89 parent->AppendSeparator(); | 90 parent->AppendSeparator(); |
90 if (show_managed) | 91 if (show_managed) |
91 BuildMenuForManagedNode(parent, &next_menu_id_); | 92 BuildMenuForManagedNode(parent, &next_menu_id_); |
| 93 if (show_supervised) |
| 94 BuildMenuForSupervisedNode(parent, &next_menu_id_); |
92 BuildMenu(node, start_child_index, parent, &next_menu_id_); | 95 BuildMenu(node, start_child_index, parent, &next_menu_id_); |
93 if (show_options == SHOW_PERMANENT_FOLDERS) | 96 if (show_options == SHOW_PERMANENT_FOLDERS) |
94 BuildMenusForPermanentNodes(parent, &next_menu_id_); | 97 BuildMenusForPermanentNodes(parent, &next_menu_id_); |
95 } else { | 98 } else { |
96 menu_ = CreateMenu(node, start_child_index, show_options); | 99 menu_ = CreateMenu(node, start_child_index, show_options); |
97 } | 100 } |
98 } | 101 } |
99 | 102 |
100 void BookmarkMenuDelegate::SetPageNavigator(PageNavigator* navigator) { | 103 void BookmarkMenuDelegate::SetPageNavigator(PageNavigator* navigator) { |
101 page_navigator_ = navigator; | 104 page_navigator_ = navigator; |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 } | 424 } |
422 | 425 |
423 MenuItemView* BookmarkMenuDelegate::CreateMenu(const BookmarkNode* parent, | 426 MenuItemView* BookmarkMenuDelegate::CreateMenu(const BookmarkNode* parent, |
424 int start_child_index, | 427 int start_child_index, |
425 ShowOptions show_options) { | 428 ShowOptions show_options) { |
426 MenuItemView* menu = new MenuItemView(real_delegate_); | 429 MenuItemView* menu = new MenuItemView(real_delegate_); |
427 menu->SetCommand(next_menu_id_++); | 430 menu->SetCommand(next_menu_id_++); |
428 menu_id_to_node_map_[menu->GetCommand()] = parent; | 431 menu_id_to_node_map_[menu->GetCommand()] = parent; |
429 menu->set_has_icons(true); | 432 menu->set_has_icons(true); |
430 bool show_permanent = show_options == SHOW_PERMANENT_FOLDERS; | 433 bool show_permanent = show_options == SHOW_PERMANENT_FOLDERS; |
431 if (show_permanent && parent == GetBookmarkModel()->bookmark_bar_node()) | 434 if (show_permanent && parent == GetBookmarkModel()->bookmark_bar_node()) { |
432 BuildMenuForManagedNode(menu, &next_menu_id_); | 435 BuildMenuForManagedNode(menu, &next_menu_id_); |
| 436 BuildMenuForSupervisedNode(menu, &next_menu_id_); |
| 437 } |
433 BuildMenu(parent, start_child_index, menu, &next_menu_id_); | 438 BuildMenu(parent, start_child_index, menu, &next_menu_id_); |
434 if (show_permanent) | 439 if (show_permanent) |
435 BuildMenusForPermanentNodes(menu, &next_menu_id_); | 440 BuildMenusForPermanentNodes(menu, &next_menu_id_); |
436 return menu; | 441 return menu; |
437 } | 442 } |
438 | 443 |
439 void BookmarkMenuDelegate::BuildMenusForPermanentNodes( | 444 void BookmarkMenuDelegate::BuildMenusForPermanentNodes( |
440 views::MenuItemView* menu, | 445 views::MenuItemView* menu, |
441 int* next_menu_id) { | 446 int* next_menu_id) { |
442 BookmarkModel* model = GetBookmarkModel(); | 447 BookmarkModel* model = GetBookmarkModel(); |
(...skipping 25 matching lines...) Expand all Loading... |
468 } | 473 } |
469 | 474 |
470 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 475 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
471 gfx::ImageSkia* folder_icon = rb->GetImageSkiaNamed(icon_resource_id); | 476 gfx::ImageSkia* folder_icon = rb->GetImageSkiaNamed(icon_resource_id); |
472 MenuItemView* submenu = menu->AppendSubMenuWithIcon( | 477 MenuItemView* submenu = menu->AppendSubMenuWithIcon( |
473 id, node->GetTitle(), *folder_icon); | 478 id, node->GetTitle(), *folder_icon); |
474 BuildMenu(node, 0, submenu, next_menu_id); | 479 BuildMenu(node, 0, submenu, next_menu_id); |
475 menu_id_to_node_map_[id] = node; | 480 menu_id_to_node_map_[id] = node; |
476 } | 481 } |
477 | 482 |
478 void BookmarkMenuDelegate::BuildMenuForManagedNode( | 483 void BookmarkMenuDelegate::BuildMenuForManagedNode(MenuItemView* menu, |
479 MenuItemView* menu, | 484 int* next_menu_id) { |
480 int* next_menu_id) { | |
481 // Don't add a separator for this menu. | 485 // Don't add a separator for this menu. |
482 bool added_separator = true; | 486 bool added_separator = true; |
483 const BookmarkNode* node = GetChromeBookmarkClient()->managed_node(); | 487 const BookmarkNode* node = GetChromeBookmarkClient()->managed_node(); |
484 BuildMenuForPermanentNode(node, IDR_BOOKMARK_BAR_FOLDER_MANAGED, menu, | 488 BuildMenuForPermanentNode(node, IDR_BOOKMARK_BAR_FOLDER_MANAGED, menu, |
485 next_menu_id, &added_separator); | 489 next_menu_id, &added_separator); |
486 } | 490 } |
487 | 491 |
| 492 void BookmarkMenuDelegate::BuildMenuForSupervisedNode(MenuItemView* menu, |
| 493 int* next_menu_id) { |
| 494 // Don't add a separator for this menu. |
| 495 bool added_separator = true; |
| 496 const BookmarkNode* node = GetChromeBookmarkClient()->supervised_node(); |
| 497 BuildMenuForPermanentNode(node, IDR_BOOKMARK_BAR_FOLDER_SUPERVISED, menu, |
| 498 next_menu_id, &added_separator); |
| 499 } |
| 500 |
488 void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent, | 501 void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent, |
489 int start_child_index, | 502 int start_child_index, |
490 MenuItemView* menu, | 503 MenuItemView* menu, |
491 int* next_menu_id) { | 504 int* next_menu_id) { |
492 node_to_menu_map_[parent] = menu; | 505 node_to_menu_map_[parent] = menu; |
493 DCHECK(parent->empty() || start_child_index < parent->child_count()); | 506 DCHECK(parent->empty() || start_child_index < parent->child_count()); |
494 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 507 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
495 for (int i = start_child_index; i < parent->child_count(); ++i) { | 508 for (int i = start_child_index; i < parent->child_count(); ++i) { |
496 const BookmarkNode* node = parent->GetChild(i); | 509 const BookmarkNode* node = parent->GetChild(i); |
497 const int id = *next_menu_id; | 510 const int id = *next_menu_id; |
(...skipping 18 matching lines...) Expand all Loading... |
516 BuildMenu(node, 0, submenu, next_menu_id); | 529 BuildMenu(node, 0, submenu, next_menu_id); |
517 } else { | 530 } else { |
518 NOTREACHED(); | 531 NOTREACHED(); |
519 } | 532 } |
520 } | 533 } |
521 } | 534 } |
522 | 535 |
523 bool BookmarkMenuDelegate::IsOutsideMenuIdRange(int menu_id) const { | 536 bool BookmarkMenuDelegate::IsOutsideMenuIdRange(int menu_id) const { |
524 return menu_id < min_menu_id_ || menu_id > max_menu_id_; | 537 return menu_id < min_menu_id_ || menu_id > max_menu_id_; |
525 } | 538 } |
OLD | NEW |