Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: ui/views/shadow_border.cc

Issue 900163002: Make ShadowBorder use ShadowValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_animations
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« ui/views/shadow_border.h ('K') | « ui/views/shadow_border.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/shadow_border.h" 5 #include "ui/views/shadow_border.h"
6 6
7 #include "ui/gfx/canvas.h" 7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/geometry/insets.h" 8 #include "ui/gfx/geometry/insets.h"
9 #include "ui/gfx/geometry/rect.h" 9 #include "ui/gfx/geometry/rect.h"
10 #include "ui/gfx/shadow_value.h"
11 #include "ui/gfx/skia_util.h" 10 #include "ui/gfx/skia_util.h"
12 #include "ui/views/view.h" 11 #include "ui/views/view.h"
13 12
14 namespace views { 13 namespace views {
15 14
16 ShadowBorder::ShadowBorder(int blur, 15 ShadowBorder::ShadowBorder(int blur,
17 SkColor color, 16 SkColor color,
18 int vertical_offset, 17 int vertical_offset,
19 int horizontal_offset) 18 int horizontal_offset)
20 : views::Border(), 19 : ShadowBorder(
21 blur_(blur), 20 gfx::ShadowValue(gfx::Point(horizontal_offset, vertical_offset),
22 color_(color), 21 blur,
23 vertical_offset_(vertical_offset), 22 color)) {
24 horizontal_offset_(horizontal_offset) {} 23 }
25 24
26 ShadowBorder::~ShadowBorder() {} 25 ShadowBorder::ShadowBorder(const gfx::ShadowValue& shadow)
26 : views::Border(), shadow_value_(shadow) {
27 }
28
29 ShadowBorder::~ShadowBorder() {
30 }
27 31
28 // TODO(sidharthms): Re-painting a shadow looper on every paint call may yield 32 // 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. 33 // poor performance. Ideally we should be caching the border to bitmaps.
30 void ShadowBorder::Paint(const views::View& view, gfx::Canvas* canvas) { 34 void ShadowBorder::Paint(const views::View& view, gfx::Canvas* canvas) {
31 SkPaint paint; 35 SkPaint paint;
32 std::vector<gfx::ShadowValue> shadows; 36 std::vector<gfx::ShadowValue> shadows;
33 shadows.push_back(gfx::ShadowValue(gfx::Point(), blur_, color_)); 37 shadows.push_back(shadow_value_);
34 skia::RefPtr<SkDrawLooper> looper = gfx::CreateShadowDrawLooper(shadows); 38 skia::RefPtr<SkDrawLooper> looper = gfx::CreateShadowDrawLooper(shadows);
35 paint.setLooper(looper.get()); 39 paint.setLooper(looper.get());
36 paint.setColor(SK_ColorTRANSPARENT); 40 paint.setColor(SK_ColorTRANSPARENT);
37 paint.setStrokeJoin(SkPaint::kRound_Join); 41 paint.setStrokeJoin(SkPaint::kRound_Join);
38 gfx::Rect bounds(view.size()); 42 gfx::Rect bounds(view.size());
39 // TODO(pkasting): This isn't right if one of the offsets is larger than 43 bounds.Inset(gfx::ShadowValue::GetMargin(shadows).Scale(-1));
sky 2015/02/05 17:33:32 While this looks right did you make sure the new l
calamity 2015/02/06 05:29:53 The only callers are the message center and app li
40 // (blur_ / 2).
41 bounds.Inset(gfx::Insets(blur_ / 2, blur_ / 2, blur_ / 2, blur_ / 2));
42 canvas->DrawRect(bounds, paint); 44 canvas->DrawRect(bounds, paint);
43 } 45 }
44 46
45 gfx::Insets ShadowBorder::GetInsets() const { 47 gfx::Insets ShadowBorder::GetInsets() const {
46 return gfx::Insets(blur_ / 2 - vertical_offset_, 48 std::vector<gfx::ShadowValue> shadows;
47 blur_ / 2 - horizontal_offset_, 49 shadows.push_back(shadow_value_);
48 blur_ / 2 + vertical_offset_, 50 return -gfx::ShadowValue::GetMargin(shadows);
sky 2015/02/05 17:33:32 Seems silly to do this all the time for something
calamity 2015/02/06 05:29:53 Done.
49 blur_ / 2 + horizontal_offset_);
50 } 51 }
51 52
52 gfx::Size ShadowBorder::GetMinimumSize() const { 53 gfx::Size ShadowBorder::GetMinimumSize() const {
53 return gfx::Size(blur_, blur_); 54 return gfx::Size(shadow_value_.blur(), shadow_value_.blur());
54 } 55 }
55 56
56 } // namespace views 57 } // namespace views
OLDNEW
« ui/views/shadow_border.h ('K') | « ui/views/shadow_border.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698