Skip to content

Commit

Permalink
Enables hot-tracking for overflow extension buttons in the app menu
Browse files Browse the repository at this point in the history
BUG=583559

Review URL: https://codereview.chromium.org/1661673004

Cr-Commit-Position: refs/heads/master@{#377999}
  • Loading branch information
varkha authored and Commit bot committed Feb 26, 2016
1 parent 3f55de7 commit ef6637f
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 74 deletions.
1 change: 1 addition & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@
'../ui/gfx/gfx.gyp:gfx_vector_icons',
'../ui/keyboard/keyboard.gyp:keyboard',
'../ui/message_center/message_center.gyp:message_center',
'../ui/native_theme/native_theme.gyp:native_theme',
'../ui/platform_window/stub/stub_window.gyp:stub_window',
'../ui/resources/ui_resources.gyp:ui_resources',
'../ui/strings/ui_strings.gyp:ui_strings',
Expand Down
7 changes: 6 additions & 1 deletion chrome/browser/ui/libgtk2ui/native_theme_gtk2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void NativeThemeGtk2::PaintMenuItemBackground(
SkCanvas* canvas,
State state,
const gfx::Rect& rect,
const MenuListExtraParams& menu_list) const {
const MenuItemExtraParams& menu_item) const {
SkColor color;
SkPaint paint;
switch (state) {
Expand All @@ -217,6 +217,11 @@ void NativeThemeGtk2::PaintMenuItemBackground(
NOTREACHED() << "Invalid state " << state;
break;
}
if (menu_item.corner_radius > 0) {
const SkScalar radius = SkIntToScalar(menu_item.corner_radius);
canvas->drawRoundRect(gfx::RectToSkRect(rect), radius, radius, paint);
return;
}
canvas->drawRect(gfx::RectToSkRect(rect), paint);
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/libgtk2ui/native_theme_gtk2.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NativeThemeGtk2 : public ui::NativeThemeBase {
SkCanvas* canvas,
State state,
const gfx::Rect& rect,
const MenuListExtraParams& menu_list) const override;
const MenuItemExtraParams& menu_item) const override;

// Gets a ChromeGtkFrame theme color; returns true on success. Always returns
// false in GTK3.
Expand Down
48 changes: 37 additions & 11 deletions chrome/browser/ui/views/toolbar/app_menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "third_party/skia/include/core/SkPaint.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font_list.h"
Expand Down Expand Up @@ -131,10 +132,20 @@ class FullscreenButton : public ImageButton {
class InMenuButtonBackground : public views::Background {
public:
enum ButtonType {
// A rectangular button with no neighbor on the left.
LEFT_BUTTON,

// A rectangular button with neighbors on both sides.
CENTER_BUTTON,

// A rectangular button with no neighbor on the right.
RIGHT_BUTTON,

// A rectangular button that is not a member in a group.
SINGLE_BUTTON,

// A button with no group neighbors and a rounded background.
ROUNDED_BUTTON,
};

explicit InMenuButtonBackground(ButtonType type)
Expand All @@ -161,14 +172,15 @@ class InMenuButtonBackground : public views::Background {
int h = view->height();

// Normal buttons get a border drawn on the right side and the rest gets
// filled in. The left button however does not get a line to combine
// buttons.
if (type_ != RIGHT_BUTTON) {
// filled in. The left or rounded buttons however do not get a line to
// combine buttons.
gfx::Rect bounds(view->GetLocalBounds());
if (type_ != RIGHT_BUTTON && type_ != ROUNDED_BUTTON) {
canvas->FillRect(gfx::Rect(0, 0, 1, h),
BorderColor(view, views::Button::STATE_NORMAL));
bounds.Inset(gfx::Insets(0, 1, 0, 0));
}

gfx::Rect bounds(view->GetLocalBounds());
bounds.set_x(view->GetMirroredXForRect(bounds));
DrawBackground(canvas, view, bounds, state);
}
Expand Down Expand Up @@ -213,11 +225,15 @@ class InMenuButtonBackground : public views::Background {
views::Button::ButtonState state) const {
if (state == views::Button::STATE_HOVERED ||
state == views::Button::STATE_PRESSED) {
ui::NativeTheme::ExtraParams params;
if (type_ == ROUNDED_BUTTON) {
// Consistent with a hover corner radius (kInkDropSmallCornerRadius).
const int kBackgroundCornerRadius = 2;
params.menu_item.corner_radius = kBackgroundCornerRadius;
}
view->GetNativeTheme()->Paint(canvas->sk_canvas(),
ui::NativeTheme::kMenuItemBackground,
ui::NativeTheme::kHovered,
bounds,
ui::NativeTheme::ExtraParams());
ui::NativeTheme::kHovered, bounds, params);
}
}

Expand Down Expand Up @@ -1137,11 +1153,21 @@ void AppMenu::PopulateMenu(MenuItemView* parent, MenuModel* model) {
case IDC_EXTENSIONS_OVERFLOW_MENU: {
scoped_ptr<ExtensionToolbarMenuView> extension_toolbar(
new ExtensionToolbarMenuView(browser_, this));
extension_toolbar_ = extension_toolbar.get();
if (extension_toolbar->ShouldShow())
item->AddChildView(extension_toolbar.release());
else
if (!extension_toolbar->ShouldShow()) {
item->SetVisible(false);
extension_toolbar_ = nullptr;
break;
}
if (ui::MaterialDesignController::IsModeMaterial()) {
for (int i = 0; i < extension_toolbar->contents()->child_count();
++i) {
View* action_view = extension_toolbar->contents()->child_at(i);
action_view->set_background(new InMenuButtonBackground(
InMenuButtonBackground::ROUNDED_BUTTON));
}
}
extension_toolbar_ = extension_toolbar.get();
item->AddChildView(extension_toolbar.release());
break;
}

Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/ui/views/toolbar/toolbar_action_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ SkColor ToolbarActionView::GetInkDropBaseColor() const {
ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
}

bool ToolbarActionView::ShouldShowInkDropHover() const {
return !delegate_->ShownInsideMenu() &&
views::MenuButton::ShouldShowInkDropHover();
}

content::WebContents* ToolbarActionView::GetCurrentWebContents() const {
return delegate_->GetCurrentWebContents();
}
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/views/toolbar/toolbar_action_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ToolbarActionView : public views::MenuButton,
void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
SkColor GetInkDropBaseColor() const override;
bool ShouldShowInkDropHover() const override;

// ToolbarActionViewDelegateViews:
content::WebContents* GetCurrentWebContents() const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,8 @@ void ActivateOverflowedActionWithKeyboard(Browser* browser,
gfx::NativeWindow native_window =
views::MenuController::GetActiveInstance()->owner()->GetNativeWindow();

// Send two key down events followed by the return key.
// The two key down events target the toolbar action in the app menu.
// TODO(devlin): Shouldn't this be one key down event?
ui_controls::SendKeyPress(native_window,
ui::VKEY_DOWN,
false, false, false, false);
// Send a key down event followed by the return key.
// The key down event targets the toolbar action in the app menu.
ui_controls::SendKeyPress(native_window,
ui::VKEY_DOWN,
false, false, false, false);
Expand Down
13 changes: 10 additions & 3 deletions ui/native_theme/common_theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,11 @@ void CommonThemePaintMenuBackground(SkCanvas* canvas, const gfx::Rect& rect) {
canvas->drawRect(gfx::RectToSkRect(rect), paint);
}

void CommonThemePaintMenuItemBackground(SkCanvas* canvas,
NativeTheme::State state,
const gfx::Rect& rect) {
void CommonThemePaintMenuItemBackground(
SkCanvas* canvas,
NativeTheme::State state,
const gfx::Rect& rect,
const NativeTheme::MenuItemExtraParams& menu_item) {
SkPaint paint;
switch (state) {
case NativeTheme::kNormal:
Expand All @@ -478,6 +480,11 @@ void CommonThemePaintMenuItemBackground(SkCanvas* canvas,
NOTREACHED() << "Invalid state " << state;
break;
}
if (menu_item.corner_radius > 0) {
const SkScalar radius = SkIntToScalar(menu_item.corner_radius);
canvas->drawRoundRect(gfx::RectToSkRect(rect), radius, radius, paint);
return;
}
canvas->drawRect(gfx::RectToSkRect(rect), paint);
}

Expand Down
3 changes: 2 additions & 1 deletion ui/native_theme/common_theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void NATIVE_THEME_EXPORT CommonThemePaintMenuBackground(SkCanvas* canvas,
void NATIVE_THEME_EXPORT CommonThemePaintMenuItemBackground(
SkCanvas* canvas,
NativeTheme::State state,
const gfx::Rect& rect);
const gfx::Rect& rect,
const NativeTheme::MenuItemExtraParams& menu_item);

// Creates a gfx::Canvas wrapping an SkCanvas.
scoped_ptr<gfx::Canvas> NATIVE_THEME_EXPORT CommonThemeCreateCanvas(
Expand Down
6 changes: 6 additions & 0 deletions ui/native_theme/native_theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

#include "ui/native_theme/native_theme.h"

#include <cstring>

#include "ui/native_theme/native_theme_observer.h"

namespace ui {

NativeTheme::ExtraParams::ExtraParams() {
memset(this, 0, sizeof(*this));
}

void NativeTheme::SetScrollbarColors(unsigned inactive_color,
unsigned active_color,
unsigned track_color) {
Expand Down
5 changes: 4 additions & 1 deletion ui/native_theme/native_theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class NATIVE_THEME_EXPORT NativeTheme {

struct MenuItemExtraParams {
bool is_selected;
int corner_radius;
};

struct MenuListExtraParams {
Expand Down Expand Up @@ -196,7 +197,9 @@ class NATIVE_THEME_EXPORT NativeTheme {
int classic_state; // Used on Windows when uxtheme is not available.
};

union ExtraParams {
union NATIVE_THEME_EXPORT ExtraParams {
ExtraParams();

ButtonExtraParams button;
InnerSpinButtonExtraParams inner_spin;
MenuArrowExtraParams menu_arrow;
Expand Down
4 changes: 2 additions & 2 deletions ui/native_theme/native_theme_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ void NativeThemeAura::PaintMenuItemBackground(
SkCanvas* canvas,
State state,
const gfx::Rect& rect,
const MenuListExtraParams& menu_list) const {
CommonThemePaintMenuItemBackground(canvas, state, rect);
const MenuItemExtraParams& menu_item) const {
CommonThemePaintMenuItemBackground(canvas, state, rect, menu_item);
}

void NativeThemeAura::PaintArrowButton(SkCanvas* canvas,
Expand Down
2 changes: 1 addition & 1 deletion ui/native_theme/native_theme_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NATIVE_THEME_EXPORT NativeThemeAura : public NativeThemeBase {
SkCanvas* canvas,
State state,
const gfx::Rect& rect,
const MenuListExtraParams& menu_list) const override;
const MenuItemExtraParams& menu_item) const override;
void PaintArrowButton(SkCanvas* gc,
const gfx::Rect& rect,
Part direction,
Expand Down
4 changes: 2 additions & 2 deletions ui/native_theme/native_theme_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void NativeThemeBase::Paint(SkCanvas* canvas,
PaintMenuPopupBackground(canvas, rect.size(), extra.menu_background);
break;
case kMenuItemBackground:
PaintMenuItemBackground(canvas, state, rect, extra.menu_list);
PaintMenuItemBackground(canvas, state, rect, extra.menu_item);
break;
case kProgressBar:
PaintProgressBar(canvas, state, rect, extra.progress_bar);
Expand Down Expand Up @@ -792,7 +792,7 @@ void NativeThemeBase::PaintMenuItemBackground(
SkCanvas* canvas,
State state,
const gfx::Rect& rect,
const MenuListExtraParams& menu_list) const {
const MenuItemExtraParams& menu_item) const {
// By default don't draw anything over the normal background.
}

Expand Down
2 changes: 1 addition & 1 deletion ui/native_theme/native_theme_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme {
SkCanvas* canvas,
State state,
const gfx::Rect& rect,
const MenuListExtraParams& menu_list) const;
const MenuItemExtraParams& menu_item) const;

virtual void PaintSliderTrack(
SkCanvas* canvas,
Expand Down
2 changes: 1 addition & 1 deletion ui/native_theme/native_theme_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase {
SkCanvas* canvas,
State state,
const gfx::Rect& rect,
const MenuListExtraParams& menu_list) const override;
const MenuItemExtraParams& menu_item) const override;

private:
NativeThemeMac();
Expand Down
2 changes: 1 addition & 1 deletion ui/native_theme/native_theme_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ SkColor NSSystemColorToSkColor(NSColor* color) {
SkCanvas* canvas,
State state,
const gfx::Rect& rect,
const MenuListExtraParams& menu_list) const {
const MenuItemExtraParams& menu_item) const {
SkPaint paint;
switch (state) {
case NativeTheme::kNormal:
Expand Down
2 changes: 1 addition & 1 deletion ui/native_theme/native_theme_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void NativeThemeWin::Paint(SkCanvas* canvas,
CommonThemePaintMenuBackground(canvas, rect);
return;
case kMenuItemBackground:
CommonThemePaintMenuItemBackground(canvas, state, rect);
CommonThemePaintMenuItemBackground(canvas, state, rect, extra.menu_item);
return;
default:
break;
Expand Down
8 changes: 4 additions & 4 deletions ui/views/controls/button/custom_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ bool CustomButton::ShouldEnterHoveredState() {
return check_mouse_position && IsMouseHovered();
}

bool CustomButton::ShouldShowInkDropHover() const {
return enabled() && IsMouseHovered() && !InDrag();
}

////////////////////////////////////////////////////////////////////////////////
// CustomButton, View overrides (protected):

Expand All @@ -425,8 +429,4 @@ void CustomButton::OnClickCanceled(const ui::Event& event) {
Button::OnClickCanceled(event);
}

bool CustomButton::ShouldShowInkDropHover() const {
return enabled() && IsMouseHovered() && !InDrag();
}

} // namespace views
5 changes: 3 additions & 2 deletions ui/views/controls/button/custom_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class VIEWS_EXPORT CustomButton : public Button, public gfx::AnimationDelegate {
// we simply return IsTriggerableEvent(event).
virtual bool ShouldEnterPushedState(const ui::Event& event);

// Returns true if hover effect should be visible.
virtual bool ShouldShowInkDropHover() const;

void set_has_ink_drop_action_on_click(bool has_ink_drop_action_on_click) {
has_ink_drop_action_on_click_ = has_ink_drop_action_on_click;
}
Expand Down Expand Up @@ -151,8 +154,6 @@ class VIEWS_EXPORT CustomButton : public Button, public gfx::AnimationDelegate {
}

private:
bool ShouldShowInkDropHover() const;

ButtonState state_;

gfx::ThrobAnimation hover_animation_;
Expand Down
Loading

0 comments on commit ef6637f

Please sign in to comment.