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 // Included for MENU_POPUPITEM and a few other Windows specific constants. | |
20 #include <vssym32.h> | |
21 #include "ui/base/native_theme/native_theme_win.h" | |
22 #endif | |
23 | |
24 //////////////////////////////////////////////////////////////////////////////// | |
25 // ActionBoxMenu | |
26 | |
27 ActionBoxMenu::ActionBoxMenu(Browser* browser, | |
28 ActionBoxMenuModel* model, | |
29 bool bookmark_item_state) | |
30 : browser_(browser), | |
31 root_(NULL), | |
32 model_(model), | |
33 bookmark_item_state_(bookmark_item_state) { | |
34 } | |
35 | |
36 ActionBoxMenu::~ActionBoxMenu() { | |
37 } | |
38 | |
39 void ActionBoxMenu::Init() { | |
40 DCHECK(!root_); | |
41 root_ = new views::MenuItemView(this); | |
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 // This menu is not deletable, | |
Peter Kasting
2012/07/26 20:37:17
Nit: Mike was wrong, this menu is in fact deletabl
yefimt
2012/07/31 00:10:11
Done.
| |
51 // ignore the result since we don't need to handle a deleted menu specially. | |
52 ignore_result( | |
53 menu_runner_->RunMenuAt(menu_button->GetWidget(), | |
54 menu_button, | |
55 gfx::Rect(screen_location, menu_button->size()), | |
56 views::MenuItemView::TOPRIGHT, | |
57 views::MenuRunner::HAS_MNEMONICS)); | |
58 } | |
59 | |
60 void ActionBoxMenu::ExecuteCommand(int id) { | |
61 }; | |
62 | |
63 views::Border* ActionBoxMenu::CreateMenuBorder() { | |
64 // TODO(yefim): Use correct theme color on non-Windows. | |
65 SkColor border_color = SK_ColorBLACK; | |
66 #if defined(OS_WIN) | |
67 // TODO(yefim): Move to Windows only files if possible. | |
68 border_color = ui::NativeThemeWin::instance()->GetThemeColorWithDefault( | |
69 ui::NativeThemeWin::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR, | |
70 COLOR_MENUTEXT); | |
71 #endif | |
72 return views::Border::CreateSolidBorder(1, border_color); | |
73 } | |
74 | |
75 views::Background* ActionBoxMenu::CreateMenuBackground() { | |
76 // TODO(yefim): Use correct theme color on non-Windows. | |
77 SkColor background_color = SK_ColorWHITE; | |
78 #if defined(OS_WIN) | |
79 // TODO(yefim): Move to Windows only files if possible. | |
80 background_color = ui::NativeThemeWin::instance()->GetThemeColorWithDefault( | |
81 ui::NativeThemeWin::TEXTFIELD, EP_BACKGROUND, EBS_NORMAL, | |
82 TMT_BACKGROUND, COLOR_WINDOW); | |
83 #endif | |
84 return views::Background::CreateSolidBackground(background_color); | |
85 } | |
86 | |
87 int ActionBoxMenu::GetCurrentTabId() const { | |
88 return 0; | |
89 } | |
90 | |
91 void ActionBoxMenu::OnBrowserActionExecuted(BrowserActionButton* button) { | |
92 } | |
93 | |
94 void ActionBoxMenu::OnBrowserActionVisibilityChanged() { | |
95 } | |
96 | |
97 gfx::Size ActionBoxMenu::GetViewContentOffset() const { | |
98 return gfx::Size(0, 0); | |
99 } | |
100 | |
101 void ActionBoxMenu::WriteDragDataForView(views::View* sender, | |
102 const gfx::Point& press_pt, | |
103 ui::OSExchangeData* data) { | |
104 } | |
105 | |
106 int ActionBoxMenu::GetDragOperationsForView(views::View* sender, | |
107 const gfx::Point& p) { | |
108 return 0; | |
109 } | |
110 | |
111 bool ActionBoxMenu::CanStartDragForView(views::View* sender, | |
112 const gfx::Point& press_pt, | |
113 const gfx::Point& p) { | |
114 return false; | |
115 } | |
116 | |
117 void ActionBoxMenu::Observe(int type, | |
118 const content::NotificationSource& source, | |
119 const content::NotificationDetails& details) { | |
120 } | |
121 | |
122 void ActionBoxMenu::PopulateMenu() { | |
123 int item_id = 1; | |
124 AddBookmarkMenuItem(root_, &item_id); | |
125 if (model_->GetItemCount() > 0) | |
126 root_->AppendSeparator(); | |
127 | |
128 for (int model_index = 0; model_index < model_->GetItemCount(); | |
129 ++model_index) { | |
130 views::MenuItemView* menu_item = root_->AppendMenuItemFromModel( | |
131 model_, model_index, item_id + model_index); | |
132 if (model_->GetTypeAt(model_index) == ui::MenuModel::TYPE_COMMAND) { | |
Peter Kasting
2012/07/26 20:37:17
Nit: I agree with Mike that this should be a DCHEC
yefimt
2012/07/31 00:10:11
Done.
| |
133 menu_item->SetMargins(0, 0); | |
134 const extensions::Extension* extension = | |
135 model_->GetActionBoxExtensionByIndex(model_index); | |
136 BrowserActionView* view = new BrowserActionView(extension, | |
137 browser_, this); | |
138 view->button()->SetShowMultipleIconStates(false); | |
Peter Kasting
2012/07/26 20:37:17
I reiterate: Why are these calls happening here in
yefimt
2012/07/31 00:10:11
Done.
| |
139 view->button()->SetTooltipDisabled(true); | |
140 browser_action_views_.push_back(view); | |
141 menu_item->SetIconView(view); | |
142 } | |
143 } | |
144 } | |
145 | |
146 views::MenuItemView* ActionBoxMenu::AddBookmarkMenuItem( | |
147 views::MenuItemView* parent, | |
148 int* item_id) { | |
149 string16 label = l10n_util::GetStringUTF16(bookmark_item_state_ ? | |
150 IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR); | |
151 gfx::ImageSkia* icon = | |
152 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
153 bookmark_item_state_ ? IDR_STAR_LIT : IDR_STAR); | |
154 views::MenuItemView* item = | |
155 parent->AppendMenuItemWithIcon(*item_id, label, *icon); | |
156 (*item_id)++; | |
157 return item; | |
158 } | |
OLD | NEW |