1 // Copyright 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 "ui/views/shadow_border.h"
7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/insets.h"
9 #include "ui/gfx/shadow_value.h"
10 #include "ui/gfx/skia_util.h"
14 ShadowBorder::ShadowBorder(int blur
,
17 int horizontal_offset
)
21 vertical_offset_(vertical_offset
),
22 horizontal_offset_(horizontal_offset
) {}
24 ShadowBorder::~ShadowBorder() {}
26 // TODO(sidharthms): Re-painting a shadow looper on every paint call may yield
27 // poor performance. Ideally we should be caching the border to bitmaps.
28 void ShadowBorder::Paint(const views::View
& view
, gfx::Canvas
* canvas
) {
30 std::vector
<gfx::ShadowValue
> shadows
;
31 shadows
.push_back(gfx::ShadowValue(gfx::Point(), blur_
, color_
));
32 skia::RefPtr
<SkDrawLooper
> looper
= gfx::CreateShadowDrawLooper(shadows
);
33 paint
.setLooper(looper
.get());
34 paint
.setColor(SK_ColorTRANSPARENT
);
35 paint
.setStrokeJoin(SkPaint::kRound_Join
);
36 gfx::Rect
bounds(view
.size());
37 bounds
.Inset(gfx::Insets(blur_
/ 2, blur_
/ 2, blur_
/ 2, blur_
/ 2));
38 canvas
->DrawRect(bounds
, paint
);
41 gfx::Insets
ShadowBorder::GetInsets() const {
42 return gfx::Insets(blur_
/ 2 - vertical_offset_
,
43 blur_
/ 2 - horizontal_offset_
,
44 blur_
/ 2 + vertical_offset_
,
45 blur_
/ 2 + horizontal_offset_
);