Automated Commit: Committing new LKGM version 7479.0.0 for chromeos.
[chromium-blink-merge.git] / ui / views / shadow_border.cc
blobfb5888b1e8e998e3051dbcd6cb4796ff40de85df
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 "third_party/skia/include/core/SkDrawLooper.h"
8 #include "ui/gfx/canvas.h"
9 #include "ui/gfx/geometry/insets.h"
10 #include "ui/gfx/geometry/rect.h"
11 #include "ui/gfx/skia_util.h"
12 #include "ui/views/view.h"
14 namespace views {
16 namespace {
18 gfx::Insets GetInsetsFromShadowValue(const gfx::ShadowValue& shadow) {
19 std::vector<gfx::ShadowValue> shadows;
20 shadows.push_back(shadow);
21 return -gfx::ShadowValue::GetMargin(shadows);
24 } // namespace
26 ShadowBorder::ShadowBorder(const gfx::ShadowValue& shadow)
27 : views::Border(),
28 shadow_value_(shadow),
29 insets_(GetInsetsFromShadowValue(shadow)) {
32 ShadowBorder::~ShadowBorder() {
35 // TODO(sidharthms): Re-painting a shadow looper on every paint call may yield
36 // poor performance. Ideally we should be caching the border to bitmaps.
37 void ShadowBorder::Paint(const views::View& view, gfx::Canvas* canvas) {
38 SkPaint paint;
39 std::vector<gfx::ShadowValue> shadows;
40 shadows.push_back(shadow_value_);
41 skia::RefPtr<SkDrawLooper> looper = gfx::CreateShadowDrawLooper(shadows);
42 paint.setLooper(looper.get());
43 paint.setColor(SK_ColorTRANSPARENT);
44 paint.setStrokeJoin(SkPaint::kRound_Join);
45 gfx::Rect bounds(view.size());
46 bounds.Inset(-gfx::ShadowValue::GetMargin(shadows));
47 canvas->DrawRect(bounds, paint);
50 gfx::Insets ShadowBorder::GetInsets() const {
51 return insets_;
54 gfx::Size ShadowBorder::GetMinimumSize() const {
55 return gfx::Size(shadow_value_.blur(), shadow_value_.blur());
58 } // namespace views