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 : login_status_(status), |
| 35 power_status_view_(NULL) { |
30 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 36 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
31 ash::kTrayPopupPaddingHorizontal, 0, | 37 ash::kTrayPopupPaddingHorizontal, 0, |
32 ash::kTrayPopupPaddingBetweenItems)); | 38 ash::kTrayPopupPaddingBetweenItems)); |
33 | 39 |
34 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 40 if (login_status_ != user::LOGGED_IN_NONE && |
35 views::ImageView* icon = | 41 login_status_ != user::LOGGED_IN_LOCKED) { |
36 new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); | 42 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
37 icon->SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia()); | 43 views::ImageView* icon = |
38 AddChildView(icon); | 44 new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); |
| 45 icon->SetImage( |
| 46 rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia()); |
| 47 AddChildView(icon); |
39 | 48 |
40 string16 text = rb.GetLocalizedString( | 49 string16 text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_SETTINGS); |
41 IDS_ASH_STATUS_TRAY_SETTINGS); | 50 label_ = new views::Label(text); |
42 label_ = new views::Label(text); | 51 AddChildView(label_); |
43 AddChildView(label_); | 52 SetAccessibleName(text); |
| 53 } |
44 | 54 |
45 SetAccessibleName(text); | 55 PowerSupplyStatus power_status = |
| 56 ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus(); |
| 57 if (power_status.battery_is_present) { |
| 58 power_status_view_ = new ash::internal::PowerStatusView( |
| 59 ash::internal::PowerStatusView::VIEW_DEFAULT); |
| 60 AddChildView(power_status_view_); |
| 61 UpdatePowerStatus(power_status); |
| 62 } |
46 } | 63 } |
47 | 64 |
48 virtual ~SettingsView() {} | 65 virtual ~SettingsDefaultView() {} |
| 66 |
| 67 void UpdatePowerStatus(const PowerSupplyStatus& status) { |
| 68 if (power_status_view_) |
| 69 power_status_view_->UpdatePowerStatus(status); |
| 70 } |
49 | 71 |
50 // Overridden from ash::internal::ActionableView. | 72 // Overridden from ash::internal::ActionableView. |
51 virtual bool PerformAction(const views::Event& event) OVERRIDE { | 73 virtual bool PerformAction(const views::Event& event) OVERRIDE { |
| 74 if (login_status_ == user::LOGGED_IN_NONE || |
| 75 login_status_ == user::LOGGED_IN_LOCKED) |
| 76 return false; |
| 77 |
52 ash::Shell::GetInstance()->tray_delegate()->ShowSettings(); | 78 ash::Shell::GetInstance()->tray_delegate()->ShowSettings(); |
53 return true; | 79 return true; |
54 } | 80 } |
55 | 81 |
| 82 // Overridden from views::View. |
| 83 virtual void Layout() OVERRIDE { |
| 84 // Let the box-layout do the layout first. Then move power_status_view_ |
| 85 // to right align if it is created. |
| 86 views::View::Layout(); |
| 87 |
| 88 if (power_status_view_) { |
| 89 gfx::Size size = power_status_view_->GetPreferredSize(); |
| 90 gfx::Rect bounds(size); |
| 91 bounds.set_x(width() - size.width() - ash::kTrayPopupPaddingBetweenItems); |
| 92 bounds.set_y((height() - size.height()) / 2); |
| 93 power_status_view_->SetBoundsRect(bounds); |
| 94 } |
| 95 } |
| 96 |
| 97 // Overridden from views::View. |
| 98 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { |
| 99 views::View::ChildPreferredSizeChanged(child); |
| 100 Layout(); |
| 101 } |
| 102 |
56 private: | 103 private: |
| 104 user::LoginStatus login_status_; |
57 views::Label* label_; | 105 views::Label* label_; |
| 106 ash::internal::PowerStatusView* power_status_view_; |
58 | 107 |
59 DISALLOW_COPY_AND_ASSIGN(SettingsView); | 108 DISALLOW_COPY_AND_ASSIGN(SettingsDefaultView); |
60 }; | 109 }; |
61 | 110 |
62 } // namespace | 111 } // namespace tray |
63 | 112 |
64 namespace ash { | 113 TraySettings::TraySettings() |
65 namespace internal { | 114 : default_view_(NULL) { |
66 | 115 } |
67 TraySettings::TraySettings() {} | |
68 | 116 |
69 TraySettings::~TraySettings() {} | 117 TraySettings::~TraySettings() {} |
70 | 118 |
71 views::View* TraySettings::CreateTrayView(user::LoginStatus status) { | 119 views::View* TraySettings::CreateTrayView(user::LoginStatus status) { |
72 return NULL; | 120 return NULL; |
73 } | 121 } |
74 | 122 |
75 views::View* TraySettings::CreateDefaultView(user::LoginStatus status) { | 123 views::View* TraySettings::CreateDefaultView(user::LoginStatus status) { |
76 if (status == user::LOGGED_IN_NONE || status == user::LOGGED_IN_LOCKED) | 124 if ((status == user::LOGGED_IN_NONE || status == user::LOGGED_IN_LOCKED) && |
| 125 (!ash::Shell::GetInstance()->tray_delegate()-> |
| 126 GetPowerSupplyStatus().battery_is_present)) |
77 return NULL; | 127 return NULL; |
78 | 128 |
79 return new SettingsView; | 129 CHECK(default_view_ == NULL); |
| 130 default_view_ = new tray::SettingsDefaultView(status); |
| 131 return default_view_; |
80 } | 132 } |
81 | 133 |
82 views::View* TraySettings::CreateDetailedView(user::LoginStatus status) { | 134 views::View* TraySettings::CreateDetailedView(user::LoginStatus status) { |
83 NOTIMPLEMENTED(); | 135 NOTIMPLEMENTED(); |
84 return NULL; | 136 return NULL; |
85 } | 137 } |
86 | 138 |
87 void TraySettings::DestroyTrayView() { | 139 void TraySettings::DestroyTrayView() { |
88 } | 140 } |
89 | 141 |
90 void TraySettings::DestroyDefaultView() { | 142 void TraySettings::DestroyDefaultView() { |
| 143 default_view_ = NULL; |
91 } | 144 } |
92 | 145 |
93 void TraySettings::DestroyDetailedView() { | 146 void TraySettings::DestroyDetailedView() { |
94 } | 147 } |
95 | 148 |
96 void TraySettings::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 149 void TraySettings::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
97 } | 150 } |
98 | 151 |
| 152 // Overridden from PowerStatusObserver. |
| 153 void TraySettings::OnPowerStatusChanged(const PowerSupplyStatus& status) { |
| 154 if (default_view_) |
| 155 default_view_->UpdatePowerStatus(status); |
| 156 } |
| 157 |
99 } // namespace internal | 158 } // namespace internal |
100 } // namespace ash | 159 } // namespace ash |
OLD | NEW |