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

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: rebase 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/flood_fill_ink_drop_ripple.h" 25 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
28 #include "ui/views/animation/ink_drop_impl.h" 26 #include "ui/views/animation/ink_drop_impl.h"
29 #include "ui/views/animation/ink_drop_mask.h" 27 #include "ui/views/animation/ink_drop_mask.h"
30 #include "ui/views/painter.h" 28 #include "ui/views/painter.h"
31 29
32 namespace ash { 30 namespace ash {
33 31
34 AppListButton::AppListButton(InkDropButtonListener* listener, 32 AppListButton::AppListButton(InkDropButtonListener* listener,
35 ShelfView* shelf_view, 33 ShelfView* shelf_view,
36 WmShelf* wm_shelf) 34 WmShelf* wm_shelf)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 break; 133 break;
136 default: 134 default:
137 ImageButton::OnGestureEvent(event); 135 ImageButton::OnGestureEvent(event);
138 return; 136 return;
139 } 137 }
140 } 138 }
141 139
142 void AppListButton::OnPaint(gfx::Canvas* canvas) { 140 void AppListButton::OnPaint(gfx::Canvas* canvas) {
143 // Call the base class first to paint any background/borders. 141 // Call the base class first to paint any background/borders.
144 View::OnPaint(canvas); 142 View::OnPaint(canvas);
145 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
146
147 const gfx::ImageSkia& foreground_image =
148 MaterialDesignController::IsShelfMaterial()
149 ? CreateVectorIcon(kShelfAppListIcon, kShelfIconColor)
150 : *rb.GetImageNamed(IDR_ASH_SHELF_ICON_APPLIST).ToImageSkia();
151 143
152 if (ash::MaterialDesignController::IsShelfMaterial()) { 144 if (ash::MaterialDesignController::IsShelfMaterial()) {
153 PaintBackgroundMD(canvas); 145 PaintMd(canvas);
154 PaintForegroundMD(canvas, foreground_image);
155 } else { 146 } else {
147 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
148 const gfx::ImageSkia& foreground_image =
149 *rb.GetImageNamed(IDR_ASH_SHELF_ICON_APPLIST).ToImageSkia();
156 PaintAppListButton(canvas, foreground_image); 150 PaintAppListButton(canvas, foreground_image);
157 } 151 }
158 152
159 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); 153 views::Painter::PaintFocusPainter(this, canvas, focus_painter());
160 } 154 }
161 155
162 void AppListButton::PaintBackgroundMD(gfx::Canvas* canvas) { 156 void AppListButton::PaintMd(gfx::Canvas* canvas) {
163 // Paint the circular background of AppList button. 157 gfx::PointF circle_center(GetCenterPoint());
164 gfx::Point circle_center = GetCenterPoint();
165 158
166 SkPaint background_paint; 159 // Paint the circular background.
167 background_paint.setColor(SkColorSetA(kShelfBaseColor, background_alpha_)); 160 SkPaint bg_paint;
168 background_paint.setFlags(SkPaint::kAntiAlias_Flag); 161 bg_paint.setColor(SkColorSetA(kShelfBaseColor, background_alpha_));
169 background_paint.setStyle(SkPaint::kFill_Style); 162 bg_paint.setFlags(SkPaint::kAntiAlias_Flag);
163 bg_paint.setStyle(SkPaint::kFill_Style);
164 canvas->DrawCircle(circle_center, kAppListButtonRadius, bg_paint);
170 165
171 canvas->DrawCircle(circle_center, kAppListButtonRadius, background_paint); 166 // Paint a white ring as the foreground. The ceil/dsf math assures that the
172 } 167 // ring draws sharply and is centered at all scale factors.
168 const float kRingOuterRadiusDp = 7.f;
169 const float kRingThicknessDp = 1.5f;
170 const float dsf = canvas->UndoDeviceScaleFactor();
171 circle_center.Scale(dsf);
173 172
174 void AppListButton::PaintForegroundMD(gfx::Canvas* canvas, 173 SkPaint fg_paint;
175 const gfx::ImageSkia& foreground_image) { 174 fg_paint.setFlags(SkPaint::kAntiAlias_Flag);
176 gfx::Rect foreground_bounds(foreground_image.size()); 175 fg_paint.setStyle(SkPaint::kStroke_Style);
177 gfx::Rect contents_bounds = GetContentsBounds(); 176 fg_paint.setColor(kShelfIconColor);
178 177 const float thickness = std::ceil(kRingThicknessDp * dsf);
179 if (IsHorizontalAlignment(wm_shelf_->GetAlignment())) { 178 const float radius = std::ceil(kRingOuterRadiusDp * dsf) - thickness / 2;
180 foreground_bounds.set_x( 179 fg_paint.setStrokeWidth(thickness);
181 (contents_bounds.width() - foreground_bounds.width()) / 2); 180 // Make sure the center of the circle lands on pixel centers.
182 foreground_bounds.set_y( 181 canvas->DrawCircle(circle_center, radius, fg_paint);
183 (contents_bounds.height() - foreground_bounds.height()) / 2);
184 } else {
185 foreground_bounds.set_x(
186 (contents_bounds.height() - foreground_bounds.height()) / 2);
187 foreground_bounds.set_y(
188 (contents_bounds.width() - foreground_bounds.width()) / 2);
189 }
190 canvas->DrawImageInt(foreground_image, foreground_bounds.x(),
191 foreground_bounds.y());
192 } 182 }
193 183
194 void AppListButton::PaintAppListButton(gfx::Canvas* canvas, 184 void AppListButton::PaintAppListButton(gfx::Canvas* canvas,
195 const gfx::ImageSkia& foreground_image) { 185 const gfx::ImageSkia& foreground_image) {
196 int background_image_id = 0; 186 int background_image_id = 0;
197 187
198 if (WmShell::Get()->GetAppListTargetVisibility() || 188 if (WmShell::Get()->GetAppListTargetVisibility() ||
199 draw_background_as_active_) { 189 draw_background_as_active_) {
200 background_image_id = IDR_AURA_LAUNCHER_BACKGROUND_PRESSED; 190 background_image_id = IDR_AURA_LAUNCHER_BACKGROUND_PRESSED;
201 } else if (wm_shelf_->IsDimmed()) { 191 } else if (wm_shelf_->IsDimmed()) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 276 }
287 277
288 void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) { 278 void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) {
289 if (draw_background_as_active_ == draw_background_as_active) 279 if (draw_background_as_active_ == draw_background_as_active)
290 return; 280 return;
291 draw_background_as_active_ = draw_background_as_active; 281 draw_background_as_active_ = draw_background_as_active;
292 SchedulePaint(); 282 SchedulePaint();
293 } 283 }
294 284
295 gfx::Point AppListButton::GetCenterPoint() const { 285 gfx::Point AppListButton::GetCenterPoint() const {
296 gfx::Point center = GetContentsBounds().CenterPoint(); 286 // During shelf hide/show animations, width and height may not be equal. Take
297 if (!IsHorizontalAlignment(wm_shelf_->GetAlignment())) 287 // the greater of the two as the one that represents the normal size of the
298 center = gfx::Point(center.y(), center.x()); 288 // button.
299 return center; 289 int center = std::max(width(), height()) / 2.f;
290 gfx::Point centroid(center, center);
291 // For the left shelf alignment, we need to right-justify. For other shelf
292 // alignments, left/top justification (i.e. no adjustments are necessary).
293 if (SHELF_ALIGNMENT_LEFT == wm_shelf_->GetAlignment())
294 centroid.set_x(width() - center);
295 return centroid;
300 } 296 }
301 297
302 } // namespace ash 298 } // 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