Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc

Issue 1624793002: Make File-Picker modal on Linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove ScopedHandle Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/libgtk2ui/select_file_dialog_interactive_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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() when the file-picker
54 // is closed.
55 void OnFilePickerDestroy(base::Closure* callback) {
56 callback->Run();
57 }
58
51 } // namespace 59 } // namespace
52 60
53 namespace libgtk2ui { 61 namespace libgtk2ui {
54 62
55 // The size of the preview we display for selected image files. We set height 63 // 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 64 // larger than width because generally there is more free space vertically
57 // than horiztonally (setting the preview image will alway expand the width of 65 // 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 66 // the dialog, but usually not the height). The image's aspect ratio will always
59 // be preserved. 67 // be preserved.
60 static const int kPreviewWidth = 256; 68 static const int kPreviewWidth = 256;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 162
155 preview_ = gtk_image_new(); 163 preview_ = gtk_image_new();
156 g_signal_connect(dialog, "destroy", 164 g_signal_connect(dialog, "destroy",
157 G_CALLBACK(OnFileChooserDestroyThunk), this); 165 G_CALLBACK(OnFileChooserDestroyThunk), this);
158 g_signal_connect(dialog, "update-preview", 166 g_signal_connect(dialog, "update-preview",
159 G_CALLBACK(OnUpdatePreviewThunk), this); 167 G_CALLBACK(OnUpdatePreviewThunk), this);
160 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); 168 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_);
161 169
162 params_map_[dialog] = params; 170 params_map_[dialog] = params;
163 171
164 // TODO(erg): Figure out how to fake GTK window-to-parent modality without 172 // Disable input events handling in the host window to make this dialog modal.
165 // having the parent be a real GtkWindow. 173 views::DesktopWindowTreeHostX11* host =
174 views::DesktopWindowTreeHostX11::GetHostForXID(
175 owning_window->GetHost()->GetAcceleratedWidget());
176 std::unique_ptr<base::Closure> callback = host->DisableEventListening(
177 GDK_WINDOW_XID(gtk_widget_get_window(dialog)));
178 // OnFilePickerDestroy() is called when |dialog| destroyed, which allows to
179 // invoke the callback function to re-enable events on the owning window.
180 g_object_set_data_full(G_OBJECT(dialog), "callback", callback.release(),
181 reinterpret_cast<GDestroyNotify>(OnFilePickerDestroy));
166 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); 182 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
167 183
168 gtk_widget_show_all(dialog); 184 gtk_widget_show_all(dialog);
169 185
170 // We need to call gtk_window_present after making the widgets visible to make 186 // We need to call gtk_window_present after making the widgets visible to make
171 // sure window gets correctly raised and gets focus. 187 // sure window gets correctly raised and gets focus.
172 gtk_window_present_with_time( 188 gtk_window_present_with_time(
173 GTK_WINDOW(dialog), ui::X11EventSource::GetInstance()->GetTimestamp()); 189 GTK_WINDOW(dialog), ui::X11EventSource::GetInstance()->GetTimestamp());
174 } 190 }
175 191
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 g_free(filename); 547 g_free(filename);
532 if (pixbuf) { 548 if (pixbuf) {
533 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); 549 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf);
534 g_object_unref(pixbuf); 550 g_object_unref(pixbuf);
535 } 551 }
536 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), 552 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser),
537 pixbuf ? TRUE : FALSE); 553 pixbuf ? TRUE : FALSE);
538 } 554 }
539 555
540 } // namespace libgtk2ui 556 } // namespace libgtk2ui
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/libgtk2ui/select_file_dialog_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698