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

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: Clang build fix. After commit/revert. 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
Property Changes:
Added: svn:eol-style
+ LF
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),
52 back_(NULL),
53 bf_separator_(NULL),
54 forward_(NULL) {
55 Browser* browser = browser_view_->browser();
56 browser->command_updater()->AddCommandObserver(IDC_BACK, this);
57 browser->command_updater()->AddCommandObserver(IDC_FORWARD, this);
58 }
59
60 CompactNavigationBar::~CompactNavigationBar() {
61 Browser* browser = browser_view_->browser();
62 browser->command_updater()->RemoveCommandObserver(IDC_BACK, this);
63 browser->command_updater()->RemoveCommandObserver(IDC_FORWARD, this);
64 }
65
66 void CompactNavigationBar::Init() {
67 DCHECK(!initialized_);
68
69 Browser* browser = browser_view_->browser();
70
71 back_menu_model_.reset(new BackForwardMenuModel(
72 browser, BackForwardMenuModel::BACKWARD_MENU));
73 forward_menu_model_.reset(new BackForwardMenuModel(
74 browser, BackForwardMenuModel::FORWARD_MENU));
75
76 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance();
77
78 back_ = new views::ButtonDropDown(this, back_menu_model_.get());
79 back_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN |
80 ui::EF_MIDDLE_BUTTON_DOWN);
81 back_->set_tag(IDC_BACK);
82 back_->SetTooltipText(
83 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK)));
84 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK));
85 back_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
86 views::ImageButton::ALIGN_MIDDLE);
87 AddChildView(back_);
88
89 bf_separator_ = new views::ImageView;
90 bf_separator_->SetImage(
91 resource_bundle.GetBitmapNamed(IDR_COMPACTNAV_SEPARATOR));
92 AddChildView(bf_separator_);
93
94 forward_ = new views::ButtonDropDown(this, forward_menu_model_.get());
95 forward_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN |
96 ui::EF_MIDDLE_BUTTON_DOWN);
97 forward_->set_tag(IDC_FORWARD);
98 forward_->SetTooltipText(
99 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)));
100 forward_->SetAccessibleName(l10n_util::GetStringUTF16((IDS_ACCNAME_FORWARD)));
101 forward_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
102 views::ImageButton::ALIGN_MIDDLE);
103 AddChildView(forward_);
104
105 LoadImages();
106
107 initialized_ = true;
108 }
109
110 gfx::Size CompactNavigationBar::GetPreferredSize() {
111 int width = kBackButtonLeftMargin;
112 width += back_->GetPreferredSize().width() + kInnerPadding * 2;
113 width += kHorizMargin;
114 width += bf_separator_->GetPreferredSize().width();
115 width += kHorizMargin;
116 width += forward_->GetPreferredSize().width() + kInnerPadding * 2;
117 width += kForwardButtonRightMargin;
118 return gfx::Size(width, kPreferredHeight);
119 }
120
121 void CompactNavigationBar::Layout() {
122 if (!initialized_)
123 return;
124
125 // Layout forward/back buttons after entry views as follows:
126 // [Back]|[Forward]
127 int curx = kBackButtonLeftMargin;
128 // "Back | Forward" section.
129 gfx::Size button_size = back_->GetPreferredSize();
130 button_size.set_width(button_size.width() + kInnerPadding * 2);
131 back_->SetBounds(curx, 0, button_size.width(), height());
132 curx += button_size.width() + kHorizMargin;
133
134 button_size = bf_separator_->GetPreferredSize();
135 bf_separator_->SetBounds(curx, 0, button_size.width(), height());
136 curx += button_size.width() + kHorizMargin;
137
138 button_size = forward_->GetPreferredSize();
139 button_size.set_width(button_size.width() + kInnerPadding * 2);
140 forward_->SetBounds(curx, 0, button_size.width(), height());
141 }
142
143 ////////////////////////////////////////////////////////////////////////////////
144 // views::ButtonListener implementation.
145
146 void CompactNavigationBar::ButtonPressed(
147 views::Button* sender, const views::Event& event) {
148 browser_view_->browser()->ExecuteCommandWithDisposition(
149 sender->tag(),
150 event_utils::DispositionFromEventFlags(sender->mouse_event_flags()));
151 }
152
153 ////////////////////////////////////////////////////////////////////////////////
154 // CommandUpdater::CommandObserver implementation.
155 void CompactNavigationBar::EnabledStateChangedForCommand(int id, bool enabled) {
156 switch (id) {
157 case IDC_BACK:
158 back_->SetEnabled(enabled);
159 break;
160 case IDC_FORWARD:
161 forward_->SetEnabled(enabled);
162 break;
163 }
164 }
165
166 void CompactNavigationBar::LoadImages() {
167 ui::ThemeProvider* tp = GetThemeProvider();
168
169 // TODO(stevet): Hook up other button image resources like
170 // IDR_COMPACTNAV_FORWARD for the different button states.
171 back_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_BACK));
172 back_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_BACK_H));
173 back_->SetImage(views::CustomButton::BS_PUSHED,
174 tp->GetBitmapNamed(IDR_BACK_P));
175 back_->SetImage(views::CustomButton::BS_DISABLED,
176 tp->GetBitmapNamed(IDR_BACK_D));
177
178 forward_->SetImage(views::CustomButton::BS_NORMAL,
179 tp->GetBitmapNamed(IDR_FORWARD));
180 forward_->SetImage(views::CustomButton::BS_HOT,
181 tp->GetBitmapNamed(IDR_FORWARD_H));
182 forward_->SetImage(views::CustomButton::BS_PUSHED,
183 tp->GetBitmapNamed(IDR_FORWARD_P));
184 forward_->SetImage(views::CustomButton::BS_DISABLED,
185 tp->GetBitmapNamed(IDR_FORWARD_D));
186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698