Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure ink drops on menu bar buttons #7397

Merged
merged 3 commits into from Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion atom/browser/ui/views/menu_bar.cc
Expand Up @@ -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)
Expand Down
39 changes: 37 additions & 2 deletions atom/browser/ui/views/submenu_button.cc
Expand Up @@ -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 {
Expand All @@ -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),
Expand All @@ -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()));
Expand All @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion atom/browser/ui/views/submenu_button.h
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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);
};
Expand Down