| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "ui/accessibility/ax_view_state.h" | 14 #include "ui/accessibility/ax_view_state.h" |
| 15 #include "ui/base/default_style.h" | 15 #include "ui/base/default_style.h" |
| 16 #include "ui/base/ime/input_method.h" | 16 #include "ui/base/ime/input_method.h" |
| 17 #include "ui/base/models/combobox_model.h" | 17 #include "ui/base/models/combobox_model.h" |
| 18 #include "ui/base/models/combobox_model_observer.h" | 18 #include "ui/base/models/combobox_model_observer.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
| 21 #include "ui/gfx/animation/throb_animation.h" | 21 #include "ui/gfx/animation/throb_animation.h" |
| 22 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 23 #include "ui/gfx/color_palette.h" | 23 #include "ui/gfx/color_palette.h" |
| 24 #include "ui/gfx/scoped_canvas.h" | 24 #include "ui/gfx/scoped_canvas.h" |
| 25 #include "ui/gfx/text_utils.h" | 25 #include "ui/gfx/text_utils.h" |
| 26 #include "ui/native_theme/common_theme.h" | 26 #include "ui/native_theme/common_theme.h" |
| 27 #include "ui/native_theme/native_theme.h" | 27 #include "ui/native_theme/native_theme.h" |
| 28 #include "ui/native_theme/native_theme_aura.h" | 28 #include "ui/native_theme/native_theme_aura.h" |
| 29 #include "ui/resources/grit/ui_resources.h" | 29 #include "ui/resources/grit/ui_resources.h" |
| 30 #include "ui/views/background.h" |
| 30 #include "ui/views/controls/button/custom_button.h" | 31 #include "ui/views/controls/button/custom_button.h" |
| 31 #include "ui/views/controls/button/label_button.h" | 32 #include "ui/views/controls/button/label_button.h" |
| 32 #include "ui/views/controls/combobox/combobox_listener.h" | 33 #include "ui/views/controls/combobox/combobox_listener.h" |
| 33 #include "ui/views/controls/focusable_border.h" | 34 #include "ui/views/controls/focusable_border.h" |
| 34 #include "ui/views/controls/menu/menu_config.h" | 35 #include "ui/views/controls/menu/menu_config.h" |
| 35 #include "ui/views/controls/menu/menu_runner.h" | 36 #include "ui/views/controls/menu/menu_runner.h" |
| 36 #include "ui/views/controls/prefix_selector.h" | 37 #include "ui/views/controls/prefix_selector.h" |
| 37 #include "ui/views/controls/textfield/textfield.h" | 38 #include "ui/views/controls/textfield/textfield.h" |
| 38 #include "ui/views/mouse_constants.h" | 39 #include "ui/views/mouse_constants.h" |
| 39 #include "ui/views/painter.h" | 40 #include "ui/views/painter.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 listener_(NULL), | 348 listener_(NULL), |
| 348 selected_index_(model_->GetDefaultIndex()), | 349 selected_index_(model_->GetDefaultIndex()), |
| 349 invalid_(false), | 350 invalid_(false), |
| 350 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), | 351 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), |
| 351 text_button_(new TransparentButton(this)), | 352 text_button_(new TransparentButton(this)), |
| 352 arrow_button_(new TransparentButton(this)), | 353 arrow_button_(new TransparentButton(this)), |
| 353 weak_ptr_factory_(this) { | 354 weak_ptr_factory_(this) { |
| 354 ModelChanged(); | 355 ModelChanged(); |
| 355 SetFocusable(true); | 356 SetFocusable(true); |
| 356 UpdateBorder(); | 357 UpdateBorder(); |
| 358 // set_background() takes ownership but takes a raw pointer. |
| 359 scoped_ptr<Background> b = PlatformStyle::CreateComboboxBackground(); |
| 360 set_background(b.release()); |
| 357 | 361 |
| 358 // Initialize the button images. | 362 // Initialize the button images. |
| 359 Button::ButtonState button_states[] = { | 363 Button::ButtonState button_states[] = { |
| 360 Button::STATE_DISABLED, | 364 Button::STATE_DISABLED, |
| 361 Button::STATE_NORMAL, | 365 Button::STATE_NORMAL, |
| 362 Button::STATE_HOVERED, | 366 Button::STATE_HOVERED, |
| 363 Button::STATE_PRESSED, | 367 Button::STATE_PRESSED, |
| 364 }; | 368 }; |
| 365 for (int i = 0; i < 2; i++) { | 369 for (int i = 0; i < 2; i++) { |
| 366 for (size_t state_index = 0; state_index < arraysize(button_states); | 370 for (size_t state_index = 0; state_index < arraysize(button_states); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 void Combobox::SetInvalid(bool invalid) { | 454 void Combobox::SetInvalid(bool invalid) { |
| 451 if (invalid == invalid_) | 455 if (invalid == invalid_) |
| 452 return; | 456 return; |
| 453 | 457 |
| 454 invalid_ = invalid; | 458 invalid_ = invalid; |
| 455 | 459 |
| 456 UpdateBorder(); | 460 UpdateBorder(); |
| 457 SchedulePaint(); | 461 SchedulePaint(); |
| 458 } | 462 } |
| 459 | 463 |
| 464 int Combobox::GetArrowButtonWidth() const { |
| 465 return GetDisclosureArrowLeftPadding() + |
| 466 ArrowSize().width() + |
| 467 GetDisclosureArrowRightPadding(); |
| 468 } |
| 469 |
| 460 void Combobox::Layout() { | 470 void Combobox::Layout() { |
| 461 PrefixDelegate::Layout(); | 471 PrefixDelegate::Layout(); |
| 462 | 472 |
| 463 gfx::Insets insets = GetInsets(); | 473 gfx::Insets insets = GetInsets(); |
| 464 int text_button_width = 0; | 474 int text_button_width = 0; |
| 465 int arrow_button_width = 0; | 475 int arrow_button_width = 0; |
| 466 | 476 |
| 467 switch (style_) { | 477 switch (style_) { |
| 468 case STYLE_NORMAL: { | 478 case STYLE_NORMAL: { |
| 469 arrow_button_width = width(); | 479 arrow_button_width = width(); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 gfx::Insets insets = GetInsets(); | 716 gfx::Insets insets = GetInsets(); |
| 707 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding); | 717 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding); |
| 708 | 718 |
| 709 gfx::ScopedCanvas scoped_canvas(canvas); | 719 gfx::ScopedCanvas scoped_canvas(canvas); |
| 710 canvas->ClipRect(GetContentsBounds()); | 720 canvas->ClipRect(GetContentsBounds()); |
| 711 | 721 |
| 712 int x = insets.left(); | 722 int x = insets.left(); |
| 713 int y = insets.top(); | 723 int y = insets.top(); |
| 714 int text_height = height() - insets.height(); | 724 int text_height = height() - insets.height(); |
| 715 SkColor text_color = GetNativeTheme()->GetSystemColor( | 725 SkColor text_color = GetNativeTheme()->GetSystemColor( |
| 716 ui::NativeTheme::kColorId_LabelEnabledColor); | 726 enabled() ? ui::NativeTheme::kColorId_LabelEnabledColor : |
| 727 ui::NativeTheme::kColorId_LabelDisabledColor); |
| 717 | 728 |
| 718 DCHECK_GE(selected_index_, 0); | 729 DCHECK_GE(selected_index_, 0); |
| 719 DCHECK_LT(selected_index_, model()->GetItemCount()); | 730 DCHECK_LT(selected_index_, model()->GetItemCount()); |
| 720 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) | 731 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) |
| 721 selected_index_ = 0; | 732 selected_index_ = 0; |
| 722 base::string16 text = model()->GetItemAt(selected_index_); | 733 base::string16 text = model()->GetItemAt(selected_index_); |
| 723 | 734 |
| 724 gfx::Size arrow_size = ArrowSize(); | 735 gfx::Size arrow_size = ArrowSize(); |
| 725 int disclosure_arrow_offset = width() - arrow_size.width() - | 736 int disclosure_arrow_offset = width() - arrow_size.width() - |
| 726 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding(); | 737 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding(); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 return gfx::Size(width, font_list.GetHeight()); | 939 return gfx::Size(width, font_list.GetHeight()); |
| 929 } | 940 } |
| 930 | 941 |
| 931 PrefixSelector* Combobox::GetPrefixSelector() { | 942 PrefixSelector* Combobox::GetPrefixSelector() { |
| 932 if (!selector_) | 943 if (!selector_) |
| 933 selector_.reset(new PrefixSelector(this)); | 944 selector_.reset(new PrefixSelector(this)); |
| 934 return selector_.get(); | 945 return selector_.get(); |
| 935 } | 946 } |
| 936 | 947 |
| 937 } // namespace views | 948 } // namespace views |
| OLD | NEW |