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

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

Issue 1363093004: Add BrowserSelectFileDialogTest.OpenCloseFileDialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: enable the test and skip libglib-2.0 from LSan report Created 5 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
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 <gtk/gtk.h> 5 #include <gtk/gtk.h>
6 #include <sys/stat.h> 6 #include <sys/stat.h>
7 #include <sys/types.h> 7 #include <sys/types.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 11 matching lines...) Expand all
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/threading/thread.h" 23 #include "base/threading/thread.h"
24 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
25 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h" 25 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h"
26 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" 26 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h"
27 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h" 27 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h"
28 #include "ui/aura/window_observer.h" 28 #include "ui/aura/window_observer.h"
29 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/shell_dialogs/select_file_dialog.h" 30 #include "ui/shell_dialogs/select_file_dialog.h"
31 #include "ui/strings/grit/ui_strings.h" 31 #include "ui/strings/grit/ui_strings.h"
32 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
32 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" 33 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h"
33 34
34 namespace { 35 namespace {
35 36
36 // Makes sure that .jpg also shows .JPG. 37 // Makes sure that .jpg also shows .JPG.
37 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info, 38 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info,
38 std::string* file_extension) { 39 std::string* file_extension) {
39 return base::EndsWith(file_info->filename, *file_extension, 40 return base::EndsWith(file_info->filename, *file_extension,
40 base::CompareCase::INSENSITIVE_ASCII); 41 base::CompareCase::INSENSITIVE_ASCII);
41 } 42 }
(...skipping 24 matching lines...) Expand all
66 // SelectFileDialog implementation. 67 // SelectFileDialog implementation.
67 // |params| is user data we pass back via the Listener interface. 68 // |params| is user data we pass back via the Listener interface.
68 void SelectFileImpl(Type type, 69 void SelectFileImpl(Type type,
69 const base::string16& title, 70 const base::string16& title,
70 const base::FilePath& default_path, 71 const base::FilePath& default_path,
71 const FileTypeInfo* file_types, 72 const FileTypeInfo* file_types,
72 int file_type_index, 73 int file_type_index,
73 const base::FilePath::StringType& default_extension, 74 const base::FilePath::StringType& default_extension,
74 gfx::NativeWindow owning_window, 75 gfx::NativeWindow owning_window,
75 void* params) override; 76 void* params) override;
77 // Close the file dialog.
78 void CloseImpl() override;
76 79
77 private: 80 private:
78 bool HasMultipleFileTypeChoicesImpl() override; 81 bool HasMultipleFileTypeChoicesImpl() override;
79 82
80 // Overridden from aura::WindowObserver: 83 // Overridden from aura::WindowObserver:
81 void OnWindowDestroying(aura::Window* window) override; 84 void OnWindowDestroying(aura::Window* window) override;
82 85
83 // Add the filters from |file_types_| to |chooser|. 86 // Add the filters from |file_types_| to |chooser|.
84 void AddFilters(GtkFileChooser* chooser); 87 void AddFilters(GtkFileChooser* chooser);
85 88
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); 285 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
283 286
284 gtk_widget_show_all(dialog); 287 gtk_widget_show_all(dialog);
285 288
286 // We need to call gtk_window_present after making the widgets visible to make 289 // We need to call gtk_window_present after making the widgets visible to make
287 // sure window gets correctly raised and gets focus. 290 // sure window gets correctly raised and gets focus.
288 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); 291 int time = views::X11DesktopHandler::get()->wm_user_time_ms();
289 gtk_window_present_with_time(GTK_WINDOW(dialog), time); 292 gtk_window_present_with_time(GTK_WINDOW(dialog), time);
290 } 293 }
291 294
295 // Close the file-picker by sending an ESC key event to it.
296 void SelectFileDialogImplGTK::CloseImpl() {
297 // Get the focused window.
msw 2015/10/16 17:01:04 Can we ensure this is the dialog window somehow? O
joone 2015/10/16 23:33:46 Yes, because the file-picker is modal.
298 XID focused_window;
299 int revert;
300 XGetInputFocus(gfx::GetXDisplay(), &focused_window, &revert);
301
302 // Send an ESC key event to the focused_window.
303 XKeyEvent event;
304 memset(&event, 0, sizeof(event));
305 event.display = gfx::GetXDisplay();
306 event.window = focused_window;
307 event.keycode = XKeysymToKeycode(gfx::GetXDisplay(), XK_Escape);
308 event.type = KeyPress;
309
310 XSendEvent(gfx::GetXDisplay(), focused_window, True, KeyPressMask,
311 reinterpret_cast<XEvent*>(&event));
312 }
313
292 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { 314 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) {
293 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { 315 for (size_t i = 0; i < file_types_.extensions.size(); ++i) {
294 GtkFileFilter* filter = NULL; 316 GtkFileFilter* filter = NULL;
295 std::set<std::string> fallback_labels; 317 std::set<std::string> fallback_labels;
296 318
297 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) { 319 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) {
298 const std::string& current_extension = file_types_.extensions[i][j]; 320 const std::string& current_extension = file_types_.extensions[i][j];
299 if (!current_extension.empty()) { 321 if (!current_extension.empty()) {
300 if (!filter) 322 if (!filter)
301 filter = gtk_file_filter_new(); 323 filter = gtk_file_filter_new();
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 g_free(filename); 669 g_free(filename);
648 if (pixbuf) { 670 if (pixbuf) {
649 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); 671 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf);
650 g_object_unref(pixbuf); 672 g_object_unref(pixbuf);
651 } 673 }
652 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), 674 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser),
653 pixbuf ? TRUE : FALSE); 675 pixbuf ? TRUE : FALSE);
654 } 676 }
655 677
656 } // namespace libgtk2ui 678 } // namespace libgtk2ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698