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

Side by Side Diff: ui/views/controls/combobox/combobox.cc

Issue 2069733002: MD - Use real comboboxes in website settings popup. Hide borders (but (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comment Created 4 years, 6 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
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 359
360 Combobox::Combobox(ui::ComboboxModel* model, Style style) 360 Combobox::Combobox(ui::ComboboxModel* model, Style style)
361 : model_(model), 361 : model_(model),
362 style_(style), 362 style_(style),
363 listener_(NULL), 363 listener_(NULL),
364 selected_index_(style == STYLE_ACTION ? 0 : model_->GetDefaultIndex()), 364 selected_index_(style == STYLE_ACTION ? 0 : model_->GetDefaultIndex()),
365 invalid_(false), 365 invalid_(false),
366 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), 366 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)),
367 text_button_(new TransparentButton(this)), 367 text_button_(new TransparentButton(this)),
368 arrow_button_(new TransparentButton(this)), 368 arrow_button_(new TransparentButton(this)),
369 size_to_largest_label_(style_ == STYLE_NORMAL),
369 weak_ptr_factory_(this) { 370 weak_ptr_factory_(this) {
370 ModelChanged(); 371 ModelChanged();
371 #if defined(OS_MACOSX) 372 #if defined(OS_MACOSX)
372 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); 373 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
373 #else 374 #else
374 SetFocusBehavior(FocusBehavior::ALWAYS); 375 SetFocusBehavior(FocusBehavior::ALWAYS);
375 #endif 376 #endif
376 377
377 UpdateBorder(); 378 UpdateBorder();
378 arrow_image_ = PlatformStyle::CreateComboboxArrow(enabled(), style); 379 arrow_image_ = PlatformStyle::CreateComboboxArrow(enabled(), style);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 432
432 content_size_ = GetContentSize(); 433 content_size_ = GetContentSize();
433 PreferredSizeChanged(); 434 PreferredSizeChanged();
434 } 435 }
435 436
436 void Combobox::SetSelectedIndex(int index) { 437 void Combobox::SetSelectedIndex(int index) {
437 if (style_ == STYLE_ACTION) 438 if (style_ == STYLE_ACTION)
438 return; 439 return;
439 440
440 selected_index_ = index; 441 selected_index_ = index;
441 SchedulePaint(); 442 if (size_to_largest_label_) {
443 SchedulePaint();
444 } else {
445 content_size_ = GetContentSize();
446 PreferredSizeChanged();
447 }
442 } 448 }
443 449
444 bool Combobox::SelectValue(const base::string16& value) { 450 bool Combobox::SelectValue(const base::string16& value) {
445 if (style_ == STYLE_ACTION) 451 if (style_ == STYLE_ACTION)
446 return false; 452 return false;
447 453
448 for (int i = 0; i < model()->GetItemCount(); ++i) { 454 for (int i = 0; i < model()->GetItemCount(); ++i) {
449 if (value == model()->GetItemAt(i)) { 455 if (value == model()->GetItemAt(i)) {
450 SetSelectedIndex(i); 456 SetSelectedIndex(i);
451 return true; 457 return true;
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 } 877 }
872 878
873 gfx::Size Combobox::GetContentSize() const { 879 gfx::Size Combobox::GetContentSize() const {
874 const gfx::FontList& font_list = GetFontList(); 880 const gfx::FontList& font_list = GetFontList();
875 881
876 int width = 0; 882 int width = 0;
877 for (int i = 0; i < model()->GetItemCount(); ++i) { 883 for (int i = 0; i < model()->GetItemCount(); ++i) {
878 if (model_->IsItemSeparatorAt(i)) 884 if (model_->IsItemSeparatorAt(i))
879 continue; 885 continue;
880 886
881 if (style_ != STYLE_ACTION || i == selected_index_) { 887 if (size_to_largest_label_ || i == selected_index_) {
882 width = std::max( 888 width = std::max(
883 width, 889 width,
884 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list)); 890 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list));
885 } 891 }
886 } 892 }
887 return gfx::Size(width, font_list.GetHeight()); 893 return gfx::Size(width, font_list.GetHeight());
888 } 894 }
889 895
890 PrefixSelector* Combobox::GetPrefixSelector() { 896 PrefixSelector* Combobox::GetPrefixSelector() {
891 if (!selector_) 897 if (!selector_)
892 selector_.reset(new PrefixSelector(this)); 898 selector_.reset(new PrefixSelector(this));
893 return selector_.get(); 899 return selector_.get();
894 } 900 }
895 901
896 int Combobox::GetArrowContainerWidth() const { 902 int Combobox::GetArrowContainerWidth() const {
897 int padding = style_ == STYLE_NORMAL 903 int padding = style_ == STYLE_NORMAL
898 ? PlatformStyle::kComboboxNormalArrowPadding * 2 904 ? PlatformStyle::kComboboxNormalArrowPadding * 2
899 : kActionLeftPadding + kActionRightPadding; 905 : kActionLeftPadding + kActionRightPadding;
900 return ArrowSize().width() + padding; 906 return ArrowSize().width() + padding;
901 } 907 }
902 908
903 } // namespace views 909 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698