| OLD | NEW |
| 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/views/background.h" | 5 #include "ui/views/background.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 // canvas is already clipped for us. | 31 // canvas is already clipped for us. |
| 32 canvas->DrawColor(get_color()); | 32 canvas->DrawColor(get_color()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 DISALLOW_COPY_AND_ASSIGN(SolidBackground); | 36 DISALLOW_COPY_AND_ASSIGN(SolidBackground); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 class BackgroundPainter : public Background { | 39 class BackgroundPainter : public Background { |
| 40 public: | 40 public: |
| 41 BackgroundPainter(bool owns_painter, Painter* painter) | 41 explicit BackgroundPainter(std::unique_ptr<Painter> painter) |
| 42 : owns_painter_(owns_painter), painter_(painter) { | 42 : painter_(std::move(painter)) { |
| 43 DCHECK(painter); | 43 DCHECK(painter_); |
| 44 } | 44 } |
| 45 | 45 |
| 46 ~BackgroundPainter() override { | 46 ~BackgroundPainter() override {} |
| 47 if (owns_painter_) | |
| 48 delete painter_; | |
| 49 } | |
| 50 | 47 |
| 51 void Paint(gfx::Canvas* canvas, View* view) const override { | 48 void Paint(gfx::Canvas* canvas, View* view) const override { |
| 52 Painter::PaintPainterAt(canvas, painter_, view->GetLocalBounds()); | 49 Painter::PaintPainterAt(canvas, painter_.get(), view->GetLocalBounds()); |
| 53 } | 50 } |
| 54 | 51 |
| 55 private: | 52 private: |
| 56 bool owns_painter_; | 53 std::unique_ptr<Painter> painter_; |
| 57 Painter* painter_; | |
| 58 | 54 |
| 59 DISALLOW_COPY_AND_ASSIGN(BackgroundPainter); | 55 DISALLOW_COPY_AND_ASSIGN(BackgroundPainter); |
| 60 }; | 56 }; |
| 61 | 57 |
| 62 Background::Background() | 58 Background::Background() |
| 63 : color_(SK_ColorWHITE) | 59 : color_(SK_ColorWHITE) |
| 64 { | 60 { |
| 65 } | 61 } |
| 66 | 62 |
| 67 Background::~Background() { | 63 Background::~Background() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 78 | 74 |
| 79 // static | 75 // static |
| 80 Background* Background::CreateStandardPanelBackground() { | 76 Background* Background::CreateStandardPanelBackground() { |
| 81 // TODO(beng): Should be in NativeTheme. | 77 // TODO(beng): Should be in NativeTheme. |
| 82 return CreateSolidBackground(SK_ColorWHITE); | 78 return CreateSolidBackground(SK_ColorWHITE); |
| 83 } | 79 } |
| 84 | 80 |
| 85 // static | 81 // static |
| 86 Background* Background::CreateVerticalGradientBackground(SkColor color1, | 82 Background* Background::CreateVerticalGradientBackground(SkColor color1, |
| 87 SkColor color2) { | 83 SkColor color2) { |
| 88 Background* background = CreateBackgroundPainter( | 84 Background* background = |
| 89 true, Painter::CreateVerticalGradient(color1, color2)); | 85 CreateBackgroundPainter(Painter::CreateVerticalGradient(color1, color2)); |
| 90 background->SetNativeControlColor( | 86 background->SetNativeControlColor( |
| 91 color_utils::AlphaBlend(color1, color2, 128)); | 87 color_utils::AlphaBlend(color1, color2, 128)); |
| 92 | 88 |
| 93 return background; | 89 return background; |
| 94 } | 90 } |
| 95 | 91 |
| 96 // static | 92 // static |
| 97 Background* Background::CreateVerticalMultiColorGradientBackground( | 93 Background* Background::CreateBackgroundPainter( |
| 98 SkColor* colors, | 94 std::unique_ptr<Painter> painter) { |
| 99 SkScalar* pos, | 95 return new BackgroundPainter(std::move(painter)); |
| 100 size_t count) { | |
| 101 Background* background = CreateBackgroundPainter( | |
| 102 true, Painter::CreateVerticalMultiColorGradient(colors, pos, count)); | |
| 103 background->SetNativeControlColor( | |
| 104 color_utils::AlphaBlend(colors[0], colors[count-1], 128)); | |
| 105 | |
| 106 return background; | |
| 107 } | |
| 108 | |
| 109 // static | |
| 110 Background* Background::CreateBackgroundPainter(bool owns_painter, | |
| 111 Painter* painter) { | |
| 112 return new BackgroundPainter(owns_painter, painter); | |
| 113 } | 96 } |
| 114 | 97 |
| 115 } // namespace views | 98 } // namespace views |
| OLD | NEW |