blob: e7944aa513b71bd44d6707dc75e278501b5420cf [file] [log] [blame]
[email protected]dfd64f02013-08-30 02:17:321// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]7e846442012-08-07 04:22:342// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
jamescook775aa6072017-03-05 06:11:585#include "ash/shelf/overflow_button.h"
[email protected]7e846442012-08-07 04:22:346
estade1b92771b2017-01-10 04:51:207#include "ash/resources/vector_icons/vector_icons.h"
jamescook775aa6072017-03-05 06:11:588#include "ash/shelf/shelf_constants.h"
9#include "ash/shelf/shelf_view.h"
10#include "ash/shelf/wm_shelf.h"
jamescooke45f8112017-03-02 16:45:4211#include "ash/strings/grit/ash_strings.h"
mohsen623c7e42016-09-16 18:45:3812#include "base/memory/ptr_util.h"
[email protected]7e846442012-08-07 04:22:3413#include "ui/base/l10n/l10n_util.h"
[email protected]7e846442012-08-07 04:22:3414#include "ui/gfx/canvas.h"
[email protected]e9edd002013-08-10 15:19:2415#include "ui/gfx/image/image_skia_operations.h"
tdanderson4f0032c2016-06-10 04:33:1516#include "ui/gfx/paint_vector_icon.h"
[email protected]e9edd002013-08-10 15:19:2417#include "ui/gfx/skbitmap_operations.h"
mohsen623c7e42016-09-16 18:45:3818#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
bruthigca8b19cd2016-11-08 02:53:5519#include "ui/views/animation/ink_drop_impl.h"
mohsen6cc1f1f2016-11-24 05:15:0920#include "ui/views/animation/ink_drop_mask.h"
[email protected]7e846442012-08-07 04:22:3421
22namespace ash {
[email protected]7e846442012-08-07 04:22:3423
jamescook65ae2bb2016-08-11 22:44:3624OverflowButton::OverflowButton(ShelfView* shelf_view, WmShelf* wm_shelf)
mohsen497110a2016-06-16 19:29:3125 : CustomButton(nullptr),
jamescook65ae2bb2016-08-11 22:44:3626 shelf_view_(shelf_view),
bruthiga2239af2016-08-02 17:07:2927 wm_shelf_(wm_shelf),
bruthig33189d22017-02-25 18:54:2128 background_color_(kShelfDefaultBaseColor) {
jamescook65ae2bb2016-08-11 22:44:3629 DCHECK(shelf_view_);
mohsen4116d2392017-02-28 19:06:2930
31 SetInkDropMode(InkDropMode::ON);
32 set_ink_drop_base_color(kShelfInkDropBaseColor);
33 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
34 set_hide_ink_drop_when_showing_context_menu(false);
35 bottom_image_ = gfx::CreateVectorIcon(kShelfOverflowIcon, kShelfIconColor);
[email protected]7e846442012-08-07 04:22:3436
karandeepbe7ad02a2016-04-27 23:57:2237 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
[email protected]81dd43d2013-08-06 05:58:2738 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME));
[email protected]7e846442012-08-07 04:22:3439}
40
[email protected]81dd43d2013-08-06 05:58:2741OverflowButton::~OverflowButton() {}
[email protected]7e846442012-08-07 04:22:3442
[email protected]1fcfb992012-12-05 01:47:2343void OverflowButton::OnShelfAlignmentChanged() {
[email protected]7e846442012-08-07 04:22:3444 SchedulePaint();
45}
46
mohsen623c7e42016-09-16 18:45:3847void OverflowButton::OnOverflowBubbleShown() {
48 AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr);
mohsen623c7e42016-09-16 18:45:3849}
50
51void OverflowButton::OnOverflowBubbleHidden() {
52 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr);
mohsen623c7e42016-09-16 18:45:3853}
54
bruthig33189d22017-02-25 18:54:2155void OverflowButton::UpdateShelfItemBackground(SkColor color) {
56 background_color_ = color;
bruthiga2239af2016-08-02 17:07:2957 SchedulePaint();
58}
59
tdanderson992a5652016-06-08 23:10:3260void OverflowButton::OnPaint(gfx::Canvas* canvas) {
61 gfx::Rect bounds = CalculateButtonBounds();
62 PaintBackground(canvas, bounds);
63 PaintForeground(canvas, bounds);
[email protected]7e846442012-08-07 04:22:3464}
65
bruthigca8b19cd2016-11-08 02:53:5566std::unique_ptr<views::InkDrop> OverflowButton::CreateInkDrop() {
mohseneb659d92016-11-15 01:04:1567 std::unique_ptr<views::InkDropImpl> ink_drop =
68 CreateDefaultFloodFillInkDropImpl();
69 ink_drop->SetShowHighlightOnHover(false);
70 ink_drop->SetAutoHighlightMode(views::InkDropImpl::AutoHighlightMode::NONE);
71 return std::move(ink_drop);
bruthigca8b19cd2016-11-08 02:53:5572}
73
mohsen623c7e42016-09-16 18:45:3874std::unique_ptr<views::InkDropRipple> OverflowButton::CreateInkDropRipple()
75 const {
mohsen7dfd81cc2016-11-29 16:08:0076 gfx::Insets insets = GetLocalBounds().InsetsFrom(CalculateButtonBounds());
mohsen623c7e42016-09-16 18:45:3877 return base::MakeUnique<views::FloodFillInkDropRipple>(
mohsen7dfd81cc2016-11-29 16:08:0078 size(), insets, GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(),
79 ink_drop_visible_opacity());
mohsen623c7e42016-09-16 18:45:3880}
81
82bool OverflowButton::ShouldEnterPushedState(const ui::Event& event) {
83 if (shelf_view_->IsShowingOverflowBubble())
84 return false;
85
86 return CustomButton::ShouldEnterPushedState(event);
87}
88
mohsen497110a2016-06-16 19:29:3189void OverflowButton::NotifyClick(const ui::Event& event) {
90 CustomButton::NotifyClick(event);
bruthig25b329d2016-11-04 19:43:5191 shelf_view_->ButtonPressed(this, event, GetInkDrop());
mohsen497110a2016-06-16 19:29:3192}
93
mohsen6cc1f1f2016-11-24 05:15:0994std::unique_ptr<views::InkDropMask> OverflowButton::CreateInkDropMask() const {
95 gfx::Insets insets = GetLocalBounds().InsetsFrom(CalculateButtonBounds());
96 return base::MakeUnique<views::RoundRectInkDropMask>(
97 size(), insets, kOverflowButtonCornerRadius);
98}
99
tdanderson992a5652016-06-08 23:10:32100void OverflowButton::PaintBackground(gfx::Canvas* canvas,
101 const gfx::Rect& bounds) {
mohsen4116d2392017-02-28 19:06:29102 cc::PaintFlags flags;
103 flags.setFlags(cc::PaintFlags::kAntiAlias_Flag);
104 flags.setColor(background_color_);
105 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, flags);
tdanderson992a5652016-06-08 23:10:32106}
[email protected]7e846442012-08-07 04:22:34107
tdanderson992a5652016-06-08 23:10:32108void OverflowButton::PaintForeground(gfx::Canvas* canvas,
109 const gfx::Rect& bounds) {
110 const gfx::ImageSkia* image = nullptr;
[email protected]b4b45aa2012-09-24 16:10:57111
jamescook8a5416dc2016-07-19 20:04:24112 switch (wm_shelf_->GetAlignment()) {
jamescook1b474d6a2016-06-04 05:56:00113 case SHELF_ALIGNMENT_LEFT:
[email protected]e9edd002013-08-10 15:19:24114 if (left_image_.isNull()) {
115 left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage(
mohsen4116d2392017-02-28 19:06:29116 bottom_image_, SkBitmapOperations::ROTATION_90_CW);
[email protected]e9edd002013-08-10 15:19:24117 }
118 image = &left_image_;
[email protected]7e846442012-08-07 04:22:34119 break;
jamescook1b474d6a2016-06-04 05:56:00120 case SHELF_ALIGNMENT_RIGHT:
[email protected]e9edd002013-08-10 15:19:24121 if (right_image_.isNull()) {
122 right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage(
mohsen4116d2392017-02-28 19:06:29123 bottom_image_, SkBitmapOperations::ROTATION_270_CW);
[email protected]e9edd002013-08-10 15:19:24124 }
125 image = &right_image_;
[email protected]7e846442012-08-07 04:22:34126 break;
[email protected]e9edd002013-08-10 15:19:24127 default:
mohsen4116d2392017-02-28 19:06:29128 image = &bottom_image_;
[email protected]8572c4872013-01-12 17:16:07129 break;
[email protected]7e846442012-08-07 04:22:34130 }
131
[email protected]e9edd002013-08-10 15:19:24132 canvas->DrawImageInt(*image,
133 bounds.x() + ((bounds.width() - image->width()) / 2),
134 bounds.y() + ((bounds.height() - image->height()) / 2));
[email protected]7e846442012-08-07 04:22:34135}
136
mohsen623c7e42016-09-16 18:45:38137gfx::Rect OverflowButton::CalculateButtonBounds() const {
jamescook8a5416dc2016-07-19 20:04:24138 ShelfAlignment alignment = wm_shelf_->GetAlignment();
mohsen4116d2392017-02-28 19:06:29139 gfx::Rect content_bounds = GetContentsBounds();
140 // Align the button to the top of a bottom-aligned shelf, to the right edge
141 // a left-aligned shelf, and to the left edge of a right-aligned shelf.
142 const int inset = (GetShelfConstant(SHELF_SIZE) - kOverflowButtonSize) / 2;
143 const int x = alignment == SHELF_ALIGNMENT_LEFT
144 ? content_bounds.right() - inset - kOverflowButtonSize
145 : content_bounds.x() + inset;
146 return gfx::Rect(x, content_bounds.y() + inset, kOverflowButtonSize,
147 kOverflowButtonSize);
tdanderson992a5652016-06-08 23:10:32148}
149
[email protected]7e846442012-08-07 04:22:34150} // namespace ash