Chromium Code Reviews| 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 = |
| 178 views::DesktopWindowTreeHostX11::GetHostForXID( | |
| 179 owning_window->GetHost()->GetAcceleratedWidget()); | |
| 180 std::unique_ptr<views::DesktopWindowTreeHostX11::ScopedHandle> scoped_handle = | |
| 181 host->DisableEventListening( | |
| 182 GDK_WINDOW_XID(gtk_widget_get_window(dialog))); | |
| 183 // OnFilePickerDestroy() is called when |dialog| destroyed. The callback | |
| 184 // destroys the ScopedHandle instance, this re-enabling events on the | |
|
sadrul
2016/05/11 05:27:47
*thus
| |
| 185 // owning window. | |
| 186 g_object_set_data_full(G_OBJECT(dialog), "scoped_handle", | |
| 187 scoped_handle.release(), | |
| 188 reinterpret_cast<GDestroyNotify>(OnFilePickerDestroy)); | |
| 169 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); | 189 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); |
| 170 | |
| 171 gtk_widget_show_all(dialog); | 190 gtk_widget_show_all(dialog); |
| 172 | 191 |
| 173 // We need to call gtk_window_present after making the widgets visible to make | 192 // We need to call gtk_window_present after making the widgets visible to make |
| 174 // sure window gets correctly raised and gets focus. | 193 // sure window gets correctly raised and gets focus. |
| 175 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); | 194 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); |
| 176 gtk_window_present_with_time(GTK_WINDOW(dialog), time); | 195 gtk_window_present_with_time(GTK_WINDOW(dialog), time); |
| 177 } | 196 } |
| 178 | 197 |
| 179 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { | 198 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { |
| 180 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { | 199 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); | 560 g_free(filename); |
| 542 if (pixbuf) { | 561 if (pixbuf) { |
| 543 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); | 562 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); |
| 544 g_object_unref(pixbuf); | 563 g_object_unref(pixbuf); |
| 545 } | 564 } |
| 546 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), | 565 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), |
| 547 pixbuf ? TRUE : FALSE); | 566 pixbuf ? TRUE : FALSE); |
| 548 } | 567 } |
| 549 | 568 |
| 550 } // namespace libgtk2ui | 569 } // namespace libgtk2ui |
| OLD | NEW |