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