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

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 #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 // ActionBoxMenu ---------------------------------------------------------------
Peter Kasting 2012/07/14 02:08:01 In some files you use dividers like: /////////...
yefimt 2012/07/17 18:20:37 Done.
19 ActionBoxMenu::ActionBoxMenu(Browser* browser,
Peter Kasting 2012/07/14 02:08:01 Nit: Blank line here
yefimt 2012/07/17 18:20:37 Done.
20 ActionBoxMenuModel* model,
21 bool bookmark_item_state)
22 : browser_(browser),
23 root_(NULL),
24 model_(model),
25 bookmark_item_state_(bookmark_item_state) {
26 }
27
28 ActionBoxMenu::~ActionBoxMenu() {
29 }
30
31 void ActionBoxMenu::Init() {
32 CHECK(!root_);
33 root_ = new views::MenuItemView(this);
34 // We have icons, set this so we get the taller menu style.
35 root_->set_has_icons(true);
36 PopulateMenu();
37 menu_runner_.reset(new views::MenuRunner(root_));
38 }
39
40 void ActionBoxMenu::RunMenu(views::MenuButton* host) {
41 gfx::Point screen_location;
42 views::View::ConvertPointToScreen(host, &screen_location);
43 gfx::Rect bounds(screen_location, host->size());
Peter Kasting 2012/07/14 02:08:01 Nit: Inline into next statement
yefimt 2012/07/17 18:20:37 Done.
44 if (menu_runner_->RunMenuAt(host->GetWidget(),
Peter Kasting 2012/07/14 02:08:01 You're not doing anything special for MENU_DELETED
yefimt 2012/07/17 18:20:37 Done.
45 host,
46 bounds,
47 views::MenuItemView::TOPRIGHT,
48 views::MenuRunner::HAS_MNEMONICS) ==
49 views::MenuRunner::MENU_DELETED) {
50 return;
51 }
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));
Peter Kasting 2012/07/14 02:08:01 Don't hardcode colors. You need to use the approp
yefimt 2012/07/17 18:20:37 I don't have written specs yet, just mocks, but I'
59 }
yefimt 2012/07/18 23:18:13 Can I do it later. This border is temporary, only
Peter Kasting 2012/07/19 04:27:31 Yes, doing it later is fine.
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;
Peter Kasting 2012/07/14 02:08:01 Nit: If you name this |bookmark_item_id|, you can
yefimt 2012/07/17 18:20:37 It is going to be a couple more menu items soon (b
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);
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, int* item_id) {
Peter Kasting 2012/07/14 02:08:01 Nit: One arg per line
yefimt 2012/07/17 18:20:37 Done.
130 string16 label =
Peter Kasting 2012/07/14 02:08:01 Nit: Wrap like: string16 label = l10n_util::Get
yefimt 2012/07/17 18:20:37 Done.
131 l10n_util::GetStringUTF16(bookmark_item_state_ ? IDS_TOOLTIP_STARRED :
132 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698