Skip to content

Commit

Permalink
[ash-md] Applied correct shape/masking to all ink drops in the system…
Browse files Browse the repository at this point in the history
… menu.

This change introduces factory functions in TrayPopupUtils to create the
ink drop parts for all system menu ink drops according to an InkDropStyle enum
and updates all target-able system menu views to use the new factory functions.

The user visible change is that all system menu ink drops should now have the
correct size and shape. This is most visible on the INSET_BOUNDS style ink drops
which will be drawn as a rounded rect with a 2 dp rounded corner.

BUG=666078, 662972, 662951, 658819, 658731, 663007, 663001, 658822

Review-Url: https://codereview.chromium.org/2501693005
Cr-Commit-Position: refs/heads/master@{#432803}
  • Loading branch information
bruthig-chromium authored and Commit bot committed Nov 17, 2016
1 parent 19cccca commit 1e373d4
Show file tree
Hide file tree
Showing 29 changed files with 314 additions and 147 deletions.
1 change: 1 addition & 0 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ component("ash") {
"common/system/tray/tray_notification_view.h",
"common/system/tray/tray_popup_header_button.cc",
"common/system/tray/tray_popup_header_button.h",
"common/system/tray/tray_popup_ink_drop_style.h",
"common/system/tray/tray_popup_item_container.cc",
"common/system/tray/tray_popup_item_container.h",
"common/system/tray/tray_popup_item_style.cc",
Expand Down
7 changes: 5 additions & 2 deletions ash/common/system/chromeos/audio/volume_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class VolumeButton : public ButtonListenerActionableView {
VolumeButton(SystemTrayItem* owner,
views::ButtonListener* listener,
system::TrayAudioDelegate* audio_delegate)
: ButtonListenerActionableView(owner, listener),
: ButtonListenerActionableView(owner,
TrayPopupInkDropStyle::INSET_BOUNDS,
listener),
audio_delegate_(audio_delegate),
image_(TrayPopupUtils::CreateMainImageView()),
image_index_(-1) {
Expand Down Expand Up @@ -177,7 +179,8 @@ VolumeView::VolumeView(SystemTrayItem* owner,
return;
}

more_button_ = new ButtonListenerActionableView(owner_, this);
more_button_ = new ButtonListenerActionableView(
owner_, TrayPopupInkDropStyle::INSET_BOUNDS, this);
TrayPopupUtils::ConfigureContainer(TriView::Container::END, more_button_);
more_button_->SetFocusBehavior(FocusBehavior::NEVER);

Expand Down
3 changes: 2 additions & 1 deletion ash/common/system/chromeos/ime_menu/ime_list_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class ImeListItemView : public ActionableView {
const base::string16& label,
bool selected,
const SkColor button_color)
: ActionableView(owner), ime_list_view_(list_view) {
: ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS),
ime_list_view_(list_view) {
if (MaterialDesignController::IsSystemTrayMenuMaterial())
SetInkDropMode(InkDropHostView::InkDropMode::ON);

Expand Down
5 changes: 2 additions & 3 deletions ash/common/system/chromeos/ime_menu/ime_menu_tray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ SystemMenuButton* CreateImeMenuButton(views::ButtonListener* listener,
const gfx::VectorIcon& icon,
int accessible_name_id,
int right_border) {
SystemMenuButton* button =
new SystemMenuButton(listener, SystemMenuButton::InkDropStyle::SQUARE,
icon, accessible_name_id);
SystemMenuButton* button = new SystemMenuButton(
listener, TrayPopupInkDropStyle::HOST_CENTERED, icon, accessible_name_id);
if (!MaterialDesignController::IsShelfMaterial()) {
button->SetBorder(
views::CreateSolidSidedBorder(0, 0, 0, right_border, kBorderDarkColor));
Expand Down
2 changes: 1 addition & 1 deletion ash/common/system/chromeos/network/network_list_md.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class WifiHeaderRowView : public NetworkListViewMd::SectionHeaderRowView {
gfx::ImageSkia disabled_image = network_icon::GetImageForNewWifiNetwork(
SkColorSetA(prominent_color, kDisabledJoinIconAlpha),
SkColorSetA(prominent_color, kDisabledJoinBadgeAlpha));
join_ = new SystemMenuButton(this, SystemMenuButton::InkDropStyle::SQUARE,
join_ = new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED,
normal_image, disabled_image,
IDS_ASH_STATUS_TRAY_OTHER_WIFI);
join_->set_ink_drop_base_color(prominent_color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,14 @@ void NetworkStateListDetailedView::CreateExtraTitleRowButtons() {
tri_view()->SetContainerVisible(TriView::Container::END, true);

info_button_md_ = new SystemMenuButton(
this, SystemMenuButton::InkDropStyle::SQUARE, kSystemMenuInfoIcon,
this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuInfoIcon,
IDS_ASH_STATUS_TRAY_NETWORK_INFO);
tri_view()->AddView(TriView::Container::END, info_button_md_);

if (login_ != LoginStatus::NOT_LOGGED_IN) {
DCHECK(!settings_button_md_);
settings_button_md_ = new SystemMenuButton(
this, SystemMenuButton::InkDropStyle::SQUARE, kSystemMenuSettingsIcon,
this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuSettingsIcon,
IDS_ASH_STATUS_TRAY_NETWORK_SETTINGS);

// Allow the user to access settings only if user is logged in
Expand All @@ -505,7 +505,7 @@ void NetworkStateListDetailedView::CreateExtraTitleRowButtons() {
tri_view()->AddView(TriView::Container::END, settings_button_md_);
} else {
proxy_settings_button_md_ = new SystemMenuButton(
this, SystemMenuButton::InkDropStyle::SQUARE, kSystemMenuSettingsIcon,
this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuSettingsIcon,
IDS_ASH_STATUS_TRAY_NETWORK_PROXY_SETTINGS);
title_row()->AddViewToTitleRow(proxy_settings_button_md_);
}
Expand Down
2 changes: 1 addition & 1 deletion ash/common/system/chromeos/settings/tray_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SettingsDefaultView : public ActionableView,
public PowerStatus::Observer {
public:
SettingsDefaultView(SystemTrayItem* owner, LoginStatus status)
: ActionableView(owner),
: ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS),
login_status_(status),
label_(nullptr),
power_status_view_(nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion ash/common/system/chromeos/tray_caps_lock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool CapsLockIsEnabled() {
class CapsLockDefaultView : public ActionableView {
public:
CapsLockDefaultView()
: ActionableView(nullptr),
: ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS),
image_(TrayPopupUtils::CreateMainImageView()),
text_label_(TrayPopupUtils::CreateDefaultLabel()),
shortcut_label_(TrayPopupUtils::CreateDefaultLabel()) {
Expand Down
3 changes: 2 additions & 1 deletion ash/common/system/chromeos/tray_tracing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace tray {

class DefaultTracingView : public ActionableView {
public:
explicit DefaultTracingView(SystemTrayItem* owner) : ActionableView(owner) {
explicit DefaultTracingView(SystemTrayItem* owner)
: ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS) {
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();

SetLayoutManager(new views::FillLayout);
Expand Down
2 changes: 1 addition & 1 deletion ash/common/system/date/date_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void BaseDateTimeView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
}

BaseDateTimeView::BaseDateTimeView(SystemTrayItem* owner)
: ActionableView(owner),
: ActionableView(owner, TrayPopupInkDropStyle::INSET_BOUNDS),
hour_type_(WmShell::Get()->system_tray_controller()->hour_clock_type()) {
SetTimer(base::Time::Now());
SetFocusBehavior(FocusBehavior::NEVER);
Expand Down
8 changes: 4 additions & 4 deletions ash/common/system/tiles/tiles_default_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ void TilesDefaultView::Init() {
const bool disable_buttons = !TrayPopupUtils::CanOpenWebUISettings(login_);

settings_button_ = new SystemMenuButton(
this, SystemMenuButton::InkDropStyle::FLOOD_FILL, kSystemMenuSettingsIcon,
this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuSettingsIcon,
IDS_ASH_STATUS_TRAY_SETTINGS);
if (disable_buttons || !shell->system_tray_delegate()->ShouldShowSettings())
settings_button_->SetState(views::Button::STATE_DISABLED);
AddChildView(settings_button_);
AddChildView(TrayPopupUtils::CreateVerticalSeparator());

help_button_ =
new SystemMenuButton(this, SystemMenuButton::InkDropStyle::FLOOD_FILL,
new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED,
kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP);
if (base::i18n::IsRTL() &&
base::i18n::GetConfiguredLocale() == kHebrewLocale) {
Expand All @@ -89,7 +89,7 @@ void TilesDefaultView::Init() {

#if !defined(OS_WIN)
lock_button_ =
new SystemMenuButton(this, SystemMenuButton::InkDropStyle::FLOOD_FILL,
new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED,
kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK);
if (disable_buttons || !shell->GetSessionStateDelegate()->CanLockScreen())
lock_button_->SetState(views::Button::STATE_DISABLED);
Expand All @@ -98,7 +98,7 @@ void TilesDefaultView::Init() {
AddChildView(TrayPopupUtils::CreateVerticalSeparator());

power_button_ =
new SystemMenuButton(this, SystemMenuButton::InkDropStyle::FLOOD_FILL,
new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED,
kSystemMenuPowerIcon, IDS_ASH_STATUS_TRAY_SHUTDOWN);
AddChildView(power_button_);
// This object is recreated every time the menu opens. Don't bother updating
Expand Down
34 changes: 18 additions & 16 deletions ash/common/system/tray/actionable_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@
#include "ash/common/system/tray/system_tray.h"
#include "ash/common/system/tray/system_tray_item.h"
#include "ash/common/system/tray/tray_constants.h"
#include "ash/common/system/tray/tray_popup_utils.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h"

namespace ash {

// static
const char ActionableView::kViewClassName[] = "tray/ActionableView";

ActionableView::ActionableView(SystemTrayItem* owner)
: views::CustomButton(this), destroyed_(nullptr), owner_(owner) {
ActionableView::ActionableView(SystemTrayItem* owner,
TrayPopupInkDropStyle ink_drop_style)
: views::CustomButton(this),
destroyed_(nullptr),
owner_(owner),
ink_drop_style_(ink_drop_style) {
SetFocusBehavior(FocusBehavior::ALWAYS);
set_ink_drop_base_color(kTrayPopupInkDropBaseColor);
set_ink_drop_visible_opacity(kTrayPopupInkDropRippleOpacity);
Expand Down Expand Up @@ -92,27 +98,22 @@ void ActionableView::OnBlur() {
}

std::unique_ptr<views::InkDrop> ActionableView::CreateInkDrop() {
std::unique_ptr<views::InkDropImpl> ink_drop =
CreateDefaultFloodFillInkDropImpl();
ink_drop->SetShowHighlightOnHover(false);
return std::move(ink_drop);
return TrayPopupUtils::CreateInkDrop(ink_drop_style_, this);
}

std::unique_ptr<views::InkDropRipple> ActionableView::CreateInkDropRipple()
const {
return base::MakeUnique<views::FloodFillInkDropRipple>(
GetLocalBounds(), GetInkDropCenterBasedOnLastEvent(),
GetInkDropBaseColor(), ink_drop_visible_opacity());
return TrayPopupUtils::CreateInkDropRipple(
ink_drop_style_, this, GetInkDropCenterBasedOnLastEvent());
}

std::unique_ptr<views::InkDropHighlight>
ActionableView::CreateInkDropHighlight() const {
std::unique_ptr<views::InkDropHighlight> highlight(
new views::InkDropHighlight(size(), 0,
gfx::RectF(GetLocalBounds()).CenterPoint(),
GetInkDropBaseColor()));
highlight->set_visible_opacity(kTrayPopupInkDropHighlightOpacity);
return highlight;
return TrayPopupUtils::CreateInkDropHighlight(ink_drop_style_, this);
}

std::unique_ptr<views::InkDropMask> ActionableView::CreateInkDropMask() const {
return TrayPopupUtils::CreateInkDropMask(ink_drop_style_, this);
}

void ActionableView::CloseSystemBubble() {
Expand All @@ -133,8 +134,9 @@ void ActionableView::ButtonPressed(Button* sender, const ui::Event& event) {

ButtonListenerActionableView::ButtonListenerActionableView(
SystemTrayItem* owner,
TrayPopupInkDropStyle ink_drop_style,
views::ButtonListener* listener)
: ActionableView(owner), listener_(listener) {}
: ActionableView(owner, ink_drop_style), listener_(listener) {}

bool ButtonListenerActionableView::PerformAction(const ui::Event& event) {
listener_->ButtonPressed(this, event);
Expand Down
8 changes: 7 additions & 1 deletion ash/common/system/tray/actionable_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ASH_COMMON_SYSTEM_TRAY_ACTIONABLE_VIEW_H_

#include "ash/ash_export.h"
#include "ash/common/system/tray/tray_popup_ink_drop_style.h"
#include "base/macros.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/controls/button/custom_button.h"
Expand All @@ -29,7 +30,7 @@ class ASH_EXPORT ActionableView : public views::ButtonListener,

// The owner is used to close the system tray bubble. Can be null if
// the action will not close the bubble.
explicit ActionableView(SystemTrayItem* owner);
ActionableView(SystemTrayItem* owner, TrayPopupInkDropStyle ink_drop_style);

~ActionableView() override;

Expand Down Expand Up @@ -71,6 +72,7 @@ class ASH_EXPORT ActionableView : public views::ButtonListener,
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;

// Overridden from views::ButtonListener.
void ButtonPressed(Button* sender, const ui::Event& event) override;
Expand All @@ -85,6 +87,9 @@ class ASH_EXPORT ActionableView : public views::ButtonListener,

base::string16 accessible_name_;

// Defines the flavor of ink drop ripple/highlight that should be constructed.
TrayPopupInkDropStyle ink_drop_style_;

DISALLOW_COPY_AND_ASSIGN(ActionableView);
};

Expand All @@ -93,6 +98,7 @@ class ASH_EXPORT ActionableView : public views::ButtonListener,
class ASH_EXPORT ButtonListenerActionableView : public ActionableView {
public:
ButtonListenerActionableView(SystemTrayItem* owner,
TrayPopupInkDropStyle ink_drop_style,
views::ButtonListener* listener);

// ActionableView:
Expand Down
2 changes: 1 addition & 1 deletion ash/common/system/tray/hover_highlight_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const gfx::FontList& GetFontList(bool highlight) {
namespace ash {

HoverHighlightView::HoverHighlightView(ViewClickListener* listener)
: ActionableView(nullptr),
: ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS),
listener_(listener),
highlight_color_(kHoverBackgroundColor) {
set_notify_enter_exit_on_child(true);
Expand Down
54 changes: 11 additions & 43 deletions ash/common/system/tray/system_menu_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
#include "ash/common/ash_constants.h"
#include "ash/common/system/tray/system_tray.h"
#include "ash/common/system/tray/tray_constants.h"
#include "ash/common/system/tray/tray_popup_utils.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/animation/square_ink_drop_ripple.h"
#include "ui/views/border.h"
#include "ui/views/painter.h"

namespace ash {

SystemMenuButton::SystemMenuButton(views::ButtonListener* listener,
InkDropStyle ink_drop_style,
TrayPopupInkDropStyle ink_drop_style,
gfx::ImageSkia normal_icon,
gfx::ImageSkia disabled_icon,
int accessible_name_id)
Expand Down Expand Up @@ -50,7 +52,7 @@ SystemMenuButton::SystemMenuButton(views::ButtonListener* listener,
}

SystemMenuButton::SystemMenuButton(views::ButtonListener* listener,
InkDropStyle ink_drop_style,
TrayPopupInkDropStyle ink_drop_style,
const gfx::VectorIcon& icon,
int accessible_name_id)
: SystemMenuButton(listener,
Expand All @@ -62,57 +64,23 @@ SystemMenuButton::SystemMenuButton(views::ButtonListener* listener,
SystemMenuButton::~SystemMenuButton() {}

std::unique_ptr<views::InkDrop> SystemMenuButton::CreateInkDrop() {
std::unique_ptr<views::InkDropImpl> ink_drop =
CreateDefaultFloodFillInkDropImpl();
ink_drop->SetShowHighlightOnHover(false);
return std::move(ink_drop);
return TrayPopupUtils::CreateInkDrop(ink_drop_style_, this);
}

std::unique_ptr<views::InkDropRipple> SystemMenuButton::CreateInkDropRipple()
const {
const gfx::Size size = GetInkDropSize();
switch (ink_drop_style_) {
case InkDropStyle::SQUARE:
return base::MakeUnique<views::SquareInkDropRipple>(
size, size.width() / 2, size, size.width() / 2,
GetInkDropCenterBasedOnLastEvent(), GetLocalBounds().CenterPoint(),
GetInkDropBaseColor(), ink_drop_visible_opacity());
case InkDropStyle::FLOOD_FILL:
gfx::Rect bounds = GetLocalBounds();
bounds.Inset(kTrayPopupInkDropInset, kTrayPopupInkDropInset);
return base::MakeUnique<views::FloodFillInkDropRipple>(
bounds, GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(),
ink_drop_visible_opacity());
}
// Required for some compilers.
NOTREACHED();
return nullptr;
return TrayPopupUtils::CreateInkDropRipple(
ink_drop_style_, this, GetInkDropCenterBasedOnLastEvent());
}

std::unique_ptr<views::InkDropHighlight>
SystemMenuButton::CreateInkDropHighlight() const {
int highlight_radius = 0;
switch (ink_drop_style_) {
case InkDropStyle::SQUARE:
highlight_radius = GetInkDropSize().width() / 2;
break;
case InkDropStyle::FLOOD_FILL:
highlight_radius = 0;
break;
}

std::unique_ptr<views::InkDropHighlight> highlight(
new views::InkDropHighlight(GetInkDropSize(), highlight_radius,
gfx::RectF(GetLocalBounds()).CenterPoint(),
GetInkDropBaseColor()));
highlight->set_visible_opacity(kTrayPopupInkDropHighlightOpacity);
return highlight;
return TrayPopupUtils::CreateInkDropHighlight(ink_drop_style_, this);
}

gfx::Size SystemMenuButton::GetInkDropSize() const {
gfx::Rect bounds = GetLocalBounds();
bounds.Inset(kTrayPopupInkDropInset, kTrayPopupInkDropInset);
return bounds.size();
std::unique_ptr<views::InkDropMask> SystemMenuButton::CreateInkDropMask()
const {
return TrayPopupUtils::CreateInkDropMask(ink_drop_style_, this);
}

} // namespace ash
Loading

0 comments on commit 1e373d4

Please sign in to comment.