network_menu_button.h revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2006-2008 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#ifndef CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_
6#define CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_
7#pragma once
8
9#include <string>
10
11#include "base/timer.h"
12#include "chrome/browser/chromeos/cros/network_library.h"
13#include "chrome/browser/chromeos/status/network_menu.h"
14#include "chrome/browser/chromeos/status/status_area_button.h"
15#include "ui/base/animation/throb_animation.h"
16
17namespace gfx {
18class Canvas;
19}
20
21namespace chromeos {
22
23class StatusAreaHost;
24
25// The network menu button in the status area.
26// This class will handle getting the wifi networks and populating the menu.
27// It will also handle the status icon changing and connecting to another
28// wifi/cellular network.
29//
30// The network menu looks like this:
31//
32// <icon>  Ethernet
33// <icon>  Wifi Network A
34// <icon>  Wifi Network B
35// <icon>  Wifi Network C
36// <icon>  Cellular Network A
37// <icon>  Cellular Network B
38// <icon>  Cellular Network C
39// <icon>  Other...
40// --------------------------------
41//         Disable Wifi
42//         Disable Celluar
43// --------------------------------
44//         <IP Address>
45//         Network settings...
46//
47// <icon> will show the strength of the wifi/cellular networks.
48// The label will be BOLD if the network is currently connected.
49class NetworkMenuButton : public StatusAreaButton,
50                          public NetworkMenu,
51                          public NetworkLibrary::NetworkManagerObserver,
52                          public NetworkLibrary::NetworkObserver,
53                          public NetworkLibrary::CellularDataPlanObserver {
54 public:
55  explicit NetworkMenuButton(StatusAreaHost* host);
56  virtual ~NetworkMenuButton();
57
58  // ui::AnimationDelegate implementation.
59  virtual void AnimationProgressed(const ui::Animation* animation);
60
61  // NetworkLibrary::NetworkManagerObserver implementation.
62  virtual void OnNetworkManagerChanged(NetworkLibrary* cros);
63  // NetworkLibrary::NetworkObserver implementation.
64  virtual void OnNetworkChanged(NetworkLibrary* cros, const Network* network);
65  // NetworkLibrary::CellularDataPlanObserver implementation.
66  virtual void OnCellularDataPlanChanged(NetworkLibrary* cros);
67
68 protected:
69  // NetworkMenu implementation:
70  virtual bool IsBrowserMode() const;
71  virtual gfx::NativeWindow GetNativeWindow() const;
72  virtual void OpenButtonOptions();
73  virtual bool ShouldOpenButtonOptions() const;
74
75 private:
76  // Sets the icon and the badge.
77  void SetIconAndBadge(const SkBitmap* icon, const SkBitmap* badge);
78  // Sets the icon only. Keep the previous badge.
79  void SetIconOnly(const SkBitmap* icon);
80  // Sets the badge only. Keep the previous icon.
81  void SetBadgeOnly(const SkBitmap* badge);
82  // Set the network icon based on the status of the |network|
83  void SetNetworkIcon(NetworkLibrary* cros, const Network* network);
84
85  // Called when the active network has possibly changed. This will remove
86  // old network observer and add a network observer for the active network.
87  void RefreshNetworkObserver(NetworkLibrary* cros);
88
89  // The status area host,
90  StatusAreaHost* host_;
91
92  // The icon showing the network strength.
93  const SkBitmap* icon_;
94  // A badge icon displayed on top of the icon.
95  const SkBitmap* badge_;
96
97  // The throb animation that does the wifi connecting animation.
98  ui::ThrobAnimation animation_connecting_;
99
100  // The duration of the icon throbbing in milliseconds.
101  static const int kThrobDuration;
102
103  // If any network is currently active, this is the service path of the one
104  // whose status is displayed in the network menu button.
105  std::string active_network_;
106
107  DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton);
108};
109
110}  // namespace chromeos
111
112#endif  // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_
113