| 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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 BuildMenu(parent, start_child_index, menu); | 447 BuildMenu(parent, start_child_index, menu); |
| 448 if (show_permanent) | 448 if (show_permanent) |
| 449 BuildMenusForPermanentNodes(menu); | 449 BuildMenusForPermanentNodes(menu); |
| 450 return menu; | 450 return menu; |
| 451 } | 451 } |
| 452 | 452 |
| 453 void BookmarkMenuDelegate::BuildMenusForPermanentNodes( | 453 void BookmarkMenuDelegate::BuildMenusForPermanentNodes( |
| 454 views::MenuItemView* menu) { | 454 views::MenuItemView* menu) { |
| 455 BookmarkModel* model = GetBookmarkModel(); | 455 BookmarkModel* model = GetBookmarkModel(); |
| 456 bool added_separator = false; | 456 bool added_separator = false; |
| 457 BuildMenuForPermanentNode(model->other_node(), IDR_BOOKMARK_BAR_FOLDER, menu, | 457 BuildMenuForPermanentNode(model->other_node(), |
| 458 chrome::GetBookmarkFolderIcon(), menu, |
| 458 &added_separator); | 459 &added_separator); |
| 459 BuildMenuForPermanentNode(model->mobile_node(), IDR_BOOKMARK_BAR_FOLDER, menu, | 460 BuildMenuForPermanentNode(model->mobile_node(), |
| 461 chrome::GetBookmarkFolderIcon(), menu, |
| 460 &added_separator); | 462 &added_separator); |
| 461 } | 463 } |
| 462 | 464 |
| 463 void BookmarkMenuDelegate::BuildMenuForPermanentNode( | 465 void BookmarkMenuDelegate::BuildMenuForPermanentNode(const BookmarkNode* node, |
| 464 const BookmarkNode* node, | 466 const gfx::ImageSkia& icon, |
| 465 int icon_resource_id, | 467 MenuItemView* menu, |
| 466 MenuItemView* menu, | 468 bool* added_separator) { |
| 467 bool* added_separator) { | |
| 468 if (!node->IsVisible() || node->GetTotalNodeCount() == 1) | 469 if (!node->IsVisible() || node->GetTotalNodeCount() == 1) |
| 469 return; // No children, don't create a menu. | 470 return; // No children, don't create a menu. |
| 470 | 471 |
| 471 if (!*added_separator) { | 472 if (!*added_separator) { |
| 472 *added_separator = true; | 473 *added_separator = true; |
| 473 menu->AppendSeparator(); | 474 menu->AppendSeparator(); |
| 474 } | 475 } |
| 475 | 476 |
| 476 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 477 AddMenuToMaps( |
| 477 gfx::ImageSkia* folder_icon = rb->GetImageSkiaNamed(icon_resource_id); | 478 menu->AppendSubMenuWithIcon(next_menu_id_++, node->GetTitle(), icon), |
| 478 AddMenuToMaps(menu->AppendSubMenuWithIcon(next_menu_id_++, node->GetTitle(), | 479 node); |
| 479 *folder_icon), | |
| 480 node); | |
| 481 } | 480 } |
| 482 | 481 |
| 483 void BookmarkMenuDelegate::BuildMenuForManagedNode(MenuItemView* menu) { | 482 void BookmarkMenuDelegate::BuildMenuForManagedNode(MenuItemView* menu) { |
| 484 // Don't add a separator for this menu. | 483 // Don't add a separator for this menu. |
| 485 bool added_separator = true; | 484 bool added_separator = true; |
| 486 const BookmarkNode* node = GetManagedBookmarkService()->managed_node(); | 485 const BookmarkNode* node = GetManagedBookmarkService()->managed_node(); |
| 487 BuildMenuForPermanentNode(node, IDR_BOOKMARK_BAR_FOLDER_MANAGED, menu, | 486 BuildMenuForPermanentNode(node, chrome::GetBookmarkManagedFolderIcon(), menu, |
| 488 &added_separator); | 487 &added_separator); |
| 489 } | 488 } |
| 490 | 489 |
| 491 void BookmarkMenuDelegate::BuildMenuForSupervisedNode(MenuItemView* menu) { | 490 void BookmarkMenuDelegate::BuildMenuForSupervisedNode(MenuItemView* menu) { |
| 492 // Don't add a separator for this menu. | 491 // Don't add a separator for this menu. |
| 493 bool added_separator = true; | 492 bool added_separator = true; |
| 494 const BookmarkNode* node = GetManagedBookmarkService()->supervised_node(); | 493 const BookmarkNode* node = GetManagedBookmarkService()->supervised_node(); |
| 495 BuildMenuForPermanentNode(node, IDR_BOOKMARK_BAR_FOLDER_SUPERVISED, menu, | 494 BuildMenuForPermanentNode(node, chrome::GetBookmarkSupervisedFolderIcon(), |
| 496 &added_separator); | 495 menu, &added_separator); |
| 497 } | 496 } |
| 498 | 497 |
| 499 void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent, | 498 void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent, |
| 500 int start_child_index, | 499 int start_child_index, |
| 501 MenuItemView* menu) { | 500 MenuItemView* menu) { |
| 502 DCHECK(parent->empty() || start_child_index < parent->child_count()); | 501 DCHECK(parent->empty() || start_child_index < parent->child_count()); |
| 503 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 502 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 504 for (int i = start_child_index; i < parent->child_count(); ++i) { | 503 for (int i = start_child_index; i < parent->child_count(); ++i) { |
| 505 const BookmarkNode* node = parent->GetChild(i); | 504 const BookmarkNode* node = parent->GetChild(i); |
| 506 const int id = next_menu_id_++; | 505 const int id = next_menu_id_++; |
| 507 MenuItemView* child_menu_item; | 506 MenuItemView* child_menu_item; |
| 508 if (node->is_url()) { | 507 if (node->is_url()) { |
| 509 const gfx::Image& image = GetBookmarkModel()->GetFavicon(node); | 508 const gfx::Image& image = GetBookmarkModel()->GetFavicon(node); |
| 510 const gfx::ImageSkia* icon = image.IsEmpty() ? | 509 const gfx::ImageSkia* icon = image.IsEmpty() ? |
| 511 rb->GetImageSkiaNamed(IDR_DEFAULT_FAVICON) : image.ToImageSkia(); | 510 rb->GetImageSkiaNamed(IDR_DEFAULT_FAVICON) : image.ToImageSkia(); |
| 512 child_menu_item = | 511 child_menu_item = |
| 513 menu->AppendMenuItemWithIcon(id, node->GetTitle(), *icon); | 512 menu->AppendMenuItemWithIcon(id, node->GetTitle(), *icon); |
| 514 } else { | 513 } else { |
| 515 DCHECK(node->is_folder()); | 514 DCHECK(node->is_folder()); |
| 516 gfx::ImageSkia* folder_icon = | 515 child_menu_item = menu->AppendSubMenuWithIcon( |
| 517 rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); | 516 id, node->GetTitle(), chrome::GetBookmarkFolderIcon()); |
| 518 child_menu_item = | |
| 519 menu->AppendSubMenuWithIcon(id, node->GetTitle(), *folder_icon); | |
| 520 } | 517 } |
| 521 AddMenuToMaps(child_menu_item, node); | 518 AddMenuToMaps(child_menu_item, node); |
| 522 } | 519 } |
| 523 } | 520 } |
| 524 | 521 |
| 525 void BookmarkMenuDelegate::AddMenuToMaps(MenuItemView* menu, | 522 void BookmarkMenuDelegate::AddMenuToMaps(MenuItemView* menu, |
| 526 const BookmarkNode* node) { | 523 const BookmarkNode* node) { |
| 527 menu_id_to_node_map_[menu->GetCommand()] = node; | 524 menu_id_to_node_map_[menu->GetCommand()] = node; |
| 528 node_to_menu_map_[node] = menu; | 525 node_to_menu_map_[node] = menu; |
| 529 } | 526 } |
| OLD | NEW |