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" |
11 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | 11 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
12 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | |
13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" | 13 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" |
15 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" | 14 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
16 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 16 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
18 #include "chrome/browser/ui/views/event_utils.h" | 17 #include "chrome/browser/ui/views/event_utils.h" |
19 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
20 #include "components/bookmarks/browser/bookmark_model.h" | 19 #include "components/bookmarks/browser/bookmark_model.h" |
| 20 #include "components/bookmarks/managed/managed_bookmark_service.h" |
21 #include "content/public/browser/page_navigator.h" | 21 #include "content/public/browser/page_navigator.h" |
22 #include "content/public/browser/user_metrics.h" | 22 #include "content/public/browser/user_metrics.h" |
23 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
24 #include "ui/base/dragdrop/os_exchange_data.h" | 24 #include "ui/base/dragdrop/os_exchange_data.h" |
25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/base/window_open_disposition.h" | 26 #include "ui/base/window_open_disposition.h" |
27 #include "ui/resources/grit/ui_resources.h" | 27 #include "ui/resources/grit/ui_resources.h" |
28 #include "ui/views/controls/button/menu_button.h" | 28 #include "ui/views/controls/button/menu_button.h" |
29 #include "ui/views/controls/menu/menu_item_view.h" | 29 #include "ui/views/controls/menu/menu_item_view.h" |
30 #include "ui/views/controls/menu/submenu_view.h" | 30 #include "ui/views/controls/menu/submenu_view.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 GetBookmarkModel()->AddObserver(this); | 69 GetBookmarkModel()->AddObserver(this); |
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 bookmarks::ManagedBookmarkService* managed = GetManagedBookmarkService(); |
80 bool show_forced_folders = show_options == SHOW_PERMANENT_FOLDERS && | 80 bool show_forced_folders = show_options == SHOW_PERMANENT_FOLDERS && |
81 node == model->bookmark_bar_node(); | 81 node == model->bookmark_bar_node(); |
82 bool show_managed = show_forced_folders && !client->managed_node()->empty(); | 82 bool show_managed = |
| 83 show_forced_folders && !managed->managed_node()->empty(); |
83 bool show_supervised = | 84 bool show_supervised = |
84 show_forced_folders && !client->supervised_node()->empty(); | 85 show_forced_folders && !managed->supervised_node()->empty(); |
85 bool has_children = (start_child_index < node->child_count()) || | 86 bool has_children = (start_child_index < node->child_count()) || |
86 show_managed || show_supervised; | 87 show_managed || show_supervised; |
87 int initial_count = parent->GetSubmenu() ? | 88 int initial_count = parent->GetSubmenu() ? |
88 parent->GetSubmenu()->GetMenuItemCount() : 0; | 89 parent->GetSubmenu()->GetMenuItemCount() : 0; |
89 if (has_children && initial_count > 0) | 90 if (has_children && initial_count > 0) |
90 parent->AppendSeparator(); | 91 parent->AppendSeparator(); |
91 if (show_managed) | 92 if (show_managed) |
92 BuildMenuForManagedNode(parent); | 93 BuildMenuForManagedNode(parent); |
93 if (show_supervised) | 94 if (show_supervised) |
94 BuildMenuForSupervisedNode(parent); | 95 BuildMenuForSupervisedNode(parent); |
95 BuildMenu(node, start_child_index, parent); | 96 BuildMenu(node, start_child_index, parent); |
96 if (show_options == SHOW_PERMANENT_FOLDERS) | 97 if (show_options == SHOW_PERMANENT_FOLDERS) |
97 BuildMenusForPermanentNodes(parent); | 98 BuildMenusForPermanentNodes(parent); |
98 } else { | 99 } else { |
99 menu_ = CreateMenu(node, start_child_index, show_options); | 100 menu_ = CreateMenu(node, start_child_index, show_options); |
100 } | 101 } |
101 } | 102 } |
102 | 103 |
103 void BookmarkMenuDelegate::SetPageNavigator(PageNavigator* navigator) { | 104 void BookmarkMenuDelegate::SetPageNavigator(PageNavigator* navigator) { |
104 page_navigator_ = navigator; | 105 page_navigator_ = navigator; |
105 if (context_menu_.get()) | 106 if (context_menu_.get()) |
106 context_menu_->SetPageNavigator(navigator); | 107 context_menu_->SetPageNavigator(navigator); |
107 } | 108 } |
108 | 109 |
109 BookmarkModel* BookmarkMenuDelegate::GetBookmarkModel() { | 110 BookmarkModel* BookmarkMenuDelegate::GetBookmarkModel() { |
110 return BookmarkModelFactory::GetForProfile(profile_); | 111 return BookmarkModelFactory::GetForProfile(profile_); |
111 } | 112 } |
112 | 113 |
113 ChromeBookmarkClient* BookmarkMenuDelegate::GetChromeBookmarkClient() { | 114 bookmarks::ManagedBookmarkService* |
114 return ChromeBookmarkClientFactory::GetForProfile(profile_); | 115 BookmarkMenuDelegate::GetManagedBookmarkService() { |
| 116 return ManagedBookmarkServiceFactory::GetForProfile(profile_); |
115 } | 117 } |
116 | 118 |
117 void BookmarkMenuDelegate::SetActiveMenu(const BookmarkNode* node, | 119 void BookmarkMenuDelegate::SetActiveMenu(const BookmarkNode* node, |
118 int start_index) { | 120 int start_index) { |
119 DCHECK(!parent_menu_item_); | 121 DCHECK(!parent_menu_item_); |
120 if (!node_to_menu_map_[node]) | 122 if (!node_to_menu_map_[node]) |
121 CreateMenu(node, start_index, HIDE_PERMANENT_FOLDERS); | 123 CreateMenu(node, start_index, HIDE_PERMANENT_FOLDERS); |
122 menu_ = node_to_menu_map_[node]; | 124 menu_ = node_to_menu_map_[node]; |
123 } | 125 } |
124 | 126 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 476 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
475 gfx::ImageSkia* folder_icon = rb->GetImageSkiaNamed(icon_resource_id); | 477 gfx::ImageSkia* folder_icon = rb->GetImageSkiaNamed(icon_resource_id); |
476 AddMenuToMaps(menu->AppendSubMenuWithIcon(next_menu_id_++, node->GetTitle(), | 478 AddMenuToMaps(menu->AppendSubMenuWithIcon(next_menu_id_++, node->GetTitle(), |
477 *folder_icon), | 479 *folder_icon), |
478 node); | 480 node); |
479 } | 481 } |
480 | 482 |
481 void BookmarkMenuDelegate::BuildMenuForManagedNode(MenuItemView* menu) { | 483 void BookmarkMenuDelegate::BuildMenuForManagedNode(MenuItemView* menu) { |
482 // Don't add a separator for this menu. | 484 // Don't add a separator for this menu. |
483 bool added_separator = true; | 485 bool added_separator = true; |
484 const BookmarkNode* node = GetChromeBookmarkClient()->managed_node(); | 486 const BookmarkNode* node = GetManagedBookmarkService()->managed_node(); |
485 BuildMenuForPermanentNode(node, IDR_BOOKMARK_BAR_FOLDER_MANAGED, menu, | 487 BuildMenuForPermanentNode(node, IDR_BOOKMARK_BAR_FOLDER_MANAGED, menu, |
486 &added_separator); | 488 &added_separator); |
487 } | 489 } |
488 | 490 |
489 void BookmarkMenuDelegate::BuildMenuForSupervisedNode(MenuItemView* menu) { | 491 void BookmarkMenuDelegate::BuildMenuForSupervisedNode(MenuItemView* menu) { |
490 // Don't add a separator for this menu. | 492 // Don't add a separator for this menu. |
491 bool added_separator = true; | 493 bool added_separator = true; |
492 const BookmarkNode* node = GetChromeBookmarkClient()->supervised_node(); | 494 const BookmarkNode* node = GetManagedBookmarkService()->supervised_node(); |
493 BuildMenuForPermanentNode(node, IDR_BOOKMARK_BAR_FOLDER_SUPERVISED, menu, | 495 BuildMenuForPermanentNode(node, IDR_BOOKMARK_BAR_FOLDER_SUPERVISED, menu, |
494 &added_separator); | 496 &added_separator); |
495 } | 497 } |
496 | 498 |
497 void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent, | 499 void BookmarkMenuDelegate::BuildMenu(const BookmarkNode* parent, |
498 int start_child_index, | 500 int start_child_index, |
499 MenuItemView* menu) { | 501 MenuItemView* menu) { |
500 DCHECK(parent->empty() || start_child_index < parent->child_count()); | 502 DCHECK(parent->empty() || start_child_index < parent->child_count()); |
501 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 503 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
502 for (int i = start_child_index; i < parent->child_count(); ++i) { | 504 for (int i = start_child_index; i < parent->child_count(); ++i) { |
(...skipping 15 matching lines...) Expand all Loading... |
518 } | 520 } |
519 AddMenuToMaps(child_menu_item, node); | 521 AddMenuToMaps(child_menu_item, node); |
520 } | 522 } |
521 } | 523 } |
522 | 524 |
523 void BookmarkMenuDelegate::AddMenuToMaps(MenuItemView* menu, | 525 void BookmarkMenuDelegate::AddMenuToMaps(MenuItemView* menu, |
524 const BookmarkNode* node) { | 526 const BookmarkNode* node) { |
525 menu_id_to_node_map_[menu->GetCommand()] = node; | 527 menu_id_to_node_map_[menu->GetCommand()] = node; |
526 node_to_menu_map_[node] = menu; | 528 node_to_menu_map_[node] = menu; |
527 } | 529 } |
OLD | NEW |