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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 177 } |
178 SetupControls(); | 178 SetupControls(); |
179 } | 179 } |
180 | 180 |
181 FirstRunSearchEngineView::~FirstRunSearchEngineView() { | 181 FirstRunSearchEngineView::~FirstRunSearchEngineView() { |
182 search_engines_model_->RemoveObserver(this); | 182 search_engines_model_->RemoveObserver(this); |
183 } | 183 } |
184 | 184 |
185 void FirstRunSearchEngineView::ButtonPressed(views::Button* sender, | 185 void FirstRunSearchEngineView::ButtonPressed(views::Button* sender, |
186 const views::Event& event) { | 186 const views::Event& event) { |
187 observer_->SearchEngineChosen( | 187 SearchEngineChoice* choice = static_cast<SearchEngineChoice*>(sender); |
188 static_cast<SearchEngineChoice*>(sender)->GetSearchEngine()); | 188 profile_->GetTemplateURLModel()->SetSearchEngineDialogSlot( |
| 189 choice->slot()); |
| 190 observer_->SearchEngineChosen(choice->GetSearchEngine()); |
189 } | 191 } |
190 | 192 |
191 void FirstRunSearchEngineView::OnTemplateURLModelChanged() { | 193 void FirstRunSearchEngineView::OnTemplateURLModelChanged() { |
192 using views::ImageView; | 194 using views::ImageView; |
193 | 195 |
194 // We only watch the search engine model change once, on load. Remove | 196 // We only watch the search engine model change once, on load. Remove |
195 // observer so we don't try to redraw if engines change under us. | 197 // observer so we don't try to redraw if engines change under us. |
196 search_engines_model_->RemoveObserver(this); | 198 search_engines_model_->RemoveObserver(this); |
197 | 199 |
198 // Add search engines in search_engines_model_ to buttons list. The | 200 // Add search engines in search_engines_model_ to buttons list. The |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 AddChildView(default_choice->GetView()); // The logo or text view. | 252 AddChildView(default_choice->GetView()); // The logo or text view. |
251 AddChildView(default_choice); // The button associated with the choice. | 253 AddChildView(default_choice); // The button associated with the choice. |
252 } | 254 } |
253 | 255 |
254 // Randomize order of logos if option has been set. | 256 // Randomize order of logos if option has been set. |
255 if (randomize_) { | 257 if (randomize_) { |
256 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 258 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
257 srand(seed); | 259 srand(seed); |
258 std::random_shuffle(search_engine_choices_.begin(), | 260 std::random_shuffle(search_engine_choices_.begin(), |
259 search_engine_choices_.end()); | 261 search_engine_choices_.end()); |
| 262 // Assign to each choice the position in which it is shown on the screen. |
| 263 std::vector<SearchEngineChoice*>::iterator it; |
| 264 int slot = 0; |
| 265 for (it = search_engine_choices_.begin(); |
| 266 it != search_engine_choices_.end(); |
| 267 it++) { |
| 268 (*it)->set_slot(slot++); |
| 269 } |
260 } | 270 } |
261 | 271 |
262 // Now that we know how many logos to show, lay out and become visible. | 272 // Now that we know how many logos to show, lay out and become visible. |
263 SetVisible(true); | 273 SetVisible(true); |
264 Layout(); | 274 Layout(); |
265 SchedulePaint(); | 275 SchedulePaint(); |
266 } | 276 } |
267 | 277 |
268 gfx::Size FirstRunSearchEngineView::GetPreferredSize() { | 278 gfx::Size FirstRunSearchEngineView::GetPreferredSize() { |
269 return views::Window::GetLocalizedContentsSize( | 279 return views::Window::GetLocalizedContentsSize( |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 logo_padding; | 418 logo_padding; |
409 search_engine_choices_[3]->SetBounds(next_h_space, next_v_space, | 419 search_engine_choices_[3]->SetBounds(next_h_space, next_v_space, |
410 button_width, button_height); | 420 button_width, button_height); |
411 } | 421 } |
412 } // if (search_engine_choices.size() > 0) | 422 } // if (search_engine_choices.size() > 0) |
413 } | 423 } |
414 | 424 |
415 std::wstring FirstRunSearchEngineView::GetWindowTitle() const { | 425 std::wstring FirstRunSearchEngineView::GetWindowTitle() const { |
416 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE); | 426 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE); |
417 } | 427 } |
OLD | NEW |