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

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

Issue 8870007: Merge 113149 - Reland 112770, but with test disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/963/src/
Patch Set: Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/views/first_run_search_engine_view.h" 5 #include "chrome/browser/ui/views/first_run_search_engine_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 133 }
134 } 134 }
135 135
136 void SearchEngineChoice::SetChoiceViewBounds(int x, int y, int width, 136 void SearchEngineChoice::SetChoiceViewBounds(int x, int y, int width,
137 int height) { 137 int height) {
138 choice_view_->SetBounds(x, y, width, height); 138 choice_view_->SetBounds(x, y, width, height);
139 } 139 }
140 140
141 FirstRunSearchEngineView::FirstRunSearchEngineView(Profile* profile, 141 FirstRunSearchEngineView::FirstRunSearchEngineView(Profile* profile,
142 bool randomize) 142 bool randomize)
143 : background_image_(NULL), 143 : views::ClientView(NULL, NULL),
144 background_image_(NULL),
144 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)), 145 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)),
145 text_direction_is_rtl_(base::i18n::IsRTL()), 146 text_direction_is_rtl_(base::i18n::IsRTL()),
146 added_to_view_hierarchy_(false), 147 added_to_view_hierarchy_(false),
147 randomize_(randomize), 148 randomize_(randomize),
148 user_chosen_engine_(false), 149 user_chosen_engine_(false),
149 fallback_choice_(NULL), 150 fallback_choice_(NULL),
150 quit_on_closing_(true) { 151 quit_on_closing_(true) {
151 // Don't show ourselves until all the search engines have loaded from 152 // Don't show ourselves until all the search engines have loaded from
152 // the profile -- otherwise we have nothing to show. 153 // the profile -- otherwise we have nothing to show.
153 SetVisible(false); 154 SetVisible(false);
154 155
155 // Start loading the search engines for the given profile. The service is 156 // Start loading the search engines for the given profile. The service is
156 // already loaded in tests. 157 // already loaded in tests.
157 DCHECK(template_url_service_); 158 DCHECK(template_url_service_);
158 if (!template_url_service_->loaded()) { 159 if (!template_url_service_->loaded()) {
159 template_url_service_->AddObserver(this); 160 template_url_service_->AddObserver(this);
160 template_url_service_->Load(); 161 template_url_service_->Load();
161 } 162 }
162 } 163 }
163 164
164 FirstRunSearchEngineView::~FirstRunSearchEngineView() { 165 FirstRunSearchEngineView::~FirstRunSearchEngineView() {
165 template_url_service_->RemoveObserver(this); 166 template_url_service_->RemoveObserver(this);
166 } 167 }
167 168
168 string16 FirstRunSearchEngineView::GetWindowTitle() const { 169 string16 FirstRunSearchEngineView::GetWindowTitle() const {
169 return l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_TITLE); 170 return l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_TITLE);
170 } 171 }
171 172
173 views::View* FirstRunSearchEngineView::GetContentsView() {
174 return this;
175 }
176
177 views::ClientView* FirstRunSearchEngineView::CreateClientView(
178 views::Widget* widget) {
179 return this;
180 }
181
172 void FirstRunSearchEngineView::WindowClosing() { 182 void FirstRunSearchEngineView::WindowClosing() {
173 // If the window is closed by clicking the close button, we default to the 183 // If the window is closed by clicking the close button, we default to the
174 // engine in the first slot. 184 // engine in the first slot.
175 if (!user_chosen_engine_) 185 if (!user_chosen_engine_)
176 ChooseSearchEngine(fallback_choice_); 186 ChooseSearchEngine(fallback_choice_);
177 if (quit_on_closing_) 187 if (quit_on_closing_)
178 MessageLoop::current()->Quit(); 188 MessageLoop::current()->Quit();
179 } 189 }
180 190
191 views::Widget* FirstRunSearchEngineView::GetWidget() {
192 return View::GetWidget();
193 }
194
195 const views::Widget* FirstRunSearchEngineView::GetWidget() const {
196 return View::GetWidget();
197 }
198
199 bool FirstRunSearchEngineView::CanClose() {
200 // We need a valid search engine to set as default, so if the user tries to
201 // close the window before the template URL service is loaded, we must prevent
202 // this from happening.
203 return fallback_choice_ != NULL;
204 }
205
181 void FirstRunSearchEngineView::ButtonPressed(views::Button* sender, 206 void FirstRunSearchEngineView::ButtonPressed(views::Button* sender,
182 const views::Event& event) { 207 const views::Event& event) {
183 ChooseSearchEngine(static_cast<SearchEngineChoice*>(sender)); 208 ChooseSearchEngine(static_cast<SearchEngineChoice*>(sender));
184 GetWidget()->Close(); 209 GetWidget()->Close();
185 // This will call through to WindowClosing() above and will quit the message 210 // This will call through to WindowClosing() above and will quit the message
186 // loop. 211 // loop.
187 } 212 }
188 213
189 void FirstRunSearchEngineView::OnPaint(gfx::Canvas* canvas) { 214 void FirstRunSearchEngineView::OnPaint(gfx::Canvas* canvas) {
190 // Fill in behind the background image with the standard gray toolbar color. 215 // Fill in behind the background image with the standard gray toolbar color.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 495
471 // This will tell screenreaders that they should read the full text 496 // This will tell screenreaders that they should read the full text
472 // of this dialog to the user now (rather than waiting for the user 497 // of this dialog to the user now (rather than waiting for the user
473 // to explore it). 498 // to explore it).
474 GetWidget()->NotifyAccessibilityEvent( 499 GetWidget()->NotifyAccessibilityEvent(
475 this, ui::AccessibilityTypes::EVENT_ALERT, true); 500 this, ui::AccessibilityTypes::EVENT_ALERT, true);
476 } 501 }
477 502
478 void FirstRunSearchEngineView::ChooseSearchEngine(SearchEngineChoice* choice) { 503 void FirstRunSearchEngineView::ChooseSearchEngine(SearchEngineChoice* choice) {
479 user_chosen_engine_ = true; 504 user_chosen_engine_ = true;
480 DCHECK(template_url_service_); 505 DCHECK(choice && template_url_service_);
481 template_url_service_->SetSearchEngineDialogSlot(choice->slot()); 506 template_url_service_->SetSearchEngineDialogSlot(choice->slot());
482 const TemplateURL* default_search = choice->GetSearchEngine(); 507 const TemplateURL* default_search = choice->GetSearchEngine();
483 if (default_search) 508 if (default_search)
484 template_url_service_->SetDefaultSearchProvider(default_search); 509 template_url_service_->SetDefaultSearchProvider(default_search);
485 } 510 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698