summaryrefslogtreecommitdiffstats
path: root/ui/views/painter.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-05 04:19:35 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-05 04:19:35 +0000
commit1966d6d1568191bb984efd30f20d884553e35450 (patch)
treecac5a77663b4c5a976970be83ad9dff926ed4599 /ui/views/painter.cc
parentfc18b9eacd5657f6ebc3b5f9e6a72ddcf751896e (diff)
downloadchromium_src-1966d6d1568191bb984efd30f20d884553e35450.zip
chromium_src-1966d6d1568191bb984efd30f20d884553e35450.tar.gz
chromium_src-1966d6d1568191bb984efd30f20d884553e35450.tar.bz2
Removes FocusBorder from views
This patch removes FocusBorder from View along with View::OnPaintFocusBorder. Views that want to render focus and that need to allow overriding get a Painter that is responsible for rendering the focus. Views that render focus differently must override OnFocus/OnBlur to SchedulePaint the necessary region. This patch simplifies View and cleans things up for views that don't ever want to paint focus, or paint focus differently (say TableView, or Textfield). On the down side it does mean any view that is focusable needs to override a few more additional methods. It was easy to get this wrong previously though as a common pattern is to override OnPaint and not invoke View::OnPaint. BUG=none TEST=none R=ben@chromium.org Review URL: https://codereview.chromium.org/105013002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238888 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/painter.cc')
-rw-r--r--ui/views/painter.cc99
1 files changed, 97 insertions, 2 deletions
diff --git a/ui/views/painter.cc b/ui/views/painter.cc
index ce84a58..b6a2e7d 100644
--- a/ui/views/painter.cc
+++ b/ui/views/painter.cc
@@ -15,12 +15,83 @@
#include "ui/gfx/insets.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
-
+#include "ui/views/view.h"
namespace views {
namespace {
+// DashedFocusPainter ----------------------------------------------------------
+
+class DashedFocusPainter : public Painter {
+ public:
+ explicit DashedFocusPainter(const gfx::Insets& insets);
+ virtual ~DashedFocusPainter();
+
+ // Painter:
+ virtual gfx::Size GetMinimumSize() const OVERRIDE;
+ virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE;
+
+ private:
+ const gfx::Insets insets_;
+
+ DISALLOW_COPY_AND_ASSIGN(DashedFocusPainter);
+};
+
+DashedFocusPainter::DashedFocusPainter(const gfx::Insets& insets)
+ : insets_(insets) {
+}
+
+DashedFocusPainter::~DashedFocusPainter() {
+}
+
+gfx::Size DashedFocusPainter::GetMinimumSize() const {
+ return gfx::Size();
+}
+
+void DashedFocusPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) {
+ gfx::Rect rect(size);
+ rect.Inset(insets_);
+ canvas->DrawFocusRect(rect);
+}
+
+// SolidFocusPainter -----------------------------------------------------------
+
+class SolidFocusPainter : public Painter {
+ public:
+ SolidFocusPainter(SkColor color, const gfx::Insets& insets);
+ virtual ~SolidFocusPainter();
+
+ // Painter:
+ virtual gfx::Size GetMinimumSize() const OVERRIDE;
+ virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE;
+
+ private:
+ const SkColor color_;
+ const gfx::Insets insets_;
+
+ DISALLOW_COPY_AND_ASSIGN(SolidFocusPainter);
+};
+
+SolidFocusPainter::SolidFocusPainter(SkColor color,
+ const gfx::Insets& insets)
+ : color_(color),
+ insets_(insets) {
+}
+
+SolidFocusPainter::~SolidFocusPainter() {
+}
+
+gfx::Size SolidFocusPainter::GetMinimumSize() const {
+ return gfx::Size();
+}
+
+void SolidFocusPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) {
+ gfx::Rect rect(size);
+ rect.Inset(insets_);
+ canvas->DrawSolidFocusRect(rect, color_);
+}
+
// GradientPainter ------------------------------------------------------------
class GradientPainter : public Painter {
@@ -88,7 +159,6 @@ void GradientPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) {
SkIntToScalar(size.height()), paint);
}
-
// ImagePainter ---------------------------------------------------------------
// ImagePainter stores and paints nine images as a scalable grid.
@@ -239,6 +309,14 @@ void Painter::PaintPainterAt(gfx::Canvas* canvas,
}
// static
+void Painter::PaintFocusPainter(View* view,
+ gfx::Canvas* canvas,
+ Painter* focus_painter) {
+ if (focus_painter && view->HasFocus())
+ PaintPainterAt(canvas, focus_painter, view->GetLocalBounds());
+}
+
+// static
Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) {
SkColor colors[2];
colors[0] = c1;
@@ -274,6 +352,23 @@ Painter* Painter::CreateImageGridPainter(const int image_ids[]) {
return new ImagePainter(image_ids);
}
+// static
+scoped_ptr<Painter> Painter::CreateDashedFocusPainter() {
+ return scoped_ptr<Painter>(new DashedFocusPainter(gfx::Insets())).Pass();
+}
+
+// static
+scoped_ptr<Painter> Painter::CreateDashedFocusPainterWithInsets(
+ const gfx::Insets& insets) {
+ return scoped_ptr<Painter>(new DashedFocusPainter(insets)).Pass();
+}
+
+// static
+scoped_ptr<Painter> Painter::CreateSolidFocusPainter(
+ SkColor color,
+ const gfx::Insets& insets) {
+ return scoped_ptr<Painter>(new SolidFocusPainter(color, insets)).Pass();
+}
// HorizontalPainter ----------------------------------------------------------