initial import
[vuplus_webkit] / Source / WebCore / rendering / style / ShadowData.cpp
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 using namespace std;
26
27 namespace WebCore {
28
29 ShadowData::ShadowData(const ShadowData& o)
30     : m_x(o.m_x)
31     , m_y(o.m_y)
32     , m_blur(o.m_blur)
33     , m_spread(o.m_spread)
34     , m_color(o.m_color)
35     , m_style(o.m_style)
36     , m_isWebkitBoxShadow(o.m_isWebkitBoxShadow)
37     , m_next(o.m_next ? adoptPtr(new ShadowData(*o.m_next)) : nullptr)
38 {
39 }
40
41 bool ShadowData::operator==(const ShadowData& o) const
42 {
43     if ((m_next && !o.m_next) || (!m_next && o.m_next)
44         || (m_next && o.m_next && *m_next != *o.m_next))
45         return false;
46     
47     return m_x == o.m_x
48         && m_y == o.m_y
49         && m_blur == o.m_blur
50         && m_spread == o.m_spread
51         && m_style == o.m_style
52         && m_color == o.m_color
53         && m_isWebkitBoxShadow == o.m_isWebkitBoxShadow;
54 }
55
56 static inline void calculateShadowExtent(const ShadowData* shadow, int additionalOutlineSize, LayoutUnit& shadowLeft, LayoutUnit& shadowRight, LayoutUnit& shadowTop, LayoutUnit& shadowBottom)
57 {
58     do {
59         int blurAndSpread = shadow->blur() + shadow->spread() + additionalOutlineSize;
60         if (shadow->style() == Normal) {
61             shadowLeft = min(shadow->x() - blurAndSpread, shadowLeft);
62             shadowRight = max(shadow->x() + blurAndSpread, shadowRight);
63             shadowTop = min(shadow->y() - blurAndSpread, shadowTop);
64             shadowBottom = max(shadow->y() + blurAndSpread, shadowBottom);
65         }
66
67         shadow = shadow->next();
68     } while (shadow);
69 }
70
71 void ShadowData::adjustRectForShadow(IntRect& rect, int additionalOutlineSize) const
72 {
73     LayoutUnit shadowLeft = 0;
74     LayoutUnit shadowRight = 0;
75     LayoutUnit shadowTop = 0;
76     LayoutUnit shadowBottom = 0;
77     calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom);
78
79     rect.move(shadowLeft, shadowTop);
80     rect.setWidth(rect.width() - shadowLeft + shadowRight);
81     rect.setHeight(rect.height() - shadowTop + shadowBottom);
82 }
83
84 void ShadowData::adjustRectForShadow(FloatRect& rect, int additionalOutlineSize) const
85 {
86     LayoutUnit shadowLeft = 0;
87     LayoutUnit shadowRight = 0;
88     LayoutUnit shadowTop = 0;
89     LayoutUnit shadowBottom = 0;
90     calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom);
91
92     rect.move(shadowLeft, shadowTop);
93     rect.setWidth(rect.width() - shadowLeft + shadowRight);
94     rect.setHeight(rect.height() - shadowTop + shadowBottom);
95 }
96
97 } // namespace WebCore