| 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 <gdk/gdkx.h> |
| 5 #include <gtk/gtk.h> | 6 #include <gtk/gtk.h> |
| 6 #include <map> | 7 #include <map> |
| 7 #include <set> | 8 #include <set> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 // Xlib defines RootWindow | 11 // Xlib defines RootWindow |
| 11 #undef RootWindow | 12 #undef RootWindow |
| 12 | 13 |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 20 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
| 21 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h" | 22 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h" |
| 22 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" | 23 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" |
| 23 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h" | 24 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h" |
| 24 #include "ui/aura/window_observer.h" | 25 #include "ui/aura/window_observer.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/shell_dialogs/select_file_dialog.h" | 27 #include "ui/shell_dialogs/select_file_dialog.h" |
| 27 #include "ui/strings/grit/ui_strings.h" | 28 #include "ui/strings/grit/ui_strings.h" |
| 29 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 28 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" | 30 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 // Makes sure that .jpg also shows .JPG. | 34 // Makes sure that .jpg also shows .JPG. |
| 33 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info, | 35 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info, |
| 34 std::string* file_extension) { | 36 std::string* file_extension) { |
| 35 return base::EndsWith(file_info->filename, *file_extension, false); | 37 return base::EndsWith(file_info->filename, *file_extension, false); |
| 36 } | 38 } |
| 37 | 39 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 267 |
| 266 preview_ = gtk_image_new(); | 268 preview_ = gtk_image_new(); |
| 267 g_signal_connect(dialog, "destroy", | 269 g_signal_connect(dialog, "destroy", |
| 268 G_CALLBACK(OnFileChooserDestroyThunk), this); | 270 G_CALLBACK(OnFileChooserDestroyThunk), this); |
| 269 g_signal_connect(dialog, "update-preview", | 271 g_signal_connect(dialog, "update-preview", |
| 270 G_CALLBACK(OnUpdatePreviewThunk), this); | 272 G_CALLBACK(OnUpdatePreviewThunk), this); |
| 271 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); | 273 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); |
| 272 | 274 |
| 273 params_map_[dialog] = params; | 275 params_map_[dialog] = params; |
| 274 | 276 |
| 275 // TODO(erg): Figure out how to fake GTK window-to-parent modality without | 277 // Disable input events handling in the host window to make this dialog modal. |
| 276 // having the parent be a real GtkWindow. | 278 views::DesktopWindowTreeHostX11* host = |
| 277 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); | 279 views::DesktopWindowTreeHostX11::GetHostForXID( |
| 280 owning_window->GetHost()->GetAcceleratedWidget()); |
| 281 host->DisableEventListening(GDK_WINDOW_XID(gtk_widget_get_window(dialog))); |
| 278 | 282 |
| 279 gtk_widget_show_all(dialog); | 283 gtk_widget_show_all(dialog); |
| 280 | 284 |
| 281 // We need to call gtk_window_present after making the widgets visible to make | 285 // We need to call gtk_window_present after making the widgets visible to make |
| 282 // sure window gets correctly raised and gets focus. | 286 // sure window gets correctly raised and gets focus. |
| 283 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); | 287 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); |
| 284 gtk_window_present_with_time(GTK_WINDOW(dialog), time); | 288 gtk_window_present_with_time(GTK_WINDOW(dialog), time); |
| 285 } | 289 } |
| 286 | 290 |
| 287 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { | 291 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 dialogs_.erase(dialog); | 522 dialogs_.erase(dialog); |
| 519 | 523 |
| 520 // Parent may be NULL in a few cases: 1) on shutdown when | 524 // Parent may be NULL in a few cases: 1) on shutdown when |
| 521 // AllBrowsersClosed() trigger this handler after all the browser | 525 // AllBrowsersClosed() trigger this handler after all the browser |
| 522 // windows got destroyed, or 2) when the parent tab has been opened by | 526 // windows got destroyed, or 2) when the parent tab has been opened by |
| 523 // 'Open Link in New Tab' context menu on a downloadable item and | 527 // 'Open Link in New Tab' context menu on a downloadable item and |
| 524 // the tab has no content (see the comment in SelectFile as well). | 528 // the tab has no content (see the comment in SelectFile as well). |
| 525 aura::Window* parent = GetAuraTransientParent(dialog); | 529 aura::Window* parent = GetAuraTransientParent(dialog); |
| 526 if (!parent) | 530 if (!parent) |
| 527 return; | 531 return; |
| 532 |
| 533 views::DesktopWindowTreeHostX11* host = |
| 534 views::DesktopWindowTreeHostX11::GetHostForXID( |
| 535 parent->GetHost()->GetAcceleratedWidget()); |
| 536 host->EnableEventListening(); |
| 537 |
| 528 std::set<aura::Window*>::iterator iter = parents_.find(parent); | 538 std::set<aura::Window*>::iterator iter = parents_.find(parent); |
| 529 if (iter != parents_.end()) { | 539 if (iter != parents_.end()) { |
| 530 (*iter)->RemoveObserver(this); | 540 (*iter)->RemoveObserver(this); |
| 531 parents_.erase(iter); | 541 parents_.erase(iter); |
| 532 } else { | 542 } else { |
| 533 NOTREACHED(); | 543 NOTREACHED(); |
| 534 } | 544 } |
| 535 } | 545 } |
| 536 | 546 |
| 537 bool SelectFileDialogImplGTK::IsCancelResponse(gint response_id) { | 547 bool SelectFileDialogImplGTK::IsCancelResponse(gint response_id) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 g_free(filename); | 637 g_free(filename); |
| 628 if (pixbuf) { | 638 if (pixbuf) { |
| 629 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); | 639 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); |
| 630 g_object_unref(pixbuf); | 640 g_object_unref(pixbuf); |
| 631 } | 641 } |
| 632 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), | 642 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), |
| 633 pixbuf ? TRUE : FALSE); | 643 pixbuf ? TRUE : FALSE); |
| 634 } | 644 } |
| 635 | 645 |
| 636 } // namespace libgtk2ui | 646 } // namespace libgtk2ui |
| OLD | NEW |