Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: ui/views/controls/combobox/combobox.cc

Issue 141523005: Combobox: Rename styles to STYLE_NORMAL and STYLE_ACTION and modify behaviors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sky's review Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5b24960b0c8dcdd1861df8a90aa399f39d8416e3 100644
--- a/ui/views/controls/combobox/combobox.cc
+++ b/ui/views/controls/combobox/combobox.cc
@@ -278,6 +278,7 @@ void Combobox::SetStyle(Style style) {
style_ = style;
UpdateBorder();
+ UpdateFromModel();
PreferredSizeChanged();
}
@@ -358,6 +359,8 @@ bool Combobox::IsCommandEnabled(int id) const {
void Combobox::ExecuteCommand(int id) {
selected_index_ = MenuCommandToIndex(id);
OnSelectionChanged();
+ if (style_ == STYLE_NOTIFY_ON_CLICK)
+ HandleClickEvent();
}
bool Combobox::GetAccelerator(int id, ui::Accelerator* accel) {
@@ -480,9 +483,11 @@ bool Combobox::OnKeyPressed(const ui::KeyEvent& e) {
UpdateFromModel();
ShowDropDownMenu(ui::MENU_SOURCE_KEYBOARD);
} else if (new_index != selected_index_ && new_index != kNoSelection) {
- DCHECK(!model()->IsItemSeparatorAt(new_index));
- selected_index_ = new_index;
- OnSelectionChanged();
+ if (style_ != STYLE_NOTIFY_ON_CLICK) {
+ DCHECK(!model()->IsItemSeparatorAt(new_index));
+ selected_index_ = new_index;
+ OnSelectionChanged();
+ }
}
return true;
@@ -492,7 +497,7 @@ bool Combobox::OnKeyReleased(const ui::KeyEvent& e) {
if (style_ != STYLE_NOTIFY_ON_CLICK)
return false; // crbug.com/127520
- if (e.key_code() == ui::VKEY_SPACE)
+ if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_NOTIFY_ON_CLICK)
HandleClickEvent();
return false;
@@ -565,7 +570,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 +577,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 +591,12 @@ 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 (style_ != STYLE_NOTIFY_ON_CLICK || i == selected_index_)
+ 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() {

Powered by Google App Engine
This is Rietveld 408576698