Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: ash/common/system/chromeos/power/tray_power.cc

Issue 2455183002: Simplify layout of tray items and fix spacing for MD. (Closed)
Patch Set: tda review Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/system/chromeos/network/tray_network.cc ('k') | ash/common/system/date/date_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ash/common/system/chromeos/power/tray_power.h" 5 #include "ash/common/system/chromeos/power/tray_power.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/accessibility_delegate.h" 9 #include "ash/common/accessibility_delegate.h"
10 #include "ash/common/ash_switches.h" 10 #include "ash/common/ash_switches.h"
11 #include "ash/common/system/chromeos/devicetype_utils.h" 11 #include "ash/common/system/chromeos/devicetype_utils.h"
12 #include "ash/common/system/chromeos/power/battery_notification.h" 12 #include "ash/common/system/chromeos/power/battery_notification.h"
13 #include "ash/common/system/chromeos/power/dual_role_notification.h" 13 #include "ash/common/system/chromeos/power/dual_role_notification.h"
14 #include "ash/common/system/date/date_view.h" 14 #include "ash/common/system/date/date_view.h"
15 #include "ash/common/system/system_notifier.h" 15 #include "ash/common/system/system_notifier.h"
16 #include "ash/common/system/tray/system_tray_delegate.h" 16 #include "ash/common/system/tray/system_tray_delegate.h"
17 #include "ash/common/system/tray/tray_constants.h" 17 #include "ash/common/system/tray/tray_constants.h"
18 #include "ash/common/system/tray/tray_item_view.h"
18 #include "ash/common/system/tray/tray_utils.h" 19 #include "ash/common/system/tray/tray_utils.h"
19 #include "base/command_line.h" 20 #include "base/command_line.h"
20 #include "base/logging.h" 21 #include "base/logging.h"
21 #include "base/metrics/histogram.h" 22 #include "base/metrics/histogram.h"
22 #include "base/time/time.h" 23 #include "base/time/time.h"
23 #include "grit/ash_resources.h" 24 #include "grit/ash_resources.h"
24 #include "grit/ash_strings.h" 25 #include "grit/ash_strings.h"
25 #include "ui/accessibility/ax_view_state.h" 26 #include "ui/accessibility/ax_view_state.h"
26 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/message_center/message_center.h" 28 #include "ui/message_center/message_center.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 LOG(WARNING) << "Showing " << GetNotificationStateString(state) 84 LOG(WARNING) << "Showing " << GetNotificationStateString(state)
84 << " notification. No charger connected." 85 << " notification. No charger connected."
85 << " Remaining time: " << remaining_minutes << " minutes."; 86 << " Remaining time: " << remaining_minutes << " minutes.";
86 } 87 }
87 88
88 } // namespace 89 } // namespace
89 90
90 namespace tray { 91 namespace tray {
91 92
92 // This view is used only for the tray. 93 // This view is used only for the tray.
93 class PowerTrayView : public views::ImageView { 94 class PowerTrayView : public TrayItemView {
94 public: 95 public:
95 PowerTrayView() { UpdateImage(); } 96 explicit PowerTrayView(SystemTrayItem* owner) : TrayItemView(owner) {
97 CreateImageView();
98 UpdateImage();
99 }
96 100
97 ~PowerTrayView() override {} 101 ~PowerTrayView() override {}
98 102
99 // Overriden from views::View. 103 // Overriden from views::View.
100 void GetAccessibleState(ui::AXViewState* state) override { 104 void GetAccessibleState(ui::AXViewState* state) override {
101 state->name = accessible_name_; 105 state->name = accessible_name_;
102 state->role = ui::AX_ROLE_BUTTON; 106 state->role = ui::AX_ROLE_BUTTON;
103 } 107 }
104 108
105 void UpdateStatus(bool battery_alert) { 109 void UpdateStatus(bool battery_alert) {
106 UpdateImage(); 110 UpdateImage();
107 SetVisible(PowerStatus::Get()->IsBatteryPresent()); 111 SetVisible(PowerStatus::Get()->IsBatteryPresent());
108 112
109 if (battery_alert) { 113 if (battery_alert) {
110 accessible_name_ = PowerStatus::Get()->GetAccessibleNameString(true); 114 accessible_name_ = PowerStatus::Get()->GetAccessibleNameString(true);
111 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 115 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
112 } 116 }
113 } 117 }
114 118
115 private: 119 private:
116 void UpdateImage() { 120 void UpdateImage() {
117 const PowerStatus::BatteryImageInfo info = 121 const PowerStatus::BatteryImageInfo info =
118 PowerStatus::Get()->GetBatteryImageInfo(PowerStatus::ICON_LIGHT); 122 PowerStatus::Get()->GetBatteryImageInfo(PowerStatus::ICON_LIGHT);
119 if (info != previous_image_info_) { 123 if (info != previous_image_info_) {
120 SetImage(PowerStatus::Get()->GetBatteryImage(info)); 124 image_view()->SetImage(PowerStatus::Get()->GetBatteryImage(info));
121 previous_image_info_ = info; 125 previous_image_info_ = info;
122 } 126 }
123 } 127 }
124 128
125 base::string16 accessible_name_; 129 base::string16 accessible_name_;
126 130
127 // Information about the last-used image. Cached to avoid unnecessary updates 131 // Information about the last-used image. Cached to avoid unnecessary updates
128 // (http://crbug.com/589348). 132 // (http://crbug.com/589348).
129 PowerStatus::BatteryImageInfo previous_image_info_; 133 PowerStatus::BatteryImageInfo previous_image_info_;
130 134
(...skipping 25 matching lines...) Expand all
156 TrayPower::~TrayPower() { 160 TrayPower::~TrayPower() {
157 PowerStatus::Get()->RemoveObserver(this); 161 PowerStatus::Get()->RemoveObserver(this);
158 message_center_->RemoveNotification(kUsbNotificationId, false); 162 message_center_->RemoveNotification(kUsbNotificationId, false);
159 } 163 }
160 164
161 views::View* TrayPower::CreateTrayView(LoginStatus status) { 165 views::View* TrayPower::CreateTrayView(LoginStatus status) {
162 // There may not be enough information when this is created about whether 166 // There may not be enough information when this is created about whether
163 // there is a battery or not. So always create this, and adjust visibility as 167 // there is a battery or not. So always create this, and adjust visibility as
164 // necessary. 168 // necessary.
165 CHECK(power_tray_ == NULL); 169 CHECK(power_tray_ == NULL);
166 power_tray_ = new tray::PowerTrayView(); 170 power_tray_ = new tray::PowerTrayView(this);
167 power_tray_->UpdateStatus(false); 171 power_tray_->UpdateStatus(false);
168 return power_tray_; 172 return power_tray_;
169 } 173 }
170 174
171 views::View* TrayPower::CreateDefaultView(LoginStatus status) { 175 views::View* TrayPower::CreateDefaultView(LoginStatus status) {
172 // Make sure icon status is up to date. (Also triggers stub activation). 176 // Make sure icon status is up to date. (Also triggers stub activation).
173 PowerStatus::Get()->RequestStatusUpdate(); 177 PowerStatus::Get()->RequestStatusUpdate();
174 return NULL; 178 return NULL;
175 } 179 }
176 180
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 354 }
351 NOTREACHED(); 355 NOTREACHED();
352 return false; 356 return false;
353 } 357 }
354 358
355 void TrayPower::NotifyUsbNotificationClosedByUser() { 359 void TrayPower::NotifyUsbNotificationClosedByUser() {
356 usb_notification_dismissed_ = true; 360 usb_notification_dismissed_ = true;
357 } 361 }
358 362
359 } // namespace ash 363 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/network/tray_network.cc ('k') | ash/common/system/date/date_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698