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

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: Added missing DropdownBarHostDelegate header file. 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 initialized_ = true;
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
88 AddChildView(back_);
89
90 bf_separator_ = new views::ImageView;
91 bf_separator_->SetImage(
92 resource_bundle.GetBitmapNamed(IDR_COMPACTNAV_SEPARATOR));
93 AddChildView(bf_separator_);
94
95 forward_ = new views::ButtonDropDown(this, forward_menu_model_.get());
96 forward_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN |
97 ui::EF_MIDDLE_BUTTON_DOWN);
98 forward_->set_tag(IDC_FORWARD);
99 forward_->SetTooltipText(
100 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)));
101 forward_->SetAccessibleName(l10n_util::GetStringUTF16((IDS_ACCNAME_FORWARD)));
102 forward_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
103 views::ImageButton::ALIGN_MIDDLE);
104 AddChildView(forward_);
105
106 LoadImages();
107 }
108
109 gfx::Size CompactNavigationBar::GetPreferredSize() {
110 int width = kBackButtonLeftMargin;
111 width += back_->GetPreferredSize().width() + kInnerPadding * 2;
112 width += kHorizMargin;
113 width += bf_separator_->GetPreferredSize().width();
114 width += kHorizMargin;
115 width += forward_->GetPreferredSize().width() + kInnerPadding * 2;
116 width += kForwardButtonRightMargin;
117 return gfx::Size(width, kPreferredHeight);
118 }
119
120 void CompactNavigationBar::Layout() {
121 if (!initialized_)
122 return;
123
124 // Layout forward/back buttons after entry views as follows:
125 // [Back]|[Forward]
126 int curx = kBackButtonLeftMargin;
127 // "Back | Forward" section.
128 gfx::Size button_size = back_->GetPreferredSize();
129 button_size.set_width(button_size.width() + kInnerPadding * 2);
130 back_->SetBounds(curx, 0, button_size.width(), height());
131 curx += button_size.width() + kHorizMargin;
132
133 button_size = bf_separator_->GetPreferredSize();
134 bf_separator_->SetBounds(curx, 0, button_size.width(), height());
135 curx += button_size.width() + kHorizMargin;
136
137 button_size = forward_->GetPreferredSize();
138 button_size.set_width(button_size.width() + kInnerPadding * 2);
139 forward_->SetBounds(curx, 0, button_size.width(), height());
140 }
141
142 ////////////////////////////////////////////////////////////////////////////////
143 // views::ButtonListener implementation.
144
145 void CompactNavigationBar::ButtonPressed(
146 views::Button* sender, const views::Event& event) {
147 browser_view_->browser()->ExecuteCommandWithDisposition(
148 sender->tag(),
149 event_utils::DispositionFromEventFlags(sender->mouse_event_flags()));
150 }
151
152 ////////////////////////////////////////////////////////////////////////////////
153 // CommandUpdater::CommandObserver implementation.
154 void CompactNavigationBar::EnabledStateChangedForCommand(int id, bool enabled) {
155 switch (id) {
156 case IDC_BACK:
157 back_->SetEnabled(enabled);
158 break;
159 case IDC_FORWARD:
160 forward_->SetEnabled(enabled);
161 break;
162 }
163 }
164
165 void CompactNavigationBar::LoadImages() {
166 ui::ThemeProvider* tp = GetThemeProvider();
167
168 // TODO(stevet): Hook up other button image resources like
169 // IDR_COMPACTNAV_FORWARD for the different button states.
170 back_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_BACK));
171 back_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_BACK_H));
172 back_->SetImage(views::CustomButton::BS_PUSHED,
173 tp->GetBitmapNamed(IDR_BACK_P));
174 back_->SetImage(views::CustomButton::BS_DISABLED,
175 tp->GetBitmapNamed(IDR_BACK_D));
176
177 forward_->SetImage(views::CustomButton::BS_NORMAL,
178 tp->GetBitmapNamed(IDR_FORWARD));
179 forward_->SetImage(views::CustomButton::BS_HOT,
180 tp->GetBitmapNamed(IDR_FORWARD_H));
181 forward_->SetImage(views::CustomButton::BS_PUSHED,
182 tp->GetBitmapNamed(IDR_FORWARD_P));
183 forward_->SetImage(views::CustomButton::BS_DISABLED,
184 tp->GetBitmapNamed(IDR_FORWARD_D));
185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698