Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: ui/views/controls/button/menu_button.cc

Issue 1904753002: MenuButton: support Mac look & feel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cache arrow images Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..815306fb1fcefe670031fe78dd99afa9730ce136 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"
tapted 2016/04/26 05:05:57 is this still needed?
Elly Fong-Jones 2016/04/26 17:41:25 It seems to be needed so that the destructor can d
tapted 2016/04/27 03:25:11 Ah, that's subtle. I think we could have PlatformS
#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"
@@ -73,15 +75,19 @@ 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);
+ SetBorder(PlatformStyle::CreateMenuButtonBorder());
+ if (show_menu_marker_) {
+ enabled_marker_image_ = PlatformStyle::CreateMenuButtonArrow(true);
+ disabled_marker_image_ = PlatformStyle::CreateMenuButtonArrow(false);
+ set_background(PlatformStyle::CreateMenuButtonBackground(GetShoulderWidth())
+ .release());
+ }
}
MenuButton::~MenuButton() {
@@ -196,13 +202,17 @@ void MenuButton::OnPaint(gfx::Canvas* canvas) {
//
////////////////////////////////////////////////////////////////////////////////
+int MenuButton::GetShoulderWidth() const {
+ const int kPadding = 7;
+ int marker_width = enabled() ? enabled_marker_image_.size().width()
tapted 2016/04/26 05:05:57 nit: remove ".size()" I think we can also do if
Elly Fong-Jones 2016/04/26 17:41:25 Done.
+ : disabled_marker_image_.size().width();
+ return marker_width + 2 * kPadding;
+}
+
gfx::Size MenuButton::GetPreferredSize() const {
gfx::Size prefsize = LabelButton::GetPreferredSize();
- if (show_menu_marker_) {
- prefsize.Enlarge(menu_marker_->width() + kMenuMarkerPaddingLeft +
- kMenuMarkerPaddingRight,
- 0);
- }
+ if (show_menu_marker_)
+ prefsize.Enlarge(GetShoulderWidth(), 0);
return prefsize;
}
@@ -316,22 +326,20 @@ void MenuButton::PaintMenuMarker(gfx::Canvas* canvas) {
// 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() - insets.right() - GetShoulderWidth(), 0,
+ GetShoulderWidth(), height());
+ gfx::ImageSkia marker =
+ enabled() ? enabled_marker_image_ : disabled_marker_image_;
+ arrow_bounds.ClampToCenteredSize(marker.size());
arrow_bounds.set_x(GetMirroredXForRect(arrow_bounds));
- canvas->DrawImageInt(*menu_marker_, arrow_bounds.x(), arrow_bounds.y());
+ canvas->DrawImageInt(marker, arrow_bounds.x(), arrow_bounds.y());
}
gfx::Rect MenuButton::GetChildAreaBounds() {
gfx::Size s = size();
- if (show_menu_marker_) {
- s.set_width(s.width() - menu_marker_->width() - kMenuMarkerPaddingLeft -
- kMenuMarkerPaddingRight);
- }
+ if (show_menu_marker_)
tapted 2016/04/26 05:05:57 not needed with the GetShoulderWidth() tweak. In f
Elly Fong-Jones 2016/04/26 17:41:25 Done.
+ s.set_width(s.width() - GetShoulderWidth());
return gfx::Rect(s);
}

Powered by Google App Engine
This is Rietveld 408576698