(Views only) Add a gradient background to the tabstrip of the view tabbed pane implementation.

BUG=138063
TEST=none


Review URL: https://chromiumcodereview.appspot.com/10823229

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151017 0039d316-1c4b-4281-b951-d872f2087c98
parent a34cc099
...@@ -113,6 +113,19 @@ Background* Background::CreateVerticalGradientBackground(SkColor color1, ...@@ -113,6 +113,19 @@ Background* Background::CreateVerticalGradientBackground(SkColor color1,
return background; 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 //static
Background* Background::CreateBackgroundPainter(bool owns_painter, Background* Background::CreateBackgroundPainter(bool owns_painter,
Painter* painter) { Painter* painter) {
......
...@@ -59,6 +59,15 @@ class VIEWS_EXPORT Background { ...@@ -59,6 +59,15 @@ class VIEWS_EXPORT Background {
static Background* CreateVerticalGradientBackground(SkColor color1, static Background* CreateVerticalGradientBackground(SkColor color1,
SkColor color2); SkColor color2);
// Creates a background that contains a vertical gradient. The gradient can
// have multiple |colors|. The |pos| array contains the relative positions of
// each corresponding color. |colors| and |pos| must be the same size. The
// first element in |pos| must be 0.0 and the last element must be 1.0.
// |count| contains the number of elements in |colors| and |pos|.
static Background* CreateVerticalMultiColorGradientBackground(SkColor* colors,
SkScalar* pos,
size_t count);
// Creates Chrome's standard panel background // Creates Chrome's standard panel background
static Background* CreateStandardPanelBackground(); static Background* CreateStandardPanelBackground();
......
...@@ -124,6 +124,20 @@ class TabStrip : public View { ...@@ -124,6 +124,20 @@ class TabStrip : public View {
explicit TabStrip(NativeTabbedPaneViews* owner) explicit TabStrip(NativeTabbedPaneViews* owner)
: owner_(owner), : owner_(owner),
selected_tab_(NULL) { selected_tab_(NULL) {
const int kCount = 4;
// The gradient colors are derived from the tabbed panes used for the
// WebUI.
SkColor colors[] = {
SkColorSetRGB(0xff, 0xff, 0xff),
SkColorSetRGB(0xff, 0xff, 0xff),
SkColorSetRGB(0xfa, 0xfa, 0xfa),
SkColorSetRGB(0xf2, 0xf2, 0xf2)
};
// The relative positions of the gradient colors are derived from the
// tabbed panes used for the WebUI.
SkScalar pos[4] = {0.0f, 0.6f, 0.8f, 1.0f};
set_background(Background::CreateVerticalMultiColorGradientBackground(
colors, pos, kCount));
} }
virtual ~TabStrip() {} virtual ~TabStrip() {}
...@@ -167,6 +181,9 @@ class TabStrip : public View { ...@@ -167,6 +181,9 @@ class TabStrip : public View {
} }
} }
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
OnPaintBackground(canvas);
// Draw the TabStrip border.
SkPaint paint; SkPaint paint;
paint.setColor(kTabBorderColor); paint.setColor(kTabBorderColor);
paint.setStrokeWidth(kTabBorderThickness); paint.setStrokeWidth(kTabBorderThickness);
......
...@@ -20,13 +20,24 @@ namespace { ...@@ -20,13 +20,24 @@ namespace {
class GradientPainter : public Painter { class GradientPainter : public Painter {
public: public:
GradientPainter(bool horizontal, SkColor top, SkColor bottom) GradientPainter(bool horizontal,
: horizontal_(horizontal) { SkColor* colors,
colors_[0] = top; SkScalar* pos,
colors_[1] = bottom; size_t count)
: horizontal_(horizontal),
count_(count) {
pos_ = new SkScalar[count_];
colors_ = new SkColor[count_];
for (size_t i = 0; i < count_; ++i) {
pos_[i] = pos[i];
colors_[i] = colors[i];
}
} }
virtual ~GradientPainter() { virtual ~GradientPainter() {
delete[] pos_;
delete[] colors_;
} }
// Overridden from Painter: // Overridden from Painter:
...@@ -39,7 +50,7 @@ class GradientPainter : public Painter { ...@@ -39,7 +50,7 @@ class GradientPainter : public Painter {
else else
p[1].iset(0, size.height()); p[1].iset(0, size.height());
SkShader* s = SkGradientShader::CreateLinear(p, colors_, NULL, 2, SkShader* s = SkGradientShader::CreateLinear(p, colors_, pos_, count_,
SkShader::kClamp_TileMode, NULL); SkShader::kClamp_TileMode, NULL);
paint.setStyle(SkPaint::kFill_Style); paint.setStyle(SkPaint::kFill_Style);
paint.setShader(s); paint.setShader(s);
...@@ -52,8 +63,14 @@ class GradientPainter : public Painter { ...@@ -52,8 +63,14 @@ class GradientPainter : public Painter {
} }
private: private:
// If |horizontal_| is true then the gradiant is painted horizontally.
bool horizontal_; bool horizontal_;
SkColor colors_[2]; // The gradient colors.
SkColor* colors_;
// The relative positions of the corresponding gradient colors.
SkScalar* pos_;
// The number of elements in |colors_| and |pos_|.
size_t count_;
DISALLOW_COPY_AND_ASSIGN(GradientPainter); DISALLOW_COPY_AND_ASSIGN(GradientPainter);
}; };
...@@ -163,12 +180,27 @@ void Painter::PaintPainterAt(gfx::Canvas* canvas, ...@@ -163,12 +180,27 @@ void Painter::PaintPainterAt(gfx::Canvas* canvas,
// static // static
Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) { Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) {
return new GradientPainter(true, c1, c2); SkColor colors[2];
colors[0] = c1;
colors[1] = c2;
SkScalar pos[] = {0, 1};
return new GradientPainter(true, colors, pos, 2);
} }
// static // static
Painter* Painter::CreateVerticalGradient(SkColor c1, SkColor c2) { Painter* Painter::CreateVerticalGradient(SkColor c1, SkColor c2) {
return new GradientPainter(false, c1, c2); SkColor colors[2];
colors[0] = c1;
colors[1] = c2;
SkScalar pos[] = {0, 1};
return new GradientPainter(false, colors, pos, 2);
}
// static
Painter* Painter::CreateVerticalMultiColorGradient(SkColor* colors,
SkScalar* pos,
size_t count) {
return new GradientPainter(false, colors, pos, count);
} }
// static // static
......
...@@ -35,6 +35,14 @@ class VIEWS_EXPORT Painter { ...@@ -35,6 +35,14 @@ class VIEWS_EXPORT Painter {
static Painter* CreateHorizontalGradient(SkColor c1, SkColor c2); static Painter* CreateHorizontalGradient(SkColor c1, SkColor c2);
static Painter* CreateVerticalGradient(SkColor c1, SkColor c2); static Painter* CreateVerticalGradient(SkColor c1, SkColor c2);
// Creates a painter that draws a multi-color gradient. |colors| contains the
// gradient colors and |pos| the relative positions of the colors. The first
// element in |pos| must be 0.0 and the last element 1.0. |count| contains
// the number of elements in |colors| and |pos|.
static Painter* CreateVerticalMultiColorGradient(SkColor* colors,
SkScalar* pos,
size_t count);
// Creates a painter that divides |image| into nine regions. The four corners // Creates a painter that divides |image| into nine regions. The four corners
// are rendered at the size specified in insets (for example, the upper // are rendered at the size specified in insets (for example, the upper
// left corners is rendered at 0x0 with a size of // left corners is rendered at 0x0 with a size of
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment