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

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 <Vssym32.h>
6
7 #include "chrome/browser/ui/views/action_box_menu.h"
8
9 #include "chrome/browser/ui/toolbar/action_box_menu_model.h"
10 #include "chrome/browser/ui/views/browser_action_view.h"
11 #include "grit/generated_resources.h"
12 #include "grit/theme_resources.h"
13 #include "ui/base/native_theme/native_theme_win.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/views/bubble/bubble_border.h"
17 #include "ui/views/controls/button/menu_button.h"
18 #include "ui/views/controls/menu/menu_runner.h"
19 #include "ui/views/view.h"
20
21 ////////////////////////////////////////////////////////////////////////////////
22 // ActionBoxMenu
23
24 ActionBoxMenu::ActionBoxMenu(Browser* browser,
25 ActionBoxMenuModel* model,
26 bool bookmark_item_state)
27 : browser_(browser),
28 root_(NULL),
29 model_(model),
30 bookmark_item_state_(bookmark_item_state) {
31 }
32
33 ActionBoxMenu::~ActionBoxMenu() {
34 }
35
36 void ActionBoxMenu::Init() {
37 CHECK(!root_);
38 root_ = new views::MenuItemView(this);
39 // We have icons, set this so we get the taller menu style.
40 root_->set_has_icons(true);
41 PopulateMenu();
42 menu_runner_.reset(new views::MenuRunner(root_));
43 }
44
45 void ActionBoxMenu::RunMenu(views::MenuButton* menu_button) {
46 gfx::Point screen_location;
47 views::View::ConvertPointToScreen(menu_button, &screen_location);
48 // Ignore the result since we don't need to handle a deleted menu specially.
49 ignore_result(
50 menu_runner_->RunMenuAt(menu_button->GetWidget(),
51 menu_button,
52 gfx::Rect(screen_location, menu_button->size()),
53 views::MenuItemView::TOPRIGHT,
54 views::MenuRunner::HAS_MNEMONICS));
55 }
56
57 void ActionBoxMenu::ExecuteCommand(int id) {
58 };
59
60 views::Border* ActionBoxMenu::CreateMenuBorder() {
61 SkColor border_color =
62 ui::NativeThemeWin::instance()->GetThemeColorWithDefault(
63 ui::NativeThemeWin::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR,
64 COLOR_MENUTEXT);
65 return views::Border::CreateSolidBorder(1, border_color);
66 }
67
68 views::Background* ActionBoxMenu::CreateMenuBackground() {
69 SkColor background_color =
70 ui::NativeThemeWin::instance()->GetThemeColorWithDefault(
71 ui::NativeThemeWin::TEXTFIELD, EP_BACKGROUND, EBS_NORMAL,
72 TMT_BACKGROUND, COLOR_WINDOW);
73 return views::Background::CreateSolidBackground(background_color);
74 }
75
76 int ActionBoxMenu::GetCurrentTabId() const {
77 return 0;
78 }
79
80 void ActionBoxMenu::OnBrowserActionExecuted(BrowserActionButton* button) {
81 }
82
83 void ActionBoxMenu::OnBrowserActionVisibilityChanged() {
84 }
85
86 gfx::Size ActionBoxMenu::GetViewContentOffset() const {
87 return gfx::Size(0, 0);
88 }
89
90 void ActionBoxMenu::WriteDragDataForView(views::View* sender,
91 const gfx::Point& press_pt,
92 ui::OSExchangeData* data) {
93 }
94
95 int ActionBoxMenu::GetDragOperationsForView(views::View* sender,
96 const gfx::Point& p) {
97 return 0;
98 }
99
100 bool ActionBoxMenu::CanStartDragForView(views::View* sender,
101 const gfx::Point& press_pt,
102 const gfx::Point& p) {
103 return false;
104 }
105
106 void ActionBoxMenu::Observe(int type,
107 const content::NotificationSource& source,
108 const content::NotificationDetails& details) {
109 }
110
111 void ActionBoxMenu::PopulateMenu() {
112 int item_id = 1;
113 AddBookmarkMenuItem(root_, &item_id);
114 if (model_->GetItemCount() > 0)
115 root_->AppendSeparator();
116
117 for (int model_index = 0; model_index < model_->GetItemCount();
118 ++model_index) {
119 views::MenuItemView* menu_item = root_->AppendMenuItemFromModel(
120 model_, model_index, item_id + model_index);
121 if (model_->GetTypeAt(model_index) == ui::MenuModel::TYPE_COMMAND) {
122 menu_item->SetMargins(0, 0);
123 const extensions::Extension* extension =
124 model_->GetActionBoxExtensionByIndex(model_index);
125 BrowserActionView* view = new BrowserActionView(extension,
126 browser_, this);
127 view->button()->SetShowMultipleIconStates(false);
128 view->button()->SetTooltipDisabled(true);
129 browser_action_views_.push_back(view);
130 menu_item->SetIconView(view);
131 }
132 }
133 }
134
135 views::MenuItemView* ActionBoxMenu::AddBookmarkMenuItem(
136 views::MenuItemView* parent,
137 int* item_id) {
138 string16 label = l10n_util::GetStringUTF16(bookmark_item_state_ ?
139 IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR);
140 gfx::ImageSkia* icon =
141 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
142 bookmark_item_state_ ? IDR_STAR_LIT : IDR_STAR);
143 DCHECK(icon);
144 views::MenuItemView* item =
145 parent->AppendMenuItemWithIcon(*item_id, label, *icon);
146 (*item_id)++;
147 return item;
148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698