| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gtk_util.h" | 5 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 6 | 6 |
| 7 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
| 8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 | 10 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 377 |
| 378 // Move to user expected desktop if window is already visible. | 378 // Move to user expected desktop if window is already visible. |
| 379 if (GTK_WIDGET(window)->window) { | 379 if (GTK_WIDGET(window)->window) { |
| 380 ui::ChangeWindowDesktop( | 380 ui::ChangeWindowDesktop( |
| 381 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(window)), | 381 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(window)), |
| 382 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(parent))); | 382 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(parent))); |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 void MakeAppModalWindowGroup() { | 386 void MakeAppModalWindowGroup() { |
| 387 #if GTK_CHECK_VERSION(2, 14, 0) | |
| 388 // Older versions of GTK+ don't give us gtk_window_group_list() which is what | 387 // Older versions of GTK+ don't give us gtk_window_group_list() which is what |
| 389 // we need to add current non-browser modal dialogs to the list. If | 388 // we need to add current non-browser modal dialogs to the list. If |
| 390 // we have 2.14+ we can do things the correct way. | 389 // we have 2.14+ we can do things the correct way. |
| 391 GtkWindowGroup* window_group = gtk_window_group_new(); | 390 GtkWindowGroup* window_group = gtk_window_group_new(); |
| 392 for (BrowserList::const_iterator it = BrowserList::begin(); | 391 for (BrowserList::const_iterator it = BrowserList::begin(); |
| 393 it != BrowserList::end(); ++it) { | 392 it != BrowserList::end(); ++it) { |
| 394 // List all windows in this current group | 393 // List all windows in this current group |
| 395 GtkWindowGroup* old_group = | 394 GtkWindowGroup* old_group = |
| 396 gtk_window_get_group((*it)->window()->GetNativeHandle()); | 395 gtk_window_get_group((*it)->window()->GetNativeHandle()); |
| 397 | 396 |
| 398 GList* all_windows = gtk_window_group_list_windows(old_group); | 397 GList* all_windows = gtk_window_group_list_windows(old_group); |
| 399 for (GList* window = all_windows; window; window = window->next) { | 398 for (GList* window = all_windows; window; window = window->next) { |
| 400 gtk_window_group_add_window(window_group, GTK_WINDOW(window->data)); | 399 gtk_window_group_add_window(window_group, GTK_WINDOW(window->data)); |
| 401 } | 400 } |
| 402 g_list_free(all_windows); | 401 g_list_free(all_windows); |
| 403 } | 402 } |
| 404 g_object_unref(window_group); | 403 g_object_unref(window_group); |
| 405 #else | |
| 406 // Otherwise just grab all browser windows and be slightly broken. | |
| 407 GtkWindowGroup* window_group = gtk_window_group_new(); | |
| 408 for (BrowserList::const_iterator it = BrowserList::begin(); | |
| 409 it != BrowserList::end(); ++it) { | |
| 410 gtk_window_group_add_window(window_group, | |
| 411 (*it)->window()->GetNativeHandle()); | |
| 412 } | |
| 413 g_object_unref(window_group); | |
| 414 #endif | |
| 415 } | 404 } |
| 416 | 405 |
| 417 void AppModalDismissedUngroupWindows() { | 406 void AppModalDismissedUngroupWindows() { |
| 418 #if GTK_CHECK_VERSION(2, 14, 0) | |
| 419 if (BrowserList::begin() != BrowserList::end()) { | 407 if (BrowserList::begin() != BrowserList::end()) { |
| 420 std::vector<GtkWindow*> transient_windows; | 408 std::vector<GtkWindow*> transient_windows; |
| 421 | 409 |
| 422 // All windows should be part of one big modal group right now. | 410 // All windows should be part of one big modal group right now. |
| 423 GtkWindowGroup* window_group = gtk_window_get_group( | 411 GtkWindowGroup* window_group = gtk_window_get_group( |
| 424 (*BrowserList::begin())->window()->GetNativeHandle()); | 412 (*BrowserList::begin())->window()->GetNativeHandle()); |
| 425 GList* windows = gtk_window_group_list_windows(window_group); | 413 GList* windows = gtk_window_group_list_windows(window_group); |
| 426 | 414 |
| 427 for (GList* item = windows; item; item = item->next) { | 415 for (GList* item = windows; item; item = item->next) { |
| 428 GtkWindow* window = GTK_WINDOW(item->data); | 416 GtkWindow* window = GTK_WINDOW(item->data); |
| 429 GtkWindow* transient_for = gtk_window_get_transient_for(window); | 417 GtkWindow* transient_for = gtk_window_get_transient_for(window); |
| 430 if (transient_for) { | 418 if (transient_for) { |
| 431 transient_windows.push_back(window); | 419 transient_windows.push_back(window); |
| 432 } else { | 420 } else { |
| 433 GtkWindowGroup* window_group = gtk_window_group_new(); | 421 GtkWindowGroup* window_group = gtk_window_group_new(); |
| 434 gtk_window_group_add_window(window_group, window); | 422 gtk_window_group_add_window(window_group, window); |
| 435 g_object_unref(window_group); | 423 g_object_unref(window_group); |
| 436 } | 424 } |
| 437 } | 425 } |
| 438 | 426 |
| 439 // Put each transient window in the same group as its transient parent. | 427 // Put each transient window in the same group as its transient parent. |
| 440 for (std::vector<GtkWindow*>::iterator it = transient_windows.begin(); | 428 for (std::vector<GtkWindow*>::iterator it = transient_windows.begin(); |
| 441 it != transient_windows.end(); ++it) { | 429 it != transient_windows.end(); ++it) { |
| 442 GtkWindow* transient_parent = gtk_window_get_transient_for(*it); | 430 GtkWindow* transient_parent = gtk_window_get_transient_for(*it); |
| 443 GtkWindowGroup* group = gtk_window_get_group(transient_parent); | 431 GtkWindowGroup* group = gtk_window_get_group(transient_parent); |
| 444 gtk_window_group_add_window(group, *it); | 432 gtk_window_group_add_window(group, *it); |
| 445 } | 433 } |
| 446 } | 434 } |
| 447 #else | |
| 448 // This is slightly broken in the case where a different window had a dialog, | |
| 449 // but its the best we can do since we don't have newer gtk stuff. | |
| 450 for (BrowserList::const_iterator it = BrowserList::begin(); | |
| 451 it != BrowserList::end(); ++it) { | |
| 452 GtkWindowGroup* window_group = gtk_window_group_new(); | |
| 453 gtk_window_group_add_window(window_group, | |
| 454 (*it)->window()->GetNativeHandle()); | |
| 455 g_object_unref(window_group); | |
| 456 } | |
| 457 #endif | |
| 458 } | 435 } |
| 459 | 436 |
| 460 void RemoveAllChildren(GtkWidget* container) { | 437 void RemoveAllChildren(GtkWidget* container) { |
| 461 gtk_container_foreach(GTK_CONTAINER(container), RemoveWidget, container); | 438 gtk_container_foreach(GTK_CONTAINER(container), RemoveWidget, container); |
| 462 } | 439 } |
| 463 | 440 |
| 464 void ForceFontSizePixels(GtkWidget* widget, double size_pixels) { | 441 void ForceFontSizePixels(GtkWidget* widget, double size_pixels) { |
| 465 PangoFontDescription* font_desc = pango_font_description_new(); | 442 PangoFontDescription* font_desc = pango_font_description_new(); |
| 466 // pango_font_description_set_absolute_size sets the font size in device | 443 // pango_font_description_set_absolute_size sets the font size in device |
| 467 // units, which for us is pixels. | 444 // units, which for us is pixels. |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 | 1259 |
| 1283 void DoCopy(BrowserWindow* window) { | 1260 void DoCopy(BrowserWindow* window) { |
| 1284 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); | 1261 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); |
| 1285 } | 1262 } |
| 1286 | 1263 |
| 1287 void DoPaste(BrowserWindow* window) { | 1264 void DoPaste(BrowserWindow* window) { |
| 1288 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); | 1265 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); |
| 1289 } | 1266 } |
| 1290 | 1267 |
| 1291 } // namespace gtk_util | 1268 } // namespace gtk_util |
| OLD | NEW |