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