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

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: call gtk_widget_destroy() to close the file-picker Created 5 years, 1 month 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/views/frame/browser_view_focus_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 <gdk/gdkx.h>
5 #include <gtk/gtk.h> 6 #include <gtk/gtk.h>
6 #include <sys/stat.h> 7 #include <sys/stat.h>
7 #include <sys/types.h> 8 #include <sys/types.h>
8 #include <unistd.h> 9 #include <unistd.h>
9 10
10 #include <map> 11 #include <map>
11 #include <set> 12 #include <set>
12 #include <vector> 13 #include <vector>
13 14
14 // Xlib defines RootWindow 15 // Xlib defines RootWindow
15 #undef RootWindow 16 #undef RootWindow
16 17
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
19 #include "base/message_loop/message_loop.h" 20 #include "base/message_loop/message_loop.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/strings/sys_string_conversions.h" 22 #include "base/strings/sys_string_conversions.h"
22 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
23 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
24 #include "base/threading/thread_restrictions.h" 25 #include "base/threading/thread_restrictions.h"
25 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h" 26 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h"
26 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" 27 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h"
27 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h" 28 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h"
28 #include "ui/aura/window_observer.h" 29 #include "ui/aura/window_observer.h"
29 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/shell_dialogs/select_file_dialog.h" 31 #include "ui/shell_dialogs/select_file_dialog.h"
31 #include "ui/strings/grit/ui_strings.h" 32 #include "ui/strings/grit/ui_strings.h"
33 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
32 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" 34 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h"
33 35
34 namespace { 36 namespace {
35 37
36 // Makes sure that .jpg also shows .JPG. 38 // Makes sure that .jpg also shows .JPG.
37 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info, 39 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info,
38 std::string* file_extension) { 40 std::string* file_extension) {
39 return base::EndsWith(file_info->filename, *file_extension, 41 return base::EndsWith(file_info->filename, *file_extension,
40 base::CompareCase::INSENSITIVE_ASCII); 42 base::CompareCase::INSENSITIVE_ASCII);
41 } 43 }
42 44
43 // Deletes |data| when gtk_file_filter_add_custom() is done with it. 45 // Deletes |data| when gtk_file_filter_add_custom() is done with it.
44 void OnFileFilterDataDestroyed(std::string* file_extension) { 46 void OnFileFilterDataDestroyed(std::string* file_extension) {
45 delete file_extension; 47 delete file_extension;
46 } 48 }
47 49
48 } // namespace 50 } // namespace
49 51
50 namespace libgtk2ui { 52 namespace libgtk2ui {
51 53
52 // Implementation of SelectFileDialog that shows a Gtk common dialog for 54 // Implementation of SelectFileDialog that shows a Gtk common dialog for
53 // choosing a file or folder. This acts as a modal dialog. 55 // choosing a file or folder. This acts as a modal dialog.
54 class SelectFileDialogImplGTK : public SelectFileDialogImpl, 56 class SelectFileDialogImplGTK : public SelectFileDialogImpl,
55 public aura::WindowObserver { 57 public aura::WindowObserver {
56 public: 58 public:
57 explicit SelectFileDialogImplGTK(Listener* listener, 59 explicit SelectFileDialogImplGTK(Listener* listener,
58 ui::SelectFilePolicy* policy); 60 ui::SelectFilePolicy* policy);
59 61
62 // Close the file dialog.
63 void Close() override;
64
60 protected: 65 protected:
61 ~SelectFileDialogImplGTK() override; 66 ~SelectFileDialogImplGTK() override;
62 67
63 // BaseShellDialog implementation: 68 // BaseShellDialog implementation:
64 bool IsRunning(gfx::NativeWindow parent_window) const override; 69 bool IsRunning(gfx::NativeWindow parent_window) const override;
65 70
66 // SelectFileDialog implementation. 71 // SelectFileDialog implementation.
67 // |params| is user data we pass back via the Listener interface. 72 // |params| is user data we pass back via the Listener interface.
68 void SelectFileImpl(Type type, 73 void SelectFileImpl(Type type,
69 const base::string16& title, 74 const base::string16& title,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); 287 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
283 288
284 gtk_widget_show_all(dialog); 289 gtk_widget_show_all(dialog);
285 290
286 // We need to call gtk_window_present after making the widgets visible to make 291 // We need to call gtk_window_present after making the widgets visible to make
287 // sure window gets correctly raised and gets focus. 292 // sure window gets correctly raised and gets focus.
288 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); 293 int time = views::X11DesktopHandler::get()->wm_user_time_ms();
289 gtk_window_present_with_time(GTK_WINDOW(dialog), time); 294 gtk_window_present_with_time(GTK_WINDOW(dialog), time);
290 } 295 }
291 296
297 void SelectFileDialogImplGTK::Close() {
298 // Close the file-picker.
299
300 // Get the focused dialog.
301 XID focused_window = 0;
302 int revert = 0;
303 XGetInputFocus(gfx::GetXDisplay(), &focused_window, &revert);
304
305 // Check if the focused window is the file-picker dialog.
306 for (auto it = dialogs_.begin(); it != dialogs_.end(); ++it) {
307 if (focused_window == GDK_WINDOW_XID(gtk_widget_get_window(*it))) {
308 gtk_widget_destroy(*it);
309 return;
310 }
311 }
sadrul 2015/11/02 01:31:38 This seems unnecessarily complex (e.g. there's no
312
313 NOTREACHED() << "Cannot find the focused dialog";
314 }
315
292 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { 316 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) {
293 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { 317 for (size_t i = 0; i < file_types_.extensions.size(); ++i) {
294 GtkFileFilter* filter = NULL; 318 GtkFileFilter* filter = NULL;
295 std::set<std::string> fallback_labels; 319 std::set<std::string> fallback_labels;
296 320
297 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) { 321 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) {
298 const std::string& current_extension = file_types_.extensions[i][j]; 322 const std::string& current_extension = file_types_.extensions[i][j];
299 if (!current_extension.empty()) { 323 if (!current_extension.empty()) {
300 if (!filter) 324 if (!filter)
301 filter = gtk_file_filter_new(); 325 filter = gtk_file_filter_new();
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 g_free(filename); 678 g_free(filename);
655 if (pixbuf) { 679 if (pixbuf) {
656 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); 680 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf);
657 g_object_unref(pixbuf); 681 g_object_unref(pixbuf);
658 } 682 }
659 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), 683 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser),
660 pixbuf ? TRUE : FALSE); 684 pixbuf ? TRUE : FALSE);
661 } 685 }
662 686
663 } // namespace libgtk2ui 687 } // namespace libgtk2ui
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/frame/browser_view_focus_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698