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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | 226 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
227 SetLayoutManager(box_layout); | 227 SetLayoutManager(box_layout); |
228 } | 228 } |
229 | 229 |
230 AutofillDialogViews::NotificationArea::~NotificationArea() {} | 230 AutofillDialogViews::NotificationArea::~NotificationArea() {} |
231 | 231 |
232 void AutofillDialogViews::NotificationArea::SetNotifications( | 232 void AutofillDialogViews::NotificationArea::SetNotifications( |
233 const std::vector<DialogNotification>& notifications) { | 233 const std::vector<DialogNotification>& notifications) { |
234 notifications_ = notifications; | 234 notifications_ = notifications; |
235 | 235 |
236 // Default checkbox to checked. Preserve checkbox state if it already exists. | |
237 bool checkbox_state = checkbox_ ? checkbox_->checked() : true; | |
238 RemoveAllChildViews(true); | 236 RemoveAllChildViews(true); |
239 checkbox_ = NULL; | 237 checkbox_ = NULL; |
240 | 238 |
241 if (notifications_.empty()) | 239 if (notifications_.empty()) |
242 return; | 240 return; |
243 | 241 |
244 for (size_t i = 0; i < notifications_.size(); ++i) { | 242 for (size_t i = 0; i < notifications_.size(); ++i) { |
245 const DialogNotification& notification = notifications_[i]; | 243 const DialogNotification& notification = notifications_[i]; |
246 | 244 |
247 scoped_ptr<views::View> view; | 245 scoped_ptr<views::View> view; |
248 if (notification.HasCheckbox()) { | 246 if (notification.HasCheckbox()) { |
249 scoped_ptr<views::Checkbox> checkbox(new views::Checkbox(string16())); | 247 scoped_ptr<views::Checkbox> checkbox(new views::Checkbox(string16())); |
250 checkbox_ = checkbox.get(); | 248 checkbox_ = checkbox.get(); |
251 // We have to do this instead of using set_border() because a border | 249 // We have to do this instead of using set_border() because a border |
252 // is being used to draw the check square. | 250 // is being used to draw the check square. |
253 static_cast<views::CheckboxNativeThemeBorder*>(checkbox->border())-> | 251 static_cast<views::CheckboxNativeThemeBorder*>(checkbox->border())-> |
254 SetCustomInsets(gfx::Insets(kNotificationPadding, | 252 SetCustomInsets(gfx::Insets(kNotificationPadding, |
255 kNotificationPadding, | 253 kNotificationPadding, |
256 kNotificationPadding, | 254 kNotificationPadding, |
257 kNotificationPadding)); | 255 kNotificationPadding)); |
258 checkbox->SetChecked(checkbox_state); | |
259 checkbox->SetText(notification.display_text()); | 256 checkbox->SetText(notification.display_text()); |
260 checkbox->SetMultiLine(true); | 257 checkbox->SetMultiLine(true); |
261 checkbox->set_alignment(views::TextButtonBase::ALIGN_LEFT); | 258 checkbox->set_alignment(views::TextButtonBase::ALIGN_LEFT); |
262 checkbox->SetEnabledColor(notification.GetTextColor()); | 259 checkbox->SetEnabledColor(notification.GetTextColor()); |
263 checkbox->SetHoverColor(notification.GetTextColor()); | 260 checkbox->SetHoverColor(notification.GetTextColor()); |
264 view.reset(checkbox.release()); | 261 view.reset(checkbox.release()); |
265 } else { | 262 } else { |
266 scoped_ptr<views::Label> label(new views::Label()); | 263 scoped_ptr<views::Label> label(new views::Label()); |
267 label->SetText(notification.display_text()); | 264 label->SetText(notification.display_text()); |
268 label->SetMultiLine(true); | 265 label->SetMultiLine(true); |
269 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 266 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
270 label->SetAutoColorReadabilityEnabled(false); | 267 label->SetAutoColorReadabilityEnabled(false); |
271 label->SetEnabledColor(notification.GetTextColor()); | 268 label->SetEnabledColor(notification.GetTextColor()); |
272 label->set_border(views::Border::CreateSolidBorder( | 269 label->set_border(views::Border::CreateSolidBorder( |
273 kNotificationPadding, notification.GetBackgroundColor())); | 270 kNotificationPadding, notification.GetBackgroundColor())); |
274 view.reset(label.release()); | 271 view.reset(label.release()); |
275 } | 272 } |
276 | 273 |
277 view->set_background(views::Background::CreateSolidBackground( | 274 view->set_background(views::Background::CreateSolidBackground( |
278 notification.GetBackgroundColor())); | 275 notification.GetBackgroundColor())); |
279 AddChildView(view.release()); | 276 AddChildView(view.release()); |
280 } | 277 } |
281 | 278 |
282 PreferredSizeChanged(); | 279 PreferredSizeChanged(); |
283 } | 280 } |
284 | 281 |
285 bool AutofillDialogViews::NotificationArea::CheckboxIsChecked() const { | |
286 return checkbox_ && checkbox_->checked(); | |
287 } | |
288 | |
289 std::string AutofillDialogViews::NotificationArea::GetClassName() const { | 282 std::string AutofillDialogViews::NotificationArea::GetClassName() const { |
290 return kNotificationAreaClassName; | 283 return kNotificationAreaClassName; |
291 } | 284 } |
292 | 285 |
293 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) { | 286 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) { |
294 views::View::OnPaint(canvas); | 287 views::View::OnPaint(canvas); |
295 | 288 |
296 if (HasArrow()) { | 289 if (HasArrow()) { |
297 const int arrow_half_width = kArrowWidth / 2.0f; | 290 const int arrow_half_width = kArrowWidth / 2.0f; |
298 const int anchor_half_width = | 291 const int anchor_half_width = |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 details_container_->SetVisible(!(controller_->AutocheckoutIsRunning() || | 598 details_container_->SetVisible(!(controller_->AutocheckoutIsRunning() || |
606 controller_->HadAutocheckoutError())); | 599 controller_->HadAutocheckoutError())); |
607 | 600 |
608 GetDialogClientView()->UpdateDialogButtons(); | 601 GetDialogClientView()->UpdateDialogButtons(); |
609 ContentsPreferredSizeChanged(); | 602 ContentsPreferredSizeChanged(); |
610 } | 603 } |
611 | 604 |
612 void AutofillDialogViews::UpdateNotificationArea() { | 605 void AutofillDialogViews::UpdateNotificationArea() { |
613 DCHECK(notification_area_); | 606 DCHECK(notification_area_); |
614 notification_area_->SetNotifications(controller_->CurrentNotifications()); | 607 notification_area_->SetNotifications(controller_->CurrentNotifications()); |
608 | |
609 views::Checkbox* checkbox = notification_area_->checkbox(); | |
610 if (checkbox) { | |
611 checkbox->SetChecked(!controller_->GetPayWithoutWallet()); | |
Dan Beam
2013/04/05 02:45:57
an alternative to this would be to use prefs direc
Evan Stade
2013/04/05 23:38:23
make initial checkmark state part of the notificat
Dan Beam
2013/04/06 04:49:50
Done.
| |
612 checkbox->set_listener(this); | |
Dan Beam
2013/04/05 02:45:57
^ an alternative to this would be to have the noti
Evan Stade
2013/04/05 23:38:23
pass controller_ in and have the NotificationArea
Dan Beam
2013/04/06 04:49:50
Done.
| |
613 } | |
614 | |
615 ContentsPreferredSizeChanged(); | 615 ContentsPreferredSizeChanged(); |
616 } | 616 } |
617 | 617 |
618 void AutofillDialogViews::UpdateSection(DialogSection section) { | 618 void AutofillDialogViews::UpdateSection(DialogSection section) { |
619 const DetailInputs& updated_inputs = | 619 const DetailInputs& updated_inputs = |
620 controller_->RequestedFieldsForSection(section); | 620 controller_->RequestedFieldsForSection(section); |
621 DetailsGroup* group = GroupForSection(section); | 621 DetailsGroup* group = GroupForSection(section); |
622 | 622 |
623 for (DetailInputs::const_iterator iter = updated_inputs.begin(); | 623 for (DetailInputs::const_iterator iter = updated_inputs.begin(); |
624 iter != updated_inputs.end(); ++iter) { | 624 iter != updated_inputs.end(); ++iter) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 DialogSection billing_section = controller_->SectionIsActive(SECTION_CC) ? | 660 DialogSection billing_section = controller_->SectionIsActive(SECTION_CC) ? |
661 SECTION_CC : SECTION_CC_BILLING; | 661 SECTION_CC : SECTION_CC_BILLING; |
662 return GroupForSection(billing_section)->suggested_info-> | 662 return GroupForSection(billing_section)->suggested_info-> |
663 decorated_textfield()->textfield()->text(); | 663 decorated_textfield()->textfield()->text(); |
664 } | 664 } |
665 | 665 |
666 bool AutofillDialogViews::UseBillingForShipping() { | 666 bool AutofillDialogViews::UseBillingForShipping() { |
667 return use_billing_for_shipping_->checked(); | 667 return use_billing_for_shipping_->checked(); |
668 } | 668 } |
669 | 669 |
670 bool AutofillDialogViews::SaveDetailsInWallet() { | |
671 return notification_area_->CheckboxIsChecked(); | |
672 } | |
673 | |
674 bool AutofillDialogViews::SaveDetailsLocally() { | 670 bool AutofillDialogViews::SaveDetailsLocally() { |
675 return save_in_chrome_checkbox_->checked(); | 671 return save_in_chrome_checkbox_->checked(); |
676 } | 672 } |
677 | 673 |
678 const content::NavigationController* AutofillDialogViews::ShowSignIn() { | 674 const content::NavigationController* AutofillDialogViews::ShowSignIn() { |
679 // TODO(abodenha) We should be able to use the WebContents of the WebView | 675 // TODO(abodenha) We should be able to use the WebContents of the WebView |
680 // to navigate instead of LoadInitialURL. Figure out why it doesn't work. | 676 // to navigate instead of LoadInitialURL. Figure out why it doesn't work. |
681 | 677 |
682 account_chooser_->SetSignInLinkEnabled(false); | 678 account_chooser_->SetSignInLinkEnabled(false); |
683 sign_in_webview_->LoadInitialURL(wallet::GetSignInUrl()); | 679 sign_in_webview_->LoadInitialURL(wallet::GetSignInUrl()); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
798 widget, | 794 widget, |
799 controller_->web_contents()->GetBrowserContext()); | 795 controller_->web_contents()->GetBrowserContext()); |
800 } | 796 } |
801 | 797 |
802 void AutofillDialogViews::ButtonPressed(views::Button* sender, | 798 void AutofillDialogViews::ButtonPressed(views::Button* sender, |
803 const ui::Event& event) { | 799 const ui::Event& event) { |
804 if (sender == use_billing_for_shipping_) { | 800 if (sender == use_billing_for_shipping_) { |
805 UpdateDetailsGroupState(*GroupForSection(SECTION_SHIPPING)); | 801 UpdateDetailsGroupState(*GroupForSection(SECTION_SHIPPING)); |
806 } else if (sender == cancel_sign_in_) { | 802 } else if (sender == cancel_sign_in_) { |
807 controller_->EndSignInFlow(); | 803 controller_->EndSignInFlow(); |
804 } else if (sender == notification_area_->checkbox()) { | |
805 controller_->SetPayWithoutWallet( | |
806 !notification_area_->checkbox()->checked()); | |
808 } else { | 807 } else { |
809 // TODO(estade): Should the menu be shown on mouse down? | 808 // TODO(estade): Should the menu be shown on mouse down? |
810 DetailsGroup* group = NULL; | 809 DetailsGroup* group = NULL; |
811 for (DetailGroupMap::iterator iter = detail_groups_.begin(); | 810 for (DetailGroupMap::iterator iter = detail_groups_.begin(); |
812 iter != detail_groups_.end(); ++iter) { | 811 iter != detail_groups_.end(); ++iter) { |
813 if (sender == iter->second.suggested_button) { | 812 if (sender == iter->second.suggested_button) { |
814 group = &iter->second; | 813 group = &iter->second; |
815 break; | 814 break; |
816 } | 815 } |
817 } | 816 } |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1336 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) | 1335 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) |
1337 : section(section), | 1336 : section(section), |
1338 container(NULL), | 1337 container(NULL), |
1339 manual_input(NULL), | 1338 manual_input(NULL), |
1340 suggested_info(NULL), | 1339 suggested_info(NULL), |
1341 suggested_button(NULL) {} | 1340 suggested_button(NULL) {} |
1342 | 1341 |
1343 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} | 1342 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} |
1344 | 1343 |
1345 } // namespace autofill | 1344 } // namespace autofill |
OLD | NEW |