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" |
11 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 11 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
12 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_controller_observer.h" | 12 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_controller_observer.h" |
13 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" | 13 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "components/bookmarks/core/browser/bookmark_model.h" | 15 #include "components/bookmarks/core/browser/bookmark_model.h" |
16 #include "content/public/browser/page_navigator.h" | 16 #include "content/public/browser/page_navigator.h" |
17 #include "content/public/browser/user_metrics.h" | 17 #include "content/public/browser/user_metrics.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
20 #include "grit/ui_resources.h" | 20 #include "grit/ui_resources.h" |
21 #include "ui/base/dragdrop/os_exchange_data.h" | 21 #include "ui/base/dragdrop/os_exchange_data.h" |
22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/views/controls/button/menu_button.h" | 23 #include "ui/views/controls/button/menu_button.h" |
| 24 #include "ui/views/controls/menu/menu_item_view.h" |
24 #include "ui/views/controls/menu/menu_runner.h" | 25 #include "ui/views/controls/menu/menu_runner.h" |
25 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
26 | 27 |
27 using base::UserMetricsAction; | 28 using base::UserMetricsAction; |
28 using content::PageNavigator; | 29 using content::PageNavigator; |
29 using views::MenuItemView; | 30 using views::MenuItemView; |
30 | 31 |
31 BookmarkMenuController::BookmarkMenuController(Browser* browser, | 32 BookmarkMenuController::BookmarkMenuController(Browser* browser, |
32 PageNavigator* page_navigator, | 33 PageNavigator* page_navigator, |
33 views::Widget* parent, | 34 views::Widget* parent, |
(...skipping 10 matching lines...) Expand all Loading... |
44 BookmarkMenuDelegate::HIDE_PERMANENT_FOLDERS, | 45 BookmarkMenuDelegate::HIDE_PERMANENT_FOLDERS, |
45 BOOKMARK_LAUNCH_LOCATION_BAR_SUBFOLDER); | 46 BOOKMARK_LAUNCH_LOCATION_BAR_SUBFOLDER); |
46 menu_runner_.reset(new views::MenuRunner(menu_delegate_->menu())); | 47 menu_runner_.reset(new views::MenuRunner(menu_delegate_->menu())); |
47 } | 48 } |
48 | 49 |
49 void BookmarkMenuController::RunMenuAt(BookmarkBarView* bookmark_bar, | 50 void BookmarkMenuController::RunMenuAt(BookmarkBarView* bookmark_bar, |
50 bool for_drop) { | 51 bool for_drop) { |
51 bookmark_bar_ = bookmark_bar; | 52 bookmark_bar_ = bookmark_bar; |
52 views::MenuButton* menu_button = bookmark_bar_->GetMenuButtonForNode(node_); | 53 views::MenuButton* menu_button = bookmark_bar_->GetMenuButtonForNode(node_); |
53 DCHECK(menu_button); | 54 DCHECK(menu_button); |
54 MenuItemView::AnchorPosition anchor; | 55 views::MenuAnchorPosition anchor; |
55 bookmark_bar_->GetAnchorPositionForButton(menu_button, &anchor); | 56 bookmark_bar_->GetAnchorPositionForButton(menu_button, &anchor); |
56 gfx::Point screen_loc; | 57 gfx::Point screen_loc; |
57 views::View::ConvertPointToScreen(menu_button, &screen_loc); | 58 views::View::ConvertPointToScreen(menu_button, &screen_loc); |
58 // Subtract 1 from the height to make the popup flush with the button border. | 59 // Subtract 1 from the height to make the popup flush with the button border. |
59 gfx::Rect bounds(screen_loc.x(), screen_loc.y(), menu_button->width(), | 60 gfx::Rect bounds(screen_loc.x(), screen_loc.y(), menu_button->width(), |
60 menu_button->height() - 1); | 61 menu_button->height() - 1); |
61 for_drop_ = for_drop; | 62 for_drop_ = for_drop; |
62 menu_delegate_->GetBookmarkModel()->AddObserver(this); | 63 menu_delegate_->GetBookmarkModel()->AddObserver(this); |
63 // 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 |
64 // the return value. | 65 // the return value. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return menu_delegate_->WriteDragData(sender, data); | 157 return menu_delegate_->WriteDragData(sender, data); |
157 } | 158 } |
158 | 159 |
159 int BookmarkMenuController::GetDragOperations(MenuItemView* sender) { | 160 int BookmarkMenuController::GetDragOperations(MenuItemView* sender) { |
160 return menu_delegate_->GetDragOperations(sender); | 161 return menu_delegate_->GetDragOperations(sender); |
161 } | 162 } |
162 | 163 |
163 views::MenuItemView* BookmarkMenuController::GetSiblingMenu( | 164 views::MenuItemView* BookmarkMenuController::GetSiblingMenu( |
164 views::MenuItemView* menu, | 165 views::MenuItemView* menu, |
165 const gfx::Point& screen_point, | 166 const gfx::Point& screen_point, |
166 views::MenuItemView::AnchorPosition* anchor, | 167 views::MenuAnchorPosition* anchor, |
167 bool* has_mnemonics, | 168 bool* has_mnemonics, |
168 views::MenuButton** button) { | 169 views::MenuButton** button) { |
169 if (!bookmark_bar_ || for_drop_) | 170 if (!bookmark_bar_ || for_drop_) |
170 return NULL; | 171 return NULL; |
171 gfx::Point bookmark_bar_loc(screen_point); | 172 gfx::Point bookmark_bar_loc(screen_point); |
172 views::View::ConvertPointFromScreen(bookmark_bar_, &bookmark_bar_loc); | 173 views::View::ConvertPointFromScreen(bookmark_bar_, &bookmark_bar_loc); |
173 int start_index; | 174 int start_index; |
174 const BookmarkNode* node = bookmark_bar_->GetNodeForButtonAtModelIndex( | 175 const BookmarkNode* node = bookmark_bar_->GetNodeForButtonAtModelIndex( |
175 bookmark_bar_loc, &start_index); | 176 bookmark_bar_loc, &start_index); |
176 if (!node || !node->is_folder()) | 177 if (!node || !node->is_folder()) |
(...skipping 13 matching lines...) Expand all Loading... |
190 void BookmarkMenuController::BookmarkModelChanged() { | 191 void BookmarkMenuController::BookmarkModelChanged() { |
191 if (!menu_delegate_->is_mutating_model()) | 192 if (!menu_delegate_->is_mutating_model()) |
192 menu()->Cancel(); | 193 menu()->Cancel(); |
193 } | 194 } |
194 | 195 |
195 BookmarkMenuController::~BookmarkMenuController() { | 196 BookmarkMenuController::~BookmarkMenuController() { |
196 menu_delegate_->GetBookmarkModel()->RemoveObserver(this); | 197 menu_delegate_->GetBookmarkModel()->RemoveObserver(this); |
197 if (observer_) | 198 if (observer_) |
198 observer_->BookmarkMenuControllerDeleted(this); | 199 observer_->BookmarkMenuControllerDeleted(this); |
199 } | 200 } |
OLD | NEW |