Index: ui/views/border.cc |
diff --git a/ui/views/border.cc b/ui/views/border.cc |
index 95628735c7dd6afa1dd74c0e0504b0b1b61193b3..0ae67cf99d6f39f838bf132dfdaff688a9f69420 100644 |
--- a/ui/views/border.cc |
+++ b/ui/views/border.cc |
@@ -6,6 +6,7 @@ |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
+#include "third_party/skia/include/core/SkPaint.h" |
#include "ui/gfx/canvas.h" |
#include "ui/views/painter.h" |
#include "ui/views/view.h" |
@@ -59,6 +60,50 @@ gfx::Size SolidSidedBorder::GetMinimumSize() const { |
return gfx::Size(insets_.width(), insets_.height()); |
} |
+// A border with a rounded rectangle and single color. |
+class RoundedRectBorder : public Border { |
+ public: |
+ RoundedRectBorder(int thickness, int corner_radius, SkColor color); |
+ |
+ // Overridden from Border: |
+ void Paint(const View& view, gfx::Canvas* canvas) override; |
+ gfx::Insets GetInsets() const override; |
+ gfx::Size GetMinimumSize() const override; |
+ |
+ private: |
+ const int thickness_; |
+ const int corner_radius_; |
+ const SkColor color_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(RoundedRectBorder); |
+}; |
+ |
+RoundedRectBorder::RoundedRectBorder(int thickness, |
+ int corner_radius, |
+ SkColor color) |
+ : thickness_(thickness), corner_radius_(corner_radius), color_(color) {} |
+ |
+void RoundedRectBorder::Paint(const View& view, gfx::Canvas* canvas) { |
+ SkPaint paint; |
+ paint.setStrokeWidth(thickness_); |
+ paint.setColor(color_); |
+ paint.setStyle(SkPaint::kStroke_Style); |
+ paint.setAntiAlias(true); |
+ int half_thickness = thickness_ / 2; |
+ canvas->DrawRoundRect( |
+ gfx::Rect(half_thickness, half_thickness, view.width() - thickness_, |
+ view.height() - thickness_), |
+ corner_radius_, paint); |
+} |
+ |
+gfx::Insets RoundedRectBorder::GetInsets() const { |
+ return gfx::Insets(thickness_, thickness_, thickness_, thickness_); |
+} |
+ |
+gfx::Size RoundedRectBorder::GetMinimumSize() const { |
+ return gfx::Size(thickness_, thickness_); |
sadrul
2015/10/29 06:03:25
thickness_ * 2, right?
Matt Giuca
2015/10/29 06:40:43
Done. Thanks.
|
+} |
+ |
class EmptyBorder : public Border { |
public: |
explicit EmptyBorder(const gfx::Insets& insets); |
@@ -147,6 +192,14 @@ scoped_ptr<Border> Border::CreateEmptyBorder(const gfx::Insets& insets) { |
} |
// static |
+scoped_ptr<Border> Border::CreateRoundedRectBorder(int thickness, |
+ int corner_radius, |
+ SkColor color) { |
+ return make_scoped_ptr( |
+ new RoundedRectBorder(thickness, corner_radius, color)); |
+} |
+ |
+// static |
scoped_ptr<Border> Border::CreateEmptyBorder(int top, |
int left, |
int bottom, |