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/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_tabstrip.h" | 18 #include "chrome/browser/ui/browser_tabstrip.h" |
18 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/browser/ui/search/search.h" | 20 #include "chrome/browser/ui/search/search.h" |
20 #include "chrome/browser/ui/search/search_model.h" | 21 #include "chrome/browser/ui/search/search_model.h" |
21 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" | 22 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" |
22 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
23 #include "content/public/browser/host_zoom_map.h" | 24 #include "content/public/browser/host_zoom_map.h" |
24 #include "content/public/browser/notification_observer.h" | 25 #include "content/public/browser/notification_observer.h" |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 selected_index_(0), | 744 selected_index_(0), |
744 bookmark_menu_(NULL), | 745 bookmark_menu_(NULL), |
745 feedback_menu_item_(NULL), | 746 feedback_menu_item_(NULL), |
746 first_bookmark_command_id_(0) { | 747 first_bookmark_command_id_(0) { |
747 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | 748 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
748 content::Source<Profile>(browser_->profile())); | 749 content::Source<Profile>(browser_->profile())); |
749 } | 750 } |
750 | 751 |
751 WrenchMenu::~WrenchMenu() { | 752 WrenchMenu::~WrenchMenu() { |
752 if (bookmark_menu_delegate_.get()) { | 753 if (bookmark_menu_delegate_.get()) { |
753 BookmarkModel* model = browser_->profile()->GetBookmarkModel(); | 754 BookmarkModel* model = BookmarkModelFactory::GetForProfile( |
| 755 browser_->profile()); |
754 if (model) | 756 if (model) |
755 model->RemoveObserver(this); | 757 model->RemoveObserver(this); |
756 } | 758 } |
757 } | 759 } |
758 | 760 |
759 void WrenchMenu::Init(ui::MenuModel* model) { | 761 void WrenchMenu::Init(ui::MenuModel* model) { |
760 DCHECK(!root_); | 762 DCHECK(!root_); |
761 root_ = new MenuItemView(this); | 763 root_ = new MenuItemView(this); |
762 root_->set_has_icons(true); // We have checks, radios and icons, set this | 764 root_->set_has_icons(true); // We have checks, radios and icons, set this |
763 // so we get the taller menu style. | 765 // so we get the taller menu style. |
764 int next_id = 1; | 766 int next_id = 1; |
765 PopulateMenu(root_, model, &next_id); | 767 PopulateMenu(root_, model, &next_id); |
766 first_bookmark_command_id_ = next_id + 1; | 768 first_bookmark_command_id_ = next_id + 1; |
767 menu_runner_.reset(new views::MenuRunner(root_)); | 769 menu_runner_.reset(new views::MenuRunner(root_)); |
768 } | 770 } |
769 | 771 |
770 void WrenchMenu::RunMenu(views::MenuButton* host) { | 772 void WrenchMenu::RunMenu(views::MenuButton* host) { |
771 gfx::Point screen_loc; | 773 gfx::Point screen_loc; |
772 views::View::ConvertPointToScreen(host, &screen_loc); | 774 views::View::ConvertPointToScreen(host, &screen_loc); |
773 gfx::Rect bounds(screen_loc, host->size()); | 775 gfx::Rect bounds(screen_loc, host->size()); |
774 content::RecordAction(UserMetricsAction("ShowAppMenu")); | 776 content::RecordAction(UserMetricsAction("ShowAppMenu")); |
775 if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds, | 777 if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds, |
776 MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == | 778 MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == |
777 views::MenuRunner::MENU_DELETED) | 779 views::MenuRunner::MENU_DELETED) |
778 return; | 780 return; |
779 if (bookmark_menu_delegate_.get()) { | 781 if (bookmark_menu_delegate_.get()) { |
780 BookmarkModel* model = browser_->profile()->GetBookmarkModel(); | 782 BookmarkModel* model = BookmarkModelFactory::GetForProfile( |
| 783 browser_->profile()); |
781 if (model) | 784 if (model) |
782 model->RemoveObserver(this); | 785 model->RemoveObserver(this); |
783 } | 786 } |
784 if (selected_menu_model_) | 787 if (selected_menu_model_) |
785 selected_menu_model_->ActivatedAt(selected_index_); | 788 selected_menu_model_->ActivatedAt(selected_index_); |
786 } | 789 } |
787 | 790 |
788 string16 WrenchMenu::GetTooltipText(int id, | 791 string16 WrenchMenu::GetTooltipText(int id, |
789 const gfx::Point& p) const { | 792 const gfx::Point& p) const { |
790 return is_bookmark_command(id) ? | 793 return is_bookmark_command(id) ? |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 void WrenchMenu::CancelAndEvaluate(MenuModel* model, int index) { | 1085 void WrenchMenu::CancelAndEvaluate(MenuModel* model, int index) { |
1083 selected_menu_model_ = model; | 1086 selected_menu_model_ = model; |
1084 selected_index_ = index; | 1087 selected_index_ = index; |
1085 root_->Cancel(); | 1088 root_->Cancel(); |
1086 } | 1089 } |
1087 | 1090 |
1088 void WrenchMenu::CreateBookmarkMenu() { | 1091 void WrenchMenu::CreateBookmarkMenu() { |
1089 if (bookmark_menu_delegate_.get()) | 1092 if (bookmark_menu_delegate_.get()) |
1090 return; // Already created the menu. | 1093 return; // Already created the menu. |
1091 | 1094 |
1092 BookmarkModel* model = browser_->profile()->GetBookmarkModel(); | 1095 BookmarkModel* model = BookmarkModelFactory::GetForProfile( |
| 1096 browser_->profile()); |
1093 if (!model->IsLoaded()) | 1097 if (!model->IsLoaded()) |
1094 return; | 1098 return; |
1095 | 1099 |
1096 model->AddObserver(this); | 1100 model->AddObserver(this); |
1097 | 1101 |
1098 // TODO(oshima): Replace with views only API. | 1102 // TODO(oshima): Replace with views only API. |
1099 views::Widget* parent = views::Widget::GetWidgetForNativeWindow( | 1103 views::Widget* parent = views::Widget::GetWidgetForNativeWindow( |
1100 browser_->window()->GetNativeWindow()); | 1104 browser_->window()->GetNativeWindow()); |
1101 bookmark_menu_delegate_.reset( | 1105 bookmark_menu_delegate_.reset( |
1102 new BookmarkMenuDelegate(browser_, | 1106 new BookmarkMenuDelegate(browser_, |
1103 browser_, | 1107 browser_, |
1104 parent, | 1108 parent, |
1105 first_bookmark_command_id_)); | 1109 first_bookmark_command_id_)); |
1106 bookmark_menu_delegate_->Init( | 1110 bookmark_menu_delegate_->Init( |
1107 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 1111 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
1108 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1112 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1109 bookmark_utils::LAUNCH_WRENCH_MENU); | 1113 bookmark_utils::LAUNCH_WRENCH_MENU); |
1110 } | 1114 } |
OLD | NEW |