| OLD | NEW |
| 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 <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
| 6 #include <map> | 6 #include <map> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/browser/ui/gtk/select_file_dialog_impl.h" | 18 #include "chrome/browser/ui/gtk/select_file_dialog_impl.h" |
| 19 #include "chrome/browser/ui/select_file_dialog.h" | 19 #include "chrome/browser/ui/select_file_dialog.h" |
| 20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 21 #include "ui/base/gtk/gtk_signal.h" | 21 #include "ui/base/gtk/gtk_signal.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 23 | 23 |
| 24 // Implementation of SelectFileDialog that shows a Gtk common dialog for | 24 // Implementation of SelectFileDialog that shows a Gtk common dialog for |
| 25 // choosing a file or folder. This acts as a modal dialog. | 25 // choosing a file or folder. This acts as a modal dialog. |
| 26 class SelectFileDialogImplGTK : public SelectFileDialogImpl { | 26 class SelectFileDialogImplGTK : public SelectFileDialogImpl { |
| 27 public: | 27 public: |
| 28 explicit SelectFileDialogImplGTK(Listener* listener, | 28 explicit SelectFileDialogImplGTK(Listener* listener); |
| 29 ui::SelectFilePolicy* policy); | |
| 30 | 29 |
| 31 protected: | 30 protected: |
| 32 virtual ~SelectFileDialogImplGTK(); | 31 virtual ~SelectFileDialogImplGTK(); |
| 33 | 32 |
| 34 // SelectFileDialog implementation. | 33 // SelectFileDialog implementation. |
| 35 // |params| is user data we pass back via the Listener interface. | 34 // |params| is user data we pass back via the Listener interface. |
| 36 virtual void SelectFileImpl(Type type, | 35 virtual void SelectFileImpl(Type type, |
| 37 const string16& title, | 36 const string16& title, |
| 38 const FilePath& default_path, | 37 const FilePath& default_path, |
| 39 const FileTypeInfo* file_types, | 38 const FileTypeInfo* file_types, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 125 |
| 127 // The size of the preview we display for selected image files. We set height | 126 // The size of the preview we display for selected image files. We set height |
| 128 // larger than width because generally there is more free space vertically | 127 // larger than width because generally there is more free space vertically |
| 129 // than horiztonally (setting the preview image will alway expand the width of | 128 // than horiztonally (setting the preview image will alway expand the width of |
| 130 // the dialog, but usually not the height). The image's aspect ratio will always | 129 // the dialog, but usually not the height). The image's aspect ratio will always |
| 131 // be preserved. | 130 // be preserved. |
| 132 static const int kPreviewWidth = 256; | 131 static const int kPreviewWidth = 256; |
| 133 static const int kPreviewHeight = 512; | 132 static const int kPreviewHeight = 512; |
| 134 | 133 |
| 135 SelectFileDialogImpl* SelectFileDialogImpl::NewSelectFileDialogImplGTK( | 134 SelectFileDialogImpl* SelectFileDialogImpl::NewSelectFileDialogImplGTK( |
| 136 Listener* listener, ui::SelectFilePolicy* policy) { | 135 Listener* listener) { |
| 137 return new SelectFileDialogImplGTK(listener, policy); | 136 return new SelectFileDialogImplGTK(listener); |
| 138 } | 137 } |
| 139 | 138 |
| 140 SelectFileDialogImplGTK::SelectFileDialogImplGTK(Listener* listener, | 139 SelectFileDialogImplGTK::SelectFileDialogImplGTK(Listener* listener) |
| 141 ui::SelectFilePolicy* policy) | 140 : SelectFileDialogImpl(listener), |
| 142 : SelectFileDialogImpl(listener, policy), | |
| 143 preview_(NULL) { | 141 preview_(NULL) { |
| 144 } | 142 } |
| 145 | 143 |
| 146 SelectFileDialogImplGTK::~SelectFileDialogImplGTK() { | 144 SelectFileDialogImplGTK::~SelectFileDialogImplGTK() { |
| 147 while (dialogs_.begin() != dialogs_.end()) { | 145 while (dialogs_.begin() != dialogs_.end()) { |
| 148 gtk_widget_destroy(*(dialogs_.begin())); | 146 gtk_widget_destroy(*(dialogs_.begin())); |
| 149 } | 147 } |
| 150 } | 148 } |
| 151 | 149 |
| 152 bool SelectFileDialogImplGTK::HasMultipleFileTypeChoicesImpl() { | 150 bool SelectFileDialogImplGTK::HasMultipleFileTypeChoicesImpl() { |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth, | 537 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth, |
| 540 kPreviewHeight, NULL); | 538 kPreviewHeight, NULL); |
| 541 g_free(filename); | 539 g_free(filename); |
| 542 if (pixbuf) { | 540 if (pixbuf) { |
| 543 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); | 541 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); |
| 544 g_object_unref(pixbuf); | 542 g_object_unref(pixbuf); |
| 545 } | 543 } |
| 546 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), | 544 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), |
| 547 pixbuf ? TRUE : FALSE); | 545 pixbuf ? TRUE : FALSE); |
| 548 } | 546 } |
| OLD | NEW |