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/compositor/paint_recorder.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/skia_util.h"
17 const SkColor kShadowLightColor
= SkColorSetARGB(0x0, 0, 0, 0);
18 const SkColor kShadowDarkColor
= SkColorSetARGB(0x70, 0, 0, 0);
19 const int kShadowThick
= 7;
25 ShadowLayerDelegate::ShadowLayerDelegate(ui::Layer
* shadow_for
)
26 : layer_(new ui::Layer(ui::LAYER_TEXTURED
)) {
27 layer_
->set_delegate(this);
28 layer_
->SetBounds(gfx::Rect(-kShadowThick
, 0, kShadowThick
,
29 shadow_for
->bounds().height()));
30 layer_
->SetFillsBoundsOpaquely(false);
31 shadow_for
->Add(layer_
.get());
34 ShadowLayerDelegate::~ShadowLayerDelegate() {
37 void ShadowLayerDelegate::OnPaintLayer(const ui::PaintContext
& context
) {
39 const SkColor kShadowColors
[2] = { kShadowLightColor
, kShadowDarkColor
};
42 points
[1].iset(kShadowThick
, 0);
44 skia::RefPtr
<SkShader
> shader
= skia::AdoptRef(
45 SkGradientShader::CreateLinear(points
, kShadowColors
, NULL
,
46 arraysize(points
), SkShader::kRepeat_TileMode
));
48 gfx::Rect paint_rect
= gfx::Rect(0, 0, kShadowThick
,
49 layer_
->bounds().height());
51 paint
.setShader(shader
.get());
52 ui::PaintRecorder
recorder(context
, layer_
->size());
53 recorder
.canvas()->DrawRect(paint_rect
, paint
);
56 void ShadowLayerDelegate::OnDelegatedFrameDamage(
57 const gfx::Rect
& damage_rect_in_dip
) {
60 void ShadowLayerDelegate::OnDeviceScaleFactorChanged(float scale_factor
) {
63 base::Closure
ShadowLayerDelegate::PrepareForLayerBoundsChange() {
64 return base::Bind(&base::DoNothing
);
67 } // namespace content