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; ...@@ -232,11 +232,6 @@ typedef std::unique_ptr<GIcon, GObjectDeleter> ScopedGIcon;
typedef std::unique_ptr<GtkIconInfo, GtkIconInfoDeleter> ScopedGtkIconInfo; typedef std::unique_ptr<GtkIconInfo, GtkIconInfoDeleter> ScopedGtkIconInfo;
typedef std::unique_ptr<GdkPixbuf, GObjectDeleter> ScopedGdkPixbuf; 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). // Number of app indicators used (used as part of app-indicator id).
int indicators_count; int indicators_count;
...@@ -545,7 +540,8 @@ bool GtkUi::IsStatusIconSupported() const { ...@@ -545,7 +540,8 @@ bool GtkUi::IsStatusIconSupported() const {
std::unique_ptr<views::StatusIconLinux> GtkUi::CreateLinuxStatusIcon( std::unique_ptr<views::StatusIconLinux> GtkUi::CreateLinuxStatusIcon(
const gfx::ImageSkia& image, 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) #if GTK_CHECK_VERSION(3, 90, 0)
NOTIMPLEMENTED(); NOTIMPLEMENTED();
return nullptr; return nullptr;
...@@ -553,8 +549,8 @@ std::unique_ptr<views::StatusIconLinux> GtkUi::CreateLinuxStatusIcon( ...@@ -553,8 +549,8 @@ std::unique_ptr<views::StatusIconLinux> GtkUi::CreateLinuxStatusIcon(
if (AppIndicatorIcon::CouldOpen()) { if (AppIndicatorIcon::CouldOpen()) {
++indicators_count; ++indicators_count;
return std::unique_ptr<views::StatusIconLinux>(new AppIndicatorIcon( return std::unique_ptr<views::StatusIconLinux>(new AppIndicatorIcon(
base::StringPrintf("%s%d", kAppIndicatorIdPrefix, indicators_count), base::StringPrintf("%s%d", id_prefix, indicators_count), image,
image, tool_tip)); tool_tip));
} else { } else {
return std::unique_ptr<views::StatusIconLinux>( return std::unique_ptr<views::StatusIconLinux>(
new GtkStatusIcon(image, tool_tip)); new GtkStatusIcon(image, tool_tip));
......
...@@ -90,7 +90,8 @@ class GtkUi : public views::LinuxUI { ...@@ -90,7 +90,8 @@ class GtkUi : public views::LinuxUI {
bool IsStatusIconSupported() const override; bool IsStatusIconSupported() const override;
std::unique_ptr<views::StatusIconLinux> CreateLinuxStatusIcon( std::unique_ptr<views::StatusIconLinux> CreateLinuxStatusIcon(
const gfx::ImageSkia& image, 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, gfx::Image GetIconForContentType(const std::string& content_type,
int size) const override; int size) const override;
std::unique_ptr<views::Border> CreateNativeBorder( std::unique_ptr<views::Border> CreateNativeBorder(
......
...@@ -8,6 +8,13 @@ ...@@ -8,6 +8,13 @@
#include "ui/message_center/public/cpp/notifier_id.h" #include "ui/message_center/public/cpp/notifier_id.h"
#include "ui/views/linux_ui/linux_ui.h" #include "ui/views/linux_ui/linux_ui.h"
namespace {
// Prefix for app indicator ids
const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_";
} // namespace
StatusIconLinuxWrapper::StatusIconLinuxWrapper( StatusIconLinuxWrapper::StatusIconLinuxWrapper(
std::unique_ptr<views::StatusIconLinux> status_icon) std::unique_ptr<views::StatusIconLinux> status_icon)
: status_icon_(std::move(status_icon)), menu_model_(nullptr) { : status_icon_(std::move(status_icon)), menu_model_(nullptr) {
...@@ -53,7 +60,8 @@ StatusIconLinuxWrapper::CreateWrappedStatusIcon( ...@@ -53,7 +60,8 @@ StatusIconLinuxWrapper::CreateWrappedStatusIcon(
const base::string16& tool_tip) { const base::string16& tool_tip) {
const views::LinuxUI* linux_ui = views::LinuxUI::instance(); const views::LinuxUI* linux_ui = views::LinuxUI::instance();
if (linux_ui) { 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) { if (status_icon) {
return base::WrapUnique( return base::WrapUnique(
new StatusIconLinuxWrapper(std::move(status_icon))); new StatusIconLinuxWrapper(std::move(status_icon)));
......
...@@ -130,10 +130,12 @@ class VIEWS_EXPORT LinuxUI : public ui::LinuxInputMethodContextFactory, ...@@ -130,10 +130,12 @@ class VIEWS_EXPORT LinuxUI : public ui::LinuxInputMethodContextFactory,
// Checks for platform support for status icons. // Checks for platform support for status icons.
virtual bool IsStatusIconSupported() const = 0; 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( virtual std::unique_ptr<StatusIconLinux> CreateLinuxStatusIcon(
const gfx::ImageSkia& image, 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. // 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 // 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