1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "ui/message_center/views/notification_background_painter.h"
6 
7 #include "third_party/skia/include/core/SkPath.h"
8 #include "ui/gfx/canvas.h"
9 #include "ui/gfx/geometry/rect.h"
10 #include "ui/gfx/geometry/size.h"
11 #include "ui/gfx/skia_util.h"
12 
13 namespace message_center {
14 
NotificationBackgroundPainter(int top_radius,int bottom_radius,SkColor color)15 NotificationBackgroundPainter::NotificationBackgroundPainter(int top_radius,
16                                                              int bottom_radius,
17                                                              SkColor color)
18     : top_radius_(SkIntToScalar(top_radius)),
19       bottom_radius_(SkIntToScalar(bottom_radius)),
20       color_(color) {}
21 
22 NotificationBackgroundPainter::~NotificationBackgroundPainter() = default;
23 
GetMinimumSize() const24 gfx::Size NotificationBackgroundPainter::GetMinimumSize() const {
25   return gfx::Size();
26 }
27 
Paint(gfx::Canvas * canvas,const gfx::Size & size)28 void NotificationBackgroundPainter::Paint(gfx::Canvas* canvas,
29                                           const gfx::Size& size) {
30   SkPath path;
31   SkScalar radii[8] = {top_radius_,    top_radius_,    top_radius_,
32                        top_radius_,    bottom_radius_, bottom_radius_,
33                        bottom_radius_, bottom_radius_};
34   gfx::Rect rect(size);
35   rect.Inset(insets_);
36   path.addRoundRect(gfx::RectToSkRect(rect), radii);
37 
38   cc::PaintFlags flags;
39   flags.setAntiAlias(true);
40   flags.setStyle(cc::PaintFlags::kFill_Style);
41   flags.setColor(color_);
42   canvas->DrawPath(path, flags);
43 }
44 
45 }  // namespace message_center
46