OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/action_box_menu.h" | |
6 | |
7 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" | |
8 #include "chrome/browser/ui/views/action_box_menu_item_view.h" | |
9 #include "chrome/browser/ui/views/browser_action_view.h" | |
10 #include "grit/generated_resources.h" | |
11 #include "grit/theme_resources.h" | |
12 #include "grit/theme_resources_standard.h" | |
13 #include "ui/base/l10n/l10n_util.h" | |
14 #include "ui/base/resource/resource_bundle.h" | |
15 #include "ui/views/controls/button/menu_button.h" | |
16 #include "ui/views/controls/menu/menu_runner.h" | |
17 #include "ui/views/view.h" | |
18 | |
19 using ui::MenuModel; | |
20 using views::MenuItemView; | |
21 using views::View; | |
22 | |
23 // ActionBoxMenu --------------------------------------------------------------- | |
24 | |
25 ActionBoxMenu::ActionBoxMenu(Browser* browser, | |
26 ActionBoxMenuModel* model, | |
27 bool bookmark_item_state) | |
28 : browser_(browser), | |
29 root_(NULL), | |
30 model_(model), | |
31 bookmark_item_state_(bookmark_item_state), | |
32 model_index_offset_(0) { | |
33 // registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | |
34 // content::Source<Profile>(browser_->profile())); | |
35 } | |
36 | |
37 ActionBoxMenu::~ActionBoxMenu() { | |
38 } | |
39 | |
40 void ActionBoxMenu::Init() { | |
41 DCHECK(!root_); | |
42 root_ = new ActionBoxMenuItemView(this); | |
43 root_->set_has_icons(true); // We have checks, radios and icons, set this | |
44 // so we get the taller menu style. | |
45 int id = 1; | |
Aaron Boodman
2012/06/12 05:53:44
This is never used for anything...? Seems like it
yefimt
2012/06/13 01:24:21
Done
Original idea was that it could be called rec
| |
46 PopulateMenu(root_, model_, &id); | |
47 menu_runner_.reset(new views::MenuRunner(root_)); | |
48 } | |
49 | |
50 void ActionBoxMenu::RunMenu(views::MenuButton* host) { | |
51 gfx::Point screen_loc; | |
52 views::View::ConvertPointToScreen(host, &screen_loc); | |
53 gfx::Rect bounds(screen_loc, host->size()); | |
54 if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds, | |
55 MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == | |
56 views::MenuRunner::MENU_DELETED) { | |
57 return; | |
58 } | |
59 } | |
60 | |
61 Browser* ActionBoxMenu::GetBrowser() const { | |
62 return browser_; | |
63 } | |
64 | |
65 int ActionBoxMenu::GetCurrentTabId() const { | |
66 return 0; | |
67 } | |
68 | |
69 void ActionBoxMenu::OnBrowserActionExecuted(BrowserActionButton* button) { | |
70 } | |
71 | |
72 void ActionBoxMenu::OnBrowserActionVisibilityChanged() { | |
73 } | |
74 | |
75 gfx::Size ActionBoxMenu::GetContentOffset() const { | |
76 return gfx::Size(0, 0); | |
77 } | |
78 | |
79 void ActionBoxMenu::WriteDragDataForView(View* sender, | |
80 const gfx::Point& press_pt, | |
81 ui::OSExchangeData* data) { | |
82 } | |
83 | |
84 int ActionBoxMenu::GetDragOperationsForView(View* sender, | |
85 const gfx::Point& p) { | |
86 return 0; | |
87 } | |
88 | |
89 bool ActionBoxMenu::CanStartDragForView(View* sender, | |
90 const gfx::Point& press_pt, | |
91 const gfx::Point& p) { | |
92 return false; | |
93 } | |
94 | |
95 void ActionBoxMenu::Observe(int type, | |
96 const content::NotificationSource& source, | |
97 const content::NotificationDetails& details) { | |
98 } | |
99 | |
100 void ActionBoxMenu::PopulateMenu(MenuItemView* parent, | |
101 ActionBoxMenuModel* model, | |
102 int* id) { | |
103 int menu_index = 0; | |
104 AddBookmarkMenuItem(parent, &menu_index, id); | |
105 parent->AppendSeparator(); | |
106 menu_index++; | |
107 model_index_offset_ = menu_index; | |
108 | |
109 for (int model_index = 0; model_index < model->GetItemCount(); | |
110 ++model_index) { | |
111 MenuItemView* menu_item = parent->AppendMenuItemFromModel(model, | |
112 model_index, *id); | |
113 if (model->GetTypeAt(model_index) == MenuModel::TYPE_COMMAND) { | |
114 const extensions::Extension* extension = | |
115 model->GetActionBoxExtensionByIndex(model_index); | |
116 BrowserActionView* view = new BrowserActionView(extension, this); | |
117 browser_action_views_.push_back(view); | |
118 menu_item->AddChildView(view); | |
119 } | |
120 (*id)++; | |
121 } | |
122 } | |
123 | |
124 MenuItemView* ActionBoxMenu::AddBookmarkMenuItem(MenuItemView* parent, | |
125 int* index, int* id) { | |
126 string16 label = | |
127 l10n_util::GetStringUTF16(bookmark_item_state_ ? IDS_TOOLTIP_STARRED : | |
128 IDS_TOOLTIP_STAR); | |
129 gfx::ImageSkia* icon = | |
130 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
131 bookmark_item_state_ ? IDR_STAR_LIT : IDR_STAR); | |
132 DCHECK(icon); | |
133 MenuItemView* item = parent->AddMenuItemAt(*index, *id, label, *icon, | |
134 MenuItemView::NORMAL); | |
135 (*id)++; | |
136 (*index)++; | |
137 return item; | |
138 } | |
OLD | NEW |