| 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/border.h" | 5 #include "ui/views/border.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/views/painter.h" | 10 #include "ui/views/painter.h" |
| 11 #include "ui/views/view.h" | 11 #include "ui/views/view.h" |
| 12 | 12 |
| 13 namespace views { | 13 namespace views { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // A simple border with different thicknesses on each side and single color. | 17 // A simple border with different thicknesses on each side and single color. |
| 18 class SidedSolidBorder : public Border { | 18 class SidedSolidBorder : public Border { |
| 19 public: | 19 public: |
| 20 SidedSolidBorder(int top, int left, int bottom, int right, SkColor color); | 20 SidedSolidBorder(int top, int left, int bottom, int right, SkColor color); |
| 21 | 21 |
| 22 // Overridden from Border: | 22 // Overridden from Border: |
| 23 virtual void Paint(const View& view, gfx::Canvas* canvas) override; | 23 void Paint(const View& view, gfx::Canvas* canvas) override; |
| 24 virtual gfx::Insets GetInsets() const override; | 24 gfx::Insets GetInsets() const override; |
| 25 virtual gfx::Size GetMinimumSize() const override; | 25 gfx::Size GetMinimumSize() const override; |
| 26 | 26 |
| 27 private: | 27 private: |
| 28 const SkColor color_; | 28 const SkColor color_; |
| 29 const gfx::Insets insets_; | 29 const gfx::Insets insets_; |
| 30 | 30 |
| 31 DISALLOW_COPY_AND_ASSIGN(SidedSolidBorder); | 31 DISALLOW_COPY_AND_ASSIGN(SidedSolidBorder); |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 SidedSolidBorder::SidedSolidBorder(int top, | 34 SidedSolidBorder::SidedSolidBorder(int top, |
| 35 int left, | 35 int left, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 private: | 71 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(SolidBorder); | 72 DISALLOW_COPY_AND_ASSIGN(SolidBorder); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 class EmptyBorder : public Border { | 75 class EmptyBorder : public Border { |
| 76 public: | 76 public: |
| 77 EmptyBorder(int top, int left, int bottom, int right) | 77 EmptyBorder(int top, int left, int bottom, int right) |
| 78 : insets_(top, left, bottom, right) {} | 78 : insets_(top, left, bottom, right) {} |
| 79 | 79 |
| 80 // Overridden from Border: | 80 // Overridden from Border: |
| 81 virtual void Paint(const View& view, gfx::Canvas* canvas) override {} | 81 void Paint(const View& view, gfx::Canvas* canvas) override {} |
| 82 | 82 |
| 83 virtual gfx::Insets GetInsets() const override { | 83 gfx::Insets GetInsets() const override { return insets_; } |
| 84 return insets_; | |
| 85 } | |
| 86 | 84 |
| 87 virtual gfx::Size GetMinimumSize() const override { | 85 gfx::Size GetMinimumSize() const override { return gfx::Size(); } |
| 88 return gfx::Size(); | |
| 89 } | |
| 90 | 86 |
| 91 private: | 87 private: |
| 92 const gfx::Insets insets_; | 88 const gfx::Insets insets_; |
| 93 | 89 |
| 94 DISALLOW_COPY_AND_ASSIGN(EmptyBorder); | 90 DISALLOW_COPY_AND_ASSIGN(EmptyBorder); |
| 95 }; | 91 }; |
| 96 | 92 |
| 97 class BorderPainter : public Border { | 93 class BorderPainter : public Border { |
| 98 public: | 94 public: |
| 99 explicit BorderPainter(Painter* painter, const gfx::Insets& insets) | 95 explicit BorderPainter(Painter* painter, const gfx::Insets& insets) |
| 100 : painter_(painter), | 96 : painter_(painter), |
| 101 insets_(insets) { | 97 insets_(insets) { |
| 102 DCHECK(painter); | 98 DCHECK(painter); |
| 103 } | 99 } |
| 104 | 100 |
| 105 virtual ~BorderPainter() {} | 101 ~BorderPainter() override {} |
| 106 | 102 |
| 107 // Overridden from Border: | 103 // Overridden from Border: |
| 108 virtual void Paint(const View& view, gfx::Canvas* canvas) override { | 104 void Paint(const View& view, gfx::Canvas* canvas) override { |
| 109 Painter::PaintPainterAt(canvas, painter_.get(), view.GetLocalBounds()); | 105 Painter::PaintPainterAt(canvas, painter_.get(), view.GetLocalBounds()); |
| 110 } | 106 } |
| 111 | 107 |
| 112 virtual gfx::Insets GetInsets() const override { | 108 gfx::Insets GetInsets() const override { return insets_; } |
| 113 return insets_; | |
| 114 } | |
| 115 | 109 |
| 116 virtual gfx::Size GetMinimumSize() const override { | 110 gfx::Size GetMinimumSize() const override { |
| 117 return painter_->GetMinimumSize(); | 111 return painter_->GetMinimumSize(); |
| 118 } | 112 } |
| 119 | 113 |
| 120 private: | 114 private: |
| 121 scoped_ptr<Painter> painter_; | 115 scoped_ptr<Painter> painter_; |
| 122 const gfx::Insets insets_; | 116 const gfx::Insets insets_; |
| 123 | 117 |
| 124 DISALLOW_COPY_AND_ASSIGN(BorderPainter); | 118 DISALLOW_COPY_AND_ASSIGN(BorderPainter); |
| 125 }; | 119 }; |
| 126 | 120 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 new SidedSolidBorder(top, left, bottom, right, color)); | 154 new SidedSolidBorder(top, left, bottom, right, color)); |
| 161 } | 155 } |
| 162 | 156 |
| 163 // static | 157 // static |
| 164 scoped_ptr<Border> Border::CreateBorderPainter(Painter* painter, | 158 scoped_ptr<Border> Border::CreateBorderPainter(Painter* painter, |
| 165 const gfx::Insets& insets) { | 159 const gfx::Insets& insets) { |
| 166 return scoped_ptr<Border>(new BorderPainter(painter, insets)); | 160 return scoped_ptr<Border>(new BorderPainter(painter, insets)); |
| 167 } | 161 } |
| 168 | 162 |
| 169 } // namespace views | 163 } // namespace views |
| OLD | NEW |