Chromium Code Reviews| 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 "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 9 #include "ui/views/painter.h" | 10 #include "ui/views/painter.h" |
| 10 | 11 |
| 11 namespace views { | 12 namespace views { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // A simple border with different thicknesses on each side and single color. | 16 // A simple border with different thicknesses on each side and single color. |
| 16 class SidedSolidBorder : public Border { | 17 class SidedSolidBorder : public Border { |
| 17 public: | 18 public: |
| 18 SidedSolidBorder(int top, int left, int bottom, int right, SkColor color); | 19 SidedSolidBorder(int top, int left, int bottom, int right, SkColor color); |
| 19 | 20 |
| 20 // Overridden from Border: | 21 // Overridden from Border: |
| 21 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE; | 22 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE; |
| 22 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE; | 23 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE; |
| 23 | 24 |
| 24 private: | 25 private: |
| 25 int top_, left_, bottom_, right_; | 26 int top_; |
|
sky
2012/09/17 14:10:27
const
| |
| 27 int left_; | |
| 28 int bottom_; | |
| 29 int right_; | |
| 26 SkColor color_; | 30 SkColor color_; |
| 27 gfx::Insets insets_; | 31 gfx::Insets insets_; |
| 28 | 32 |
| 29 DISALLOW_COPY_AND_ASSIGN(SidedSolidBorder); | 33 DISALLOW_COPY_AND_ASSIGN(SidedSolidBorder); |
| 30 }; | 34 }; |
| 31 | 35 |
| 32 SidedSolidBorder::SidedSolidBorder(int top, int left, int bottom, int right, | 36 SidedSolidBorder::SidedSolidBorder(int top, int left, int bottom, int right, |
|
sky
2012/09/17 14:10:27
each param on its own line.
| |
| 33 SkColor color) | 37 SkColor color) |
| 34 : top_(top), | 38 : top_(top), |
| 35 left_(left), | 39 left_(left), |
| 36 bottom_(bottom), | 40 bottom_(bottom), |
| 37 right_(right), | 41 right_(right), |
| 38 color_(color), | 42 color_(color), |
| 39 insets_(top, left, bottom, right) { | 43 insets_(top, left, bottom, right) { |
| 40 } | 44 } |
| 41 | 45 |
| 42 void SidedSolidBorder::Paint(const View& view, gfx::Canvas* canvas) const { | 46 void SidedSolidBorder::Paint(const View& view, gfx::Canvas* canvas) const { |
| 43 // Top border. | 47 // Top border. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 DISALLOW_COPY_AND_ASSIGN(EmptyBorder); | 94 DISALLOW_COPY_AND_ASSIGN(EmptyBorder); |
| 91 }; | 95 }; |
| 92 | 96 |
| 93 class BorderPainter : public Border { | 97 class BorderPainter : public Border { |
| 94 public: | 98 public: |
| 95 explicit BorderPainter(Painter* painter) | 99 explicit BorderPainter(Painter* painter) |
| 96 : painter_(painter) { | 100 : painter_(painter) { |
| 97 DCHECK(painter); | 101 DCHECK(painter); |
| 98 } | 102 } |
| 99 | 103 |
| 100 virtual ~BorderPainter() { | 104 virtual ~BorderPainter() {} |
| 101 delete painter_; | |
| 102 painter_ = NULL; | |
| 103 } | |
| 104 | 105 |
| 105 // Overridden from Border: | 106 // Overridden from Border: |
| 106 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE { | 107 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE { |
| 107 Painter::PaintPainterAt(canvas, painter_, view.GetLocalBounds()); | 108 Painter::PaintPainterAt(canvas, painter_.get(), view.GetLocalBounds()); |
| 108 } | 109 } |
| 109 | 110 |
| 110 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE { | 111 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE { |
| 111 DCHECK(insets); | 112 DCHECK(insets); |
| 112 insets->Set(0, 0, 0, 0); | 113 insets->Set(0, 0, 0, 0); |
| 113 } | 114 } |
| 114 | 115 |
| 115 private: | 116 private: |
| 116 Painter* painter_; | 117 scoped_ptr<Painter> painter_; |
| 117 | 118 |
| 118 DISALLOW_COPY_AND_ASSIGN(BorderPainter); | 119 DISALLOW_COPY_AND_ASSIGN(BorderPainter); |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 } // namespace | 122 } // namespace |
| 122 | 123 |
| 123 Border::Border() { | 124 Border::Border() { |
| 124 } | 125 } |
| 125 | 126 |
| 126 Border::~Border() { | 127 Border::~Border() { |
| 127 } | 128 } |
| 128 | 129 |
| 129 // static | 130 // static |
| 130 Border* Border::CreateSolidBorder(int thickness, SkColor color) { | 131 Border* Border::CreateSolidBorder(int thickness, SkColor color) { |
| 131 return new SolidBorder(thickness, color); | 132 return new SolidBorder(thickness, color); |
| 132 } | 133 } |
| 133 | 134 |
| 134 // static | 135 // static |
| 135 Border* Border::CreateEmptyBorder(int top, int left, int bottom, int right) { | 136 Border* Border::CreateEmptyBorder(int top, int left, int bottom, int right) { |
| 136 return new EmptyBorder(top, left, bottom, right); | 137 return new EmptyBorder(top, left, bottom, right); |
| 137 } | 138 } |
| 138 | 139 |
| 139 // static | 140 // static |
| 140 Border* Border::CreateSolidSidedBorder(int top, int left, | 141 Border* Border::CreateSolidSidedBorder(int top, int left, |
|
sky
2012/09/17 14:10:27
each param on its own line.
| |
| 141 int bottom, int right, | 142 int bottom, int right, |
| 142 SkColor color) { | 143 SkColor color) { |
| 143 return new SidedSolidBorder(top, left, bottom, right, color); | 144 return new SidedSolidBorder(top, left, bottom, right, color); |
| 144 } | 145 } |
| 145 | 146 |
| 146 //static | 147 // static |
| 147 Border* Border::CreateBorderPainter(Painter* painter) { | 148 Border* Border::CreateBorderPainter(Painter* painter) { |
| 148 return new BorderPainter(painter); | 149 return new BorderPainter(painter); |
| 149 } | 150 } |
| 150 | 151 |
| 151 } // namespace views | 152 } // namespace views |
| OLD | NEW |