mac: Disable Address Book integration.
[chromium-blink-merge.git] / ui / gfx / shadow_value.cc
blob7e310578c3d19656803f1b0c26d845da1dfec1f4
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"
7 #include <algorithm>
9 #include "base/strings/stringprintf.h"
10 #include "ui/gfx/geometry/insets.h"
11 #include "ui/gfx/geometry/vector2d_conversions.h"
13 namespace gfx {
15 ShadowValue::ShadowValue()
16 : blur_(0),
17 color_(0) {
20 ShadowValue::ShadowValue(const gfx::Vector2d& offset,
21 double blur,
22 SkColor color)
23 : offset_(offset), blur_(blur), color_(color) {
26 ShadowValue::~ShadowValue() {
29 ShadowValue ShadowValue::Scale(float scale) const {
30 gfx::Vector2d scaled_offset =
31 gfx::ToFlooredVector2d(gfx::ScaleVector2d(offset_, scale));
32 return ShadowValue(scaled_offset, blur_ * scale, color_);
35 std::string ShadowValue::ToString() const {
36 return base::StringPrintf(
37 "(%d,%d),%.2f,rgba(%d,%d,%d,%d)",
38 offset_.x(), offset_.y(),
39 blur_,
40 SkColorGetR(color_),
41 SkColorGetG(color_),
42 SkColorGetB(color_),
43 SkColorGetA(color_));
46 // static
47 Insets ShadowValue::GetMargin(const ShadowValues& shadows) {
48 int left = 0;
49 int top = 0;
50 int right = 0;
51 int bottom = 0;
53 for (size_t i = 0; i < shadows.size(); ++i) {
54 const ShadowValue& shadow = shadows[i];
56 // Add 0.5 to round up to the next integer.
57 int blur = static_cast<int>(shadow.blur() / 2 + 0.5);
59 left = std::max(left, blur - shadow.x());
60 top = std::max(top, blur - shadow.y());
61 right = std::max(right, blur + shadow.x());
62 bottom = std::max(bottom, blur + shadow.y());
65 return Insets(-top, -left, -bottom, -right);
68 } // namespace gfx