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