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

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

Issue 2550593002: Update WM shadows for MD. (Closed)
Patch Set: fix border for small windows 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
« no previous file with comments | « ui/gfx/shadow_value.h ('k') | ui/wm/core/shadow.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ShadowValue::ShadowValue() 17 namespace {
18 : blur_(0), 18
19 color_(0) { 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 double blur = shadow.blur();
29 if (!include_inner_blur)
30 blur /= 2;
31 // Add 0.5 to round up to the next integer.
32 int blur_length = static_cast<int>(blur + 0.5);
33
34 left = std::max(left, blur_length - shadow.x());
35 top = std::max(top, blur_length - shadow.y());
36 right = std::max(right, blur_length + shadow.x());
37 bottom = std::max(bottom, blur_length + shadow.y());
38 }
39
40 return Insets(top, left, bottom, right);
20 } 41 }
21 42
43 } // namespace
44
45 ShadowValue::ShadowValue() : blur_(0), color_(0) {}
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 }
27 52
28 ShadowValue::~ShadowValue() { 53 ShadowValue::~ShadowValue() {}
29 }
30 54
31 ShadowValue ShadowValue::Scale(float scale) const { 55 ShadowValue ShadowValue::Scale(float scale) const {
32 gfx::Vector2d scaled_offset = 56 gfx::Vector2d scaled_offset =
33 gfx::ToFlooredVector2d(gfx::ScaleVector2d(offset_, scale)); 57 gfx::ToFlooredVector2d(gfx::ScaleVector2d(offset_, scale));
34 return ShadowValue(scaled_offset, blur_ * scale, color_); 58 return ShadowValue(scaled_offset, blur_ * scale, color_);
35 } 59 }
36 60
37 std::string ShadowValue::ToString() const { 61 std::string ShadowValue::ToString() const {
38 return base::StringPrintf( 62 return base::StringPrintf(
39 "(%d,%d),%.2f,rgba(%d,%d,%d,%d)", 63 "(%d,%d),%.2f,rgba(%d,%d,%d,%d)",
40 offset_.x(), offset_.y(), 64 offset_.x(), offset_.y(),
41 blur_, 65 blur_,
42 SkColorGetR(color_), 66 SkColorGetR(color_),
43 SkColorGetG(color_), 67 SkColorGetG(color_),
44 SkColorGetB(color_), 68 SkColorGetB(color_),
45 SkColorGetA(color_)); 69 SkColorGetA(color_));
46 } 70 }
47 71
48 // static 72 // static
49 Insets ShadowValue::GetMargin(const ShadowValues& shadows) { 73 Insets ShadowValue::GetMargin(const ShadowValues& shadows) {
50 int left = 0; 74 gfx::Insets margins = GetInsets(shadows, false);
51 int top = 0; 75 return -margins;
52 int right = 0; 76 }
53 int bottom = 0;
54 77
55 for (size_t i = 0; i < shadows.size(); ++i) { 78 // static
56 const ShadowValue& shadow = shadows[i]; 79 Insets ShadowValue::GetBlurRegion(const ShadowValues& shadows) {
57 80 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 } 81 }
69 82
70 } // namespace gfx 83 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/shadow_value.h ('k') | ui/wm/core/shadow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698