Commit 08d4fc12 authored by Jeremy Apthorp's avatar Jeremy Apthorp Committed by Commit Bot

Make gtk app indicator id prefix customizable

This makes the app indicator API in libgtkui usable by non-Chrome apps (in
particular, Electron).

Change-Id: I39e547fc04595900d99806208955c632e4199be4
Reviewed-on: https://chromium-review.googlesource.com/c/1315840
Commit-Queue: Jeremy Apthorp <jeremya@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605435}
parent 678cb604
......@@ -232,11 +232,6 @@ typedef std::unique_ptr<GIcon, GObjectDeleter> ScopedGIcon;
typedef std::unique_ptr<GtkIconInfo, GtkIconInfoDeleter> ScopedGtkIconInfo;
typedef std::unique_ptr<GdkPixbuf, GObjectDeleter> ScopedGdkPixbuf;
#if !GTK_CHECK_VERSION(3, 90, 0)
// Prefix for app indicator ids
const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_";
#endif
// Number of app indicators used (used as part of app-indicator id).
int indicators_count;
......@@ -545,7 +540,8 @@ bool GtkUi::IsStatusIconSupported() const {
std::unique_ptr<views::StatusIconLinux> GtkUi::CreateLinuxStatusIcon(
const gfx::ImageSkia& image,
const base::string16& tool_tip) const {
const base::string16& tool_tip,
const char* id_prefix) const {
#if GTK_CHECK_VERSION(3, 90, 0)
NOTIMPLEMENTED();
return nullptr;
......@@ -553,8 +549,8 @@ std::unique_ptr<views::StatusIconLinux> GtkUi::CreateLinuxStatusIcon(
if (AppIndicatorIcon::CouldOpen()) {
++indicators_count;
return std::unique_ptr<views::StatusIconLinux>(new AppIndicatorIcon(
base::StringPrintf("%s%d", kAppIndicatorIdPrefix, indicators_count),
image, tool_tip));
base::StringPrintf("%s%d", id_prefix, indicators_count), image,
tool_tip));
} else {
return std::unique_ptr<views::StatusIconLinux>(
new GtkStatusIcon(image, tool_tip));
......
......@@ -90,7 +90,8 @@ class GtkUi : public views::LinuxUI {
bool IsStatusIconSupported() const override;
std::unique_ptr<views::StatusIconLinux> CreateLinuxStatusIcon(
const gfx::ImageSkia& image,
const base::string16& tool_tip) const override;
const base::string16& tool_tip,
const char* id_prefix) const override;
gfx::Image GetIconForContentType(const std::string& content_type,
int size) const override;
std::unique_ptr<views::Border> CreateNativeBorder(
......
......@@ -8,6 +8,13 @@
#include "ui/message_center/public/cpp/notifier_id.h"
#include "ui/views/linux_ui/linux_ui.h"
namespace {
// Prefix for app indicator ids
const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_";
} // namespace
StatusIconLinuxWrapper::StatusIconLinuxWrapper(
std::unique_ptr<views::StatusIconLinux> status_icon)
: status_icon_(std::move(status_icon)), menu_model_(nullptr) {
......@@ -53,7 +60,8 @@ StatusIconLinuxWrapper::CreateWrappedStatusIcon(
const base::string16& tool_tip) {
const views::LinuxUI* linux_ui = views::LinuxUI::instance();
if (linux_ui) {
auto status_icon = linux_ui->CreateLinuxStatusIcon(image, tool_tip);
auto status_icon =
linux_ui->CreateLinuxStatusIcon(image, tool_tip, kAppIndicatorIdPrefix);
if (status_icon) {
return base::WrapUnique(
new StatusIconLinuxWrapper(std::move(status_icon)));
......
......@@ -130,10 +130,12 @@ class VIEWS_EXPORT LinuxUI : public ui::LinuxInputMethodContextFactory,
// Checks for platform support for status icons.
virtual bool IsStatusIconSupported() const = 0;
// Create a native status icon.
// Create a native status icon. The id_prefix is used to distinguish Chrome's
// status icons from other apps' status icons, and should be unique.
virtual std::unique_ptr<StatusIconLinux> CreateLinuxStatusIcon(
const gfx::ImageSkia& image,
const base::string16& tool_tip) const = 0;
const base::string16& tool_tip,
const char* id_prefix) const = 0;
// Returns the icon for a given content type from the icon theme.
// TODO(davidben): Add an observer for the theme changing, so we can drop the
......
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