Roll libjpeg_turbo to git hash feec46f80444b8eed4126a86a2c0e2cffe1c9673
[chromium-blink-merge.git] / ui / views / shadow_border.cc
blobfe744721f38fe0e8c146163e2914372eeea105d7
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/geometry/insets.h"
9 #include "ui/gfx/geometry/rect.h"
10 #include "ui/gfx/skia_util.h"
11 #include "ui/views/view.h"
13 namespace views {
15 namespace {
17 gfx::Insets GetInsetsFromShadowValue(const gfx::ShadowValue& shadow) {
18 std::vector<gfx::ShadowValue> shadows;
19 shadows.push_back(shadow);
20 return -gfx::ShadowValue::GetMargin(shadows);
23 } // namespace
25 ShadowBorder::ShadowBorder(const gfx::ShadowValue& shadow)
26 : views::Border(),
27 shadow_value_(shadow),
28 insets_(GetInsetsFromShadowValue(shadow)) {
31 ShadowBorder::~ShadowBorder() {
34 // TODO(sidharthms): Re-painting a shadow looper on every paint call may yield
35 // poor performance. Ideally we should be caching the border to bitmaps.
36 void ShadowBorder::Paint(const views::View& view, gfx::Canvas* canvas) {
37 SkPaint paint;
38 std::vector<gfx::ShadowValue> shadows;
39 shadows.push_back(shadow_value_);
40 skia::RefPtr<SkDrawLooper> looper = gfx::CreateShadowDrawLooper(shadows);
41 paint.setLooper(looper.get());
42 paint.setColor(SK_ColorTRANSPARENT);
43 paint.setStrokeJoin(SkPaint::kRound_Join);
44 gfx::Rect bounds(view.size());
45 bounds.Inset(-gfx::ShadowValue::GetMargin(shadows));
46 canvas->DrawRect(bounds, paint);
49 gfx::Insets ShadowBorder::GetInsets() const {
50 return insets_;
53 gfx::Size ShadowBorder::GetMinimumSize() const {
54 return gfx::Size(shadow_value_.blur(), shadow_value_.blur());
57 } // namespace views