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

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

Issue 2808006: Allow randomized search engines in selection dialog.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 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
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/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 <map> 8 #include <map>
8 9
9 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 11 #include "app/resource_bundle.h"
11 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/time.h"
12 #include "chrome/browser/options_window.h" 14 #include "chrome/browser/options_window.h"
13 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
14 #include "chrome/browser/search_engines/template_url.h" 16 #include "chrome/browser/search_engines/template_url.h"
15 #include "chrome/browser/search_engines/template_url_model.h" 17 #include "chrome/browser/search_engines/template_url_model.h"
16 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 18 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
17 #include "gfx/font.h" 19 #include "gfx/font.h"
18 #include "grit/browser_resources.h" 20 #include "grit/browser_resources.h"
19 #include "grit/chromium_strings.h" 21 #include "grit/chromium_strings.h"
20 #include "grit/google_chrome_strings.h" 22 #include "grit/google_chrome_strings.h"
21 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
22 #include "grit/locale_settings.h" 24 #include "grit/locale_settings.h"
23 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
24 #include "views/controls/button/button.h" 26 #include "views/controls/button/button.h"
25 #include "views/controls/image_view.h" 27 #include "views/controls/image_view.h"
26 #include "views/controls/label.h" 28 #include "views/controls/label.h"
27 #include "views/controls/separator.h" 29 #include "views/controls/separator.h"
28 #include "views/standard_layout.h" 30 #include "views/standard_layout.h"
29 #include "views/view_text_utils.h" 31 #include "views/view_text_utils.h"
30 #include "views/window/window.h" 32 #include "views/window/window.h"
31 33
34 using base::Time;
32 using TemplateURLPrepopulateData::SearchEngineType; 35 using TemplateURLPrepopulateData::SearchEngineType;
33 36
34 namespace { 37 namespace {
35 38
36 // These strings mark the embedded link in IDS_FIRSTRUN_SEARCH_SUBTEXT. 39 // These strings mark the embedded link in IDS_FIRSTRUN_SEARCH_SUBTEXT.
37 const wchar_t* kBeginLink = L"BEGIN_LINK_SE"; 40 const wchar_t* kBeginLink = L"BEGIN_LINK_SE";
38 const wchar_t* kEndLink = L"END_LINK_SE"; 41 const wchar_t* kEndLink = L"END_LINK_SE";
39 42
40 // Represents an id for which we have no logo. 43 // Represents an id for which we have no logo.
41 const int kNoLogo = -1; 44 const int kNoLogo = -1;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return choice_view_->GetPreferredSize().height(); 152 return choice_view_->GetPreferredSize().height();
150 } 153 }
151 } 154 }
152 155
153 void SearchEngineChoice::SetChoiceViewBounds(int x, int y, int width, 156 void SearchEngineChoice::SetChoiceViewBounds(int x, int y, int width,
154 int height) { 157 int height) {
155 choice_view_->SetBounds(x, y, width, height); 158 choice_view_->SetBounds(x, y, width, height);
156 } 159 }
157 160
158 FirstRunSearchEngineView::FirstRunSearchEngineView( 161 FirstRunSearchEngineView::FirstRunSearchEngineView(
159 SearchEngineSelectionObserver* observer, Profile* profile) 162 SearchEngineSelectionObserver* observer, Profile* profile, bool randomize)
160 : profile_(profile), 163 : profile_(profile),
161 observer_(observer), 164 observer_(observer),
162 text_direction_is_rtl_(base::i18n::IsRTL()) { 165 text_direction_is_rtl_(base::i18n::IsRTL()),
166 randomize_(randomize) {
163 DCHECK(observer); 167 DCHECK(observer);
164 // Don't show ourselves until all the search engines have loaded from 168 // Don't show ourselves until all the search engines have loaded from
165 // the profile -- otherwise we have nothing to show. 169 // the profile -- otherwise we have nothing to show.
166 SetVisible(false); 170 SetVisible(false);
167 171
168 // Start loading the search engines for the given profile. 172 // Start loading the search engines for the given profile.
169 search_engines_model_ = profile_->GetTemplateURLModel(); 173 search_engines_model_ = profile_->GetTemplateURLModel();
170 if (search_engines_model_) { 174 if (search_engines_model_) {
171 DCHECK(!search_engines_model_->loaded()); 175 DCHECK(!search_engines_model_->loaded());
172 search_engines_model_->AddObserver(this); 176 search_engines_model_->AddObserver(this);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 AddChildView(choice->GetView()); // The logo or text view. 247 AddChildView(choice->GetView()); // The logo or text view.
244 AddChildView(choice); // The button associated with the choice. 248 AddChildView(choice); // The button associated with the choice.
245 } 249 }
246 // Push the default choice to the fourth position. 250 // Push the default choice to the fourth position.
247 if (default_choice) { 251 if (default_choice) {
248 search_engine_choices_.push_back(default_choice); 252 search_engine_choices_.push_back(default_choice);
249 AddChildView(default_choice->GetView()); // The logo or text view. 253 AddChildView(default_choice->GetView()); // The logo or text view.
250 AddChildView(default_choice); // The button associated with the choice. 254 AddChildView(default_choice); // The button associated with the choice.
251 } 255 }
252 256
257 // Randomize order of logos if option has been set.
258 if (randomize_) {
259 int seed = static_cast<int>(Time::Now().ToInternalValue());
260 srand(seed);
261 std::random_shuffle(search_engine_choices_.begin(),
262 search_engine_choices_.end());
mattm 2010/06/16 00:20:26 I guess it's not really important for this usage,
Miranda Callahan 2010/06/16 15:30:00 Good idea -- I'll file a bug for it, but will let
263 }
264
253 // Now that we know how many logos to show, lay out and become visible. 265 // Now that we know how many logos to show, lay out and become visible.
254 SetVisible(true); 266 SetVisible(true);
255 Layout(); 267 Layout();
256 SchedulePaint(); 268 SchedulePaint();
257 } 269 }
258 270
259 gfx::Size FirstRunSearchEngineView::GetPreferredSize() { 271 gfx::Size FirstRunSearchEngineView::GetPreferredSize() {
260 return views::Window::GetLocalizedContentsSize( 272 return views::Window::GetLocalizedContentsSize(
261 IDS_FIRSTRUN_SEARCH_ENGINE_SELECTION_WIDTH_CHARS, 273 IDS_FIRSTRUN_SEARCH_ENGINE_SELECTION_WIDTH_CHARS,
262 IDS_FIRSTRUN_SEARCH_ENGINE_SELECTION_HEIGHT_LINES); 274 IDS_FIRSTRUN_SEARCH_ENGINE_SELECTION_HEIGHT_LINES);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 text_direction_is_rtl_, label_bounds, font); 485 text_direction_is_rtl_, label_bounds, font);
474 486
475 options_link_->SetBounds(link_rect.x(), link_rect.y(), link_rect.width(), 487 options_link_->SetBounds(link_rect.x(), link_rect.y(), link_rect.width(),
476 link_rect.height()); 488 link_rect.height());
477 } 489 }
478 490
479 std::wstring FirstRunSearchEngineView::GetWindowTitle() const { 491 std::wstring FirstRunSearchEngineView::GetWindowTitle() const {
480 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE); 492 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE);
481 } 493 }
482 494
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698