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/browser_action_view.h" | |
9 #include "grit/generated_resources.h" | |
10 #include "grit/theme_resources.h" | |
11 #include "grit/theme_resources_standard.h" | |
12 #include "ui/base/l10n/l10n_util.h" | |
13 #include "ui/base/resource/resource_bundle.h" | |
14 #include "ui/views/bubble/bubble_border.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; | |
tfarina
2012/07/02 22:49:18
nit: please, avoid using declarations if possible.
yefimt
2012/07/11 22:34:34
Done.
| |
21 using views::View; | |
22 | |
23 // ActionBoxMenu --------------------------------------------------------------- | |
Aaron Boodman
2012/07/02 22:41:34
Remove this line.
yefimt
2012/07/11 22:34:34
Done.
| |
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 } | |
34 | |
35 ActionBoxMenu::~ActionBoxMenu() { | |
36 STLDeleteElements(&browser_action_views_); | |
Aaron Boodman
2012/07/02 22:41:34
Use std::vector<linked_ptr<BrowserActionView> > to
tfarina
2012/07/02 22:49:18
Ham? What is that? :/
Do you mean using ScopedVec
Aaron Boodman
2012/07/03 00:03:32
What is what? base/memory/linked_ptr.h
yefimt
2012/07/11 22:34:34
Done.
| |
37 } | |
38 | |
39 void ActionBoxMenu::Init() { | |
40 DCHECK(!root_); | |
Aaron Boodman
2012/07/02 22:41:34
CHECK(!root_)
yefimt
2012/07/11 22:34:34
Done.
| |
41 root_ = new MenuItemView(this); | |
42 root_->set_has_icons(true); // We have checks, radios and icons, set this | |
Aaron Boodman
2012/07/02 22:41:34
Put this comment on the line above. Multiline trai
Aaron Boodman
2012/07/02 22:41:34
We actually only have icons right, not checks or r
yefimt
2012/07/11 22:34:34
Done.
| |
43 // so we get the taller menu style. | |
44 PopulateMenu(); | |
45 menu_runner_.reset(new views::MenuRunner(root_)); | |
46 } | |
47 | |
48 void ActionBoxMenu::RunMenu(views::MenuButton* host) { | |
49 gfx::Point screen_loc; | |
Aaron Boodman
2012/07/02 22:41:34
Avoid abbreviation: screen_location
yefimt
2012/07/11 22:34:34
Done.
| |
50 views::View::ConvertPointToScreen(host, &screen_loc); | |
51 gfx::Rect bounds(screen_loc, host->size()); | |
52 if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds, | |
53 MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == | |
Aaron Boodman
2012/07/02 22:41:34
Left column of all params lines should line up.
yefimt
2012/07/11 22:34:34
Done.
| |
54 views::MenuRunner::MENU_DELETED) { | |
55 return; | |
56 } | |
57 } | |
58 | |
59 void ActionBoxMenu::ExecuteCommand(int id) { | |
60 }; | |
61 | |
62 views::Border* ActionBoxMenu::CreateMenuBorder() { | |
63 return views::Border::CreateSolidBorder(1, SkColorSetRGB(0, 0, 0)); | |
64 // views::BubbleBorder* border = new views::BubbleBorder( | |
Aaron Boodman
2012/07/02 22:41:34
Kill dead code.
yefimt
2012/07/11 22:34:34
Done.
| |
65 // views::BubbleBorder::NONE, views::BubbleBorder::NO_SHADOW); | |
66 // return border; | |
67 } | |
68 | |
69 views::Background* ActionBoxMenu::CreateMenuBackground() { | |
70 return views::Background::CreateSolidBackground(SkColorSetRGB(255, 255, 255)); | |
71 } | |
72 | |
73 Browser* ActionBoxMenu::GetBrowser() const { | |
74 return browser_; | |
75 } | |
76 | |
77 int ActionBoxMenu::GetCurrentTabId() const { | |
78 return 0; | |
79 } | |
80 | |
81 void ActionBoxMenu::OnBrowserActionExecuted(BrowserActionButton* button) { | |
82 } | |
83 | |
84 void ActionBoxMenu::OnBrowserActionVisibilityChanged() { | |
85 } | |
86 | |
87 gfx::Size ActionBoxMenu::GetViewContentOffset() const { | |
88 return gfx::Size(0, 0); | |
89 } | |
90 | |
91 void ActionBoxMenu::WriteDragDataForView(View* sender, | |
92 const gfx::Point& press_pt, | |
93 ui::OSExchangeData* data) { | |
94 } | |
95 | |
96 int ActionBoxMenu::GetDragOperationsForView(View* sender, | |
97 const gfx::Point& p) { | |
98 return 0; | |
99 } | |
100 | |
101 bool ActionBoxMenu::CanStartDragForView(View* sender, | |
102 const gfx::Point& press_pt, | |
103 const gfx::Point& p) { | |
104 return false; | |
105 } | |
106 | |
107 void ActionBoxMenu::Observe(int type, | |
108 const content::NotificationSource& source, | |
109 const content::NotificationDetails& details) { | |
110 } | |
111 | |
112 void ActionBoxMenu::PopulateMenu() { | |
113 int id = 1; | |
Aaron Boodman
2012/07/02 22:41:34
Consider changing this counter into a member varia
yefimt
2012/07/11 22:34:34
Would be weird to have a member variable that keep
| |
114 int menu_index = 0; | |
115 AddBookmarkMenuItem(root_, &menu_index, &id); | |
116 root_->AppendSeparator(); | |
117 menu_index++; | |
118 model_index_offset_ = menu_index; | |
119 | |
120 for (int model_index = 0; model_index < model_->GetItemCount(); | |
121 ++model_index) { | |
122 MenuItemView* menu_item = root_->AppendMenuItemFromModel(model_, | |
123 model_index, id); | |
124 if (model_->GetTypeAt(model_index) == MenuModel::TYPE_COMMAND) { | |
125 menu_item->SetMargins(0, 0); | |
126 const extensions::Extension* extension = | |
127 model_->GetActionBoxExtensionByIndex(model_index); | |
128 BrowserActionView* view = new BrowserActionView(extension, this); | |
129 view->button()->SetShowMultipleIconStates(false); | |
130 view->button()->DisableTooltip(true); | |
131 browser_action_views_.push_back(view); | |
132 menu_item->SetIconView(view); | |
133 } | |
134 id++; | |
135 } | |
136 } | |
137 | |
138 MenuItemView* ActionBoxMenu::AddBookmarkMenuItem(MenuItemView* parent, | |
139 int* index, int* id) { | |
140 string16 label = | |
141 l10n_util::GetStringUTF16(bookmark_item_state_ ? IDS_TOOLTIP_STARRED : | |
142 IDS_TOOLTIP_STAR); | |
143 gfx::ImageSkia* icon = | |
144 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
145 bookmark_item_state_ ? IDR_STAR_LIT : IDR_STAR); | |
146 DCHECK(icon); | |
147 MenuItemView* item = parent->AddMenuItemAt(*index, *id, label, *icon, | |
148 MenuItemView::NORMAL); | |
Aaron Boodman
2012/07/02 22:41:34
Don't any of the AppendMenuItem* methods work? If
yefimt
2012/07/11 22:34:34
Done.
| |
149 (*id)++; | |
150 (*index)++; | |
151 return item; | |
152 } | |
OLD | NEW |