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

Side by Side Diff: ui/gfx/shadow_value.cc

Issue 2550593002: Update WM shadows for MD. (Closed)
Patch Set: fix corners Created 4 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/gfx/shadow_value.h" 5 #include "ui/gfx/shadow_value.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "ui/gfx/geometry/insets.h" 12 #include "ui/gfx/geometry/insets.h"
13 #include "ui/gfx/geometry/vector2d_conversions.h" 13 #include "ui/gfx/geometry/vector2d_conversions.h"
14 14
15 namespace gfx { 15 namespace gfx {
16 16
17 namespace {
18
19 Insets GetInsets(const ShadowValues& shadows, bool include_inner_blur) {
20 int left = 0;
21 int top = 0;
22 int right = 0;
23 int bottom = 0;
24
25 for (size_t i = 0; i < shadows.size(); ++i) {
26 const ShadowValue& shadow = shadows[i];
27
28 // Add 0.5 to round up to the next integer.
29 int blur =
James Cook 2016/12/05 23:38:35 nit: this might be clearer as int blur = include_
Evan Stade 2016/12/06 00:53:21 re-arranged
30 static_cast<int>(shadow.blur() / (include_inner_blur ? 1 : 2) + 0.5);
James Cook 2016/12/05 23:38:35 optional: Style guide is now OK with int{blah} for
Evan Stade 2016/12/06 00:53:21 Done.
Evan Stade 2016/12/07 01:56:42 Windows didn't like it --- cast from double to int
31
32 left = std::max(left, blur - shadow.x());
33 top = std::max(top, blur - shadow.y());
34 right = std::max(right, blur + shadow.x());
35 bottom = std::max(bottom, blur + shadow.y());
36 }
37
38 return Insets(top, left, bottom, right);
39 }
40 }
41
17 ShadowValue::ShadowValue() 42 ShadowValue::ShadowValue()
18 : blur_(0), 43 : blur_(0),
19 color_(0) { 44 color_(0) {
20 } 45 }
21 46
22 ShadowValue::ShadowValue(const gfx::Vector2d& offset, 47 ShadowValue::ShadowValue(const gfx::Vector2d& offset,
23 double blur, 48 double blur,
24 SkColor color) 49 SkColor color)
25 : offset_(offset), blur_(blur), color_(color) { 50 : offset_(offset), blur_(blur), color_(color) {
26 } 51 }
(...skipping 13 matching lines...) Expand all
40 offset_.x(), offset_.y(), 65 offset_.x(), offset_.y(),
41 blur_, 66 blur_,
42 SkColorGetR(color_), 67 SkColorGetR(color_),
43 SkColorGetG(color_), 68 SkColorGetG(color_),
44 SkColorGetB(color_), 69 SkColorGetB(color_),
45 SkColorGetA(color_)); 70 SkColorGetA(color_));
46 } 71 }
47 72
48 // static 73 // static
49 Insets ShadowValue::GetMargin(const ShadowValues& shadows) { 74 Insets ShadowValue::GetMargin(const ShadowValues& shadows) {
50 int left = 0; 75 gfx::Insets margins = GetInsets(shadows, false);
51 int top = 0; 76 return -margins;
52 int right = 0; 77 }
53 int bottom = 0;
54 78
55 for (size_t i = 0; i < shadows.size(); ++i) { 79 // static
56 const ShadowValue& shadow = shadows[i]; 80 Insets ShadowValue::GetBlurRegion(const ShadowValues& shadows) {
57 81 return GetInsets(shadows, true);
58 // Add 0.5 to round up to the next integer.
59 int blur = static_cast<int>(shadow.blur() / 2 + 0.5);
60
61 left = std::max(left, blur - shadow.x());
62 top = std::max(top, blur - shadow.y());
63 right = std::max(right, blur + shadow.x());
64 bottom = std::max(bottom, blur + shadow.y());
65 }
66
67 return Insets(-top, -left, -bottom, -right);
68 } 82 }
69 83
70 } // namespace gfx 84 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698