summaryrefslogtreecommitdiff
path: root/chromium/ui/views/background.cc
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
committerZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
commit679147eead574d186ebf3069647b4c23e8ccace6 (patch)
treefc247a0ac8ff119f7c8550879ebb6d3dd8d1ff69 /chromium/ui/views/background.cc
downloadqtwebengine-chromium-679147eead574d186ebf3069647b4c23e8ccace6.tar.gz
Initial import.
Diffstat (limited to 'chromium/ui/views/background.cc')
-rw-r--r--chromium/ui/views/background.cc135
1 files changed, 135 insertions, 0 deletions
diff --git a/chromium/ui/views/background.cc b/chromium/ui/views/background.cc
new file mode 100644
index 00000000000..b37318dc2b4
--- /dev/null
+++ b/chromium/ui/views/background.cc
@@ -0,0 +1,135 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/background.h"
+
+#include "base/logging.h"
+#include "skia/ext/skia_utils_win.h"
+#include "third_party/skia/include/core/SkPaint.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/color_utils.h"
+#include "ui/views/painter.h"
+#include "ui/views/view.h"
+
+namespace views {
+
+// SolidBackground is a trivial Background implementation that fills the
+// background in a solid color.
+class SolidBackground : public Background {
+ public:
+ explicit SolidBackground(SkColor color) {
+ SetNativeControlColor(color);
+ }
+
+ virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE {
+ // Fill the background. Note that we don't constrain to the bounds as
+ // canvas is already clipped for us.
+ canvas->DrawColor(get_color());
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SolidBackground);
+};
+
+class BackgroundPainter : public Background {
+ public:
+ BackgroundPainter(bool owns_painter, Painter* painter)
+ : owns_painter_(owns_painter), painter_(painter) {
+ DCHECK(painter);
+ }
+
+ virtual ~BackgroundPainter() {
+ if (owns_painter_)
+ delete painter_;
+ }
+
+
+ virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE {
+ Painter::PaintPainterAt(canvas, painter_, view->GetLocalBounds());
+ }
+
+ private:
+ bool owns_painter_;
+ Painter* painter_;
+
+ DISALLOW_COPY_AND_ASSIGN(BackgroundPainter);
+};
+
+Background::Background()
+ : color_(SK_ColorWHITE)
+#if defined(OS_WIN)
+ , native_control_brush_(NULL)
+#endif
+{
+}
+
+Background::~Background() {
+#if defined(OS_WIN)
+ DeleteObject(native_control_brush_);
+#endif
+}
+
+void Background::SetNativeControlColor(SkColor color) {
+ color_ = color;
+#if defined(OS_WIN)
+ DeleteObject(native_control_brush_);
+ native_control_brush_ = NULL;
+#endif
+}
+
+#if defined(OS_WIN)
+HBRUSH Background::GetNativeControlBrush() const {
+ if (!native_control_brush_)
+ native_control_brush_ = CreateSolidBrush(skia::SkColorToCOLORREF(color_));
+ return native_control_brush_;
+}
+#endif
+
+//static
+Background* Background::CreateSolidBackground(SkColor color) {
+ return new SolidBackground(color);
+}
+
+//static
+Background* Background::CreateStandardPanelBackground() {
+ // TODO(beng): Should be in NativeTheme.
+#if defined(USE_AURA)
+ return CreateSolidBackground(SK_ColorWHITE);
+#else
+ return CreateVerticalGradientBackground(SkColorSetRGB(246, 250, 255),
+ SkColorSetRGB(219, 235, 255));
+#endif
+}
+
+//static
+Background* Background::CreateVerticalGradientBackground(SkColor color1,
+ SkColor color2) {
+ Background* background = CreateBackgroundPainter(
+ true, Painter::CreateVerticalGradient(color1, color2));
+ background->SetNativeControlColor(
+ color_utils::AlphaBlend(color1, color2, 128));
+
+ return background;
+}
+
+//static
+Background* Background::CreateVerticalMultiColorGradientBackground(
+ SkColor* colors,
+ SkScalar* pos,
+ size_t count) {
+ Background* background = CreateBackgroundPainter(
+ true, Painter::CreateVerticalMultiColorGradient(colors, pos, count));
+ background->SetNativeControlColor(
+ color_utils::AlphaBlend(colors[0], colors[count-1], 128));
+
+ return background;
+}
+
+//static
+Background* Background::CreateBackgroundPainter(bool owns_painter,
+ Painter* painter) {
+ return new BackgroundPainter(owns_painter, painter);
+}
+
+} // namespace views