Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Side by Side Diff: chrome/browser/chromeos/login/update_view.cc

Issue 8436002: [cros] Remove Views implementation for login/OOBE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "chrome/browser/chromeos/login/update_view.h"
6
7 #include <algorithm>
8 #include <string>
9
10 #include "base/logging.h"
11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/chromeos/login/helper.h"
13 #include "chrome/browser/chromeos/login/rounded_rect_painter.h"
14 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h"
15 #include "grit/chromium_strings.h"
16 #include "grit/generated_resources.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/color_utils.h"
20 #include "views/border.h"
21 #include "views/controls/label.h"
22 #include "views/controls/progress_bar.h"
23 #include "views/controls/throbber.h"
24 #include "views/focus/focus_manager.h"
25 #include "views/widget/widget.h"
26
27 using std::max;
28 using views::Background;
29 using views::Label;
30 using views::View;
31 using views::Widget;
32
33 namespace {
34
35 // TODO(nkostylev): Switch to GridLayout.
36
37 // Y offset for the 'installing updates' label.
38 const int kInstallingUpdatesLabelYBottomFromProgressBar = 18;
39 // Y offset for the progress bar.
40 const int kProgressBarY = 130;
41 // Y offset for the 'computer will restart' label.
42 const int kRebootLabelYFromProgressBar = 55;
43 // Y offset for the 'ESCAPE to skip' label.
44 const int kEscapeToSkipLabelY = 48;
45 // Progress bar width.
46 const int kProgressBarWidth = 420;
47 // Progress bar height.
48 const int kProgressBarHeight = 18;
49 // Horizontal spacing (ex. min left and right margins for label on the screen).
50 const int kHorizontalSpacing = 65;
51 // Horizontal spacing between spinner and label on the curtain screen.
52 const int kBetweenSpacing = 25;
53
54 // Label color.
55 const SkColor kLabelColor = 0xFF000000;
56 const SkColor kSkipLabelColor = 0xFFAA0000;
57 const SkColor kManualRebootLabelColor = 0xFFAA0000;
58
59 } // namespace
60
61 namespace chromeos {
62
63 UpdateView::UpdateView(chromeos::ScreenObserver* observer)
64 : installing_updates_label_(NULL),
65 preparing_updates_label_(NULL),
66 reboot_label_(NULL),
67 manual_reboot_label_(NULL),
68 progress_bar_(NULL),
69 show_curtain_(true),
70 show_manual_reboot_label_(false),
71 show_preparing_updates_label_(false),
72 observer_(observer) {
73 }
74
75 UpdateView::~UpdateView() {
76 }
77
78 void UpdateView::Init() {
79 // Use rounded-rect background.
80 views::Painter* painter = chromeos::CreateWizardPainter(
81 &chromeos::BorderDefinition::kScreenBorder);
82 set_background(views::Background::CreateBackgroundPainter(true, painter));
83 SkColor background_color = color_utils::AlphaBlend(
84 BorderDefinition::kScreenBorder.top_color,
85 BorderDefinition::kScreenBorder.bottom_color, 128);
86
87 installing_updates_label_ = InitLabel(background_color);
88 preparing_updates_label_ = InitLabel(background_color);
89 preparing_updates_label_->SetVisible(false);
90 reboot_label_ = InitLabel(background_color);
91 manual_reboot_label_ = InitLabel(background_color);
92 manual_reboot_label_->SetVisible(false);
93 manual_reboot_label_->SetEnabledColor(kManualRebootLabelColor);
94
95 progress_bar_ = new views::ProgressBar();
96 AddChildView(progress_bar_);
97 progress_bar_->SetDisplayRange(0.0, 100.0);
98
99 // Curtain view.
100 checking_label_ = InitLabel(background_color);
101 throbber_ = CreateDefaultThrobber();
102 AddChildView(throbber_);
103
104 #if !defined(OFFICIAL_BUILD)
105 escape_to_skip_label_ = InitLabel(background_color);
106 escape_to_skip_label_->SetEnabledColor(kSkipLabelColor);
107 escape_to_skip_label_->SetText(
108 ASCIIToUTF16("Press ESCAPE to skip (Non-official builds only)"));
109 #endif
110
111 UpdateLocalizedStrings();
112 UpdateVisibility();
113 }
114
115 void UpdateView::Reset() {
116 progress_bar_->SetValue(0.0);
117 }
118
119 void UpdateView::UpdateLocalizedStrings() {
120 installing_updates_label_->SetText(l10n_util::GetStringFUTF16(
121 IDS_INSTALLING_UPDATE,
122 l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME)));
123 preparing_updates_label_->SetText(
124 l10n_util::GetStringUTF16(IDS_UPDATE_AVAILABLE));
125 reboot_label_->SetText(
126 l10n_util::GetStringUTF16(IDS_INSTALLING_UPDATE_DESC));
127 manual_reboot_label_->SetText(
128 l10n_util::GetStringUTF16(IDS_UPDATE_COMPLETED));
129 checking_label_->SetText(
130 l10n_util::GetStringUTF16(IDS_CHECKING_FOR_UPDATES));
131 }
132
133 void UpdateView::AddProgress(int ticks) {
134 progress_bar_->SetValue(
135 max(progress_bar_->current_value() + ticks, 100.0));
136 }
137
138 void UpdateView::SetProgress(int progress) {
139 progress_bar_->SetValue(progress);
140 }
141
142 void UpdateView::ShowManualRebootInfo() {
143 show_manual_reboot_label_ = true;
144 UpdateVisibility();
145 }
146
147 void UpdateView::ShowPreparingUpdatesInfo(bool visible) {
148 show_preparing_updates_label_ = visible;
149 UpdateVisibility();
150 }
151
152 void UpdateView::ShowCurtain(bool show_curtain) {
153 if (show_curtain_ != show_curtain) {
154 show_curtain_ = show_curtain;
155 UpdateVisibility();
156 }
157 }
158
159 // Sets the bounds of the view, placing center of the view at the given
160 // coordinates (|x| and |y|).
161 static void setViewBounds(views::View* view, int x, int y) {
162 int preferred_width = view->GetPreferredSize().width();
163 int preferred_height = view->GetPreferredSize().height();
164 view->SetBounds(
165 x - preferred_width / 2,
166 y - preferred_height / 2,
167 preferred_width,
168 preferred_height);
169 }
170
171 void UpdateView::Layout() {
172 int max_width = width() - GetInsets().width() - 2 * kHorizontalSpacing;
173 int right_margin = GetInsets().right() + kHorizontalSpacing;
174 int max_height = height() - GetInsets().height();
175 int vertical_center = GetInsets().top() + max_height / 2;
176
177 installing_updates_label_->SizeToFit(max_width);
178 preparing_updates_label_->SizeToFit(max_width);
179 reboot_label_->SizeToFit(max_width);
180 manual_reboot_label_->SizeToFit(max_width);
181
182 progress_bar_->SetBounds(right_margin,
183 vertical_center - kProgressBarHeight / 2,
184 max_width,
185 kProgressBarHeight);
186
187 installing_updates_label_->SetX(right_margin);
188 installing_updates_label_->SetY(
189 progress_bar_->y() -
190 kInstallingUpdatesLabelYBottomFromProgressBar -
191 installing_updates_label_->height());
192 preparing_updates_label_->SetX(installing_updates_label_->x());
193 preparing_updates_label_->SetY(installing_updates_label_->y());
194 reboot_label_->SetX(right_margin);
195 reboot_label_->SetY(
196 progress_bar_->y() +
197 progress_bar_->height() +
198 kRebootLabelYFromProgressBar);
199 manual_reboot_label_->SetX(reboot_label_->x());
200 manual_reboot_label_->SetY(reboot_label_->y());
201 // Curtain layout is independed.
202 int x_center = width() / 2;
203 int throbber_width = throbber_->GetPreferredSize().width();
204 checking_label_->SizeToFit(max_width - throbber_width - kBetweenSpacing);
205 int checking_label_width = checking_label_->GetPreferredSize().width();
206 int space_half = (kBetweenSpacing + 1) / 2;
207 setViewBounds(
208 throbber_, x_center - checking_label_width / 2 - space_half,
209 vertical_center);
210 setViewBounds(
211 checking_label_, x_center + (throbber_width + 1) / 2 + space_half,
212 vertical_center);
213 #if !defined(OFFICIAL_BUILD)
214 escape_to_skip_label_->SizeToFit(max_width);
215 escape_to_skip_label_->SetX(right_margin);
216 escape_to_skip_label_->SetY(kEscapeToSkipLabelY);
217 #endif
218 SchedulePaint();
219 }
220
221 views::Label* UpdateView::InitLabel(SkColor background_color) {
222 views::Label* label = new views::Label();
223 label->SetBackgroundColor(background_color);
224 label->SetEnabledColor(kLabelColor);
225 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
226 label->SetMultiLine(true);
227
228 ResourceBundle& res_bundle = ResourceBundle::GetSharedInstance();
229 gfx::Font label_font = res_bundle.GetFont(ResourceBundle::MediumFont);
230 label->SetFont(label_font);
231
232 AddChildView(label);
233 return label;
234 }
235
236 void UpdateView::UpdateVisibility() {
237 installing_updates_label_->SetVisible(!show_curtain_ &&
238 !show_manual_reboot_label_ &&
239 !show_preparing_updates_label_);
240 preparing_updates_label_->SetVisible(!show_curtain_ &&
241 !show_manual_reboot_label_ &&
242 show_preparing_updates_label_);
243 reboot_label_->SetVisible(!show_curtain_&& !show_manual_reboot_label_);
244 manual_reboot_label_->SetVisible(!show_curtain_ && show_manual_reboot_label_);
245 progress_bar_->SetVisible(!show_curtain_);
246
247 checking_label_->SetVisible(show_curtain_);
248 throbber_->SetVisible(show_curtain_);
249 if (show_curtain_) {
250 throbber_->Start();
251 } else {
252 throbber_->Stop();
253 }
254
255 // Speak the shown label when accessibility is enabled.
256 const Label* label_spoken(NULL);
257 if (checking_label_->IsVisible()) {
258 label_spoken = checking_label_;
259 } else if (manual_reboot_label_->IsVisible()) {
260 label_spoken = manual_reboot_label_;
261 } else if (preparing_updates_label_->IsVisible()) {
262 label_spoken = preparing_updates_label_;
263 } else if (installing_updates_label_->IsVisible()) {
264 label_spoken = installing_updates_label_;
265 } else {
266 NOTREACHED();
267 }
268 const std::string text =
269 label_spoken ? UTF16ToUTF8(label_spoken->GetText()) : std::string();
270 WizardAccessibilityHelper::GetInstance()->MaybeSpeak(text.c_str(), false,
271 true);
272 }
273
274 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/update_view.h ('k') | chrome/browser/chromeos/login/user_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698