[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / ui / views / painter.h
blobd4b0daa080edc63657a8d3daba5bcae011b34edc
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 #ifndef UI_VIEWS_PAINTER_H_
6 #define UI_VIEWS_PAINTER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/views/views_export.h"
13 namespace gfx {
14 class Canvas;
15 class ImageSkia;
16 class Insets;
17 class Rect;
18 class Size;
21 // A macro to define arrays of IDR constants used with CreateImageGridPainter.
22 #define IMAGE_GRID(x) { x ## _TOP_LEFT, x ## _TOP, x ## _TOP_RIGHT, \
23 x ## _LEFT, x ## _CENTER, x ## _RIGHT, \
24 x ## _BOTTOM_LEFT, x ## _BOTTOM, x ## _BOTTOM_RIGHT, }
26 namespace views {
28 // Painter, as the name implies, is responsible for painting in a particular
29 // region. Think of Painter as a Border or Background that can be painted
30 // in any region of a View.
31 class VIEWS_EXPORT Painter {
32 public:
33 // A convenience method for painting a Painter in a particular region.
34 // This translates the canvas to x/y and paints the painter.
35 static void PaintPainterAt(gfx::Canvas* canvas,
36 Painter* painter,
37 const gfx::Rect& rect);
39 // Creates a painter that draws a gradient between the two colors.
40 static Painter* CreateHorizontalGradient(SkColor c1, SkColor c2);
41 static Painter* CreateVerticalGradient(SkColor c1, SkColor c2);
43 // Creates a painter that draws a multi-color gradient. |colors| contains the
44 // gradient colors and |pos| the relative positions of the colors. The first
45 // element in |pos| must be 0.0 and the last element 1.0. |count| contains
46 // the number of elements in |colors| and |pos|.
47 static Painter* CreateVerticalMultiColorGradient(SkColor* colors,
48 SkScalar* pos,
49 size_t count);
51 // Creates a painter that divides |image| into nine regions. The four corners
52 // are rendered at the size specified in insets (eg. the upper-left corner is
53 // rendered at 0 x 0 with a size of insets.left() x insets.top()). The four
54 // edges are tiled and the center is stretched to fill the destination size.
55 static Painter* CreateImagePainter(const gfx::ImageSkia& image,
56 const gfx::Insets& insets);
58 // Creates a painter that paints nine images as a scalable grid. The four
59 // corners are rendered in their full sizes (they are assumed to share widths
60 // by column and heights by row). The four edges are tiled and the center is
61 // stretched to fill the destination size.
62 // |image_ids| must contain nine image IDs specified in this order: Top-Left,
63 // Top, Top-Right, Left, Center, Right, Bottom-Left, Bottom, Bottom-Right.
64 static Painter* CreateImageGridPainter(const int image_ids[]);
66 virtual ~Painter() {}
68 // Paints the painter in the specified region.
69 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) = 0;
72 // HorizontalPainter paints 3 images into a box: left, center and right. The
73 // left and right images are drawn to size at the left/right edges of the
74 // region. The center is tiled in the remaining space. All images must have the
75 // same height.
76 class VIEWS_EXPORT HorizontalPainter : public Painter {
77 public:
78 // Constructs a new HorizontalPainter loading the specified image names.
79 // The images must be in the order left, right and center.
80 explicit HorizontalPainter(const int image_resource_names[]);
82 virtual ~HorizontalPainter() {}
84 // Paints the images.
85 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE;
87 // Height of the images.
88 int height() const { return height_; }
90 private:
91 // The image chunks.
92 enum BorderElements {
93 LEFT,
94 CENTER,
95 RIGHT
98 // The height.
99 int height_;
100 // NOTE: the images are owned by ResourceBundle. Don't free them.
101 const gfx::ImageSkia* images_[3];
103 DISALLOW_COPY_AND_ASSIGN(HorizontalPainter);
106 } // namespace views
108 #endif // UI_VIEWS_PAINTER_H_