1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/compact_navigation_bar.h"
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "app/theme_provider.h"
#include "base/logging.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/back_forward_menu_model.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_theme_provider.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/view_ids.h"
#include "chrome/browser/views/event_utils.h"
#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/browser/views/theme_background.h"
#include "gfx/canvas.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "views/controls/button/button_dropdown.h"
#include "views/controls/button/image_button.h"
#include "views/controls/image_view.h"
#include "views/controls/native/native_view_host.h"
namespace chromeos {
// Padding inside each button around the image.
static const int kInnerPadding = 1;
// Spacing between buttons (excluding left/right most margin)
static const int kHorizMargin = 3;
// Left side margin of the back button to align with the main menu.
static const int kBackButtonLeftMargin = 10;
// Right side margin of the forward button to align with the main menu.
static const int kForwardButtonRightMargin = 1;
// Preferred height.
static const int kPreferredHeight = 25;
////////////////////////////////////////////////////////////////////////////////
// CompactNavigationBar public:
CompactNavigationBar::CompactNavigationBar(::BrowserView* browser_view)
: browser_view_(browser_view),
initialized_(false) {
}
CompactNavigationBar::~CompactNavigationBar() {
}
void CompactNavigationBar::Init() {
DCHECK(!initialized_);
initialized_ = true;
Browser* browser = browser_view_->browser();
browser->command_updater()->AddCommandObserver(IDC_BACK, this);
browser->command_updater()->AddCommandObserver(IDC_FORWARD, this);
back_menu_model_.reset(new BackForwardMenuModel(
browser, BackForwardMenuModel::BACKWARD_MENU));
forward_menu_model_.reset(new BackForwardMenuModel(
browser, BackForwardMenuModel::FORWARD_MENU));
ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance();
back_ = new views::ButtonDropDown(this, back_menu_model_.get());
back_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN |
views::Event::EF_MIDDLE_BUTTON_DOWN);
back_->set_tag(IDC_BACK);
back_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_BACK));
back_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_BACK));
back_->SetImage(views::CustomButton::BS_NORMAL,
resource_bundle.GetBitmapNamed(IDR_COMPACTNAV_BACK));
back_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
views::ImageButton::ALIGN_MIDDLE);
AddChildView(back_);
bf_separator_ = new views::ImageView;
bf_separator_->SetImage(
resource_bundle.GetBitmapNamed(IDR_COMPACTNAV_SEPARATOR));
AddChildView(bf_separator_);
forward_ = new views::ButtonDropDown(this, forward_menu_model_.get());
forward_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN |
views::Event::EF_MIDDLE_BUTTON_DOWN);
forward_->set_tag(IDC_FORWARD);
forward_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_FORWARD));
forward_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_FORWARD));
forward_->SetImage(views::CustomButton::BS_NORMAL,
resource_bundle.GetBitmapNamed(IDR_COMPACTNAV_FORWARD));
forward_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
views::ImageButton::ALIGN_MIDDLE);
AddChildView(forward_);
set_background(new ThemeBackground(browser_view_));
}
gfx::Size CompactNavigationBar::GetPreferredSize() {
int width = kBackButtonLeftMargin;
width += back_->GetPreferredSize().width() + kInnerPadding * 2;
width += kHorizMargin;
width += bf_separator_->GetPreferredSize().width();
width += kHorizMargin;
width += forward_->GetPreferredSize().width() + kInnerPadding * 2;
width += kForwardButtonRightMargin;
return gfx::Size(width, kPreferredHeight);
}
void CompactNavigationBar::Layout() {
if (!initialized_)
return;
// Layout forward/back buttons after entry views as follows:
// [Back]|[Forward]
int curx = kBackButtonLeftMargin;
// "Back | Forward" section.
gfx::Size button_size = back_->GetPreferredSize();
button_size.set_width(button_size.width() + kInnerPadding * 2);
back_->SetBounds(curx, 0, button_size.width(), height());
curx += button_size.width() + kHorizMargin;
button_size = bf_separator_->GetPreferredSize();
bf_separator_->SetBounds(curx, 0, button_size.width(), height());
curx += button_size.width() + kHorizMargin;
button_size = forward_->GetPreferredSize();
button_size.set_width(button_size.width() + kInnerPadding * 2);
forward_->SetBounds(curx, 0, button_size.width(), height());
}
void CompactNavigationBar::Paint(gfx::Canvas* canvas) {
PaintBackground(canvas);
}
////////////////////////////////////////////////////////////////////////////////
// views::ButtonListener implementation.
void CompactNavigationBar::ButtonPressed(
views::Button* sender, const views::Event& event) {
browser_view_->browser()->ExecuteCommandWithDisposition(
sender->tag(),
event_utils::DispositionFromEventFlags(sender->mouse_event_flags()));
}
////////////////////////////////////////////////////////////////////////////////
// CommandUpdater::CommandObserver implementation.
void CompactNavigationBar::EnabledStateChangedForCommand(int id, bool enabled) {
switch (id) {
case IDC_BACK:
back_->SetEnabled(enabled);
break;
case IDC_FORWARD:
forward_->SetEnabled(enabled);
break;
}
}
} // namespace chromeos
|