| 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/libgtk2ui/select_file_dialog_impl_gtk2.h" | 5 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.h" |
| 6 | 6 |
| 7 #include <gdk/gdkx.h> | |
| 8 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 9 #include <stddef.h> | 8 #include <stddef.h> |
| 10 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 11 #include <sys/types.h> | 10 #include <sys/types.h> |
| 12 #include <unistd.h> | 11 #include <unistd.h> |
| 13 | 12 |
| 14 #include <map> | 13 #include <map> |
| 15 #include <set> | 14 #include <set> |
| 16 #include <vector> | 15 #include <vector> |
| 17 | 16 |
| 18 // Xlib defines RootWindow | 17 // Xlib defines RootWindow |
| 19 #undef RootWindow | 18 #undef RootWindow |
| 20 | 19 |
| 21 #include "base/logging.h" | 20 #include "base/logging.h" |
| 22 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 23 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
| 24 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 25 #include "base/strings/sys_string_conversions.h" | 24 #include "base/strings/sys_string_conversions.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
| 28 #include "base/threading/thread_restrictions.h" | 27 #include "base/threading/thread_restrictions.h" |
| 29 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h" | 28 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h" |
| 30 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" | 29 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" |
| 31 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h" | 30 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h" |
| 32 #include "ui/aura/window_observer.h" | 31 #include "ui/aura/window_observer.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/shell_dialogs/select_file_dialog.h" | 33 #include "ui/shell_dialogs/select_file_dialog.h" |
| 35 #include "ui/strings/grit/ui_strings.h" | 34 #include "ui/strings/grit/ui_strings.h" |
| 36 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | |
| 37 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" | 35 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" |
| 38 | 36 |
| 39 namespace { | 37 namespace { |
| 40 | 38 |
| 41 // Makes sure that .jpg also shows .JPG. | 39 // Makes sure that .jpg also shows .JPG. |
| 42 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info, | 40 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info, |
| 43 std::string* file_extension) { | 41 std::string* file_extension) { |
| 44 return base::EndsWith(file_info->filename, *file_extension, | 42 return base::EndsWith(file_info->filename, *file_extension, |
| 45 base::CompareCase::INSENSITIVE_ASCII); | 43 base::CompareCase::INSENSITIVE_ASCII); |
| 46 } | 44 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 157 |
| 160 preview_ = gtk_image_new(); | 158 preview_ = gtk_image_new(); |
| 161 g_signal_connect(dialog, "destroy", | 159 g_signal_connect(dialog, "destroy", |
| 162 G_CALLBACK(OnFileChooserDestroyThunk), this); | 160 G_CALLBACK(OnFileChooserDestroyThunk), this); |
| 163 g_signal_connect(dialog, "update-preview", | 161 g_signal_connect(dialog, "update-preview", |
| 164 G_CALLBACK(OnUpdatePreviewThunk), this); | 162 G_CALLBACK(OnUpdatePreviewThunk), this); |
| 165 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); | 163 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); |
| 166 | 164 |
| 167 params_map_[dialog] = params; | 165 params_map_[dialog] = params; |
| 168 | 166 |
| 169 if (owning_window && owning_window->GetHost()) { | 167 // TODO(erg): Figure out how to fake GTK window-to-parent modality without |
| 170 // Disable input events handling in the host to make this dialog modal. | 168 // having the parent be a real GtkWindow. |
| 171 views::DesktopWindowTreeHostX11* host = | 169 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); |
| 172 views::DesktopWindowTreeHostX11::GetHostForXID( | |
| 173 owning_window->GetHost()->GetAcceleratedWidget()); | |
| 174 host->DisableEventListening(GDK_WINDOW_XID(gtk_widget_get_window(dialog))); | |
| 175 } | |
| 176 | 170 |
| 177 gtk_widget_show_all(dialog); | 171 gtk_widget_show_all(dialog); |
| 178 | 172 |
| 179 // We need to call gtk_window_present after making the widgets visible to make | 173 // We need to call gtk_window_present after making the widgets visible to make |
| 180 // sure window gets correctly raised and gets focus. | 174 // sure window gets correctly raised and gets focus. |
| 181 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); | 175 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); |
| 182 gtk_window_present_with_time(GTK_WINDOW(dialog), time); | 176 gtk_window_present_with_time(GTK_WINDOW(dialog), time); |
| 183 } | 177 } |
| 184 | 178 |
| 185 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { | 179 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 dialogs_.erase(dialog); | 418 dialogs_.erase(dialog); |
| 425 | 419 |
| 426 // Parent may be NULL in a few cases: 1) on shutdown when | 420 // Parent may be NULL in a few cases: 1) on shutdown when |
| 427 // AllBrowsersClosed() trigger this handler after all the browser | 421 // AllBrowsersClosed() trigger this handler after all the browser |
| 428 // windows got destroyed, or 2) when the parent tab has been opened by | 422 // windows got destroyed, or 2) when the parent tab has been opened by |
| 429 // 'Open Link in New Tab' context menu on a downloadable item and | 423 // 'Open Link in New Tab' context menu on a downloadable item and |
| 430 // the tab has no content (see the comment in SelectFile as well). | 424 // the tab has no content (see the comment in SelectFile as well). |
| 431 aura::Window* parent = GetAuraTransientParent(dialog); | 425 aura::Window* parent = GetAuraTransientParent(dialog); |
| 432 if (!parent) | 426 if (!parent) |
| 433 return; | 427 return; |
| 434 | |
| 435 views::DesktopWindowTreeHostX11* host = | |
| 436 views::DesktopWindowTreeHostX11::GetHostForXID( | |
| 437 parent->GetHost()->GetAcceleratedWidget()); | |
| 438 host->EnableEventListening(); | |
| 439 | |
| 440 std::set<aura::Window*>::iterator iter = parents_.find(parent); | 428 std::set<aura::Window*>::iterator iter = parents_.find(parent); |
| 441 if (iter != parents_.end()) { | 429 if (iter != parents_.end()) { |
| 442 (*iter)->RemoveObserver(this); | 430 (*iter)->RemoveObserver(this); |
| 443 parents_.erase(iter); | 431 parents_.erase(iter); |
| 444 } else { | 432 } else { |
| 445 NOTREACHED(); | 433 NOTREACHED(); |
| 446 } | 434 } |
| 447 } | 435 } |
| 448 | 436 |
| 449 bool SelectFileDialogImplGTK::IsCancelResponse(gint response_id) { | 437 bool SelectFileDialogImplGTK::IsCancelResponse(gint response_id) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 g_free(filename); | 541 g_free(filename); |
| 554 if (pixbuf) { | 542 if (pixbuf) { |
| 555 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); | 543 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); |
| 556 g_object_unref(pixbuf); | 544 g_object_unref(pixbuf); |
| 557 } | 545 } |
| 558 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), | 546 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), |
| 559 pixbuf ? TRUE : FALSE); | 547 pixbuf ? TRUE : FALSE); |
| 560 } | 548 } |
| 561 | 549 |
| 562 } // namespace libgtk2ui | 550 } // namespace libgtk2ui |
| OLD | NEW |