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

Side by Side Diff: chrome/browser/ui/views/compact_nav/compact_options_bar.cc

Issue 6913026: Compact Navigation prototype (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 7 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) 2011 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/compact_nav/compact_options_bar.h"
6
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/ui/toolbar/wrench_menu_model.h"
9 #include "chrome/browser/ui/view_ids.h"
10 #include "chrome/browser/ui/views/event_utils.h"
11 #include "chrome/browser/ui/views/frame/browser_view.h"
12 #include "chrome/browser/ui/views/toolbar_view.h"
13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/canvas.h"
18
19 namespace {
20 const int kPreferredHeight = 25;
sky 2011/05/03 18:38:32 no indentation in a namespace
SteveT 2011/05/06 18:48:43 Done.
21 // Pad the left and right ends from other tabstrip region items.
22 const int kEndPadding = 3;
23 }
24
25 ////////////////////////////////////////////////////////////////////////////////
26 // CompactOptionsBar public:
27
28 CompactOptionsBar::CompactOptionsBar(BrowserView* browser_view)
29 : browser_view_(browser_view),
30 initialized_(false),
31 app_menu_(NULL),
32 destroyed_flag_(NULL) {
33 }
34
35 CompactOptionsBar::~CompactOptionsBar() {
36 if (destroyed_flag_)
37 *destroyed_flag_ = true;
38 }
39
40 void CompactOptionsBar::Init() {
41 DCHECK(!initialized_);
42 initialized_ = true;
43
44 wrench_menu_model_.reset(new WrenchMenuModel(this, browser_view_->browser()));
45
46 app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false);
47 app_menu_->set_border(NULL);
48 app_menu_->EnableCanvasFlippingForRTLUI(true);
49 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP));
50 app_menu_->SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16(
51 IDS_APPMENU_TOOLTIP,
52 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))));
53 app_menu_->SetID(VIEW_ID_APP_MENU);
54 AddChildView(app_menu_);
55
56 LoadImages();
57 }
58
59 gfx::Size CompactOptionsBar::GetPreferredSize() {
60 int width = kEndPadding * 2 + app_menu_->GetPreferredSize().width();
61 // TODO(stevet): Add the width of the browser actions container here when that
62 // is added to the bar.
63 return gfx::Size(width, kPreferredHeight);
64 }
65
66 void CompactOptionsBar::Layout() {
67 if (!initialized_)
68 return;
69
70 int curx = kEndPadding;
71 gfx::Size button_size = app_menu_->GetPreferredSize();
72 app_menu_->SetBounds(curx, 0, button_size.width(), height());
sky 2011/05/03 18:38:32 You don't really need curx here.
SteveT 2011/05/06 18:48:43 Oops, yeah. Removing this for now, but we'll bring
73 curx += button_size.width();
74 }
75
76 void CompactOptionsBar::OnPaint(gfx::Canvas* canvas) {
77 OnPaintBackground(canvas);
sky 2011/05/03 18:38:32 Do you really need to override this?
SteveT 2011/05/06 18:48:43 No - removed.
78 }
79
80 void CompactOptionsBar::AddMenuListener(views::MenuListener* listener) {
81 menu_listeners_.push_back(listener);
82 }
83
84 void CompactOptionsBar::RemoveMenuListener(views::MenuListener* listener) {
85 for (std::vector<views::MenuListener*>::iterator i(menu_listeners_.begin());
86 i != menu_listeners_.end(); ++i) {
sky 2011/05/03 18:38:32 indentation is off.
SteveT 2011/05/06 18:48:43 Done.
87 if (*i == listener) {
88 menu_listeners_.erase(i);
89 return;
90 }
91 }
92 }
93
94 ////////////////////////////////////////////////////////////////////////////////
95 // CompactOptionsBar, views::MenuDelegate implementation:
96
97 void CompactOptionsBar::RunMenu(views::View* source,
98 const gfx::Point& /* pt */) {
99 DCHECK_EQ(VIEW_ID_APP_MENU, source->GetID());
100
101 bool destroyed_flag = false;
102 destroyed_flag_ = &destroyed_flag;
103 wrench_menu_ = new WrenchMenu(browser_view_->browser());
104 wrench_menu_->Init(wrench_menu_model_.get());
105
106 for (size_t i = 0; i < menu_listeners_.size(); ++i)
107 menu_listeners_[i]->OnMenuOpened();
108
109 wrench_menu_->RunMenu(app_menu_);
110
111 if (destroyed_flag)
sky 2011/05/03 18:38:32 Given you've got nothing after destroyed_flag_, do
SteveT 2011/05/06 18:48:43 That is a good point - do you want me to get ride
sky 2011/05/06 19:56:06 Sure, but in a separate patch please.
SteveT 2011/05/06 22:13:40 Noted.
112 return;
113 destroyed_flag_ = NULL;
114 }
115
116 ////////////////////////////////////////////////////////////////////////////////
117 // CompactOptionsBar, ui::AcceleratorProvider implementation:
118
119 bool CompactOptionsBar::GetAcceleratorForCommandId(int command_id,
120 ui::Accelerator* accelerator) {
121 // TODO(stevet): Can we share ToolbarView's implementation? It's exactly the
122 // same so far.
123 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators
124 // anywhere so we need to check for them explicitly here.
125 // TODO(cpu) Bug 1109102. Query WebKit land for the actual bindings.
126 switch (command_id) {
127 case IDC_CUT:
128 *accelerator = views::Accelerator(ui::VKEY_X, false, true, false);
129 return true;
130 case IDC_COPY:
131 *accelerator = views::Accelerator(ui::VKEY_C, false, true, false);
132 return true;
133 case IDC_PASTE:
134 *accelerator = views::Accelerator(ui::VKEY_V, false, true, false);
135 return true;
136 }
137 // Else, we retrieve the accelerator information from the frame.
138 return GetWidget()->GetAccelerator(command_id, accelerator);
139 }
140
141 ////////////////////////////////////////////////////////////////////////////////
142 // CompactOptionsBar, views::ButtonListener implementation.
143
144 void CompactOptionsBar::ButtonPressed(views::Button* sender,
145 const views::Event& event) {
146 browser_view_->browser()->ExecuteCommandWithDisposition(
147 sender->tag(),
148 event_utils::DispositionFromEventFlags(sender->mouse_event_flags()));
149 }
150
151 void CompactOptionsBar::LoadImages() {
152 // Reuse the resources loaded for the Toolbar's AppMenu.
153 DCHECK(browser_view_->toolbar());
154 app_menu_->SetIcon(browser_view_->toolbar()->GetAppMenuIcon(
155 views::CustomButton::BS_NORMAL));
156 app_menu_->SetHoverIcon(browser_view_->toolbar()->GetAppMenuIcon(
157 views::CustomButton::BS_HOT));
158 app_menu_->SetPushedIcon(browser_view_->toolbar()->GetAppMenuIcon(
159 views::CustomButton::BS_PUSHED));
160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698