Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/autofill/autofill_dialog_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1500 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( | 1500 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( |
| 1501 DialogSection section) { | 1501 DialogSection section) { |
| 1502 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); | 1502 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); |
| 1503 if (!model.get()) | 1503 if (!model.get()) |
| 1504 return gfx::Image(); | 1504 return gfx::Image(); |
| 1505 | 1505 |
| 1506 return model->GetIcon(); | 1506 return model->GetIcon(); |
| 1507 } | 1507 } |
| 1508 | 1508 |
| 1509 gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection( | 1509 gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection( |
| 1510 DialogSection section) const { | 1510 DialogSection section) { |
| 1511 if (section == SECTION_CC || section == SECTION_CC_BILLING) | 1511 if (section != SECTION_CC && section != SECTION_CC_BILLING) |
| 1512 return IconForField(CREDIT_CARD_VERIFICATION_CODE, string16()); | 1512 return gfx::Image(); |
| 1513 | 1513 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); |
| 1514 return gfx::Image(); | 1514 if (!model.get()) |
| 1515 return gfx::Image(); | |
| 1516 FieldValueMap section_values; | |
| 1517 section_values[CREDIT_CARD_NUMBER] = | |
| 1518 model->GetInfo(AutofillType(CREDIT_CARD_NUMBER)); | |
|
Evan Stade
2013/09/16 23:36:59
this won't work for wallet (SECTION_CC_BILLING); w
please use gerrit instead
2013/09/17 00:38:17
Using CREDIT_CARD_TYPE instead.
| |
| 1519 section_values[CREDIT_CARD_VERIFICATION_CODE] = string16(); | |
| 1520 FieldIconMap section_icons = IconsForFields(section_values); | |
| 1521 return section_icons[CREDIT_CARD_VERIFICATION_CODE]; | |
|
Evan Stade
2013/09/16 23:36:59
this function needs vertical whitespace
please use gerrit instead
2013/09/17 00:38:17
Done.
| |
| 1515 } | 1522 } |
| 1516 | 1523 |
| 1524 // TODO(groby): Remove this deprecated method after Mac starts using | |
| 1525 // IconsForFields. http://crbug.com/292876 | |
| 1517 gfx::Image AutofillDialogControllerImpl::IconForField( | 1526 gfx::Image AutofillDialogControllerImpl::IconForField( |
| 1518 ServerFieldType type, const string16& user_input) const { | 1527 ServerFieldType type, const string16& user_input) const { |
| 1519 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1528 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 1520 if (type == CREDIT_CARD_VERIFICATION_CODE) | 1529 if (type == CREDIT_CARD_VERIFICATION_CODE) |
| 1521 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); | 1530 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); |
| 1522 | 1531 |
| 1523 if (type == CREDIT_CARD_NUMBER) { | 1532 if (type == CREDIT_CARD_NUMBER) { |
| 1524 const int input_card_idr = CreditCard::IconResourceId( | 1533 const int input_card_idr = CreditCard::IconResourceId( |
| 1525 CreditCard::GetCreditCardType(user_input)); | 1534 CreditCard::GetCreditCardType(user_input)); |
| 1526 if (input_card_idr != IDR_AUTOFILL_CC_GENERIC) | 1535 if (input_card_idr != IDR_AUTOFILL_CC_GENERIC) |
| 1527 return rb.GetImageNamed(input_card_idr); | 1536 return rb.GetImageNamed(input_card_idr); |
| 1528 | 1537 |
| 1529 // When the credit card type is unknown, no image should be shown. However, | 1538 // When the credit card type is unknown, no image should be shown. However, |
| 1530 // to simplify the view code on Mac, save space for the credit card image by | 1539 // to simplify the view code on Mac, save space for the credit card image by |
| 1531 // returning a transparent image of the appropriate size. | 1540 // returning a transparent image of the appropriate size. |
| 1532 gfx::ImageSkia image = *rb.GetImageSkiaNamed(input_card_idr); | 1541 gfx::ImageSkia image = *rb.GetImageSkiaNamed(input_card_idr); |
| 1533 return | 1542 return |
| 1534 gfx::Image(gfx::ImageSkiaOperations::CreateTransparentImage(image, 0)); | 1543 gfx::Image(gfx::ImageSkiaOperations::CreateTransparentImage(image, 0)); |
| 1535 } | 1544 } |
| 1536 | 1545 |
| 1537 return gfx::Image(); | 1546 return gfx::Image(); |
| 1538 } | 1547 } |
| 1539 | 1548 |
| 1549 FieldIconMap AutofillDialogControllerImpl::IconsForFields( | |
| 1550 const FieldValueMap& user_inputs) const { | |
| 1551 FieldIconMap result; | |
| 1552 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 1553 FieldValueMap::const_iterator credit_card_iter = | |
| 1554 user_inputs.find(CREDIT_CARD_NUMBER); | |
| 1555 std::string credit_card_type = autofill::kGenericCard; | |
| 1556 if (credit_card_iter != user_inputs.end()) { | |
| 1557 const string16& credit_card_number = credit_card_iter->second; | |
| 1558 credit_card_type = CreditCard::GetCreditCardType(credit_card_number); | |
| 1559 const int input_card_idr = CreditCard::IconResourceId(credit_card_type); | |
| 1560 result[CREDIT_CARD_NUMBER] = rb.GetImageNamed(input_card_idr); | |
| 1561 if (input_card_idr == IDR_AUTOFILL_CC_GENERIC) { | |
| 1562 // When the credit card type is unknown, no image should be shown. | |
| 1563 // However, to simplify the view code on Mac, save space for the credit | |
| 1564 // card image by returning a transparent image of the appropriate size. | |
| 1565 result[CREDIT_CARD_NUMBER] = | |
| 1566 gfx::Image(gfx::ImageSkiaOperations::CreateTransparentImage( | |
| 1567 result[CREDIT_CARD_NUMBER].AsImageSkia(), 0)); | |
| 1568 } | |
| 1569 } | |
| 1570 | |
| 1571 FieldValueMap::const_iterator cvc_iter = | |
| 1572 user_inputs.find(CREDIT_CARD_VERIFICATION_CODE); | |
| 1573 if (cvc_iter == user_inputs.end()) | |
| 1574 return result; | |
| 1575 if (credit_card_type == autofill::kAmericanExpressCard) { | |
| 1576 result[CREDIT_CARD_VERIFICATION_CODE] = | |
| 1577 rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT_AMEX); | |
| 1578 return result; | |
| 1579 } | |
| 1580 result[CREDIT_CARD_VERIFICATION_CODE] = | |
| 1581 rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); | |
| 1582 return result; | |
| 1583 } | |
| 1584 | |
| 1585 bool AutofillDialogControllerImpl::FieldControlsIcons( | |
| 1586 ServerFieldType type) const { | |
| 1587 return type == CREDIT_CARD_NUMBER; | |
| 1588 } | |
| 1589 | |
| 1540 // TODO(estade): Replace all the error messages here with more helpful and | 1590 // TODO(estade): Replace all the error messages here with more helpful and |
| 1541 // translateable ones. TODO(groby): Also add tests. | 1591 // translateable ones. TODO(groby): Also add tests. |
| 1542 string16 AutofillDialogControllerImpl::InputValidityMessage( | 1592 string16 AutofillDialogControllerImpl::InputValidityMessage( |
| 1543 DialogSection section, | 1593 DialogSection section, |
| 1544 ServerFieldType type, | 1594 ServerFieldType type, |
| 1545 const string16& value) { | 1595 const string16& value) { |
| 1546 // If the field is edited, clear any Wallet errors. | 1596 // If the field is edited, clear any Wallet errors. |
| 1547 if (IsPayingWithWallet()) { | 1597 if (IsPayingWithWallet()) { |
| 1548 WalletValidationErrors::iterator it = wallet_errors_.find(section); | 1598 WalletValidationErrors::iterator it = wallet_errors_.find(section); |
| 1549 if (it != wallet_errors_.end()) { | 1599 if (it != wallet_errors_.end()) { |
| (...skipping 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3360 } | 3410 } |
| 3361 | 3411 |
| 3362 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { | 3412 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { |
| 3363 if (!view_) | 3413 if (!view_) |
| 3364 return; | 3414 return; |
| 3365 ScopedViewUpdates updates(view_.get()); | 3415 ScopedViewUpdates updates(view_.get()); |
| 3366 view_->UpdateButtonStrip(); | 3416 view_->UpdateButtonStrip(); |
| 3367 } | 3417 } |
| 3368 | 3418 |
| 3369 } // namespace autofill | 3419 } // namespace autofill |
| OLD | NEW |