Chromium Code Reviews

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

Issue 2807013: Update screen refactoring, exit on successful update. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: merge Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « chrome/browser/chromeos/login/update_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/login/update_view.h" 5 #include "chrome/browser/chromeos/login/update_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
(...skipping 15 matching lines...)
26 namespace { 26 namespace {
27 27
28 // Y offset for the 'installing updates' label. 28 // Y offset for the 'installing updates' label.
29 const int kInstallingUpdatesLabelY = 200; 29 const int kInstallingUpdatesLabelY = 200;
30 // Y offset for the progress bar. 30 // Y offset for the progress bar.
31 const int kProgressBarY = 250; 31 const int kProgressBarY = 250;
32 // Y offset for the 'ESCAPE to skip' label. 32 // Y offset for the 'ESCAPE to skip' label.
33 const int kEscapeToSkipLabelY = 290; 33 const int kEscapeToSkipLabelY = 290;
34 // Progress bar width. 34 // Progress bar width.
35 const int kProgressBarWidth = 450; 35 const int kProgressBarWidth = 450;
36 // Horizontal spacing (ex. min left and right margins for label on the screen).
37 const int kHorizontalSpacing = 25;
36 38
37 // Label color. 39 // Label color.
38 const SkColor kLabelColor = 0xFF000000; 40 const SkColor kLabelColor = 0xFF000000;
39 const SkColor kSkipLabelColor = 0xFFAA0000; 41 const SkColor kSkipLabelColor = 0xFFAA0000;
40 42
41 } // namespace 43 } // namespace
42 44
43 namespace chromeos { 45 namespace chromeos {
44 46
45 UpdateView::UpdateView(chromeos::ScreenObserver* observer) 47 UpdateView::UpdateView(chromeos::ScreenObserver* observer)
46 : escape_accelerator_(base::VKEY_ESCAPE, false, false, false), 48 : escape_accelerator_(base::VKEY_ESCAPE, false, false, false),
47 installing_updates_label_(NULL), 49 installing_updates_label_(NULL),
48 progress_bar_(NULL), 50 progress_bar_(NULL),
49 observer_(observer) { 51 observer_(observer) {
50 } 52 }
51 53
52 UpdateView::~UpdateView() { 54 UpdateView::~UpdateView() {
53 } 55 }
54 56
55 void UpdateView::Init() { 57 void UpdateView::Init() {
56 // Use rounded-rect background. 58 // Use rounded-rect background.
57 views::Painter* painter = chromeos::CreateWizardPainter( 59 views::Painter* painter = chromeos::CreateWizardPainter(
58 &chromeos::BorderDefinition::kScreenBorder); 60 &chromeos::BorderDefinition::kScreenBorder);
59 set_background(views::Background::CreateBackgroundPainter(true, painter)); 61 set_background(views::Background::CreateBackgroundPainter(true, painter));
60 62
61 ResourceBundle& res_bundle = ResourceBundle::GetSharedInstance(); 63 ResourceBundle& res_bundle = ResourceBundle::GetSharedInstance();
62 gfx::Font base_font = res_bundle.GetFont(ResourceBundle::BaseFont); 64 gfx::Font base_font = res_bundle.GetFont(ResourceBundle::BaseFont);
63 65
64 installing_updates_label_ = new views::Label(); 66 InitLabel(&installing_updates_label_);
65 installing_updates_label_->SetColor(kLabelColor);
66 installing_updates_label_->SetFont(base_font); 67 installing_updates_label_->SetFont(base_font);
67 installing_updates_label_->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
68 installing_updates_label_->SetMultiLine(true);
69 68
70 progress_bar_ = new views::ProgressBar(); 69 progress_bar_ = new views::ProgressBar();
70 AddChildView(progress_bar_);
71 71
72 UpdateLocalizedStrings(); 72 UpdateLocalizedStrings();
73 AddChildView(installing_updates_label_);
74 AddChildView(progress_bar_);
75 73
76 #if !defined(OFFICIAL_BUILD) 74 #if !defined(OFFICIAL_BUILD)
77 escape_to_skip_label_ = new views::Label(); 75 escape_to_skip_label_ = new views::Label();
78 escape_to_skip_label_->SetColor(kSkipLabelColor); 76 escape_to_skip_label_->SetColor(kSkipLabelColor);
79 escape_to_skip_label_->SetFont(base_font); 77 escape_to_skip_label_->SetFont(base_font);
80 escape_to_skip_label_->SetText( 78 escape_to_skip_label_->SetText(
81 L"Press ESCAPE to skip (Non-official builds only)"); 79 L"Press ESCAPE to skip (Non-official builds only)");
82 AddChildView(escape_to_skip_label_); 80 AddChildView(escape_to_skip_label_);
83 #endif 81 #endif
84 } 82 }
85 83
86 void UpdateView::Reset() { 84 void UpdateView::Reset() {
87 progress_bar_->SetProgress(0); 85 progress_bar_->SetProgress(0);
88 #if !defined(OFFICIAL_BUILD) 86 #if !defined(OFFICIAL_BUILD)
89 AddAccelerator(escape_accelerator_); 87 AddAccelerator(escape_accelerator_);
90 #endif 88 #endif
91 } 89 }
92 90
93 void UpdateView::UpdateLocalizedStrings() { 91 void UpdateView::UpdateLocalizedStrings() {
94 installing_updates_label_->SetText( 92 installing_updates_label_->SetText(
95 l10n_util::GetStringF(IDS_INSTALLING_UPDATE, 93 l10n_util::GetStringF(IDS_INSTALLING_UPDATE,
96 l10n_util::GetString(IDS_PRODUCT_OS_NAME))); 94 l10n_util::GetString(IDS_PRODUCT_OS_NAME)));
97 } 95 }
98 96
99 void UpdateView::AddProgress(int ticks) { 97 void UpdateView::AddProgress(int ticks) {
100 progress_bar_->AddProgress(ticks); 98 progress_bar_->AddProgress(ticks);
101 } 99 }
102 100
101 // Sets the bounds of the view, placing it at the center of the screen
102 // with the |y| coordinate provided. |width| could specify desired view width
103 // otherwise preferred width/height are used.
104 // |x_center| specifies screen center.
105 static void setViewBounds(
106 views::View* view, int x_center, int y, int width = -1) {
107 int preferred_width = (width >= 0) ? width : view->GetPreferredSize().width();
108 int preferred_height = view->GetPreferredSize().height();
109 view->SetBounds(
110 x_center - preferred_width / 2,
111 y,
112 preferred_width,
113 preferred_height);
114 }
115
103 void UpdateView::Layout() { 116 void UpdateView::Layout() {
104 int x_center = width() / 2; 117 int x_center = width() / 2;
105 int preferred_width = installing_updates_label_->GetPreferredSize().width(); 118 int max_width = width() - GetInsets().width() - 2 * kHorizontalSpacing;
106 int preferred_height = installing_updates_label_->GetPreferredSize().height(); 119 installing_updates_label_->SizeToFit(max_width);
107 installing_updates_label_->SetBounds( 120 setViewBounds(installing_updates_label_, x_center, kInstallingUpdatesLabelY);
108 x_center - preferred_width / 2, 121 setViewBounds(progress_bar_, x_center, kProgressBarY, kProgressBarWidth);
109 kInstallingUpdatesLabelY,
110 preferred_width,
111 preferred_height);
112 preferred_width = kProgressBarWidth;
113 preferred_height = progress_bar_->GetPreferredSize().height();
114 progress_bar_->SetBounds(
115 x_center - preferred_width / 2,
116 kProgressBarY,
117 preferred_width,
118 preferred_height);
119 #if !defined(OFFICIAL_BUILD) 122 #if !defined(OFFICIAL_BUILD)
120 preferred_width = escape_to_skip_label_->GetPreferredSize().width(); 123 setViewBounds(escape_to_skip_label_, x_center, kEscapeToSkipLabelY);
121 preferred_height = escape_to_skip_label_->GetPreferredSize().height();
122 escape_to_skip_label_->SetBounds(
123 x_center - preferred_width / 2,
124 kEscapeToSkipLabelY,
125 preferred_width,
126 preferred_height);
127 #endif 124 #endif
128 SchedulePaint(); 125 SchedulePaint();
129 } 126 }
130 127
131 bool UpdateView::AcceleratorPressed(const views::Accelerator& a) { 128 bool UpdateView::AcceleratorPressed(const views::Accelerator& a) {
132 #if !defined(OFFICIAL_BUILD) 129 #if !defined(OFFICIAL_BUILD)
133 RemoveAccelerator(escape_accelerator_); 130 RemoveAccelerator(escape_accelerator_);
134 if (a.GetKeyCode() == base::VKEY_ESCAPE) { 131 if (a.GetKeyCode() == base::VKEY_ESCAPE) {
135 if (controller_ != NULL) { 132 if (controller_ != NULL) {
136 controller_->CancelUpdate(); 133 controller_->CancelUpdate();
137 } 134 }
138 return true; 135 return true;
139 } 136 }
140 #endif 137 #endif
141 return false; 138 return false;
142 } 139 }
143 140
141 void UpdateView::InitLabel(views::Label** label) {
142 *label = new views::Label();
143 (*label)->SetColor(kLabelColor);
144 (*label)->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
145 (*label)->SetMultiLine(true);
146 AddChildView(*label);
147 }
148
144 } // namespace chromeos 149 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/update_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine