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

Side by Side Diff: chrome/browser/ui/views/autofill/autofill_dialog_views.cc

Issue 13625002: Change the behavior of the [X] Save details to Wallet checkbox notification to: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/autofill/autofill_dialog_views.h" 5 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 0)); 229 0));
230 } 230 }
231 231
232 void AutofillDialogViews::AccountChooser::LinkClicked(views::Link* source, 232 void AutofillDialogViews::AccountChooser::LinkClicked(views::Link* source,
233 int event_flags) { 233 int event_flags) {
234 controller_->StartSignInFlow(); 234 controller_->StartSignInFlow();
235 } 235 }
236 236
237 // AutofillDialogViews::NotificationArea --------------------------------------- 237 // AutofillDialogViews::NotificationArea ---------------------------------------
238 238
239 AutofillDialogViews::NotificationArea::NotificationArea() 239 AutofillDialogViews::NotificationArea::NotificationArea(
240 : checkbox_(NULL) { 240 AutofillDialogController* controller)
241 : controller_(controller),
242 checkbox_(NULL) {
241 // Reserve vertical space for the arrow (regardless of whether one exists). 243 // Reserve vertical space for the arrow (regardless of whether one exists).
242 set_border(views::Border::CreateEmptyBorder(kArrowHeight, 0, 0, 0)); 244 set_border(views::Border::CreateEmptyBorder(kArrowHeight, 0, 0, 0));
243 245
244 views::BoxLayout* box_layout = 246 views::BoxLayout* box_layout =
245 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); 247 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
246 SetLayoutManager(box_layout); 248 SetLayoutManager(box_layout);
247 } 249 }
248 250
249 AutofillDialogViews::NotificationArea::~NotificationArea() {} 251 AutofillDialogViews::NotificationArea::~NotificationArea() {}
250 252
251 void AutofillDialogViews::NotificationArea::SetNotifications( 253 void AutofillDialogViews::NotificationArea::SetNotifications(
252 const std::vector<DialogNotification>& notifications) { 254 const std::vector<DialogNotification>& notifications) {
253 notifications_ = notifications; 255 notifications_ = notifications;
254 256
255 // Default checkbox to checked. Preserve checkbox state if it already exists.
256 bool checkbox_state = checkbox_ ? checkbox_->checked() : true;
257 RemoveAllChildViews(true); 257 RemoveAllChildViews(true);
258 checkbox_ = NULL; 258 checkbox_ = NULL;
259 259
260 if (notifications_.empty()) 260 if (notifications_.empty())
261 return; 261 return;
262 262
263 for (size_t i = 0; i < notifications_.size(); ++i) { 263 for (size_t i = 0; i < notifications_.size(); ++i) {
264 const DialogNotification& notification = notifications_[i]; 264 const DialogNotification& notification = notifications_[i];
265 265
266 scoped_ptr<views::View> view; 266 scoped_ptr<views::View> view;
267 if (notification.HasCheckbox()) { 267 if (notification.HasCheckbox()) {
268 scoped_ptr<views::Checkbox> checkbox(new views::Checkbox(string16())); 268 scoped_ptr<views::Checkbox> checkbox(new views::Checkbox(string16()));
269 checkbox_ = checkbox.get(); 269 checkbox_ = checkbox.get();
270 // We have to do this instead of using set_border() because a border 270 // We have to do this instead of using set_border() because a border
271 // is being used to draw the check square. 271 // is being used to draw the check square.
272 static_cast<views::CheckboxNativeThemeBorder*>(checkbox->border())-> 272 static_cast<views::CheckboxNativeThemeBorder*>(checkbox->border())->
273 SetCustomInsets(gfx::Insets(kNotificationPadding, 273 SetCustomInsets(gfx::Insets(kNotificationPadding,
274 kNotificationPadding, 274 kNotificationPadding,
275 kNotificationPadding, 275 kNotificationPadding,
276 kNotificationPadding)); 276 kNotificationPadding));
277 checkbox->SetChecked(checkbox_state);
278 if (!notification.interactive()) 277 if (!notification.interactive())
279 checkbox->SetState(views::Button::STATE_DISABLED); 278 checkbox->SetState(views::Button::STATE_DISABLED);
280 checkbox->SetText(notification.display_text()); 279 checkbox->SetText(notification.display_text());
281 checkbox->SetMultiLine(true); 280 checkbox->SetMultiLine(true);
282 checkbox->set_alignment(views::TextButtonBase::ALIGN_LEFT); 281 checkbox->set_alignment(views::TextButtonBase::ALIGN_LEFT);
283 checkbox->SetEnabledColor(notification.GetTextColor()); 282 checkbox->SetEnabledColor(notification.GetTextColor());
284 checkbox->SetHoverColor(notification.GetTextColor()); 283 checkbox->SetHoverColor(notification.GetTextColor());
284 checkbox->SetChecked(notification.checked());
285 checkbox->set_listener(this);
285 view.reset(checkbox.release()); 286 view.reset(checkbox.release());
286 } else { 287 } else {
287 scoped_ptr<views::Label> label(new views::Label()); 288 scoped_ptr<views::Label> label(new views::Label());
288 label->SetText(notification.display_text()); 289 label->SetText(notification.display_text());
289 label->SetMultiLine(true); 290 label->SetMultiLine(true);
290 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 291 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
291 label->SetAutoColorReadabilityEnabled(false); 292 label->SetAutoColorReadabilityEnabled(false);
292 label->SetEnabledColor(notification.GetTextColor()); 293 label->SetEnabledColor(notification.GetTextColor());
293 label->set_border(views::Border::CreateSolidBorder( 294 label->set_border(views::Border::CreateSolidBorder(
294 kNotificationPadding, notification.GetBackgroundColor())); 295 kNotificationPadding, notification.GetBackgroundColor()));
295 view.reset(label.release()); 296 view.reset(label.release());
296 } 297 }
297 298
298 view->set_background(views::Background::CreateSolidBackground( 299 view->set_background(views::Background::CreateSolidBackground(
299 notification.GetBackgroundColor())); 300 notification.GetBackgroundColor()));
300 AddChildView(view.release()); 301 AddChildView(view.release());
301 } 302 }
302 303
303 PreferredSizeChanged(); 304 PreferredSizeChanged();
304 } 305 }
305 306
306 bool AutofillDialogViews::NotificationArea::CheckboxIsChecked() const {
307 return checkbox_ && checkbox_->checked();
308 }
309
310 std::string AutofillDialogViews::NotificationArea::GetClassName() const { 307 std::string AutofillDialogViews::NotificationArea::GetClassName() const {
311 return kNotificationAreaClassName; 308 return kNotificationAreaClassName;
312 } 309 }
313 310
314 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) { 311 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) {
315 views::View::OnPaint(canvas); 312 views::View::OnPaint(canvas);
316 313
317 if (HasArrow()) { 314 if (HasArrow()) {
318 const int arrow_half_width = kArrowWidth / 2.0f; 315 const int arrow_half_width = kArrowWidth / 2.0f;
319 const int anchor_half_width = 316 const int anchor_half_width =
320 arrow_centering_anchor_->width() / 2.0f; 317 arrow_centering_anchor_->width() / 2.0f;
321 const int arrow_middle = 318 const int arrow_middle =
322 GetMirroredXInView(width() - anchor_half_width - arrow_half_width); 319 GetMirroredXInView(width() - anchor_half_width - arrow_half_width);
323 320
324 SkPath arrow; 321 SkPath arrow;
325 arrow.moveTo(arrow_middle - arrow_half_width, kArrowHeight); 322 arrow.moveTo(arrow_middle - arrow_half_width, kArrowHeight);
326 arrow.lineTo(arrow_middle + arrow_half_width, kArrowHeight); 323 arrow.lineTo(arrow_middle + arrow_half_width, kArrowHeight);
327 arrow.lineTo(arrow_middle, 0); 324 arrow.lineTo(arrow_middle, 0);
328 arrow.close(); 325 arrow.close();
329 canvas->ClipPath(arrow); 326 canvas->ClipPath(arrow);
330 canvas->DrawColor(notifications_[0].GetBackgroundColor()); 327 canvas->DrawColor(notifications_[0].GetBackgroundColor());
331 } 328 }
332 } 329 }
333 330
331 void AutofillDialogViews::NotificationArea::ButtonPressed(
332 views::Button* sender, const ui::Event& event) {
333 DCHECK_EQ(sender, checkbox_);
334 controller_->CheckboxStateChanged(notifications_.front().type(),
335 checkbox_->checked());
336 }
337
334 bool AutofillDialogViews::NotificationArea::HasArrow() { 338 bool AutofillDialogViews::NotificationArea::HasArrow() {
335 return !notifications_.empty() && notifications_[0].HasArrow() && 339 return !notifications_.empty() && notifications_[0].HasArrow() &&
336 arrow_centering_anchor_.get(); 340 arrow_centering_anchor_.get();
337 } 341 }
338 342
339 // AutofillDialogViews::SectionContainer --------------------------------------- 343 // AutofillDialogViews::SectionContainer ---------------------------------------
340 344
341 AutofillDialogViews::SectionContainer::SectionContainer( 345 AutofillDialogViews::SectionContainer::SectionContainer(
342 const string16& label, 346 const string16& label,
343 views::View* controls, 347 views::View* controls,
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 DialogSection billing_section = controller_->SectionIsActive(SECTION_CC) ? 700 DialogSection billing_section = controller_->SectionIsActive(SECTION_CC) ?
697 SECTION_CC : SECTION_CC_BILLING; 701 SECTION_CC : SECTION_CC_BILLING;
698 return GroupForSection(billing_section)->suggested_info-> 702 return GroupForSection(billing_section)->suggested_info->
699 decorated_textfield()->textfield()->text(); 703 decorated_textfield()->textfield()->text();
700 } 704 }
701 705
702 bool AutofillDialogViews::UseBillingForShipping() { 706 bool AutofillDialogViews::UseBillingForShipping() {
703 return use_billing_for_shipping_->checked(); 707 return use_billing_for_shipping_->checked();
704 } 708 }
705 709
706 bool AutofillDialogViews::SaveDetailsInWallet() {
707 return notification_area_->CheckboxIsChecked();
708 }
709
710 bool AutofillDialogViews::SaveDetailsLocally() { 710 bool AutofillDialogViews::SaveDetailsLocally() {
711 return save_in_chrome_checkbox_->checked(); 711 return save_in_chrome_checkbox_->checked();
712 } 712 }
713 713
714 const content::NavigationController* AutofillDialogViews::ShowSignIn() { 714 const content::NavigationController* AutofillDialogViews::ShowSignIn() {
715 // TODO(abodenha) We should be able to use the WebContents of the WebView 715 // TODO(abodenha) We should be able to use the WebContents of the WebView
716 // to navigate instead of LoadInitialURL. Figure out why it doesn't work. 716 // to navigate instead of LoadInitialURL. Figure out why it doesn't work.
717 717
718 account_chooser_->SetSignInLinkEnabled(false); 718 account_chooser_->SetSignInLinkEnabled(false);
719 sign_in_webview_->LoadInitialURL(wallet::GetSignInUrl()); 719 sign_in_webview_->LoadInitialURL(wallet::GetSignInUrl());
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 views::View* AutofillDialogViews::CreateMainContainer() { 994 views::View* AutofillDialogViews::CreateMainContainer() {
995 main_container_ = new views::View(); 995 main_container_ = new views::View();
996 main_container_->SetLayoutManager( 996 main_container_->SetLayoutManager(
997 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 997 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
998 views::kRelatedControlVerticalSpacing)); 998 views::kRelatedControlVerticalSpacing));
999 999
1000 account_chooser_ = new AccountChooser(controller_); 1000 account_chooser_ = new AccountChooser(controller_);
1001 if (!views::DialogDelegate::UseNewStyle()) 1001 if (!views::DialogDelegate::UseNewStyle())
1002 main_container_->AddChildView(account_chooser_); 1002 main_container_->AddChildView(account_chooser_);
1003 1003
1004 notification_area_ = new NotificationArea(); 1004 notification_area_ = new NotificationArea(controller_);
1005 notification_area_->set_arrow_centering_anchor(account_chooser_->AsWeakPtr()); 1005 notification_area_->set_arrow_centering_anchor(account_chooser_->AsWeakPtr());
1006 main_container_->AddChildView(notification_area_); 1006 main_container_->AddChildView(notification_area_);
1007 1007
1008 main_container_->AddChildView(CreateDetailsContainer()); 1008 main_container_->AddChildView(CreateDetailsContainer());
1009 return main_container_; 1009 return main_container_;
1010 } 1010 }
1011 1011
1012 views::View* AutofillDialogViews::CreateDetailsContainer() { 1012 views::View* AutofillDialogViews::CreateDetailsContainer() {
1013 details_container_ = new views::View(); 1013 details_container_ = new views::View();
1014 // A box layout is used because it respects widget visibility. 1014 // A box layout is used because it respects widget visibility.
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 1391 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
1392 : section(section), 1392 : section(section),
1393 container(NULL), 1393 container(NULL),
1394 manual_input(NULL), 1394 manual_input(NULL),
1395 suggested_info(NULL), 1395 suggested_info(NULL),
1396 suggested_button(NULL) {} 1396 suggested_button(NULL) {}
1397 1397
1398 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 1398 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
1399 1399
1400 } // namespace autofill 1400 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698