Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: chrome/browser/ui/views/action_box_menu.cc

Issue 10533086: Action box menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Action box menu Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #if defined(OS_WIN)
8 #include <vssym32.h>
9 #endif
Peter Kasting 2012/07/21 01:55:13 Nit: All #ifdefed #includes should go below all th
yefimt 2012/07/23 23:47:52 Done.
10
11 #include "chrome/browser/ui/toolbar/action_box_menu_model.h"
12 #include "chrome/browser/ui/views/browser_action_view.h"
13 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h"
15 #if defined(OS_WIN)
16 #include "ui/base/native_theme/native_theme_win.h"
17 #endif
18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/views/bubble/bubble_border.h"
21 #include "ui/views/controls/button/menu_button.h"
22 #include "ui/views/controls/menu/menu_runner.h"
23 #include "ui/views/view.h"
24
25 ////////////////////////////////////////////////////////////////////////////////
26 // ActionBoxMenu
27
28 ActionBoxMenu::ActionBoxMenu(Browser* browser,
29 ActionBoxMenuModel* model,
30 bool bookmark_item_state)
31 : browser_(browser),
32 root_(NULL),
33 model_(model),
34 bookmark_item_state_(bookmark_item_state) {
35 }
36
37 ActionBoxMenu::~ActionBoxMenu() {
38 }
39
40 void ActionBoxMenu::Init() {
41 DCHECK(!root_);
42 root_ = new views::MenuItemView(this);
43 // We have icons, set this so we get the taller menu style.
44 root_->set_has_icons(true);
45 PopulateMenu();
46 menu_runner_.reset(new views::MenuRunner(root_));
47 }
48
49 void ActionBoxMenu::RunMenu(views::MenuButton* menu_button) {
50 gfx::Point screen_location;
51 views::View::ConvertPointToScreen(menu_button, &screen_location);
52 // Ignore the result since we don't need to handle a deleted menu specially.
53 ignore_result(
54 menu_runner_->RunMenuAt(menu_button->GetWidget(),
55 menu_button,
56 gfx::Rect(screen_location, menu_button->size()),
57 views::MenuItemView::TOPRIGHT,
58 views::MenuRunner::HAS_MNEMONICS));
59 }
60
61 void ActionBoxMenu::ExecuteCommand(int id) {
62 };
63
64 views::Border* ActionBoxMenu::CreateMenuBorder() {
65 #if defined(OS_WIN)
Peter Kasting 2012/07/21 01:55:13 Nit: I'd #ifdef as little as possible, and add a T
yefimt 2012/07/23 23:47:52 Done.
66 SkColor border_color =
67 ui::NativeThemeWin::instance()->GetThemeColorWithDefault(
Peter Kasting 2012/07/21 01:55:13 Not necessary for this change, but it would be nic
yefimt 2012/07/23 23:47:52 OK
68 ui::NativeThemeWin::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR,
69 COLOR_MENUTEXT);
70 return views::Border::CreateSolidBorder(1, border_color);
71 #else
72 return views::Border::CreateSolidBorder(1, SkColorSetRGB(0, 0, 0));
73 #endif
74 }
75
76 views::Background* ActionBoxMenu::CreateMenuBackground() {
77 #if defined(OS_WIN)
78 SkColor background_color =
79 ui::NativeThemeWin::instance()->GetThemeColorWithDefault(
80 ui::NativeThemeWin::TEXTFIELD, EP_BACKGROUND, EBS_NORMAL,
81 TMT_BACKGROUND, COLOR_WINDOW);
82 return views::Background::CreateSolidBackground(background_color);
83 #else
84 return views::Background::CreateSolidBackground(SkColorSetRGB(255, 255, 255));
85 #endif
86 }
87
88 int ActionBoxMenu::GetCurrentTabId() const {
89 return 0;
90 }
91
92 void ActionBoxMenu::OnBrowserActionExecuted(BrowserActionButton* button) {
93 }
94
95 void ActionBoxMenu::OnBrowserActionVisibilityChanged() {
96 }
97
98 gfx::Size ActionBoxMenu::GetViewContentOffset() const {
99 return gfx::Size(0, 0);
100 }
101
102 void ActionBoxMenu::WriteDragDataForView(views::View* sender,
103 const gfx::Point& press_pt,
104 ui::OSExchangeData* data) {
105 }
106
107 int ActionBoxMenu::GetDragOperationsForView(views::View* sender,
108 const gfx::Point& p) {
109 return 0;
110 }
111
112 bool ActionBoxMenu::CanStartDragForView(views::View* sender,
113 const gfx::Point& press_pt,
114 const gfx::Point& p) {
115 return false;
116 }
117
118 void ActionBoxMenu::Observe(int type,
119 const content::NotificationSource& source,
120 const content::NotificationDetails& details) {
121 }
122
123 void ActionBoxMenu::PopulateMenu() {
124 int item_id = 1;
125 AddBookmarkMenuItem(root_, &item_id);
126 if (model_->GetItemCount() > 0)
127 root_->AppendSeparator();
128
129 for (int model_index = 0; model_index < model_->GetItemCount();
130 ++model_index) {
131 views::MenuItemView* menu_item = root_->AppendMenuItemFromModel(
132 model_, model_index, item_id + model_index);
133 if (model_->GetTypeAt(model_index) == ui::MenuModel::TYPE_COMMAND) {
134 menu_item->SetMargins(0, 0);
135 const extensions::Extension* extension =
136 model_->GetActionBoxExtensionByIndex(model_index);
137 BrowserActionView* view = new BrowserActionView(extension,
138 browser_, this);
139 view->button()->SetShowMultipleIconStates(false);
140 view->button()->SetTooltipDisabled(true);
141 browser_action_views_.push_back(view);
142 menu_item->SetIconView(view);
143 }
144 }
145 }
146
147 views::MenuItemView* ActionBoxMenu::AddBookmarkMenuItem(
148 views::MenuItemView* parent,
149 int* item_id) {
150 string16 label = l10n_util::GetStringUTF16(bookmark_item_state_ ?
151 IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR);
152 gfx::ImageSkia* icon =
153 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
154 bookmark_item_state_ ? IDR_STAR_LIT : IDR_STAR);
155 DCHECK(icon);
156 views::MenuItemView* item =
157 parent->AppendMenuItemWithIcon(*item_id, label, *icon);
158 (*item_id)++;
159 return item;
160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698