Configure ink drops on menu bar buttons (#7397)

* Add ink drop to menu bar buttons

* Pass background color to submenu button

* Sort includes
This commit is contained in:
Kevin Sawicki 2016-09-29 09:15:12 -07:00 committed by GitHub
parent df0bda058f
commit b3b9994ce8
3 changed files with 51 additions and 4 deletions

View file

@ -63,7 +63,10 @@ void MenuBar::SetMenu(AtomMenuModel* model) {
RemoveAllChildViews(true);
for (int i = 0; i < model->GetItemCount(); ++i) {
SubmenuButton* button = new SubmenuButton(this, model->GetLabelAt(i), this);
SubmenuButton* button = new SubmenuButton(this,
model->GetLabelAt(i),
this,
background_color_);
button->set_tag(i);
#if defined(USE_X11)

View file

@ -7,7 +7,10 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/text_utils.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_host_view.h"
#include "ui/views/controls/button/label_button_border.h"
namespace atom {
@ -25,7 +28,8 @@ base::string16 FilterAccelerator(const base::string16& label) {
SubmenuButton::SubmenuButton(views::ButtonListener* listener,
const base::string16& title,
views::MenuButtonListener* menu_button_listener)
views::MenuButtonListener* menu_button_listener,
const SkColor& background_color)
: views::MenuButton(FilterAccelerator(title),
menu_button_listener, false),
accelerator_(0),
@ -34,7 +38,8 @@ SubmenuButton::SubmenuButton(views::ButtonListener* listener,
underline_end_(-1),
text_width_(0),
text_height_(0),
underline_color_(SK_ColorBLACK) {
underline_color_(SK_ColorBLACK),
background_color_(background_color) {
#if defined(OS_LINUX)
// Dont' use native style border.
SetBorder(std::move(CreateDefaultBorder()));
@ -44,11 +49,41 @@ SubmenuButton::SubmenuButton(views::ButtonListener* listener,
&underline_end_))
gfx::Canvas::SizeStringInt(GetText(), GetFontList(), &text_width_,
&text_height_, 0, 0);
SetHasInkDrop(true);
set_ink_drop_base_color(
color_utils::BlendTowardOppositeLuma(background_color_, 0x61));
}
SubmenuButton::~SubmenuButton() {
}
std::unique_ptr<views::InkDropRipple> SubmenuButton::CreateInkDropRipple()
const {
return base::MakeUnique<views::FloodFillInkDropRipple>(
GetLocalBounds(),
GetInkDropCenterBasedOnLastEvent(),
GetInkDropBaseColor(),
ink_drop_visible_opacity());
}
std::unique_ptr<views::InkDropHighlight>
SubmenuButton::CreateInkDropHighlight() const {
if (!ShouldShowInkDropHighlight())
return nullptr;
gfx::Size size = GetLocalBounds().size();
return base::MakeUnique<views::InkDropHighlight>(
size,
kInkDropSmallCornerRadius,
gfx::RectF(gfx::SizeF(size)).CenterPoint(),
GetInkDropBaseColor());
}
bool SubmenuButton::ShouldShowInkDropForFocus() const {
return false;
}
void SubmenuButton::SetAcceleratorVisibility(bool visible) {
if (visible == show_underline_)
return;

View file

@ -5,6 +5,7 @@
#ifndef ATOM_BROWSER_UI_VIEWS_SUBMENU_BUTTON_H_
#define ATOM_BROWSER_UI_VIEWS_SUBMENU_BUTTON_H_
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/controls/button/menu_button.h"
namespace atom {
@ -14,7 +15,8 @@ class SubmenuButton : public views::MenuButton {
public:
SubmenuButton(views::ButtonListener* listener,
const base::string16& title,
views::MenuButtonListener* menu_button_listener);
views::MenuButtonListener* menu_button_listener,
const SkColor& background_color);
virtual ~SubmenuButton();
void SetAcceleratorVisibility(bool visible);
@ -28,6 +30,12 @@ class SubmenuButton : public views::MenuButton {
// views::MenuButton:
void OnPaint(gfx::Canvas* canvas) override;
// views::InkDropHostView:
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override;
bool ShouldShowInkDropForFocus() const override;
private:
bool GetUnderlinePosition(const base::string16& text,
base::char16* accelerator,
@ -44,6 +52,7 @@ class SubmenuButton : public views::MenuButton {
int text_width_;
int text_height_;
SkColor underline_color_;
SkColor background_color_;
DISALLOW_COPY_AND_ASSIGN(SubmenuButton);
};