1 // Copyright (c) 2013 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 #include "content/browser/web_contents/aura/shadow_layer_delegate.h"
8 #include "third_party/skia/include/effects/SkGradientShader.h"
9 #include "ui/aura/window.h"
10 #include "ui/compositor/layer.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/skia_util.h"
16 const SkColor kShadowLightColor
= SkColorSetARGB(0x0, 0, 0, 0);
17 const SkColor kShadowDarkColor
= SkColorSetARGB(0x70, 0, 0, 0);
18 const int kShadowThick
= 7;
24 ShadowLayerDelegate::ShadowLayerDelegate(ui::Layer
* shadow_for
)
25 : layer_(new ui::Layer(ui::LAYER_TEXTURED
)) {
26 layer_
->set_delegate(this);
27 layer_
->SetBounds(gfx::Rect(-kShadowThick
, 0, kShadowThick
,
28 shadow_for
->bounds().height()));
29 layer_
->SetFillsBoundsOpaquely(false);
30 shadow_for
->Add(layer_
.get());
33 ShadowLayerDelegate::~ShadowLayerDelegate() {
36 void ShadowLayerDelegate::OnPaintLayer(gfx::Canvas
* canvas
) {
38 const SkColor kShadowColors
[2] = { kShadowLightColor
, kShadowDarkColor
};
41 points
[1].iset(kShadowThick
, 0);
43 skia::RefPtr
<SkShader
> shader
= skia::AdoptRef(
44 SkGradientShader::CreateLinear(points
, kShadowColors
, NULL
,
45 arraysize(points
), SkShader::kRepeat_TileMode
, NULL
));
47 gfx::Rect paint_rect
= gfx::Rect(0, 0, kShadowThick
,
48 layer_
->bounds().height());
50 paint
.setShader(shader
.get());
51 canvas
->sk_canvas()->drawRect(gfx::RectToSkRect(paint_rect
), paint
);
54 void ShadowLayerDelegate::OnDeviceScaleFactorChanged(float scale_factor
) {
57 base::Closure
ShadowLayerDelegate::PrepareForLayerBoundsChange() {
58 return base::Bind(&base::DoNothing
);
61 } // namespace content