| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ui/views/shadow_border.h" | |
| 6 | |
| 7 #include "ui/gfx/canvas.h" | |
| 8 #include "ui/gfx/insets.h" | |
| 9 #include "ui/gfx/rect.h" | |
| 10 #include "ui/gfx/shadow_value.h" | |
| 11 #include "ui/gfx/skia_util.h" | |
| 12 #include "ui/views/view.h" | |
| 13 | |
| 14 namespace views { | |
| 15 | |
| 16 ShadowBorder::ShadowBorder(int blur, | |
| 17 SkColor color, | |
| 18 int vertical_offset, | |
| 19 int horizontal_offset) | |
| 20 : views::Border(), | |
| 21 blur_(blur), | |
| 22 color_(color), | |
| 23 vertical_offset_(vertical_offset), | |
| 24 horizontal_offset_(horizontal_offset) {} | |
| 25 | |
| 26 ShadowBorder::~ShadowBorder() {} | |
| 27 | |
| 28 // TODO(sidharthms): Re-painting a shadow looper on every paint call may yield | |
| 29 // poor performance. Ideally we should be caching the border to bitmaps. | |
| 30 void ShadowBorder::Paint(const views::View& view, gfx::Canvas* canvas) { | |
| 31 SkPaint paint; | |
| 32 std::vector<gfx::ShadowValue> shadows; | |
| 33 shadows.push_back(gfx::ShadowValue(gfx::Point(), blur_, color_)); | |
| 34 skia::RefPtr<SkDrawLooper> looper = gfx::CreateShadowDrawLooper(shadows); | |
| 35 paint.setLooper(looper.get()); | |
| 36 paint.setColor(SK_ColorTRANSPARENT); | |
| 37 paint.setStrokeJoin(SkPaint::kRound_Join); | |
| 38 gfx::Rect bounds(view.size()); | |
| 39 // TODO(pkasting): This isn't right if one of the offsets is larger than | |
| 40 // (blur_ / 2). | |
| 41 bounds.Inset(gfx::Insets(blur_ / 2, blur_ / 2, blur_ / 2, blur_ / 2)); | |
| 42 canvas->DrawRect(bounds, paint); | |
| 43 } | |
| 44 | |
| 45 gfx::Insets ShadowBorder::GetInsets() const { | |
| 46 return gfx::Insets(blur_ / 2 - vertical_offset_, | |
| 47 blur_ / 2 - horizontal_offset_, | |
| 48 blur_ / 2 + vertical_offset_, | |
| 49 blur_ / 2 + horizontal_offset_); | |
| 50 } | |
| 51 | |
| 52 gfx::Size ShadowBorder::GetMinimumSize() const { | |
| 53 return gfx::Size(blur_, blur_); | |
| 54 } | |
| 55 | |
| 56 } // namespace views | |
| OLD | NEW |