Correct blacklist entry message
[chromium-blink-merge.git] / ui / views / border.cc
blob5de602fd50bea99c244bb4b67e681a35e45d1905
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
3 // found in the LICENSE file.
5 #include "ui/views/border.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/views/painter.h"
12 namespace views {
14 namespace {
16 // A simple border with different thicknesses on each side and single color.
17 class SidedSolidBorder : public Border {
18 public:
19 SidedSolidBorder(int top, int left, int bottom, int right, SkColor color);
21 // Overridden from Border:
22 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE;
23 virtual gfx::Insets GetInsets() const OVERRIDE;
25 private:
26 const SkColor color_;
27 const gfx::Insets insets_;
29 DISALLOW_COPY_AND_ASSIGN(SidedSolidBorder);
32 SidedSolidBorder::SidedSolidBorder(int top,
33 int left,
34 int bottom,
35 int right,
36 SkColor color)
37 : color_(color),
38 insets_(top, left, bottom, right) {
41 void SidedSolidBorder::Paint(const View& view, gfx::Canvas* canvas) {
42 // Top border.
43 canvas->FillRect(gfx::Rect(0, 0, view.width(), insets_.top()), color_);
44 // Left border.
45 canvas->FillRect(gfx::Rect(0, 0, insets_.left(), view.height()), color_);
46 // Bottom border.
47 canvas->FillRect(gfx::Rect(0, view.height() - insets_.bottom(), view.width(),
48 insets_.bottom()), color_);
49 // Right border.
50 canvas->FillRect(gfx::Rect(view.width() - insets_.right(), 0, insets_.right(),
51 view.height()), color_);
54 gfx::Insets SidedSolidBorder::GetInsets() const {
55 return insets_;
58 // A variation of SidedSolidBorder, where each side has the same thickness.
59 class SolidBorder : public SidedSolidBorder {
60 public:
61 SolidBorder(int thickness, SkColor color)
62 : SidedSolidBorder(thickness, thickness, thickness, thickness, color) {
65 private:
66 DISALLOW_COPY_AND_ASSIGN(SolidBorder);
69 class EmptyBorder : public Border {
70 public:
71 EmptyBorder(int top, int left, int bottom, int right)
72 : insets_(top, left, bottom, right) {}
74 // Overridden from Border:
75 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE {}
77 virtual gfx::Insets GetInsets() const OVERRIDE {
78 return insets_;
81 private:
82 const gfx::Insets insets_;
84 DISALLOW_COPY_AND_ASSIGN(EmptyBorder);
87 class BorderPainter : public Border {
88 public:
89 explicit BorderPainter(Painter* painter, const gfx::Insets& insets)
90 : painter_(painter),
91 insets_(insets) {
92 DCHECK(painter);
95 virtual ~BorderPainter() {}
97 // Overridden from Border:
98 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE {
99 Painter::PaintPainterAt(canvas, painter_.get(), view.GetLocalBounds());
102 virtual gfx::Insets GetInsets() const OVERRIDE {
103 return insets_;
106 private:
107 scoped_ptr<Painter> painter_;
108 const gfx::Insets insets_;
110 DISALLOW_COPY_AND_ASSIGN(BorderPainter);
113 } // namespace
115 Border::Border() {
118 Border::~Border() {
121 // static
122 Border* Border::CreateSolidBorder(int thickness, SkColor color) {
123 return new SolidBorder(thickness, color);
126 // static
127 Border* Border::CreateEmptyBorder(int top, int left, int bottom, int right) {
128 return new EmptyBorder(top, left, bottom, right);
131 // static
132 Border* Border::CreateSolidSidedBorder(int top,
133 int left,
134 int bottom,
135 int right,
136 SkColor color) {
137 return new SidedSolidBorder(top, left, bottom, right, color);
140 // static
141 Border* Border::CreateBorderPainter(Painter* painter,
142 const gfx::Insets& insets) {
143 return new BorderPainter(painter, insets);
146 TextButtonBorder* Border::AsTextButtonBorder() {
147 return NULL;
150 const TextButtonBorder* Border::AsTextButtonBorder() const {
151 return NULL;
154 } // namespace views