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/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/bookmarks/bookmark_stats.h" | 9 #include "chrome/browser/bookmarks/bookmark_stats.h" |
10 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 10 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 int start_child_index, | 31 int start_child_index, |
32 bool for_drop) | 32 bool for_drop) |
33 : menu_delegate_(new BookmarkMenuDelegate(browser, page_navigator, parent)), | 33 : menu_delegate_(new BookmarkMenuDelegate(browser, page_navigator, parent)), |
34 node_(node), | 34 node_(node), |
35 observer_(NULL), | 35 observer_(NULL), |
36 for_drop_(for_drop), | 36 for_drop_(for_drop), |
37 bookmark_bar_(NULL) { | 37 bookmark_bar_(NULL) { |
38 menu_delegate_->Init(this, NULL, node, start_child_index, | 38 menu_delegate_->Init(this, NULL, node, start_child_index, |
39 BookmarkMenuDelegate::HIDE_PERMANENT_FOLDERS, | 39 BookmarkMenuDelegate::HIDE_PERMANENT_FOLDERS, |
40 BOOKMARK_LAUNCH_LOCATION_BAR_SUBFOLDER); | 40 BOOKMARK_LAUNCH_LOCATION_BAR_SUBFOLDER); |
41 int run_type = views::MenuRunner::ASYNC; | 41 int run_type = 0; |
42 if (for_drop) | 42 if (for_drop) |
43 run_type |= views::MenuRunner::FOR_DROP; | 43 run_type |= views::MenuRunner::FOR_DROP; |
44 menu_runner_.reset(new views::MenuRunner(menu_delegate_->menu(), run_type)); | 44 menu_runner_.reset(new views::MenuRunner(menu_delegate_->menu(), run_type)); |
45 } | 45 } |
46 | 46 |
47 void BookmarkMenuController::RunMenuAt(BookmarkBarView* bookmark_bar) { | 47 void BookmarkMenuController::RunMenuAt(BookmarkBarView* bookmark_bar) { |
48 bookmark_bar_ = bookmark_bar; | 48 bookmark_bar_ = bookmark_bar; |
49 views::MenuButton* menu_button = bookmark_bar_->GetMenuButtonForNode(node_); | 49 views::MenuButton* menu_button = bookmark_bar_->GetMenuButtonForNode(node_); |
50 DCHECK(menu_button); | 50 DCHECK(menu_button); |
51 views::MenuAnchorPosition anchor; | 51 views::MenuAnchorPosition anchor; |
52 bookmark_bar_->GetAnchorPositionForButton(menu_button, &anchor); | 52 bookmark_bar_->GetAnchorPositionForButton(menu_button, &anchor); |
53 gfx::Point screen_loc; | 53 gfx::Point screen_loc; |
54 views::View::ConvertPointToScreen(menu_button, &screen_loc); | 54 views::View::ConvertPointToScreen(menu_button, &screen_loc); |
55 // Subtract 1 from the height to make the popup flush with the button border. | 55 // Subtract 1 from the height to make the popup flush with the button border. |
56 gfx::Rect bounds(screen_loc.x(), screen_loc.y(), menu_button->width(), | 56 gfx::Rect bounds(screen_loc.x(), screen_loc.y(), menu_button->width(), |
57 menu_button->height() - 1); | 57 menu_button->height() - 1); |
58 menu_delegate_->GetBookmarkModel()->AddObserver(this); | 58 menu_delegate_->GetBookmarkModel()->AddObserver(this); |
59 // We only delete ourself after the menu completes, so we can safely ignore | 59 // We only delete ourself after the menu completes, so we can safely ignore |
60 // the return value. | 60 // the return value. |
61 ignore_result(menu_runner_->RunMenuAt(menu_delegate_->parent(), | 61 menu_runner_->RunMenuAt(menu_delegate_->parent(), menu_button, bounds, anchor, |
62 menu_button, | 62 ui::MENU_SOURCE_NONE); |
63 bounds, | |
64 anchor, | |
65 ui::MENU_SOURCE_NONE)); | |
66 } | 63 } |
67 | 64 |
68 void BookmarkMenuController::Cancel() { | 65 void BookmarkMenuController::Cancel() { |
69 menu_delegate_->menu()->Cancel(); | 66 menu_delegate_->menu()->Cancel(); |
70 } | 67 } |
71 | 68 |
72 MenuItemView* BookmarkMenuController::menu() const { | 69 MenuItemView* BookmarkMenuController::menu() const { |
73 return menu_delegate_->menu(); | 70 return menu_delegate_->menu(); |
74 } | 71 } |
75 | 72 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 142 |
146 void BookmarkMenuController::WriteDragData(MenuItemView* sender, | 143 void BookmarkMenuController::WriteDragData(MenuItemView* sender, |
147 ui::OSExchangeData* data) { | 144 ui::OSExchangeData* data) { |
148 return menu_delegate_->WriteDragData(sender, data); | 145 return menu_delegate_->WriteDragData(sender, data); |
149 } | 146 } |
150 | 147 |
151 int BookmarkMenuController::GetDragOperations(MenuItemView* sender) { | 148 int BookmarkMenuController::GetDragOperations(MenuItemView* sender) { |
152 return menu_delegate_->GetDragOperations(sender); | 149 return menu_delegate_->GetDragOperations(sender); |
153 } | 150 } |
154 | 151 |
155 void BookmarkMenuController::OnMenuClosed(views::MenuItemView* menu, | 152 void BookmarkMenuController::OnMenuClosed(views::MenuItemView* menu) { |
156 views::MenuRunner::RunResult result) { | |
157 delete this; | 153 delete this; |
158 } | 154 } |
159 | 155 |
160 views::MenuItemView* BookmarkMenuController::GetSiblingMenu( | 156 views::MenuItemView* BookmarkMenuController::GetSiblingMenu( |
161 views::MenuItemView* menu, | 157 views::MenuItemView* menu, |
162 const gfx::Point& screen_point, | 158 const gfx::Point& screen_point, |
163 views::MenuAnchorPosition* anchor, | 159 views::MenuAnchorPosition* anchor, |
164 bool* has_mnemonics, | 160 bool* has_mnemonics, |
165 views::MenuButton** button) { | 161 views::MenuButton** button) { |
166 if (!bookmark_bar_ || for_drop_) | 162 if (!bookmark_bar_ || for_drop_) |
(...skipping 24 matching lines...) Expand all Loading... |
191 void BookmarkMenuController::BookmarkModelChanged() { | 187 void BookmarkMenuController::BookmarkModelChanged() { |
192 if (!menu_delegate_->is_mutating_model()) | 188 if (!menu_delegate_->is_mutating_model()) |
193 menu()->Cancel(); | 189 menu()->Cancel(); |
194 } | 190 } |
195 | 191 |
196 BookmarkMenuController::~BookmarkMenuController() { | 192 BookmarkMenuController::~BookmarkMenuController() { |
197 menu_delegate_->GetBookmarkModel()->RemoveObserver(this); | 193 menu_delegate_->GetBookmarkModel()->RemoveObserver(this); |
198 if (observer_) | 194 if (observer_) |
199 observer_->BookmarkMenuControllerDeleted(this); | 195 observer_->BookmarkMenuControllerDeleted(this); |
200 } | 196 } |
OLD | NEW |