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