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
3 // found in the LICENSE file.
5 #include "ui/gfx/shadow_value.h"
9 #include "base/strings/stringprintf.h"
10 #include "ui/gfx/geometry/insets.h"
11 #include "ui/gfx/geometry/point_conversions.h"
15 ShadowValue::ShadowValue()
20 ShadowValue::ShadowValue(const gfx::Point
& offset
,
28 ShadowValue::~ShadowValue() {
31 ShadowValue
ShadowValue::Scale(float scale
) const {
32 gfx::Point scaled_offset
=
33 gfx::ToFlooredPoint(gfx::ScalePoint(offset_
, scale
));
34 return ShadowValue(scaled_offset
, blur_
* scale
, color_
);
37 std::string
ShadowValue::ToString() const {
38 return base::StringPrintf(
39 "(%d,%d),%.2f,rgba(%d,%d,%d,%d)",
40 offset_
.x(), offset_
.y(),
49 Insets
ShadowValue::GetMargin(const ShadowValues
& shadows
) {
55 for (size_t i
= 0; i
< shadows
.size(); ++i
) {
56 const ShadowValue
& shadow
= shadows
[i
];
58 // Add 0.5 to round up to the next integer.
59 int blur
= static_cast<int>(shadow
.blur() / 2 + 0.5);
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());
67 return Insets(-top
, -left
, -bottom
, -right
);