OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 5 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
6 | 6 |
7 #include <dlfcn.h> | |
8 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
9 | 8 |
10 #include <algorithm> | 9 #include <algorithm> |
11 #include <string> | 10 #include <string> |
12 | 11 |
13 #include "base/base_paths.h" | 12 #include "base/base_paths.h" |
14 #include "base/bind.h" | 13 #include "base/bind.h" |
15 #include "base/command_line.h" | 14 #include "base/command_line.h" |
16 #include "base/debug/trace_event.h" | 15 #include "base/debug/trace_event.h" |
17 #include "base/environment.h" | 16 #include "base/environment.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include "chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.h" | 53 #include "chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.h" |
55 #include "chrome/browser/ui/gtk/download/download_in_progress_dialog_gtk.h" | 54 #include "chrome/browser/ui/gtk/download/download_in_progress_dialog_gtk.h" |
56 #include "chrome/browser/ui/gtk/download/download_shelf_gtk.h" | 55 #include "chrome/browser/ui/gtk/download/download_shelf_gtk.h" |
57 #include "chrome/browser/ui/gtk/edit_search_engine_dialog.h" | 56 #include "chrome/browser/ui/gtk/edit_search_engine_dialog.h" |
58 #include "chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.h" | 57 #include "chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.h" |
59 #include "chrome/browser/ui/gtk/find_bar_gtk.h" | 58 #include "chrome/browser/ui/gtk/find_bar_gtk.h" |
60 #include "chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.h" | 59 #include "chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.h" |
61 #include "chrome/browser/ui/gtk/global_menu_bar.h" | 60 #include "chrome/browser/ui/gtk/global_menu_bar.h" |
62 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 61 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
63 #include "chrome/browser/ui/gtk/gtk_util.h" | 62 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 63 #include "chrome/browser/ui/gtk/gtk_window_util.h" |
64 #include "chrome/browser/ui/gtk/infobars/infobar_container_gtk.h" | 64 #include "chrome/browser/ui/gtk/infobars/infobar_container_gtk.h" |
65 #include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" | 65 #include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" |
66 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" | 66 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
67 #include "chrome/browser/ui/gtk/nine_box.h" | 67 #include "chrome/browser/ui/gtk/nine_box.h" |
68 #include "chrome/browser/ui/gtk/one_click_signin_bubble_gtk.h" | 68 #include "chrome/browser/ui/gtk/one_click_signin_bubble_gtk.h" |
69 #include "chrome/browser/ui/gtk/password_generation_bubble_gtk.h" | 69 #include "chrome/browser/ui/gtk/password_generation_bubble_gtk.h" |
70 #include "chrome/browser/ui/gtk/reload_button_gtk.h" | 70 #include "chrome/browser/ui/gtk/reload_button_gtk.h" |
71 #include "chrome/browser/ui/gtk/status_bubble_gtk.h" | 71 #include "chrome/browser/ui/gtk/status_bubble_gtk.h" |
72 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" | 72 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" |
73 #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" | 73 #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // window background to line up with the tab background regardless of whether | 145 // window background to line up with the tab background regardless of whether |
146 // we're in custom frame mode or not. Since themes are designed with the | 146 // we're in custom frame mode or not. Since themes are designed with the |
147 // custom frame in mind, we need to offset the background when the custom frame | 147 // custom frame in mind, we need to offset the background when the custom frame |
148 // is off. | 148 // is off. |
149 const int kCustomFrameBackgroundVerticalOffset = 15; | 149 const int kCustomFrameBackgroundVerticalOffset = 15; |
150 | 150 |
151 // The timeout in milliseconds before we'll get the true window position with | 151 // The timeout in milliseconds before we'll get the true window position with |
152 // gtk_window_get_position() after the last GTK configure-event signal. | 152 // gtk_window_get_position() after the last GTK configure-event signal. |
153 const int kDebounceTimeoutMilliseconds = 100; | 153 const int kDebounceTimeoutMilliseconds = 100; |
154 | 154 |
155 // Ubuntu patches their verrsion of GTK+ so that there is always a | |
156 // gripper in the bottom right corner of the window. We dynamically | |
157 // look up this symbol because it's a non-standard Ubuntu extension to | |
158 // GTK+. We always need to disable this feature since we can't | |
159 // communicate this to WebKit easily. | |
160 typedef void (*gtk_window_set_has_resize_grip_func)(GtkWindow*, gboolean); | |
161 gtk_window_set_has_resize_grip_func gtk_window_set_has_resize_grip_sym; | |
162 | |
163 void EnsureResizeGripFunction() { | |
164 static bool resize_grip_looked_up = false; | |
165 if (!resize_grip_looked_up) { | |
166 resize_grip_looked_up = true; | |
167 gtk_window_set_has_resize_grip_sym = | |
168 reinterpret_cast<gtk_window_set_has_resize_grip_func>( | |
169 dlsym(NULL, "gtk_window_set_has_resize_grip")); | |
170 } | |
171 } | |
172 | |
173 // Using gtk_window_get_position/size creates a race condition, so only use | 155 // Using gtk_window_get_position/size creates a race condition, so only use |
174 // this to get the initial bounds. After window creation, we pick up the | 156 // this to get the initial bounds. After window creation, we pick up the |
175 // normal bounds by connecting to the configure-event signal. | 157 // normal bounds by connecting to the configure-event signal. |
176 gfx::Rect GetInitialWindowBounds(GtkWindow* window) { | 158 gfx::Rect GetInitialWindowBounds(GtkWindow* window) { |
177 gint x, y, width, height; | 159 gint x, y, width, height; |
178 gtk_window_get_position(window, &x, &y); | 160 gtk_window_get_position(window, &x, &y); |
179 gtk_window_get_size(window, &width, &height); | 161 gtk_window_get_size(window, &width, &height); |
180 return gfx::Rect(x, y, width, height); | 162 return gfx::Rect(x, y, width, height); |
181 } | 163 } |
182 | 164 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return IDC_MOVE_TAB_PREVIOUS; | 211 return IDC_MOVE_TAB_PREVIOUS; |
230 } | 212 } |
231 break; | 213 break; |
232 | 214 |
233 default: | 215 default: |
234 break; | 216 break; |
235 } | 217 } |
236 return -1; | 218 return -1; |
237 } | 219 } |
238 | 220 |
239 GdkCursorType GdkWindowEdgeToGdkCursorType(GdkWindowEdge edge) { | |
240 switch (edge) { | |
241 case GDK_WINDOW_EDGE_NORTH_WEST: | |
242 return GDK_TOP_LEFT_CORNER; | |
243 case GDK_WINDOW_EDGE_NORTH: | |
244 return GDK_TOP_SIDE; | |
245 case GDK_WINDOW_EDGE_NORTH_EAST: | |
246 return GDK_TOP_RIGHT_CORNER; | |
247 case GDK_WINDOW_EDGE_WEST: | |
248 return GDK_LEFT_SIDE; | |
249 case GDK_WINDOW_EDGE_EAST: | |
250 return GDK_RIGHT_SIDE; | |
251 case GDK_WINDOW_EDGE_SOUTH_WEST: | |
252 return GDK_BOTTOM_LEFT_CORNER; | |
253 case GDK_WINDOW_EDGE_SOUTH: | |
254 return GDK_BOTTOM_SIDE; | |
255 case GDK_WINDOW_EDGE_SOUTH_EAST: | |
256 return GDK_BOTTOM_RIGHT_CORNER; | |
257 default: | |
258 NOTREACHED(); | |
259 } | |
260 return GDK_LAST_CURSOR; | |
261 } | |
262 | |
263 // A helper method for setting the GtkWindow size that should be used in place | 221 // A helper method for setting the GtkWindow size that should be used in place |
264 // of calling gtk_window_resize directly. This is done to avoid a WM "feature" | 222 // of calling gtk_window_resize directly. This is done to avoid a WM "feature" |
265 // where setting the window size to the monitor size causes the WM to set the | 223 // where setting the window size to the monitor size causes the WM to set the |
266 // EWMH for full screen mode. | 224 // EWMH for full screen mode. |
267 void SetWindowSize(GtkWindow* window, const gfx::Size& size) { | 225 void SetWindowSize(GtkWindow* window, const gfx::Size& size) { |
268 gfx::Size new_size = size; | 226 gfx::Size new_size = size; |
269 | 227 |
270 gint current_width = 0; | 228 gint current_width = 0; |
271 gint current_height = 0; | 229 gint current_height = 0; |
272 gtk_window_get_size(window, ¤t_width, ¤t_height); | 230 gtk_window_get_size(window, ¤t_width, ¤t_height); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 // compiz, suppress such raises, as they are not necessary in compiz anyway. | 332 // compiz, suppress such raises, as they are not necessary in compiz anyway. |
375 if (ui::GuessWindowManager() == ui::WM_COMPIZ) | 333 if (ui::GuessWindowManager() == ui::WM_COMPIZ) |
376 suppress_window_raise_ = true; | 334 suppress_window_raise_ = true; |
377 | 335 |
378 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 336 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
379 g_object_set_qdata(G_OBJECT(window_), GetBrowserWindowQuarkKey(), this); | 337 g_object_set_qdata(G_OBJECT(window_), GetBrowserWindowQuarkKey(), this); |
380 gtk_widget_add_events(GTK_WIDGET(window_), GDK_BUTTON_PRESS_MASK | | 338 gtk_widget_add_events(GTK_WIDGET(window_), GDK_BUTTON_PRESS_MASK | |
381 GDK_POINTER_MOTION_MASK); | 339 GDK_POINTER_MOTION_MASK); |
382 | 340 |
383 // Disable the resize gripper on Ubuntu. | 341 // Disable the resize gripper on Ubuntu. |
384 EnsureResizeGripFunction(); | 342 gtk_window_util::DisableResizeGrip(window_); |
385 if (gtk_window_set_has_resize_grip_sym) | |
386 gtk_window_set_has_resize_grip_sym(GTK_WINDOW(window_), FALSE); | |
387 | 343 |
388 // Add this window to its own unique window group to allow for | 344 // Add this window to its own unique window group to allow for |
389 // window-to-parent modality. | 345 // window-to-parent modality. |
390 gtk_window_group_add_window(gtk_window_group_new(), window_); | 346 gtk_window_group_add_window(gtk_window_group_new(), window_); |
391 g_object_unref(gtk_window_get_group(window_)); | 347 g_object_unref(gtk_window_get_group(window_)); |
392 | 348 |
393 // Set up a custom WM_CLASS for some sorts of window types. This allows | 349 // Set up a custom WM_CLASS for some sorts of window types. This allows |
394 // task switchers to distinguish between main browser windows and e.g | 350 // task switchers to distinguish between main browser windows and e.g |
395 // app windows. | 351 // app windows. |
396 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 352 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 else | 1175 else |
1220 gtk_window_activate_key(window_, os_event); | 1176 gtk_window_activate_key(window_, os_event); |
1221 } | 1177 } |
1222 | 1178 |
1223 void BrowserWindowGtk::ShowCreateChromeAppShortcutsDialog( | 1179 void BrowserWindowGtk::ShowCreateChromeAppShortcutsDialog( |
1224 Profile* profile, const extensions::Extension* app) { | 1180 Profile* profile, const extensions::Extension* app) { |
1225 CreateChromeApplicationShortcutsDialogGtk::Show(window_, profile, app); | 1181 CreateChromeApplicationShortcutsDialogGtk::Show(window_, profile, app); |
1226 } | 1182 } |
1227 | 1183 |
1228 void BrowserWindowGtk::Cut() { | 1184 void BrowserWindowGtk::Cut() { |
1229 gtk_util::DoCut(this); | 1185 gtk_window_util::DoCut( |
| 1186 window_, chrome::GetActiveWebContents(browser_.get())); |
1230 } | 1187 } |
1231 | 1188 |
1232 void BrowserWindowGtk::Copy() { | 1189 void BrowserWindowGtk::Copy() { |
1233 gtk_util::DoCopy(this); | 1190 gtk_window_util::DoCopy( |
| 1191 window_, chrome::GetActiveWebContents(browser_.get())); |
1234 } | 1192 } |
1235 | 1193 |
1236 void BrowserWindowGtk::Paste() { | 1194 void BrowserWindowGtk::Paste() { |
1237 gtk_util::DoPaste(this); | 1195 gtk_window_util::DoPaste( |
| 1196 window_, chrome::GetActiveWebContents(browser_.get())); |
1238 } | 1197 } |
1239 | 1198 |
1240 void BrowserWindowGtk::ShowInstant(TabContents* preview) { | 1199 void BrowserWindowGtk::ShowInstant(TabContents* preview) { |
1241 contents_container_->SetPreview(preview); | 1200 contents_container_->SetPreview(preview); |
1242 MaybeShowBookmarkBar(false); | 1201 MaybeShowBookmarkBar(false); |
1243 } | 1202 } |
1244 | 1203 |
1245 void BrowserWindowGtk::HideInstant() { | 1204 void BrowserWindowGtk::HideInstant() { |
1246 contents_container_->PopPreview(); | 1205 contents_container_->PopPreview(); |
1247 MaybeShowBookmarkBar(false); | 1206 MaybeShowBookmarkBar(false); |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2251 } | 2210 } |
2252 return FALSE; | 2211 return FALSE; |
2253 } | 2212 } |
2254 | 2213 |
2255 // Update the cursor if we're on the custom frame border. | 2214 // Update the cursor if we're on the custom frame border. |
2256 GdkWindowEdge edge; | 2215 GdkWindowEdge edge; |
2257 bool has_hit_edge = GetWindowEdge(static_cast<int>(event->x), | 2216 bool has_hit_edge = GetWindowEdge(static_cast<int>(event->x), |
2258 static_cast<int>(event->y), &edge); | 2217 static_cast<int>(event->y), &edge); |
2259 GdkCursorType new_cursor = GDK_LAST_CURSOR; | 2218 GdkCursorType new_cursor = GDK_LAST_CURSOR; |
2260 if (has_hit_edge) | 2219 if (has_hit_edge) |
2261 new_cursor = GdkWindowEdgeToGdkCursorType(edge); | 2220 new_cursor = gtk_window_util::GdkWindowEdgeToGdkCursorType(edge); |
2262 | 2221 |
2263 GdkCursorType last_cursor = GDK_LAST_CURSOR; | 2222 GdkCursorType last_cursor = GDK_LAST_CURSOR; |
2264 if (frame_cursor_) | 2223 if (frame_cursor_) |
2265 last_cursor = frame_cursor_->type; | 2224 last_cursor = frame_cursor_->type; |
2266 | 2225 |
2267 if (last_cursor != new_cursor) { | 2226 if (last_cursor != new_cursor) { |
2268 if (has_hit_edge) { | 2227 if (has_hit_edge) { |
2269 frame_cursor_ = gfx::GetCursor(new_cursor); | 2228 frame_cursor_ = gfx::GetCursor(new_cursor); |
2270 } else { | 2229 } else { |
2271 frame_cursor_ = NULL; | 2230 frame_cursor_ = NULL; |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2593 wm_type == ui::WM_OPENBOX || | 2552 wm_type == ui::WM_OPENBOX || |
2594 wm_type == ui::WM_XFWM4); | 2553 wm_type == ui::WM_XFWM4); |
2595 } | 2554 } |
2596 | 2555 |
2597 // static | 2556 // static |
2598 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 2557 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
2599 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); | 2558 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); |
2600 browser_window_gtk->Init(); | 2559 browser_window_gtk->Init(); |
2601 return browser_window_gtk; | 2560 return browser_window_gtk; |
2602 } | 2561 } |
OLD | NEW |