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

Unified 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: skip libgtk-x11-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 side-by-side diff with in-line comments
Download patch
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..e9a6852f722987ad834dd2a2a8cebac50ee37a05 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 dialog.
+ bool is_dialog_focused = false;
+ for (auto it = dialogs_.begin();
+ it != dialogs_.end(); ++it) {
msw 2015/10/22 22:23:05 nit: fits on line above now.
joone 2015/10/23 10:51:42 Done.
+ if (focused_window == GDK_WINDOW_XID(gtk_widget_get_window(*it))) {
+ is_dialog_focused = true;
+ break;
+ }
+ }
+
+ if (!is_dialog_focused) {
+ NOTREACHED() << "Cannot find the focused dialog";
+ 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;

Powered by Google App Engine
This is Rietveld 408576698