| OLD | NEW |
| 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/views/first_run_search_engine_view.h" | 5 #include "chrome/browser/views/first_run_search_engine_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 146 |
| 147 // We only watch the search engine model change once, on load. Remove | 147 // We only watch the search engine model change once, on load. Remove |
| 148 // observer so we don't try to redraw if engines change under us. | 148 // observer so we don't try to redraw if engines change under us. |
| 149 search_engines_model_->RemoveObserver(this); | 149 search_engines_model_->RemoveObserver(this); |
| 150 | 150 |
| 151 // Add search engines in search_engines_model_ to buttons list. The | 151 // Add search engines in search_engines_model_ to buttons list. The |
| 152 // first three will always be from prepopulated data. | 152 // first three will always be from prepopulated data. |
| 153 std::vector<const TemplateURL*> template_urls = | 153 std::vector<const TemplateURL*> template_urls = |
| 154 search_engines_model_->GetTemplateURLs(); | 154 search_engines_model_->GetTemplateURLs(); |
| 155 | 155 |
| 156 // If we have fewer than three search engines, signal that the search engine | 156 // If we have fewer than two search engines, end search engine dialog |
| 157 // experiment is over, leaving imported default search engine setting intact. | 157 // immediately, leaving imported default search engine setting intact. |
| 158 if (template_urls.size() < 3) | 158 if (template_urls.size() < 2) { |
| 159 MessageLoop::current()->Quit(); |
| 159 return; | 160 return; |
| 161 } |
| 160 | 162 |
| 161 std::vector<const TemplateURL*>::iterator search_engine_iter; | 163 std::vector<const TemplateURL*>::iterator search_engine_iter; |
| 162 | 164 |
| 163 // Is user's default search engine included in first three prepopulated | 165 // Is user's default search engine included in first three prepopulated |
| 164 // set? If not, we need to expand the dialog to include a fourth engine. | 166 // set? If not, we need to expand the dialog to include a fourth engine. |
| 165 const TemplateURL* default_search_engine = | 167 const TemplateURL* default_search_engine = |
| 166 search_engines_model_->GetDefaultSearchProvider(); | 168 search_engines_model_->GetDefaultSearchProvider(); |
| 167 // If the user's default choice is not in the first three search engines | 169 // If the user's default choice is not in the first three search engines |
| 168 // in template_urls, store it in |default_choice| and provide it as a | 170 // in template_urls, store it in |default_choice| and provide it as a |
| 169 // fourth option. | 171 // fourth option. |
| 170 SearchEngineChoice* default_choice = NULL; | 172 SearchEngineChoice* default_choice = NULL; |
| 171 | 173 |
| 172 // First, see if we have 4 logos to show (in which case we use small logos). | 174 // First, see if we have 4 logos to show (in which case we use small logos). |
| 173 // We show 4 logos when the default search engine the user has chosen is | 175 // We show 4 logos when the default search engine the user has chosen is |
| 174 // not one of the first three prepopulated engines. | 176 // not one of the first three prepopulated engines. |
| 175 if (template_urls.size() > 3) { | 177 if (template_urls.size() > 3) { |
| 176 for (search_engine_iter = template_urls.begin() + 3; | 178 for (search_engine_iter = template_urls.begin() + 3; |
| 177 search_engine_iter != template_urls.end(); | 179 search_engine_iter != template_urls.end(); |
| 178 ++search_engine_iter) { | 180 ++search_engine_iter) { |
| 179 if (default_search_engine == *search_engine_iter) { | 181 if (default_search_engine == *search_engine_iter) { |
| 180 default_choice = new SearchEngineChoice(this, *search_engine_iter, | 182 default_choice = new SearchEngineChoice(this, *search_engine_iter, |
| 181 true); | 183 true); |
| 182 } | 184 } |
| 183 } | 185 } |
| 184 } | 186 } |
| 185 | 187 |
| 186 // Now that we know what size the logos should be, create new search engine | 188 // Now that we know what size the logos should be, create new search engine |
| 187 // choices for the view: | 189 // choices for the view. If there are 2 search engines, only show 2 |
| 190 // choices; for 3 or more, show 3 (unless the default is not one of the |
| 191 // top 3, in which case show 4). |
| 188 for (search_engine_iter = template_urls.begin(); | 192 for (search_engine_iter = template_urls.begin(); |
| 189 search_engine_iter < template_urls.begin() + 3; | 193 search_engine_iter < template_urls.begin() + |
| 194 (template_urls.size() < 3 ? 2 : 3); |
| 190 ++search_engine_iter) { | 195 ++search_engine_iter) { |
| 191 // Push first three engines into buttons: | 196 // Push first three engines into buttons: |
| 192 SearchEngineChoice* choice = new SearchEngineChoice(this, | 197 SearchEngineChoice* choice = new SearchEngineChoice(this, |
| 193 *search_engine_iter, default_choice != NULL); | 198 *search_engine_iter, default_choice != NULL); |
| 194 search_engine_choices_.push_back(choice); | 199 search_engine_choices_.push_back(choice); |
| 195 AddChildView(choice->GetView()); // The logo or text view. | 200 AddChildView(choice->GetView()); // The logo or text view. |
| 196 AddChildView(choice); // The button associated with the choice. | 201 AddChildView(choice); // The button associated with the choice. |
| 197 } | 202 } |
| 198 // Push the default choice to the fourth position. | 203 // Push the default choice to the fourth position. |
| 199 if (default_choice) { | 204 if (default_choice) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 kPanelHorizMargin + logo_padding, next_v_space, logo_width, | 333 kPanelHorizMargin + logo_padding, next_v_space, logo_width, |
| 329 logo_height); | 334 logo_height); |
| 330 | 335 |
| 331 int next_h_space = search_engine_choices_[0]->GetView()->x() + | 336 int next_h_space = search_engine_choices_[0]->GetView()->x() + |
| 332 logo_width + logo_padding; | 337 logo_width + logo_padding; |
| 333 search_engine_choices_[1]->SetChoiceViewBounds( | 338 search_engine_choices_[1]->SetChoiceViewBounds( |
| 334 next_h_space, next_v_space, logo_width, logo_height); | 339 next_h_space, next_v_space, logo_width, logo_height); |
| 335 | 340 |
| 336 next_h_space = search_engine_choices_[1]->GetView()->x() + logo_width + | 341 next_h_space = search_engine_choices_[1]->GetView()->x() + logo_width + |
| 337 logo_padding; | 342 logo_padding; |
| 338 search_engine_choices_[2]->SetChoiceViewBounds( | 343 if (num_choices > 2) { |
| 339 next_h_space, next_v_space, logo_width, logo_height); | 344 search_engine_choices_[2]->SetChoiceViewBounds( |
| 345 next_h_space, next_v_space, logo_width, logo_height); |
| 346 } |
| 340 | 347 |
| 341 if (num_choices > 3) { | 348 if (num_choices > 3) { |
| 342 next_h_space = search_engine_choices_[2]->GetView()->x() + logo_width + | 349 next_h_space = search_engine_choices_[2]->GetView()->x() + logo_width + |
| 343 logo_padding; | 350 logo_padding; |
| 344 search_engine_choices_[3]->SetChoiceViewBounds( | 351 search_engine_choices_[3]->SetChoiceViewBounds( |
| 345 next_h_space, next_v_space, logo_width, logo_height); | 352 next_h_space, next_v_space, logo_width, logo_height); |
| 346 } | 353 } |
| 347 | 354 |
| 348 next_v_space = search_engine_choices_[0]->GetView()->y() + logo_height + | 355 next_v_space = search_engine_choices_[0]->GetView()->y() + logo_height + |
| 349 kVertSpacing; | 356 kVertSpacing; |
| 350 | 357 |
| 351 // The buttons for search engine selection: | 358 // The buttons for search engine selection: |
| 352 int button_padding = logo_padding + logo_width / 2 - button_width / 2; | 359 int button_padding = logo_padding + logo_width / 2 - button_width / 2; |
| 353 | 360 |
| 354 search_engine_choices_[0]->SetBounds(kPanelHorizMargin + button_padding, | 361 search_engine_choices_[0]->SetBounds(kPanelHorizMargin + button_padding, |
| 355 next_v_space, button_width, | 362 next_v_space, button_width, |
| 356 button_height); | 363 button_height); |
| 357 | 364 |
| 358 next_h_space = search_engine_choices_[0]->x() + logo_width + logo_padding; | 365 next_h_space = search_engine_choices_[0]->x() + logo_width + logo_padding; |
| 359 search_engine_choices_[1]->SetBounds(next_h_space, next_v_space, | 366 search_engine_choices_[1]->SetBounds(next_h_space, next_v_space, |
| 360 button_width, button_height); | 367 button_width, button_height); |
| 361 next_h_space = search_engine_choices_[1]->x() + logo_width + logo_padding; | 368 next_h_space = search_engine_choices_[1]->x() + logo_width + logo_padding; |
| 362 search_engine_choices_[2]->SetBounds(next_h_space, next_v_space, | 369 if (num_choices > 2) { |
| 363 button_width, button_height); | 370 search_engine_choices_[2]->SetBounds(next_h_space, next_v_space, |
| 371 button_width, button_height); |
| 372 } |
| 364 | 373 |
| 365 if (num_choices > 3) { | 374 if (num_choices > 3) { |
| 366 next_h_space = search_engine_choices_[2]->x() + logo_width + | 375 next_h_space = search_engine_choices_[2]->x() + logo_width + |
| 367 logo_padding; | 376 logo_padding; |
| 368 search_engine_choices_[3]->SetBounds(next_h_space, next_v_space, | 377 search_engine_choices_[3]->SetBounds(next_h_space, next_v_space, |
| 369 button_width, button_height); | 378 button_width, button_height); |
| 370 } | 379 } |
| 371 } // if (search_engine_choices.size() > 0) | 380 } // if (search_engine_choices.size() > 0) |
| 372 } | 381 } |
| 373 | 382 |
| 374 std::wstring FirstRunSearchEngineView::GetWindowTitle() const { | 383 std::wstring FirstRunSearchEngineView::GetWindowTitle() const { |
| 375 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE); | 384 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE); |
| 376 } | 385 } |
| OLD | NEW |