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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
// 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/browser_window_gtk.h"
#include "base/logging.h"
#include "base/base_paths_linux.h"
#include "base/path_service.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/gtk/nine_box.h"
#include "chrome/browser/gtk/browser_toolbar_view_gtk.h"
#include "chrome/browser/gtk/status_bubble_gtk.h"
#include "chrome/browser/gtk/tab_contents_container_gtk.h"
#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
#include "chrome/browser/tab_contents/web_contents.h"
namespace {
static GdkPixbuf* LoadThemeImage(const std::string& filename) {
FilePath path;
bool ok = PathService::Get(base::DIR_SOURCE_ROOT, &path);
DCHECK(ok);
path = path.Append("chrome/app/theme").Append(filename);
// We intentionally ignore errors here, as some buttons don't have images
// for all states. This will all be removed once ResourceBundle works.
return gdk_pixbuf_new_from_file(path.value().c_str(), NULL);
}
gboolean MainWindowDestroyed(GtkWindow* window, BrowserWindowGtk* browser_win) {
delete browser_win;
return FALSE; // Don't stop this message.
}
gboolean MainWindowConfigured(GtkWindow* window, GdkEventConfigure* event,
BrowserWindowGtk* browser_win) {
gfx::Rect bounds = gfx::Rect(event->x, event->y, event->width, event->height);
browser_win->OnBoundsChanged(bounds);
return FALSE;
}
gboolean MainWindowStateChanged(GtkWindow* window, GdkEventWindowState* event,
BrowserWindowGtk* browser_win) {
browser_win->OnStateChanged(event->new_window_state);
return FALSE;
}
// Using gtk_window_get_position/size creates a race condition, so only use
// this to get the initial bounds. After window creation, we pick up the
// normal bounds by connecting to the configure-event signal.
gfx::Rect GetInitialWindowBounds(GtkWindow* window) {
gint x, y, width, height;
gtk_window_get_position(window, &x, &y);
gtk_window_get_size(window, &width, &height);
return gfx::Rect(x, y, width, height);
}
} // namespace
BrowserWindowGtk::BrowserWindowGtk(Browser* browser)
: browser_(browser),
// TODO(port): make this a pref.
custom_frame_(false) {
Init();
browser_->tabstrip_model()->AddObserver(this);
}
BrowserWindowGtk::~BrowserWindowGtk() {
browser_->tabstrip_model()->RemoveObserver(this);
Close();
}
gboolean BrowserWindowGtk::OnContentAreaExpose(GtkWidget* widget,
GdkEventExpose* e,
BrowserWindowGtk* window) {
if (window->custom_frame_) {
NOTIMPLEMENTED() << " needs custom drawing for the custom frame.";
return FALSE;
}
// The theme graphics include the 2px frame, but we don't draw the frame
// in the non-custom-frame mode. So we subtract it off.
const int kFramePixels = 2;
GdkPixbuf* pixbuf =
gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, // alpha
8, // bit depth
widget->allocation.width,
BrowserToolbarGtk::kToolbarHeight + kFramePixels);
#ifndef NDEBUG
// Fill with a bright color so we can see any pixels we're missing.
gdk_pixbuf_fill(pixbuf, 0x00FFFFFF);
#endif
window->content_area_ninebox_->RenderTopCenterStrip(pixbuf, 0,
widget->allocation.width);
gdk_draw_pixbuf(widget->window, NULL, pixbuf,
0, 0,
widget->allocation.x,
widget->allocation.y - kFramePixels,
-1, -1,
GDK_RGB_DITHER_NORMAL, 0, 0);
gdk_pixbuf_unref(pixbuf);
return FALSE; // Allow subwidgets to paint.
}
void BrowserWindowGtk::Init() {
window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
gtk_window_set_title(window_, "Chromium");
gtk_window_set_default_size(window_, 640, 480);
g_signal_connect(G_OBJECT(window_), "destroy",
G_CALLBACK(MainWindowDestroyed), this);
g_signal_connect(G_OBJECT(window_), "configure-event",
G_CALLBACK(MainWindowConfigured), this);
g_signal_connect(G_OBJECT(window_), "window-state-event",
G_CALLBACK(MainWindowStateChanged), this);
bounds_ = GetInitialWindowBounds(window_);
GdkPixbuf* images[9] = {
LoadThemeImage("content_top_left_corner.png"),
LoadThemeImage("content_top_center.png"),
LoadThemeImage("content_top_right_corner.png"),
LoadThemeImage("content_left_side.png"),
NULL,
LoadThemeImage("content_right_side.png"),
LoadThemeImage("content_bottom_left_corner.png"),
LoadThemeImage("content_bottom_center.png"),
LoadThemeImage("content_bottom_right_corner.png")
};
content_area_ninebox_.reset(new NineBox(images));
// This vbox is intended to surround the "content": toolbar+page.
// When we add the tab strip, it should go in a vbox surrounding this one.
vbox_ = gtk_vbox_new(FALSE, 0);
gtk_widget_set_app_paintable(vbox_, TRUE);
gtk_widget_set_double_buffered(vbox_, FALSE);
g_signal_connect(G_OBJECT(vbox_), "expose-event",
G_CALLBACK(&OnContentAreaExpose), this);
toolbar_.reset(new BrowserToolbarGtk(browser_.get()));
toolbar_->Init(browser_->profile());
toolbar_->AddToolbarToBox(vbox_);
contents_container_.reset(new TabContentsContainerGtk());
contents_container_->AddContainerToBox(vbox_);
// Note that calling this the first time is necessary to get the
// proper control layout.
// TODO(port): make this a pref.
SetCustomFrame(false);
status_bubble_.reset(new StatusBubbleGtk(window_));
gtk_container_add(GTK_CONTAINER(window_), vbox_);
}
void BrowserWindowGtk::Show() {
gtk_widget_show_all(GTK_WIDGET(window_));
}
void BrowserWindowGtk::SetBounds(const gfx::Rect& bounds) {
gint x = static_cast<gint>(bounds.x());
gint y = static_cast<gint>(bounds.y());
gint width = static_cast<gint>(bounds.width());
gint height = static_cast<gint>(bounds.height());
gtk_window_move(window_, x, y);
gtk_window_resize(window_, width, height);
}
void BrowserWindowGtk::Close() {
if (!window_)
return;
gtk_widget_destroy(GTK_WIDGET(window_));
window_ = NULL;
}
void BrowserWindowGtk::Activate() {
gtk_window_present(window_);
}
void BrowserWindowGtk::FlashFrame() {
// May not be respected by all window managers.
gtk_window_set_urgency_hint(window_, TRUE);
}
void* BrowserWindowGtk::GetNativeHandle() {
return window_;
}
BrowserWindowTesting* BrowserWindowGtk::GetBrowserWindowTesting() {
NOTIMPLEMENTED();
return NULL;
}
StatusBubble* BrowserWindowGtk::GetStatusBubble() {
return status_bubble_.get();
}
void BrowserWindowGtk::SelectedTabToolbarSizeChanged(bool is_animating) {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::UpdateTitleBar() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::UpdateLoadingAnimations(bool should_animate) {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::SetStarredState(bool is_starred) {
NOTIMPLEMENTED();
}
gfx::Rect BrowserWindowGtk::GetNormalBounds() const {
return bounds_;
}
bool BrowserWindowGtk::IsMaximized() const {
return (state_ & GDK_WINDOW_STATE_MAXIMIZED);
}
void BrowserWindowGtk::SetFullscreen(bool fullscreen) {
NOTIMPLEMENTED();
}
bool BrowserWindowGtk::IsFullscreen() const {
NOTIMPLEMENTED();
return false;
}
LocationBar* BrowserWindowGtk::GetLocationBar() const {
NOTIMPLEMENTED();
return NULL;
}
void BrowserWindowGtk::SetFocusToLocationBar() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::UpdateStopGoState(bool is_loading) {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::UpdateToolbar(TabContents* contents,
bool should_restore_state) {
toolbar_->UpdateTabContents(contents, should_restore_state);
}
void BrowserWindowGtk::FocusToolbar() {
NOTIMPLEMENTED();
}
bool BrowserWindowGtk::IsBookmarkBarVisible() const {
NOTIMPLEMENTED();
return false;
}
gfx::Rect BrowserWindowGtk::GetRootWindowResizerRect() const {
return gfx::Rect();
}
void BrowserWindowGtk::ToggleBookmarkBar() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::ShowAboutChromeDialog() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::ShowBookmarkManager() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::ShowBookmarkBubble(const GURL& url,
bool already_bookmarked) {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::ShowReportBugDialog() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::ShowClearBrowsingDataDialog() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::ShowImportDialog() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::ShowSearchEnginesDialog() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::ShowPasswordManager() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::ShowSelectProfileDialog() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::ShowNewProfileDialog() {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::ShowHTMLDialog(HtmlDialogContentsDelegate* delegate,
void* parent_window) {
NOTIMPLEMENTED();
}
void BrowserWindowGtk::TabDetachedAt(TabContents* contents, int index) {
// We use index here rather than comparing |contents| because by this time
// the model has already removed |contents| from its list, so
// browser_->GetSelectedTabContents() will return NULL or something else.
if (index == browser_->tabstrip_model()->selected_index()) {
// TODO(port): Uncoment this line when we get infobars.
// infobar_container_->ChangeTabContents(NULL);
contents_container_->SetTabContents(NULL);
}
}
void BrowserWindowGtk::TabSelectedAt(TabContents* old_contents,
TabContents* new_contents,
int index,
bool user_gesture) {
DCHECK(old_contents != new_contents);
// Update various elements that are interested in knowing the current
// TabContents.
// TOOD(port): Un-comment this line when we get infobars.
// infobar_container_->ChangeTabContents(new_contents);
contents_container_->SetTabContents(new_contents);
new_contents->DidBecomeSelected();
// Update all the UI bits.
UpdateTitleBar();
toolbar_->SetProfile(new_contents->profile());
UpdateToolbar(new_contents, true);
}
void BrowserWindowGtk::TabStripEmpty() {
}
void BrowserWindowGtk::DestroyBrowser() {
browser_.reset();
}
void BrowserWindowGtk::OnBoundsChanged(const gfx::Rect& bounds) {
bounds_ = bounds;
}
void BrowserWindowGtk::OnStateChanged(GdkWindowState state) {
state_ = state;
}
void BrowserWindowGtk::SetCustomFrame(bool custom_frame) {
custom_frame_ = custom_frame;
if (custom_frame_) {
gtk_container_set_border_width(GTK_CONTAINER(vbox_), 2);
// TODO(port): all the crazy blue title bar, etc.
NOTIMPLEMENTED();
} else {
gtk_container_set_border_width(GTK_CONTAINER(vbox_), 0);
}
}
|