| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "athena/system/status_icon_container_view.h" | 5 #include "athena/system/status_icon_container_view.h" |
| 6 | 6 |
| 7 #include "athena/resources/athena_resources.h" | 7 #include "athena/resources/athena_resources.h" |
| 8 #include "athena/system/network_selector.h" | 8 #include "athena/system/network_selector.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 25 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
| 26 #include "ui/gfx/image/image_skia_operations.h" | 26 #include "ui/gfx/image/image_skia_operations.h" |
| 27 #include "ui/views/controls/image_view.h" | 27 #include "ui/views/controls/image_view.h" |
| 28 #include "ui/views/controls/label.h" | 28 #include "ui/views/controls/label.h" |
| 29 #include "ui/views/layout/box_layout.h" | 29 #include "ui/views/layout/box_layout.h" |
| 30 | 30 |
| 31 namespace athena { | 31 namespace athena { |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 views::Label* CreateLabel(const std::string& text) { | 34 views::Label* CreateLabel(SystemUI::ColorScheme color_scheme, |
| 35 const std::string& text) { |
| 35 views::Label* label = new views::Label(base::UTF8ToUTF16(text)); | 36 views::Label* label = new views::Label(base::UTF8ToUTF16(text)); |
| 36 label->SetEnabledColor(SK_ColorWHITE); | 37 label->SetEnabledColor((color_scheme == SystemUI::COLOR_SCHEME_LIGHT) |
| 38 ? SK_ColorWHITE |
| 39 : SK_ColorDKGRAY); |
| 37 label->SetAutoColorReadabilityEnabled(false); | 40 label->SetAutoColorReadabilityEnabled(false); |
| 38 label->SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD)); | 41 label->SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD)); |
| 39 return label; | 42 return label; |
| 40 } | 43 } |
| 41 | 44 |
| 42 } // namespace | 45 } // namespace |
| 43 | 46 |
| 44 class StatusIconContainerView::PowerStatus | 47 class StatusIconContainerView::PowerStatus |
| 45 : public chromeos::PowerManagerClient::Observer { | 48 : public chromeos::PowerManagerClient::Observer { |
| 46 public: | 49 public: |
| 47 explicit PowerStatus(views::ImageView* icon) : icon_(icon) { | 50 PowerStatus(SystemUI::ColorScheme color_scheme, |
| 51 views::ImageView* icon) |
| 52 : color_scheme_(color_scheme), |
| 53 icon_(icon) { |
| 48 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 54 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
| 49 this); | 55 this); |
| 50 chromeos::DBusThreadManager::Get() | 56 chromeos::DBusThreadManager::Get() |
| 51 ->GetPowerManagerClient() | 57 ->GetPowerManagerClient() |
| 52 ->RequestStatusUpdate(); | 58 ->RequestStatusUpdate(); |
| 53 } | 59 } |
| 54 | 60 |
| 55 virtual ~PowerStatus() { | 61 virtual ~PowerStatus() { |
| 56 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( | 62 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
| 57 this); | 63 this); |
| 58 } | 64 } |
| 59 | 65 |
| 60 private: | 66 private: |
| 61 const gfx::ImageSkia GetPowerIcon( | 67 const gfx::ImageSkia GetPowerIcon( |
| 62 const power_manager::PowerSupplyProperties& proto) const { | 68 const power_manager::PowerSupplyProperties& proto) const { |
| 63 // Width and height of battery images. | 69 // Width and height of battery images. |
| 64 const int kBatteryImageHeight = 25; | 70 const int kBatteryImageHeight = 25; |
| 65 const int kBatteryImageWidth = 25; | 71 const int kBatteryImageWidth = 25; |
| 66 | 72 |
| 67 // Number of different power states. | 73 // Number of different power states. |
| 68 const int kNumPowerImages = 15; | 74 const int kNumPowerImages = 15; |
| 69 | 75 |
| 70 gfx::Image all = ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 76 gfx::Image all = ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 71 IDR_AURA_UBER_TRAY_POWER_SMALL); | 77 (color_scheme_ == SystemUI::COLOR_SCHEME_LIGHT) |
| 78 ? IDR_AURA_UBER_TRAY_POWER_SMALL |
| 79 : IDR_AURA_UBER_TRAY_POWER_SMALL_DARK); |
| 72 int horiz_offset = IsCharging(proto) ? 1 : 0; | 80 int horiz_offset = IsCharging(proto) ? 1 : 0; |
| 73 int vert_offset = -1; | 81 int vert_offset = -1; |
| 74 if (proto.battery_percent() >= 100) { | 82 if (proto.battery_percent() >= 100) { |
| 75 vert_offset = kNumPowerImages - 1; | 83 vert_offset = kNumPowerImages - 1; |
| 76 } else { | 84 } else { |
| 77 vert_offset = static_cast<int>((kNumPowerImages - 1) * | 85 vert_offset = static_cast<int>((kNumPowerImages - 1) * |
| 78 proto.battery_percent() / 100); | 86 proto.battery_percent() / 100); |
| 79 vert_offset = std::max(std::min(vert_offset, kNumPowerImages - 2), 0); | 87 vert_offset = std::max(std::min(vert_offset, kNumPowerImages - 2), 0); |
| 80 } | 88 } |
| 81 gfx::Rect region(horiz_offset * kBatteryImageWidth, | 89 gfx::Rect region(horiz_offset * kBatteryImageWidth, |
| 82 vert_offset * kBatteryImageHeight, | 90 vert_offset * kBatteryImageHeight, |
| 83 kBatteryImageWidth, | 91 kBatteryImageWidth, |
| 84 kBatteryImageHeight); | 92 kBatteryImageHeight); |
| 85 return gfx::ImageSkiaOperations::ExtractSubset(*all.ToImageSkia(), region); | 93 return gfx::ImageSkiaOperations::ExtractSubset(*all.ToImageSkia(), region); |
| 86 } | 94 } |
| 87 | 95 |
| 88 bool IsCharging(const power_manager::PowerSupplyProperties& proto) const { | 96 bool IsCharging(const power_manager::PowerSupplyProperties& proto) const { |
| 89 return proto.external_power() != | 97 return proto.external_power() != |
| 90 power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED; | 98 power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED; |
| 91 } | 99 } |
| 92 | 100 |
| 93 // chromeos::PowerManagerClient::Observer: | 101 // chromeos::PowerManagerClient::Observer: |
| 94 virtual void PowerChanged( | 102 virtual void PowerChanged( |
| 95 const power_manager::PowerSupplyProperties& proto) OVERRIDE { | 103 const power_manager::PowerSupplyProperties& proto) OVERRIDE { |
| 96 icon_->SetImage(GetPowerIcon(proto)); | 104 icon_->SetImage(GetPowerIcon(proto)); |
| 97 } | 105 } |
| 98 | 106 |
| 107 SystemUI::ColorScheme color_scheme_; |
| 99 views::ImageView* icon_; | 108 views::ImageView* icon_; |
| 100 | 109 |
| 101 DISALLOW_COPY_AND_ASSIGN(PowerStatus); | 110 DISALLOW_COPY_AND_ASSIGN(PowerStatus); |
| 102 }; | 111 }; |
| 103 | 112 |
| 104 class StatusIconContainerView::NetworkStatus | 113 class StatusIconContainerView::NetworkStatus |
| 105 : public chromeos::NetworkStateHandlerObserver { | 114 : public chromeos::NetworkStateHandlerObserver { |
| 106 public: | 115 public: |
| 107 explicit NetworkStatus(views::Label* label) : label_(label) { | 116 explicit NetworkStatus(views::Label* label) : label_(label) { |
| 108 chromeos::NetworkStateHandler* handler = | 117 chromeos::NetworkStateHandler* handler = |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 }; | 164 }; |
| 156 | 165 |
| 157 void StartUpdateCallback( | 166 void StartUpdateCallback( |
| 158 chromeos::UpdateEngineClient::UpdateCheckResult result) { | 167 chromeos::UpdateEngineClient::UpdateCheckResult result) { |
| 159 VLOG(1) << "Callback from RequestUpdateCheck, result " << result; | 168 VLOG(1) << "Callback from RequestUpdateCheck, result " << result; |
| 160 } | 169 } |
| 161 | 170 |
| 162 class StatusIconContainerView::UpdateStatus | 171 class StatusIconContainerView::UpdateStatus |
| 163 : public chromeos::UpdateEngineClient::Observer { | 172 : public chromeos::UpdateEngineClient::Observer { |
| 164 public: | 173 public: |
| 165 explicit UpdateStatus(views::ImageView* icon) : icon_(icon) { | 174 UpdateStatus(SystemUI::ColorScheme color_scheme, views::ImageView* icon) |
| 175 : color_scheme_(color_scheme), |
| 176 icon_(icon) { |
| 166 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver( | 177 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver( |
| 167 this); | 178 this); |
| 168 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()-> | 179 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()-> |
| 169 RequestUpdateCheck(base::Bind(StartUpdateCallback)); | 180 RequestUpdateCheck(base::Bind(StartUpdateCallback)); |
| 170 } | 181 } |
| 171 | 182 |
| 172 virtual ~UpdateStatus() { | 183 virtual ~UpdateStatus() { |
| 173 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver( | 184 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver( |
| 174 this); | 185 this); |
| 175 } | 186 } |
| 176 | 187 |
| 177 // chromeos::UpdateEngineClient::Observer: | 188 // chromeos::UpdateEngineClient::Observer: |
| 178 virtual void UpdateStatusChanged( | 189 virtual void UpdateStatusChanged( |
| 179 const chromeos::UpdateEngineClient::Status& status) OVERRIDE { | 190 const chromeos::UpdateEngineClient::Status& status) OVERRIDE { |
| 180 if (status.status != | 191 if (status.status != |
| 181 chromeos::UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT) { | 192 chromeos::UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT) { |
| 182 return; | 193 return; |
| 183 } | 194 } |
| 184 icon_->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 195 int image_id = (color_scheme_ == SystemUI::COLOR_SCHEME_LIGHT) |
| 185 IDR_AURA_UBER_TRAY_UPDATE)); | 196 ? IDR_AURA_UBER_TRAY_UPDATE |
| 197 : IDR_AURA_UBER_TRAY_UPDATE_DARK; |
| 198 icon_->SetImage( |
| 199 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(image_id)); |
| 186 } | 200 } |
| 187 | 201 |
| 188 private: | 202 private: |
| 203 SystemUI::ColorScheme color_scheme_; |
| 189 views::ImageView* icon_; | 204 views::ImageView* icon_; |
| 190 | 205 |
| 191 DISALLOW_COPY_AND_ASSIGN(UpdateStatus); | 206 DISALLOW_COPY_AND_ASSIGN(UpdateStatus); |
| 192 }; | 207 }; |
| 193 | 208 |
| 194 StatusIconContainerView::StatusIconContainerView( | 209 StatusIconContainerView::StatusIconContainerView( |
| 210 SystemUI::ColorScheme color_scheme, |
| 195 aura::Window* system_modal_container) | 211 aura::Window* system_modal_container) |
| 196 : system_modal_container_(system_modal_container) { | 212 : system_modal_container_(system_modal_container) { |
| 197 const int kHorizontalSpacing = 10; | 213 const int kHorizontalSpacing = 10; |
| 198 const int kVerticalSpacing = 3; | 214 const int kVerticalSpacing = 3; |
| 199 const int kBetweenChildSpacing = 10; | 215 const int kBetweenChildSpacing = 10; |
| 200 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 216 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 201 kHorizontalSpacing, | 217 kHorizontalSpacing, |
| 202 kVerticalSpacing, | 218 kVerticalSpacing, |
| 203 kBetweenChildSpacing)); | 219 kBetweenChildSpacing)); |
| 204 | 220 |
| 205 std::string version_text = | 221 std::string version_text = |
| 206 base::StringPrintf("%s (Build %s)", PRODUCT_VERSION, LAST_CHANGE); | 222 base::StringPrintf("%s (Build %s)", PRODUCT_VERSION, LAST_CHANGE); |
| 207 AddChildView(CreateLabel(version_text)); | 223 AddChildView(CreateLabel(color_scheme, version_text)); |
| 208 | 224 |
| 209 AddChildView(CreateLabel("Network:")); | 225 AddChildView(CreateLabel(color_scheme, "Network:")); |
| 210 views::Label* network_label = CreateLabel(std::string()); | 226 views::Label* network_label = CreateLabel(color_scheme, std::string()); |
| 211 AddChildView(network_label); | 227 AddChildView(network_label); |
| 212 network_status_.reset(new NetworkStatus(network_label)); | 228 network_status_.reset(new NetworkStatus(network_label)); |
| 213 | 229 |
| 214 views::ImageView* battery_view = new views::ImageView(); | 230 views::ImageView* battery_view = new views::ImageView(); |
| 215 AddChildView(battery_view); | 231 AddChildView(battery_view); |
| 216 power_status_.reset(new PowerStatus(battery_view)); | 232 power_status_.reset(new PowerStatus(color_scheme, battery_view)); |
| 217 | 233 |
| 218 views::ImageView* update_view = new views::ImageView(); | 234 views::ImageView* update_view = new views::ImageView(); |
| 219 AddChildView(update_view); | 235 AddChildView(update_view); |
| 220 update_status_.reset(new UpdateStatus(update_view)); | 236 update_status_.reset(new UpdateStatus(color_scheme, update_view)); |
| 221 } | 237 } |
| 222 | 238 |
| 223 StatusIconContainerView::~StatusIconContainerView() { | 239 StatusIconContainerView::~StatusIconContainerView() { |
| 224 } | 240 } |
| 225 | 241 |
| 226 bool StatusIconContainerView::OnMousePressed(const ui::MouseEvent& event) { | 242 bool StatusIconContainerView::OnMousePressed(const ui::MouseEvent& event) { |
| 227 CreateNetworkSelector(system_modal_container_); | 243 CreateNetworkSelector(system_modal_container_); |
| 228 return true; | 244 return true; |
| 229 } | 245 } |
| 230 | 246 |
| 231 void StatusIconContainerView::OnGestureEvent(ui::GestureEvent* event) { | 247 void StatusIconContainerView::OnGestureEvent(ui::GestureEvent* event) { |
| 232 if (event->type() == ui::ET_GESTURE_TAP) { | 248 if (event->type() == ui::ET_GESTURE_TAP) { |
| 233 CreateNetworkSelector(system_modal_container_); | 249 CreateNetworkSelector(system_modal_container_); |
| 234 event->SetHandled(); | 250 event->SetHandled(); |
| 235 } | 251 } |
| 236 } | 252 } |
| 237 | 253 |
| 238 void StatusIconContainerView::ChildPreferredSizeChanged(views::View* child) { | 254 void StatusIconContainerView::ChildPreferredSizeChanged(views::View* child) { |
| 239 PreferredSizeChanged(); | 255 PreferredSizeChanged(); |
| 240 } | 256 } |
| 241 | 257 |
| 242 } // namespace athena | 258 } // namespace athena |
| OLD | NEW |