Chromium Code Reviews| Index: ui/views/controls/button/menu_button.cc |
| diff --git a/ui/views/controls/button/menu_button.cc b/ui/views/controls/button/menu_button.cc |
| index 4d1a1b9728157e8581a4ec725a94de28183a7715..83f2a64be9baf17028154646b35c5f8aeb36bbb2 100644 |
| --- a/ui/views/controls/button/menu_button.cc |
| +++ b/ui/views/controls/button/menu_button.cc |
| @@ -21,8 +21,10 @@ |
| #include "ui/views/animation/ink_drop_delegate.h" |
| #include "ui/views/controls/button/button.h" |
| #include "ui/views/controls/button/menu_button_listener.h" |
| +#include "ui/views/controls/focusable_border.h" |
| #include "ui/views/mouse_constants.h" |
| #include "ui/views/resources/grit/views_resources.h" |
| +#include "ui/views/style/platform_style.h" |
| #include "ui/views/widget/root_view.h" |
| #include "ui/views/widget/widget.h" |
| @@ -37,8 +39,6 @@ static const int kDefaultMenuOffsetY = -4; |
| // static |
| const char MenuButton::kViewClassName[] = "MenuButton"; |
| -const int MenuButton::kMenuMarkerPaddingLeft = 3; |
| -const int MenuButton::kMenuMarkerPaddingRight = -1; |
| //////////////////////////////////////////////////////////////////////////////// |
| // |
| @@ -73,15 +73,15 @@ MenuButton::MenuButton(const base::string16& text, |
| menu_offset_(kDefaultMenuOffsetX, kDefaultMenuOffsetY), |
| listener_(menu_button_listener), |
| show_menu_marker_(show_menu_marker), |
| - menu_marker_(ui::ResourceBundle::GetSharedInstance() |
| - .GetImageNamed(IDR_MENU_DROPARROW) |
| - .ToImageSkia()), |
| destroyed_flag_(nullptr), |
| pressed_lock_count_(0), |
| increment_pressed_lock_called_(nullptr), |
| should_disable_after_press_(false), |
| weak_factory_(this) { |
| SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + if (show_menu_marker_) { |
|
tapted
2016/05/09 08:01:35
just call OnEnabledChanged
|
| + menu_marker_ = PlatformStyle::CreateMenuButtonArrow(enabled()); |
| + } |
| } |
| MenuButton::~MenuButton() { |
| @@ -198,11 +198,7 @@ void MenuButton::OnPaint(gfx::Canvas* canvas) { |
| gfx::Size MenuButton::GetPreferredSize() const { |
| gfx::Size prefsize = LabelButton::GetPreferredSize(); |
| - if (show_menu_marker_) { |
| - prefsize.Enlarge(menu_marker_->width() + kMenuMarkerPaddingLeft + |
| - kMenuMarkerPaddingRight, |
| - 0); |
| - } |
| + prefsize.Enlarge(GetShoulderWidth(), 0); |
| return prefsize; |
| } |
| @@ -311,29 +307,44 @@ void MenuButton::GetAccessibleState(ui::AXViewState* state) { |
| state->AddStateFlag(ui::AX_STATE_HASPOPUP); |
| } |
| +void MenuButton::OnEnabledChanged() { |
| + if (show_menu_marker_) |
| + menu_marker_ = PlatformStyle::CreateMenuButtonArrow(enabled()); |
|
tapted
2016/05/09 08:01:35
So now the background is not unexpectedly blue, th
|
| + LabelButton::OnEnabledChanged(); |
| +} |
| + |
| +void MenuButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| + LabelButton::OnNativeThemeChanged(theme); |
| + if (ShouldUsePlatformStyleBackground()) { |
| + set_background(PlatformStyle::CreateMenuButtonBackground(GetShoulderWidth()) |
| + .release()); |
| + } |
| + if (ShouldUsePlatformStyleBorder()) |
|
tapted
2016/05/09 08:01:35
There's still an issue with this. MenuButton inher
|
| + SetBorder(PlatformStyle::CreateMenuButtonBorder()); |
| +} |
| + |
| void MenuButton::PaintMenuMarker(gfx::Canvas* canvas) { |
| gfx::Insets insets = GetInsets(); |
| // Using the Views mirroring infrastructure incorrectly flips icon content. |
| // Instead, manually mirror the position of the down arrow. |
| - gfx::Rect arrow_bounds(width() - insets.right() - |
| - menu_marker_->width() - kMenuMarkerPaddingRight, |
| - height() / 2 - menu_marker_->height() / 2, |
| - menu_marker_->width(), |
| - menu_marker_->height()); |
| + gfx::Rect arrow_bounds(width() - GetShoulderWidth(), 0, GetShoulderWidth(), |
| + height()); |
| + arrow_bounds.ClampToCenteredSize(menu_marker_.size()); |
| arrow_bounds.set_x(GetMirroredXForRect(arrow_bounds)); |
| - canvas->DrawImageInt(*menu_marker_, arrow_bounds.x(), arrow_bounds.y()); |
| + canvas->DrawImageInt(menu_marker_, arrow_bounds.x(), arrow_bounds.y()); |
| } |
| -gfx::Rect MenuButton::GetChildAreaBounds() { |
| - gfx::Size s = size(); |
| +bool MenuButton::ShouldUsePlatformStyleBackground() const { |
| + return true; |
| +} |
| - if (show_menu_marker_) { |
| - s.set_width(s.width() - menu_marker_->width() - kMenuMarkerPaddingLeft - |
| - kMenuMarkerPaddingRight); |
| - } |
| +bool MenuButton::ShouldUsePlatformStyleBorder() const { |
| + return true; |
| +} |
| - return gfx::Rect(s); |
| +gfx::Rect MenuButton::GetChildAreaBounds() { |
| + return gfx::Rect(width() - GetShoulderWidth(), height()); |
| } |
| bool MenuButton::IsTriggerableEvent(const ui::Event& event) { |
| @@ -415,4 +426,11 @@ int MenuButton::GetMaximumScreenXCoordinate() { |
| return monitor_bounds.right() - 1; |
| } |
| +int MenuButton::GetShoulderWidth() const { |
| + const int kPadding = 7; |
| + if (!show_menu_marker_) |
| + return 0; |
| + return menu_marker_.width() + 2 * kPadding; |
| +} |
| + |
| } // namespace views |