Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Unified Diff: ui/views/border.cc

Issue 1428623005: views::Border: Added CreateRoundedRectBorder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@boxlayout-collapse_when_hidden
Patch Set: Rebase. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/border.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « ui/views/border.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698