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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 BuildMenu(parent, start_child_index, menu, &next_menu_id_); | 433 BuildMenu(parent, start_child_index, menu, &next_menu_id_); |
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 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | |
444 gfx::ImageSkia* folder_icon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); | |
443 bool added_separator = false; | 445 bool added_separator = false; |
444 BuildMenuForPermanentNode(model->other_node(), menu, next_menu_id, | 446 BuildMenuForPermanentNode(model->other_node(), folder_icon, menu, |
sky
2014/06/19 15:02:54
How about making this take the id, that way code t
Joao da Silva
2014/06/19 15:56:35
Done.
| |
445 &added_separator); | 447 next_menu_id, &added_separator); |
446 BuildMenuForPermanentNode(model->mobile_node(), menu, next_menu_id, | 448 BuildMenuForPermanentNode(model->mobile_node(), folder_icon, menu, |
447 &added_separator); | 449 next_menu_id, &added_separator); |
448 } | 450 } |
449 | 451 |
450 void BookmarkMenuDelegate::BuildMenuForPermanentNode( | 452 void BookmarkMenuDelegate::BuildMenuForPermanentNode( |
451 const BookmarkNode* node, | 453 const BookmarkNode* node, |
454 gfx::ImageSkia* folder_icon, | |
452 MenuItemView* menu, | 455 MenuItemView* menu, |
453 int* next_menu_id, | 456 int* next_menu_id, |
454 bool* added_separator) { | 457 bool* added_separator) { |
455 if (!node->IsVisible() || node->GetTotalNodeCount() == 1) | 458 if (!node->IsVisible() || node->GetTotalNodeCount() == 1) |
456 return; // No children, don't create a menu. | 459 return; // No children, don't create a menu. |
457 | 460 |
458 int id = *next_menu_id; | 461 int id = *next_menu_id; |
459 // Don't create the submenu if its menu ID will be outside the range allowed. | 462 // Don't create the submenu if its menu ID will be outside the range allowed. |
460 if (IsOutsideMenuIdRange(id)) | 463 if (IsOutsideMenuIdRange(id)) |
461 return; | 464 return; |
462 (*next_menu_id)++; | 465 (*next_menu_id)++; |
463 | 466 |
464 if (!*added_separator) { | 467 if (!*added_separator) { |
465 *added_separator = true; | 468 *added_separator = true; |
466 menu->AppendSeparator(); | 469 menu->AppendSeparator(); |
467 } | 470 } |
468 | 471 |
469 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | |
470 gfx::ImageSkia* folder_icon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); | |
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 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
484 // http://crbug.com/49598 | 485 gfx::ImageSkia* folder_icon = |
485 BuildMenuForPermanentNode(node, menu, next_menu_id, &added_separator); | 486 rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER_MANAGED); |
487 BuildMenuForPermanentNode(node, folder_icon, menu, next_menu_id, | |
488 &added_separator); | |
486 } | 489 } |
487 | 490 |
488 void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent, | 491 void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent, |
489 int start_child_index, | 492 int start_child_index, |
490 MenuItemView* menu, | 493 MenuItemView* menu, |
491 int* next_menu_id) { | 494 int* next_menu_id) { |
492 node_to_menu_map_[parent] = menu; | 495 node_to_menu_map_[parent] = menu; |
493 DCHECK(parent->empty() || start_child_index < parent->child_count()); | 496 DCHECK(parent->empty() || start_child_index < parent->child_count()); |
494 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 497 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
495 for (int i = start_child_index; i < parent->child_count(); ++i) { | 498 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); | 519 BuildMenu(node, 0, submenu, next_menu_id); |
517 } else { | 520 } else { |
518 NOTREACHED(); | 521 NOTREACHED(); |
519 } | 522 } |
520 } | 523 } |
521 } | 524 } |
522 | 525 |
523 bool BookmarkMenuDelegate::IsOutsideMenuIdRange(int menu_id) const { | 526 bool BookmarkMenuDelegate::IsOutsideMenuIdRange(int menu_id) const { |
524 return menu_id < min_menu_id_ || menu_id > max_menu_id_; | 527 return menu_id < min_menu_id_ || menu_id > max_menu_id_; |
525 } | 528 } |
OLD | NEW |