| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/system/chromeos/settings/tray_settings.h" | |
| 6 | |
| 7 #include "ash/common/session/session_state_delegate.h" | |
| 8 #include "ash/common/system/tray/actionable_view.h" | |
| 9 #include "ash/common/system/tray/fixed_sized_image_view.h" | |
| 10 #include "ash/common/system/tray/system_tray_delegate.h" | |
| 11 #include "ash/common/system/tray/tray_constants.h" | |
| 12 #include "ash/common/wm_shell.h" | |
| 13 #include "ash/shell.h" | |
| 14 #include "ash/system/chromeos/power/power_status.h" | |
| 15 #include "ash/system/chromeos/power/power_status_view.h" | |
| 16 #include "base/logging.h" | |
| 17 #include "base/strings/utf_string_conversions.h" | |
| 18 #include "grit/ash_resources.h" | |
| 19 #include "grit/ash_strings.h" | |
| 20 #include "third_party/skia/include/core/SkColor.h" | |
| 21 #include "ui/base/resource/resource_bundle.h" | |
| 22 #include "ui/gfx/image/image.h" | |
| 23 #include "ui/views/controls/image_view.h" | |
| 24 #include "ui/views/controls/label.h" | |
| 25 #include "ui/views/layout/box_layout.h" | |
| 26 #include "ui/views/layout/fill_layout.h" | |
| 27 #include "ui/views/view.h" | |
| 28 | |
| 29 namespace ash { | |
| 30 namespace tray { | |
| 31 | |
| 32 class SettingsDefaultView : public ActionableView, | |
| 33 public PowerStatus::Observer { | |
| 34 public: | |
| 35 explicit SettingsDefaultView(LoginStatus status) | |
| 36 : login_status_(status), label_(NULL), power_status_view_(NULL) { | |
| 37 PowerStatus::Get()->AddObserver(this); | |
| 38 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | |
| 39 ash::kTrayPopupPaddingHorizontal, 0, | |
| 40 ash::kTrayPopupPaddingBetweenItems)); | |
| 41 | |
| 42 bool power_view_right_align = false; | |
| 43 bool userAddingRunning = ash::Shell::GetInstance() | |
| 44 ->session_state_delegate() | |
| 45 ->IsInSecondaryLoginScreen(); | |
| 46 | |
| 47 if (login_status_ != LoginStatus::NOT_LOGGED_IN && | |
| 48 login_status_ != LoginStatus::LOCKED && !userAddingRunning) { | |
| 49 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 50 views::ImageView* icon = | |
| 51 new ash::FixedSizedImageView(0, ash::kTrayPopupItemHeight); | |
| 52 icon->SetImage( | |
| 53 rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia()); | |
| 54 icon->set_id(test::kSettingsTrayItemViewId); | |
| 55 AddChildView(icon); | |
| 56 | |
| 57 base::string16 text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_SETTINGS); | |
| 58 label_ = new views::Label(text); | |
| 59 AddChildView(label_); | |
| 60 SetAccessibleName(text); | |
| 61 | |
| 62 power_view_right_align = true; | |
| 63 } | |
| 64 | |
| 65 if (PowerStatus::Get()->IsBatteryPresent()) { | |
| 66 power_status_view_ = new ash::PowerStatusView(power_view_right_align); | |
| 67 AddChildView(power_status_view_); | |
| 68 OnPowerStatusChanged(); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 ~SettingsDefaultView() override { PowerStatus::Get()->RemoveObserver(this); } | |
| 73 | |
| 74 // Overridden from ash::ActionableView. | |
| 75 bool PerformAction(const ui::Event& event) override { | |
| 76 bool adding_user = Shell::GetInstance() | |
| 77 ->session_state_delegate() | |
| 78 ->IsInSecondaryLoginScreen(); | |
| 79 | |
| 80 if (login_status_ == LoginStatus::NOT_LOGGED_IN || | |
| 81 login_status_ == LoginStatus::LOCKED || adding_user) { | |
| 82 return false; | |
| 83 } | |
| 84 | |
| 85 WmShell::Get()->system_tray_delegate()->ShowSettings(); | |
| 86 return true; | |
| 87 } | |
| 88 | |
| 89 // Overridden from views::View. | |
| 90 void Layout() override { | |
| 91 views::View::Layout(); | |
| 92 | |
| 93 if (label_ && power_status_view_) { | |
| 94 // Let the box-layout do the layout first. Then move power_status_view_ | |
| 95 // to right align if it is created. | |
| 96 gfx::Size size = power_status_view_->GetPreferredSize(); | |
| 97 gfx::Rect bounds(size); | |
| 98 bounds.set_x(width() - size.width() - ash::kTrayPopupPaddingBetweenItems); | |
| 99 bounds.set_y((height() - size.height()) / 2); | |
| 100 power_status_view_->SetBoundsRect(bounds); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 // Overridden from views::View. | |
| 105 void ChildPreferredSizeChanged(views::View* child) override { | |
| 106 views::View::ChildPreferredSizeChanged(child); | |
| 107 Layout(); | |
| 108 } | |
| 109 | |
| 110 // Overridden from PowerStatus::Observer. | |
| 111 void OnPowerStatusChanged() override { | |
| 112 if (!PowerStatus::Get()->IsBatteryPresent()) | |
| 113 return; | |
| 114 | |
| 115 base::string16 accessible_name = label_ ? | |
| 116 label_->text() + base::ASCIIToUTF16(", ") + | |
| 117 PowerStatus::Get()->GetAccessibleNameString(true) : | |
| 118 PowerStatus::Get()->GetAccessibleNameString(true); | |
| 119 SetAccessibleName(accessible_name); | |
| 120 } | |
| 121 | |
| 122 private: | |
| 123 LoginStatus login_status_; | |
| 124 views::Label* label_; | |
| 125 ash::PowerStatusView* power_status_view_; | |
| 126 | |
| 127 DISALLOW_COPY_AND_ASSIGN(SettingsDefaultView); | |
| 128 }; | |
| 129 | |
| 130 } // namespace tray | |
| 131 | |
| 132 TraySettings::TraySettings(SystemTray* system_tray) | |
| 133 : SystemTrayItem(system_tray), | |
| 134 default_view_(NULL) { | |
| 135 } | |
| 136 | |
| 137 TraySettings::~TraySettings() { | |
| 138 } | |
| 139 | |
| 140 views::View* TraySettings::CreateTrayView(LoginStatus status) { | |
| 141 return NULL; | |
| 142 } | |
| 143 | |
| 144 views::View* TraySettings::CreateDefaultView(LoginStatus status) { | |
| 145 if ((status == LoginStatus::NOT_LOGGED_IN || status == LoginStatus::LOCKED) && | |
| 146 !PowerStatus::Get()->IsBatteryPresent()) | |
| 147 return NULL; | |
| 148 if (!WmShell::Get()->system_tray_delegate()->ShouldShowSettings()) | |
| 149 return NULL; | |
| 150 CHECK(default_view_ == NULL); | |
| 151 default_view_ = new tray::SettingsDefaultView(status); | |
| 152 return default_view_; | |
| 153 } | |
| 154 | |
| 155 views::View* TraySettings::CreateDetailedView(LoginStatus status) { | |
| 156 NOTIMPLEMENTED(); | |
| 157 return NULL; | |
| 158 } | |
| 159 | |
| 160 void TraySettings::DestroyTrayView() { | |
| 161 } | |
| 162 | |
| 163 void TraySettings::DestroyDefaultView() { | |
| 164 default_view_ = NULL; | |
| 165 } | |
| 166 | |
| 167 void TraySettings::DestroyDetailedView() { | |
| 168 } | |
| 169 | |
| 170 void TraySettings::UpdateAfterLoginStatusChange(LoginStatus status) {} | |
| 171 | |
| 172 } // namespace ash | |
| OLD | NEW |