OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/app_menu.h" | 5 #include "chrome/browser/ui/views/toolbar/app_menu.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 feedback_menu_item_(nullptr), | 796 feedback_menu_item_(nullptr), |
797 screenshot_menu_item_(nullptr), | 797 screenshot_menu_item_(nullptr), |
798 extension_toolbar_(nullptr), | 798 extension_toolbar_(nullptr), |
799 run_flags_(run_flags) { | 799 run_flags_(run_flags) { |
800 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | 800 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
801 content::Source<Profile>(browser_->profile())); | 801 content::Source<Profile>(browser_->profile())); |
802 } | 802 } |
803 | 803 |
804 AppMenu::~AppMenu() { | 804 AppMenu::~AppMenu() { |
805 if (bookmark_menu_delegate_.get()) { | 805 if (bookmark_menu_delegate_.get()) { |
806 BookmarkModel* model = BookmarkModelFactory::GetForProfile( | 806 BookmarkModel* model = |
807 browser_->profile()); | 807 BookmarkModelFactory::GetForBrowserContext(browser_->profile()); |
808 if (model) | 808 if (model) |
809 model->RemoveObserver(this); | 809 model->RemoveObserver(this); |
810 } | 810 } |
811 FOR_EACH_OBSERVER(AppMenuObserver, observer_list_, AppMenuDestroyed()); | 811 FOR_EACH_OBSERVER(AppMenuObserver, observer_list_, AppMenuDestroyed()); |
812 } | 812 } |
813 | 813 |
814 void AppMenu::Init(ui::MenuModel* model) { | 814 void AppMenu::Init(ui::MenuModel* model) { |
815 DCHECK(!root_); | 815 DCHECK(!root_); |
816 root_ = new MenuItemView(this); | 816 root_ = new MenuItemView(this); |
817 root_->set_has_icons(true); // We have checks, radios and icons, set this | 817 root_->set_has_icons(true); // We have checks, radios and icons, set this |
(...skipping 16 matching lines...) Expand all Loading... |
834 gfx::Rect bounds(screen_loc, host->size()); | 834 gfx::Rect bounds(screen_loc, host->size()); |
835 content::RecordAction(UserMetricsAction("ShowAppMenu")); | 835 content::RecordAction(UserMetricsAction("ShowAppMenu")); |
836 if (menu_runner_->RunMenuAt(host->GetWidget(), | 836 if (menu_runner_->RunMenuAt(host->GetWidget(), |
837 host, | 837 host, |
838 bounds, | 838 bounds, |
839 views::MENU_ANCHOR_TOPRIGHT, | 839 views::MENU_ANCHOR_TOPRIGHT, |
840 ui::MENU_SOURCE_NONE) == | 840 ui::MENU_SOURCE_NONE) == |
841 views::MenuRunner::MENU_DELETED) | 841 views::MenuRunner::MENU_DELETED) |
842 return; | 842 return; |
843 if (bookmark_menu_delegate_.get()) { | 843 if (bookmark_menu_delegate_.get()) { |
844 BookmarkModel* model = BookmarkModelFactory::GetForProfile( | 844 BookmarkModel* model = |
845 browser_->profile()); | 845 BookmarkModelFactory::GetForBrowserContext(browser_->profile()); |
846 if (model) | 846 if (model) |
847 model->RemoveObserver(this); | 847 model->RemoveObserver(this); |
848 } | 848 } |
849 if (selected_menu_model_) { | 849 if (selected_menu_model_) { |
850 selected_menu_model_->ActivatedAt(selected_index_); | 850 selected_menu_model_->ActivatedAt(selected_index_); |
851 } | 851 } |
852 } | 852 } |
853 | 853 |
854 void AppMenu::CloseMenu() { | 854 void AppMenu::CloseMenu() { |
855 if (menu_runner_.get()) | 855 if (menu_runner_.get()) |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 selected_menu_model_ = model; | 1227 selected_menu_model_ = model; |
1228 selected_index_ = index; | 1228 selected_index_ = index; |
1229 root_->Cancel(); | 1229 root_->Cancel(); |
1230 } | 1230 } |
1231 | 1231 |
1232 void AppMenu::CreateBookmarkMenu() { | 1232 void AppMenu::CreateBookmarkMenu() { |
1233 if (bookmark_menu_delegate_.get()) | 1233 if (bookmark_menu_delegate_.get()) |
1234 return; // Already created the menu. | 1234 return; // Already created the menu. |
1235 | 1235 |
1236 BookmarkModel* model = | 1236 BookmarkModel* model = |
1237 BookmarkModelFactory::GetForProfile(browser_->profile()); | 1237 BookmarkModelFactory::GetForBrowserContext(browser_->profile()); |
1238 if (!model->loaded()) | 1238 if (!model->loaded()) |
1239 return; | 1239 return; |
1240 | 1240 |
1241 model->AddObserver(this); | 1241 model->AddObserver(this); |
1242 | 1242 |
1243 // TODO(oshima): Replace with views only API. | 1243 // TODO(oshima): Replace with views only API. |
1244 views::Widget* parent = views::Widget::GetWidgetForNativeWindow( | 1244 views::Widget* parent = views::Widget::GetWidgetForNativeWindow( |
1245 browser_->window()->GetNativeWindow()); | 1245 browser_->window()->GetNativeWindow()); |
1246 bookmark_menu_delegate_.reset( | 1246 bookmark_menu_delegate_.reset( |
1247 new BookmarkMenuDelegate(browser_, browser_, parent)); | 1247 new BookmarkMenuDelegate(browser_, browser_, parent)); |
1248 bookmark_menu_delegate_->Init(this, | 1248 bookmark_menu_delegate_->Init(this, |
1249 bookmark_menu_, | 1249 bookmark_menu_, |
1250 model->bookmark_bar_node(), | 1250 model->bookmark_bar_node(), |
1251 0, | 1251 0, |
1252 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1252 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1253 BOOKMARK_LAUNCH_LOCATION_APP_MENU); | 1253 BOOKMARK_LAUNCH_LOCATION_APP_MENU); |
1254 } | 1254 } |
1255 | 1255 |
1256 int AppMenu::ModelIndexFromCommandId(int command_id) const { | 1256 int AppMenu::ModelIndexFromCommandId(int command_id) const { |
1257 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1257 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
1258 DCHECK(ix != command_id_to_entry_.end()); | 1258 DCHECK(ix != command_id_to_entry_.end()); |
1259 return ix->second.second; | 1259 return ix->second.second; |
1260 } | 1260 } |
OLD | NEW |