1 | /* |
2 | * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) |
3 | * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public License |
16 | * along with this library; see the file COPYING.LIB. If not, write to |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | * Boston, MA 02110-1301, USA. |
19 | * |
20 | */ |
21 | |
22 | #include "config.h" |
23 | #include "ShadowData.h" |
24 | |
25 | #include <wtf/PointerComparison.h> |
26 | |
27 | namespace WebCore { |
28 | |
29 | ShadowData::ShadowData(const ShadowData& o) |
30 | : m_location(o.m_location) |
31 | , m_radius(o.m_radius) |
32 | , m_spread(o.m_spread) |
33 | , m_color(o.m_color) |
34 | , m_style(o.m_style) |
35 | , m_isWebkitBoxShadow(o.m_isWebkitBoxShadow) |
36 | , m_next(o.m_next ? std::make_unique<ShadowData>(*o.m_next) : nullptr) |
37 | { |
38 | } |
39 | |
40 | Optional<ShadowData> ShadowData::clone(const ShadowData* data) |
41 | { |
42 | if (!data) |
43 | return WTF::nullopt; |
44 | return *data; |
45 | } |
46 | |
47 | bool ShadowData::operator==(const ShadowData& o) const |
48 | { |
49 | if (!arePointingToEqualData(m_next, o.m_next)) |
50 | return false; |
51 | |
52 | return m_location == o.m_location |
53 | && m_radius == o.m_radius |
54 | && m_spread == o.m_spread |
55 | && m_style == o.m_style |
56 | && m_color == o.m_color |
57 | && m_isWebkitBoxShadow == o.m_isWebkitBoxShadow; |
58 | } |
59 | |
60 | static inline void calculateShadowExtent(const ShadowData* shadow, int additionalOutlineSize, int& shadowLeft, int& shadowRight, int& shadowTop, int& shadowBottom) |
61 | { |
62 | do { |
63 | int extentAndSpread = shadow->paintingExtent() + shadow->spread() + additionalOutlineSize; |
64 | if (shadow->style() == Normal) { |
65 | shadowLeft = std::min(shadow->x() - extentAndSpread, shadowLeft); |
66 | shadowRight = std::max(shadow->x() + extentAndSpread, shadowRight); |
67 | shadowTop = std::min(shadow->y() - extentAndSpread, shadowTop); |
68 | shadowBottom = std::max(shadow->y() + extentAndSpread, shadowBottom); |
69 | } |
70 | |
71 | shadow = shadow->next(); |
72 | } while (shadow); |
73 | } |
74 | |
75 | void ShadowData::adjustRectForShadow(LayoutRect& rect, int additionalOutlineSize) const |
76 | { |
77 | int shadowLeft = 0; |
78 | int shadowRight = 0; |
79 | int shadowTop = 0; |
80 | int shadowBottom = 0; |
81 | calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom); |
82 | |
83 | rect.move(shadowLeft, shadowTop); |
84 | rect.setWidth(rect.width() - shadowLeft + shadowRight); |
85 | rect.setHeight(rect.height() - shadowTop + shadowBottom); |
86 | } |
87 | |
88 | void ShadowData::adjustRectForShadow(FloatRect& rect, int additionalOutlineSize) const |
89 | { |
90 | int shadowLeft = 0; |
91 | int shadowRight = 0; |
92 | int shadowTop = 0; |
93 | int shadowBottom = 0; |
94 | calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom); |
95 | |
96 | rect.move(shadowLeft, shadowTop); |
97 | rect.setWidth(rect.width() - shadowLeft + shadowRight); |
98 | rect.setHeight(rect.height() - shadowTop + shadowBottom); |
99 | } |
100 | |
101 | } // namespace WebCore |
102 | |