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