Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: ash/common/shelf/overflow_button.cc

Issue 2178163002: Add ink drop ripple to shelf overflow button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/shelf/overflow_button.h" 5 #include "ash/common/shelf/overflow_button.h"
6 6
7 #include "ash/common/ash_constants.h" 7 #include "ash/common/ash_constants.h"
8 #include "ash/common/material_design/material_design_controller.h" 8 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/shelf/ink_drop_button_listener.h" 9 #include "ash/common/shelf/ink_drop_button_listener.h"
10 #include "ash/common/shelf/shelf_constants.h" 10 #include "ash/common/shelf/shelf_constants.h"
11 #include "ash/common/shelf/shelf_view.h" 11 #include "ash/common/shelf/shelf_view.h"
12 #include "ash/common/shelf/wm_shelf.h" 12 #include "ash/common/shelf/wm_shelf.h"
13 #include "ash/common/shelf/wm_shelf_util.h" 13 #include "ash/common/shelf/wm_shelf_util.h"
14 #include "base/memory/ptr_util.h"
14 #include "grit/ash_resources.h" 15 #include "grit/ash_resources.h"
15 #include "grit/ash_strings.h" 16 #include "grit/ash_strings.h"
16 #include "third_party/skia/include/core/SkPaint.h" 17 #include "third_party/skia/include/core/SkPaint.h"
17 #include "third_party/skia/include/core/SkPath.h" 18 #include "third_party/skia/include/core/SkPath.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/image/image_skia_operations.h" 22 #include "ui/gfx/image/image_skia_operations.h"
22 #include "ui/gfx/paint_vector_icon.h" 23 #include "ui/gfx/paint_vector_icon.h"
23 #include "ui/gfx/skbitmap_operations.h" 24 #include "ui/gfx/skbitmap_operations.h"
24 #include "ui/gfx/skia_util.h" 25 #include "ui/gfx/skia_util.h"
25 #include "ui/gfx/transform.h" 26 #include "ui/gfx/transform.h"
26 #include "ui/gfx/vector_icons_public.h" 27 #include "ui/gfx/vector_icons_public.h"
28 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
27 29
28 namespace ash { 30 namespace ash {
29 31
30 OverflowButton::OverflowButton(ShelfView* shelf_view, WmShelf* wm_shelf) 32 OverflowButton::OverflowButton(ShelfView* shelf_view, WmShelf* wm_shelf)
31 : CustomButton(nullptr), 33 : CustomButton(nullptr),
32 bottom_image_(nullptr), 34 bottom_image_(nullptr),
33 shelf_view_(shelf_view), 35 shelf_view_(shelf_view),
34 wm_shelf_(wm_shelf), 36 wm_shelf_(wm_shelf),
35 background_alpha_(0) { 37 background_alpha_(0) {
36 DCHECK(shelf_view_); 38 DCHECK(shelf_view_);
37 if (MaterialDesignController::IsShelfMaterial()) { 39 if (MaterialDesignController::IsShelfMaterial()) {
40 SetInkDropMode(InkDropMode::ON);
41 set_ink_drop_base_color(kShelfInkDropBaseColor);
42 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
43 set_hide_ink_drop_when_showing_context_menu(false);
38 bottom_image_md_ = 44 bottom_image_md_ =
39 CreateVectorIcon(gfx::VectorIconId::SHELF_OVERFLOW, kShelfIconColor); 45 CreateVectorIcon(gfx::VectorIconId::SHELF_OVERFLOW, kShelfIconColor);
40 bottom_image_ = &bottom_image_md_; 46 bottom_image_ = &bottom_image_md_;
41 } else { 47 } else {
42 bottom_image_ = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 48 bottom_image_ = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
43 IDR_ASH_SHELF_OVERFLOW); 49 IDR_ASH_SHELF_OVERFLOW);
44 } 50 }
45 51
46 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); 52 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
47 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); 53 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME));
48 } 54 }
49 55
50 OverflowButton::~OverflowButton() {} 56 OverflowButton::~OverflowButton() {}
51 57
52 void OverflowButton::OnShelfAlignmentChanged() { 58 void OverflowButton::OnShelfAlignmentChanged() {
53 SchedulePaint(); 59 SchedulePaint();
54 } 60 }
55 61
62 void OverflowButton::OnOverflowBubbleShown() {
63 AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr);
64 if (!ash::MaterialDesignController::IsShelfMaterial())
65 SchedulePaint();
66 }
67
68 void OverflowButton::OnOverflowBubbleHidden() {
69 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr);
70 if (!ash::MaterialDesignController::IsShelfMaterial())
71 SchedulePaint();
72 }
73
56 void OverflowButton::SetBackgroundAlpha(int alpha) { 74 void OverflowButton::SetBackgroundAlpha(int alpha) {
57 background_alpha_ = alpha; 75 background_alpha_ = alpha;
58 SchedulePaint(); 76 SchedulePaint();
59 } 77 }
60 78
61 void OverflowButton::OnPaint(gfx::Canvas* canvas) { 79 void OverflowButton::OnPaint(gfx::Canvas* canvas) {
62 gfx::Rect bounds = CalculateButtonBounds(); 80 gfx::Rect bounds = CalculateButtonBounds();
63 PaintBackground(canvas, bounds); 81 PaintBackground(canvas, bounds);
64 PaintForeground(canvas, bounds); 82 PaintForeground(canvas, bounds);
65 } 83 }
66 84
85 std::unique_ptr<views::InkDropRipple> OverflowButton::CreateInkDropRipple()
86 const {
87 return base::MakeUnique<views::FloodFillInkDropRipple>(
88 CalculateButtonBounds(), GetInkDropCenterBasedOnLastEvent(),
89 GetInkDropBaseColor(), ink_drop_visible_opacity());
90 }
91
92 bool OverflowButton::ShouldEnterPushedState(const ui::Event& event) {
93 if (shelf_view_->IsShowingOverflowBubble())
94 return false;
95
96 return CustomButton::ShouldEnterPushedState(event);
97 }
98
99 bool OverflowButton::ShouldShowInkDropHighlight() const {
100 return false;
101 }
102
67 void OverflowButton::NotifyClick(const ui::Event& event) { 103 void OverflowButton::NotifyClick(const ui::Event& event) {
68 CustomButton::NotifyClick(event); 104 CustomButton::NotifyClick(event);
69 shelf_view_->ButtonPressed(this, event, ink_drop()); 105 shelf_view_->ButtonPressed(this, event, ink_drop());
70 } 106 }
71 107
72 void OverflowButton::PaintBackground(gfx::Canvas* canvas, 108 void OverflowButton::PaintBackground(gfx::Canvas* canvas,
73 const gfx::Rect& bounds) { 109 const gfx::Rect& bounds) {
74 if (MaterialDesignController::IsShelfMaterial()) { 110 if (MaterialDesignController::IsShelfMaterial()) {
75 SkPaint background_paint; 111 SkPaint background_paint;
76 background_paint.setFlags(SkPaint::kAntiAlias_Flag); 112 background_paint.setFlags(SkPaint::kAntiAlias_Flag);
77 background_paint.setColor(SkColorSetA(kShelfBaseColor, background_alpha_)); 113 background_paint.setColor(SkColorSetA(kShelfBaseColor, background_alpha_));
78 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, 114 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius,
79 background_paint); 115 background_paint);
80
81 if (shelf_view_->IsShowingOverflowBubble()) {
82 SkPaint highlight_paint;
83 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag);
84 highlight_paint.setColor(kShelfButtonActivatedHighlightColor);
85 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius,
86 highlight_paint);
87 }
88 } else { 116 } else {
89 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 117 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
90 const gfx::ImageSkia* background = 118 const gfx::ImageSkia* background =
91 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); 119 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia();
92 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); 120 canvas->DrawImageInt(*background, bounds.x(), bounds.y());
93 } 121 }
94 } 122 }
95 123
96 void OverflowButton::PaintForeground(gfx::Canvas* canvas, 124 void OverflowButton::PaintForeground(gfx::Canvas* canvas,
97 const gfx::Rect& bounds) { 125 const gfx::Rect& bounds) {
(...skipping 17 matching lines...) Expand all
115 default: 143 default:
116 image = bottom_image_; 144 image = bottom_image_;
117 break; 145 break;
118 } 146 }
119 147
120 canvas->DrawImageInt(*image, 148 canvas->DrawImageInt(*image,
121 bounds.x() + ((bounds.width() - image->width()) / 2), 149 bounds.x() + ((bounds.width() - image->width()) / 2),
122 bounds.y() + ((bounds.height() - image->height()) / 2)); 150 bounds.y() + ((bounds.height() - image->height()) / 2));
123 } 151 }
124 152
125 int OverflowButton::NonMaterialBackgroundImageId() { 153 int OverflowButton::NonMaterialBackgroundImageId() const {
126 if (shelf_view_->IsShowingOverflowBubble()) 154 if (shelf_view_->IsShowingOverflowBubble())
127 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; 155 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED;
128 else if (wm_shelf_->IsDimmed()) 156 else if (wm_shelf_->IsDimmed())
129 return IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; 157 return IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK;
130 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; 158 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL;
131 } 159 }
132 160
133 gfx::Rect OverflowButton::CalculateButtonBounds() { 161 gfx::Rect OverflowButton::CalculateButtonBounds() const {
134 ShelfAlignment alignment = wm_shelf_->GetAlignment(); 162 ShelfAlignment alignment = wm_shelf_->GetAlignment();
135 gfx::Rect bounds(GetContentsBounds()); 163 gfx::Rect bounds(GetContentsBounds());
136 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 164 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
137 if (MaterialDesignController::IsShelfMaterial()) { 165 if (MaterialDesignController::IsShelfMaterial()) {
138 const int width_offset = (bounds.width() - kOverflowButtonSize) / 2; 166 const int width_offset = (bounds.width() - kOverflowButtonSize) / 2;
139 const int height_offset = (bounds.height() - kOverflowButtonSize) / 2; 167 const int height_offset = (bounds.height() - kOverflowButtonSize) / 2;
140 if (IsHorizontalAlignment(alignment)) { 168 if (IsHorizontalAlignment(alignment)) {
141 bounds = gfx::Rect(bounds.x() + width_offset, bounds.y() + height_offset, 169 bounds = gfx::Rect(bounds.x() + width_offset, bounds.y() + height_offset,
142 kOverflowButtonSize, kOverflowButtonSize); 170 kOverflowButtonSize, kOverflowButtonSize);
143 } else { 171 } else {
(...skipping 17 matching lines...) Expand all
161 bounds = 189 bounds =
162 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2, 190 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2,
163 bounds.y() + kShelfItemInset, background->width(), 191 bounds.y() + kShelfItemInset, background->width(),
164 background->height()); 192 background->height());
165 } 193 }
166 } 194 }
167 return bounds; 195 return bounds;
168 } 196 }
169 197
170 } // namespace ash 198 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698