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> |
7 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
8 | 9 |
9 #include <algorithm> | 10 #include <algorithm> |
10 #include <string> | 11 #include <string> |
11 | 12 |
12 #include "base/base_paths.h" | 13 #include "base/base_paths.h" |
13 #include "base/bind.h" | 14 #include "base/bind.h" |
14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
15 #include "base/debug/trace_event.h" | 16 #include "base/debug/trace_event.h" |
16 #include "base/environment.h" | 17 #include "base/environment.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include "chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.h" | 54 #include "chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.h" |
54 #include "chrome/browser/ui/gtk/download/download_in_progress_dialog_gtk.h" | 55 #include "chrome/browser/ui/gtk/download/download_in_progress_dialog_gtk.h" |
55 #include "chrome/browser/ui/gtk/download/download_shelf_gtk.h" | 56 #include "chrome/browser/ui/gtk/download/download_shelf_gtk.h" |
56 #include "chrome/browser/ui/gtk/edit_search_engine_dialog.h" | 57 #include "chrome/browser/ui/gtk/edit_search_engine_dialog.h" |
57 #include "chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.h" | 58 #include "chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.h" |
58 #include "chrome/browser/ui/gtk/find_bar_gtk.h" | 59 #include "chrome/browser/ui/gtk/find_bar_gtk.h" |
59 #include "chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.h" | 60 #include "chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.h" |
60 #include "chrome/browser/ui/gtk/global_menu_bar.h" | 61 #include "chrome/browser/ui/gtk/global_menu_bar.h" |
61 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 62 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
62 #include "chrome/browser/ui/gtk/gtk_util.h" | 63 #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 |
155 // Using gtk_window_get_position/size creates a race condition, so only use | 173 // Using gtk_window_get_position/size creates a race condition, so only use |
156 // this to get the initial bounds. After window creation, we pick up the | 174 // this to get the initial bounds. After window creation, we pick up the |
157 // normal bounds by connecting to the configure-event signal. | 175 // normal bounds by connecting to the configure-event signal. |
158 gfx::Rect GetInitialWindowBounds(GtkWindow* window) { | 176 gfx::Rect GetInitialWindowBounds(GtkWindow* window) { |
159 gint x, y, width, height; | 177 gint x, y, width, height; |
160 gtk_window_get_position(window, &x, &y); | 178 gtk_window_get_position(window, &x, &y); |
161 gtk_window_get_size(window, &width, &height); | 179 gtk_window_get_size(window, &width, &height); |
162 return gfx::Rect(x, y, width, height); | 180 return gfx::Rect(x, y, width, height); |
163 } | 181 } |
164 | 182 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 return IDC_MOVE_TAB_PREVIOUS; | 229 return IDC_MOVE_TAB_PREVIOUS; |
212 } | 230 } |
213 break; | 231 break; |
214 | 232 |
215 default: | 233 default: |
216 break; | 234 break; |
217 } | 235 } |
218 return -1; | 236 return -1; |
219 } | 237 } |
220 | 238 |
| 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 |
221 // A helper method for setting the GtkWindow size that should be used in place | 263 // A helper method for setting the GtkWindow size that should be used in place |
222 // of calling gtk_window_resize directly. This is done to avoid a WM "feature" | 264 // of calling gtk_window_resize directly. This is done to avoid a WM "feature" |
223 // where setting the window size to the monitor size causes the WM to set the | 265 // where setting the window size to the monitor size causes the WM to set the |
224 // EWMH for full screen mode. | 266 // EWMH for full screen mode. |
225 void SetWindowSize(GtkWindow* window, const gfx::Size& size) { | 267 void SetWindowSize(GtkWindow* window, const gfx::Size& size) { |
226 gfx::Size new_size = size; | 268 gfx::Size new_size = size; |
227 | 269 |
228 gint current_width = 0; | 270 gint current_width = 0; |
229 gint current_height = 0; | 271 gint current_height = 0; |
230 gtk_window_get_size(window, ¤t_width, ¤t_height); | 272 gtk_window_get_size(window, ¤t_width, ¤t_height); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 // compiz, suppress such raises, as they are not necessary in compiz anyway. | 374 // compiz, suppress such raises, as they are not necessary in compiz anyway. |
333 if (ui::GuessWindowManager() == ui::WM_COMPIZ) | 375 if (ui::GuessWindowManager() == ui::WM_COMPIZ) |
334 suppress_window_raise_ = true; | 376 suppress_window_raise_ = true; |
335 | 377 |
336 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 378 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
337 g_object_set_qdata(G_OBJECT(window_), GetBrowserWindowQuarkKey(), this); | 379 g_object_set_qdata(G_OBJECT(window_), GetBrowserWindowQuarkKey(), this); |
338 gtk_widget_add_events(GTK_WIDGET(window_), GDK_BUTTON_PRESS_MASK | | 380 gtk_widget_add_events(GTK_WIDGET(window_), GDK_BUTTON_PRESS_MASK | |
339 GDK_POINTER_MOTION_MASK); | 381 GDK_POINTER_MOTION_MASK); |
340 | 382 |
341 // Disable the resize gripper on Ubuntu. | 383 // Disable the resize gripper on Ubuntu. |
342 gtk_window_util::DisableResizeGrip(window_); | 384 EnsureResizeGripFunction(); |
| 385 if (gtk_window_set_has_resize_grip_sym) |
| 386 gtk_window_set_has_resize_grip_sym(GTK_WINDOW(window_), FALSE); |
343 | 387 |
344 // Add this window to its own unique window group to allow for | 388 // Add this window to its own unique window group to allow for |
345 // window-to-parent modality. | 389 // window-to-parent modality. |
346 gtk_window_group_add_window(gtk_window_group_new(), window_); | 390 gtk_window_group_add_window(gtk_window_group_new(), window_); |
347 g_object_unref(gtk_window_get_group(window_)); | 391 g_object_unref(gtk_window_get_group(window_)); |
348 | 392 |
349 // Set up a custom WM_CLASS for some sorts of window types. This allows | 393 // Set up a custom WM_CLASS for some sorts of window types. This allows |
350 // task switchers to distinguish between main browser windows and e.g | 394 // task switchers to distinguish between main browser windows and e.g |
351 // app windows. | 395 // app windows. |
352 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 396 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 else | 1219 else |
1176 gtk_window_activate_key(window_, os_event); | 1220 gtk_window_activate_key(window_, os_event); |
1177 } | 1221 } |
1178 | 1222 |
1179 void BrowserWindowGtk::ShowCreateChromeAppShortcutsDialog( | 1223 void BrowserWindowGtk::ShowCreateChromeAppShortcutsDialog( |
1180 Profile* profile, const extensions::Extension* app) { | 1224 Profile* profile, const extensions::Extension* app) { |
1181 CreateChromeApplicationShortcutsDialogGtk::Show(window_, profile, app); | 1225 CreateChromeApplicationShortcutsDialogGtk::Show(window_, profile, app); |
1182 } | 1226 } |
1183 | 1227 |
1184 void BrowserWindowGtk::Cut() { | 1228 void BrowserWindowGtk::Cut() { |
1185 gtk_window_util::DoCut( | 1229 gtk_util::DoCut(this); |
1186 window_, chrome::GetActiveWebContents(browser_.get())); | |
1187 } | 1230 } |
1188 | 1231 |
1189 void BrowserWindowGtk::Copy() { | 1232 void BrowserWindowGtk::Copy() { |
1190 gtk_window_util::DoCopy( | 1233 gtk_util::DoCopy(this); |
1191 window_, chrome::GetActiveWebContents(browser_.get())); | |
1192 } | 1234 } |
1193 | 1235 |
1194 void BrowserWindowGtk::Paste() { | 1236 void BrowserWindowGtk::Paste() { |
1195 gtk_window_util::DoPaste( | 1237 gtk_util::DoPaste(this); |
1196 window_, chrome::GetActiveWebContents(browser_.get())); | |
1197 } | 1238 } |
1198 | 1239 |
1199 void BrowserWindowGtk::ShowInstant(TabContents* preview) { | 1240 void BrowserWindowGtk::ShowInstant(TabContents* preview) { |
1200 contents_container_->SetPreview(preview); | 1241 contents_container_->SetPreview(preview); |
1201 MaybeShowBookmarkBar(false); | 1242 MaybeShowBookmarkBar(false); |
1202 } | 1243 } |
1203 | 1244 |
1204 void BrowserWindowGtk::HideInstant() { | 1245 void BrowserWindowGtk::HideInstant() { |
1205 contents_container_->PopPreview(); | 1246 contents_container_->PopPreview(); |
1206 MaybeShowBookmarkBar(false); | 1247 MaybeShowBookmarkBar(false); |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2210 } | 2251 } |
2211 return FALSE; | 2252 return FALSE; |
2212 } | 2253 } |
2213 | 2254 |
2214 // Update the cursor if we're on the custom frame border. | 2255 // Update the cursor if we're on the custom frame border. |
2215 GdkWindowEdge edge; | 2256 GdkWindowEdge edge; |
2216 bool has_hit_edge = GetWindowEdge(static_cast<int>(event->x), | 2257 bool has_hit_edge = GetWindowEdge(static_cast<int>(event->x), |
2217 static_cast<int>(event->y), &edge); | 2258 static_cast<int>(event->y), &edge); |
2218 GdkCursorType new_cursor = GDK_LAST_CURSOR; | 2259 GdkCursorType new_cursor = GDK_LAST_CURSOR; |
2219 if (has_hit_edge) | 2260 if (has_hit_edge) |
2220 new_cursor = gtk_window_util::GdkWindowEdgeToGdkCursorType(edge); | 2261 new_cursor = GdkWindowEdgeToGdkCursorType(edge); |
2221 | 2262 |
2222 GdkCursorType last_cursor = GDK_LAST_CURSOR; | 2263 GdkCursorType last_cursor = GDK_LAST_CURSOR; |
2223 if (frame_cursor_) | 2264 if (frame_cursor_) |
2224 last_cursor = frame_cursor_->type; | 2265 last_cursor = frame_cursor_->type; |
2225 | 2266 |
2226 if (last_cursor != new_cursor) { | 2267 if (last_cursor != new_cursor) { |
2227 if (has_hit_edge) { | 2268 if (has_hit_edge) { |
2228 frame_cursor_ = gfx::GetCursor(new_cursor); | 2269 frame_cursor_ = gfx::GetCursor(new_cursor); |
2229 } else { | 2270 } else { |
2230 frame_cursor_ = NULL; | 2271 frame_cursor_ = NULL; |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2552 wm_type == ui::WM_OPENBOX || | 2593 wm_type == ui::WM_OPENBOX || |
2553 wm_type == ui::WM_XFWM4); | 2594 wm_type == ui::WM_XFWM4); |
2554 } | 2595 } |
2555 | 2596 |
2556 // static | 2597 // static |
2557 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 2598 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
2558 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); | 2599 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); |
2559 browser_window_gtk->Init(); | 2600 browser_window_gtk->Init(); |
2560 return browser_window_gtk; | 2601 return browser_window_gtk; |
2561 } | 2602 } |
OLD | NEW |