Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 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); | |
| 41 } | |
| 42 } | |
|
sky
2016/12/07 16:39:32
// namespace
Evan Stade
2016/12/07 18:55:00
Done.
| |
| 43 | |
| 17 ShadowValue::ShadowValue() | 44 ShadowValue::ShadowValue() |
| 18 : blur_(0), | 45 : blur_(0), |
| 19 color_(0) { | 46 color_(0) { |
| 20 } | 47 } |
| 21 | 48 |
| 22 ShadowValue::ShadowValue(const gfx::Vector2d& offset, | 49 ShadowValue::ShadowValue(const gfx::Vector2d& offset, |
| 23 double blur, | 50 double blur, |
| 24 SkColor color) | 51 SkColor color) |
| 25 : offset_(offset), blur_(blur), color_(color) { | 52 : offset_(offset), blur_(blur), color_(color) { |
| 26 } | 53 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 40 offset_.x(), offset_.y(), | 67 offset_.x(), offset_.y(), |
| 41 blur_, | 68 blur_, |
| 42 SkColorGetR(color_), | 69 SkColorGetR(color_), |
| 43 SkColorGetG(color_), | 70 SkColorGetG(color_), |
| 44 SkColorGetB(color_), | 71 SkColorGetB(color_), |
| 45 SkColorGetA(color_)); | 72 SkColorGetA(color_)); |
| 46 } | 73 } |
| 47 | 74 |
| 48 // static | 75 // static |
| 49 Insets ShadowValue::GetMargin(const ShadowValues& shadows) { | 76 Insets ShadowValue::GetMargin(const ShadowValues& shadows) { |
| 50 int left = 0; | 77 gfx::Insets margins = GetInsets(shadows, false); |
| 51 int top = 0; | 78 return -margins; |
| 52 int right = 0; | 79 } |
| 53 int bottom = 0; | |
| 54 | 80 |
| 55 for (size_t i = 0; i < shadows.size(); ++i) { | 81 // static |
| 56 const ShadowValue& shadow = shadows[i]; | 82 Insets ShadowValue::GetBlurRegion(const ShadowValues& shadows) { |
| 57 | 83 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 } | 84 } |
| 69 | 85 |
| 70 } // namespace gfx | 86 } // namespace gfx |
| OLD | NEW |