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 #include "ash/system/settings/tray_settings.h" | 5 #include "ash/system/settings/tray_settings.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/power/power_status_view.h" | |
8 #include "ash/system/tray/system_tray_delegate.h" | 9 #include "ash/system/tray/system_tray_delegate.h" |
9 #include "ash/system/tray/tray_constants.h" | 10 #include "ash/system/tray/tray_constants.h" |
10 #include "ash/system/tray/tray_views.h" | 11 #include "ash/system/tray/tray_views.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
14 #include "grit/ui_resources_standard.h" | 15 #include "grit/ui_resources_standard.h" |
15 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
16 #include "ui/base/accessibility/accessible_view_state.h" | 17 #include "ui/base/accessibility/accessible_view_state.h" |
17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
19 #include "ui/views/controls/image_view.h" | 20 #include "ui/views/controls/image_view.h" |
20 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
21 #include "ui/views/layout/box_layout.h" | 22 #include "ui/views/layout/box_layout.h" |
22 #include "ui/views/layout/fill_layout.h" | 23 #include "ui/views/layout/fill_layout.h" |
23 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
24 | 25 |
25 namespace { | 26 namespace ash { |
27 namespace internal { | |
26 | 28 |
27 class SettingsView : public ash::internal::ActionableView { | 29 namespace tray { |
30 | |
31 class SettingsDefaultView : public ash::internal::ActionableView { | |
28 public: | 32 public: |
29 SettingsView() { | 33 explicit SettingsDefaultView(user::LoginStatus status) |
34 : power_status_view_(NULL) { | |
30 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 35 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
31 ash::kTrayPopupPaddingHorizontal, 0, | 36 ash::kTrayPopupPaddingHorizontal, 0, |
32 ash::kTrayPopupPaddingBetweenItems)); | 37 ash::kTrayPopupPaddingBetweenItems)); |
33 | 38 |
34 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 39 if (status != user::LOGGED_IN_NONE && status != user::LOGGED_IN_LOCKED) { |
35 views::ImageView* icon = | 40 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
36 new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); | 41 views::ImageView* icon = |
37 icon->SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia()); | 42 new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); |
38 AddChildView(icon); | 43 icon->SetImage( |
44 rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia()); | |
45 AddChildView(icon); | |
39 | 46 |
40 string16 text = rb.GetLocalizedString( | 47 string16 text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_SETTINGS); |
41 IDS_ASH_STATUS_TRAY_SETTINGS); | 48 label_ = new views::Label(text); |
42 label_ = new views::Label(text); | 49 AddChildView(label_); |
43 AddChildView(label_); | 50 SetAccessibleName(text); |
51 } | |
44 | 52 |
45 SetAccessibleName(text); | 53 PowerSupplyStatus power_status = |
54 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); | |
55 if (power_status.battery_is_present) { | |
56 power_status_view_ = new ash::internal::tray::PowerStatusView( | |
57 ash::internal::tray::PowerStatusView::VIEW_DEFAULT); | |
58 AddChildView(power_status_view_); | |
59 power_status_view_->UpdatePowerStatus(power_status); | |
stevenjb
2012/06/07 01:31:18
nit: Put this into UpdatePowerStatus()? (See comme
jennyz
2012/06/07 22:06:52
Done.
| |
60 } | |
46 } | 61 } |
47 | 62 |
48 virtual ~SettingsView() {} | 63 virtual ~SettingsDefaultView() {} |
49 | 64 |
50 // Overridden from ash::internal::ActionableView. | 65 // Overridden from ash::internal::ActionableView. |
51 virtual bool PerformAction(const views::Event& event) OVERRIDE { | 66 virtual bool PerformAction(const views::Event& event) OVERRIDE { |
52 ash::Shell::GetInstance()->tray_delegate()->ShowSettings(); | 67 ash::Shell::GetInstance()->tray_delegate()->ShowSettings(); |
53 return true; | 68 return true; |
54 } | 69 } |
55 | 70 |
71 // Overridden from views::View. | |
72 virtual void Layout() OVERRIDE { | |
73 // Let the box-layout do the layout first. Then move power_status_view_ | |
74 // to right align if it is created. | |
75 views::View::Layout(); | |
76 | |
77 if (power_status_view_) { | |
78 gfx::Size size = power_status_view_->GetPreferredSize(); | |
79 gfx::Rect bounds(size); | |
80 bounds.set_x(width() - size.width() - ash::kTrayPopupPaddingBetweenItems); | |
81 bounds.set_y((height() - size.height()) / 2); | |
82 power_status_view_->SetBoundsRect(bounds); | |
83 } | |
84 } | |
85 | |
86 // Overridden from views::View. | |
87 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { | |
88 views::View::ChildPreferredSizeChanged(child); | |
89 Layout(); | |
90 } | |
91 | |
92 ash::internal::tray::PowerStatusView* power_status_view() { | |
93 return power_status_view_; | |
94 } | |
95 | |
56 private: | 96 private: |
57 views::Label* label_; | 97 views::Label* label_; |
98 ash::internal::tray::PowerStatusView* power_status_view_; | |
58 | 99 |
59 DISALLOW_COPY_AND_ASSIGN(SettingsView); | 100 DISALLOW_COPY_AND_ASSIGN(SettingsDefaultView); |
60 }; | 101 }; |
61 | 102 |
62 } // namespace | 103 } // namespace tray |
63 | 104 |
64 namespace ash { | 105 TraySettings::TraySettings() |
65 namespace internal { | 106 : default_(NULL) { |
66 | 107 } |
67 TraySettings::TraySettings() {} | |
68 | 108 |
69 TraySettings::~TraySettings() {} | 109 TraySettings::~TraySettings() {} |
70 | 110 |
71 views::View* TraySettings::CreateTrayView(user::LoginStatus status) { | 111 views::View* TraySettings::CreateTrayView(user::LoginStatus status) { |
72 return NULL; | 112 return NULL; |
73 } | 113 } |
74 | 114 |
75 views::View* TraySettings::CreateDefaultView(user::LoginStatus status) { | 115 views::View* TraySettings::CreateDefaultView(user::LoginStatus status) { |
76 if (status == user::LOGGED_IN_NONE || status == user::LOGGED_IN_LOCKED) | 116 if ((status == user::LOGGED_IN_NONE || status == user::LOGGED_IN_LOCKED) && |
117 (!ash::Shell::GetInstance()->tray_delegate()-> | |
118 GetPowerSupplyStatus().battery_is_present)) | |
77 return NULL; | 119 return NULL; |
78 | 120 |
79 return new SettingsView; | 121 CHECK(default_ == NULL); |
122 default_ = new tray::SettingsDefaultView(status); | |
123 return default_; | |
80 } | 124 } |
81 | 125 |
82 views::View* TraySettings::CreateDetailedView(user::LoginStatus status) { | 126 views::View* TraySettings::CreateDetailedView(user::LoginStatus status) { |
83 NOTIMPLEMENTED(); | 127 NOTIMPLEMENTED(); |
84 return NULL; | 128 return NULL; |
85 } | 129 } |
86 | 130 |
87 void TraySettings::DestroyTrayView() { | 131 void TraySettings::DestroyTrayView() { |
88 } | 132 } |
89 | 133 |
90 void TraySettings::DestroyDefaultView() { | 134 void TraySettings::DestroyDefaultView() { |
135 default_ = NULL; | |
91 } | 136 } |
92 | 137 |
93 void TraySettings::DestroyDetailedView() { | 138 void TraySettings::DestroyDetailedView() { |
94 } | 139 } |
95 | 140 |
96 void TraySettings::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 141 void TraySettings::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
97 } | 142 } |
98 | 143 |
144 // Overridden from PowerStatusObserver. | |
145 void TraySettings::OnPowerStatusChanged(const PowerSupplyStatus& status) { | |
146 if (default_ && default_->power_status_view()) | |
147 default_->power_status_view()->UpdatePowerStatus(status); | |
stevenjb
2012/06/07 01:31:18
nit: Make UpdatePowerStatus() a member of PowerSta
jennyz
2012/06/07 22:06:52
Done, you mean make UpdatePowerStatus() a member o
| |
148 } | |
149 | |
99 } // namespace internal | 150 } // namespace internal |
100 } // namespace ash | 151 } // namespace ash |
OLD | NEW |