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
166
167
168
169
170
171
172
173
174
|
// 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/gtk/location_bar_view_gtk.h"
#include <string>
#include "base/basictypes.h"
#include "base/gfx/gtk_util.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/alternate_nav_url_fetcher.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/page_transition_types.h"
#include "skia/include/SkBitmap.h"
#include "webkit/glue/window_open_disposition.h"
namespace {
// We are positioned with a little bit of extra space that we don't use now.
const int kTopPadding = 1;
const int kBottomPadding = 2;
// TODO(deanm): Eventually this should be painted with the background png
// image, but for now we get pretty close by just drawing a solid border.
const GdkColor kBorderColor = GDK_COLOR_RGB(0xbe, 0xc8, 0xd4);
} // namespace
LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater,
ToolbarModel* toolbar_model)
: outer_bin_(NULL),
inner_vbox_(NULL),
profile_(NULL),
command_updater_(command_updater),
toolbar_model_(toolbar_model),
disposition_(CURRENT_TAB),
transition_(PageTransition::TYPED) {
}
LocationBarViewGtk::~LocationBarViewGtk() {
gtk_widget_destroy(outer_bin_);
}
void LocationBarViewGtk::Init() {
location_entry_.reset(new AutocompleteEditViewGtk(this,
toolbar_model_,
profile_,
command_updater_));
location_entry_->Init();
inner_vbox_ = gtk_vbox_new(false, 0);
// TODO(deanm): We use a bunch of widgets to get things to layout with a
// border, etc. This should eventually be custom paint using the correct
// background image, etc.
gtk_box_pack_start(GTK_BOX(inner_vbox_), location_entry_->widget(),
TRUE, TRUE, 0);
// Use an alignment to position our bordered location entry exactly.
outer_bin_ = gtk_alignment_new(0, 0, 1, 1);
gtk_alignment_set_padding(GTK_ALIGNMENT(outer_bin_),
kTopPadding, kBottomPadding, 0, 0);
gtk_container_add(
GTK_CONTAINER(outer_bin_),
gfx::CreateGtkBorderBin(inner_vbox_, &kBorderColor, 1, 1, 0, 0));
// Sink the ref so that we own the widget, and will destroy on destruction.
g_object_ref_sink(outer_bin_);
}
void LocationBarViewGtk::SetProfile(Profile* profile) {
profile_ = profile;
}
void LocationBarViewGtk::Update(const TabContents* contents) {
location_entry_->Update(contents);
}
void LocationBarViewGtk::OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
const GURL& alternate_nav_url) {
if (!url.is_valid())
return;
location_input_ = UTF8ToWide(url.spec());
disposition_ = disposition;
transition_ = transition;
if (!command_updater_)
return;
if (!alternate_nav_url.is_valid()) {
command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
return;
}
scoped_ptr<AlternateNavURLFetcher> fetcher(
new AlternateNavURLFetcher(alternate_nav_url));
// The AlternateNavURLFetcher will listen for the pending navigation
// notification that will be issued as a result of the "open URL." It
// will automatically install itself into that navigation controller.
command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) {
// I'm not sure this should be reachable, but I'm not also sure enough
// that it shouldn't to stick in a NOTREACHED(). In any case, this is
// harmless; we can simply let the fetcher get deleted here and it will
// clean itself up properly.
} else {
fetcher.release(); // The navigation controller will delete the fetcher.
}
}
void LocationBarViewGtk::OnChanged() {
// TODO(deanm): Here is where we would do layout when we have things like
// the keyword display, ssl icons, etc.
}
void LocationBarViewGtk::OnInputInProgress(bool in_progress) {
NOTIMPLEMENTED();
}
SkBitmap LocationBarViewGtk::GetFavIcon() const {
NOTIMPLEMENTED();
return SkBitmap();
}
std::wstring LocationBarViewGtk::GetTitle() const {
NOTIMPLEMENTED();
return std::wstring();
}
void LocationBarViewGtk::ShowFirstRunBubble() {
NOTIMPLEMENTED();
}
std::wstring LocationBarViewGtk::GetInputString() const {
return location_input_;
}
WindowOpenDisposition LocationBarViewGtk::GetWindowOpenDisposition() const {
return disposition_;
}
PageTransition::Type LocationBarViewGtk::GetPageTransition() const {
return transition_;
}
void LocationBarViewGtk::AcceptInput() {
location_entry_->model()->AcceptInput(CURRENT_TAB, false);
}
void LocationBarViewGtk::FocusLocation() {
location_entry_->SetFocus();
location_entry_->SelectAll(true);
}
void LocationBarViewGtk::FocusSearch() {
location_entry_->SetUserText(L"?");
location_entry_->SetFocus();
}
void LocationBarViewGtk::UpdateFeedIcon() {
NOTIMPLEMENTED();
}
void LocationBarViewGtk::SaveStateToContents(TabContents* contents) {
NOTIMPLEMENTED();
}
|