| OLD | NEW |
| 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 "chrome/browser/profiles/profile_avatar_icon_util.h" | 5 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 // Offset the rectangle by a half pixel so the border is drawn within the | 183 // Offset the rectangle by a half pixel so the border is drawn within the |
| 184 // appropriate pixels no matter the scale factor. Subtract 1 from the right | 184 // appropriate pixels no matter the scale factor. Subtract 1 from the right |
| 185 // and bottom sizes to specify the endpoints, yielding -0.5. | 185 // and bottom sizes to specify the endpoints, yielding -0.5. |
| 186 SkPath path; | 186 SkPath path; |
| 187 path.addRect(SkFloatToScalar(x + 0.5f), // left | 187 path.addRect(SkFloatToScalar(x + 0.5f), // left |
| 188 SkFloatToScalar(y + 0.5f), // top | 188 SkFloatToScalar(y + 0.5f), // top |
| 189 SkFloatToScalar(x + border_size - 0.5f), // right | 189 SkFloatToScalar(x + border_size - 0.5f), // right |
| 190 SkFloatToScalar(y + border_size - 0.5f)); // bottom | 190 SkFloatToScalar(y + border_size - 0.5f)); // bottom |
| 191 | 191 |
| 192 cc::PaintFlags paint; | 192 cc::PaintFlags flags; |
| 193 paint.setColor(border_color); | 193 flags.setColor(border_color); |
| 194 paint.setStyle(cc::PaintFlags::kStroke_Style); | 194 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 195 paint.setStrokeWidth(SkIntToScalar(1)); | 195 flags.setStrokeWidth(SkIntToScalar(1)); |
| 196 | 196 |
| 197 canvas->DrawPath(path, paint); | 197 canvas->DrawPath(path, flags); |
| 198 } else if (border_ == BORDER_ETCHED) { | 198 } else if (border_ == BORDER_ETCHED) { |
| 199 // Give the avatar an etched look by drawing a highlight on the bottom and | 199 // Give the avatar an etched look by drawing a highlight on the bottom and |
| 200 // right edges. | 200 // right edges. |
| 201 SkColor shadow_color = SkColorSetARGB(83, 0, 0, 0); | 201 SkColor shadow_color = SkColorSetARGB(83, 0, 0, 0); |
| 202 SkColor highlight_color = SkColorSetARGB(96, 255, 255, 255); | 202 SkColor highlight_color = SkColorSetARGB(96, 255, 255, 255); |
| 203 | 203 |
| 204 cc::PaintFlags paint; | 204 cc::PaintFlags flags; |
| 205 paint.setStyle(cc::PaintFlags::kStroke_Style); | 205 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 206 paint.setStrokeWidth(SkIntToScalar(1)); | 206 flags.setStrokeWidth(SkIntToScalar(1)); |
| 207 | 207 |
| 208 SkPath path; | 208 SkPath path; |
| 209 | 209 |
| 210 // Left and top shadows. To support higher scale factors than 1, position | 210 // Left and top shadows. To support higher scale factors than 1, position |
| 211 // the orthogonal dimension of each line on the half-pixel to separate the | 211 // the orthogonal dimension of each line on the half-pixel to separate the |
| 212 // pixel. For a vertical line, this means adding 0.5 to the x-value. | 212 // pixel. For a vertical line, this means adding 0.5 to the x-value. |
| 213 path.moveTo(SkFloatToScalar(x + 0.5f), SkIntToScalar(y + height_)); | 213 path.moveTo(SkFloatToScalar(x + 0.5f), SkIntToScalar(y + height_)); |
| 214 | 214 |
| 215 // Draw up to the top-left. Stop with the y-value at a half-pixel. | 215 // Draw up to the top-left. Stop with the y-value at a half-pixel. |
| 216 path.rLineTo(SkIntToScalar(0), SkFloatToScalar(-height_ + 0.5f)); | 216 path.rLineTo(SkIntToScalar(0), SkFloatToScalar(-height_ + 0.5f)); |
| 217 | 217 |
| 218 // Draw right to the top-right, stopping within the last pixel. | 218 // Draw right to the top-right, stopping within the last pixel. |
| 219 path.rLineTo(SkFloatToScalar(width_ - 0.5f), SkIntToScalar(0)); | 219 path.rLineTo(SkFloatToScalar(width_ - 0.5f), SkIntToScalar(0)); |
| 220 | 220 |
| 221 paint.setColor(shadow_color); | 221 flags.setColor(shadow_color); |
| 222 canvas->DrawPath(path, paint); | 222 canvas->DrawPath(path, flags); |
| 223 | 223 |
| 224 path.reset(); | 224 path.reset(); |
| 225 | 225 |
| 226 // Bottom and right highlights. Note that the shadows own the shared corner | 226 // Bottom and right highlights. Note that the shadows own the shared corner |
| 227 // pixels, so reduce the sizes accordingly. | 227 // pixels, so reduce the sizes accordingly. |
| 228 path.moveTo(SkIntToScalar(x + 1), SkFloatToScalar(y + height_ - 0.5f)); | 228 path.moveTo(SkIntToScalar(x + 1), SkFloatToScalar(y + height_ - 0.5f)); |
| 229 | 229 |
| 230 // Draw right to the bottom-right. | 230 // Draw right to the bottom-right. |
| 231 path.rLineTo(SkFloatToScalar(width_ - 1.5f), SkIntToScalar(0)); | 231 path.rLineTo(SkFloatToScalar(width_ - 1.5f), SkIntToScalar(0)); |
| 232 | 232 |
| 233 // Draw up to the top-right. | 233 // Draw up to the top-right. |
| 234 path.rLineTo(SkIntToScalar(0), SkFloatToScalar(-height_ + 1.5f)); | 234 path.rLineTo(SkIntToScalar(0), SkFloatToScalar(-height_ + 1.5f)); |
| 235 | 235 |
| 236 paint.setColor(highlight_color); | 236 flags.setColor(highlight_color); |
| 237 canvas->DrawPath(path, paint); | 237 canvas->DrawPath(path, flags); |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 | 240 |
| 241 } // namespace | 241 } // namespace |
| 242 | 242 |
| 243 namespace profiles { | 243 namespace profiles { |
| 244 | 244 |
| 245 struct IconResourceInfo { | 245 struct IconResourceInfo { |
| 246 int resource_id; | 246 int resource_id; |
| 247 const char* filename; | 247 const char* filename; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 avatar_info->SetString( | 568 avatar_info->SetString( |
| 569 "label", l10n_util::GetStringUTF16( | 569 "label", l10n_util::GetStringUTF16( |
| 570 profiles::GetDefaultAvatarLabelResourceIDAtIndex(i))); | 570 profiles::GetDefaultAvatarLabelResourceIDAtIndex(i))); |
| 571 | 571 |
| 572 avatars->Append(std::move(avatar_info)); | 572 avatars->Append(std::move(avatar_info)); |
| 573 } | 573 } |
| 574 return avatars; | 574 return avatars; |
| 575 } | 575 } |
| 576 | 576 |
| 577 } // namespace profiles | 577 } // namespace profiles |
| OLD | NEW |