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" |
11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "chrome/browser/options_window.h" | 14 #include "chrome/browser/options_window.h" |
15 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
16 #include "chrome/browser/search_engines/template_url.h" | 16 #include "chrome/browser/search_engines/template_url.h" |
17 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 17 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 18 #include "gfx/canvas.h" |
18 #include "gfx/font.h" | 19 #include "gfx/font.h" |
19 #include "grit/browser_resources.h" | 20 #include "grit/browser_resources.h" |
20 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
21 #include "grit/google_chrome_strings.h" | 22 #include "grit/google_chrome_strings.h" |
22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
23 #include "grit/locale_settings.h" | 24 #include "grit/locale_settings.h" |
24 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
25 #include "views/controls/button/button.h" | 26 #include "views/controls/button/button.h" |
26 #include "views/controls/image_view.h" | 27 #include "views/controls/image_view.h" |
27 #include "views/controls/label.h" | 28 #include "views/controls/label.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 TemplateURLModel* template_url_model = profile_->GetTemplateURLModel(); | 136 TemplateURLModel* template_url_model = profile_->GetTemplateURLModel(); |
136 DCHECK(template_url_model); | 137 DCHECK(template_url_model); |
137 template_url_model->SetSearchEngineDialogSlot(choice->slot()); | 138 template_url_model->SetSearchEngineDialogSlot(choice->slot()); |
138 const TemplateURL* default_search = choice->GetSearchEngine(); | 139 const TemplateURL* default_search = choice->GetSearchEngine(); |
139 if (default_search) | 140 if (default_search) |
140 template_url_model->SetDefaultSearchProvider(default_search); | 141 template_url_model->SetDefaultSearchProvider(default_search); |
141 | 142 |
142 MessageLoop::current()->Quit(); | 143 MessageLoop::current()->Quit(); |
143 } | 144 } |
144 | 145 |
| 146 void FirstRunSearchEngineView::Paint(gfx::Canvas* canvas) { |
| 147 // Fill in behind the background image with the standard gray toolbar color. |
| 148 canvas->FillRectInt(SkColorSetRGB(237, 238, 237), 0, 0, width(), |
| 149 background_image_->height()); |
| 150 // The rest of the dialog background should be white. |
| 151 DCHECK(height() > background_image_->height()); |
| 152 canvas->FillRectInt(SK_ColorWHITE, 0, background_image_->height(), width(), |
| 153 height() - background_image_->height()); |
| 154 } |
| 155 |
145 void FirstRunSearchEngineView::OnTemplateURLModelChanged() { | 156 void FirstRunSearchEngineView::OnTemplateURLModelChanged() { |
146 using views::ImageView; | 157 using views::ImageView; |
147 | 158 |
148 // We only watch the search engine model change once, on load. Remove | 159 // We only watch the search engine model change once, on load. Remove |
149 // observer so we don't try to redraw if engines change under us. | 160 // observer so we don't try to redraw if engines change under us. |
150 search_engines_model_->RemoveObserver(this); | 161 search_engines_model_->RemoveObserver(this); |
151 | 162 |
152 // Add search engines in search_engines_model_ to buttons list. The | 163 // Add search engines in search_engines_model_ to buttons list. The |
153 // first three will always be from prepopulated data. | 164 // first three will always be from prepopulated data. |
154 std::vector<const TemplateURL*> template_urls = | 165 std::vector<const TemplateURL*> template_urls = |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 248 } |
238 | 249 |
239 void FirstRunSearchEngineView::SetupControls() { | 250 void FirstRunSearchEngineView::SetupControls() { |
240 using views::Background; | 251 using views::Background; |
241 using views::ImageView; | 252 using views::ImageView; |
242 using views::Label; | 253 using views::Label; |
243 using views::NativeButton; | 254 using views::NativeButton; |
244 | 255 |
245 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 256 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
246 background_image_ = new views::ImageView(); | 257 background_image_ = new views::ImageView(); |
| 258 background_image_->SetImage(rb.GetBitmapNamed(IDR_SEARCH_ENGINE_DIALOG_TOP)); |
| 259 background_image_->EnableCanvasFlippingForRTLUI(true); |
247 if (text_direction_is_rtl_) { | 260 if (text_direction_is_rtl_) { |
248 background_image_->SetImage(rb.GetBitmapNamed( | 261 background_image_->SetHorizontalAlignment(ImageView::LEADING); |
249 IDR_SEARCH_ENGINE_DIALOG_TOP_RTL)); | |
250 } else { | 262 } else { |
251 background_image_->SetImage(rb.GetBitmapNamed( | 263 background_image_->SetHorizontalAlignment(ImageView::TRAILING); |
252 IDR_SEARCH_ENGINE_DIALOG_TOP)); | |
253 } | 264 } |
254 background_image_->SetHorizontalAlignment(ImageView::TRAILING); | 265 |
255 AddChildView(background_image_); | 266 AddChildView(background_image_); |
256 | 267 |
257 int label_width = GetPreferredSize().width() - 2 * kPanelHorizMargin; | 268 int label_width = GetPreferredSize().width() - 2 * kPanelHorizMargin; |
258 | 269 |
259 set_background(Background::CreateSolidBackground(SK_ColorWHITE)); | |
260 | |
261 // Add title and text asking the user to choose a search engine: | 270 // Add title and text asking the user to choose a search engine: |
262 title_label_ = new Label(l10n_util::GetString( | 271 title_label_ = new Label(l10n_util::GetString( |
263 IDS_FR_SEARCH_MAIN_LABEL)); | 272 IDS_FR_SEARCH_MAIN_LABEL)); |
264 title_label_->SetColor(SK_ColorBLACK); | 273 title_label_->SetColor(SK_ColorBLACK); |
265 title_label_->SetFont(title_label_->font().DeriveFont(3, gfx::Font::BOLD)); | 274 title_label_->SetFont(title_label_->font().DeriveFont(3, gfx::Font::BOLD)); |
266 title_label_->SetMultiLine(true); | 275 title_label_->SetMultiLine(true); |
267 title_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); | 276 title_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); |
268 title_label_->SizeToFit(label_width); | 277 title_label_->SizeToFit(label_width); |
269 AddChildView(title_label_); | 278 AddChildView(title_label_); |
270 | 279 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 logo_padding; | 392 logo_padding; |
384 search_engine_choices_[3]->SetBounds(next_h_space, next_v_space, | 393 search_engine_choices_[3]->SetBounds(next_h_space, next_v_space, |
385 button_width, button_height); | 394 button_width, button_height); |
386 } | 395 } |
387 } // if (search_engine_choices.size() > 0) | 396 } // if (search_engine_choices.size() > 0) |
388 } | 397 } |
389 | 398 |
390 std::wstring FirstRunSearchEngineView::GetWindowTitle() const { | 399 std::wstring FirstRunSearchEngineView::GetWindowTitle() const { |
391 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE); | 400 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE); |
392 } | 401 } |
OLD | NEW |