Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: chrome/browser/views/bookmark_menu_controller_views.cc

Issue 2853024: Remove the bookmark menu. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/stl_util-inl.h"
(...skipping 11 matching lines...) Expand all
22 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
23 #include "views/controls/button/menu_button.h" 23 #include "views/controls/button/menu_button.h"
24 24
25 using views::MenuItemView; 25 using views::MenuItemView;
26 26
27 BookmarkMenuController::BookmarkMenuController(Browser* browser, 27 BookmarkMenuController::BookmarkMenuController(Browser* browser,
28 Profile* profile, 28 Profile* profile,
29 PageNavigator* navigator, 29 PageNavigator* navigator,
30 gfx::NativeWindow parent, 30 gfx::NativeWindow parent,
31 const BookmarkNode* node, 31 const BookmarkNode* node,
32 int start_child_index, 32 int start_child_index)
33 bool show_other_folder)
34 : browser_(browser), 33 : browser_(browser),
35 profile_(profile), 34 profile_(profile),
36 page_navigator_(navigator), 35 page_navigator_(navigator),
37 parent_(parent), 36 parent_(parent),
38 node_(node), 37 node_(node),
39 menu_(NULL), 38 menu_(NULL),
40 observer_(NULL), 39 observer_(NULL),
41 for_drop_(false), 40 for_drop_(false),
42 show_other_folder_(show_other_folder),
43 bookmark_bar_(NULL), 41 bookmark_bar_(NULL),
44 next_menu_id_(1) { 42 next_menu_id_(1) {
45 menu_ = CreateMenu(node, start_child_index); 43 menu_ = CreateMenu(node, start_child_index);
46 } 44 }
47 45
48 void BookmarkMenuController::RunMenuAt(BookmarkBarView* bookmark_bar, 46 void BookmarkMenuController::RunMenuAt(BookmarkBarView* bookmark_bar,
49 bool for_drop) { 47 bool for_drop) {
50 bookmark_bar_ = bookmark_bar; 48 bookmark_bar_ = bookmark_bar;
51 views::MenuButton* menu_button = bookmark_bar_->GetMenuButtonForNode(node_); 49 views::MenuButton* menu_button = bookmark_bar_->GetMenuButtonForNode(node_);
52 DCHECK(menu_button); 50 DCHECK(menu_button);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 MenuItemView* item, 143 MenuItemView* item,
146 const views::DropTargetEvent& event, 144 const views::DropTargetEvent& event,
147 DropPosition* position) { 145 DropPosition* position) {
148 // Should only get here if we have drop data. 146 // Should only get here if we have drop data.
149 DCHECK(drop_data_.is_valid()); 147 DCHECK(drop_data_.is_valid());
150 148
151 const BookmarkNode* node = menu_id_to_node_map_[item->GetCommand()]; 149 const BookmarkNode* node = menu_id_to_node_map_[item->GetCommand()];
152 const BookmarkNode* drop_parent = node->GetParent(); 150 const BookmarkNode* drop_parent = node->GetParent();
153 int index_to_drop_at = drop_parent->IndexOfChild(node); 151 int index_to_drop_at = drop_parent->IndexOfChild(node);
154 if (*position == DROP_AFTER) { 152 if (*position == DROP_AFTER) {
155 if (node == profile_->GetBookmarkModel()->other_node()) {
156 // The other folder is shown after all bookmarks on the bookmark bar.
157 // Dropping after the other folder makes no sense.
158 *position = DROP_NONE;
159 }
160 index_to_drop_at++; 153 index_to_drop_at++;
161 } else if (*position == DROP_ON) { 154 } else if (*position == DROP_ON) {
162 drop_parent = node; 155 drop_parent = node;
163 index_to_drop_at = node->GetChildCount(); 156 index_to_drop_at = node->GetChildCount();
164 } 157 }
165 DCHECK(drop_parent); 158 DCHECK(drop_parent);
166 return bookmark_utils::BookmarkDropOperation( 159 return bookmark_utils::BookmarkDropOperation(
167 profile_, event, drop_data_, drop_parent, index_to_drop_at); 160 profile_, event, drop_data_, drop_parent, index_to_drop_at);
168 } 161 }
169 162
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 context_menu_->RunMenuAt(p); 203 context_menu_->RunMenuAt(p);
211 context_menu_.reset(NULL); 204 context_menu_.reset(NULL);
212 return true; 205 return true;
213 } 206 }
214 207
215 void BookmarkMenuController::DropMenuClosed(MenuItemView* menu) { 208 void BookmarkMenuController::DropMenuClosed(MenuItemView* menu) {
216 delete this; 209 delete this;
217 } 210 }
218 211
219 bool BookmarkMenuController::CanDrag(MenuItemView* menu) { 212 bool BookmarkMenuController::CanDrag(MenuItemView* menu) {
220 const BookmarkNode* node = menu_id_to_node_map_[menu->GetCommand()]; 213 return true;
221 // Don't let users drag the other folder.
222 return node->GetParent() != profile_->GetBookmarkModel()->root_node();
223 } 214 }
224 215
225 void BookmarkMenuController::WriteDragData(MenuItemView* sender, 216 void BookmarkMenuController::WriteDragData(MenuItemView* sender,
226 OSExchangeData* data) { 217 OSExchangeData* data) {
227 DCHECK(sender && data); 218 DCHECK(sender && data);
228 219
229 UserMetrics::RecordAction(UserMetricsAction("BookmarkBar_DragFromFolder"), 220 UserMetrics::RecordAction(UserMetricsAction("BookmarkBar_DragFromFolder"),
230 profile_); 221 profile_);
231 222
232 BookmarkDragData drag_data(menu_id_to_node_map_[sender->GetCommand()]); 223 BookmarkDragData drag_data(menu_id_to_node_map_[sender->GetCommand()]);
233 drag_data.Write(profile_, data); 224 drag_data.Write(profile_, data);
234 } 225 }
235 226
236 int BookmarkMenuController::GetDragOperations(MenuItemView* sender) { 227 int BookmarkMenuController::GetDragOperations(MenuItemView* sender) {
237 return bookmark_utils::BookmarkDragOperation( 228 return bookmark_utils::BookmarkDragOperation(
238 menu_id_to_node_map_[sender->GetCommand()]); 229 menu_id_to_node_map_[sender->GetCommand()]);
239 } 230 }
240 231
241 views::MenuItemView* BookmarkMenuController::GetSiblingMenu( 232 views::MenuItemView* BookmarkMenuController::GetSiblingMenu(
242 views::MenuItemView* menu, 233 views::MenuItemView* menu,
243 const gfx::Point& screen_point, 234 const gfx::Point& screen_point,
244 views::MenuItemView::AnchorPosition* anchor, 235 views::MenuItemView::AnchorPosition* anchor,
245 bool* has_mnemonics, 236 bool* has_mnemonics,
246 views::MenuButton** button) { 237 views::MenuButton** button) {
247 if (show_other_folder_ || !bookmark_bar_ || for_drop_) 238 if (!bookmark_bar_ || for_drop_)
248 return NULL; 239 return NULL;
249 gfx::Point bookmark_bar_loc(screen_point); 240 gfx::Point bookmark_bar_loc(screen_point);
250 views::View::ConvertPointToView(NULL, bookmark_bar_, &bookmark_bar_loc); 241 views::View::ConvertPointToView(NULL, bookmark_bar_, &bookmark_bar_loc);
251 int start_index; 242 int start_index;
252 const BookmarkNode* node = 243 const BookmarkNode* node =
253 bookmark_bar_->GetNodeForButtonAt(bookmark_bar_loc, &start_index); 244 bookmark_bar_->GetNodeForButtonAt(bookmark_bar_loc, &start_index);
254 if (!node || !node->is_folder()) 245 if (!node || !node->is_folder())
255 return NULL; 246 return NULL;
256 247
257 MenuItemView* alt_menu = node_to_menu_map_[node]; 248 MenuItemView* alt_menu = node_to_menu_map_[node];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 profile_->GetBookmarkModel()->AddObserver(this); 292 profile_->GetBookmarkModel()->AddObserver(this);
302 } 293 }
303 294
304 MenuItemView* BookmarkMenuController::CreateMenu(const BookmarkNode* parent, 295 MenuItemView* BookmarkMenuController::CreateMenu(const BookmarkNode* parent,
305 int start_child_index) { 296 int start_child_index) {
306 MenuItemView* menu = new MenuItemView(this); 297 MenuItemView* menu = new MenuItemView(this);
307 menu->SetCommand(next_menu_id_++); 298 menu->SetCommand(next_menu_id_++);
308 menu_id_to_node_map_[menu->GetCommand()] = parent; 299 menu_id_to_node_map_[menu->GetCommand()] = parent;
309 menu->set_has_icons(true); 300 menu->set_has_icons(true);
310 BuildMenu(parent, start_child_index, menu, &next_menu_id_); 301 BuildMenu(parent, start_child_index, menu, &next_menu_id_);
311 if (show_other_folder_)
312 BuildOtherFolderMenu(menu, &next_menu_id_);
313 node_to_menu_map_[parent] = menu; 302 node_to_menu_map_[parent] = menu;
314 return menu; 303 return menu;
315 } 304 }
316 305
317 void BookmarkMenuController::BuildOtherFolderMenu(
318 MenuItemView* menu, int* next_menu_id) {
319 const BookmarkNode* other_folder = profile_->GetBookmarkModel()->other_node();
320 int id = *next_menu_id;
321 (*next_menu_id)++;
322 SkBitmap* folder_icon = ResourceBundle::GetSharedInstance().
323 GetBitmapNamed(IDR_BOOKMARK_BAR_FOLDER);
324 MenuItemView* submenu = menu->AppendSubMenuWithIcon(
325 id, l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED), *folder_icon);
326 BuildMenu(other_folder, 0, submenu, next_menu_id);
327 menu_id_to_node_map_[id] = other_folder;
328 }
329
330 void BookmarkMenuController::BuildMenu(const BookmarkNode* parent, 306 void BookmarkMenuController::BuildMenu(const BookmarkNode* parent,
331 int start_child_index, 307 int start_child_index,
332 MenuItemView* menu, 308 MenuItemView* menu,
333 int* next_menu_id) { 309 int* next_menu_id) {
334 DCHECK(!parent->GetChildCount() || 310 DCHECK(!parent->GetChildCount() ||
335 start_child_index < parent->GetChildCount()); 311 start_child_index < parent->GetChildCount());
336 for (int i = start_child_index; i < parent->GetChildCount(); ++i) { 312 for (int i = start_child_index; i < parent->GetChildCount(); ++i) {
337 const BookmarkNode* node = parent->GetChild(i); 313 const BookmarkNode* node = parent->GetChild(i);
338 int id = *next_menu_id; 314 int id = *next_menu_id;
339 315
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 break; 398 break;
423 } 399 }
424 } 400 }
425 if (ancestor_removed) { 401 if (ancestor_removed) {
426 node_to_menu_id_map_.erase(i++); 402 node_to_menu_id_map_.erase(i++);
427 } else { 403 } else {
428 ++i; 404 ++i;
429 } 405 }
430 } 406 }
431 } 407 }
OLDNEW
« no previous file with comments | « chrome/browser/views/bookmark_menu_controller_views.h ('k') | chrome/browser/views/toolbar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698