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/events/platform/x11/x11_event_source.h" | 34 #include "ui/events/platform/x11/x11_event_source.h" |
34 #include "ui/shell_dialogs/select_file_dialog.h" | 35 #include "ui/shell_dialogs/select_file_dialog.h" |
35 #include "ui/strings/grit/ui_strings.h" | 36 #include "ui/strings/grit/ui_strings.h" |
| 37 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 163 |
155 preview_ = gtk_image_new(); | 164 preview_ = gtk_image_new(); |
156 g_signal_connect(dialog, "destroy", | 165 g_signal_connect(dialog, "destroy", |
157 G_CALLBACK(OnFileChooserDestroyThunk), this); | 166 G_CALLBACK(OnFileChooserDestroyThunk), this); |
158 g_signal_connect(dialog, "update-preview", | 167 g_signal_connect(dialog, "update-preview", |
159 G_CALLBACK(OnUpdatePreviewThunk), this); | 168 G_CALLBACK(OnUpdatePreviewThunk), this); |
160 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); | 169 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); |
161 | 170 |
162 params_map_[dialog] = params; | 171 params_map_[dialog] = params; |
163 | 172 |
164 // TODO(erg): Figure out how to fake GTK window-to-parent modality without | 173 // Disable input events handling in the host window to make this dialog modal. |
165 // having the parent be a real GtkWindow. | 174 views::DesktopWindowTreeHostX11* host = |
| 175 views::DesktopWindowTreeHostX11::GetHostForXID( |
| 176 owning_window->GetHost()->GetAcceleratedWidget()); |
| 177 std::unique_ptr<views::DesktopWindowTreeHostX11::ScopedHandle> scoped_handle = |
| 178 host->DisableEventListening( |
| 179 GDK_WINDOW_XID(gtk_widget_get_window(dialog))); |
| 180 // OnFilePickerDestroy() is called when |dialog| destroyed. The callback |
| 181 // destroys the ScopedHandle instance, thus re-enabling events on the |
| 182 // owning window. |
| 183 g_object_set_data_full(G_OBJECT(dialog), "scoped_handle", |
| 184 scoped_handle.release(), |
| 185 reinterpret_cast<GDestroyNotify>(OnFilePickerDestroy)); |
166 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); | 186 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); |
167 | |
168 gtk_widget_show_all(dialog); | 187 gtk_widget_show_all(dialog); |
169 | 188 |
170 // We need to call gtk_window_present after making the widgets visible to make | 189 // We need to call gtk_window_present after making the widgets visible to make |
171 // sure window gets correctly raised and gets focus. | 190 // sure window gets correctly raised and gets focus. |
172 gtk_window_present_with_time( | 191 gtk_window_present_with_time( |
173 GTK_WINDOW(dialog), ui::X11EventSource::GetInstance()->GetTimestamp()); | 192 GTK_WINDOW(dialog), ui::X11EventSource::GetInstance()->GetTimestamp()); |
174 } | 193 } |
175 | 194 |
176 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { | 195 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { |
177 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { | 196 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 g_free(filename); | 550 g_free(filename); |
532 if (pixbuf) { | 551 if (pixbuf) { |
533 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); | 552 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); |
534 g_object_unref(pixbuf); | 553 g_object_unref(pixbuf); |
535 } | 554 } |
536 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), | 555 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), |
537 pixbuf ? TRUE : FALSE); | 556 pixbuf ? TRUE : FALSE); |
538 } | 557 } |
539 | 558 |
540 } // namespace libgtk2ui | 559 } // namespace libgtk2ui |
OLD | NEW |