Commit ec5f4330 authored by erg@chromium.org's avatar erg@chromium.org

Use current gtk dialogs in linux_aura.

They payoff for the last month of refactoring: We now use the LinuxUI interface
to generate gtk file selection dialogs from the shim library. We could
theoretically make a Qt or EFL shim and get those desktops' native open
dialogs.

BUG=136909, 134167
TEST=none


Review URL: https://chromiumcodereview.appspot.com/10829021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148813 0039d316-1c4b-4281-b951-d872f2087c98
parent fa4f3668
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_LIBGTK2UI_GTK2_SIGNAL_H_
#define CHROME_BROWSER_UI_LIBGTK2UI_GTK2_SIGNAL_H_
#include "ui/base/glib/glib_signal.h"
typedef struct _GtkWidget GtkWidget;
// These macros handle the common case where the sender object will be a
// GtkWidget*.
#define CHROMEGTK_CALLBACK_0(CLASS, RETURN, METHOD) \
CHROMEG_CALLBACK_0(CLASS, RETURN, METHOD, GtkWidget*);
#define CHROMEGTK_CALLBACK_1(CLASS, RETURN, METHOD, ARG1) \
CHROMEG_CALLBACK_1(CLASS, RETURN, METHOD, GtkWidget*, ARG1);
#define CHROMEGTK_CALLBACK_2(CLASS, RETURN, METHOD, ARG1, ARG2) \
CHROMEG_CALLBACK_2(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2);
#define CHROMEGTK_CALLBACK_3(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3) \
CHROMEG_CALLBACK_3(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, ARG3);
#define CHROMEGTK_CALLBACK_4(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3, ARG4) \
CHROMEG_CALLBACK_4(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, ARG3, \
ARG4);
#define CHROMEGTK_CALLBACK_5(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3, ARG4, \
ARG5) \
CHROMEG_CALLBACK_5(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, ARG3, \
ARG4, ARG5);
#define CHROMEGTK_CALLBACK_6(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3, ARG4, \
ARG5, ARG6) \
CHROMEG_CALLBACK_6(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, ARG3, \
ARG4, ARG5, ARG6);
#define CHROMEGTK_VIRTUAL_CALLBACK_0(CLASS, RETURN, METHOD) \
CHROMEG_VIRTUAL_CALLBACK_0(CLASS, RETURN, METHOD, GtkWidget*);
#define CHROMEGTK_VIRTUAL_CALLBACK_1(CLASS, RETURN, METHOD, ARG1) \
CHROMEG_VIRTUAL_CALLBACK_1(CLASS, RETURN, METHOD, GtkWidget*, ARG1);
#define CHROMEGTK_VIRTUAL_CALLBACK_2(CLASS, RETURN, METHOD, ARG1, ARG2) \
CHROMEG_VIRTUAL_CALLBACK_2(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2);
#define CHROMEGTK_VIRTUAL_CALLBACK_3(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3) \
CHROMEG_VIRTUAL_CALLBACK_3(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, \
ARG3);
#define CHROMEGTK_VIRTUAL_CALLBACK_4(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3, \
ARG4) \
CHROMEG_VIRTUAL_CALLBACK_4(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, \
ARG3, ARG4);
#define CHROMEGTK_VIRTUAL_CALLBACK_5(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3, \
ARG4, ARG5) \
CHROMEG_VIRTUAL_CALLBACK_5(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, \
ARG3, ARG4, ARG5);
#define CHROMEGTK_VIRTUAL_CALLBACK_6(CLASS, RETURN, METHOD, ARG1, ARG2, ARG3, \
ARG4, ARG5, ARG6) \
CHROMEG_VIRTUAL_CALLBACK_6(CLASS, RETURN, METHOD, GtkWidget*, ARG1, ARG2, \
ARG3, ARG4, ARG5, ARG6);
#endif // CHROME_BROWSER_UI_LIBGTK2UI_GTK2_SIGNAL_H_
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/ui/libgtk2ui/chrome_gtk_frame.h" #include "chrome/browser/ui/libgtk2ui/chrome_gtk_frame.h"
#include "chrome/browser/ui/libgtk2ui/gtk2_util.h" #include "chrome/browser/ui/libgtk2ui/gtk2_util.h"
#include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h"
#include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h"
#include "grit/theme_resources.h" #include "grit/theme_resources.h"
#include "grit/ui_resources.h" #include "grit/ui_resources.h"
...@@ -330,6 +331,12 @@ bool Gtk2UI::GetColor(int id, SkColor* color) const { ...@@ -330,6 +331,12 @@ bool Gtk2UI::GetColor(int id, SkColor* color) const {
return false; return false;
} }
ui::SelectFileDialog* Gtk2UI::CreateSelectFileDialog(
ui::SelectFileDialog::Listener* listener,
ui::SelectFilePolicy* policy) const {
return SelectFileDialogImpl::Create(listener, policy);
}
void Gtk2UI::GetScrollbarColors(GdkColor* thumb_active_color, void Gtk2UI::GetScrollbarColors(GdkColor* thumb_active_color,
GdkColor* thumb_inactive_color, GdkColor* thumb_inactive_color,
GdkColor* track_color) { GdkColor* track_color) {
......
...@@ -37,6 +37,9 @@ class Gtk2UI : public ui::LinuxUI { ...@@ -37,6 +37,9 @@ class Gtk2UI : public ui::LinuxUI {
virtual bool UseNativeTheme() const OVERRIDE; virtual bool UseNativeTheme() const OVERRIDE;
virtual gfx::Image* GetThemeImageNamed(int id) const OVERRIDE; virtual gfx::Image* GetThemeImageNamed(int id) const OVERRIDE;
virtual bool GetColor(int id, SkColor* color) const OVERRIDE; virtual bool GetColor(int id, SkColor* color) const OVERRIDE;
virtual ui::SelectFileDialog* CreateSelectFileDialog(
ui::SelectFileDialog::Listener* listener,
ui::SelectFilePolicy* policy) const OVERRIDE;
private: private:
typedef std::map<int, SkColor> ColorMap; typedef std::map<int, SkColor> ColorMap;
......
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
'../../../../base/base.gyp:base_i18n', '../../../../base/base.gyp:base_i18n',
'../../../../build/linux/system.gyp:gtk', '../../../../build/linux/system.gyp:gtk',
'../../../../skia/skia.gyp:skia', '../../../../skia/skia.gyp:skia',
'../../../../ui/base/strings/ui_strings.gyp:ui_strings',
'../../../../ui/ui.gyp:ui', '../../../../ui/ui.gyp:ui',
'../../../../ui/ui.gyp:ui_resources', '../../../../ui/ui.gyp:ui_resources',
'../../../chrome_resources.gyp:chrome_extra_resources', '../../../chrome_resources.gyp:chrome_extra_resources',
'../../../chrome_resources.gyp:chrome_resources', '../../../chrome_resources.gyp:chrome_resources',
'../../../chrome_resources.gyp:chrome_strings',
'../../../chrome_resources.gyp:theme_resources', '../../../chrome_resources.gyp:theme_resources',
], ],
'defines': [ 'defines': [
...@@ -39,6 +41,10 @@ ...@@ -39,6 +41,10 @@
'libgtk2ui_export.h', 'libgtk2ui_export.h',
'owned_widget_gtk2.cc', 'owned_widget_gtk2.cc',
'owned_widget_gtk2.h', 'owned_widget_gtk2.h',
'select_file_dialog_impl.cc',
'select_file_dialog_impl.h',
'select_file_dialog_impl_gtk2.cc',
'select_file_dialog_impl_kde.cc',
'skia_utils_gtk2.cc', 'skia_utils_gtk2.cc',
'skia_utils_gtk2.h', 'skia_utils_gtk2.h',
], ],
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// //
// This file implements common select dialog functionality between GTK and KDE. // This file implements common select dialog functionality between GTK and KDE.
//#include "chrome/browser/ui/gtk/select_file_dialog_impl.h" #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h"
#include "base/environment.h" #include "base/environment.h"
#include "base/file_util.h" #include "base/file_util.h"
...@@ -26,12 +26,15 @@ UseKdeFileDialogStatus use_kde_ = UNKNOWN; ...@@ -26,12 +26,15 @@ UseKdeFileDialogStatus use_kde_ = UNKNOWN;
} // namespace } // namespace
namespace libgtk2ui {
FilePath* SelectFileDialogImpl::last_saved_path_ = NULL; FilePath* SelectFileDialogImpl::last_saved_path_ = NULL;
FilePath* SelectFileDialogImpl::last_opened_path_ = NULL; FilePath* SelectFileDialogImpl::last_opened_path_ = NULL;
// static // static
SelectFileDialog* SelectFileDialog::Create(Listener* listener, ui::SelectFileDialog* SelectFileDialogImpl::Create(
ui::SelectFilePolicy* policy) { ui::SelectFileDialog::Listener* listener,
ui::SelectFilePolicy* policy) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (use_kde_ == UNKNOWN) { if (use_kde_ == UNKNOWN) {
// Start out assumimg we are not going to use KDE. // Start out assumimg we are not going to use KDE.
...@@ -88,3 +91,5 @@ bool SelectFileDialogImpl::CallDirectoryExistsOnUIThread(const FilePath& path) { ...@@ -88,3 +91,5 @@ bool SelectFileDialogImpl::CallDirectoryExistsOnUIThread(const FilePath& path) {
base::ThreadRestrictions::ScopedAllowIO allow_io; base::ThreadRestrictions::ScopedAllowIO allow_io;
return file_util::DirectoryExists(path); return file_util::DirectoryExists(path);
} }
} // namespace libgtk2ui
...@@ -4,18 +4,26 @@ ...@@ -4,18 +4,26 @@
// //
// This file implements common select dialog functionality between GTK and KDE. // This file implements common select dialog functionality between GTK and KDE.
#ifndef CHROME_BROWSER_UI_GTK_SELECT_FILE_DIALOG_IMPL_H_ #ifndef CHROME_BROWSER_UI_LIBGTK2UI_SELECT_FILE_DIALOG_IMPL_H_
#define CHROME_BROWSER_UI_GTK_SELECT_FILE_DIALOG_IMPL_H_ #define CHROME_BROWSER_UI_LIBGTK2UI_SELECT_FILE_DIALOG_IMPL_H_
#include <set> #include <set>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/nix/xdg_util.h" #include "base/nix/xdg_util.h"
#include "chrome/browser/ui/select_file_dialog.h" #include "ui/base/dialogs/select_file_dialog.h"
#include "ui/base/dialogs/select_file_policy.h"
#include "ui/aura/window.h"
namespace libgtk2ui {
// Shared implementation SelectFileDialog used by SelectFileDialogImplGTK // Shared implementation SelectFileDialog used by SelectFileDialogImplGTK
class SelectFileDialogImpl : public SelectFileDialog { class SelectFileDialogImpl : public ui::SelectFileDialog {
public: public:
// Main factory method which returns correct type.
static ui::SelectFileDialog* Create(Listener* listener,
ui::SelectFilePolicy* policy);
// Factory method for creating a GTK-styled SelectFileDialogImpl // Factory method for creating a GTK-styled SelectFileDialogImpl
static SelectFileDialogImpl* NewSelectFileDialogImplGTK( static SelectFileDialogImpl* NewSelectFileDialogImplGTK(
Listener* listener, Listener* listener,
...@@ -64,7 +72,7 @@ class SelectFileDialogImpl : public SelectFileDialog { ...@@ -64,7 +72,7 @@ class SelectFileDialogImpl : public SelectFileDialog {
size_t file_type_index_; size_t file_type_index_;
// The set of all parent windows for which we are currently running dialogs. // The set of all parent windows for which we are currently running dialogs.
std::set<GtkWindow*> parents_; std::set<aura::Window*> parents_;
// The type of dialog we are showing the user. // The type of dialog we are showing the user.
Type type_; Type type_;
...@@ -77,4 +85,6 @@ class SelectFileDialogImpl : public SelectFileDialog { ...@@ -77,4 +85,6 @@ class SelectFileDialogImpl : public SelectFileDialog {
DISALLOW_COPY_AND_ASSIGN(SelectFileDialogImpl); DISALLOW_COPY_AND_ASSIGN(SelectFileDialogImpl);
}; };
#endif // CHROME_BROWSER_UI_GTK_SELECT_FILE_DIALOG_IMPL_H_ } // namespace libgtk2ui
#endif // CHROME_BROWSER_UI_LIBGTK2UI_SELECT_FILE_DIALOG_IMPL_H_
...@@ -2,11 +2,16 @@ ...@@ -2,11 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <map> #include <map>
#include <set> #include <set>
#include <vector> #include <vector>
// Xlib defines RootWindow
#undef RootWindow
#include "base/file_util.h" #include "base/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop.h" #include "base/message_loop.h"
...@@ -15,15 +20,43 @@ ...@@ -15,15 +20,43 @@
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
//#include "chrome/browser/ui/gtk/select_file_dialog_impl.h" #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h"
#include "chrome/browser/ui/select_file_dialog.h" #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h"
#include "grit/generated_resources.h" #include "grit/ui_strings.h"
//#include "ui/base/gtk/gtk_signal.h" #include "ui/aura/root_window.h"
#include "ui/aura/window_observer.h"
#include "ui/base/dialogs/select_file_dialog.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
namespace {
const char kAuraTransientParent[] = "aura-transient-parent";
// Set |dialog| as transient for |parent|, which will keep it on top and center
// it above |parent|.
void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent) {
gtk_widget_realize(dialog);
GdkWindow* gdk_window = gtk_widget_get_window(dialog);
// TODO(erg): Check to make sure we're using X11 if wayland or some other
// display server ever happens. Otherwise, this will crash.
XSetTransientForHint(GDK_WINDOW_XDISPLAY(gdk_window),
GDK_WINDOW_XID(gdk_window),
parent->GetRootWindow()->GetAcceleratedWidget());
// We also set the |parent| as a property of |dialog|, so that we can unlink
// the two later.
g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, parent);
}
} // namespace
namespace libgtk2ui {
// Implementation of SelectFileDialog that shows a Gtk common dialog for // Implementation of SelectFileDialog that shows a Gtk common dialog for
// choosing a file or folder. This acts as a modal dialog. // choosing a file or folder. This acts as a modal dialog.
class SelectFileDialogImplGTK : public SelectFileDialogImpl { class SelectFileDialogImplGTK : public SelectFileDialogImpl,
public aura::WindowObserver {
public: public:
explicit SelectFileDialogImplGTK(Listener* listener, explicit SelectFileDialogImplGTK(Listener* listener,
ui::SelectFilePolicy* policy); ui::SelectFilePolicy* policy);
...@@ -45,6 +78,9 @@ class SelectFileDialogImplGTK : public SelectFileDialogImpl { ...@@ -45,6 +78,9 @@ class SelectFileDialogImplGTK : public SelectFileDialogImpl {
private: private:
virtual bool HasMultipleFileTypeChoicesImpl() OVERRIDE; virtual bool HasMultipleFileTypeChoicesImpl() OVERRIDE;
// Overridden from aura::WindowObserver:
virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
// Add the filters from |file_types_| to |chooser|. // Add the filters from |file_types_| to |chooser|.
void AddFilters(GtkFileChooser* chooser); void AddFilters(GtkFileChooser* chooser);
...@@ -153,6 +189,14 @@ bool SelectFileDialogImplGTK::HasMultipleFileTypeChoicesImpl() { ...@@ -153,6 +189,14 @@ bool SelectFileDialogImplGTK::HasMultipleFileTypeChoicesImpl() {
return file_types_.extensions.size() > 1; return file_types_.extensions.size() > 1;
} }
void SelectFileDialogImplGTK::OnWindowDestroying(aura::Window* window) {
std::set<aura::Window*>::iterator iter = parents_.find(window);
if (iter != parents_.end()) {
(*iter)->RemoveObserver(this);
parents_.erase(iter);
}
}
// We ignore |default_extension|. // We ignore |default_extension|.
void SelectFileDialogImplGTK::SelectFileImpl( void SelectFileDialogImplGTK::SelectFileImpl(
Type type, Type type,
...@@ -167,8 +211,10 @@ void SelectFileDialogImplGTK::SelectFileImpl( ...@@ -167,8 +211,10 @@ void SelectFileDialogImplGTK::SelectFileImpl(
// |owning_window| can be null when user right-clicks on a downloadable item // |owning_window| can be null when user right-clicks on a downloadable item
// and chooses 'Open Link in New Tab' when 'Ask where to save each file // and chooses 'Open Link in New Tab' when 'Ask where to save each file
// before downloading.' preference is turned on. (http://crbug.com/29213) // before downloading.' preference is turned on. (http://crbug.com/29213)
if (owning_window) if (owning_window) {
owning_window->AddObserver(this);
parents_.insert(owning_window); parents_.insert(owning_window);
}
std::string title_string = UTF16ToUTF8(title); std::string title_string = UTF16ToUTF8(title);
...@@ -211,10 +257,8 @@ void SelectFileDialogImplGTK::SelectFileImpl( ...@@ -211,10 +257,8 @@ void SelectFileDialogImplGTK::SelectFileImpl(
params_map_[dialog] = params; params_map_[dialog] = params;
// Set window-to-parent modality by adding the dialog to the same window // TODO(erg): Figure out how to fake GTK window-to-parent modality without
// group as the parent. // having the parent be a real GtkWindow.
gtk_window_group_add_window(gtk_window_get_group(owning_window),
GTK_WINDOW(dialog));
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
gtk_widget_show_all(dialog); gtk_widget_show_all(dialog);
...@@ -310,11 +354,12 @@ GtkWidget* SelectFileDialogImplGTK::CreateFileOpenHelper( ...@@ -310,11 +354,12 @@ GtkWidget* SelectFileDialogImplGTK::CreateFileOpenHelper(
const FilePath& default_path, const FilePath& default_path,
gfx::NativeWindow parent) { gfx::NativeWindow parent) {
GtkWidget* dialog = GtkWidget* dialog =
gtk_file_chooser_dialog_new(title.c_str(), parent, gtk_file_chooser_dialog_new(title.c_str(), NULL,
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL); NULL);
SetGtkTransientForAura(dialog, parent);
AddFilters(GTK_FILE_CHOOSER(dialog)); AddFilters(GTK_FILE_CHOOSER(dialog));
if (!default_path.empty()) { if (!default_path.empty()) {
...@@ -342,11 +387,12 @@ GtkWidget* SelectFileDialogImplGTK::CreateSelectFolderDialog( ...@@ -342,11 +387,12 @@ GtkWidget* SelectFileDialogImplGTK::CreateSelectFolderDialog(
l10n_util::GetStringUTF8(IDS_SELECT_FOLDER_DIALOG_TITLE); l10n_util::GetStringUTF8(IDS_SELECT_FOLDER_DIALOG_TITLE);
GtkWidget* dialog = GtkWidget* dialog =
gtk_file_chooser_dialog_new(title_string.c_str(), parent, gtk_file_chooser_dialog_new(title_string.c_str(), NULL,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL); NULL);
SetGtkTransientForAura(dialog, parent);
if (!default_path.empty()) { if (!default_path.empty()) {
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),
...@@ -395,11 +441,12 @@ GtkWidget* SelectFileDialogImplGTK::CreateSaveAsDialog(const std::string& title, ...@@ -395,11 +441,12 @@ GtkWidget* SelectFileDialogImplGTK::CreateSaveAsDialog(const std::string& title,
l10n_util::GetStringUTF8(IDS_SAVE_AS_DIALOG_TITLE); l10n_util::GetStringUTF8(IDS_SAVE_AS_DIALOG_TITLE);
GtkWidget* dialog = GtkWidget* dialog =
gtk_file_chooser_dialog_new(title_string.c_str(), parent, gtk_file_chooser_dialog_new(title_string.c_str(), NULL,
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL); NULL);
SetGtkTransientForAura(dialog, parent);
AddFilters(GTK_FILE_CHOOSER(dialog)); AddFilters(GTK_FILE_CHOOSER(dialog));
if (!default_path.empty()) { if (!default_path.empty()) {
...@@ -438,14 +485,17 @@ void SelectFileDialogImplGTK::FileDialogDestroyed(GtkWidget* dialog) { ...@@ -438,14 +485,17 @@ void SelectFileDialogImplGTK::FileDialogDestroyed(GtkWidget* dialog) {
// windows got destroyed, or 2) when the parent tab has been opened by // windows got destroyed, or 2) when the parent tab has been opened by
// 'Open Link in New Tab' context menu on a downloadable item and // 'Open Link in New Tab' context menu on a downloadable item and
// the tab has no content (see the comment in SelectFile as well). // the tab has no content (see the comment in SelectFile as well).
GtkWindow* parent = gtk_window_get_transient_for(GTK_WINDOW(dialog)); aura::Window* parent = reinterpret_cast<aura::Window*>(
g_object_get_data(G_OBJECT(dialog), kAuraTransientParent));
if (!parent) if (!parent)
return; return;
std::set<GtkWindow*>::iterator iter = parents_.find(parent); std::set<aura::Window*>::iterator iter = parents_.find(parent);
if (iter != parents_.end()) if (iter != parents_.end()) {
(*iter)->RemoveObserver(this);
parents_.erase(iter); parents_.erase(iter);
else } else {
NOTREACHED(); NOTREACHED();
}
} }
bool SelectFileDialogImplGTK::IsCancelResponse(gint response_id) { bool SelectFileDialogImplGTK::IsCancelResponse(gint response_id) {
...@@ -546,3 +596,5 @@ void SelectFileDialogImplGTK::OnUpdatePreview(GtkWidget* chooser) { ...@@ -546,3 +596,5 @@ void SelectFileDialogImplGTK::OnUpdatePreview(GtkWidget* chooser) {
gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser),
pixbuf ? TRUE : FALSE); pixbuf ? TRUE : FALSE);
} }
} // namespace libgtk2ui
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
#include "base/string_util.h" #include "base/string_util.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
//#include "chrome/browser/ui/gtk/select_file_dialog_impl.h" #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl.h"
// TODO(erg): Move all of this into WorkerPool.
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "grit/ui_strings.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
// These conflict with base/tracked_objects.h, so need to come last. // These conflict with base/tracked_objects.h, so need to come last.
...@@ -38,6 +38,8 @@ const char kKdialogBinary[] = "kdialog"; ...@@ -38,6 +38,8 @@ const char kKdialogBinary[] = "kdialog";
} // namespace } // namespace
namespace libgtk2ui {
// Implementation of SelectFileDialog that shows a KDE common dialog for // Implementation of SelectFileDialog that shows a KDE common dialog for
// choosing a file or folder. This acts as a modal dialog. // choosing a file or folder. This acts as a modal dialog.
class SelectFileDialogImplKDE : public SelectFileDialogImpl { class SelectFileDialogImplKDE : public SelectFileDialogImpl {
...@@ -271,11 +273,14 @@ void SelectFileDialogImplKDE::CallKDialogOutput(const KDialogParams& params) { ...@@ -271,11 +273,14 @@ void SelectFileDialogImplKDE::CallKDialogOutput(const KDialogParams& params) {
base::GetAppOutputWithExitCode(command_line, &output, &exit_code); base::GetAppOutputWithExitCode(command_line, &output, &exit_code);
if (!output.empty()) if (!output.empty())
output.erase(output.size() - 1); output.erase(output.size() - 1);
// Now the dialog is no longer showing. We can erase its parent from the // Now the dialog is no longer showing. We can erase its parent from the
// parent set. // parent set.
std::set<GtkWindow*>::iterator iter = parents_.find(params.parent); // TODO(erg): FIX THIS.
if (iter != parents_.end()) // std::set<GtkWindow*>::iterator iter = parents_.find(params.parent);
parents_.erase(iter); // if (iter != parents_.end())
// parents_.erase(iter);
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(params.callback, this, output, exit_code, base::Bind(params.callback, this, output, exit_code,
...@@ -465,3 +470,5 @@ void SelectFileDialogImplKDE::OnSelectMultiFileDialogResponse( ...@@ -465,3 +470,5 @@ void SelectFileDialogImplKDE::OnSelectMultiFileDialogResponse(
} }
MultiFilesSelected(filenames_fp, params); MultiFilesSelected(filenames_fp, params);
} }
} // namespace libgtk2ui
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ui/base/dialogs/select_file_dialog_factory.h" #include "ui/base/dialogs/select_file_dialog_factory.h"
#include "ui/base/dialogs/select_file_policy.h" #include "ui/base/dialogs/select_file_policy.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/linux_ui.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "ui/base/dialogs/select_file_dialog_win.h" #include "ui/base/dialogs/select_file_dialog_win.h"
...@@ -67,9 +68,12 @@ SelectFileDialog* SelectFileDialog::Create(Listener* listener, ...@@ -67,9 +68,12 @@ SelectFileDialog* SelectFileDialog::Create(Listener* listener,
return dialog; return dialog;
} }
// TODO(erg): Proxy to LinuxUI here. #if defined(USE_AURA) && !defined(USE_ASH) && defined(OS_LINUX)
const ui::LinuxUI* linux_ui = ui::LinuxUI::instance();
if (linux_ui)
return linux_ui->CreateSelectFileDialog(listener, policy);
#endif
// TODO(erg): Add other OSs one by one here.
#if defined(OS_WIN) && !defined(USE_AURA) #if defined(OS_WIN) && !defined(USE_AURA)
// TODO(port): The windows people need this to work in aura, too. // TODO(port): The windows people need this to work in aura, too.
return CreateWinSelectFileDialog(listener, policy); return CreateWinSelectFileDialog(listener, policy);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef UI_BASE_LINUX_UI_H_ #ifndef UI_BASE_LINUX_UI_H_
#define UI_BASE_LINUX_UI_H_ #define UI_BASE_LINUX_UI_H_
#include "ui/base/dialogs/select_file_dialog.h"
#include "ui/base/ui_export.h" #include "ui/base/ui_export.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
...@@ -16,6 +17,7 @@ class Image; ...@@ -16,6 +17,7 @@ class Image;
} }
namespace ui { namespace ui {
class SelectFilePolicy;
// Adapter class with targets to render like different toolkits. Set by any // Adapter class with targets to render like different toolkits. Set by any
// project that wants to do linux desktop native rendering. // project that wants to do linux desktop native rendering.
...@@ -42,6 +44,11 @@ class UI_EXPORT LinuxUI { ...@@ -42,6 +44,11 @@ class UI_EXPORT LinuxUI {
virtual bool UseNativeTheme() const = 0; virtual bool UseNativeTheme() const = 0;
virtual gfx::Image* GetThemeImageNamed(int id) const = 0; virtual gfx::Image* GetThemeImageNamed(int id) const = 0;
virtual bool GetColor(int id, SkColor* color) const = 0; virtual bool GetColor(int id, SkColor* color) const = 0;
// Returns a native file selection dialog.
virtual SelectFileDialog* CreateSelectFileDialog(
SelectFileDialog::Listener* listener,
SelectFilePolicy* policy) const = 0;
}; };
} // namespace ui } // namespace ui
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment