Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ui/gfx/paint_vector_icon.h" | 5 #include "ui/gfx/paint_vector_icon.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 | 9 |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 id_(VectorIconId::VECTOR_ICON_NONE), | 304 id_(VectorIconId::VECTOR_ICON_NONE), |
| 305 path_(PathFromSource(definition)), | 305 path_(PathFromSource(definition)), |
| 306 color_(color), | 306 color_(color), |
| 307 badge_id_(VectorIconId::VECTOR_ICON_NONE) {} | 307 badge_id_(VectorIconId::VECTOR_ICON_NONE) {} |
| 308 | 308 |
| 309 ~VectorIconSource() override {} | 309 ~VectorIconSource() override {} |
| 310 | 310 |
| 311 // CanvasImageSource: | 311 // CanvasImageSource: |
| 312 void Draw(gfx::Canvas* canvas) override { | 312 void Draw(gfx::Canvas* canvas) override { |
| 313 if (path_.empty()) { | 313 if (path_.empty()) { |
| 314 PaintVectorIcon(canvas, id_, size_.width(), color_); | 314 if (id_ != VectorIconId::VECTOR_ICON_NONE) |
| 315 PaintVectorIcon(canvas, id_, size_.width(), color_); | |
| 315 if (badge_id_ != VectorIconId::VECTOR_ICON_NONE) | 316 if (badge_id_ != VectorIconId::VECTOR_ICON_NONE) |
| 316 PaintVectorIcon(canvas, badge_id_, size_.width(), color_); | 317 PaintVectorIcon(canvas, badge_id_, size_.width(), color_); |
| 317 } else { | 318 } else { |
| 318 PaintPath(canvas, path_.data(), size_.width(), color_); | 319 PaintPath(canvas, path_.data(), size_.width(), color_); |
| 319 } | 320 } |
| 320 } | 321 } |
| 321 | 322 |
| 322 private: | 323 private: |
| 323 const VectorIconId id_; | 324 const VectorIconId id_; |
| 324 const std::vector<PathElement> path_; | 325 const std::vector<PathElement> path_; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 | 379 |
| 379 static base::LazyInstance<VectorIconCache> g_icon_cache = | 380 static base::LazyInstance<VectorIconCache> g_icon_cache = |
| 380 LAZY_INSTANCE_INITIALIZER; | 381 LAZY_INSTANCE_INITIALIZER; |
| 381 | 382 |
| 382 } // namespace | 383 } // namespace |
| 383 | 384 |
| 384 void PaintVectorIcon(Canvas* canvas, | 385 void PaintVectorIcon(Canvas* canvas, |
| 385 VectorIconId id, | 386 VectorIconId id, |
| 386 size_t dip_size, | 387 size_t dip_size, |
| 387 SkColor color) { | 388 SkColor color) { |
| 388 DCHECK(VectorIconId::VECTOR_ICON_NONE != id); | 389 DCHECK(id != VectorIconId::VECTOR_ICON_NONE); |
|
danakj
2016/03/25 23:35:28
DCHECK_NE if you can
Peter Kasting
2016/03/26 01:01:57
Can't (I tried that first); no operator<< for this
| |
| 389 const PathElement* path = canvas->image_scale() == 1.f | 390 const PathElement* path = canvas->image_scale() == 1.f |
| 390 ? GetPathForVectorIconAt1xScale(id) | 391 ? GetPathForVectorIconAt1xScale(id) |
| 391 : GetPathForVectorIcon(id); | 392 : GetPathForVectorIcon(id); |
| 392 PaintPath(canvas, path, dip_size, color); | 393 PaintPath(canvas, path, dip_size, color); |
| 393 } | 394 } |
| 394 | 395 |
| 395 ImageSkia CreateVectorIcon(VectorIconId id, size_t dip_size, SkColor color) { | 396 ImageSkia CreateVectorIcon(VectorIconId id, size_t dip_size, SkColor color) { |
| 396 return CreateVectorIconWithBadge(id, dip_size, color, | 397 return CreateVectorIconWithBadge(id, dip_size, color, |
| 397 VectorIconId::VECTOR_ICON_NONE); | 398 VectorIconId::VECTOR_ICON_NONE); |
| 398 } | 399 } |
| 399 | 400 |
| 400 ImageSkia CreateVectorIconWithBadge(VectorIconId id, | 401 ImageSkia CreateVectorIconWithBadge(VectorIconId id, |
| 401 size_t dip_size, | 402 size_t dip_size, |
| 402 SkColor color, | 403 SkColor color, |
| 403 VectorIconId badge_id) { | 404 VectorIconId badge_id) { |
| 404 return g_icon_cache.Get().GetOrCreateIcon(id, dip_size, color, badge_id); | 405 return g_icon_cache.Get().GetOrCreateIcon(id, dip_size, color, badge_id); |
| 405 } | 406 } |
| 406 | 407 |
| 407 ImageSkia CreateVectorIconFromSource(const std::string& source, | 408 ImageSkia CreateVectorIconFromSource(const std::string& source, |
| 408 size_t dip_size, | 409 size_t dip_size, |
| 409 SkColor color) { | 410 SkColor color) { |
| 410 return ImageSkia( | 411 return ImageSkia( |
| 411 new VectorIconSource(source, dip_size, color), | 412 new VectorIconSource(source, dip_size, color), |
| 412 gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size))); | 413 gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size))); |
| 413 } | 414 } |
| 414 | 415 |
| 415 } // namespace gfx | 416 } // namespace gfx |
| OLD | NEW |