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 "shell/browser/ui/tray_icon_gtk.h"
  5. #include "base/strings/stringprintf.h"
  6. #include "base/strings/utf_string_conversions.h"
  7. #include "shell/browser/browser.h"
  8. #include "shell/common/application_info.h"
  9. #include "ui/gfx/image/image.h"
  10. #include "ui/views/linux_ui/linux_ui.h"
  11. namespace electron {
  12. TrayIconGtk::TrayIconGtk() {}
  13. TrayIconGtk::~TrayIconGtk() {}
  14. void TrayIconGtk::SetImage(const gfx::Image& image) {
  15. if (icon_) {
  16. icon_->SetIcon(image.AsImageSkia());
  17. return;
  18. }
  19. const auto toolTip = base::UTF8ToUTF16(GetApplicationName());
  20. icon_ = views::LinuxUI::instance()->CreateLinuxStatusIcon(
  21. image.AsImageSkia(), toolTip, Browser::Get()->GetName().c_str());
  22. icon_->SetDelegate(this);
  23. }
  24. void TrayIconGtk::SetToolTip(const std::string& tool_tip) {
  25. icon_->SetToolTip(base::UTF8ToUTF16(tool_tip));
  26. }
  27. void TrayIconGtk::SetContextMenu(AtomMenuModel* menu_model) {
  28. icon_->UpdatePlatformContextMenu(menu_model);
  29. }
  30. const gfx::ImageSkia& TrayIconGtk::GetImage() const {
  31. NOTREACHED();
  32. return dummy_image_;
  33. }
  34. const base::string16& TrayIconGtk::GetToolTip() const {
  35. NOTREACHED();
  36. return dummy_string_;
  37. }
  38. ui::MenuModel* TrayIconGtk::GetMenuModel() const {
  39. NOTREACHED();
  40. return nullptr;
  41. }
  42. void TrayIconGtk::OnImplInitializationFailed() {}
  43. void TrayIconGtk::OnClick() {
  44. NotifyClicked();
  45. }
  46. bool TrayIconGtk::HasClickAction() {
  47. return false;
  48. }
  49. // static
  50. TrayIcon* TrayIcon::Create() {
  51. return new TrayIconGtk;
  52. }
  53. } // namespace electron