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

Side by Side Diff: chrome/browser/ui/views/compact_nav/compact_navigation_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_navigation_bar.h"
6
7 #include "base/logging.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h"
14 #include "chrome/browser/ui/view_ids.h"
15 #include "chrome/browser/ui/views/event_utils.h"
16 #include "chrome/browser/ui/views/frame/browser_view.h"
17 #include "chrome/browser/ui/views/theme_background.h"
18 #include "content/browser/tab_contents/tab_contents.h"
19 #include "grit/generated_resources.h"
20 #include "grit/theme_resources.h"
21 #include "grit/theme_resources_standard.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/base/theme_provider.h"
25 #include "ui/gfx/canvas.h"
26 #include "views/controls/button/button_dropdown.h"
27 #include "views/controls/button/image_button.h"
28 #include "views/controls/image_view.h"
29 #include "views/controls/native/native_view_host.h"
30
31 // Padding inside each button around the image.
32 static const int kInnerPadding = 1;
33
34 // Spacing between buttons (excluding left/right most margin)
35 static const int kHorizMargin = 3;
36
37 // Left side margin of the back button to align with the main menu.
38 static const int kBackButtonLeftMargin = 10;
39
40 // Right side margin of the forward button to align with the main menu.
41 static const int kForwardButtonRightMargin = 1;
42
43 // Preferred height.
44 static const int kPreferredHeight = 25;
45
46 ////////////////////////////////////////////////////////////////////////////////
47 // CompactNavigationBar public:
48
49 CompactNavigationBar::CompactNavigationBar(::BrowserView* browser_view)
50 : browser_view_(browser_view),
51 initialized_(false) {
sky 2011/05/03 18:38:32 initialize back_, bf_separator_ and forward_ too.
SteveT 2011/05/06 18:48:43 Done.
52 }
53
54 CompactNavigationBar::~CompactNavigationBar() {
55 }
56
57 void CompactNavigationBar::Init() {
58 DCHECK(!initialized_);
59 initialized_ = true;
60 Browser* browser = browser_view_->browser();
61 browser->command_updater()->AddCommandObserver(IDC_BACK, this);
62 browser->command_updater()->AddCommandObserver(IDC_FORWARD, this);
sky 2011/05/03 18:38:32 I don't see you removing the observers.
SteveT 2011/05/06 18:48:43 Added Remove calls to the dtor. Moved the AddComma
63
64 back_menu_model_.reset(new BackForwardMenuModel(
65 browser, BackForwardMenuModel::BACKWARD_MENU));
66 forward_menu_model_.reset(new BackForwardMenuModel(
67 browser, BackForwardMenuModel::FORWARD_MENU));
68
69 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance();
70
71 back_ = new views::ButtonDropDown(this, back_menu_model_.get());
72 back_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN |
73 ui::EF_MIDDLE_BUTTON_DOWN);
74 back_->set_tag(IDC_BACK);
75 back_->SetTooltipText(
76 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK)));
77 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK));
78 back_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
79 views::ImageButton::ALIGN_MIDDLE);
80
81 AddChildView(back_);
82
83 bf_separator_ = new views::ImageView;
84 bf_separator_->SetImage(
85 resource_bundle.GetBitmapNamed(IDR_COMPACTNAV_SEPARATOR));
86 AddChildView(bf_separator_);
87
88 forward_ = new views::ButtonDropDown(this, forward_menu_model_.get());
89 forward_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN |
90 ui::EF_MIDDLE_BUTTON_DOWN);
91 forward_->set_tag(IDC_FORWARD);
92 forward_->SetTooltipText(
93 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)));
94 forward_->SetAccessibleName(l10n_util::GetStringUTF16((IDS_ACCNAME_FORWARD)));
95 forward_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
96 views::ImageButton::ALIGN_MIDDLE);
97 AddChildView(forward_);
98
99 LoadImages();
100 }
101
102 gfx::Size CompactNavigationBar::GetPreferredSize() {
103 int width = kBackButtonLeftMargin;
104 width += back_->GetPreferredSize().width() + kInnerPadding * 2;
105 width += kHorizMargin;
106 width += bf_separator_->GetPreferredSize().width();
107 width += kHorizMargin;
108 width += forward_->GetPreferredSize().width() + kInnerPadding * 2;
109 width += kForwardButtonRightMargin;
110 return gfx::Size(width, kPreferredHeight);
111 }
112
113 void CompactNavigationBar::Layout() {
114 if (!initialized_)
115 return;
116
117 // Layout forward/back buttons after entry views as follows:
118 // [Back]|[Forward]
119 int curx = kBackButtonLeftMargin;
120 // "Back | Forward" section.
121 gfx::Size button_size = back_->GetPreferredSize();
122 button_size.set_width(button_size.width() + kInnerPadding * 2);
123 back_->SetBounds(curx, 0, button_size.width(), height());
124 curx += button_size.width() + kHorizMargin;
125
126 button_size = bf_separator_->GetPreferredSize();
127 bf_separator_->SetBounds(curx, 0, button_size.width(), height());
128 curx += button_size.width() + kHorizMargin;
129
130 button_size = forward_->GetPreferredSize();
131 button_size.set_width(button_size.width() + kInnerPadding * 2);
132 forward_->SetBounds(curx, 0, button_size.width(), height());
133 }
134
135 void CompactNavigationBar::OnPaint(gfx::Canvas* canvas) {
sky 2011/05/03 18:38:32 View::OnPaint invokes OnPaintBackground. Do you ne
SteveT 2011/05/06 18:48:43 Yeah you're right, this isn't needed. Removed.
136 OnPaintBackground(canvas);
137 }
138
139 ////////////////////////////////////////////////////////////////////////////////
140 // views::ButtonListener implementation.
141
142 void CompactNavigationBar::ButtonPressed(
143 views::Button* sender, const views::Event& event) {
144 browser_view_->browser()->ExecuteCommandWithDisposition(
145 sender->tag(),
146 event_utils::DispositionFromEventFlags(sender->mouse_event_flags()));
147 }
148
149 ////////////////////////////////////////////////////////////////////////////////
150 // CommandUpdater::CommandObserver implementation.
151 void CompactNavigationBar::EnabledStateChangedForCommand(int id, bool enabled) {
152 switch (id) {
153 case IDC_BACK:
154 back_->SetEnabled(enabled);
155 break;
156 case IDC_FORWARD:
157 forward_->SetEnabled(enabled);
158 break;
159 }
160 }
161
162 void CompactNavigationBar::LoadImages() {
163 ui::ThemeProvider* tp = GetThemeProvider();
164
165 // TODO: Hook up other button image resources like IDR_COMPACTNAV_FORWARD for
166 // the different button states.
167 back_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_BACK));
168 back_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_BACK_H));
169 back_->SetImage(views::CustomButton::BS_PUSHED,
170 tp->GetBitmapNamed(IDR_BACK_P));
171 back_->SetImage(views::CustomButton::BS_DISABLED,
172 tp->GetBitmapNamed(IDR_BACK_D));
173
174 forward_->SetImage(views::CustomButton::BS_NORMAL,
175 tp->GetBitmapNamed(IDR_FORWARD));
176 forward_->SetImage(views::CustomButton::BS_HOT,
177 tp->GetBitmapNamed(IDR_FORWARD_H));
178 forward_->SetImage(views::CustomButton::BS_PUSHED,
179 tp->GetBitmapNamed(IDR_FORWARD_P));
180 forward_->SetImage(views::CustomButton::BS_DISABLED,
181 tp->GetBitmapNamed(IDR_FORWARD_D));
182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698