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

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: Fix around selected_index_ 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
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | ui/views/controls/combobox/combobox_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d38e3510b913c4f0696eea22a2f3cb5ce960b195 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(CLICK_EVENT_SOURCE_MENU_ITEM);
}
bool Combobox::GetAccelerator(int id, ui::Accelerator* accel) {
@@ -469,7 +472,7 @@ bool Combobox::OnKeyPressed(const ui::KeyEvent& e) {
case ui::VKEY_RETURN:
if (style_ != STYLE_NOTIFY_ON_CLICK)
return false;
- HandleClickEvent();
+ HandleClickEvent(CLICK_EVENT_SOURCE_KEYBOARD);
break;
default:
@@ -492,8 +495,8 @@ 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)
- HandleClickEvent();
+ if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_NOTIFY_ON_CLICK)
+ HandleClickEvent(CLICK_EVENT_SOURCE_KEYBOARD);
return false;
}
@@ -546,7 +549,7 @@ void Combobox::ButtonPressed(Button* sender, const ui::Event& event) {
RequestFocus();
if (sender == text_button_) {
- HandleClickEvent();
+ HandleClickEvent(CLICK_EVENT_SOURCE_MOUSE);
} else {
DCHECK_EQ(arrow_button_, sender);
// TODO(hajimehoshi): Fix the problem that the arrow button blinks when
@@ -565,7 +568,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 +575,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 +589,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 (style_ != STYLE_NOTIFY_ON_CLICK || i == 0)
sky 2014/01/23 15:40:25 Based on your description I think this should use
hajimehoshi 2014/01/24 04:10:56 Done.
+ 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() {
@@ -621,7 +625,11 @@ void Combobox::PaintText(gfx::Canvas* canvas) {
DCHECK_LT(selected_index_, model()->GetItemCount());
if (selected_index_ < 0 || selected_index_ > model()->GetItemCount())
selected_index_ = 0;
- base::string16 text = model()->GetItemAt(selected_index_);
+ base::string16 text;
+ if (style_ == STYLE_SHOW_DROP_DOWN_ON_CLICK)
sky 2014/01/23 15:40:25 This shouldn't be needed. If a consumer wants to f
hajimehoshi 2014/01/24 04:10:56 Done.
+ text = model()->GetItemAt(selected_index_);
+ else
+ text = model()->GetItemAt(0);
int disclosure_arrow_offset = width() - disclosure_arrow_->width() -
GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding();
@@ -788,10 +796,13 @@ int Combobox::GetDisclosureArrowRightPadding() const {
return 0;
}
-void Combobox::HandleClickEvent() {
+void Combobox::HandleClickEvent(ClickEventSource source) {
if (style_ != STYLE_NOTIFY_ON_CLICK)
return;
+ if (source != CLICK_EVENT_SOURCE_MENU_ITEM)
sky 2014/01/23 15:40:25 Same comment as above. Your code should change sel
hajimehoshi 2014/01/24 04:10:56 Done.
+ selected_index_ = 0;
+
if (listener_)
listener_->OnComboboxTextButtonClicked(this);
}
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | ui/views/controls/combobox/combobox_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698