Merge pull request #11879 from electron/fix-gtk-deprecations
Fix GTK+ 3 deprecations
This commit is contained in:
commit
78ccfa0612
9 changed files with 107 additions and 117 deletions
|
@ -15,8 +15,7 @@ RUN apt-get update && apt-get install -y\
|
|||
libgconf2-dev \
|
||||
libgnome-keyring-dev \
|
||||
libgtk-3-0 \
|
||||
libgtk2.0-0 \
|
||||
libgtk2.0-dev \
|
||||
libgtk-3-dev \
|
||||
libnotify-dev \
|
||||
libnss3 \
|
||||
libnss3-dev \
|
||||
|
|
|
@ -15,8 +15,7 @@ RUN apt-get update && apt-get install -y\
|
|||
libgconf2-dev \
|
||||
libgnome-keyring-dev \
|
||||
libgtk-3-0 \
|
||||
libgtk2.0-0 \
|
||||
libgtk2.0-dev \
|
||||
libgtk-3-dev \
|
||||
libnotify-dev \
|
||||
libnss3 \
|
||||
libnss3-dev \
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "atom/browser/ui/file_dialog.h"
|
||||
|
||||
#include <glib/gi18n.h> // _() macro
|
||||
|
||||
#include "atom/browser/native_window_views.h"
|
||||
#include "atom/browser/unresponsive_suppressor.h"
|
||||
#include "base/callback.h"
|
||||
|
@ -23,9 +25,8 @@ gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info,
|
|||
// Makes .* file extension matches all file types.
|
||||
if (*file_extension == ".*")
|
||||
return true;
|
||||
return base::EndsWith(
|
||||
file_info->filename,
|
||||
*file_extension, base::CompareCase::INSENSITIVE_ASCII);
|
||||
return base::EndsWith(file_info->filename, *file_extension,
|
||||
base::CompareCase::INSENSITIVE_ASCII);
|
||||
}
|
||||
|
||||
// Deletes |data| when gtk_file_filter_add_custom() is done with it.
|
||||
|
@ -35,26 +36,21 @@ void OnFileFilterDataDestroyed(std::string* file_extension) {
|
|||
|
||||
class FileChooserDialog {
|
||||
public:
|
||||
FileChooserDialog(GtkFileChooserAction action,
|
||||
const DialogSettings& settings)
|
||||
FileChooserDialog(GtkFileChooserAction action, const DialogSettings& settings)
|
||||
: parent_(static_cast<atom::NativeWindowViews*>(settings.parent_window)),
|
||||
filters_(settings.filters) {
|
||||
const char* confirm_text = GTK_STOCK_OK;
|
||||
const char* confirm_text = _("_OK");
|
||||
|
||||
if (!settings.button_label.empty())
|
||||
confirm_text = settings.button_label.c_str();
|
||||
else if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
||||
confirm_text = GTK_STOCK_SAVE;
|
||||
confirm_text = _("_Save");
|
||||
else if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
|
||||
confirm_text = GTK_STOCK_OPEN;
|
||||
confirm_text = _("_Open");
|
||||
|
||||
dialog_ = gtk_file_chooser_dialog_new(
|
||||
settings.title.c_str(),
|
||||
NULL,
|
||||
action,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
confirm_text, GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
settings.title.c_str(), NULL, action, _("_Cancel"), GTK_RESPONSE_CANCEL,
|
||||
confirm_text, GTK_RESPONSE_ACCEPT, NULL);
|
||||
if (parent_) {
|
||||
parent_->SetEnabled(false);
|
||||
libgtkui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow());
|
||||
|
@ -69,8 +65,8 @@ class FileChooserDialog {
|
|||
|
||||
if (!settings.default_path.empty()) {
|
||||
if (base::DirectoryExists(settings.default_path)) {
|
||||
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog_),
|
||||
settings.default_path.value().c_str());
|
||||
gtk_file_chooser_set_current_folder(
|
||||
GTK_FILE_CHOOSER(dialog_), settings.default_path.value().c_str());
|
||||
} else {
|
||||
if (settings.default_path.IsAbsolute()) {
|
||||
gtk_file_chooser_set_current_folder(
|
||||
|
@ -78,7 +74,8 @@ class FileChooserDialog {
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +100,8 @@ class FileChooserDialog {
|
|||
void RunAsynchronous() {
|
||||
g_signal_connect(dialog_, "delete-event",
|
||||
G_CALLBACK(gtk_widget_hide_on_delete), NULL);
|
||||
g_signal_connect(dialog_, "response",
|
||||
G_CALLBACK(OnFileDialogResponseThunk), this);
|
||||
g_signal_connect(dialog_, "response", G_CALLBACK(OnFileDialogResponseThunk),
|
||||
this);
|
||||
gtk_widget_show_all(dialog_);
|
||||
|
||||
// We need to call gtk_window_present after making the widgets visible to
|
||||
|
@ -132,11 +129,11 @@ class FileChooserDialog {
|
|||
|
||||
std::vector<base::FilePath> GetFileNames() const {
|
||||
std::vector<base::FilePath> paths;
|
||||
GSList* filenames = gtk_file_chooser_get_filenames(
|
||||
GTK_FILE_CHOOSER(dialog_));
|
||||
GSList* filenames =
|
||||
gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog_));
|
||||
for (GSList* iter = filenames; iter != NULL; iter = g_slist_next(iter)) {
|
||||
base::FilePath path = AddExtensionForFilename(
|
||||
static_cast<char*>(iter->data));
|
||||
base::FilePath path =
|
||||
AddExtensionForFilename(static_cast<char*>(iter->data));
|
||||
g_free(iter->data);
|
||||
paths.push_back(path);
|
||||
}
|
||||
|
@ -190,8 +187,7 @@ void FileChooserDialog::AddFilters(const Filters& filters) {
|
|||
std::unique_ptr<std::string> file_extension(
|
||||
new std::string("." + filter.second[j]));
|
||||
gtk_file_filter_add_custom(
|
||||
gtk_filter,
|
||||
GTK_FILE_FILTER_FILENAME,
|
||||
gtk_filter, GTK_FILE_FILTER_FILENAME,
|
||||
reinterpret_cast<GtkFileFilterFunc>(FileFilterCaseInsensitive),
|
||||
file_extension.release(),
|
||||
reinterpret_cast<GDestroyNotify>(OnFileFilterDataDestroyed));
|
||||
|
@ -227,7 +223,6 @@ base::FilePath FileChooserDialog::AddExtensionForFilename(
|
|||
return path.ReplaceExtension(extensions[0]);
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
bool ShowOpenDialog(const DialogSettings& settings,
|
||||
|
@ -258,8 +253,7 @@ void ShowOpenDialog(const DialogSettings& settings,
|
|||
open_dialog->RunOpenAsynchronous(callback);
|
||||
}
|
||||
|
||||
bool ShowSaveDialog(const DialogSettings& settings,
|
||||
base::FilePath* path) {
|
||||
bool ShowSaveDialog(const DialogSettings& settings, base::FilePath* path) {
|
||||
FileChooserDialog save_dialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings);
|
||||
gtk_widget_show_all(save_dialog.dialog());
|
||||
int response = gtk_dialog_run(GTK_DIALOG(save_dialog.dialog()));
|
||||
|
@ -273,8 +267,8 @@ bool ShowSaveDialog(const DialogSettings& settings,
|
|||
|
||||
void ShowSaveDialog(const DialogSettings& settings,
|
||||
const SaveDialogCallback& callback) {
|
||||
FileChooserDialog* save_dialog = new FileChooserDialog(
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE, settings);
|
||||
FileChooserDialog* save_dialog =
|
||||
new FileChooserDialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings);
|
||||
save_dialog->RunSaveAsynchronous(callback);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "atom/browser/ui/message_box.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/native_window_observer.h"
|
||||
#include "atom/browser/native_window_views.h"
|
||||
|
@ -37,40 +39,23 @@ class GtkMessageBox : public NativeWindowObserver {
|
|||
const std::string& message,
|
||||
const std::string& detail,
|
||||
const std::string& checkbox_label,
|
||||
bool checkbox_checked,
|
||||
const gfx::ImageSkia& icon)
|
||||
bool checkbox_checked)
|
||||
: cancel_id_(cancel_id),
|
||||
checkbox_checked_(false),
|
||||
parent_(static_cast<NativeWindow*>(parent_window)) {
|
||||
// Create dialog.
|
||||
dialog_ = gtk_message_dialog_new(
|
||||
nullptr, // parent
|
||||
dialog_ =
|
||||
gtk_message_dialog_new(nullptr, // parent
|
||||
static_cast<GtkDialogFlags>(0), // no flags
|
||||
GetMessageType(type), // type
|
||||
GTK_BUTTONS_NONE, // no buttons
|
||||
"%s", message.c_str());
|
||||
if (!detail.empty())
|
||||
gtk_message_dialog_format_secondary_text(
|
||||
GTK_MESSAGE_DIALOG(dialog_), "%s", detail.c_str());
|
||||
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog_),
|
||||
"%s", detail.c_str());
|
||||
if (!title.empty())
|
||||
gtk_window_set_title(GTK_WINDOW(dialog_), title.c_str());
|
||||
|
||||
// Set dialog's icon.
|
||||
if (!icon.isNull()) {
|
||||
GdkPixbuf* pixbuf = libgtkui::GdkPixbufFromSkBitmap(*icon.bitmap());
|
||||
GtkIconSource* iconsource = gtk_icon_source_new();
|
||||
GtkIconSet* iconset = gtk_icon_set_new();
|
||||
gtk_icon_source_set_pixbuf(iconsource, pixbuf);
|
||||
gtk_icon_set_add_source(iconset, iconsource);
|
||||
GtkWidget* image = gtk_image_new_from_icon_set(iconset,
|
||||
GTK_ICON_SIZE_DIALOG);
|
||||
gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(dialog_), image);
|
||||
gtk_widget_show(image);
|
||||
gtk_icon_source_free(iconsource);
|
||||
gtk_icon_set_unref(iconset);
|
||||
g_object_unref(pixbuf);
|
||||
}
|
||||
|
||||
if (!checkbox_label.empty()) {
|
||||
GtkWidget* message_area =
|
||||
gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(dialog_));
|
||||
|
@ -124,16 +109,15 @@ class GtkMessageBox : public NativeWindowObserver {
|
|||
}
|
||||
|
||||
const char* TranslateToStock(int id, const std::string& text) {
|
||||
std::string lower = base::ToLowerASCII(text);
|
||||
const std::string lower = base::ToLowerASCII(text);
|
||||
if (lower == "cancel")
|
||||
return GTK_STOCK_CANCEL;
|
||||
else if (lower == "no")
|
||||
return GTK_STOCK_NO;
|
||||
else if (lower == "ok")
|
||||
return GTK_STOCK_OK;
|
||||
else if (lower == "yes")
|
||||
return GTK_STOCK_YES;
|
||||
else
|
||||
return _("_Cancel");
|
||||
if (lower == "no")
|
||||
return _("_No");
|
||||
if (lower == "ok")
|
||||
return _("_OK");
|
||||
if (lower == "yes")
|
||||
return _("_Yes");
|
||||
return text.c_str();
|
||||
}
|
||||
|
||||
|
@ -158,8 +142,8 @@ class GtkMessageBox : public NativeWindowObserver {
|
|||
callback_ = callback;
|
||||
g_signal_connect(dialog_, "delete-event",
|
||||
G_CALLBACK(gtk_widget_hide_on_delete), nullptr);
|
||||
g_signal_connect(dialog_, "response",
|
||||
G_CALLBACK(OnResponseDialogThunk), this);
|
||||
g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseDialogThunk),
|
||||
this);
|
||||
Show();
|
||||
}
|
||||
|
||||
|
@ -211,9 +195,9 @@ int ShowMessageBox(NativeWindow* parent,
|
|||
const std::string& title,
|
||||
const std::string& message,
|
||||
const std::string& detail,
|
||||
const gfx::ImageSkia& icon) {
|
||||
const gfx::ImageSkia& /*icon*/) {
|
||||
return GtkMessageBox(parent, type, buttons, default_id, cancel_id, title,
|
||||
message, detail, "", false, icon)
|
||||
message, detail, "", false)
|
||||
.RunSynchronous();
|
||||
}
|
||||
|
||||
|
@ -228,10 +212,10 @@ void ShowMessageBox(NativeWindow* parent,
|
|||
const std::string& detail,
|
||||
const std::string& checkbox_label,
|
||||
bool checkbox_checked,
|
||||
const gfx::ImageSkia& icon,
|
||||
const gfx::ImageSkia& /*icon*/,
|
||||
const MessageBoxCallback& callback) {
|
||||
(new GtkMessageBox(parent, type, buttons, default_id, cancel_id, title,
|
||||
message, detail, checkbox_label, checkbox_checked, icon))
|
||||
message, detail, checkbox_label, checkbox_checked))
|
||||
->RunAsynchronous(callback);
|
||||
}
|
||||
|
||||
|
@ -239,15 +223,11 @@ void ShowErrorBox(const base::string16& title, const base::string16& content) {
|
|||
if (Browser::Get()->is_ready()) {
|
||||
GtkMessageBox(nullptr, MESSAGE_BOX_TYPE_ERROR, {"OK"}, -1, 0, "Error",
|
||||
base::UTF16ToUTF8(title).c_str(),
|
||||
base::UTF16ToUTF8(content).c_str(), "", false,
|
||||
gfx::ImageSkia())
|
||||
base::UTF16ToUTF8(content).c_str(), "", false)
|
||||
.RunSynchronous();
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
ANSI_TEXT_BOLD ANSI_BACKGROUND_GRAY
|
||||
ANSI_FOREGROUND_RED "%s\n"
|
||||
ANSI_FOREGROUND_BLACK "%s"
|
||||
ANSI_RESET "\n",
|
||||
fprintf(stderr, ANSI_TEXT_BOLD ANSI_BACKGROUND_GRAY ANSI_FOREGROUND_RED
|
||||
"%s\n" ANSI_FOREGROUND_BLACK "%s" ANSI_RESET "\n",
|
||||
base::UTF16ToUTF8(title).c_str(),
|
||||
base::UTF16ToUTF8(content).c_str());
|
||||
}
|
||||
|
|
|
@ -24,48 +24,66 @@ namespace atom {
|
|||
|
||||
namespace {
|
||||
|
||||
#if defined(USE_X11)
|
||||
|
||||
SkColor GdkRgbaToSkColor(const GdkRGBA& rgba) {
|
||||
return SkColorSetARGB(rgba.alpha * 255, rgba.red * 255, rgba.green * 255,
|
||||
rgba.blue * 255);
|
||||
}
|
||||
|
||||
SkColor GetStyleContextFgColor(GtkStyleContext* style_context,
|
||||
GtkStateFlags state) {
|
||||
GdkRGBA rgba;
|
||||
gtk_style_context_get_color(style_context, state, &rgba);
|
||||
return GdkRgbaToSkColor(rgba);
|
||||
}
|
||||
|
||||
SkColor GetStyleContextBgColor(GtkStyleContext* style_context,
|
||||
GtkStateFlags state) {
|
||||
GdkRGBA rgba;
|
||||
gtk_style_context_get_background_color(style_context, state, &rgba);
|
||||
return GdkRgbaToSkColor(rgba);
|
||||
}
|
||||
|
||||
void GetMenuBarColor(SkColor* enabled,
|
||||
SkColor* disabled,
|
||||
SkColor* highlight,
|
||||
SkColor* hover,
|
||||
SkColor* background) {
|
||||
GtkWidget* menu_bar = gtk_menu_bar_new();
|
||||
GtkStyleContext* sc = gtk_widget_get_style_context(menu_bar);
|
||||
*enabled = GetStyleContextFgColor(sc, GTK_STATE_FLAG_NORMAL);
|
||||
*disabled = GetStyleContextFgColor(sc, GTK_STATE_FLAG_INSENSITIVE);
|
||||
*highlight = GetStyleContextFgColor(sc, GTK_STATE_FLAG_SELECTED);
|
||||
*hover = GetStyleContextFgColor(sc, GTK_STATE_FLAG_PRELIGHT);
|
||||
*background = GetStyleContextBgColor(sc, GTK_STATE_FLAG_NORMAL);
|
||||
g_object_unref(G_OBJECT(menu_bar));
|
||||
}
|
||||
|
||||
#endif // USE_X11
|
||||
|
||||
const char kViewClassName[] = "ElectronMenuBar";
|
||||
|
||||
// Default color of the menu bar.
|
||||
const SkColor kDefaultColor = SkColorSetARGB(255, 233, 233, 233);
|
||||
|
||||
#if defined(USE_X11)
|
||||
void GetMenuBarColor(SkColor* enabled, SkColor* disabled, SkColor* highlight,
|
||||
SkColor* hover, SkColor* background) {
|
||||
GtkWidget* menu_bar = gtk_menu_bar_new();
|
||||
|
||||
GtkStyle* style = gtk_rc_get_style(menu_bar);
|
||||
*enabled = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_NORMAL]);
|
||||
*disabled = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_INSENSITIVE]);
|
||||
*highlight = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_SELECTED]);
|
||||
*hover = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_PRELIGHT]);
|
||||
*background = libgtkui::GdkColorToSkColor(style->bg[GTK_STATE_NORMAL]);
|
||||
|
||||
gtk_widget_destroy(menu_bar);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
MenuBar::MenuBar(NativeWindow* window)
|
||||
: background_color_(kDefaultColor),
|
||||
menu_model_(NULL),
|
||||
window_(window) {
|
||||
: background_color_(kDefaultColor), menu_model_(NULL), window_(window) {
|
||||
UpdateMenuBarColor();
|
||||
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal));
|
||||
}
|
||||
|
||||
MenuBar::~MenuBar() {
|
||||
}
|
||||
MenuBar::~MenuBar() {}
|
||||
|
||||
void MenuBar::SetMenu(AtomMenuModel* model) {
|
||||
menu_model_ = model;
|
||||
RemoveAllChildViews(true);
|
||||
|
||||
for (int i = 0; i < model->GetItemCount(); ++i) {
|
||||
SubmenuButton* button = new SubmenuButton(model->GetLabelAt(i),
|
||||
this,
|
||||
background_color_);
|
||||
SubmenuButton* button =
|
||||
new SubmenuButton(model->GetLabelAt(i), this, background_color_);
|
||||
button->set_tag(i);
|
||||
|
||||
#if defined(USE_X11)
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
['exclude', '_gtk(_browsertest|_unittest)?\\.(h|cc)$'],
|
||||
['exclude', '(^|/)gtk/'],
|
||||
['exclude', '(^|/)gtk_[^/]*\\.(h|cc)$'],
|
||||
['exclude', '(^|/)libgtk2ui/'],
|
||||
['exclude', '(^|/)libgtkui/'],
|
||||
['exclude', '(^|/)x/'],
|
||||
],
|
||||
}],
|
||||
|
|
|
@ -17,7 +17,7 @@ Follow the guidelines below for building Electron on Linux.
|
|||
On Ubuntu, install the following libraries:
|
||||
|
||||
```sh
|
||||
$ sudo apt-get install build-essential clang libdbus-1-dev libgtk2.0-dev \
|
||||
$ sudo apt-get install build-essential clang libdbus-1-dev libgtk-3-dev \
|
||||
libnotify-dev libgnome-keyring-dev libgconf2-dev \
|
||||
libasound2-dev libcap-dev libcups2-dev libxtst-dev \
|
||||
libxss1 libnss3-dev gcc-multilib g++-multilib curl \
|
||||
|
@ -27,7 +27,7 @@ $ sudo apt-get install build-essential clang libdbus-1-dev libgtk2.0-dev \
|
|||
On RHEL / CentOS, install the following libraries:
|
||||
|
||||
```sh
|
||||
$ sudo yum install clang dbus-devel gtk2-devel libnotify-devel \
|
||||
$ sudo yum install clang dbus-devel gtk3-devel libnotify-devel \
|
||||
libgnome-keyring-devel xorg-x11-server-utils libcap-devel \
|
||||
cups-devel libXtst-devel alsa-lib-devel libXrandr-devel \
|
||||
GConf2-devel nss-devel
|
||||
|
@ -36,7 +36,7 @@ $ sudo yum install clang dbus-devel gtk2-devel libnotify-devel \
|
|||
On Fedora, install the following libraries:
|
||||
|
||||
```sh
|
||||
$ sudo dnf install clang dbus-devel gtk2-devel libnotify-devel \
|
||||
$ sudo dnf install clang dbus-devel gtk3-devel libnotify-devel \
|
||||
libgnome-keyring-devel xorg-x11-server-utils libcap-devel \
|
||||
cups-devel libXtst-devel alsa-lib-devel libXrandr-devel \
|
||||
GConf2-devel nss-devel
|
||||
|
|
|
@ -125,7 +125,7 @@ parts:
|
|||
source: my-deb.deb
|
||||
source-type: deb
|
||||
after:
|
||||
- desktop-gtk2
|
||||
- desktop-gtk3
|
||||
stage-packages:
|
||||
- libasound2
|
||||
- libgconf2-4
|
||||
|
|
|
@ -14,7 +14,7 @@ LINUX_DEPS = [
|
|||
'libdbus-1-dev',
|
||||
'libgconf2-dev',
|
||||
'libgnome-keyring-dev',
|
||||
'libgtk2.0-dev',
|
||||
'libgtk-3-dev',
|
||||
'libnotify-dev',
|
||||
'libnss3-dev',
|
||||
'libxtst-dev',
|
||||
|
|
Loading…
Reference in a new issue