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

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: only cache one arrow image 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..fd3b76d2ad7a568b23bed4465fc1f6c72a7a35eb 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"
@@ -73,15 +75,18 @@ 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());
tapted 2016/04/27 03:25:11 The issue with the MenuButton subclass used for th
Elly Fong-Jones 2016/04/28 17:03:12 Ick. Whether the subclasses need borders or not se
+ if (show_menu_marker_) {
+ marker_image_ = PlatformStyle::CreateMenuButtonArrow(enabled());
+ set_background(PlatformStyle::CreateMenuButtonBackground(GetShoulderWidth())
+ .release());
+ }
}
MenuButton::~MenuButton() {
@@ -196,13 +201,16 @@ void MenuButton::OnPaint(gfx::Canvas* canvas) {
//
////////////////////////////////////////////////////////////////////////////////
+int MenuButton::GetShoulderWidth() const {
tapted 2016/04/27 03:25:11 move definition to end of file
Elly Fong-Jones 2016/04/28 17:03:11 Done.
+ const int kPadding = 7;
+ if (!show_menu_marker_)
+ return 0;
+ return marker_image_.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);
- }
+ prefsize.Enlarge(GetShoulderWidth(), 0);
return prefsize;
}
@@ -311,29 +319,26 @@ void MenuButton::GetAccessibleState(ui::AXViewState* state) {
state->AddStateFlag(ui::AX_STATE_HASPOPUP);
}
+void MenuButton::OnEnabledChanged() {
+ if (show_menu_marker_)
+ marker_image_ = PlatformStyle::CreateMenuButtonArrow(enabled());
+ LabelButton::OnEnabledChanged();
+}
+
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() - insets.right() - GetShoulderWidth(), 0,
+ GetShoulderWidth(), height());
+ arrow_bounds.ClampToCenteredSize(marker_image_.size());
arrow_bounds.set_x(GetMirroredXForRect(arrow_bounds));
- canvas->DrawImageInt(*menu_marker_, arrow_bounds.x(), arrow_bounds.y());
+ canvas->DrawImageInt(marker_image_, 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);
- }
-
- return gfx::Rect(s);
+ return gfx::Rect(width() - GetShoulderWidth(), height());
}
bool MenuButton::IsTriggerableEvent(const ui::Event& event) {

Powered by Google App Engine
This is Rietveld 408576698