tray_icon_gtk.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/browser/ui/tray_icon_gtk.h"
  5. #include "atom/browser/browser.h"
  6. #include "base/strings/stringprintf.h"
  7. #include "base/strings/utf_string_conversions.h"
  8. #include "chrome/browser/ui/libgtkui/app_indicator_icon.h"
  9. #include "chrome/browser/ui/libgtkui/gtk_status_icon.h"
  10. #include "ui/gfx/image/image.h"
  11. namespace atom {
  12. namespace {
  13. // Number of app indicators used (used as part of app-indicator id).
  14. int indicators_count;
  15. } // namespace
  16. TrayIconGtk::TrayIconGtk() {
  17. }
  18. TrayIconGtk::~TrayIconGtk() {
  19. }
  20. void TrayIconGtk::SetImage(const gfx::Image& image) {
  21. if (icon_) {
  22. icon_->SetImage(image.AsImageSkia());
  23. return;
  24. }
  25. base::string16 empty;
  26. if (libgtkui::AppIndicatorIcon::CouldOpen()) {
  27. ++indicators_count;
  28. icon_.reset(new libgtkui::AppIndicatorIcon(
  29. base::StringPrintf(
  30. "%s%d", Browser::Get()->GetName().c_str(), indicators_count),
  31. image.AsImageSkia(),
  32. empty));
  33. } else {
  34. icon_.reset(new libgtkui::Gtk2StatusIcon(image.AsImageSkia(), empty));
  35. }
  36. icon_->set_delegate(this);
  37. }
  38. void TrayIconGtk::SetToolTip(const std::string& tool_tip) {
  39. icon_->SetToolTip(base::UTF8ToUTF16(tool_tip));
  40. }
  41. void TrayIconGtk::SetContextMenu(AtomMenuModel* menu_model) {
  42. icon_->UpdatePlatformContextMenu(menu_model);
  43. }
  44. void TrayIconGtk::OnClick() {
  45. NotifyClicked();
  46. }
  47. bool TrayIconGtk::HasClickAction() {
  48. return false;
  49. }
  50. // static
  51. TrayIcon* TrayIcon::Create() {
  52. return new TrayIconGtk;
  53. }
  54. } // namespace atom