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 #if defined(OS_WIN) | |
19 #include <vssym32.h> | |
msw
2012/07/24 23:41:55
nit: comment as to why this is needed.
yefimt
2012/07/25 21:09:21
Done.
| |
20 #include "ui/base/native_theme/native_theme_win.h" | |
21 #endif | |
22 | |
23 //////////////////////////////////////////////////////////////////////////////// | |
24 // ActionBoxMenu | |
25 | |
26 ActionBoxMenu::ActionBoxMenu(Browser* browser, | |
27 ActionBoxMenuModel* model, | |
28 bool bookmark_item_state) | |
29 : browser_(browser), | |
30 root_(NULL), | |
31 model_(model), | |
32 bookmark_item_state_(bookmark_item_state) { | |
33 } | |
34 | |
35 ActionBoxMenu::~ActionBoxMenu() { | |
36 } | |
37 | |
38 void ActionBoxMenu::Init() { | |
39 DCHECK(!root_); | |
40 root_ = new views::MenuItemView(this); | |
41 // We have icons, set this so we get the taller menu style. | |
msw
2012/07/24 23:41:55
nit: I prefer making statements about the objects
yefimt
2012/07/25 21:09:21
Removed.
As I'm new to chrome, I often use existin
msw
2012/07/25 23:02:03
Very true, I just prefer explicitly specifying the
| |
42 root_->set_has_icons(true); | |
43 PopulateMenu(); | |
44 menu_runner_.reset(new views::MenuRunner(root_)); | |
45 } | |
46 | |
47 void ActionBoxMenu::RunMenu(views::MenuButton* menu_button) { | |
48 gfx::Point screen_location; | |
49 views::View::ConvertPointToScreen(menu_button, &screen_location); | |
50 // Ignore the result since we don't need to handle a deleted menu specially. | |
msw
2012/07/24 23:41:55
nit: for clarity, perhaps mention that this menu i
yefimt
2012/07/25 21:09:21
Done.
| |
51 ignore_result( | |
52 menu_runner_->RunMenuAt(menu_button->GetWidget(), | |
53 menu_button, | |
54 gfx::Rect(screen_location, menu_button->size()), | |
55 views::MenuItemView::TOPRIGHT, | |
56 views::MenuRunner::HAS_MNEMONICS)); | |
57 } | |
58 | |
59 void ActionBoxMenu::ExecuteCommand(int id) { | |
60 }; | |
61 | |
62 views::Border* ActionBoxMenu::CreateMenuBorder() { | |
63 #if defined(OS_WIN) | |
msw
2012/07/24 23:41:55
nit: declare and init an SkColor with SK_ColorBLAC
yefimt
2012/07/25 21:09:21
Done.
| |
64 // TODO: Move to Windows only files if possible. | |
msw
2012/07/24 23:41:55
nit: use TODO(ldap): style here and elsewhere...
yefimt
2012/07/25 21:09:21
Done.
| |
65 SkColor border_color = | |
66 ui::NativeThemeWin::instance()->GetThemeColorWithDefault( | |
67 ui::NativeThemeWin::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR, | |
68 COLOR_MENUTEXT); | |
69 return views::Border::CreateSolidBorder(1, border_color); | |
70 #else | |
71 // TODO: Use correct theme color on non-Windows. | |
72 return views::Border::CreateSolidBorder(1, SkColorSetRGB(0, 0, 0)); | |
73 #endif | |
74 } | |
75 | |
76 views::Background* ActionBoxMenu::CreateMenuBackground() { | |
77 #if defined(OS_WIN) | |
msw
2012/07/24 23:41:55
nit: employ the pattern I suggested above here as
yefimt
2012/07/25 21:09:21
Done.
| |
78 // TODO: Move to Windows only files if possible. | |
79 SkColor background_color = | |
80 ui::NativeThemeWin::instance()->GetThemeColorWithDefault( | |
81 ui::NativeThemeWin::TEXTFIELD, EP_BACKGROUND, EBS_NORMAL, | |
82 TMT_BACKGROUND, COLOR_WINDOW); | |
83 return views::Background::CreateSolidBackground(background_color); | |
84 #else | |
85 // TODO: Use correct theme color on non-Windows. | |
86 return views::Background::CreateSolidBackground(SkColorSetRGB(255, 255, 255)); | |
87 #endif | |
88 } | |
89 | |
90 int ActionBoxMenu::GetCurrentTabId() const { | |
91 return 0; | |
92 } | |
93 | |
94 void ActionBoxMenu::OnBrowserActionExecuted(BrowserActionButton* button) { | |
95 } | |
96 | |
97 void ActionBoxMenu::OnBrowserActionVisibilityChanged() { | |
98 } | |
99 | |
100 gfx::Size ActionBoxMenu::GetViewContentOffset() const { | |
101 return gfx::Size(0, 0); | |
102 } | |
103 | |
104 void ActionBoxMenu::WriteDragDataForView(views::View* sender, | |
105 const gfx::Point& press_pt, | |
106 ui::OSExchangeData* data) { | |
107 } | |
108 | |
109 int ActionBoxMenu::GetDragOperationsForView(views::View* sender, | |
110 const gfx::Point& p) { | |
111 return 0; | |
112 } | |
113 | |
114 bool ActionBoxMenu::CanStartDragForView(views::View* sender, | |
115 const gfx::Point& press_pt, | |
116 const gfx::Point& p) { | |
117 return false; | |
118 } | |
119 | |
120 void ActionBoxMenu::Observe(int type, | |
121 const content::NotificationSource& source, | |
122 const content::NotificationDetails& details) { | |
123 } | |
124 | |
125 void ActionBoxMenu::PopulateMenu() { | |
126 int item_id = 1; | |
127 AddBookmarkMenuItem(root_, &item_id); | |
128 if (model_->GetItemCount() > 0) | |
129 root_->AppendSeparator(); | |
130 | |
131 for (int model_index = 0; model_index < model_->GetItemCount(); | |
132 ++model_index) { | |
133 views::MenuItemView* menu_item = root_->AppendMenuItemFromModel( | |
134 model_, model_index, item_id + model_index); | |
135 if (model_->GetTypeAt(model_index) == ui::MenuModel::TYPE_COMMAND) { | |
msw
2012/07/24 23:41:55
nit: Can you clarify generally what menu items are
yefimt
2012/07/25 21:09:21
I did it looking at how other menus are implemente
msw
2012/07/25 23:02:03
Then I'd make this a DCHECK instead of a condition
yefimt
2012/07/31 00:10:11
Done.
| |
136 menu_item->SetMargins(0, 0); | |
137 const extensions::Extension* extension = | |
138 model_->GetActionBoxExtensionByIndex(model_index); | |
139 BrowserActionView* view = new BrowserActionView(extension, | |
140 browser_, this); | |
141 view->button()->SetShowMultipleIconStates(false); | |
142 view->button()->SetTooltipDisabled(true); | |
143 browser_action_views_.push_back(view); | |
144 menu_item->SetIconView(view); | |
145 } | |
146 } | |
147 } | |
148 | |
149 views::MenuItemView* ActionBoxMenu::AddBookmarkMenuItem( | |
msw
2012/07/24 23:41:55
nit: the return value is unused in the sole caller
yefimt
2012/07/25 21:09:21
Would it be better to have it consistent with all
msw
2012/07/25 23:02:03
Sure, I suppose that's fine.
| |
150 views::MenuItemView* parent, | |
151 int* item_id) { | |
152 string16 label = l10n_util::GetStringUTF16(bookmark_item_state_ ? | |
153 IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR); | |
154 gfx::ImageSkia* icon = | |
155 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
156 bookmark_item_state_ ? IDR_STAR_LIT : IDR_STAR); | |
157 DCHECK(icon); | |
msw
2012/07/24 23:41:55
nit: no need to DCHECK immediately before a de-ref
yefimt
2012/07/25 21:09:21
Done.
| |
158 views::MenuItemView* item = | |
159 parent->AppendMenuItemWithIcon(*item_id, label, *icon); | |
160 (*item_id)++; | |
161 return item; | |
162 } | |
OLD | NEW |