| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_ICON_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_ICON_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_ICON_H_ | 6 #define CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_ICON_H_ |
| 7 | 7 |
| 8 // NetworkMenuIcon Manages an icon that reflects the current state of the | 8 // NetworkMenuIcon Manages an icon that reflects the current state of the |
| 9 // network (see chromeos::NetworkLibrary). It takes an optional Delegate | 9 // network (see chromeos::NetworkLibrary). It takes an optional Delegate |
| 10 // argument in the constructor that signals the delegate when the icon changes. | 10 // argument in the constructor that signals the delegate when the icon changes. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // Example usage: | 26 // Example usage: |
| 27 // Network* network = network_library->FindNetworkByPath(my_network_path_); | 27 // Network* network = network_library->FindNetworkByPath(my_network_path_); |
| 28 // SetIcon(NetworkMenuIcon::GetBitmap(network); | 28 // SetIcon(NetworkMenuIcon::GetBitmap(network); |
| 29 // | 29 // |
| 30 // This class is not explicitly thread-safe and functions are expected to be | 30 // This class is not explicitly thread-safe and functions are expected to be |
| 31 // called from the UI thread. | 31 // called from the UI thread. |
| 32 | 32 |
| 33 #include <map> | 33 #include <map> |
| 34 #include <string> | 34 #include <string> |
| 35 | 35 |
| 36 #include "ash/system/chromeos/network/network_icon_animation_observer.h" |
| 36 #include "base/memory/scoped_ptr.h" | 37 #include "base/memory/scoped_ptr.h" |
| 37 #include "base/time.h" | 38 #include "base/time.h" |
| 38 #include "chrome/browser/chromeos/cros/network_library.h" | 39 #include "chrome/browser/chromeos/cros/network_library.h" |
| 39 #include "ui/base/animation/animation_delegate.h" | |
| 40 #include "ui/base/animation/throb_animation.h" | |
| 41 #include "ui/gfx/image/image_skia.h" | 40 #include "ui/gfx/image/image_skia.h" |
| 42 | 41 |
| 43 namespace chromeos { | 42 namespace chromeos { |
| 44 | 43 |
| 45 class NetworkIcon; | 44 class NetworkIcon; |
| 46 | 45 |
| 47 class NetworkMenuIcon : public ui::AnimationDelegate { | 46 class NetworkMenuIcon : public ash::network_icon::AnimationObserver { |
| 48 public: | 47 public: |
| 49 enum Mode { | 48 enum Mode { |
| 50 MENU_MODE, // Prioritizes connecting networks and sets tooltips. | 49 MENU_MODE, // Prioritizes connecting networks and sets tooltips. |
| 51 DROPDOWN_MODE, // Prioritizes connected networks and sets display text. | 50 DROPDOWN_MODE, // Prioritizes connected networks and sets display text. |
| 52 }; | 51 }; |
| 53 | 52 |
| 54 enum ResourceColorTheme { | 53 enum ResourceColorTheme { |
| 55 COLOR_DARK, | 54 COLOR_DARK, |
| 56 COLOR_LIGHT, | 55 COLOR_LIGHT, |
| 57 }; | 56 }; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 84 | 83 |
| 85 // Returns true if the icon should be visible in a system tray. | 84 // Returns true if the icon should be visible in a system tray. |
| 86 bool ShouldShowIconInTray(); | 85 bool ShouldShowIconInTray(); |
| 87 | 86 |
| 88 // Generates and returns the icon image. If |text| is not NULL, sets it to | 87 // Generates and returns the icon image. If |text| is not NULL, sets it to |
| 89 // the tooltip or display text to show, based on the value of mode_. | 88 // the tooltip or display text to show, based on the value of mode_. |
| 90 const gfx::ImageSkia GetIconAndText(string16* text); | 89 const gfx::ImageSkia GetIconAndText(string16* text); |
| 91 // Generates and returns the icon image for vpn network connection. | 90 // Generates and returns the icon image for vpn network connection. |
| 92 const gfx::ImageSkia GetVpnIconAndText(string16* text); | 91 const gfx::ImageSkia GetVpnIconAndText(string16* text); |
| 93 | 92 |
| 94 | 93 // ash::network_icon::AnimationObserver implementation. |
| 95 // ui::AnimationDelegate implementation. | 94 virtual void NetworkIconChanged() OVERRIDE; |
| 96 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | |
| 97 | 95 |
| 98 // Static functions for generating network icon images: | 96 // Static functions for generating network icon images: |
| 99 | 97 |
| 100 // Composites the images to generate a network icon. Input parameters are | 98 // Composites the images to generate a network icon. Input parameters are |
| 101 // the icon and badges that are composited to generate |result|. Public | 99 // the icon and badges that are composited to generate |result|. Public |
| 102 // primarily for unit tests. | 100 // primarily for unit tests. |
| 103 static const gfx::ImageSkia GenerateImageFromComponents( | 101 static const gfx::ImageSkia GenerateImageFromComponents( |
| 104 const gfx::ImageSkia& icon, | 102 const gfx::ImageSkia& icon, |
| 105 const gfx::ImageSkia* top_left_badge, | 103 const gfx::ImageSkia* top_left_badge, |
| 106 const gfx::ImageSkia* top_right_badge, | 104 const gfx::ImageSkia* top_right_badge, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 135 | 133 |
| 136 // Returns total number of images for given type. | 134 // Returns total number of images for given type. |
| 137 static int NumImages(ImageType type); | 135 static int NumImages(ImageType type); |
| 138 | 136 |
| 139 protected: | 137 protected: |
| 140 // Starts the connection animation if necessary and returns its current value. | 138 // Starts the connection animation if necessary and returns its current value. |
| 141 // Virtual so that unit tests can override this. | 139 // Virtual so that unit tests can override this. |
| 142 virtual double GetAnimation(); | 140 virtual double GetAnimation(); |
| 143 | 141 |
| 144 private: | 142 private: |
| 143 // Returns the index for a connecting icon. |
| 144 int GetConnectingIndex(); |
| 145 // Returns the appropriate connecting network if any. | 145 // Returns the appropriate connecting network if any. |
| 146 const Network* GetConnectingNetwork(); | 146 const Network* GetConnectingNetwork(); |
| 147 // Sets the icon based on the state of the network and the network library. | 147 // Sets the icon based on the state of the network and the network library. |
| 148 // Sets text_ to the appropriate tooltip or display text. | 148 // Sets text_ to the appropriate tooltip or display text. |
| 149 void SetIconAndText(); | 149 // Returns true if the icon should animate. |
| 150 bool SetIconAndText(); |
| 150 // Sets the icon and text for VPN connection. | 151 // Sets the icon and text for VPN connection. |
| 151 void SetVpnIconAndText(); | 152 // Returns true if the icon should animate. |
| 153 bool SetVpnIconAndText(); |
| 152 // Set the icon and text to show a warning if unable to load the cros library. | 154 // Set the icon and text to show a warning if unable to load the cros library. |
| 153 void SetWarningIconAndText(); | 155 void SetWarningIconAndText(); |
| 154 // Sets the icon and text when displaying a connecting state. | 156 // Sets the icon and text when displaying a connecting state. |
| 155 void SetConnectingIconAndText(); | 157 void SetConnectingIconAndText(const Network* connecting_network); |
| 156 // Sets the icon and text when connected to |network|. | 158 // Sets the icon and text when connected to |network|. |
| 157 void SetActiveNetworkIconAndText(const Network* network); | 159 // Returns true if the icon should animate. |
| 160 bool SetActiveNetworkIconAndText(const Network* network); |
| 158 // Sets the icon and text when disconnected. | 161 // Sets the icon and text when disconnected. |
| 159 void SetDisconnectedIconAndText(); | 162 void SetDisconnectedIconAndText(); |
| 160 | 163 |
| 161 // Specifies whether this icon is for a normal menu or a dropdown menu. | 164 // Specifies whether this icon is for a normal menu or a dropdown menu. |
| 162 Mode mode_; | 165 Mode mode_; |
| 163 // A delegate may be specified to receive notifications when this animates. | 166 // A delegate may be specified to receive notifications when this animates. |
| 164 Delegate* delegate_; | 167 Delegate* delegate_; |
| 165 // Generated image for connecting to a VPN. | 168 // Generated image for connecting to a VPN. |
| 166 gfx::ImageSkia vpn_connecting_badge_; | 169 gfx::ImageSkia vpn_connecting_badge_; |
| 167 ResourceColorTheme resource_color_theme_; | 170 ResourceColorTheme resource_color_theme_; |
| 168 // Animation throbber for animating the icon while conencting. | |
| 169 ui::ThrobAnimation animation_connecting_; | |
| 170 // The generated icon image. | 171 // The generated icon image. |
| 171 scoped_ptr<NetworkIcon> icon_; | 172 scoped_ptr<NetworkIcon> icon_; |
| 172 // A weak pointer to the currently connecting network. Used only for | 173 // A weak pointer to the currently connecting network. Used only for |
| 173 // comparison purposes; accessing this directly may be invalid. | 174 // comparison purposes; accessing this directly may be invalid. |
| 174 const Network* connecting_network_; | 175 const Network* connecting_network_; |
| 176 // Index of current connecting animation. |
| 177 int connecting_index_; |
| 175 // The tooltip or display text associated with the menu icon. | 178 // The tooltip or display text associated with the menu icon. |
| 176 string16 text_; | 179 string16 text_; |
| 177 // Timer to eliminate noise while initializing cellular. | 180 // Timer to eliminate noise while initializing cellular. |
| 178 base::Time initialize_state_time_; | 181 base::Time initialize_state_time_; |
| 179 | 182 |
| 180 DISALLOW_COPY_AND_ASSIGN(NetworkMenuIcon); | 183 DISALLOW_COPY_AND_ASSIGN(NetworkMenuIcon); |
| 181 }; | 184 }; |
| 182 | 185 |
| 183 } // namespace chromeos | 186 } // namespace chromeos |
| 184 | 187 |
| 185 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_ICON_H_ | 188 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_ICON_H_ |
| OLD | NEW |