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 "ui/base/l10n/l10n_util.h" | |
12 #include "ui/base/resource/resource_bundle.h" | |
13 #include "ui/views/bubble/bubble_border.h" | |
14 #include "ui/views/controls/button/menu_button.h" | |
15 #include "ui/views/controls/menu/menu_runner.h" | |
16 #include "ui/views/view.h" | |
17 | |
18 //////////////////////////////////////////////////////////////////////////////// | |
19 // ActionBoxMenu | |
20 | |
21 ActionBoxMenu::ActionBoxMenu(Browser* browser, | |
22 ActionBoxMenuModel* model, | |
23 bool bookmark_item_state) | |
24 : browser_(browser), | |
25 root_(NULL), | |
26 model_(model), | |
27 bookmark_item_state_(bookmark_item_state) { | |
28 } | |
29 | |
30 ActionBoxMenu::~ActionBoxMenu() { | |
31 } | |
32 | |
33 void ActionBoxMenu::Init() { | |
34 CHECK(!root_); | |
Peter Kasting
2012/07/18 01:37:25
Nit: Why does this need to be a CHECK() rather tha
yefimt
2012/07/18 23:18:13
I guess because another reviewer asked me to chang
Peter Kasting
2012/07/19 04:27:31
CHECKs are unusual -- normally they're used in sit
yefimt
2012/07/19 20:00:15
Done.
| |
35 root_ = new views::MenuItemView(this); | |
36 // We have icons, set this so we get the taller menu style. | |
37 root_->set_has_icons(true); | |
38 PopulateMenu(); | |
39 menu_runner_.reset(new views::MenuRunner(root_)); | |
40 } | |
41 | |
42 void ActionBoxMenu::RunMenu(views::MenuButton* menu_button) { | |
43 gfx::Point screen_location; | |
44 views::View::ConvertPointToScreen(menu_button, &screen_location); | |
45 // Ignore the result since we don't need to handle a deleted menu specially. | |
46 ignore_result( | |
47 menu_runner_->RunMenuAt(menu_button->GetWidget(), | |
48 menu_button, | |
49 gfx::Rect(screen_location, menu_button->size()), | |
50 views::MenuItemView::TOPRIGHT, | |
51 views::MenuRunner::HAS_MNEMONICS)); | |
52 } | |
53 | |
54 void ActionBoxMenu::ExecuteCommand(int id) { | |
55 }; | |
56 | |
57 views::Border* ActionBoxMenu::CreateMenuBorder() { | |
58 return views::Border::CreateSolidBorder(1, SkColorSetRGB(0, 0, 0)); | |
59 } | |
60 | |
61 views::Background* ActionBoxMenu::CreateMenuBackground() { | |
62 return views::Background::CreateSolidBackground(SkColorSetRGB(255, 255, 255)); | |
63 } | |
64 | |
65 Browser* ActionBoxMenu::GetBrowser() const { | |
66 return browser_; | |
67 } | |
68 | |
69 int ActionBoxMenu::GetCurrentTabId() const { | |
70 return 0; | |
71 } | |
72 | |
73 void ActionBoxMenu::OnBrowserActionExecuted(BrowserActionButton* button) { | |
74 } | |
75 | |
76 void ActionBoxMenu::OnBrowserActionVisibilityChanged() { | |
77 } | |
78 | |
79 gfx::Size ActionBoxMenu::GetViewContentOffset() const { | |
80 return gfx::Size(0, 0); | |
81 } | |
82 | |
83 void ActionBoxMenu::WriteDragDataForView(views::View* sender, | |
84 const gfx::Point& press_pt, | |
85 ui::OSExchangeData* data) { | |
86 } | |
87 | |
88 int ActionBoxMenu::GetDragOperationsForView(views::View* sender, | |
89 const gfx::Point& p) { | |
90 return 0; | |
91 } | |
92 | |
93 bool ActionBoxMenu::CanStartDragForView(views::View* sender, | |
94 const gfx::Point& press_pt, | |
95 const gfx::Point& p) { | |
96 return false; | |
97 } | |
98 | |
99 void ActionBoxMenu::Observe(int type, | |
100 const content::NotificationSource& source, | |
101 const content::NotificationDetails& details) { | |
102 } | |
103 | |
104 void ActionBoxMenu::PopulateMenu() { | |
105 int item_id = 1; | |
106 AddBookmarkMenuItem(root_, &item_id); | |
107 if (model_->GetItemCount() > 0) | |
108 root_->AppendSeparator(); | |
109 | |
110 for (int model_index = 0; model_index < model_->GetItemCount(); | |
111 ++model_index) { | |
112 views::MenuItemView* menu_item = root_->AppendMenuItemFromModel( | |
113 model_, model_index, item_id); | |
Peter Kasting
2012/07/18 01:37:25
Nit: As mentioned previously, if you pass "item_id
yefimt
2012/07/18 23:18:13
Done.
| |
114 if (model_->GetTypeAt(model_index) == ui::MenuModel::TYPE_COMMAND) { | |
115 menu_item->SetMargins(0, 0); | |
116 const extensions::Extension* extension = | |
117 model_->GetActionBoxExtensionByIndex(model_index); | |
118 BrowserActionView* view = new BrowserActionView(extension, this); | |
119 view->button()->SetShowMultipleIconStates(false); | |
120 view->button()->SetTooltipDisabled(true); | |
121 browser_action_views_.push_back(linked_ptr<BrowserActionView>(view)); | |
122 menu_item->SetIconView(view); | |
123 } | |
124 item_id++; | |
125 } | |
126 } | |
127 | |
128 views::MenuItemView* ActionBoxMenu::AddBookmarkMenuItem( | |
129 views::MenuItemView* parent, | |
130 int* item_id) { | |
131 string16 label = l10n_util::GetStringUTF16(bookmark_item_state_ ? | |
132 IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR); | |
133 gfx::ImageSkia* icon = | |
134 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
135 bookmark_item_state_ ? IDR_STAR_LIT : IDR_STAR); | |
136 DCHECK(icon); | |
137 views::MenuItemView* item = | |
138 parent->AppendMenuItemWithIcon(*item_id, label, *icon); | |
139 (*item_id)++; | |
140 return item; | |
141 } | |
OLD | NEW |