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

Side by Side Diff: ui/gfx/image/image_skia_operations.cc

Issue 2589163003: Add shadow/corner radius to notifications (toasts and in-center). (Closed)
Patch Set: sky reviews Created 3 years, 11 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
« no previous file with comments | « ui/gfx/image/image_skia_operations.h ('k') | ui/gfx/shadow_util.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/image/image_skia_operations.h" 5 #include "ui/gfx/image/image_skia_operations.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return ImageSkiaRep(shadow_bitmap, image_rep.scale()); 389 return ImageSkiaRep(shadow_bitmap, image_rep.scale());
390 } 390 }
391 391
392 private: 392 private:
393 const ImageSkia source_; 393 const ImageSkia source_;
394 const ShadowValues shadows_in_dip_; 394 const ShadowValues shadows_in_dip_;
395 395
396 DISALLOW_COPY_AND_ASSIGN(DropShadowSource); 396 DISALLOW_COPY_AND_ASSIGN(DropShadowSource);
397 }; 397 };
398 398
399 class ShadowNineboxSource : public CanvasImageSource {
400 public:
401 ShadowNineboxSource(const std::vector<ShadowValue>& shadows,
402 float corner_radius)
403 : CanvasImageSource(CalculateSize(shadows, corner_radius), false),
404 shadows_(shadows),
405 corner_radius_(corner_radius) {
406 DCHECK(!shadows.empty());
407 }
408 ~ShadowNineboxSource() override {}
409
410 // CanvasImageSource overrides:
411 void Draw(Canvas* canvas) override {
412 SkPaint paint;
413 paint.setLooper(CreateShadowDrawLooperCorrectBlur(shadows_));
414 Insets insets = -ShadowValue::GetMargin(shadows_);
415 gfx::Rect bounds(size());
416 bounds.Inset(insets);
417 SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectToSkRect(bounds),
418 corner_radius_, corner_radius_);
419
420 // Clip out the center so it's not painted with the shadow.
421 canvas->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference, true);
422 // Clipping alone is not enough --- due to anti aliasing there will still be
423 // some of the fill color in the rounded corners. We must make the fill
424 // color transparent.
425 paint.setColor(SK_ColorTRANSPARENT);
426 canvas->sk_canvas()->drawRRect(r_rect, paint);
427 }
428
429 private:
430 static Size CalculateSize(const std::vector<ShadowValue>& shadows,
431 float corner_radius) {
432 // The "content" area (the middle tile in the 3x3 grid) is a single pixel.
433 gfx::Rect bounds(0, 0, 1, 1);
434 // We need enough space to render the full range of blur.
435 bounds.Inset(-ShadowValue::GetBlurRegion(shadows));
436 // We also need space for the full roundrect corner rounding.
437 bounds.Inset(-gfx::Insets(corner_radius));
438 return bounds.size();
439 }
440
441 const std::vector<ShadowValue> shadows_;
442
443 const float corner_radius_;
444
445 DISALLOW_COPY_AND_ASSIGN(ShadowNineboxSource);
446 };
447
448 // An image source that is 1px wide, suitable for tiling horizontally. 399 // An image source that is 1px wide, suitable for tiling horizontally.
449 class HorizontalShadowSource : public CanvasImageSource { 400 class HorizontalShadowSource : public CanvasImageSource {
450 public: 401 public:
451 HorizontalShadowSource(const std::vector<ShadowValue>& shadows, 402 HorizontalShadowSource(const std::vector<ShadowValue>& shadows,
452 bool fades_down) 403 bool fades_down)
453 : CanvasImageSource(Size(1, GetHeightForShadows(shadows)), false), 404 : CanvasImageSource(Size(1, GetHeightForShadows(shadows)), false),
454 shadows_(shadows), 405 shadows_(shadows),
455 fades_down_(fades_down) {} 406 fades_down_(fades_down) {}
456 ~HorizontalShadowSource() override {} 407 ~HorizontalShadowSource() override {}
457 408
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 return ImageSkia(); 583 return ImageSkia();
633 584
634 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows); 585 const gfx::Insets shadow_padding = -gfx::ShadowValue::GetMargin(shadows);
635 gfx::Size shadow_image_size = source.size(); 586 gfx::Size shadow_image_size = source.size();
636 shadow_image_size.Enlarge(shadow_padding.width(), 587 shadow_image_size.Enlarge(shadow_padding.width(),
637 shadow_padding.height()); 588 shadow_padding.height());
638 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size); 589 return ImageSkia(new DropShadowSource(source, shadows), shadow_image_size);
639 } 590 }
640 591
641 // static 592 // static
642 ImageSkia ImageSkiaOperations::CreateShadowNinebox(const ShadowValues& shadows,
643 float corner_radius) {
644 auto source = new ShadowNineboxSource(shadows, corner_radius);
645 return ImageSkia(source, source->size());
646 }
647
648 // static
649 ImageSkia ImageSkiaOperations::CreateHorizontalShadow( 593 ImageSkia ImageSkiaOperations::CreateHorizontalShadow(
650 const std::vector<ShadowValue>& shadows, 594 const std::vector<ShadowValue>& shadows,
651 bool fades_down) { 595 bool fades_down) {
652 auto source = new HorizontalShadowSource(shadows, fades_down); 596 auto source = new HorizontalShadowSource(shadows, fades_down);
653 return ImageSkia(source, source->size()); 597 return ImageSkia(source, source->size());
654 } 598 }
655 599
656 // static 600 // static
657 ImageSkia ImageSkiaOperations::CreateRotatedImage( 601 ImageSkia ImageSkiaOperations::CreateRotatedImage(
658 const ImageSkia& source, 602 const ImageSkia& source,
(...skipping 14 matching lines...) Expand all
673 if (icon.isNull()) 617 if (icon.isNull())
674 return ImageSkia(); 618 return ImageSkia();
675 619
676 if (badge.isNull()) 620 if (badge.isNull())
677 return icon; 621 return icon;
678 622
679 return ImageSkia(new IconWithBadgeSource(icon, badge), icon.size()); 623 return ImageSkia(new IconWithBadgeSource(icon, badge), icon.size());
680 } 624 }
681 625
682 } // namespace gfx 626 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image_skia_operations.h ('k') | ui/gfx/shadow_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698