| 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_controller_views.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_stats.h" | 10 #include "chrome/browser/bookmarks/bookmark_stats.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 27 | 27 |
| 28 using base::UserMetricsAction; | 28 using base::UserMetricsAction; |
| 29 using content::PageNavigator; | 29 using content::PageNavigator; |
| 30 using views::MenuItemView; | 30 using views::MenuItemView; |
| 31 | 31 |
| 32 BookmarkMenuController::BookmarkMenuController(Browser* browser, | 32 BookmarkMenuController::BookmarkMenuController(Browser* browser, |
| 33 PageNavigator* page_navigator, | 33 PageNavigator* page_navigator, |
| 34 views::Widget* parent, | 34 views::Widget* parent, |
| 35 const BookmarkNode* node, | 35 const BookmarkNode* node, |
| 36 int start_child_index) | 36 int start_child_index, |
| 37 bool for_drop) |
| 37 : menu_delegate_( | 38 : menu_delegate_( |
| 38 new BookmarkMenuDelegate(browser, page_navigator, parent, 1, | 39 new BookmarkMenuDelegate(browser, page_navigator, parent, 1, |
| 39 kint32max)), | 40 kint32max)), |
| 40 node_(node), | 41 node_(node), |
| 41 observer_(NULL), | 42 observer_(NULL), |
| 42 for_drop_(false), | 43 for_drop_(for_drop), |
| 43 bookmark_bar_(NULL) { | 44 bookmark_bar_(NULL) { |
| 44 menu_delegate_->Init(this, NULL, node, start_child_index, | 45 menu_delegate_->Init(this, NULL, node, start_child_index, |
| 45 BookmarkMenuDelegate::HIDE_PERMANENT_FOLDERS, | 46 BookmarkMenuDelegate::HIDE_PERMANENT_FOLDERS, |
| 46 BOOKMARK_LAUNCH_LOCATION_BAR_SUBFOLDER); | 47 BOOKMARK_LAUNCH_LOCATION_BAR_SUBFOLDER); |
| 47 menu_runner_.reset(new views::MenuRunner(menu_delegate_->menu())); | 48 menu_runner_.reset(new views::MenuRunner( |
| 49 menu_delegate_->menu(), for_drop ? views::MenuRunner::FOR_DROP : 0)); |
| 48 } | 50 } |
| 49 | 51 |
| 50 void BookmarkMenuController::RunMenuAt(BookmarkBarView* bookmark_bar, | 52 void BookmarkMenuController::RunMenuAt(BookmarkBarView* bookmark_bar) { |
| 51 bool for_drop) { | |
| 52 bookmark_bar_ = bookmark_bar; | 53 bookmark_bar_ = bookmark_bar; |
| 53 views::MenuButton* menu_button = bookmark_bar_->GetMenuButtonForNode(node_); | 54 views::MenuButton* menu_button = bookmark_bar_->GetMenuButtonForNode(node_); |
| 54 DCHECK(menu_button); | 55 DCHECK(menu_button); |
| 55 views::MenuAnchorPosition anchor; | 56 views::MenuAnchorPosition anchor; |
| 56 bookmark_bar_->GetAnchorPositionForButton(menu_button, &anchor); | 57 bookmark_bar_->GetAnchorPositionForButton(menu_button, &anchor); |
| 57 gfx::Point screen_loc; | 58 gfx::Point screen_loc; |
| 58 views::View::ConvertPointToScreen(menu_button, &screen_loc); | 59 views::View::ConvertPointToScreen(menu_button, &screen_loc); |
| 59 // Subtract 1 from the height to make the popup flush with the button border. | 60 // Subtract 1 from the height to make the popup flush with the button border. |
| 60 gfx::Rect bounds(screen_loc.x(), screen_loc.y(), menu_button->width(), | 61 gfx::Rect bounds(screen_loc.x(), screen_loc.y(), menu_button->width(), |
| 61 menu_button->height() - 1); | 62 menu_button->height() - 1); |
| 62 for_drop_ = for_drop; | |
| 63 menu_delegate_->GetBookmarkModel()->AddObserver(this); | 63 menu_delegate_->GetBookmarkModel()->AddObserver(this); |
| 64 // We only delete ourself after the menu completes, so we can safely ignore | 64 // We only delete ourself after the menu completes, so we can safely ignore |
| 65 // the return value. | 65 // the return value. |
| 66 ignore_result(menu_runner_->RunMenuAt(menu_delegate_->parent(), menu_button, | 66 ignore_result(menu_runner_->RunMenuAt(menu_delegate_->parent(), |
| 67 bounds, anchor, ui::MENU_SOURCE_NONE, | 67 menu_button, |
| 68 for_drop ? views::MenuRunner::FOR_DROP : 0)); | 68 bounds, |
| 69 if (!for_drop) | 69 anchor, |
| 70 ui::MENU_SOURCE_NONE)); |
| 71 if (!for_drop_) |
| 70 delete this; | 72 delete this; |
| 71 } | 73 } |
| 72 | 74 |
| 73 void BookmarkMenuController::Cancel() { | 75 void BookmarkMenuController::Cancel() { |
| 74 menu_delegate_->menu()->Cancel(); | 76 menu_delegate_->menu()->Cancel(); |
| 75 } | 77 } |
| 76 | 78 |
| 77 MenuItemView* BookmarkMenuController::menu() const { | 79 MenuItemView* BookmarkMenuController::menu() const { |
| 78 return menu_delegate_->menu(); | 80 return menu_delegate_->menu(); |
| 79 } | 81 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 void BookmarkMenuController::BookmarkModelChanged() { | 193 void BookmarkMenuController::BookmarkModelChanged() { |
| 192 if (!menu_delegate_->is_mutating_model()) | 194 if (!menu_delegate_->is_mutating_model()) |
| 193 menu()->Cancel(); | 195 menu()->Cancel(); |
| 194 } | 196 } |
| 195 | 197 |
| 196 BookmarkMenuController::~BookmarkMenuController() { | 198 BookmarkMenuController::~BookmarkMenuController() { |
| 197 menu_delegate_->GetBookmarkModel()->RemoveObserver(this); | 199 menu_delegate_->GetBookmarkModel()->RemoveObserver(this); |
| 198 if (observer_) | 200 if (observer_) |
| 199 observer_->BookmarkMenuControllerDeleted(this); | 201 observer_->BookmarkMenuControllerDeleted(this); |
| 200 } | 202 } |
| OLD | NEW |