| 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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 if (show_permanent) | 434 if (show_permanent) |
| 435 BuildMenusForPermanentNodes(menu, &next_menu_id_); | 435 BuildMenusForPermanentNodes(menu, &next_menu_id_); |
| 436 return menu; | 436 return menu; |
| 437 } | 437 } |
| 438 | 438 |
| 439 void BookmarkMenuDelegate::BuildMenusForPermanentNodes( | 439 void BookmarkMenuDelegate::BuildMenusForPermanentNodes( |
| 440 views::MenuItemView* menu, | 440 views::MenuItemView* menu, |
| 441 int* next_menu_id) { | 441 int* next_menu_id) { |
| 442 BookmarkModel* model = GetBookmarkModel(); | 442 BookmarkModel* model = GetBookmarkModel(); |
| 443 bool added_separator = false; | 443 bool added_separator = false; |
| 444 BuildMenuForPermanentNode(model->other_node(), menu, next_menu_id, | 444 BuildMenuForPermanentNode(model->other_node(), IDR_BOOKMARK_BAR_FOLDER, menu, |
| 445 &added_separator); | 445 next_menu_id, &added_separator); |
| 446 BuildMenuForPermanentNode(model->mobile_node(), menu, next_menu_id, | 446 BuildMenuForPermanentNode(model->mobile_node(), IDR_BOOKMARK_BAR_FOLDER, menu, |
| 447 &added_separator); | 447 next_menu_id, &added_separator); |
| 448 } | 448 } |
| 449 | 449 |
| 450 void BookmarkMenuDelegate::BuildMenuForPermanentNode( | 450 void BookmarkMenuDelegate::BuildMenuForPermanentNode( |
| 451 const BookmarkNode* node, | 451 const BookmarkNode* node, |
| 452 int icon_resource_id, |
| 452 MenuItemView* menu, | 453 MenuItemView* menu, |
| 453 int* next_menu_id, | 454 int* next_menu_id, |
| 454 bool* added_separator) { | 455 bool* added_separator) { |
| 455 if (!node->IsVisible() || node->GetTotalNodeCount() == 1) | 456 if (!node->IsVisible() || node->GetTotalNodeCount() == 1) |
| 456 return; // No children, don't create a menu. | 457 return; // No children, don't create a menu. |
| 457 | 458 |
| 458 int id = *next_menu_id; | 459 int id = *next_menu_id; |
| 459 // Don't create the submenu if its menu ID will be outside the range allowed. | 460 // Don't create the submenu if its menu ID will be outside the range allowed. |
| 460 if (IsOutsideMenuIdRange(id)) | 461 if (IsOutsideMenuIdRange(id)) |
| 461 return; | 462 return; |
| 462 (*next_menu_id)++; | 463 (*next_menu_id)++; |
| 463 | 464 |
| 464 if (!*added_separator) { | 465 if (!*added_separator) { |
| 465 *added_separator = true; | 466 *added_separator = true; |
| 466 menu->AppendSeparator(); | 467 menu->AppendSeparator(); |
| 467 } | 468 } |
| 468 | 469 |
| 469 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 470 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 470 gfx::ImageSkia* folder_icon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); | 471 gfx::ImageSkia* folder_icon = rb->GetImageSkiaNamed(icon_resource_id); |
| 471 MenuItemView* submenu = menu->AppendSubMenuWithIcon( | 472 MenuItemView* submenu = menu->AppendSubMenuWithIcon( |
| 472 id, node->GetTitle(), *folder_icon); | 473 id, node->GetTitle(), *folder_icon); |
| 473 BuildMenu(node, 0, submenu, next_menu_id); | 474 BuildMenu(node, 0, submenu, next_menu_id); |
| 474 menu_id_to_node_map_[id] = node; | 475 menu_id_to_node_map_[id] = node; |
| 475 } | 476 } |
| 476 | 477 |
| 477 void BookmarkMenuDelegate::BuildMenuForManagedNode( | 478 void BookmarkMenuDelegate::BuildMenuForManagedNode( |
| 478 MenuItemView* menu, | 479 MenuItemView* menu, |
| 479 int* next_menu_id) { | 480 int* next_menu_id) { |
| 480 // Don't add a separator for this menu. | 481 // Don't add a separator for this menu. |
| 481 bool added_separator = true; | 482 bool added_separator = true; |
| 482 const BookmarkNode* node = GetChromeBookmarkClient()->managed_node(); | 483 const BookmarkNode* node = GetChromeBookmarkClient()->managed_node(); |
| 483 // TODO(joaodasilva): use the "managed bookmark folder" icon here. | 484 BuildMenuForPermanentNode(node, IDR_BOOKMARK_BAR_FOLDER_MANAGED, menu, |
| 484 // http://crbug.com/49598 | 485 next_menu_id, &added_separator); |
| 485 BuildMenuForPermanentNode(node, menu, next_menu_id, &added_separator); | |
| 486 } | 486 } |
| 487 | 487 |
| 488 void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent, | 488 void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent, |
| 489 int start_child_index, | 489 int start_child_index, |
| 490 MenuItemView* menu, | 490 MenuItemView* menu, |
| 491 int* next_menu_id) { | 491 int* next_menu_id) { |
| 492 node_to_menu_map_[parent] = menu; | 492 node_to_menu_map_[parent] = menu; |
| 493 DCHECK(parent->empty() || start_child_index < parent->child_count()); | 493 DCHECK(parent->empty() || start_child_index < parent->child_count()); |
| 494 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 494 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 495 for (int i = start_child_index; i < parent->child_count(); ++i) { | 495 for (int i = start_child_index; i < parent->child_count(); ++i) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 516 BuildMenu(node, 0, submenu, next_menu_id); | 516 BuildMenu(node, 0, submenu, next_menu_id); |
| 517 } else { | 517 } else { |
| 518 NOTREACHED(); | 518 NOTREACHED(); |
| 519 } | 519 } |
| 520 } | 520 } |
| 521 } | 521 } |
| 522 | 522 |
| 523 bool BookmarkMenuDelegate::IsOutsideMenuIdRange(int menu_id) const { | 523 bool BookmarkMenuDelegate::IsOutsideMenuIdRange(int menu_id) const { |
| 524 return menu_id < min_menu_id_ || menu_id > max_menu_id_; | 524 return menu_id < min_menu_id_ || menu_id > max_menu_id_; |
| 525 } | 525 } |
| OLD | NEW |