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

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

Issue 221813010: Sets transient for PrintDialogGtk2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/libgtk2ui/print_dialog_gtk2.cc ('k') | no next file » | 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/gdk.h>
6 #include <gdk/gdkx.h>
7 #include <gtk/gtk.h> 5 #include <gtk/gtk.h>
8 #include <map> 6 #include <map>
9 #include <set> 7 #include <set>
10 #include <vector> 8 #include <vector>
11 9
12 // Xlib defines RootWindow 10 // Xlib defines RootWindow
13 #undef RootWindow 11 #undef RootWindow
14 12
15 #include "base/logging.h" 13 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
17 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
18 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
19 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
21 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
22 #include "base/threading/thread_restrictions.h" 20 #include "base/threading/thread_restrictions.h"
23 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h" 21 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h"
22 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h"
24 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h" 23 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h"
25 #include "grit/ui_strings.h" 24 #include "grit/ui_strings.h"
26 #include "ui/aura/window_observer.h" 25 #include "ui/aura/window_observer.h"
27 #include "ui/aura/window_tree_host.h"
28 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/shell_dialogs/select_file_dialog.h" 27 #include "ui/shell_dialogs/select_file_dialog.h"
30 28
31 namespace { 29 namespace {
32 30
33 const char kAuraTransientParent[] = "aura-transient-parent";
34
35 // Set |dialog| as transient for |parent|, which will keep it on top and center
36 // it above |parent|.
37 void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent) {
38 gtk_widget_realize(dialog);
39 GdkWindow* gdk_window = gtk_widget_get_window(dialog);
40
41 // TODO(erg): Check to make sure we're using X11 if wayland or some other
42 // display server ever happens. Otherwise, this will crash.
43 XSetTransientForHint(GDK_WINDOW_XDISPLAY(gdk_window),
44 GDK_WINDOW_XID(gdk_window),
45 parent->GetHost()->GetAcceleratedWidget());
46
47 // We also set the |parent| as a property of |dialog|, so that we can unlink
48 // the two later.
49 g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, parent);
50 }
51
52 // Makes sure that .jpg also shows .JPG. 31 // Makes sure that .jpg also shows .JPG.
53 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info, 32 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info,
54 std::string* file_extension) { 33 std::string* file_extension) {
55 return EndsWith(file_info->filename, *file_extension, false); 34 return EndsWith(file_info->filename, *file_extension, false);
56 } 35 }
57 36
58 // Deletes |data| when gtk_file_filter_add_custom() is done with it. 37 // Deletes |data| when gtk_file_filter_add_custom() is done with it.
59 void OnFileFilterDataDestroyed(std::string* file_extension) { 38 void OnFileFilterDataDestroyed(std::string* file_extension) {
60 delete file_extension; 39 delete file_extension;
61 } 40 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 180 }
202 181
203 bool SelectFileDialogImplGTK::HasMultipleFileTypeChoicesImpl() { 182 bool SelectFileDialogImplGTK::HasMultipleFileTypeChoicesImpl() {
204 return file_types_.extensions.size() > 1; 183 return file_types_.extensions.size() > 1;
205 } 184 }
206 185
207 void SelectFileDialogImplGTK::OnWindowDestroying(aura::Window* window) { 186 void SelectFileDialogImplGTK::OnWindowDestroying(aura::Window* window) {
208 // Remove the |parent| property associated with the |dialog|. 187 // Remove the |parent| property associated with the |dialog|.
209 for (std::set<GtkWidget*>::iterator it = dialogs_.begin(); 188 for (std::set<GtkWidget*>::iterator it = dialogs_.begin();
210 it != dialogs_.end(); ++it) { 189 it != dialogs_.end(); ++it) {
211 aura::Window* parent = reinterpret_cast<aura::Window*>( 190 aura::Window* parent = GetAuraTransientParent(*it);
212 g_object_get_data(G_OBJECT(*it), kAuraTransientParent));
213 if (parent == window) 191 if (parent == window)
214 g_object_set_data(G_OBJECT(*it), kAuraTransientParent, NULL); 192 ClearAuraTransientParent(*it);
215 } 193 }
216 194
217 std::set<aura::Window*>::iterator iter = parents_.find(window); 195 std::set<aura::Window*>::iterator iter = parents_.find(window);
218 if (iter != parents_.end()) { 196 if (iter != parents_.end()) {
219 (*iter)->RemoveObserver(this); 197 (*iter)->RemoveObserver(this);
220 parents_.erase(iter); 198 parents_.erase(iter);
221 } 199 }
222 } 200 }
223 201
224 // We ignore |default_extension|. 202 // We ignore |default_extension|.
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 } 496 }
519 497
520 void SelectFileDialogImplGTK::FileDialogDestroyed(GtkWidget* dialog) { 498 void SelectFileDialogImplGTK::FileDialogDestroyed(GtkWidget* dialog) {
521 dialogs_.erase(dialog); 499 dialogs_.erase(dialog);
522 500
523 // Parent may be NULL in a few cases: 1) on shutdown when 501 // Parent may be NULL in a few cases: 1) on shutdown when
524 // AllBrowsersClosed() trigger this handler after all the browser 502 // AllBrowsersClosed() trigger this handler after all the browser
525 // windows got destroyed, or 2) when the parent tab has been opened by 503 // windows got destroyed, or 2) when the parent tab has been opened by
526 // 'Open Link in New Tab' context menu on a downloadable item and 504 // 'Open Link in New Tab' context menu on a downloadable item and
527 // the tab has no content (see the comment in SelectFile as well). 505 // the tab has no content (see the comment in SelectFile as well).
528 aura::Window* parent = reinterpret_cast<aura::Window*>( 506 aura::Window* parent = GetAuraTransientParent(dialog);
529 g_object_get_data(G_OBJECT(dialog), kAuraTransientParent));
530 if (!parent) 507 if (!parent)
531 return; 508 return;
532 std::set<aura::Window*>::iterator iter = parents_.find(parent); 509 std::set<aura::Window*>::iterator iter = parents_.find(parent);
533 if (iter != parents_.end()) { 510 if (iter != parents_.end()) {
534 (*iter)->RemoveObserver(this); 511 (*iter)->RemoveObserver(this);
535 parents_.erase(iter); 512 parents_.erase(iter);
536 } else { 513 } else {
537 NOTREACHED(); 514 NOTREACHED();
538 } 515 }
539 } 516 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 g_free(filename); 608 g_free(filename);
632 if (pixbuf) { 609 if (pixbuf) {
633 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); 610 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf);
634 g_object_unref(pixbuf); 611 g_object_unref(pixbuf);
635 } 612 }
636 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), 613 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser),
637 pixbuf ? TRUE : FALSE); 614 pixbuf ? TRUE : FALSE);
638 } 615 }
639 616
640 } // namespace libgtk2ui 617 } // namespace libgtk2ui
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtk2ui/print_dialog_gtk2.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698