Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / views / status_icons / status_icon_linux_wrapper.cc
blobb0b1609e434d1c23e3b8236682f6265c394d05ef
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.
5 #include "chrome/browser/ui/views/status_icons/status_icon_linux_wrapper.h"
7 #include "ui/views/linux_ui/linux_ui.h"
9 StatusIconLinuxWrapper::StatusIconLinuxWrapper(
10 views::StatusIconLinux* status_icon)
11 : menu_model_(NULL) {
12 status_icon_.reset(status_icon);
13 status_icon_->set_delegate(this);
16 StatusIconLinuxWrapper::~StatusIconLinuxWrapper() {
17 if (menu_model_)
18 menu_model_->RemoveObserver(this);
21 void StatusIconLinuxWrapper::SetImage(const gfx::ImageSkia& image) {
22 status_icon_->SetImage(image);
25 void StatusIconLinuxWrapper::SetToolTip(const base::string16& tool_tip) {
26 status_icon_->SetToolTip(tool_tip);
29 void StatusIconLinuxWrapper::DisplayBalloon(const gfx::ImageSkia& icon,
30 const base::string16& title,
31 const base::string16& contents) {
32 notification_.DisplayBalloon(icon, title, contents);
35 void StatusIconLinuxWrapper::OnClick() {
36 DispatchClickEvent();
39 bool StatusIconLinuxWrapper::HasClickAction() {
40 return HasObservers();
43 void StatusIconLinuxWrapper::OnMenuStateChanged() {
44 status_icon_->RefreshPlatformContextMenu();
47 StatusIconLinuxWrapper* StatusIconLinuxWrapper::CreateWrappedStatusIcon(
48 const gfx::ImageSkia& image,
49 const base::string16& tool_tip) {
50 const views::LinuxUI* linux_ui = views::LinuxUI::instance();
51 if (linux_ui) {
52 scoped_ptr<views::StatusIconLinux> status_icon =
53 linux_ui->CreateLinuxStatusIcon(image, tool_tip);
54 if (status_icon.get())
55 return new StatusIconLinuxWrapper(status_icon.release());
57 return NULL;
60 void StatusIconLinuxWrapper::UpdatePlatformContextMenu(
61 StatusIconMenuModel* model) {
62 // If a menu already exists, remove ourself from its oberver list.
63 if (menu_model_)
64 menu_model_->RemoveObserver(this);
66 status_icon_->UpdatePlatformContextMenu(model);
67 menu_model_ = model;
69 if (model)
70 model->AddObserver(this);