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

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: use ANNOTATE_SCOPED_MEMORY_LEAK 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
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/views/frame/browser_view_focus_uitest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..507c6ff20c3baf64a634852b9b7a4492dfd9d40e 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.
msw 2015/10/23 19:01:19 nit: add a blank line above.
joone 2015/10/23 22:20:47 Done.
+ void Close() override;
protected:
~SelectFileDialogImplGTK() override;
@@ -289,6 +293,39 @@ void SelectFileDialogImplGTK::SelectFileImpl(
gtk_window_present_with_time(GTK_WINDOW(dialog), time);
}
+// Close the file-picker by sending an ESC key event to it.
msw 2015/10/23 19:01:19 nit: move this comment to the function declaration
joone 2015/10/23 22:20:47 Done.
+void SelectFileDialogImplGTK::Close() {
+ // Get the focused window.
+ XID focused_window;
msw 2015/10/23 19:01:19 nit: init to 0 (or None from usr/include/X11/X.h)
joone 2015/10/23 22:20:47 Done.
+ int revert;
msw 2015/10/23 19:01:19 nit: init to RevertToParent or 0? (maybe nix this
joone 2015/10/23 22:20:47 When I pass nullptr, it crashes.
+ 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) {
+ 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.
msw 2015/10/23 19:01:19 nit: bars around |focused_window| or use the gener
joone 2015/10/23 22:20:47 Done.
+ XKeyEvent event;
msw 2015/10/23 19:01:19 nit: init with {0} and drop the following memset.
joone 2015/10/23 22:20:47 Done.
+ 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));
msw 2015/10/23 19:01:19 nit: indent to match "gfx::" inside the open paren
joone 2015/10/23 22:20:47 Done.
+}
+
void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) {
for (size_t i = 0; i < file_types_.extensions.size(); ++i) {
GtkFileFilter* filter = NULL;
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | 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