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
This commit is contained in:
chrome/browser/ui/autofill
components/autofill/browser/wallet
ui/base/models
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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_) {
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user