run clang-format on changed sources

This commit is contained in:
Charles Kerr 2018-02-15 15:20:55 -06:00
parent d30310a2f2
commit 5e7a5ce3a9
3 changed files with 50 additions and 62 deletions

View file

@ -25,9 +25,8 @@ gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info,
// Makes .* file extension matches all file types. // Makes .* file extension matches all file types.
if (*file_extension == ".*") if (*file_extension == ".*")
return true; return true;
return base::EndsWith( return base::EndsWith(file_info->filename, *file_extension,
file_info->filename, base::CompareCase::INSENSITIVE_ASCII);
*file_extension, base::CompareCase::INSENSITIVE_ASCII);
} }
// Deletes |data| when gtk_file_filter_add_custom() is done with it. // Deletes |data| when gtk_file_filter_add_custom() is done with it.
@ -37,8 +36,7 @@ void OnFileFilterDataDestroyed(std::string* file_extension) {
class FileChooserDialog { class FileChooserDialog {
public: public:
FileChooserDialog(GtkFileChooserAction action, FileChooserDialog(GtkFileChooserAction action, const DialogSettings& settings)
const DialogSettings& settings)
: parent_(static_cast<atom::NativeWindowViews*>(settings.parent_window)), : parent_(static_cast<atom::NativeWindowViews*>(settings.parent_window)),
filters_(settings.filters) { filters_(settings.filters) {
const char* confirm_text = _("_OK"); const char* confirm_text = _("_OK");
@ -51,12 +49,8 @@ class FileChooserDialog {
confirm_text = _("_Open"); confirm_text = _("_Open");
dialog_ = gtk_file_chooser_dialog_new( dialog_ = gtk_file_chooser_dialog_new(
settings.title.c_str(), settings.title.c_str(), NULL, action, _("_Cancel"), GTK_RESPONSE_CANCEL,
NULL, confirm_text, GTK_RESPONSE_ACCEPT, NULL);
action,
_("_Cancel"), GTK_RESPONSE_CANCEL,
confirm_text, GTK_RESPONSE_ACCEPT,
NULL);
if (parent_) { if (parent_) {
parent_->SetEnabled(false); parent_->SetEnabled(false);
libgtkui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow()); libgtkui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow());
@ -71,8 +65,8 @@ class FileChooserDialog {
if (!settings.default_path.empty()) { if (!settings.default_path.empty()) {
if (base::DirectoryExists(settings.default_path)) { if (base::DirectoryExists(settings.default_path)) {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog_), gtk_file_chooser_set_current_folder(
settings.default_path.value().c_str()); GTK_FILE_CHOOSER(dialog_), settings.default_path.value().c_str());
} else { } else {
if (settings.default_path.IsAbsolute()) { if (settings.default_path.IsAbsolute()) {
gtk_file_chooser_set_current_folder( gtk_file_chooser_set_current_folder(
@ -80,7 +74,8 @@ class FileChooserDialog {
settings.default_path.DirName().value().c_str()); settings.default_path.DirName().value().c_str());
} }
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog_), gtk_file_chooser_set_current_name(
GTK_FILE_CHOOSER(dialog_),
settings.default_path.BaseName().value().c_str()); settings.default_path.BaseName().value().c_str());
} }
} }
@ -105,8 +100,8 @@ class FileChooserDialog {
void RunAsynchronous() { void RunAsynchronous() {
g_signal_connect(dialog_, "delete-event", g_signal_connect(dialog_, "delete-event",
G_CALLBACK(gtk_widget_hide_on_delete), NULL); G_CALLBACK(gtk_widget_hide_on_delete), NULL);
g_signal_connect(dialog_, "response", g_signal_connect(dialog_, "response", G_CALLBACK(OnFileDialogResponseThunk),
G_CALLBACK(OnFileDialogResponseThunk), this); this);
gtk_widget_show_all(dialog_); gtk_widget_show_all(dialog_);
// We need to call gtk_window_present after making the widgets visible to // We need to call gtk_window_present after making the widgets visible to
@ -134,11 +129,11 @@ class FileChooserDialog {
std::vector<base::FilePath> GetFileNames() const { std::vector<base::FilePath> GetFileNames() const {
std::vector<base::FilePath> paths; std::vector<base::FilePath> paths;
GSList* filenames = gtk_file_chooser_get_filenames( GSList* filenames =
GTK_FILE_CHOOSER(dialog_)); gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog_));
for (GSList* iter = filenames; iter != NULL; iter = g_slist_next(iter)) { for (GSList* iter = filenames; iter != NULL; iter = g_slist_next(iter)) {
base::FilePath path = AddExtensionForFilename( base::FilePath path =
static_cast<char*>(iter->data)); AddExtensionForFilename(static_cast<char*>(iter->data));
g_free(iter->data); g_free(iter->data);
paths.push_back(path); paths.push_back(path);
} }
@ -192,8 +187,7 @@ void FileChooserDialog::AddFilters(const Filters& filters) {
std::unique_ptr<std::string> file_extension( std::unique_ptr<std::string> file_extension(
new std::string("." + filter.second[j])); new std::string("." + filter.second[j]));
gtk_file_filter_add_custom( gtk_file_filter_add_custom(
gtk_filter, gtk_filter, GTK_FILE_FILTER_FILENAME,
GTK_FILE_FILTER_FILENAME,
reinterpret_cast<GtkFileFilterFunc>(FileFilterCaseInsensitive), reinterpret_cast<GtkFileFilterFunc>(FileFilterCaseInsensitive),
file_extension.release(), file_extension.release(),
reinterpret_cast<GDestroyNotify>(OnFileFilterDataDestroyed)); reinterpret_cast<GDestroyNotify>(OnFileFilterDataDestroyed));
@ -229,7 +223,6 @@ base::FilePath FileChooserDialog::AddExtensionForFilename(
return path.ReplaceExtension(extensions[0]); return path.ReplaceExtension(extensions[0]);
} }
} // namespace } // namespace
bool ShowOpenDialog(const DialogSettings& settings, bool ShowOpenDialog(const DialogSettings& settings,
@ -260,8 +253,7 @@ void ShowOpenDialog(const DialogSettings& settings,
open_dialog->RunOpenAsynchronous(callback); open_dialog->RunOpenAsynchronous(callback);
} }
bool ShowSaveDialog(const DialogSettings& settings, bool ShowSaveDialog(const DialogSettings& settings, base::FilePath* path) {
base::FilePath* path) {
FileChooserDialog save_dialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings); FileChooserDialog save_dialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings);
gtk_widget_show_all(save_dialog.dialog()); gtk_widget_show_all(save_dialog.dialog());
int response = gtk_dialog_run(GTK_DIALOG(save_dialog.dialog())); int response = gtk_dialog_run(GTK_DIALOG(save_dialog.dialog()));
@ -275,8 +267,8 @@ bool ShowSaveDialog(const DialogSettings& settings,
void ShowSaveDialog(const DialogSettings& settings, void ShowSaveDialog(const DialogSettings& settings,
const SaveDialogCallback& callback) { const SaveDialogCallback& callback) {
FileChooserDialog* save_dialog = new FileChooserDialog( FileChooserDialog* save_dialog =
GTK_FILE_CHOOSER_ACTION_SAVE, settings); new FileChooserDialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings);
save_dialog->RunSaveAsynchronous(callback); save_dialog->RunSaveAsynchronous(callback);
} }

View file

@ -18,11 +18,11 @@
#include "chrome/browser/ui/libgtkui/skia_utils_gtk.h" #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
#include "ui/views/widget/desktop_aura/x11_desktop_handler.h" #include "ui/views/widget/desktop_aura/x11_desktop_handler.h"
#define ANSI_FOREGROUND_RED "\x1b[31m" #define ANSI_FOREGROUND_RED "\x1b[31m"
#define ANSI_FOREGROUND_BLACK "\x1b[30m" #define ANSI_FOREGROUND_BLACK "\x1b[30m"
#define ANSI_TEXT_BOLD "\x1b[1m" #define ANSI_TEXT_BOLD "\x1b[1m"
#define ANSI_BACKGROUND_GRAY "\x1b[47m" #define ANSI_BACKGROUND_GRAY "\x1b[47m"
#define ANSI_RESET "\x1b[0m" #define ANSI_RESET "\x1b[0m"
namespace atom { namespace atom {
@ -44,15 +44,15 @@ class GtkMessageBox : public NativeWindowObserver {
checkbox_checked_(false), checkbox_checked_(false),
parent_(static_cast<NativeWindow*>(parent_window)) { parent_(static_cast<NativeWindow*>(parent_window)) {
// Create dialog. // Create dialog.
dialog_ = gtk_message_dialog_new( dialog_ =
nullptr, // parent gtk_message_dialog_new(nullptr, // parent
static_cast<GtkDialogFlags>(0), // no flags static_cast<GtkDialogFlags>(0), // no flags
GetMessageType(type), // type GetMessageType(type), // type
GTK_BUTTONS_NONE, // no buttons GTK_BUTTONS_NONE, // no buttons
"%s", message.c_str()); "%s", message.c_str());
if (!detail.empty()) if (!detail.empty())
gtk_message_dialog_format_secondary_text( gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog_),
GTK_MESSAGE_DIALOG(dialog_), "%s", detail.c_str()); "%s", detail.c_str());
if (!title.empty()) if (!title.empty())
gtk_window_set_title(GTK_WINDOW(dialog_), title.c_str()); gtk_window_set_title(GTK_WINDOW(dialog_), title.c_str());
@ -142,8 +142,8 @@ class GtkMessageBox : public NativeWindowObserver {
callback_ = callback; callback_ = callback;
g_signal_connect(dialog_, "delete-event", g_signal_connect(dialog_, "delete-event",
G_CALLBACK(gtk_widget_hide_on_delete), nullptr); G_CALLBACK(gtk_widget_hide_on_delete), nullptr);
g_signal_connect(dialog_, "response", g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseDialogThunk),
G_CALLBACK(OnResponseDialogThunk), this); this);
Show(); Show();
} }
@ -226,11 +226,8 @@ void ShowErrorBox(const base::string16& title, const base::string16& content) {
base::UTF16ToUTF8(content).c_str(), "", false) base::UTF16ToUTF8(content).c_str(), "", false)
.RunSynchronous(); .RunSynchronous();
} else { } else {
fprintf(stderr, fprintf(stderr, ANSI_TEXT_BOLD ANSI_BACKGROUND_GRAY ANSI_FOREGROUND_RED
ANSI_TEXT_BOLD ANSI_BACKGROUND_GRAY "%s\n" ANSI_FOREGROUND_BLACK "%s" ANSI_RESET "\n",
ANSI_FOREGROUND_RED "%s\n"
ANSI_FOREGROUND_BLACK "%s"
ANSI_RESET "\n",
base::UTF16ToUTF8(title).c_str(), base::UTF16ToUTF8(title).c_str(),
base::UTF16ToUTF8(content).c_str()); base::UTF16ToUTF8(content).c_str());
} }

View file

@ -27,8 +27,8 @@ namespace {
#if defined(USE_X11) #if defined(USE_X11)
SkColor GdkRgbaToSkColor(const GdkRGBA& rgba) { SkColor GdkRgbaToSkColor(const GdkRGBA& rgba) {
return SkColorSetARGB(rgba.alpha*255, rgba.red*255, return SkColorSetARGB(rgba.alpha * 255, rgba.red * 255, rgba.green * 255,
rgba.green*255, rgba.blue*255); rgba.blue * 255);
} }
SkColor GetStyleContextFgColor(GtkStyleContext* style_context, SkColor GetStyleContextFgColor(GtkStyleContext* style_context,
@ -45,14 +45,17 @@ SkColor GetStyleContextBgColor(GtkStyleContext* style_context,
return GdkRgbaToSkColor(rgba); return GdkRgbaToSkColor(rgba);
} }
void GetMenuBarColor(SkColor* enabled, SkColor* disabled, SkColor* highlight, void GetMenuBarColor(SkColor* enabled,
SkColor* hover, SkColor* background) { SkColor* disabled,
SkColor* highlight,
SkColor* hover,
SkColor* background) {
GtkWidget* menu_bar = gtk_menu_bar_new(); GtkWidget* menu_bar = gtk_menu_bar_new();
GtkStyleContext* sc = gtk_widget_get_style_context(menu_bar); GtkStyleContext* sc = gtk_widget_get_style_context(menu_bar);
*enabled = GetStyleContextFgColor(sc, GTK_STATE_FLAG_NORMAL); *enabled = GetStyleContextFgColor(sc, GTK_STATE_FLAG_NORMAL);
*disabled = GetStyleContextFgColor(sc, GTK_STATE_FLAG_INSENSITIVE); *disabled = GetStyleContextFgColor(sc, GTK_STATE_FLAG_INSENSITIVE);
*highlight = GetStyleContextFgColor(sc, GTK_STATE_FLAG_SELECTED); *highlight = GetStyleContextFgColor(sc, GTK_STATE_FLAG_SELECTED);
*hover = GetStyleContextFgColor(sc, GTK_STATE_FLAG_PRELIGHT); *hover = GetStyleContextFgColor(sc, GTK_STATE_FLAG_PRELIGHT);
*background = GetStyleContextBgColor(sc, GTK_STATE_FLAG_NORMAL); *background = GetStyleContextBgColor(sc, GTK_STATE_FLAG_NORMAL);
g_object_unref(G_OBJECT(menu_bar)); g_object_unref(G_OBJECT(menu_bar));
} }
@ -67,24 +70,20 @@ const SkColor kDefaultColor = SkColorSetARGB(255, 233, 233, 233);
} // namespace } // namespace
MenuBar::MenuBar(NativeWindow* window) MenuBar::MenuBar(NativeWindow* window)
: background_color_(kDefaultColor), : background_color_(kDefaultColor), menu_model_(NULL), window_(window) {
menu_model_(NULL),
window_(window) {
UpdateMenuBarColor(); UpdateMenuBarColor();
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal)); SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal));
} }
MenuBar::~MenuBar() { MenuBar::~MenuBar() {}
}
void MenuBar::SetMenu(AtomMenuModel* model) { void MenuBar::SetMenu(AtomMenuModel* model) {
menu_model_ = model; menu_model_ = model;
RemoveAllChildViews(true); RemoveAllChildViews(true);
for (int i = 0; i < model->GetItemCount(); ++i) { for (int i = 0; i < model->GetItemCount(); ++i) {
SubmenuButton* button = new SubmenuButton(model->GetLabelAt(i), SubmenuButton* button =
this, new SubmenuButton(model->GetLabelAt(i), this, background_color_);
background_color_);
button->set_tag(i); button->set_tag(i);
#if defined(USE_X11) #if defined(USE_X11)