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

Side by Side Diff: chrome/browser/views/first_run_view_base.cc

Issue 2934011: New first run sequence for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Added support for control of all import via master_preferences Created 10 years, 5 months 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
« no previous file with comments | « chrome/browser/views/first_run_view_base.h ('k') | chrome/browser/views/keyword_editor_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/views/first_run_view_base.h"
6
7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h"
9 #include "base/command_line.h"
10 #include "base/path_service.h"
11 #include "base/thread.h"
12 #include "chrome/browser/browser_list.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/first_run.h"
15 #include "chrome/browser/importer/importer.h"
16 #include "chrome/browser/metrics/user_metrics.h"
17 #include "chrome/browser/pref_service.h"
18 #include "chrome/browser/shell_integration.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h"
21 #include "chrome/installer/util/browser_distribution.h"
22 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h"
24 #include "grit/theme_resources.h"
25 #include "views/background.h"
26 #include "views/controls/button/checkbox.h"
27 #include "views/controls/image_view.h"
28 #include "views/controls/label.h"
29 #include "views/controls/throbber.h"
30 #include "views/controls/separator.h"
31 #include "views/standard_layout.h"
32 #include "views/window/client_view.h"
33 #include "views/window/window.h"
34
35 FirstRunViewBase::FirstRunViewBase(Profile* profile, bool homepage_defined,
36 int import_items, int dont_import_items,
37 bool search_engine_experiment,
38 bool randomize_search_engine_experiment)
39 : preferred_width_(0),
40 background_image_(NULL),
41 separator_1_(NULL),
42 default_browser_(NULL),
43 non_default_browser_label_(NULL),
44 separator_2_(NULL),
45 importer_host_(NULL),
46 profile_(profile),
47 homepage_defined_(homepage_defined),
48 import_items_(import_items),
49 dont_import_items_(dont_import_items),
50 search_engine_experiment_(search_engine_experiment),
51 randomize_search_engine_experiment_(randomize_search_engine_experiment) {
52 DCHECK(profile);
53 SetupControls();
54 }
55
56 FirstRunViewBase::~FirstRunViewBase() {
57 FirstRun::SetShowFirstRunBubblePref(true);
58 FirstRun::SetShowWelcomePagePref();
59 }
60
61 void FirstRunViewBase::SetupControls() {
62 using views::Label;
63 using views::ImageView;
64 using views::Background;
65
66 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
67 background_image_ = new views::ImageView();
68 background_image_->SetImage(rb.GetBitmapNamed(IDR_WIZARD_ICON));
69 background_image_->SetHorizontalAlignment(ImageView::TRAILING);
70
71 int color = 0;
72 {
73 SkAutoLockPixels pixel_loc(background_image_->GetImage());
74 uint32_t* pixel = background_image_->GetImage().getAddr32(0, 0);
75 color = (0xff & (*pixel));
76 }
77 Background* bkg = Background::CreateSolidBackground(color, color, color);
78
79 // The bitmap we use as the background contains a clipped logo and therefore
80 // we can not automatically mirror it for RTL UIs by simply flipping it. This
81 // is why we load a different bitmap if the View is using a right-to-left UI
82 // layout.
83 //
84 // Note that we first load the LTR image and then replace it with the RTL
85 // image because the code above derives the background color from the LTR
86 // image so we have to use the LTR logo initially and then replace it with
87 // the RTL logo if we find out that we are running in a right-to-left locale.
88 if (base::i18n::IsRTL())
89 background_image_->SetImage(rb.GetBitmapNamed(IDR_WIZARD_ICON_RTL));
90
91 background_image_->set_background(bkg);
92 AddChildView(background_image_);
93
94 // The first separator marks the end of the image.
95 separator_1_ = new views::Separator;
96 AddChildView(separator_1_);
97
98 if (BrowserDistribution::GetDistribution()->CanSetAsDefault()) {
99 // The "make us default browser" check box.
100 default_browser_ = new views::Checkbox(
101 l10n_util::GetString(IDS_FR_CUSTOMIZE_DEFAULT_BROWSER));
102 default_browser_->SetMultiLine(true);
103 AddChildView(default_browser_);
104 default_browser_->set_listener(this);
105 } else {
106 non_default_browser_label_ = new Label(
107 l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_SXS,
108 l10n_util::GetString(IDS_PRODUCT_NAME)));
109 non_default_browser_label_->SetMultiLine(true);
110 non_default_browser_label_->SetHorizontalAlignment(
111 views::Label::ALIGN_LEFT);
112 AddChildView(non_default_browser_label_);
113 }
114
115 // The second separator marks the start of buttons.
116 separator_2_ = new views::Separator;
117 AddChildView(separator_2_);
118 }
119
120 void FirstRunViewBase::AdjustDialogWidth(const views::View* sub_view) {
121 gfx::Rect sub_view_bounds = sub_view->bounds();
122 preferred_width_ =
123 std::max(preferred_width_,
124 static_cast<int>(sub_view_bounds.right()) + kPanelHorizMargin);
125 }
126
127 void FirstRunViewBase::SetMinimumDialogWidth(int width) {
128 preferred_width_ = std::max(preferred_width_, width);
129 }
130
131 void FirstRunViewBase::Layout() {
132 const int kVertSpacing = 8;
133
134 gfx::Size canvas = GetPreferredSize();
135
136 gfx::Size pref_size = background_image_->GetPreferredSize();
137 background_image_->SetBounds(0, 0, canvas.width(), pref_size.height());
138
139 int next_v_space = background_image_->y() +
140 background_image_->height() - 2;
141
142 pref_size = separator_1_->GetPreferredSize();
143 separator_1_->SetBounds(0, next_v_space, canvas.width() + 1,
144 pref_size.height());
145
146 next_v_space = canvas.height() - kPanelSubVerticalSpacing - 2 * kVertSpacing;
147 pref_size = separator_2_->GetPreferredSize();
148 separator_2_->SetBounds(kPanelHorizMargin , next_v_space,
149 canvas.width() - 2 * kPanelHorizMargin,
150 pref_size.height());
151
152 next_v_space = separator_2_->y() + separator_2_->height() + kVertSpacing;
153
154 int width = canvas.width() - 2 * kPanelHorizMargin;
155 if (default_browser_) {
156 #if defined(OS_WIN)
157 // Add or remove a shield icon before calculating the button width.
158 // (If a button has a shield icon, Windows automatically adds the icon width
159 // to the button width.)
160 views::DialogClientView* client_view = GetDialogClientView();
161 if (client_view)
162 client_view->ok_button()->SetNeedElevation(default_browser_->checked());
163 #endif
164
165 int height = default_browser_->GetHeightForWidth(width);
166 default_browser_->SetBounds(kPanelHorizMargin, next_v_space, width, height);
167 AdjustDialogWidth(default_browser_);
168 } else {
169 int height = non_default_browser_label_->GetHeightForWidth(width);
170 non_default_browser_label_->SetBounds(kPanelHorizMargin, next_v_space,
171 width, height);
172 AdjustDialogWidth(non_default_browser_label_);
173 }
174 }
175
176 void FirstRunViewBase::ButtonPressed(views::Button* sender,
177 const views::Event& event) {
178 #if defined(OS_WIN)
179 if (default_browser_ && sender == default_browser_) {
180 // Update the elevation state of the "start chromium" button so we can add
181 // a shield icon when we need elevation.
182 views::DialogClientView* client_view = GetDialogClientView();
183 client_view->ok_button()->SetNeedElevation(default_browser_->checked());
184 }
185 #endif
186 }
187
188 bool FirstRunViewBase::CanResize() const {
189 return false;
190 }
191
192 bool FirstRunViewBase::CanMaximize() const {
193 return false;
194 }
195
196 bool FirstRunViewBase::IsAlwaysOnTop() const {
197 return false;
198 }
199
200 bool FirstRunViewBase::HasAlwaysOnTopMenu() const {
201 return false;
202 }
203
204 std::wstring FirstRunViewBase::GetDialogButtonLabel(
205 MessageBoxFlags::DialogButton button) const {
206 if (MessageBoxFlags::DIALOGBUTTON_OK == button)
207 return search_engine_experiment_ ?
208 l10n_util::GetString(IDS_ACCNAME_NEXT) :
209 l10n_util::GetString(IDS_FIRSTRUN_DLG_OK);
210 // The other buttons get the default text.
211 return std::wstring();
212 }
213
214 int FirstRunViewBase::GetImportItems() const {
215 // It is best to avoid importing cookies because there is a bug that make
216 // the process take way too much time among other issues. So for the time
217 // being we say: TODO(CPU): Bug 1196875
218 int items = import_items_;
219 if (!(dont_import_items_ & importer::HISTORY))
220 items = items | importer::HISTORY;
221 if (!(dont_import_items_ & importer::FAVORITES))
222 items = items | importer::FAVORITES;
223 if (!(dont_import_items_ & importer::PASSWORDS))
224 items = items | importer::PASSWORDS;
225 if (!(dont_import_items_ & importer::SEARCH_ENGINES))
226 items = items | importer::SEARCH_ENGINES;
227 if (!homepage_defined_)
228 items = items | importer::HOME_PAGE;
229 return items;
230 };
231
232 void FirstRunViewBase::DisableButtons() {
233 window()->EnableClose(false);
234 views::DialogClientView* dcv = GetDialogClientView();
235 dcv->ok_button()->SetEnabled(false);
236 dcv->cancel_button()->SetEnabled(false);
237 if (default_browser_)
238 default_browser_->SetEnabled(false);
239 }
240
241 bool FirstRunViewBase::CreateDesktopShortcut() {
242 return FirstRun::CreateChromeDesktopShortcut();
243 }
244
245 bool FirstRunViewBase::CreateQuickLaunchShortcut() {
246 return FirstRun::CreateChromeQuickLaunchShortcut();
247 }
248
249 bool FirstRunViewBase::SetDefaultBrowser() {
250 UserMetrics::RecordAction(UserMetricsAction("FirstRun_Do_DefBrowser"),
251 profile_);
252 return ShellIntegration::SetAsDefaultBrowser();
253 }
254
255 bool FirstRunViewBase::FirstRunComplete() {
256 return FirstRun::CreateSentinel();
257 }
OLDNEW
« no previous file with comments | « chrome/browser/views/first_run_view_base.h ('k') | chrome/browser/views/keyword_editor_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698