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

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

Issue 11784036: [gtk] Fix file filter bug for <input type=file accept=mime/type>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: erg@ review Created 7 years, 11 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
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> 5 #include <gdk/gdk.h>
6 #include <gdk/gdkx.h> 6 #include <gdk/gdkx.h>
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // display server ever happens. Otherwise, this will crash. 42 // display server ever happens. Otherwise, this will crash.
43 XSetTransientForHint(GDK_WINDOW_XDISPLAY(gdk_window), 43 XSetTransientForHint(GDK_WINDOW_XDISPLAY(gdk_window),
44 GDK_WINDOW_XID(gdk_window), 44 GDK_WINDOW_XID(gdk_window),
45 parent->GetRootWindow()->GetAcceleratedWidget()); 45 parent->GetRootWindow()->GetAcceleratedWidget());
46 46
47 // We also set the |parent| as a property of |dialog|, so that we can unlink 47 // We also set the |parent| as a property of |dialog|, so that we can unlink
48 // the two later. 48 // the two later.
49 g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, parent); 49 g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, parent);
50 } 50 }
51 51
52 // Makes sure that .jpg also shows .JPG. |data| is a std::string* in disguise.
53 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info,
54 gpointer data) {
55 std::string* file_extension = reinterpret_cast<std::string*>(data);
56 return EndsWith(file_info->filename, *file_extension, false);
57 }
58
59 // Deletes |data| when gtk_file_filter_add_custom() is done with it.
60 void OnFileFilterDataDestroyed(gpointer data) {
61 delete reinterpret_cast<std::string*>(data);
62 }
63
52 } // namespace 64 } // namespace
53 65
54 namespace libgtk2ui { 66 namespace libgtk2ui {
55 67
56 // Implementation of SelectFileDialog that shows a Gtk common dialog for 68 // Implementation of SelectFileDialog that shows a Gtk common dialog for
57 // choosing a file or folder. This acts as a modal dialog. 69 // choosing a file or folder. This acts as a modal dialog.
58 class SelectFileDialogImplGTK : public SelectFileDialogImpl, 70 class SelectFileDialogImplGTK : public SelectFileDialogImpl,
59 public aura::WindowObserver { 71 public aura::WindowObserver {
60 public: 72 public:
61 explicit SelectFileDialogImplGTK(Listener* listener, 73 explicit SelectFileDialogImplGTK(Listener* listener,
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { 277 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) {
266 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { 278 for (size_t i = 0; i < file_types_.extensions.size(); ++i) {
267 GtkFileFilter* filter = NULL; 279 GtkFileFilter* filter = NULL;
268 std::set<std::string> fallback_labels; 280 std::set<std::string> fallback_labels;
269 281
270 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) { 282 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) {
271 const std::string& current_extension = file_types_.extensions[i][j]; 283 const std::string& current_extension = file_types_.extensions[i][j];
272 if (!current_extension.empty()) { 284 if (!current_extension.empty()) {
273 if (!filter) 285 if (!filter)
274 filter = gtk_file_filter_new(); 286 filter = gtk_file_filter_new();
275 std::string pattern = "*." + current_extension; 287 // |file_extension| is freed in |OnFileFilterDataDestroyed()|.
276 gtk_file_filter_add_pattern(filter, pattern.c_str()); 288 std::string* file_extension = new std::string("." + current_extension);
277 fallback_labels.insert(pattern); 289 gtk_file_filter_add_custom(filter,
290 GTK_FILE_FILTER_FILENAME,
291 &FileFilterCaseInsensitive,
292 reinterpret_cast<gpointer>(file_extension),
293 &OnFileFilterDataDestroyed);
294 fallback_labels.insert(std::string("*").append(*file_extension));
278 } 295 }
279 } 296 }
280 // We didn't find any non-empty extensions to filter on. 297 // We didn't find any non-empty extensions to filter on.
281 if (!filter) 298 if (!filter)
282 continue; 299 continue;
283 300
284 // The description vector may be blank, in which case we are supposed to 301 // The description vector may be blank, in which case we are supposed to
285 // use some sort of default description based on the filter. 302 // use some sort of default description based on the filter.
286 if (i < file_types_.extension_description_overrides.size()) { 303 if (i < file_types_.extension_description_overrides.size()) {
287 gtk_file_filter_set_name(filter, UTF16ToUTF8( 304 gtk_file_filter_set_name(filter, UTF16ToUTF8(
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 g_free(filename); 606 g_free(filename);
590 if (pixbuf) { 607 if (pixbuf) {
591 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); 608 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf);
592 g_object_unref(pixbuf); 609 g_object_unref(pixbuf);
593 } 610 }
594 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), 611 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser),
595 pixbuf ? TRUE : FALSE); 612 pixbuf ? TRUE : FALSE);
596 } 613 }
597 614
598 } // namespace libgtk2ui 615 } // namespace libgtk2ui
OLDNEW
« no previous file with comments | « no previous file | ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc » ('j') | ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698