Revert of Output closure-compiled JavaScript files (patchset #10 id:180001 of https...
[chromium-blink-merge.git] / ui / views / border.cc
blob6e28cafb884debe05c05f5a638e179f3062f637f
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"
11 #include "ui/views/view.h"
13 namespace views {
15 namespace {
17 // A simple border with different thicknesses on each side and single color.
18 class SidedSolidBorder : public Border {
19 public:
20 SidedSolidBorder(int top, int left, int bottom, int right, SkColor color);
22 // Overridden from Border:
23 void Paint(const View& view, gfx::Canvas* canvas) override;
24 gfx::Insets GetInsets() const override;
25 gfx::Size GetMinimumSize() const override;
27 private:
28 const SkColor color_;
29 const gfx::Insets insets_;
31 DISALLOW_COPY_AND_ASSIGN(SidedSolidBorder);
34 SidedSolidBorder::SidedSolidBorder(int top,
35 int left,
36 int bottom,
37 int right,
38 SkColor color)
39 : color_(color),
40 insets_(top, left, bottom, right) {
43 void SidedSolidBorder::Paint(const View& view, gfx::Canvas* canvas) {
44 // Top border.
45 canvas->FillRect(gfx::Rect(0, 0, view.width(), insets_.top()), color_);
46 // Left border.
47 canvas->FillRect(gfx::Rect(0, 0, insets_.left(), view.height()), color_);
48 // Bottom border.
49 canvas->FillRect(gfx::Rect(0, view.height() - insets_.bottom(), view.width(),
50 insets_.bottom()), color_);
51 // Right border.
52 canvas->FillRect(gfx::Rect(view.width() - insets_.right(), 0, insets_.right(),
53 view.height()), color_);
56 gfx::Insets SidedSolidBorder::GetInsets() const {
57 return insets_;
60 gfx::Size SidedSolidBorder::GetMinimumSize() const {
61 return gfx::Size(insets_.width(), insets_.height());
64 // A variation of SidedSolidBorder, where each side has the same thickness.
65 class SolidBorder : public SidedSolidBorder {
66 public:
67 SolidBorder(int thickness, SkColor color)
68 : SidedSolidBorder(thickness, thickness, thickness, thickness, color) {
71 private:
72 DISALLOW_COPY_AND_ASSIGN(SolidBorder);
75 class EmptyBorder : public Border {
76 public:
77 EmptyBorder(int top, int left, int bottom, int right)
78 : insets_(top, left, bottom, right) {}
80 // Overridden from Border:
81 void Paint(const View& view, gfx::Canvas* canvas) override {}
83 gfx::Insets GetInsets() const override { return insets_; }
85 gfx::Size GetMinimumSize() const override { return gfx::Size(); }
87 private:
88 const gfx::Insets insets_;
90 DISALLOW_COPY_AND_ASSIGN(EmptyBorder);
93 class BorderPainter : public Border {
94 public:
95 explicit BorderPainter(Painter* painter, const gfx::Insets& insets)
96 : painter_(painter),
97 insets_(insets) {
98 DCHECK(painter);
101 ~BorderPainter() override {}
103 // Overridden from Border:
104 void Paint(const View& view, gfx::Canvas* canvas) override {
105 Painter::PaintPainterAt(canvas, painter_.get(), view.GetLocalBounds());
108 gfx::Insets GetInsets() const override { return insets_; }
110 gfx::Size GetMinimumSize() const override {
111 return painter_->GetMinimumSize();
114 private:
115 scoped_ptr<Painter> painter_;
116 const gfx::Insets insets_;
118 DISALLOW_COPY_AND_ASSIGN(BorderPainter);
121 } // namespace
123 Border::Border() {
126 Border::~Border() {
129 // static
130 scoped_ptr<Border> Border::NullBorder() {
131 return nullptr;
134 // static
135 scoped_ptr<Border> Border::CreateSolidBorder(int thickness, SkColor color) {
136 return make_scoped_ptr(new SolidBorder(thickness, color));
139 // static
140 scoped_ptr<Border> Border::CreateEmptyBorder(int top,
141 int left,
142 int bottom,
143 int right) {
144 return make_scoped_ptr(new EmptyBorder(top, left, bottom, right));
147 // static
148 scoped_ptr<Border> Border::CreateSolidSidedBorder(int top,
149 int left,
150 int bottom,
151 int right,
152 SkColor color) {
153 return make_scoped_ptr(new SidedSolidBorder(top, left, bottom, right, color));
156 // static
157 scoped_ptr<Border> Border::CreateBorderPainter(Painter* painter,
158 const gfx::Insets& insets) {
159 return make_scoped_ptr(new BorderPainter(painter, insets));
162 } // namespace views