| Index: ui/views/controls/combobox/combobox.cc
|
| diff --git a/ui/views/controls/combobox/combobox.cc b/ui/views/controls/combobox/combobox.cc
|
| index 1f0b9fdbcc8a1b60270806c9594389401440181c..589352d70617fc136424d048ff13556d4c08821d 100644
|
| --- a/ui/views/controls/combobox/combobox.cc
|
| +++ b/ui/views/controls/combobox/combobox.cc
|
| @@ -220,6 +220,7 @@ const char Combobox::kViewClassName[] = "views/Combobox";
|
| Combobox::Combobox(ui::ComboboxModel* model)
|
| : model_(model),
|
| style_(STYLE_SHOW_DROP_DOWN_ON_CLICK),
|
| + menu_item_raises_click_event_(false),
|
| listener_(NULL),
|
| selected_index_(model_->GetDefaultIndex()),
|
| invalid_(false),
|
| @@ -281,6 +282,16 @@ void Combobox::SetStyle(Style style) {
|
| PreferredSizeChanged();
|
| }
|
|
|
| +void Combobox::SetMenuItemRaisesClickEvent(bool value) {
|
| + if (menu_item_raises_click_event_ == value)
|
| + return;
|
| +
|
| + menu_item_raises_click_event_ = value;
|
| +
|
| + UpdateFromModel();
|
| + PreferredSizeChanged();
|
| +}
|
| +
|
| void Combobox::ModelChanged() {
|
| selected_index_ = std::min(0, model_->GetItemCount());
|
| UpdateFromModel();
|
| @@ -358,6 +369,8 @@ bool Combobox::IsCommandEnabled(int id) const {
|
| void Combobox::ExecuteCommand(int id) {
|
| selected_index_ = MenuCommandToIndex(id);
|
| OnSelectionChanged();
|
| + if (style_ == STYLE_NOTIFY_ON_CLICK && menu_item_raises_click_event_)
|
| + HandleClickEvent();
|
| }
|
|
|
| bool Combobox::GetAccelerator(int id, ui::Accelerator* accel) {
|
| @@ -565,7 +578,6 @@ void Combobox::ButtonPressed(Button* sender, const ui::Event& event) {
|
| }
|
|
|
| void Combobox::UpdateFromModel() {
|
| - int max_width = 0;
|
| const gfx::FontList& font_list = Combobox::GetFontList();
|
|
|
| MenuItemView* menu = new MenuItemView(this);
|
| @@ -573,6 +585,7 @@ void Combobox::UpdateFromModel() {
|
| dropdown_list_menu_runner_.reset(new MenuRunner(menu));
|
|
|
| int num_items = model()->GetItemCount();
|
| + int width = 0;
|
| for (int i = 0; i < num_items; ++i) {
|
| if (model()->IsItemSeparatorAt(i)) {
|
| menu->AppendSeparator();
|
| @@ -586,10 +599,11 @@ void Combobox::UpdateFromModel() {
|
| base::i18n::AdjustStringForLocaleDirection(&text);
|
|
|
| menu->AppendMenuItem(i + kFirstMenuItemId, text, MenuItemView::NORMAL);
|
| - max_width = std::max(max_width, gfx::GetStringWidth(text, font_list));
|
| + if (!menu_item_raises_click_event_ || i == 0)
|
| + width = std::max(width, gfx::GetStringWidth(text, font_list));
|
| }
|
|
|
| - content_size_.SetSize(max_width, font_list.GetHeight());
|
| + content_size_.SetSize(width, font_list.GetHeight());
|
| }
|
|
|
| void Combobox::UpdateBorder() {
|
|
|