Chromium Code Reviews| 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/wrench_menu.h" | 5 #include "chrome/browser/ui/views/wrench_menu.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_tabstrip.h" | 18 #include "chrome/browser/ui/browser_tabstrip.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/browser/ui/search/search.h" | 20 #include "chrome/browser/ui/search/search.h" |
| 21 #include "chrome/browser/ui/search/search_model.h" | 21 #include "chrome/browser/ui/search/search_model.h" |
| 22 #include "chrome/browser/ui/toolbar/recent_tabs_menu_model_delegate.h" | |
| 22 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" | 23 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" |
| 23 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "content/public/browser/host_zoom_map.h" | 25 #include "content/public/browser/host_zoom_map.h" |
| 25 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
| 26 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
| 27 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
| 28 #include "content/public/browser/notification_types.h" | 29 #include "content/public/browser/notification_types.h" |
| 29 #include "content/public/browser/user_metrics.h" | 30 #include "content/public/browser/user_metrics.h" |
| 30 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 31 #include "grit/chromium_strings.h" | 32 #include "grit/chromium_strings.h" |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds, | 752 if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds, |
| 752 MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == | 753 MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == |
| 753 views::MenuRunner::MENU_DELETED) | 754 views::MenuRunner::MENU_DELETED) |
| 754 return; | 755 return; |
| 755 if (bookmark_menu_delegate_.get()) { | 756 if (bookmark_menu_delegate_.get()) { |
| 756 BookmarkModel* model = BookmarkModelFactory::GetForProfile( | 757 BookmarkModel* model = BookmarkModelFactory::GetForProfile( |
| 757 browser_->profile()); | 758 browser_->profile()); |
| 758 if (model) | 759 if (model) |
| 759 model->RemoveObserver(this); | 760 model->RemoveObserver(this); |
| 760 } | 761 } |
| 762 recent_tabs_menu_model_delegate_.reset(); | |
|
sky
2012/11/07 00:10:47
Is there a reason to explicitly destroy this here?
kuan
2012/11/07 02:29:46
the only reason is wherever we stop observing book
sky
2012/11/07 14:40:12
But your code doesn't need to be cleaned up explic
kuan
2012/11/07 16:48:52
Done.
| |
| 761 if (selected_menu_model_) | 763 if (selected_menu_model_) |
| 762 selected_menu_model_->ActivatedAt(selected_index_); | 764 selected_menu_model_->ActivatedAt(selected_index_); |
| 763 } | 765 } |
| 764 | 766 |
| 765 bool WrenchMenu::IsShowing() { | 767 bool WrenchMenu::IsShowing() { |
| 766 return menu_runner_.get() && menu_runner_->IsRunning(); | 768 return menu_runner_.get() && menu_runner_->IsRunning(); |
| 767 } | 769 } |
| 768 | 770 |
| 769 string16 WrenchMenu::GetTooltipText(int id, | 771 string16 WrenchMenu::GetTooltipText(int id, |
| 770 const gfx::Point& p) const { | 772 const gfx::Point& p) const { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 885 const Entry& entry = id_to_entry_.find(id)->second; | 887 const Entry& entry = id_to_entry_.find(id)->second; |
| 886 int command_id = entry.first->GetCommandIdAt(entry.second); | 888 int command_id = entry.first->GetCommandIdAt(entry.second); |
| 887 | 889 |
| 888 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) { | 890 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) { |
| 889 // These items are represented by child views. If ExecuteCommand is invoked | 891 // These items are represented by child views. If ExecuteCommand is invoked |
| 890 // it means the user clicked on the area around the buttons and we should | 892 // it means the user clicked on the area around the buttons and we should |
| 891 // not do anyting. | 893 // not do anyting. |
| 892 return; | 894 return; |
| 893 } | 895 } |
| 894 | 896 |
| 895 return entry.first->ActivatedAt(entry.second); | 897 return entry.first->ActivatedAt(entry.second, mouse_event_flags); |
| 896 } | 898 } |
| 897 | 899 |
| 898 bool WrenchMenu::GetAccelerator(int id, ui::Accelerator* accelerator) { | 900 bool WrenchMenu::GetAccelerator(int id, ui::Accelerator* accelerator) { |
| 899 if (is_bookmark_command(id)) | 901 if (is_bookmark_command(id)) |
| 900 return false; | 902 return false; |
| 901 IDToEntry::iterator ix = id_to_entry_.find(id); | 903 IDToEntry::iterator ix = id_to_entry_.find(id); |
| 902 if (ix == id_to_entry_.end()) { | 904 if (ix == id_to_entry_.end()) { |
| 903 // There is no entry for this id. | 905 // There is no entry for this id. |
| 904 return false; | 906 return false; |
| 905 } | 907 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 SetVisibilityChangedAnimationsEnabled(false); | 940 SetVisibilityChangedAnimationsEnabled(false); |
| 939 } | 941 } |
| 940 } | 942 } |
| 941 | 943 |
| 942 void WrenchMenu::BookmarkModelChanged() { | 944 void WrenchMenu::BookmarkModelChanged() { |
| 943 DCHECK(bookmark_menu_delegate_.get()); | 945 DCHECK(bookmark_menu_delegate_.get()); |
| 944 if (!bookmark_menu_delegate_->is_mutating_model()) | 946 if (!bookmark_menu_delegate_->is_mutating_model()) |
| 945 root_->Cancel(); | 947 root_->Cancel(); |
| 946 } | 948 } |
| 947 | 949 |
| 948 | |
| 949 void WrenchMenu::Observe(int type, | 950 void WrenchMenu::Observe(int type, |
| 950 const content::NotificationSource& source, | 951 const content::NotificationSource& source, |
| 951 const content::NotificationDetails& details) { | 952 const content::NotificationDetails& details) { |
| 952 switch (type) { | 953 switch (type) { |
| 953 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: | 954 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: |
| 954 // A change in the global errors list can add or remove items from the | 955 // A change in the global errors list can add or remove items from the |
| 955 // menu. Close the menu to avoid have a stale menu on-screen. | 956 // menu. Close the menu to avoid have a stale menu on-screen. |
| 956 root_->Cancel(); | 957 root_->Cancel(); |
| 957 break; | 958 break; |
| 958 default: | 959 default: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1009 case IDC_BOOKMARKS_MENU: | 1010 case IDC_BOOKMARKS_MENU: |
| 1010 DCHECK(!bookmark_menu_); | 1011 DCHECK(!bookmark_menu_); |
| 1011 bookmark_menu_ = item; | 1012 bookmark_menu_ = item; |
| 1012 break; | 1013 break; |
| 1013 | 1014 |
| 1014 case IDC_FEEDBACK: | 1015 case IDC_FEEDBACK: |
| 1015 DCHECK(!feedback_menu_item_); | 1016 DCHECK(!feedback_menu_item_); |
| 1016 feedback_menu_item_ = item; | 1017 feedback_menu_item_ = item; |
| 1017 break; | 1018 break; |
| 1018 | 1019 |
| 1020 case IDC_RECENT_TABS_MENU: | |
| 1021 DCHECK(chrome::search::IsInstantExtendedAPIEnabled( | |
| 1022 browser_->profile())); | |
| 1023 DCHECK(!recent_tabs_menu_model_delegate_.get()); | |
| 1024 recent_tabs_menu_model_delegate_.reset( | |
| 1025 new RecentTabsMenuModelDelegate(model->GetSubmenuModelAt(index), | |
| 1026 item)); | |
| 1027 break; | |
| 1028 | |
| 1019 default: | 1029 default: |
| 1020 break; | 1030 break; |
| 1021 } | 1031 } |
| 1022 } | 1032 } |
| 1023 } | 1033 } |
| 1024 | 1034 |
| 1025 MenuItemView* WrenchMenu::AppendMenuItem(MenuItemView* parent, | 1035 MenuItemView* WrenchMenu::AppendMenuItem(MenuItemView* parent, |
| 1026 MenuModel* model, | 1036 MenuModel* model, |
| 1027 int index, | 1037 int index, |
| 1028 MenuModel::ItemType menu_type, | 1038 MenuModel::ItemType menu_type, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1083 bookmark_menu_delegate_.reset( | 1093 bookmark_menu_delegate_.reset( |
| 1084 new BookmarkMenuDelegate(browser_, | 1094 new BookmarkMenuDelegate(browser_, |
| 1085 browser_, | 1095 browser_, |
| 1086 parent, | 1096 parent, |
| 1087 first_bookmark_command_id_)); | 1097 first_bookmark_command_id_)); |
| 1088 bookmark_menu_delegate_->Init( | 1098 bookmark_menu_delegate_->Init( |
| 1089 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 1099 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
| 1090 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1100 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1091 bookmark_utils::LAUNCH_WRENCH_MENU); | 1101 bookmark_utils::LAUNCH_WRENCH_MENU); |
| 1092 } | 1102 } |
| OLD | NEW |