Index: chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc |
diff --git a/chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc b/chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc |
index 6a0cb7cb8957ab5ace97619c5bbc2c51ddd44b7f..054f6b2b46c068176097f65b74ba5bc57a3935ef 100644 |
--- a/chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc |
+++ b/chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc |
@@ -2,6 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include <gdk/gdkx.h> |
#include <gtk/gtk.h> |
#include <sys/stat.h> |
#include <sys/types.h> |
@@ -29,6 +30,7 @@ |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/shell_dialogs/select_file_dialog.h" |
#include "ui/strings/grit/ui_strings.h" |
+#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
#include "ui/views/widget/desktop_aura/x11_desktop_handler.h" |
namespace { |
@@ -56,6 +58,8 @@ class SelectFileDialogImplGTK : public SelectFileDialogImpl, |
public: |
explicit SelectFileDialogImplGTK(Listener* listener, |
ui::SelectFilePolicy* policy); |
+ // Close the file dialog. |
+ void Close() override; |
protected: |
~SelectFileDialogImplGTK() override; |
@@ -289,6 +293,40 @@ void SelectFileDialogImplGTK::SelectFileImpl( |
gtk_window_present_with_time(GTK_WINDOW(dialog), time); |
} |
+// Close the file-picker by sending an ESC key event to it. |
+void SelectFileDialogImplGTK::Close() { |
+ // Get the focused window. |
+ XID focused_window; |
+ int revert; |
+ XGetInputFocus(gfx::GetXDisplay(), &focused_window, &revert); |
+ |
+ // Check if the focused window is the file-picker dailog. |
msw
2015/10/20 23:18:14
nit: 'dialog'
joone
2015/10/22 02:14:47
Done.
|
+ bool is_dialog_focused = false; |
+ for (std::set<GtkWidget*>::iterator it = dialogs_.begin(); |
msw
2015/10/20 23:18:14
nit: "auto it"
joone
2015/10/22 02:14:47
Done.
|
+ it != dialogs_.end(); ++it) { |
+ if (focused_window == GDK_WINDOW_XID(gtk_widget_get_window(*it))) { |
+ is_dialog_focused = true; |
+ break; |
+ } |
+ } |
+ |
+ if (!is_dialog_focused) { |
+ LOG(ERROR) << "Cannot find the focused dialog"; |
msw
2015/10/20 23:18:14
nit: make this a "NOTREACHED() << ...;" to crash i
joone
2015/10/22 02:14:47
Done.
|
+ return; |
+ } |
+ |
+ // Send an ESC key event to the focused_window. |
+ XKeyEvent event; |
+ memset(&event, 0, sizeof(event)); |
+ event.display = gfx::GetXDisplay(); |
+ event.window = focused_window; |
+ event.keycode = XKeysymToKeycode(gfx::GetXDisplay(), XK_Escape); |
+ event.type = KeyPress; |
+ |
+ XSendEvent(gfx::GetXDisplay(), focused_window, True, KeyPressMask, |
+ reinterpret_cast<XEvent*>(&event)); |
+} |
+ |
void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { |
for (size_t i = 0; i < file_types_.extensions.size(); ++i) { |
GtkFileFilter* filter = NULL; |