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

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

Issue 2509743002: Adjust MD shelf app list icon for better centering. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « ash/common/shelf/app_list_button.h ('k') | ash/resources/vector_icons/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/app_list_button.h" 5 #include "ash/common/shelf/app_list_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_item_types.h" 11 #include "ash/common/shelf/shelf_item_types.h"
12 #include "ash/common/shelf/shelf_view.h" 12 #include "ash/common/shelf/shelf_view.h"
13 #include "ash/common/shelf/wm_shelf.h" 13 #include "ash/common/shelf/wm_shelf.h"
14 #include "ash/common/shelf/wm_shelf_util.h" 14 #include "ash/common/shelf/wm_shelf_util.h"
15 #include "ash/common/wm_shell.h" 15 #include "ash/common/wm_shell.h"
16 #include "ash/public/cpp/shelf_types.h" 16 #include "ash/public/cpp/shelf_types.h"
17 #include "ash/resources/vector_icons/vector_icons.h"
18 #include "base/command_line.h" 17 #include "base/command_line.h"
19 #include "grit/ash_resources.h" 18 #include "grit/ash_resources.h"
20 #include "grit/ash_strings.h" 19 #include "grit/ash_strings.h"
21 #include "ui/accessibility/ax_node_data.h" 20 #include "ui/accessibility/ax_node_data.h"
22 #include "ui/app_list/app_list_switches.h" 21 #include "ui/app_list/app_list_switches.h"
23 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/paint_vector_icon.h"
27 #include "ui/views/animation/ink_drop_impl.h" 25 #include "ui/views/animation/ink_drop_impl.h"
28 #include "ui/views/animation/square_ink_drop_ripple.h" 26 #include "ui/views/animation/square_ink_drop_ripple.h"
29 #include "ui/views/painter.h" 27 #include "ui/views/painter.h"
30 28
31 namespace ash { 29 namespace ash {
32 30
33 AppListButton::AppListButton(InkDropButtonListener* listener, 31 AppListButton::AppListButton(InkDropButtonListener* listener,
34 ShelfView* shelf_view, 32 ShelfView* shelf_view,
35 WmShelf* wm_shelf) 33 WmShelf* wm_shelf)
36 : views::ImageButton(nullptr), 34 : views::ImageButton(nullptr),
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 break; 132 break;
135 default: 133 default:
136 ImageButton::OnGestureEvent(event); 134 ImageButton::OnGestureEvent(event);
137 return; 135 return;
138 } 136 }
139 } 137 }
140 138
141 void AppListButton::OnPaint(gfx::Canvas* canvas) { 139 void AppListButton::OnPaint(gfx::Canvas* canvas) {
142 // Call the base class first to paint any background/borders. 140 // Call the base class first to paint any background/borders.
143 View::OnPaint(canvas); 141 View::OnPaint(canvas);
144 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
145
146 const gfx::ImageSkia& foreground_image =
147 MaterialDesignController::IsShelfMaterial()
148 ? CreateVectorIcon(kShelfAppListIcon, kShelfIconColor)
149 : *rb.GetImageNamed(IDR_ASH_SHELF_ICON_APPLIST).ToImageSkia();
150 142
151 if (ash::MaterialDesignController::IsShelfMaterial()) { 143 if (ash::MaterialDesignController::IsShelfMaterial()) {
152 PaintBackgroundMD(canvas); 144 PaintMd(canvas);
153 PaintForegroundMD(canvas, foreground_image);
154 } else { 145 } else {
146 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
147 const gfx::ImageSkia& foreground_image =
148 *rb.GetImageNamed(IDR_ASH_SHELF_ICON_APPLIST).ToImageSkia();
155 PaintAppListButton(canvas, foreground_image); 149 PaintAppListButton(canvas, foreground_image);
156 } 150 }
157 151
158 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); 152 views::Painter::PaintFocusPainter(this, canvas, focus_painter());
159 } 153 }
160 154
161 void AppListButton::PaintBackgroundMD(gfx::Canvas* canvas) { 155 void AppListButton::PaintMd(gfx::Canvas* canvas) {
162 // Paint the circular background of AppList button. 156 // Paint the circular background of AppList button.
tdanderson 2016/11/16 18:19:36 nit: consider DCHECK(IsMd())
Evan Stade 2016/11/16 18:29:53 I like to use that as documentation but in this ca
tdanderson 2016/11/16 20:20:18 Acknowledged.
163 gfx::Point circle_center = GetContentsBounds().CenterPoint(); 157 gfx::PointF circle_center = gfx::RectF(GetContentsBounds()).CenterPoint();
164 if (!IsHorizontalAlignment(wm_shelf_->GetAlignment())) 158 if (!IsHorizontalAlignment(wm_shelf_->GetAlignment()))
165 circle_center = gfx::Point(circle_center.y(), circle_center.x()); 159 circle_center = gfx::PointF(circle_center.y(), circle_center.x());
166 160
167 SkPaint background_paint; 161 SkPaint bg_paint;
168 background_paint.setColor(SkColorSetA(kShelfBaseColor, background_alpha_)); 162 bg_paint.setColor(SkColorSetA(kShelfBaseColor, background_alpha_));
169 background_paint.setFlags(SkPaint::kAntiAlias_Flag); 163 bg_paint.setFlags(SkPaint::kAntiAlias_Flag);
170 background_paint.setStyle(SkPaint::kFill_Style); 164 bg_paint.setStyle(SkPaint::kFill_Style);
165 canvas->DrawCircle(circle_center, kAppListButtonRadius, bg_paint);
171 166
172 canvas->DrawCircle(circle_center, kAppListButtonRadius, background_paint); 167 // Paint a white ring as the foreground. The ceil/dsf math assures that the
173 } 168 // ring draws sharply and is centered at all scale factors.
169 const float kRingOuterRadiusDp = 6.5f;
170 const float kRingThicknessDp = 1.5f;
171 const float dsf = canvas->UndoDeviceScaleFactor();
tdanderson 2016/11/16 18:19:36 Do you not need a corresponding call to Restore()?
Evan Stade 2016/11/16 18:29:53 we have done that a lot in the past, but Sadrul po
tdanderson 2016/11/16 20:20:18 Acknowledged.
172 circle_center.Scale(dsf);
174 173
175 void AppListButton::PaintForegroundMD(gfx::Canvas* canvas, 174 SkPaint fg_paint;
176 const gfx::ImageSkia& foreground_image) { 175 fg_paint.setFlags(SkPaint::kAntiAlias_Flag);
177 gfx::Rect foreground_bounds(foreground_image.size()); 176 fg_paint.setStyle(SkPaint::kStroke_Style);
178 gfx::Rect contents_bounds = GetContentsBounds(); 177 fg_paint.setColor(kShelfIconColor);
179 178 const float thickness = std::ceil(kRingThicknessDp * dsf);
180 if (IsHorizontalAlignment(wm_shelf_->GetAlignment())) { 179 const float radius = std::ceil(kRingOuterRadiusDp * dsf) - thickness / 2;
181 foreground_bounds.set_x( 180 fg_paint.setStrokeWidth(thickness);
182 (contents_bounds.width() - foreground_bounds.width()) / 2); 181 // Make sure the center of the circle lands on pixel centers.
183 foreground_bounds.set_y( 182 canvas->DrawCircle(circle_center, radius, fg_paint);
184 (contents_bounds.height() - foreground_bounds.height()) / 2);
185 } else {
186 foreground_bounds.set_x(
187 (contents_bounds.height() - foreground_bounds.height()) / 2);
188 foreground_bounds.set_y(
189 (contents_bounds.width() - foreground_bounds.width()) / 2);
190 }
191 canvas->DrawImageInt(foreground_image, foreground_bounds.x(),
192 foreground_bounds.y());
193 } 183 }
194 184
195 void AppListButton::PaintAppListButton(gfx::Canvas* canvas, 185 void AppListButton::PaintAppListButton(gfx::Canvas* canvas,
196 const gfx::ImageSkia& foreground_image) { 186 const gfx::ImageSkia& foreground_image) {
197 int background_image_id = 0; 187 int background_image_id = 0;
198 188
199 if (WmShell::Get()->GetAppListTargetVisibility() || 189 if (WmShell::Get()->GetAppListTargetVisibility() ||
200 draw_background_as_active_) { 190 draw_background_as_active_) {
201 background_image_id = IDR_AURA_LAUNCHER_BACKGROUND_PRESSED; 191 background_image_id = IDR_AURA_LAUNCHER_BACKGROUND_PRESSED;
202 } else if (wm_shelf_->IsDimmed()) { 192 } else if (wm_shelf_->IsDimmed()) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 274 }
285 275
286 void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) { 276 void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) {
287 if (draw_background_as_active_ == draw_background_as_active) 277 if (draw_background_as_active_ == draw_background_as_active)
288 return; 278 return;
289 draw_background_as_active_ = draw_background_as_active; 279 draw_background_as_active_ = draw_background_as_active;
290 SchedulePaint(); 280 SchedulePaint();
291 } 281 }
292 282
293 } // namespace ash 283 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/app_list_button.h ('k') | ash/resources/vector_icons/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698