Skip to content

Commit

Permalink
Cleanup ui/shell_dialogs.
Browse files Browse the repository at this point in the history
This CL removes unneeded #ifdef preprocessor directives from
select_file_dialog.cc by removing platform specific declarations of
CreateSelectFileDialog and ensuring the correct platform specific implementation
is linked.

This is helpful since it removes the need for select_file_dialog.cc to include
platform specific headers. Hence select_file_dialog_mac.h is no longer included
from a C++ context, which allows us to make Objective-C imports in the header.

This CL also moves the SelectFileDialogImpl declaration from
select_file_dialog_mac.mm to select_file_dialog_mac.h which shall facilitate
easier unit testing.

This CL also removes select_file_dialog_auraandroid.* files since these are no
longer used.

This CL is dependent on https://codereview.chromium.org/1756753002.

BUG=none

Review URL: https://codereview.chromium.org/1750233002

Cr-Commit-Position: refs/heads/master@{#379719}
  • Loading branch information
karandeepb authored and Commit bot committed Mar 8, 2016
1 parent a359420 commit 2576728
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 245 deletions.
7 changes: 0 additions & 7 deletions ui/shell_dialogs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ component("shell_dialogs") {
include_dirs = [ "$root_gen_dir/ui" ]
libs = [ "jnigraphics" ]
}

if (is_android && use_aura) {
sources += [
"select_file_dialog_auraandroid.cc",
"select_file_dialog_auraandroid.h",
]
}
}

test("shell_dialogs_unittests") {
Expand Down
27 changes: 1 addition & 26 deletions ui/shell_dialogs/select_file_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@
#include "ui/shell_dialogs/select_file_policy.h"
#include "ui/shell_dialogs/selected_file_info.h"

#if defined(OS_WIN)
#include "ui/shell_dialogs/select_file_dialog_win.h"
#elif defined(OS_MACOSX)
#include "ui/shell_dialogs/select_file_dialog_mac.h"
#elif defined(OS_ANDROID)
#include "ui/shell_dialogs/select_file_dialog_android.h"
#elif defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
#include "ui/shell_dialogs/shell_dialog_linux.h"
#endif

namespace {

// Optional dialog factory. Leaked.
Expand Down Expand Up @@ -79,22 +69,7 @@ scoped_refptr<SelectFileDialog> SelectFileDialog::Create(
return dialog;
}

#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
const ui::ShellDialogLinux* shell_dialogs = ui::ShellDialogLinux::instance();
if (shell_dialogs)
return shell_dialogs->CreateSelectFileDialog(listener, policy);
#endif

#if defined(OS_WIN)
return CreateDefaultWinSelectFileDialog(listener, policy);
#elif defined(OS_MACOSX) && !defined(USE_AURA)
return CreateMacSelectFileDialog(listener, policy);
#elif defined(OS_ANDROID)
return CreateAndroidSelectFileDialog(listener, policy);
#else
NOTIMPLEMENTED();
return NULL;
#endif
return CreateSelectFileDialog(listener, policy);
}

void SelectFileDialog::SelectFile(
Expand Down
2 changes: 2 additions & 0 deletions ui/shell_dialogs/select_file_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class SHELL_DIALOGS_EXPORT SelectFileDialog
DISALLOW_COPY_AND_ASSIGN(SelectFileDialog);
};

SelectFileDialog* CreateSelectFileDialog(SelectFileDialog::Listener* listener,
SelectFilePolicy* policy);
} // namespace ui

#endif // UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_H_
5 changes: 2 additions & 3 deletions ui/shell_dialogs/select_file_dialog_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ bool SelectFileDialogImpl::HasMultipleFileTypeChoicesImpl() {
return false;
}

SelectFileDialog* CreateAndroidSelectFileDialog(
SelectFileDialog::Listener* listener,
SelectFilePolicy* policy) {
SelectFileDialog* CreateSelectFileDialog(SelectFileDialog::Listener* listener,
SelectFilePolicy* policy) {
return SelectFileDialogImpl::Create(listener, policy);
}

Expand Down
4 changes: 0 additions & 4 deletions ui/shell_dialogs/select_file_dialog_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ class SelectFileDialogImpl : public SelectFileDialog {
DISALLOW_COPY_AND_ASSIGN(SelectFileDialogImpl);
};

SelectFileDialog* CreateAndroidSelectFileDialog(
SelectFileDialog::Listener* listener,
SelectFilePolicy* policy);

} // namespace ui

#endif // UI_SHELL_DIALOGS_ANDROID_SELECT_FILE_DIALOG_ANDROID_H_
Expand Down
56 changes: 0 additions & 56 deletions ui/shell_dialogs/select_file_dialog_auraandroid.cc

This file was deleted.

48 changes: 0 additions & 48 deletions ui/shell_dialogs/select_file_dialog_auraandroid.h

This file was deleted.

83 changes: 80 additions & 3 deletions ui/shell_dialogs/select_file_dialog_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,91 @@
#ifndef UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_MAC_H_
#define UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_MAC_H_

#import <Cocoa/Cocoa.h>

#include <map>
#include <set>

#import "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/shell_dialogs/select_file_dialog.h"

@class ExtensionDropdownHandler;
@class SelectFileDialogBridge;

namespace ui {

SelectFileDialog* CreateMacSelectFileDialog(
SelectFileDialog::Listener* listener,
SelectFilePolicy* policy);
// Implementation of SelectFileDialog that shows Cocoa dialogs for choosing a
// file or folder.
class SelectFileDialogImpl : public ui::SelectFileDialog {
public:
SelectFileDialogImpl(Listener* listener, ui::SelectFilePolicy* policy);

// BaseShellDialog implementation.
bool IsRunning(gfx::NativeWindow parent_window) const override;
void ListenerDestroyed() override;

// Callback from ObjC bridge.
void FileWasSelected(NSSavePanel* dialog,
NSWindow* parent_window,
bool was_cancelled,
bool is_multi,
const std::vector<base::FilePath>& files,
int index);

protected:
// SelectFileDialog implementation.
// |params| is user data we pass back via the Listener interface.
void SelectFileImpl(Type type,
const base::string16& title,
const base::FilePath& default_path,
const FileTypeInfo* file_types,
int file_type_index,
const base::FilePath::StringType& default_extension,
gfx::NativeWindow owning_window,
void* params) override;

private:
// Struct to store data associated with a file dialog while it is showing.
struct DialogData {
DialogData(void* params_,
base::scoped_nsobject<ExtensionDropdownHandler> handler);

// |params| user data associated with this file dialog.
void* params;

// Extension dropdown handler corresponding to this file dialog.
base::scoped_nsobject<ExtensionDropdownHandler> extension_dropdown_handler;

~DialogData();
};

~SelectFileDialogImpl() override;

// Sets the accessory view for the |dialog| and returns the associated
// ExtensionDropdownHandler.
static base::scoped_nsobject<ExtensionDropdownHandler> SetAccessoryView(
NSSavePanel* dialog,
const FileTypeInfo* file_types,
int file_type_index,
const base::FilePath::StringType& default_extension);

bool HasMultipleFileTypeChoicesImpl() override;

// The bridge for results from Cocoa to return to us.
base::scoped_nsobject<SelectFileDialogBridge> bridge_;

// The set of all parent windows for which we are currently running dialogs.
std::set<NSWindow*> parents_;

// A map from file dialogs to the DialogData associated with them.
std::map<NSSavePanel*, DialogData> dialog_data_map_;

bool hasMultipleFileTypeChoices_;

DISALLOW_COPY_AND_ASSIGN(SelectFileDialogImpl);
};

} // namespace ui

Expand Down
Loading

0 comments on commit 2576728

Please sign in to comment.