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