| OLD | NEW |
| 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 bool Combobox::SelectValue(const base::string16& value) { | 314 bool Combobox::SelectValue(const base::string16& value) { |
| 315 for (int i = 0; i < model()->GetItemCount(); ++i) { | 315 for (int i = 0; i < model()->GetItemCount(); ++i) { |
| 316 if (value == model()->GetItemAt(i)) { | 316 if (value == model()->GetItemAt(i)) { |
| 317 SetSelectedIndex(i); | 317 SetSelectedIndex(i); |
| 318 return true; | 318 return true; |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 return false; | 321 return false; |
| 322 } | 322 } |
| 323 | 323 |
| 324 void Combobox::SetAccessibleName(const string16& name) { | 324 void Combobox::SetAccessibleName(const base::string16& name) { |
| 325 accessible_name_ = name; | 325 accessible_name_ = name; |
| 326 } | 326 } |
| 327 | 327 |
| 328 void Combobox::SetInvalid(bool invalid) { | 328 void Combobox::SetInvalid(bool invalid) { |
| 329 if (invalid == invalid_) | 329 if (invalid == invalid_) |
| 330 return; | 330 return; |
| 331 | 331 |
| 332 invalid_ = invalid; | 332 invalid_ = invalid; |
| 333 | 333 |
| 334 set_background(invalid_ ? new InvalidBackground() : NULL); | 334 set_background(invalid_ ? new InvalidBackground() : NULL); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 } | 389 } |
| 390 | 390 |
| 391 int Combobox::GetSelectedRow() { | 391 int Combobox::GetSelectedRow() { |
| 392 return selected_index_; | 392 return selected_index_; |
| 393 } | 393 } |
| 394 | 394 |
| 395 void Combobox::SetSelectedRow(int row) { | 395 void Combobox::SetSelectedRow(int row) { |
| 396 SetSelectedIndex(row); | 396 SetSelectedIndex(row); |
| 397 } | 397 } |
| 398 | 398 |
| 399 string16 Combobox::GetTextForRow(int row) { | 399 base::string16 Combobox::GetTextForRow(int row) { |
| 400 return model()->IsItemSeparatorAt(row) ? string16() : model()->GetItemAt(row); | 400 return model()->IsItemSeparatorAt(row) ? base::string16() : |
| 401 model()->GetItemAt(row); |
| 401 } | 402 } |
| 402 | 403 |
| 403 //////////////////////////////////////////////////////////////////////////////// | 404 //////////////////////////////////////////////////////////////////////////////// |
| 404 // Combobox, View overrides: | 405 // Combobox, View overrides: |
| 405 | 406 |
| 406 gfx::Size Combobox::GetPreferredSize() { | 407 gfx::Size Combobox::GetPreferredSize() { |
| 407 if (content_size_.IsEmpty()) | 408 if (content_size_.IsEmpty()) |
| 408 UpdateFromModel(); | 409 UpdateFromModel(); |
| 409 | 410 |
| 410 // The preferred size will drive the local bounds which in turn is used to set | 411 // The preferred size will drive the local bounds which in turn is used to set |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 // MenuRunner owns |menu|. | 587 // MenuRunner owns |menu|. |
| 587 dropdown_list_menu_runner_.reset(new MenuRunner(menu)); | 588 dropdown_list_menu_runner_.reset(new MenuRunner(menu)); |
| 588 | 589 |
| 589 int num_items = model()->GetItemCount(); | 590 int num_items = model()->GetItemCount(); |
| 590 for (int i = 0; i < num_items; ++i) { | 591 for (int i = 0; i < num_items; ++i) { |
| 591 if (model()->IsItemSeparatorAt(i)) { | 592 if (model()->IsItemSeparatorAt(i)) { |
| 592 menu->AppendSeparator(); | 593 menu->AppendSeparator(); |
| 593 continue; | 594 continue; |
| 594 } | 595 } |
| 595 | 596 |
| 596 string16 text = model()->GetItemAt(i); | 597 base::string16 text = model()->GetItemAt(i); |
| 597 | 598 |
| 598 // Inserting the Unicode formatting characters if necessary so that the | 599 // Inserting the Unicode formatting characters if necessary so that the |
| 599 // text is displayed correctly in right-to-left UIs. | 600 // text is displayed correctly in right-to-left UIs. |
| 600 base::i18n::AdjustStringForLocaleDirection(&text); | 601 base::i18n::AdjustStringForLocaleDirection(&text); |
| 601 | 602 |
| 602 menu->AppendMenuItem(i + kFirstMenuItemId, text, MenuItemView::NORMAL); | 603 menu->AppendMenuItem(i + kFirstMenuItemId, text, MenuItemView::NORMAL); |
| 603 max_width = std::max(max_width, font.GetStringWidth(text)); | 604 max_width = std::max(max_width, font.GetStringWidth(text)); |
| 604 } | 605 } |
| 605 | 606 |
| 606 content_size_.SetSize(max_width, font.GetHeight()); | 607 content_size_.SetSize(max_width, font.GetHeight()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 629 int y = insets.top(); | 630 int y = insets.top(); |
| 630 int text_height = height() - insets.height(); | 631 int text_height = height() - insets.height(); |
| 631 SkColor text_color = invalid() ? kInvalidTextColor : | 632 SkColor text_color = invalid() ? kInvalidTextColor : |
| 632 GetNativeTheme()->GetSystemColor( | 633 GetNativeTheme()->GetSystemColor( |
| 633 ui::NativeTheme::kColorId_LabelEnabledColor); | 634 ui::NativeTheme::kColorId_LabelEnabledColor); |
| 634 | 635 |
| 635 DCHECK_GE(selected_index_, 0); | 636 DCHECK_GE(selected_index_, 0); |
| 636 DCHECK_LT(selected_index_, model()->GetItemCount()); | 637 DCHECK_LT(selected_index_, model()->GetItemCount()); |
| 637 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) | 638 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) |
| 638 selected_index_ = 0; | 639 selected_index_ = 0; |
| 639 string16 text = model()->GetItemAt(selected_index_); | 640 base::string16 text = model()->GetItemAt(selected_index_); |
| 640 | 641 |
| 641 int disclosure_arrow_offset = width() - disclosure_arrow_->width() - | 642 int disclosure_arrow_offset = width() - disclosure_arrow_->width() - |
| 642 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding(); | 643 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding(); |
| 643 | 644 |
| 644 const gfx::Font& font = Combobox::GetFont(); | 645 const gfx::Font& font = Combobox::GetFont(); |
| 645 int text_width = font.GetStringWidth(text); | 646 int text_width = font.GetStringWidth(text); |
| 646 if ((text_width + insets.width()) > disclosure_arrow_offset) | 647 if ((text_width + insets.width()) > disclosure_arrow_offset) |
| 647 text_width = disclosure_arrow_offset - insets.width(); | 648 text_width = disclosure_arrow_offset - insets.width(); |
| 648 | 649 |
| 649 gfx::Rect text_bounds(x, y, text_width, text_height); | 650 gfx::Rect text_bounds(x, y, text_width, text_height); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 | 811 |
| 811 void Combobox::HandleClickEvent() { | 812 void Combobox::HandleClickEvent() { |
| 812 if (style_ != STYLE_NOTIFY_ON_CLICK) | 813 if (style_ != STYLE_NOTIFY_ON_CLICK) |
| 813 return; | 814 return; |
| 814 | 815 |
| 815 if (listener_) | 816 if (listener_) |
| 816 listener_->OnComboboxTextButtonClicked(this); | 817 listener_->OnComboboxTextButtonClicked(this); |
| 817 } | 818 } |
| 818 | 819 |
| 819 } // namespace views | 820 } // namespace views |
| OLD | NEW |