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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // window background to line up with the tab background regardless of whether | 144 // 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 | 145 // 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 | 146 // custom frame in mind, we need to offset the background when the custom frame |
148 // is off. | 147 // is off. |
149 const int kCustomFrameBackgroundVerticalOffset = 15; | 148 const int kCustomFrameBackgroundVerticalOffset = 15; |
150 | 149 |
151 // The timeout in milliseconds before we'll get the true window position with | 150 // 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. | 151 // gtk_window_get_position() after the last GTK configure-event signal. |
153 const int kDebounceTimeoutMilliseconds = 100; | 152 const int kDebounceTimeoutMilliseconds = 100; |
154 | 153 |
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 | 154 // 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 | 155 // this to get the initial bounds. After window creation, we pick up the |
175 // normal bounds by connecting to the configure-event signal. | 156 // normal bounds by connecting to the configure-event signal. |
176 gfx::Rect GetInitialWindowBounds(GtkWindow* window) { | 157 gfx::Rect GetInitialWindowBounds(GtkWindow* window) { |
177 gint x, y, width, height; | 158 gint x, y, width, height; |
178 gtk_window_get_position(window, &x, &y); | 159 gtk_window_get_position(window, &x, &y); |
179 gtk_window_get_size(window, &width, &height); | 160 gtk_window_get_size(window, &width, &height); |
180 return gfx::Rect(x, y, width, height); | 161 return gfx::Rect(x, y, width, height); |
181 } | 162 } |
182 | 163 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return IDC_MOVE_TAB_PREVIOUS; | 210 return IDC_MOVE_TAB_PREVIOUS; |
230 } | 211 } |
231 break; | 212 break; |
232 | 213 |
233 default: | 214 default: |
234 break; | 215 break; |
235 } | 216 } |
236 return -1; | 217 return -1; |
237 } | 218 } |
238 | 219 |
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 | 220 // 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" | 221 // 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 | 222 // where setting the window size to the monitor size causes the WM to set the |
266 // EWMH for full screen mode. | 223 // EWMH for full screen mode. |
267 void SetWindowSize(GtkWindow* window, const gfx::Size& size) { | 224 void SetWindowSize(GtkWindow* window, const gfx::Size& size) { |
268 gfx::Size new_size = size; | 225 gfx::Size new_size = size; |
269 | 226 |
270 gint current_width = 0; | 227 gint current_width = 0; |
271 gint current_height = 0; | 228 gint current_height = 0; |
272 gtk_window_get_size(window, ¤t_width, ¤t_height); | 229 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. | 331 // compiz, suppress such raises, as they are not necessary in compiz anyway. |
375 if (ui::GuessWindowManager() == ui::WM_COMPIZ) | 332 if (ui::GuessWindowManager() == ui::WM_COMPIZ) |
376 suppress_window_raise_ = true; | 333 suppress_window_raise_ = true; |
377 | 334 |
378 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 335 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
379 g_object_set_qdata(G_OBJECT(window_), GetBrowserWindowQuarkKey(), this); | 336 g_object_set_qdata(G_OBJECT(window_), GetBrowserWindowQuarkKey(), this); |
380 gtk_widget_add_events(GTK_WIDGET(window_), GDK_BUTTON_PRESS_MASK | | 337 gtk_widget_add_events(GTK_WIDGET(window_), GDK_BUTTON_PRESS_MASK | |
381 GDK_POINTER_MOTION_MASK); | 338 GDK_POINTER_MOTION_MASK); |
382 | 339 |
383 // Disable the resize gripper on Ubuntu. | 340 // Disable the resize gripper on Ubuntu. |
384 EnsureResizeGripFunction(); | 341 gtk_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 | 342 |
388 // Add this window to its own unique window group to allow for | 343 // Add this window to its own unique window group to allow for |
389 // window-to-parent modality. | 344 // window-to-parent modality. |
390 gtk_window_group_add_window(gtk_window_group_new(), window_); | 345 gtk_window_group_add_window(gtk_window_group_new(), window_); |
391 g_object_unref(gtk_window_get_group(window_)); | 346 g_object_unref(gtk_window_get_group(window_)); |
392 | 347 |
393 // Set up a custom WM_CLASS for some sorts of window types. This allows | 348 // 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 | 349 // task switchers to distinguish between main browser windows and e.g |
395 // app windows. | 350 // app windows. |
396 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 351 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 else | 1174 else |
1220 gtk_window_activate_key(window_, os_event); | 1175 gtk_window_activate_key(window_, os_event); |
1221 } | 1176 } |
1222 | 1177 |
1223 void BrowserWindowGtk::ShowCreateChromeAppShortcutsDialog( | 1178 void BrowserWindowGtk::ShowCreateChromeAppShortcutsDialog( |
1224 Profile* profile, const extensions::Extension* app) { | 1179 Profile* profile, const extensions::Extension* app) { |
1225 CreateChromeApplicationShortcutsDialogGtk::Show(window_, profile, app); | 1180 CreateChromeApplicationShortcutsDialogGtk::Show(window_, profile, app); |
1226 } | 1181 } |
1227 | 1182 |
1228 void BrowserWindowGtk::Cut() { | 1183 void BrowserWindowGtk::Cut() { |
1229 gtk_util::DoCut(this); | 1184 gtk_util::DoCut(window_, chrome::GetActiveWebContents(browser_.get())); |
1230 } | 1185 } |
1231 | 1186 |
1232 void BrowserWindowGtk::Copy() { | 1187 void BrowserWindowGtk::Copy() { |
1233 gtk_util::DoCopy(this); | 1188 gtk_util::DoCopy(window_, chrome::GetActiveWebContents(browser_.get())); |
1234 } | 1189 } |
1235 | 1190 |
1236 void BrowserWindowGtk::Paste() { | 1191 void BrowserWindowGtk::Paste() { |
1237 gtk_util::DoPaste(this); | 1192 gtk_util::DoPaste(window_, chrome::GetActiveWebContents(browser_.get())); |
1238 } | 1193 } |
1239 | 1194 |
1240 void BrowserWindowGtk::ShowInstant(TabContents* preview) { | 1195 void BrowserWindowGtk::ShowInstant(TabContents* preview) { |
1241 contents_container_->SetPreview(preview); | 1196 contents_container_->SetPreview(preview); |
1242 MaybeShowBookmarkBar(false); | 1197 MaybeShowBookmarkBar(false); |
1243 } | 1198 } |
1244 | 1199 |
1245 void BrowserWindowGtk::HideInstant() { | 1200 void BrowserWindowGtk::HideInstant() { |
1246 contents_container_->PopPreview(); | 1201 contents_container_->PopPreview(); |
1247 MaybeShowBookmarkBar(false); | 1202 MaybeShowBookmarkBar(false); |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2251 } | 2206 } |
2252 return FALSE; | 2207 return FALSE; |
2253 } | 2208 } |
2254 | 2209 |
2255 // Update the cursor if we're on the custom frame border. | 2210 // Update the cursor if we're on the custom frame border. |
2256 GdkWindowEdge edge; | 2211 GdkWindowEdge edge; |
2257 bool has_hit_edge = GetWindowEdge(static_cast<int>(event->x), | 2212 bool has_hit_edge = GetWindowEdge(static_cast<int>(event->x), |
2258 static_cast<int>(event->y), &edge); | 2213 static_cast<int>(event->y), &edge); |
2259 GdkCursorType new_cursor = GDK_LAST_CURSOR; | 2214 GdkCursorType new_cursor = GDK_LAST_CURSOR; |
2260 if (has_hit_edge) | 2215 if (has_hit_edge) |
2261 new_cursor = GdkWindowEdgeToGdkCursorType(edge); | 2216 new_cursor = gtk_util::GdkWindowEdgeToGdkCursorType(edge); |
2262 | 2217 |
2263 GdkCursorType last_cursor = GDK_LAST_CURSOR; | 2218 GdkCursorType last_cursor = GDK_LAST_CURSOR; |
2264 if (frame_cursor_) | 2219 if (frame_cursor_) |
2265 last_cursor = frame_cursor_->type; | 2220 last_cursor = frame_cursor_->type; |
2266 | 2221 |
2267 if (last_cursor != new_cursor) { | 2222 if (last_cursor != new_cursor) { |
2268 if (has_hit_edge) { | 2223 if (has_hit_edge) { |
2269 frame_cursor_ = gfx::GetCursor(new_cursor); | 2224 frame_cursor_ = gfx::GetCursor(new_cursor); |
2270 } else { | 2225 } else { |
2271 frame_cursor_ = NULL; | 2226 frame_cursor_ = NULL; |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2593 wm_type == ui::WM_OPENBOX || | 2548 wm_type == ui::WM_OPENBOX || |
2594 wm_type == ui::WM_XFWM4); | 2549 wm_type == ui::WM_XFWM4); |
2595 } | 2550 } |
2596 | 2551 |
2597 // static | 2552 // static |
2598 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 2553 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
2599 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); | 2554 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); |
2600 browser_window_gtk->Init(); | 2555 browser_window_gtk->Init(); |
2601 return browser_window_gtk; | 2556 return browser_window_gtk; |
2602 } | 2557 } |
OLD | NEW |