| 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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 arrow_button_->SetVisible(true); | 445 arrow_button_->SetVisible(true); |
| 446 AddChildView(text_button_); | 446 AddChildView(text_button_); |
| 447 AddChildView(arrow_button_); | 447 AddChildView(arrow_button_); |
| 448 | 448 |
| 449 // A layer is applied to make sure that canvas bounds are snapped to pixel | 449 // A layer is applied to make sure that canvas bounds are snapped to pixel |
| 450 // boundaries (for the sake of drawing the arrow). | 450 // boundaries (for the sake of drawing the arrow). |
| 451 if (UseMd()) { | 451 if (UseMd()) { |
| 452 SetPaintToLayer(); | 452 SetPaintToLayer(); |
| 453 layer()->SetFillsBoundsOpaquely(false); | 453 layer()->SetFillsBoundsOpaquely(false); |
| 454 } else { | 454 } else { |
| 455 arrow_image_ = PlatformStyle::CreateComboboxArrow(enabled(), style); | 455 arrow_image_ = *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 456 IDR_MENU_DROPARROW); |
| 456 } | 457 } |
| 457 } | 458 } |
| 458 | 459 |
| 459 Combobox::~Combobox() { | 460 Combobox::~Combobox() { |
| 460 if (GetInputMethod() && selector_.get()) { | 461 if (GetInputMethod() && selector_.get()) { |
| 461 // Combobox should have been blurred before destroy. | 462 // Combobox should have been blurred before destroy. |
| 462 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); | 463 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); |
| 463 } | 464 } |
| 464 } | 465 } |
| 465 | 466 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 text_button_width = width() - arrow_button_width; | 544 text_button_width = width() - arrow_button_width; |
| 544 break; | 545 break; |
| 545 } | 546 } |
| 546 } | 547 } |
| 547 | 548 |
| 548 int arrow_button_x = std::max(0, text_button_width); | 549 int arrow_button_x = std::max(0, text_button_width); |
| 549 text_button_->SetBounds(0, 0, std::max(0, text_button_width), height()); | 550 text_button_->SetBounds(0, 0, std::max(0, text_button_width), height()); |
| 550 arrow_button_->SetBounds(arrow_button_x, 0, arrow_button_width, height()); | 551 arrow_button_->SetBounds(arrow_button_x, 0, arrow_button_width, height()); |
| 551 } | 552 } |
| 552 | 553 |
| 553 void Combobox::OnEnabledChanged() { | |
| 554 View::OnEnabledChanged(); | |
| 555 if (!UseMd()) | |
| 556 arrow_image_ = PlatformStyle::CreateComboboxArrow(enabled(), style_); | |
| 557 } | |
| 558 | |
| 559 void Combobox::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 554 void Combobox::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 560 if (!UseMd()) | 555 if (!UseMd()) |
| 561 return; | 556 return; |
| 562 | 557 |
| 563 set_background( | 558 set_background( |
| 564 Background::CreateBackgroundPainter(Painter::CreateSolidRoundRectPainter( | 559 Background::CreateBackgroundPainter(Painter::CreateSolidRoundRectPainter( |
| 565 theme->GetSystemColor( | 560 theme->GetSystemColor( |
| 566 ui::NativeTheme::kColorId_TextfieldDefaultBackground), | 561 ui::NativeTheme::kColorId_TextfieldDefaultBackground), |
| 567 FocusableBorder::kCornerRadiusDp))); | 562 FocusableBorder::kCornerRadiusDp))); |
| 568 } | 563 } |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 return gfx::Size(width, font_list.GetHeight()); | 1001 return gfx::Size(width, font_list.GetHeight()); |
| 1007 } | 1002 } |
| 1008 | 1003 |
| 1009 PrefixSelector* Combobox::GetPrefixSelector() { | 1004 PrefixSelector* Combobox::GetPrefixSelector() { |
| 1010 if (!selector_) | 1005 if (!selector_) |
| 1011 selector_.reset(new PrefixSelector(this, this)); | 1006 selector_.reset(new PrefixSelector(this, this)); |
| 1012 return selector_.get(); | 1007 return selector_.get(); |
| 1013 } | 1008 } |
| 1014 | 1009 |
| 1015 int Combobox::GetArrowContainerWidth() const { | 1010 int Combobox::GetArrowContainerWidth() const { |
| 1016 const int kMdPaddingWidth = 8; | 1011 constexpr int kMdPaddingWidth = 8; |
| 1017 int arrow_pad = UseMd() ? kMdPaddingWidth | 1012 constexpr int kNormalPaddingWidth = 7; |
| 1018 : PlatformStyle::kComboboxNormalArrowPadding; | 1013 int arrow_pad = UseMd() ? kMdPaddingWidth : kNormalPaddingWidth; |
| 1019 int padding = style_ == STYLE_NORMAL | 1014 int padding = style_ == STYLE_NORMAL |
| 1020 ? arrow_pad * 2 | 1015 ? arrow_pad * 2 |
| 1021 : kActionLeftPadding + kActionRightPadding; | 1016 : kActionLeftPadding + kActionRightPadding; |
| 1022 return ArrowSize().width() + padding; | 1017 return ArrowSize().width() + padding; |
| 1023 } | 1018 } |
| 1024 | 1019 |
| 1025 } // namespace views | 1020 } // namespace views |
| OLD | NEW |