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 <memory> | 15 #include <memory> |
15 #include <set> | 16 #include <set> |
16 #include <vector> | 17 #include <vector> |
17 | 18 |
18 // Xlib defines RootWindow | 19 // Xlib defines RootWindow |
19 #undef RootWindow | 20 #undef RootWindow |
20 | 21 |
21 #include "base/logging.h" | 22 #include "base/logging.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 } |
45 | 47 |
46 // Deletes |data| when gtk_file_filter_add_custom() is done with it. | 48 // Deletes |data| when gtk_file_filter_add_custom() is done with it. |
47 void OnFileFilterDataDestroyed(std::string* file_extension) { | 49 void OnFileFilterDataDestroyed(std::string* file_extension) { |
48 delete file_extension; | 50 delete file_extension; |
49 } | 51 } |
50 | 52 |
53 // Runs DesktopWindowTreeHostX11::EnableEventListening() by calling the | |
54 // destructor of ScopedHandle class when the file-picker is closed. | |
55 void OnFilePickerDestroy(views::DesktopWindowTreeHostX11::ScopedHandle* | |
56 scoped_handle) { | |
57 delete scoped_handle; | |
58 } | |
59 | |
51 } // namespace | 60 } // namespace |
52 | 61 |
53 namespace libgtk2ui { | 62 namespace libgtk2ui { |
54 | 63 |
55 // The size of the preview we display for selected image files. We set height | 64 // The size of the preview we display for selected image files. We set height |
56 // larger than width because generally there is more free space vertically | 65 // larger than width because generally there is more free space vertically |
57 // than horiztonally (setting the preview image will alway expand the width of | 66 // than horiztonally (setting the preview image will alway expand the width of |
58 // the dialog, but usually not the height). The image's aspect ratio will always | 67 // the dialog, but usually not the height). The image's aspect ratio will always |
59 // be preserved. | 68 // be preserved. |
60 static const int kPreviewWidth = 256; | 69 static const int kPreviewWidth = 256; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 | 166 |
158 preview_ = gtk_image_new(); | 167 preview_ = gtk_image_new(); |
159 g_signal_connect(dialog, "destroy", | 168 g_signal_connect(dialog, "destroy", |
160 G_CALLBACK(OnFileChooserDestroyThunk), this); | 169 G_CALLBACK(OnFileChooserDestroyThunk), this); |
161 g_signal_connect(dialog, "update-preview", | 170 g_signal_connect(dialog, "update-preview", |
162 G_CALLBACK(OnUpdatePreviewThunk), this); | 171 G_CALLBACK(OnUpdatePreviewThunk), this); |
163 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); | 172 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); |
164 | 173 |
165 params_map_[dialog] = params; | 174 params_map_[dialog] = params; |
166 | 175 |
167 // TODO(erg): Figure out how to fake GTK window-to-parent modality without | 176 // Disable input events handling in the host window to make this dialog modal. |
168 // having the parent be a real GtkWindow. | 177 views::DesktopWindowTreeHostX11* host = |
169 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); | 178 views::DesktopWindowTreeHostX11::GetHostForXID( |
170 | 179 owning_window->GetHost()->GetAcceleratedWidget()); |
sadrul
2016/04/19 14:56:11
owning_window can be null, right? (see code/commen
joone
2016/04/19 22:29:56
I tried to reproduce the bug, but the file-picker
sadrul
2016/05/11 05:27:47
Update the code/comment from above too (lines 128:
joone
2016/05/11 19:18:05
I already did it: https://codereview.chromium.org/
| |
180 std::unique_ptr<views::DesktopWindowTreeHostX11::ScopedHandle> scoped_handle = | |
181 host->DisableEventListening( | |
182 GDK_WINDOW_XID(gtk_widget_get_window(dialog))); | |
183 g_object_set_data_full(G_OBJECT(dialog), "scoped_handle", | |
184 scoped_handle.release(), | |
185 reinterpret_cast<GDestroyNotify>(OnFilePickerDestroy)); | |
sadrul
2016/04/19 14:56:11
Add a comment here:
// OnFilePickerDestroy() is
| |
171 gtk_widget_show_all(dialog); | 186 gtk_widget_show_all(dialog); |
172 | 187 |
173 // We need to call gtk_window_present after making the widgets visible to make | 188 // We need to call gtk_window_present after making the widgets visible to make |
174 // sure window gets correctly raised and gets focus. | 189 // sure window gets correctly raised and gets focus. |
175 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); | 190 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); |
176 gtk_window_present_with_time(GTK_WINDOW(dialog), time); | 191 gtk_window_present_with_time(GTK_WINDOW(dialog), time); |
177 } | 192 } |
178 | 193 |
179 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { | 194 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { |
180 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { | 195 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 g_free(filename); | 556 g_free(filename); |
542 if (pixbuf) { | 557 if (pixbuf) { |
543 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); | 558 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); |
544 g_object_unref(pixbuf); | 559 g_object_unref(pixbuf); |
545 } | 560 } |
546 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), | 561 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), |
547 pixbuf ? TRUE : FALSE); | 562 pixbuf ? TRUE : FALSE); |
548 } | 563 } |
549 | 564 |
550 } // namespace libgtk2ui | 565 } // namespace libgtk2ui |
OLD | NEW |