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

Side by Side 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: Added comment and test 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/combobox/combobox.h" 5 #include "ui/views/controls/combobox/combobox.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "ui/base/accessibility/accessible_view_state.h" 10 #include "ui/base/accessibility/accessible_view_state.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 return rb.GetFontList(ui::ResourceBundle::BaseFont); 271 return rb.GetFontList(ui::ResourceBundle::BaseFont);
272 } 272 }
273 273
274 void Combobox::SetStyle(Style style) { 274 void Combobox::SetStyle(Style style) {
275 if (style_ == style) 275 if (style_ == style)
276 return; 276 return;
277 277
278 style_ = style; 278 style_ = style;
279 279
280 UpdateBorder(); 280 UpdateBorder();
281 UpdateFromModel();
281 PreferredSizeChanged(); 282 PreferredSizeChanged();
282 } 283 }
283 284
284 void Combobox::ModelChanged() { 285 void Combobox::ModelChanged() {
285 selected_index_ = std::min(0, model_->GetItemCount()); 286 selected_index_ = std::min(0, model_->GetItemCount());
286 UpdateFromModel(); 287 UpdateFromModel();
287 PreferredSizeChanged(); 288 PreferredSizeChanged();
288 } 289 }
289 290
290 void Combobox::SetSelectedIndex(int index) { 291 void Combobox::SetSelectedIndex(int index) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 return false; 352 return false;
352 } 353 }
353 354
354 bool Combobox::IsCommandEnabled(int id) const { 355 bool Combobox::IsCommandEnabled(int id) const {
355 return model()->IsItemEnabledAt(MenuCommandToIndex(id)); 356 return model()->IsItemEnabledAt(MenuCommandToIndex(id));
356 } 357 }
357 358
358 void Combobox::ExecuteCommand(int id) { 359 void Combobox::ExecuteCommand(int id) {
359 selected_index_ = MenuCommandToIndex(id); 360 selected_index_ = MenuCommandToIndex(id);
360 OnSelectionChanged(); 361 OnSelectionChanged();
362 if (style_ == STYLE_NOTIFY_ON_CLICK)
363 HandleClickEvent();
361 } 364 }
362 365
363 bool Combobox::GetAccelerator(int id, ui::Accelerator* accel) { 366 bool Combobox::GetAccelerator(int id, ui::Accelerator* accel) {
364 return false; 367 return false;
365 } 368 }
366 369
367 int Combobox::GetRowCount() { 370 int Combobox::GetRowCount() {
368 return model()->GetItemCount(); 371 return model()->GetItemCount();
369 } 372 }
370 373
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 ui::MenuSourceType source_type = ui::MENU_SOURCE_MOUSE; 561 ui::MenuSourceType source_type = ui::MENU_SOURCE_MOUSE;
559 if (event.IsKeyEvent()) 562 if (event.IsKeyEvent())
560 source_type = ui::MENU_SOURCE_KEYBOARD; 563 source_type = ui::MENU_SOURCE_KEYBOARD;
561 else if (event.IsGestureEvent() || event.IsTouchEvent()) 564 else if (event.IsGestureEvent() || event.IsTouchEvent())
562 source_type = ui::MENU_SOURCE_TOUCH; 565 source_type = ui::MENU_SOURCE_TOUCH;
563 ShowDropDownMenu(source_type); 566 ShowDropDownMenu(source_type);
564 } 567 }
565 } 568 }
566 569
567 void Combobox::UpdateFromModel() { 570 void Combobox::UpdateFromModel() {
568 int max_width = 0;
569 const gfx::FontList& font_list = Combobox::GetFontList(); 571 const gfx::FontList& font_list = Combobox::GetFontList();
570 572
571 MenuItemView* menu = new MenuItemView(this); 573 MenuItemView* menu = new MenuItemView(this);
572 // MenuRunner owns |menu|. 574 // MenuRunner owns |menu|.
573 dropdown_list_menu_runner_.reset(new MenuRunner(menu)); 575 dropdown_list_menu_runner_.reset(new MenuRunner(menu));
574 576
575 int num_items = model()->GetItemCount(); 577 int num_items = model()->GetItemCount();
578 int width = 0;
576 for (int i = 0; i < num_items; ++i) { 579 for (int i = 0; i < num_items; ++i) {
577 if (model()->IsItemSeparatorAt(i)) { 580 if (model()->IsItemSeparatorAt(i)) {
578 menu->AppendSeparator(); 581 menu->AppendSeparator();
579 continue; 582 continue;
580 } 583 }
581 584
582 base::string16 text = model()->GetItemAt(i); 585 base::string16 text = model()->GetItemAt(i);
583 586
584 // Inserting the Unicode formatting characters if necessary so that the 587 // Inserting the Unicode formatting characters if necessary so that the
585 // text is displayed correctly in right-to-left UIs. 588 // text is displayed correctly in right-to-left UIs.
586 base::i18n::AdjustStringForLocaleDirection(&text); 589 base::i18n::AdjustStringForLocaleDirection(&text);
587 590
588 menu->AppendMenuItem(i + kFirstMenuItemId, text, MenuItemView::NORMAL); 591 menu->AppendMenuItem(i + kFirstMenuItemId, text, MenuItemView::NORMAL);
589 max_width = std::max(max_width, gfx::GetStringWidth(text, font_list)); 592 if (style_ != STYLE_NOTIFY_ON_CLICK || i == 0)
sky 2014/01/22 16:04:07 I don't understand this part of the change. Should
sky 2014/01/23 01:11:23 Sorry, one question here. If you do this and the s
hajimehoshi 2014/01/23 02:16:32 For the current usage of Translate bubble, the bub
593 width = std::max(width, gfx::GetStringWidth(text, font_list));
590 } 594 }
591 595
592 content_size_.SetSize(max_width, font_list.GetHeight()); 596 content_size_.SetSize(width, font_list.GetHeight());
593 } 597 }
594 598
595 void Combobox::UpdateBorder() { 599 void Combobox::UpdateBorder() {
596 FocusableBorder* border = new FocusableBorder(); 600 FocusableBorder* border = new FocusableBorder();
597 if (style_ == STYLE_NOTIFY_ON_CLICK) 601 if (style_ == STYLE_NOTIFY_ON_CLICK)
598 border->SetInsets(8, 13, 8, 13); 602 border->SetInsets(8, 13, 8, 13);
599 if (invalid_) 603 if (invalid_)
600 border->SetColor(kWarningColor); 604 border->SetColor(kWarningColor);
601 set_border(border); 605 set_border(border);
602 } 606 }
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 794
791 void Combobox::HandleClickEvent() { 795 void Combobox::HandleClickEvent() {
792 if (style_ != STYLE_NOTIFY_ON_CLICK) 796 if (style_ != STYLE_NOTIFY_ON_CLICK)
793 return; 797 return;
794 798
795 if (listener_) 799 if (listener_)
796 listener_->OnComboboxTextButtonClicked(this); 800 listener_->OnComboboxTextButtonClicked(this);
797 } 801 }
798 802
799 } // namespace views 803 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698