diff options
author | aruslan@chromium.org <aruslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-15 10:55:48 +0000 |
---|---|---|
committer | aruslan@chromium.org <aruslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-15 10:55:48 +0000 |
commit | 009c27661b5d19e1804ae49d6ff33043439e42b6 (patch) | |
tree | a7e56f52b4578c1bc9a75c4a109306267783e27b | |
parent | ada92fc87a7a6ab0ee2f4664eb299081d1f2eded (diff) | |
download | chromium_src-009c27661b5d19e1804ae49d6ff33043439e42b6.zip chromium_src-009c27661b5d19e1804ae49d6ff33043439e42b6.tar.gz chromium_src-009c27661b5d19e1804ae49d6ff33043439e42b6.tar.bz2 |
Add 2-lines summary to CC/Address for Wallet items.
This adds functionality, not the final formatting of CC and Address data.
BUG=181286
Review URL: https://chromiumcodereview.appspot.com/12755019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188329 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc | 11 | ||||
-rw-r--r-- | chrome/browser/ui/autofill/autofill_dialog_models.cc | 15 | ||||
-rw-r--r-- | chrome/browser/ui/autofill/autofill_dialog_models.h | 13 | ||||
-rw-r--r-- | components/autofill/browser/wallet/wallet_address.cc | 16 | ||||
-rw-r--r-- | components/autofill/browser/wallet/wallet_address.h | 4 | ||||
-rw-r--r-- | components/autofill/browser/wallet/wallet_items.cc | 18 | ||||
-rw-r--r-- | components/autofill/browser/wallet/wallet_items.h | 5 | ||||
-rw-r--r-- | ui/base/models/menu_model.cc | 8 | ||||
-rw-r--r-- | ui/base/models/menu_model.h | 20 | ||||
-rw-r--r-- | ui/base/models/simple_menu_model.cc | 60 | ||||
-rw-r--r-- | ui/base/models/simple_menu_model.h | 7 |
11 files changed, 143 insertions, 34 deletions
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index f42ce6f..a36bf0f 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -1276,17 +1276,20 @@ void AutofillDialogControllerImpl::GenerateSuggestionsModels() { wallet_items_->addresses(); for (size_t i = 0; i < addresses.size(); ++i) { // TODO(dbeam): respect wallet_items_->default_instrument_id(). - suggested_shipping_.AddKeyedItem(base::IntToString(i), - addresses[i]->DisplayName()); + suggested_shipping_.AddKeyedItemWithSublabel( + base::IntToString(i), + addresses[i]->DisplayName(), + addresses[i]->DisplayNameDetail()); } const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = wallet_items_->instruments(); for (size_t i = 0; i < instruments.size(); ++i) { // TODO(dbeam): respect wallet_items_->default_address_id(). - suggested_cc_billing_.AddKeyedItemWithIcon( + suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( base::IntToString(i), - instruments[i]->descriptive_name(), + instruments[i]->DisplayName(), + instruments[i]->DisplayNameDetail(), instruments[i]->CardIcon()); } } diff --git a/chrome/browser/ui/autofill/autofill_dialog_models.cc b/chrome/browser/ui/autofill/autofill_dialog_models.cc index c64147b..99c5479 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_models.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_models.cc @@ -43,6 +43,21 @@ void SuggestionsMenuModel::AddKeyedItemWithIcon( SetIcon(items_.size() - 1, icon); } +void SuggestionsMenuModel::AddKeyedItemWithSublabel( + const std::string& key, + const string16& display_label, const string16& display_sublabel) { + AddKeyedItem(key, display_label); + SetSublabel(items_.size() - 1, display_sublabel); +} + +void SuggestionsMenuModel::AddKeyedItemWithSublabelAndIcon( + const std::string& key, + const string16& display_label, const string16& display_sublabel, + const gfx::Image& icon) { + AddKeyedItemWithIcon(key, display_label, icon); + SetSublabel(items_.size() - 1, display_sublabel); +} + void SuggestionsMenuModel::Reset() { checked_item_ = 0; items_.clear(); diff --git a/chrome/browser/ui/autofill/autofill_dialog_models.h b/chrome/browser/ui/autofill/autofill_dialog_models.h index c04c888..bd2488a 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_models.h +++ b/chrome/browser/ui/autofill/autofill_dialog_models.h @@ -47,6 +47,19 @@ class SuggestionsMenuModel : public ui::SimpleMenuModel, const string16& display_label, const gfx::Image& icon); + // Adds a label with a sublabel and its identifying key to the model. + // Keys needn't be unique. + void AddKeyedItemWithSublabel(const std::string& key, + const string16& display_label, + const string16& display_sublabel); + + // As above, but also accepts an image which will be displayed alongside the + // text. + void AddKeyedItemWithSublabelAndIcon(const std::string& key, + const string16& display_label, + const string16& display_sublabel, + const gfx::Image& icon); + // Resets the model to empty. void Reset(); diff --git a/components/autofill/browser/wallet/wallet_address.cc b/components/autofill/browser/wallet/wallet_address.cc index 5b0cc08..8f7a0b8 100644 --- a/components/autofill/browser/wallet/wallet_address.cc +++ b/components/autofill/browser/wallet/wallet_address.cc @@ -214,8 +214,22 @@ scoped_ptr<base::DictionaryValue> Address::ToDictionaryWithoutID() const { } string16 Address::DisplayName() const { - // TODO(estade): improve this stub implementation. +#if defined(OS_ANDROID) + // TODO(aruslan): improve this stub implementation. + return recipient_name(); +#else + // TODO(estade): improve this stub implementation + l10n. return recipient_name() + ASCIIToUTF16(", ") + address_line_1(); +#endif +} + +string16 Address::DisplayNameDetail() const { +#if defined(OS_ANDROID) + // TODO(aruslan): improve this stub implementation. + return address_line_1(); +#else + return string16(); +#endif } string16 Address::GetInfo(AutofillFieldType type) const { diff --git a/components/autofill/browser/wallet/wallet_address.h b/components/autofill/browser/wallet/wallet_address.h index 2925f0f3..c6ac95e 100644 --- a/components/autofill/browser/wallet/wallet_address.h +++ b/components/autofill/browser/wallet/wallet_address.h @@ -83,6 +83,10 @@ class Address { // the user. string16 DisplayName() const; + // Returns a string that could be used as a sub-label, suitable for display + // to the user together with DisplayName(). + string16 DisplayNameDetail() const; + // Returns data appropriate for |type|. string16 GetInfo(AutofillFieldType type) const; diff --git a/components/autofill/browser/wallet/wallet_items.cc b/components/autofill/browser/wallet/wallet_items.cc index 6a779ac..2a40522 100644 --- a/components/autofill/browser/wallet/wallet_items.cc +++ b/components/autofill/browser/wallet/wallet_items.cc @@ -206,6 +206,24 @@ bool WalletItems::HasRequiredAction(RequiredAction action) const { action) != required_actions_.end(); } +string16 WalletItems::MaskedInstrument::DisplayName() const { +#if defined(OS_ANDROID) + // TODO(aruslan): improve this stub implementation. + return descriptive_name(); +#else + return descriptive_name(); +#endif +} + +string16 WalletItems::MaskedInstrument::DisplayNameDetail() const { +#if defined(OS_ANDROID) + // TODO(aruslan): improve this stub implementation. + return address().DisplayName(); +#else + return string16(); +#endif +} + const gfx::Image& WalletItems::MaskedInstrument::CardIcon() const { int idr = 0; switch (type_) { diff --git a/components/autofill/browser/wallet/wallet_items.h b/components/autofill/browser/wallet/wallet_items.h index f507b88..6cb0308 100644 --- a/components/autofill/browser/wallet/wallet_items.h +++ b/components/autofill/browser/wallet/wallet_items.h @@ -77,6 +77,11 @@ class WalletItems { // Gets an image to display for this instrument. const gfx::Image& CardIcon() const; + // Returns a pair of strings that summarizes this CC, + // suitable for display to the user. + string16 DisplayName() const; + string16 DisplayNameDetail() const; + const string16& descriptive_name() const { return descriptive_name_; } const Type& type() const { return type_; } const std::vector<string16>& supported_currencies() const { diff --git a/ui/base/models/menu_model.cc b/ui/base/models/menu_model.cc index 1a3190d..60d47fd 100644 --- a/ui/base/models/menu_model.cc +++ b/ui/base/models/menu_model.cc @@ -32,10 +32,18 @@ bool MenuModel::GetModelAndIndexForCommandId(int command_id, return false; } +string16 MenuModel::GetSublabelAt(int index) const { + return string16(); +} + const gfx::Font* MenuModel::GetLabelFontAt(int index) const { return NULL; } +const gfx::Font* MenuModel::GetSublabelFontAt(int index) const { + return NULL; +} + // Default implementation ignores the event flags. void MenuModel::ActivatedAt(int index, int event_flags) { ActivatedAt(index); diff --git a/ui/base/models/menu_model.h b/ui/base/models/menu_model.h index 095dde5..8e5331c 100644 --- a/ui/base/models/menu_model.h +++ b/ui/base/models/menu_model.h @@ -58,16 +58,24 @@ class UI_EXPORT MenuModel { // Returns the label of the item at the specified index. virtual string16 GetLabelAt(int index) const = 0; - // Returns true if the menu item (label/icon) at the specified index can - // change over the course of the menu's lifetime. If this function returns - // true, the label and icon of the menu item will be updated each time the - // menu is shown. + // Returns the sublabel of the item at the specified index. The sublabel + // is rendered beneath the label and using the font GetSublabelFontAt(). + virtual string16 GetSublabelAt(int index) const; + + // Returns true if the menu item (label/sublabel/icon) at the specified + // index can change over the course of the menu's lifetime. If this function + // returns true, the label, sublabel and icon of the menu item will be + // updated each time the menu is shown. virtual bool IsItemDynamicAt(int index) const = 0; - // Returns the font use for the label at the specified index. - // If NULL, then use default font. + // Returns the font used for the label at the specified index. + // If NULL, then the default font should be used. virtual const gfx::Font* GetLabelFontAt(int index) const; + // Returns the font used for the sublabel at the specified index. + // If NULL, then the default font should be used. + virtual const gfx::Font* GetSublabelFontAt(int index) const; + // Gets the acclerator information for the specified index, returning true if // there is a shortcut accelerator for the item, false otherwise. virtual bool GetAcceleratorAt(int index, diff --git a/ui/base/models/simple_menu_model.cc b/ui/base/models/simple_menu_model.cc index 4d52132..227d502 100644 --- a/ui/base/models/simple_menu_model.cc +++ b/ui/base/models/simple_menu_model.cc @@ -16,6 +16,7 @@ const int kSeparatorId = -1; struct SimpleMenuModel::Item { int command_id; string16 label; + string16 sublabel; gfx::Image icon; ItemType type; int group_id; @@ -40,6 +41,11 @@ string16 SimpleMenuModel::Delegate::GetLabelForCommandId(int command_id) const { return string16(); } +string16 SimpleMenuModel::Delegate::GetSublabelForCommandId( + int command_id) const { + return string16(); +} + bool SimpleMenuModel::Delegate::GetIconForCommandId( int command_id, gfx::Image* image_skia) const { return false; @@ -72,8 +78,8 @@ SimpleMenuModel::~SimpleMenuModel() { } void SimpleMenuModel::AddItem(int command_id, const string16& label) { - Item item = { command_id, label, gfx::Image(), TYPE_COMMAND, -1, NULL, - NULL, NORMAL_SEPARATOR }; + Item item = { command_id, label, string16(), gfx::Image(), + TYPE_COMMAND, -1, NULL, NULL, NORMAL_SEPARATOR }; AppendItem(item); } @@ -82,8 +88,8 @@ void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) { } void SimpleMenuModel::AddCheckItem(int command_id, const string16& label) { - Item item = { command_id, label, gfx::Image(), TYPE_CHECK, -1, NULL, - NULL, NORMAL_SEPARATOR }; + Item item = { command_id, label, string16(), gfx::Image(), + TYPE_CHECK, -1, NULL, NULL, NORMAL_SEPARATOR }; AppendItem(item); } @@ -93,8 +99,8 @@ void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) { void SimpleMenuModel::AddRadioItem(int command_id, const string16& label, int group_id) { - Item item = { command_id, label, gfx::Image(), TYPE_RADIO, group_id, NULL, - NULL, NORMAL_SEPARATOR }; + Item item = { command_id, label, string16(), gfx::Image(), + TYPE_RADIO, group_id, NULL, NULL, NORMAL_SEPARATOR }; AppendItem(item); } @@ -118,8 +124,8 @@ void SimpleMenuModel::AddSeparator(MenuSeparatorType separator_type) { if (separator_type != NORMAL_SEPARATOR) NOTIMPLEMENTED(); #endif - Item item = { kSeparatorId, string16(), gfx::Image(), TYPE_SEPARATOR, - -1, NULL, NULL , separator_type }; + Item item = { kSeparatorId, string16(), string16(), gfx::Image(), + TYPE_SEPARATOR, -1, NULL, NULL , separator_type }; AppendItem(item); } @@ -130,15 +136,15 @@ void SimpleMenuModel::RemoveTrailingSeparators() { void SimpleMenuModel::AddButtonItem(int command_id, ButtonMenuItemModel* model) { - Item item = { command_id, string16(), gfx::Image(), TYPE_BUTTON_ITEM, -1, - NULL, model, NORMAL_SEPARATOR }; + Item item = { command_id, string16(), string16(), gfx::Image(), + TYPE_BUTTON_ITEM, -1, NULL, model, NORMAL_SEPARATOR }; AppendItem(item); } void SimpleMenuModel::AddSubMenu(int command_id, const string16& label, MenuModel* model) { - Item item = { command_id, label, gfx::Image(), TYPE_SUBMENU, -1, model, - NULL, NORMAL_SEPARATOR }; + Item item = { command_id, label, string16(), gfx::Image(), + TYPE_SUBMENU, -1, model, NULL, NORMAL_SEPARATOR }; AppendItem(item); } @@ -149,8 +155,8 @@ void SimpleMenuModel::AddSubMenuWithStringId(int command_id, void SimpleMenuModel::InsertItemAt( int index, int command_id, const string16& label) { - Item item = { command_id, label, gfx::Image(), TYPE_COMMAND, -1, NULL, - NULL, NORMAL_SEPARATOR }; + Item item = { command_id, label, string16(), gfx::Image(), + TYPE_COMMAND, -1, NULL, NULL, NORMAL_SEPARATOR }; InsertItemAtIndex(item, index); } @@ -166,15 +172,15 @@ void SimpleMenuModel::InsertSeparatorAt(int index, NOTIMPLEMENTED(); } #endif - Item item = { kSeparatorId, string16(), gfx::Image(), TYPE_SEPARATOR, - -1, NULL, NULL, separator_type }; + Item item = { kSeparatorId, string16(), string16(), gfx::Image(), + TYPE_SEPARATOR, -1, NULL, NULL, separator_type }; InsertItemAtIndex(item, index); } void SimpleMenuModel::InsertCheckItemAt( int index, int command_id, const string16& label) { - Item item = { command_id, label, gfx::Image(), TYPE_CHECK, -1, NULL, - NULL, NORMAL_SEPARATOR }; + Item item = { command_id, label, string16(), gfx::Image(), + TYPE_CHECK, -1, NULL, NULL, NORMAL_SEPARATOR }; InsertItemAtIndex(item, index); } @@ -185,8 +191,8 @@ void SimpleMenuModel::InsertCheckItemWithStringIdAt( void SimpleMenuModel::InsertRadioItemAt( int index, int command_id, const string16& label, int group_id) { - Item item = { command_id, label, gfx::Image(), TYPE_RADIO, group_id, NULL, - NULL, NORMAL_SEPARATOR }; + Item item = { command_id, label, string16(), gfx::Image(), + TYPE_RADIO, group_id, NULL, NULL, NORMAL_SEPARATOR }; InsertItemAtIndex(item, index); } @@ -198,8 +204,8 @@ void SimpleMenuModel::InsertRadioItemWithStringIdAt( void SimpleMenuModel::InsertSubMenuAt( int index, int command_id, const string16& label, MenuModel* model) { - Item item = { command_id, label, gfx::Image(), TYPE_SUBMENU, -1, model, - NULL, NORMAL_SEPARATOR }; + Item item = { command_id, label, string16(), gfx::Image(), + TYPE_SUBMENU, -1, model, NULL, NORMAL_SEPARATOR }; InsertItemAtIndex(item, index); } @@ -213,6 +219,10 @@ void SimpleMenuModel::SetIcon(int index, const gfx::Image& icon) { items_[ValidateItemIndex(index)].icon = icon; } +void SimpleMenuModel::SetSublabel(int index, const string16& sublabel) { + items_[ValidateItemIndex(index)].sublabel = sublabel; +} + void SimpleMenuModel::Clear() { items_.clear(); } @@ -259,6 +269,12 @@ string16 SimpleMenuModel::GetLabelAt(int index) const { return items_[ValidateItemIndex(index)].label; } +string16 SimpleMenuModel::GetSublabelAt(int index) const { + if (IsItemDynamicAt(index)) + return delegate_->GetSublabelForCommandId(GetCommandIdAt(index)); + return items_[ValidateItemIndex(index)].sublabel; +} + bool SimpleMenuModel::IsItemDynamicAt(int index) const { if (delegate_) return delegate_->IsItemForCommandIdDynamic(GetCommandIdAt(index)); diff --git a/ui/base/models/simple_menu_model.h b/ui/base/models/simple_menu_model.h index 552e9b7..f7f3c00 100644 --- a/ui/base/models/simple_menu_model.h +++ b/ui/base/models/simple_menu_model.h @@ -38,9 +38,10 @@ class UI_EXPORT SimpleMenuModel : public MenuModel { int command_id, ui::Accelerator* accelerator) = 0; - // Some command ids have labels and icons that change over time. + // Some command ids have labels, sublabels and icons that change over time. virtual bool IsItemForCommandIdDynamic(int command_id) const; virtual string16 GetLabelForCommandId(int command_id) const; + virtual string16 GetSublabelForCommandId(int command_id) const; // Gets the icon for the item with the specified id, returning true if there // is an icon, false otherwise. virtual bool GetIconForCommandId(int command_id, @@ -113,6 +114,9 @@ class UI_EXPORT SimpleMenuModel : public MenuModel { // Sets the icon for the item at |index|. void SetIcon(int index, const gfx::Image& icon); + // Sets the sublabel for the item at |index|. + void SetSublabel(int index, const string16& sublabel); + // Clears all items. Note that it does not free MenuModel of submenu. void Clear(); @@ -127,6 +131,7 @@ class UI_EXPORT SimpleMenuModel : public MenuModel { virtual ui::MenuSeparatorType GetSeparatorTypeAt(int index) const OVERRIDE; virtual int GetCommandIdAt(int index) const OVERRIDE; virtual string16 GetLabelAt(int index) const OVERRIDE; + virtual string16 GetSublabelAt(int index) const OVERRIDE; virtual bool IsItemDynamicAt(int index) const OVERRIDE; virtual bool GetAcceleratorAt(int index, ui::Accelerator* accelerator) const OVERRIDE; |