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

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

Issue 2033553003: Add MD ink drop ripple to shelf app items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests Created 4 years, 6 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/shelf/overflow_button.h" 5 #include "ash/shelf/overflow_button.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.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/shelf_constants.h" 9 #include "ash/common/shelf/shelf_constants.h"
10 #include "ash/shelf/shelf.h" 10 #include "ash/shelf/shelf.h"
11 #include "ash/shelf/shelf_layout_manager.h" 11 #include "ash/shelf/shelf_layout_manager.h"
12 #include "ash/shelf/shelf_view.h"
12 #include "ash/shelf/shelf_widget.h" 13 #include "ash/shelf/shelf_widget.h"
13 #include "grit/ash_resources.h" 14 #include "grit/ash_resources.h"
14 #include "grit/ash_strings.h" 15 #include "grit/ash_strings.h"
15 #include "third_party/skia/include/core/SkPaint.h" 16 #include "third_party/skia/include/core/SkPaint.h"
16 #include "third_party/skia/include/core/SkPath.h" 17 #include "third_party/skia/include/core/SkPath.h"
17 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/animation/throb_animation.h" 20 #include "ui/gfx/animation/throb_animation.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/skbitmap_operations.h" 23 #include "ui/gfx/skbitmap_operations.h"
23 #include "ui/gfx/skia_util.h" 24 #include "ui/gfx/skia_util.h"
24 #include "ui/gfx/transform.h" 25 #include "ui/gfx/transform.h"
25 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
26 27
27 namespace ash { 28 namespace ash {
28 29
29 OverflowButton::OverflowButton(views::ButtonListener* listener, Shelf* shelf) 30 OverflowButton::OverflowButton(ShelfView* shelf_view)
30 : CustomButton(listener), bottom_image_(nullptr), shelf_(shelf) { 31 : CustomButton(nullptr), bottom_image_(nullptr), shelf_view_(shelf_view) {
31 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 32 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
32 bottom_image_ = rb->GetImageNamed(IDR_ASH_SHELF_OVERFLOW).ToImageSkia(); 33 bottom_image_ = rb->GetImageNamed(IDR_ASH_SHELF_OVERFLOW).ToImageSkia();
33 34
34 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); 35 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
35 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); 36 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME));
36 } 37 }
37 38
38 OverflowButton::~OverflowButton() {} 39 OverflowButton::~OverflowButton() {}
39 40
40 void OverflowButton::OnShelfAlignmentChanged() { 41 void OverflowButton::OnShelfAlignmentChanged() {
41 SchedulePaint(); 42 SchedulePaint();
42 } 43 }
43 44
44 void OverflowButton::OnPaint(gfx::Canvas* canvas) { 45 void OverflowButton::OnPaint(gfx::Canvas* canvas) {
45 gfx::Rect bounds = CalculateButtonBounds(); 46 gfx::Rect bounds = CalculateButtonBounds();
46 PaintBackground(canvas, bounds); 47 PaintBackground(canvas, bounds);
47 PaintForeground(canvas, bounds); 48 PaintForeground(canvas, bounds);
48 } 49 }
49 50
51 void OverflowButton::NotifyClick(const ui::Event& event) {
52 CustomButton::NotifyClick(event);
53 shelf_view_->ButtonPressed(this, event, ink_drop());
54 }
55
50 void OverflowButton::PaintBackground(gfx::Canvas* canvas, 56 void OverflowButton::PaintBackground(gfx::Canvas* canvas,
51 const gfx::Rect& bounds) { 57 const gfx::Rect& bounds) {
52 if (MaterialDesignController::IsShelfMaterial()) { 58 if (MaterialDesignController::IsShelfMaterial()) {
53 SkColor color = SK_ColorTRANSPARENT; 59 SkColor color = SK_ColorTRANSPARENT;
54 ShelfWidget* shelf_widget = shelf_->shelf_widget(); 60 ShelfWidget* shelf_widget = shelf_view_->shelf()->shelf_widget();
55 if (shelf_->IsShowingOverflowBubble()) { 61 if (shelf_view_->shelf()->IsShowingOverflowBubble()) {
56 // TODO(bruthig|mohsen): Use of this color is temporary. Draw the active 62 // TODO(bruthig|mohsen): Use of this color is temporary. Draw the active
57 // state using the material design ripple animation. 63 // state using the material design ripple animation.
58 color = SK_ColorBLUE; 64 color = SK_ColorBLUE;
59 } else if (shelf_widget && 65 } else if (shelf_widget &&
60 shelf_widget->GetBackgroundType() == 66 shelf_widget->GetBackgroundType() ==
61 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { 67 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) {
62 color = SkColorSetA(kShelfBaseColor, 68 color = SkColorSetA(kShelfBaseColor,
63 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); 69 GetShelfConstant(SHELF_BACKGROUND_ALPHA));
64 } 70 }
65 71
66 // TODO(bruthig|tdanderson): The background should be changed using a 72 // TODO(bruthig|tdanderson): The background should be changed using a
67 // fade in/out animation. 73 // fade in/out animation.
68 const int kCornerRadius = 2; 74 const int kCornerRadius = 2;
69 SkPaint paint; 75 SkPaint paint;
70 paint.setFlags(SkPaint::kAntiAlias_Flag); 76 paint.setFlags(SkPaint::kAntiAlias_Flag);
71 paint.setColor(color); 77 paint.setColor(color);
72 canvas->DrawRoundRect(bounds, kCornerRadius, paint); 78 canvas->DrawRoundRect(bounds, kCornerRadius, paint);
73 } else { 79 } else {
74 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 80 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
75 const gfx::ImageSkia* background = 81 const gfx::ImageSkia* background =
76 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); 82 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia();
77 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); 83 canvas->DrawImageInt(*background, bounds.x(), bounds.y());
78 } 84 }
79 } 85 }
80 86
81 void OverflowButton::PaintForeground(gfx::Canvas* canvas, 87 void OverflowButton::PaintForeground(gfx::Canvas* canvas,
82 const gfx::Rect& bounds) { 88 const gfx::Rect& bounds) {
83 const gfx::ImageSkia* image = nullptr; 89 const gfx::ImageSkia* image = nullptr;
84 90
85 switch(shelf_->alignment()) { 91 switch (shelf_view_->shelf()->alignment()) {
86 case SHELF_ALIGNMENT_LEFT: 92 case SHELF_ALIGNMENT_LEFT:
87 if (left_image_.isNull()) { 93 if (left_image_.isNull()) {
88 left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( 94 left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage(
89 *bottom_image_, SkBitmapOperations::ROTATION_90_CW); 95 *bottom_image_, SkBitmapOperations::ROTATION_90_CW);
90 } 96 }
91 image = &left_image_; 97 image = &left_image_;
92 break; 98 break;
93 case SHELF_ALIGNMENT_RIGHT: 99 case SHELF_ALIGNMENT_RIGHT:
94 if (right_image_.isNull()) { 100 if (right_image_.isNull()) {
95 right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( 101 right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage(
96 *bottom_image_, SkBitmapOperations::ROTATION_270_CW); 102 *bottom_image_, SkBitmapOperations::ROTATION_270_CW);
97 } 103 }
98 image = &right_image_; 104 image = &right_image_;
99 break; 105 break;
100 default: 106 default:
101 image = bottom_image_; 107 image = bottom_image_;
102 break; 108 break;
103 } 109 }
104 110
105 canvas->DrawImageInt(*image, 111 canvas->DrawImageInt(*image,
106 bounds.x() + ((bounds.width() - image->width()) / 2), 112 bounds.x() + ((bounds.width() - image->width()) / 2),
107 bounds.y() + ((bounds.height() - image->height()) / 2)); 113 bounds.y() + ((bounds.height() - image->height()) / 2));
108 } 114 }
109 115
110 int OverflowButton::NonMaterialBackgroundImageId() { 116 int OverflowButton::NonMaterialBackgroundImageId() {
111 if (shelf_->IsShowingOverflowBubble()) 117 if (shelf_view_->shelf()->IsShowingOverflowBubble())
112 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; 118 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED;
113 else if (shelf_->shelf_widget()->GetDimsShelf()) 119 else if (shelf_view_->shelf()->shelf_widget()->GetDimsShelf())
114 return IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; 120 return IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK;
115 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; 121 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL;
116 } 122 }
117 123
118 gfx::Rect OverflowButton::CalculateButtonBounds() { 124 gfx::Rect OverflowButton::CalculateButtonBounds() {
119 ShelfAlignment alignment = shelf_->alignment(); 125 ShelfAlignment alignment = shelf_view_->shelf()->alignment();
120 gfx::Rect bounds(GetContentsBounds()); 126 gfx::Rect bounds(GetContentsBounds());
121 if (!MaterialDesignController::IsShelfMaterial()) { 127 if (!MaterialDesignController::IsShelfMaterial()) {
122 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 128 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
123 const gfx::ImageSkia* background = 129 const gfx::ImageSkia* background =
124 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); 130 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia();
125 if (alignment == SHELF_ALIGNMENT_LEFT) { 131 if (alignment == SHELF_ALIGNMENT_LEFT) {
126 bounds = gfx::Rect( 132 bounds = gfx::Rect(
127 bounds.right() - background->width() - 133 bounds.right() - background->width() -
128 ShelfLayoutManager::kShelfItemInset, 134 ShelfLayoutManager::kShelfItemInset,
129 bounds.y() + (bounds.height() - background->height()) / 2, 135 bounds.y() + (bounds.height() - background->height()) / 2,
130 background->width(), background->height()); 136 background->width(), background->height());
131 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { 137 } else if (alignment == SHELF_ALIGNMENT_RIGHT) {
132 bounds = gfx::Rect( 138 bounds = gfx::Rect(
133 bounds.x() + ShelfLayoutManager::kShelfItemInset, 139 bounds.x() + ShelfLayoutManager::kShelfItemInset,
134 bounds.y() + (bounds.height() - background->height()) / 2, 140 bounds.y() + (bounds.height() - background->height()) / 2,
135 background->width(), background->height()); 141 background->width(), background->height());
136 } else { 142 } else {
137 bounds = gfx::Rect( 143 bounds = gfx::Rect(
138 bounds.x() + (bounds.width() - background->width()) / 2, 144 bounds.x() + (bounds.width() - background->width()) / 2,
139 bounds.y() + ShelfLayoutManager::kShelfItemInset, 145 bounds.y() + ShelfLayoutManager::kShelfItemInset,
140 background->width(), background->height()); 146 background->width(), background->height());
141 } 147 }
142 } 148 }
143 149
144 return bounds; 150 return bounds;
145 } 151 }
146 152
147 } // namespace ash 153 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698