1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/status_icons/status_icon_linux_wrapper.h"
6
7 #include "ui/views/linux_ui/linux_ui.h"
8
StatusIconLinuxWrapper(views::StatusIconLinux * status_icon)9 StatusIconLinuxWrapper::StatusIconLinuxWrapper(
10 views::StatusIconLinux* status_icon)
11 : menu_model_(NULL) {
12 status_icon_.reset(status_icon);
13 status_icon_->set_delegate(this);
14 }
15
~StatusIconLinuxWrapper()16 StatusIconLinuxWrapper::~StatusIconLinuxWrapper() {
17 if (menu_model_)
18 menu_model_->RemoveObserver(this);
19 }
20
SetImage(const gfx::ImageSkia & image)21 void StatusIconLinuxWrapper::SetImage(const gfx::ImageSkia& image) {
22 status_icon_->SetImage(image);
23 }
24
SetPressedImage(const gfx::ImageSkia & image)25 void StatusIconLinuxWrapper::SetPressedImage(const gfx::ImageSkia& image) {
26 status_icon_->SetPressedImage(image);
27 }
28
SetToolTip(const base::string16 & tool_tip)29 void StatusIconLinuxWrapper::SetToolTip(const base::string16& tool_tip) {
30 status_icon_->SetToolTip(tool_tip);
31 }
32
DisplayBalloon(const gfx::ImageSkia & icon,const base::string16 & title,const base::string16 & contents)33 void StatusIconLinuxWrapper::DisplayBalloon(const gfx::ImageSkia& icon,
34 const base::string16& title,
35 const base::string16& contents) {
36 notification_.DisplayBalloon(icon, title, contents);
37 }
38
OnClick()39 void StatusIconLinuxWrapper::OnClick() {
40 DispatchClickEvent();
41 }
42
HasClickAction()43 bool StatusIconLinuxWrapper::HasClickAction() {
44 return HasObservers();
45 }
46
OnMenuStateChanged()47 void StatusIconLinuxWrapper::OnMenuStateChanged() {
48 status_icon_->RefreshPlatformContextMenu();
49 }
50
CreateWrappedStatusIcon(const gfx::ImageSkia & image,const base::string16 & tool_tip)51 StatusIconLinuxWrapper* StatusIconLinuxWrapper::CreateWrappedStatusIcon(
52 const gfx::ImageSkia& image,
53 const base::string16& tool_tip) {
54 const views::LinuxUI* linux_ui = views::LinuxUI::instance();
55 if (linux_ui) {
56 scoped_ptr<views::StatusIconLinux> status_icon =
57 linux_ui->CreateLinuxStatusIcon(image, tool_tip);
58 if (status_icon.get())
59 return new StatusIconLinuxWrapper(status_icon.release());
60 }
61 return NULL;
62 }
63
UpdatePlatformContextMenu(StatusIconMenuModel * model)64 void StatusIconLinuxWrapper::UpdatePlatformContextMenu(
65 StatusIconMenuModel* model) {
66 // If a menu already exists, remove ourself from its oberver list.
67 if (menu_model_)
68 menu_model_->RemoveObserver(this);
69
70 status_icon_->UpdatePlatformContextMenu(model);
71 menu_model_ = model;
72
73 if (model)
74 model->AddObserver(this);
75 }
76