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

Unified Diff: ui/views/background.cc

Issue 2637383003: Change Painter factory functions to unique_ptr (Closed)
Patch Set: msw review 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/background.h ('k') | ui/views/bubble/bubble_border.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/background.cc
diff --git a/ui/views/background.cc b/ui/views/background.cc
index 56f1eb36405ad801fc649a7091a1222e3bc1f22c..f8bf1b69578fb8c35f686b21bbc02a6f096825de 100644
--- a/ui/views/background.cc
+++ b/ui/views/background.cc
@@ -38,23 +38,19 @@ class SolidBackground : public Background {
class BackgroundPainter : public Background {
public:
- BackgroundPainter(bool owns_painter, Painter* painter)
- : owns_painter_(owns_painter), painter_(painter) {
- DCHECK(painter);
+ explicit BackgroundPainter(std::unique_ptr<Painter> painter)
+ : painter_(std::move(painter)) {
+ DCHECK(painter_);
}
- ~BackgroundPainter() override {
- if (owns_painter_)
- delete painter_;
- }
+ ~BackgroundPainter() override {}
void Paint(gfx::Canvas* canvas, View* view) const override {
- Painter::PaintPainterAt(canvas, painter_, view->GetLocalBounds());
+ Painter::PaintPainterAt(canvas, painter_.get(), view->GetLocalBounds());
}
private:
- bool owns_painter_;
- Painter* painter_;
+ std::unique_ptr<Painter> painter_;
DISALLOW_COPY_AND_ASSIGN(BackgroundPainter);
};
@@ -85,8 +81,8 @@ Background* Background::CreateStandardPanelBackground() {
// static
Background* Background::CreateVerticalGradientBackground(SkColor color1,
SkColor color2) {
- Background* background = CreateBackgroundPainter(
- true, Painter::CreateVerticalGradient(color1, color2));
+ Background* background =
+ CreateBackgroundPainter(Painter::CreateVerticalGradient(color1, color2));
background->SetNativeControlColor(
color_utils::AlphaBlend(color1, color2, 128));
@@ -94,22 +90,9 @@ Background* Background::CreateVerticalGradientBackground(SkColor color1,
}
// static
-Background* Background::CreateVerticalMultiColorGradientBackground(
- SkColor* colors,
- SkScalar* pos,
- size_t count) {
- Background* background = CreateBackgroundPainter(
- true, Painter::CreateVerticalMultiColorGradient(colors, pos, count));
- background->SetNativeControlColor(
- color_utils::AlphaBlend(colors[0], colors[count-1], 128));
-
- return background;
-}
-
-// static
-Background* Background::CreateBackgroundPainter(bool owns_painter,
- Painter* painter) {
- return new BackgroundPainter(owns_painter, painter);
+Background* Background::CreateBackgroundPainter(
+ std::unique_ptr<Painter> painter) {
+ return new BackgroundPainter(std::move(painter));
}
} // namespace views
« no previous file with comments | « ui/views/background.h ('k') | ui/views/bubble/bubble_border.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698