OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/views/bookmark_menu_controller_views.h" | 5 #include "chrome/browser/views/bookmark_menu_controller_views.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/os_exchange_data.h" | 8 #include "app/os_exchange_data.h" |
9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/stl_util-inl.h" |
10 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 11 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
11 #include "chrome/browser/bookmarks/bookmark_utils.h" | 12 #include "chrome/browser/bookmarks/bookmark_utils.h" |
12 #include "chrome/browser/metrics/user_metrics.h" | 13 #include "chrome/browser/metrics/user_metrics.h" |
13 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
14 #include "chrome/browser/tab_contents/page_navigator.h" | 15 #include "chrome/browser/tab_contents/page_navigator.h" |
| 16 #include "chrome/browser/views/bookmark_bar_view.h" |
15 #include "chrome/browser/views/event_utils.h" | 17 #include "chrome/browser/views/event_utils.h" |
16 #include "chrome/common/page_transition_types.h" | 18 #include "chrome/common/page_transition_types.h" |
17 #include "grit/app_resources.h" | 19 #include "grit/app_resources.h" |
18 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
19 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
| 22 #include "views/controls/button/menu_button.h" |
| 23 |
| 24 using views::MenuItemView; |
20 | 25 |
21 BookmarkMenuController::BookmarkMenuController(Browser* browser, | 26 BookmarkMenuController::BookmarkMenuController(Browser* browser, |
22 Profile* profile, | 27 Profile* profile, |
23 PageNavigator* navigator, | 28 PageNavigator* navigator, |
24 gfx::NativeWindow parent, | 29 gfx::NativeWindow parent, |
25 const BookmarkNode* node, | 30 const BookmarkNode* node, |
26 int start_child_index, | 31 int start_child_index, |
27 bool show_other_folder) | 32 bool show_other_folder) |
28 : browser_(browser), | 33 : browser_(browser), |
29 profile_(profile), | 34 profile_(profile), |
30 page_navigator_(navigator), | 35 page_navigator_(navigator), |
31 parent_(parent), | 36 parent_(parent), |
32 node_(node), | 37 node_(node), |
| 38 menu_(NULL), |
33 observer_(NULL), | 39 observer_(NULL), |
34 for_drop_(false), | 40 for_drop_(false), |
35 show_other_folder_(show_other_folder) { | 41 show_other_folder_(show_other_folder), |
36 menu_.reset(new views::MenuItemView(this)); | 42 bookmark_bar_(NULL), |
37 int next_menu_id = 1; | 43 next_menu_id_(1) { |
38 menu_id_to_node_map_[menu_->GetCommand()] = node; | 44 menu_ = CreateMenu(node, start_child_index); |
39 menu_->set_has_icons(true); | 45 } |
40 BuildMenu(node, start_child_index, menu_.get(), &next_menu_id); | 46 |
41 if (show_other_folder) | 47 void BookmarkMenuController::RunMenuAt(BookmarkBarView* bookmark_bar, |
42 BuildOtherFolderMenu(&next_menu_id); | 48 bool for_drop) { |
| 49 bookmark_bar_ = bookmark_bar; |
| 50 views::MenuButton* menu_button = bookmark_bar_->GetMenuButtonForNode(node_); |
| 51 DCHECK(menu_button); |
| 52 MenuItemView::AnchorPosition anchor; |
| 53 int start_index; |
| 54 bookmark_bar_->GetAnchorPositionAndStartIndexForButton( |
| 55 menu_button, &anchor, &start_index); |
| 56 RunMenuAt(menu_button, anchor, for_drop); |
43 } | 57 } |
44 | 58 |
45 void BookmarkMenuController::RunMenuAt( | 59 void BookmarkMenuController::RunMenuAt( |
46 const gfx::Rect& bounds, | 60 views::MenuButton* button, |
47 views::MenuItemView::AnchorPosition position, | 61 MenuItemView::AnchorPosition position, |
48 bool for_drop) { | 62 bool for_drop) { |
| 63 gfx::Point screen_loc; |
| 64 views::View::ConvertPointToScreen(button, &screen_loc); |
| 65 // Subtract 1 from the height to make the popup flush with the button border. |
| 66 gfx::Rect bounds(screen_loc.x(), screen_loc.y(), button->width(), |
| 67 button->height() - 1); |
49 for_drop_ = for_drop; | 68 for_drop_ = for_drop; |
50 profile_->GetBookmarkModel()->AddObserver(this); | 69 profile_->GetBookmarkModel()->AddObserver(this); |
| 70 // The constructor creates the initial menu and that is all we should have |
| 71 // at this point. |
| 72 DCHECK(node_to_menu_map_.size() == 1); |
51 if (for_drop) { | 73 if (for_drop) { |
52 menu_->RunMenuForDropAt(parent_, bounds, position); | 74 menu_->RunMenuForDropAt(parent_, bounds, position); |
53 } else { | 75 } else { |
54 menu_->RunMenuAt(parent_, bounds, position, false); | 76 menu_->RunMenuAt(parent_, button, bounds, position, false); |
55 delete this; | 77 delete this; |
56 } | 78 } |
57 } | 79 } |
58 | 80 |
59 void BookmarkMenuController::Cancel() { | 81 void BookmarkMenuController::Cancel() { |
60 menu_->Cancel(); | 82 menu_->Cancel(); |
61 } | 83 } |
62 | 84 |
63 bool BookmarkMenuController::IsTriggerableEvent(const views::MouseEvent& e) { | 85 bool BookmarkMenuController::IsTriggerableEvent(const views::MouseEvent& e) { |
64 return event_utils::IsPossibleDispositionEvent(e); | 86 return event_utils::IsPossibleDispositionEvent(e); |
65 } | 87 } |
66 | 88 |
67 void BookmarkMenuController::ExecuteCommand(int id, int mouse_event_flags) { | 89 void BookmarkMenuController::ExecuteCommand(int id, int mouse_event_flags) { |
68 DCHECK(page_navigator_); | 90 DCHECK(page_navigator_); |
69 DCHECK(menu_id_to_node_map_.find(id) != menu_id_to_node_map_.end()); | 91 DCHECK(menu_id_to_node_map_.find(id) != menu_id_to_node_map_.end()); |
70 GURL url = menu_id_to_node_map_[id]->GetURL(); | 92 GURL url = menu_id_to_node_map_[id]->GetURL(); |
71 page_navigator_->OpenURL( | 93 page_navigator_->OpenURL( |
72 url, GURL(), event_utils::DispositionFromEventFlags(mouse_event_flags), | 94 url, GURL(), event_utils::DispositionFromEventFlags(mouse_event_flags), |
73 PageTransition::AUTO_BOOKMARK); | 95 PageTransition::AUTO_BOOKMARK); |
74 } | 96 } |
75 | 97 |
76 bool BookmarkMenuController::GetDropFormats( | 98 bool BookmarkMenuController::GetDropFormats( |
77 views::MenuItemView* menu, | 99 MenuItemView* menu, |
78 int* formats, | 100 int* formats, |
79 std::set<OSExchangeData::CustomFormat>* custom_formats) { | 101 std::set<OSExchangeData::CustomFormat>* custom_formats) { |
80 *formats = OSExchangeData::URL; | 102 *formats = OSExchangeData::URL; |
81 custom_formats->insert(BookmarkDragData::GetBookmarkCustomFormat()); | 103 custom_formats->insert(BookmarkDragData::GetBookmarkCustomFormat()); |
82 return true; | 104 return true; |
83 } | 105 } |
84 | 106 |
85 bool BookmarkMenuController::AreDropTypesRequired(views::MenuItemView* menu) { | 107 bool BookmarkMenuController::AreDropTypesRequired(MenuItemView* menu) { |
86 return true; | 108 return true; |
87 } | 109 } |
88 | 110 |
89 bool BookmarkMenuController::CanDrop(views::MenuItemView* menu, | 111 bool BookmarkMenuController::CanDrop(MenuItemView* menu, |
90 const OSExchangeData& data) { | 112 const OSExchangeData& data) { |
91 // Only accept drops of 1 node, which is the case for all data dragged from | 113 // Only accept drops of 1 node, which is the case for all data dragged from |
92 // bookmark bar and menus. | 114 // bookmark bar and menus. |
93 | 115 |
94 if (!drop_data_.Read(data) || drop_data_.elements.size() != 1) | 116 if (!drop_data_.Read(data) || drop_data_.elements.size() != 1) |
95 return false; | 117 return false; |
96 | 118 |
97 if (drop_data_.has_single_url()) | 119 if (drop_data_.has_single_url()) |
98 return true; | 120 return true; |
99 | 121 |
100 const BookmarkNode* drag_node = drop_data_.GetFirstNode(profile_); | 122 const BookmarkNode* drag_node = drop_data_.GetFirstNode(profile_); |
101 if (!drag_node) { | 123 if (!drag_node) { |
102 // Dragging a group from another profile, always accept. | 124 // Dragging a group from another profile, always accept. |
103 return true; | 125 return true; |
104 } | 126 } |
105 | 127 |
106 // Drag originated from same profile and is not a URL. Only accept it if | 128 // Drag originated from same profile and is not a URL. Only accept it if |
107 // the dragged node is not a parent of the node menu represents. | 129 // the dragged node is not a parent of the node menu represents. |
108 const BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; | 130 const BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; |
109 DCHECK(drop_node); | 131 DCHECK(drop_node); |
110 while (drop_node && drop_node != drag_node) | 132 while (drop_node && drop_node != drag_node) |
111 drop_node = drop_node->GetParent(); | 133 drop_node = drop_node->GetParent(); |
112 return (drop_node == NULL); | 134 return (drop_node == NULL); |
113 } | 135 } |
114 | 136 |
115 int BookmarkMenuController::GetDropOperation( | 137 int BookmarkMenuController::GetDropOperation( |
116 views::MenuItemView* item, | 138 MenuItemView* item, |
117 const views::DropTargetEvent& event, | 139 const views::DropTargetEvent& event, |
118 DropPosition* position) { | 140 DropPosition* position) { |
119 // Should only get here if we have drop data. | 141 // Should only get here if we have drop data. |
120 DCHECK(drop_data_.is_valid()); | 142 DCHECK(drop_data_.is_valid()); |
121 | 143 |
122 const BookmarkNode* node = menu_id_to_node_map_[item->GetCommand()]; | 144 const BookmarkNode* node = menu_id_to_node_map_[item->GetCommand()]; |
123 const BookmarkNode* drop_parent = node->GetParent(); | 145 const BookmarkNode* drop_parent = node->GetParent(); |
124 int index_to_drop_at = drop_parent->IndexOfChild(node); | 146 int index_to_drop_at = drop_parent->IndexOfChild(node); |
125 if (*position == DROP_AFTER) { | 147 if (*position == DROP_AFTER) { |
126 if (node == profile_->GetBookmarkModel()->other_node()) { | 148 if (node == profile_->GetBookmarkModel()->other_node()) { |
127 // The other folder is shown after all bookmarks on the bookmark bar. | 149 // The other folder is shown after all bookmarks on the bookmark bar. |
128 // Dropping after the other folder makes no sense. | 150 // Dropping after the other folder makes no sense. |
129 *position = DROP_NONE; | 151 *position = DROP_NONE; |
130 } | 152 } |
131 index_to_drop_at++; | 153 index_to_drop_at++; |
132 } else if (*position == DROP_ON) { | 154 } else if (*position == DROP_ON) { |
133 drop_parent = node; | 155 drop_parent = node; |
134 index_to_drop_at = node->GetChildCount(); | 156 index_to_drop_at = node->GetChildCount(); |
135 } | 157 } |
136 DCHECK(drop_parent); | 158 DCHECK(drop_parent); |
137 return bookmark_utils::BookmarkDropOperation( | 159 return bookmark_utils::BookmarkDropOperation( |
138 profile_, event, drop_data_, drop_parent, index_to_drop_at); | 160 profile_, event, drop_data_, drop_parent, index_to_drop_at); |
139 } | 161 } |
140 | 162 |
141 int BookmarkMenuController::OnPerformDrop(views::MenuItemView* menu, | 163 int BookmarkMenuController::OnPerformDrop(MenuItemView* menu, |
142 DropPosition position, | 164 DropPosition position, |
143 const views::DropTargetEvent& event) { | 165 const views::DropTargetEvent& event) { |
144 const BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; | 166 const BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; |
145 DCHECK(drop_node); | 167 DCHECK(drop_node); |
146 BookmarkModel* model = profile_->GetBookmarkModel(); | 168 BookmarkModel* model = profile_->GetBookmarkModel(); |
147 DCHECK(model); | 169 DCHECK(model); |
148 const BookmarkNode* drop_parent = drop_node->GetParent(); | 170 const BookmarkNode* drop_parent = drop_node->GetParent(); |
149 DCHECK(drop_parent); | 171 DCHECK(drop_parent); |
150 int index_to_drop_at = drop_parent->IndexOfChild(drop_node); | 172 int index_to_drop_at = drop_parent->IndexOfChild(drop_node); |
151 if (position == DROP_AFTER) { | 173 if (position == DROP_AFTER) { |
152 index_to_drop_at++; | 174 index_to_drop_at++; |
153 } else if (position == DROP_ON) { | 175 } else if (position == DROP_ON) { |
154 DCHECK(drop_node->is_folder()); | 176 DCHECK(drop_node->is_folder()); |
155 drop_parent = drop_node; | 177 drop_parent = drop_node; |
156 index_to_drop_at = drop_node->GetChildCount(); | 178 index_to_drop_at = drop_node->GetChildCount(); |
157 } | 179 } |
158 | 180 |
159 int result = bookmark_utils::PerformBookmarkDrop( | 181 int result = bookmark_utils::PerformBookmarkDrop( |
160 profile_, drop_data_, drop_parent, index_to_drop_at); | 182 profile_, drop_data_, drop_parent, index_to_drop_at); |
161 if (for_drop_) | 183 if (for_drop_) |
162 delete this; | 184 delete this; |
163 return result; | 185 return result; |
164 } | 186 } |
165 | 187 |
166 bool BookmarkMenuController::ShowContextMenu(views::MenuItemView* source, | 188 bool BookmarkMenuController::ShowContextMenu(MenuItemView* source, |
167 int id, | 189 int id, |
168 int x, | 190 int x, |
169 int y, | 191 int y, |
170 bool is_mouse_gesture) { | 192 bool is_mouse_gesture) { |
171 DCHECK(menu_id_to_node_map_.find(id) != menu_id_to_node_map_.end()); | 193 DCHECK(menu_id_to_node_map_.find(id) != menu_id_to_node_map_.end()); |
172 std::vector<const BookmarkNode*> nodes; | 194 std::vector<const BookmarkNode*> nodes; |
173 nodes.push_back(menu_id_to_node_map_[id]); | 195 nodes.push_back(menu_id_to_node_map_[id]); |
174 context_menu_.reset( | 196 context_menu_.reset( |
175 new BookmarkContextMenu(parent_, | 197 new BookmarkContextMenu(parent_, |
176 profile_, | 198 profile_, |
177 page_navigator_, | 199 page_navigator_, |
178 nodes[0]->GetParent(), | 200 nodes[0]->GetParent(), |
179 nodes, | 201 nodes, |
180 BookmarkContextMenuController::BOOKMARK_BAR)); | 202 BookmarkContextMenuController::BOOKMARK_BAR)); |
181 context_menu_->RunMenuAt(gfx::Point(x, y)); | 203 context_menu_->RunMenuAt(gfx::Point(x, y)); |
182 context_menu_.reset(NULL); | 204 context_menu_.reset(NULL); |
183 return true; | 205 return true; |
184 } | 206 } |
185 | 207 |
186 void BookmarkMenuController::DropMenuClosed(views::MenuItemView* menu) { | 208 void BookmarkMenuController::DropMenuClosed(MenuItemView* menu) { |
187 delete this; | 209 delete this; |
188 } | 210 } |
189 | 211 |
190 bool BookmarkMenuController::CanDrag(views::MenuItemView* menu) { | 212 bool BookmarkMenuController::CanDrag(MenuItemView* menu) { |
191 const BookmarkNode* node = menu_id_to_node_map_[menu->GetCommand()]; | 213 const BookmarkNode* node = menu_id_to_node_map_[menu->GetCommand()]; |
192 // Don't let users drag the other folder. | 214 // Don't let users drag the other folder. |
193 return node->GetParent() != profile_->GetBookmarkModel()->root_node(); | 215 return node->GetParent() != profile_->GetBookmarkModel()->root_node(); |
194 } | 216 } |
195 | 217 |
196 void BookmarkMenuController::WriteDragData(views::MenuItemView* sender, | 218 void BookmarkMenuController::WriteDragData(MenuItemView* sender, |
197 OSExchangeData* data) { | 219 OSExchangeData* data) { |
198 DCHECK(sender && data); | 220 DCHECK(sender && data); |
199 | 221 |
200 UserMetrics::RecordAction(L"BookmarkBar_DragFromFolder", profile_); | 222 UserMetrics::RecordAction(L"BookmarkBar_DragFromFolder", profile_); |
201 | 223 |
202 BookmarkDragData drag_data(menu_id_to_node_map_[sender->GetCommand()]); | 224 BookmarkDragData drag_data(menu_id_to_node_map_[sender->GetCommand()]); |
203 drag_data.Write(profile_, data); | 225 drag_data.Write(profile_, data); |
204 } | 226 } |
205 | 227 |
206 int BookmarkMenuController::GetDragOperations(views::MenuItemView* sender) { | 228 int BookmarkMenuController::GetDragOperations(MenuItemView* sender) { |
207 return bookmark_utils::BookmarkDragOperation( | 229 return bookmark_utils::BookmarkDragOperation( |
208 menu_id_to_node_map_[sender->GetCommand()]); | 230 menu_id_to_node_map_[sender->GetCommand()]); |
209 } | 231 } |
210 | 232 |
| 233 views::MenuItemView* BookmarkMenuController::GetSiblingMenu( |
| 234 views::MenuItemView* menu, |
| 235 const gfx::Point& screen_point, |
| 236 views::MenuItemView::AnchorPosition* anchor, |
| 237 bool* has_mnemonics, |
| 238 views::MenuButton** button) { |
| 239 if (show_other_folder_ || !bookmark_bar_ || for_drop_) |
| 240 return NULL; |
| 241 gfx::Point bookmark_bar_loc(screen_point); |
| 242 views::View::ConvertPointToView(NULL, bookmark_bar_, &bookmark_bar_loc); |
| 243 int start_index; |
| 244 const BookmarkNode* node = |
| 245 bookmark_bar_->GetNodeForButtonAt(bookmark_bar_loc, &start_index); |
| 246 if (!node || !node->is_folder()) |
| 247 return NULL; |
| 248 |
| 249 MenuItemView* alt_menu = node_to_menu_map_[node]; |
| 250 if (!alt_menu) |
| 251 alt_menu = CreateMenu(node, start_index); |
| 252 |
| 253 if (alt_menu) |
| 254 menu_ = alt_menu; |
| 255 |
| 256 *button = bookmark_bar_->GetMenuButtonForNode(node); |
| 257 bookmark_bar_->GetAnchorPositionAndStartIndexForButton( |
| 258 *button, anchor, &start_index); |
| 259 *has_mnemonics = false; |
| 260 return alt_menu; |
| 261 } |
| 262 |
211 void BookmarkMenuController::BookmarkModelChanged() { | 263 void BookmarkMenuController::BookmarkModelChanged() { |
212 menu_->Cancel(); | 264 menu_->Cancel(); |
213 } | 265 } |
214 | 266 |
215 void BookmarkMenuController::BookmarkNodeFavIconLoaded( | 267 void BookmarkMenuController::BookmarkNodeFavIconLoaded( |
216 BookmarkModel* model, const BookmarkNode* node) { | 268 BookmarkModel* model, const BookmarkNode* node) { |
217 if (node_to_menu_id_map_.find(node) != node_to_menu_id_map_.end()) | 269 if (node_to_menu_id_map_.find(node) != node_to_menu_id_map_.end()) |
218 menu_->SetIcon(model->GetFavIcon(node), node_to_menu_id_map_[node]); | 270 menu_->SetIcon(model->GetFavIcon(node), node_to_menu_id_map_[node]); |
219 } | 271 } |
220 | 272 |
221 void BookmarkMenuController::BuildOtherFolderMenu(int* next_menu_id) { | 273 MenuItemView* BookmarkMenuController::CreateMenu(const BookmarkNode* parent, |
| 274 int start_child_index) { |
| 275 MenuItemView* menu = new MenuItemView(this); |
| 276 menu->SetCommand(next_menu_id_++); |
| 277 menu_id_to_node_map_[menu->GetCommand()] = parent; |
| 278 menu->set_has_icons(true); |
| 279 BuildMenu(parent, start_child_index, menu, &next_menu_id_); |
| 280 if (show_other_folder_) |
| 281 BuildOtherFolderMenu(menu, &next_menu_id_); |
| 282 node_to_menu_map_[parent] = menu; |
| 283 return menu; |
| 284 } |
| 285 |
| 286 void BookmarkMenuController::BuildOtherFolderMenu( |
| 287 MenuItemView* menu, int* next_menu_id) { |
222 const BookmarkNode* other_folder = profile_->GetBookmarkModel()->other_node(); | 288 const BookmarkNode* other_folder = profile_->GetBookmarkModel()->other_node(); |
223 int id = *next_menu_id; | 289 int id = *next_menu_id; |
224 (*next_menu_id)++; | 290 (*next_menu_id)++; |
225 SkBitmap* folder_icon = ResourceBundle::GetSharedInstance(). | 291 SkBitmap* folder_icon = ResourceBundle::GetSharedInstance(). |
226 GetBitmapNamed(IDR_BOOKMARK_BAR_FOLDER); | 292 GetBitmapNamed(IDR_BOOKMARK_BAR_FOLDER); |
227 views::MenuItemView* submenu = menu_->AppendSubMenuWithIcon( | 293 MenuItemView* submenu = menu->AppendSubMenuWithIcon( |
228 id, l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED), *folder_icon); | 294 id, l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED), *folder_icon); |
229 BuildMenu(other_folder, 0, submenu, next_menu_id); | 295 BuildMenu(other_folder, 0, submenu, next_menu_id); |
230 menu_id_to_node_map_[id] = other_folder; | 296 menu_id_to_node_map_[id] = other_folder; |
231 } | 297 } |
232 | 298 |
233 void BookmarkMenuController::BuildMenu(const BookmarkNode* parent, | 299 void BookmarkMenuController::BuildMenu(const BookmarkNode* parent, |
234 int start_child_index, | 300 int start_child_index, |
235 views::MenuItemView* menu, | 301 MenuItemView* menu, |
236 int* next_menu_id) { | 302 int* next_menu_id) { |
237 DCHECK(!parent->GetChildCount() || | 303 DCHECK(!parent->GetChildCount() || |
238 start_child_index < parent->GetChildCount()); | 304 start_child_index < parent->GetChildCount()); |
239 for (int i = start_child_index; i < parent->GetChildCount(); ++i) { | 305 for (int i = start_child_index; i < parent->GetChildCount(); ++i) { |
240 const BookmarkNode* node = parent->GetChild(i); | 306 const BookmarkNode* node = parent->GetChild(i); |
241 int id = *next_menu_id; | 307 int id = *next_menu_id; |
242 | 308 |
243 (*next_menu_id)++; | 309 (*next_menu_id)++; |
244 if (node->is_url()) { | 310 if (node->is_url()) { |
245 SkBitmap icon = profile_->GetBookmarkModel()->GetFavIcon(node); | 311 SkBitmap icon = profile_->GetBookmarkModel()->GetFavIcon(node); |
246 if (icon.width() == 0) { | 312 if (icon.width() == 0) { |
247 icon = *ResourceBundle::GetSharedInstance(). | 313 icon = *ResourceBundle::GetSharedInstance(). |
248 GetBitmapNamed(IDR_DEFAULT_FAVICON); | 314 GetBitmapNamed(IDR_DEFAULT_FAVICON); |
249 } | 315 } |
250 menu->AppendMenuItemWithIcon(id, node->GetTitle(), icon); | 316 menu->AppendMenuItemWithIcon(id, node->GetTitle(), icon); |
251 node_to_menu_id_map_[node] = id; | 317 node_to_menu_id_map_[node] = id; |
252 } else if (node->is_folder()) { | 318 } else if (node->is_folder()) { |
253 SkBitmap* folder_icon = ResourceBundle::GetSharedInstance(). | 319 SkBitmap* folder_icon = ResourceBundle::GetSharedInstance(). |
254 GetBitmapNamed(IDR_BOOKMARK_BAR_FOLDER); | 320 GetBitmapNamed(IDR_BOOKMARK_BAR_FOLDER); |
255 views::MenuItemView* submenu = | 321 MenuItemView* submenu = |
256 menu->AppendSubMenuWithIcon(id, node->GetTitle(), *folder_icon); | 322 menu->AppendSubMenuWithIcon(id, node->GetTitle(), *folder_icon); |
257 BuildMenu(node, 0, submenu, next_menu_id); | 323 BuildMenu(node, 0, submenu, next_menu_id); |
258 } else { | 324 } else { |
259 NOTREACHED(); | 325 NOTREACHED(); |
260 } | 326 } |
261 menu_id_to_node_map_[id] = node; | 327 menu_id_to_node_map_[id] = node; |
262 } | 328 } |
263 } | 329 } |
264 | 330 |
265 BookmarkMenuController::~BookmarkMenuController() { | 331 BookmarkMenuController::~BookmarkMenuController() { |
266 profile_->GetBookmarkModel()->RemoveObserver(this); | 332 profile_->GetBookmarkModel()->RemoveObserver(this); |
267 if (observer_) | 333 if (observer_) |
268 observer_->BookmarkMenuDeleted(this); | 334 observer_->BookmarkMenuDeleted(this); |
| 335 STLDeleteValues(&node_to_menu_map_); |
269 } | 336 } |
OLD | NEW |