Chromium Code Reviews| 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 |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 weak_ptr_factory_(this) { | 400 weak_ptr_factory_(this) { |
| 401 ModelChanged(); | 401 ModelChanged(); |
| 402 #if defined(OS_MACOSX) | 402 #if defined(OS_MACOSX) |
| 403 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 403 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 404 #else | 404 #else |
| 405 SetFocusBehavior(FocusBehavior::ALWAYS); | 405 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 406 #endif | 406 #endif |
| 407 | 407 |
| 408 UpdateBorder(); | 408 UpdateBorder(); |
| 409 // set_background() takes ownership but takes a raw pointer. | 409 // set_background() takes ownership but takes a raw pointer. |
| 410 std::unique_ptr<Background> b = | 410 if (!UseMd()) { |
| 411 PlatformStyle::CreateComboboxBackground(GetArrowContainerWidth()); | 411 std::unique_ptr<Background> b = |
| 412 set_background(b.release()); | 412 PlatformStyle::CreateComboboxBackground(GetArrowContainerWidth()); |
| 413 set_background(b.release()); | |
| 414 } | |
| 413 | 415 |
| 414 // Initialize the button images. | 416 // Initialize the button images. |
| 415 Button::ButtonState button_states[] = { | 417 Button::ButtonState button_states[] = { |
| 416 Button::STATE_DISABLED, | 418 Button::STATE_DISABLED, |
| 417 Button::STATE_NORMAL, | 419 Button::STATE_NORMAL, |
| 418 Button::STATE_HOVERED, | 420 Button::STATE_HOVERED, |
| 419 Button::STATE_PRESSED, | 421 Button::STATE_PRESSED, |
| 420 }; | 422 }; |
| 421 for (int i = 0; i < 2; i++) { | 423 for (int i = 0; i < 2; i++) { |
| 422 for (size_t state_index = 0; state_index < arraysize(button_states); | 424 for (size_t state_index = 0; state_index < arraysize(button_states); |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 | 783 |
| 782 int disclosure_arrow_offset = width() - GetArrowContainerWidth(); | 784 int disclosure_arrow_offset = width() - GetArrowContainerWidth(); |
| 783 | 785 |
| 784 const gfx::FontList& font_list = Combobox::GetFontList(); | 786 const gfx::FontList& font_list = Combobox::GetFontList(); |
| 785 int text_width = gfx::GetStringWidth(text, font_list); | 787 int text_width = gfx::GetStringWidth(text, font_list); |
| 786 if ((text_width + insets.width()) > disclosure_arrow_offset) | 788 if ((text_width + insets.width()) > disclosure_arrow_offset) |
| 787 text_width = disclosure_arrow_offset - insets.width(); | 789 text_width = disclosure_arrow_offset - insets.width(); |
| 788 | 790 |
| 789 gfx::Rect text_bounds(x, y, text_width, text_height); | 791 gfx::Rect text_bounds(x, y, text_width, text_height); |
| 790 AdjustBoundsForRTLUI(&text_bounds); | 792 AdjustBoundsForRTLUI(&text_bounds); |
| 793 // TODO(ellyjones): This doesn't seem right. There's no particular reason why | |
| 794 // the text should need the rectangle underneath it filled first while none of | |
| 795 // the other drawn things need that. Also, drawing over with | |
| 796 // SK_ColorTRANSPARENT doesn't seem to suffice. Why? | |
| 797 if (UseMd()) | |
| 798 canvas->FillRect(text_bounds, SK_ColorWHITE); | |
| 791 canvas->DrawStringRect(text, font_list, text_color, text_bounds); | 799 canvas->DrawStringRect(text, font_list, text_color, text_bounds); |
| 792 | 800 |
| 793 gfx::Rect arrow_bounds(disclosure_arrow_offset, 0, GetArrowContainerWidth(), | 801 gfx::Rect arrow_bounds(disclosure_arrow_offset, 0, GetArrowContainerWidth(), |
| 794 height()); | 802 height()); |
| 795 arrow_bounds = | 803 arrow_bounds = |
| 796 PositionArrowWithinContainer(arrow_bounds, ArrowSize(), style_); | 804 PositionArrowWithinContainer(arrow_bounds, ArrowSize(), style_); |
| 797 AdjustBoundsForRTLUI(&arrow_bounds); | 805 AdjustBoundsForRTLUI(&arrow_bounds); |
| 798 | 806 |
| 799 if (UseMd()) { | 807 if (UseMd()) { |
| 800 // Since this is a core piece of UI and vector icons don't handle fractional | 808 // Since this is a core piece of UI and vector icons don't handle fractional |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 return gfx::Size(width, font_list.GetHeight()); | 969 return gfx::Size(width, font_list.GetHeight()); |
| 962 } | 970 } |
| 963 | 971 |
| 964 PrefixSelector* Combobox::GetPrefixSelector() { | 972 PrefixSelector* Combobox::GetPrefixSelector() { |
| 965 if (!selector_) | 973 if (!selector_) |
| 966 selector_.reset(new PrefixSelector(this, this)); | 974 selector_.reset(new PrefixSelector(this, this)); |
| 967 return selector_.get(); | 975 return selector_.get(); |
| 968 } | 976 } |
| 969 | 977 |
| 970 int Combobox::GetArrowContainerWidth() const { | 978 int Combobox::GetArrowContainerWidth() const { |
| 979 const int kMdPaddingWidth = 8; | |
|
Evan Stade
2016/09/07 17:24:43
this change seems fine
| |
| 980 int arrow_pad = UseMd() ? kMdPaddingWidth | |
| 981 : PlatformStyle::kComboboxNormalArrowPadding; | |
| 971 int padding = style_ == STYLE_NORMAL | 982 int padding = style_ == STYLE_NORMAL |
| 972 ? PlatformStyle::kComboboxNormalArrowPadding * 2 | 983 ? arrow_pad * 2 |
| 973 : kActionLeftPadding + kActionRightPadding; | 984 : kActionLeftPadding + kActionRightPadding; |
| 974 return ArrowSize().width() + padding; | 985 return ArrowSize().width() + padding; |
| 975 } | 986 } |
| 976 | 987 |
| 977 } // namespace views | 988 } // namespace views |
| OLD | NEW |