summaryrefslogtreecommitdiffstats
path: root/content/browser/web_contents/aura/shadow_layer_delegate.cc
blob: a4a1660be5bf077a6e1174d77369af79b55788cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2013 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 "content/browser/web_contents/aura/shadow_layer_delegate.h"

#include "base/bind.h"
#include "base/macros.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/skia_util.h"

namespace {

const SkColor kShadowLightColor = SkColorSetARGB(0x0, 0, 0, 0);
const SkColor kShadowDarkColor = SkColorSetARGB(0x70, 0, 0, 0);
const int kShadowThick = 7;

}  // namespace

namespace content {

ShadowLayerDelegate::ShadowLayerDelegate(ui::Layer* shadow_for)
    : layer_(new ui::Layer(ui::LAYER_TEXTURED)) {
  layer_->set_delegate(this);
  layer_->SetBounds(gfx::Rect(-kShadowThick, 0, kShadowThick,
                              shadow_for->bounds().height()));
  layer_->SetFillsBoundsOpaquely(false);
  shadow_for->Add(layer_.get());
}

ShadowLayerDelegate::~ShadowLayerDelegate() {
}

void ShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
  SkPoint points[2];
  const SkColor kShadowColors[2] = { kShadowLightColor, kShadowDarkColor };

  points[0].iset(0, 0);
  points[1].iset(kShadowThick, 0);

  gfx::Rect paint_rect = gfx::Rect(0, 0, kShadowThick,
                                   layer_->bounds().height());
  SkPaint paint;
  paint.setShader(SkGradientShader::MakeLinear(points, kShadowColors, NULL,
                                               arraysize(points),
                                               SkShader::kRepeat_TileMode));
  ui::PaintRecorder recorder(context, layer_->size());
  recorder.canvas()->DrawRect(paint_rect, paint);
}

void ShadowLayerDelegate::OnDelegatedFrameDamage(
    const gfx::Rect& damage_rect_in_dip) {
}

void ShadowLayerDelegate::OnDeviceScaleFactorChanged(float scale_factor) {
}

base::Closure ShadowLayerDelegate::PrepareForLayerBoundsChange() {
  return base::Bind(&base::DoNothing);
}

}  // namespace content