1/*
2 * Copyright (C) 2000 Lars Knoll ([email protected])
3 * (C) 2000 Antti Koivisto ([email protected])
4 * (C) 2000 Dirk Mueller ([email protected])
5 * Copyright (C) 2003, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
6 * Copyright (C) 2006 Graham Dennis ([email protected])
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#pragma once
26
27#include "Color.h"
28#include "FloatRect.h"
29#include "LayoutRect.h"
30
31namespace WebCore {
32
33enum ShadowStyle { Normal, Inset };
34
35// This class holds information about shadows for the text-shadow and box-shadow properties.
36
37class ShadowData {
38 WTF_MAKE_FAST_ALLOCATED;
39public:
40 ShadowData()
41 : m_radius(0)
42 , m_spread(0)
43 , m_style(Normal)
44 , m_isWebkitBoxShadow(false)
45 {
46 }
47
48 ShadowData(const IntPoint& location, int radius, int spread, ShadowStyle style, bool isWebkitBoxShadow, const Color& color)
49 : m_location(location)
50 , m_radius(radius)
51 , m_spread(spread)
52 , m_color(color)
53 , m_style(style)
54 , m_isWebkitBoxShadow(isWebkitBoxShadow)
55 {
56 }
57
58 ShadowData(const ShadowData&);
59 static Optional<ShadowData> clone(const ShadowData*);
60
61 ShadowData& operator=(ShadowData&&) = default;
62
63 bool operator==(const ShadowData& o) const;
64 bool operator!=(const ShadowData& o) const
65 {
66 return !(*this == o);
67 }
68
69 int x() const { return m_location.x(); }
70 int y() const { return m_location.y(); }
71 IntPoint location() const { return m_location; }
72 int radius() const { return m_radius; }
73 int paintingExtent() const
74 {
75 // Blurring uses a Gaussian function whose std. deviation is m_radius/2, and which in theory
76 // extends to infinity. In 8-bit contexts, however, rounding causes the effect to become
77 // undetectable at around 1.4x the radius.
78 const float radiusExtentMultiplier = 1.4;
79 return ceilf(m_radius * radiusExtentMultiplier);
80 }
81 int spread() const { return m_spread; }
82 ShadowStyle style() const { return m_style; }
83 const Color& color() const { return m_color; }
84 bool isWebkitBoxShadow() const { return m_isWebkitBoxShadow; }
85
86 const ShadowData* next() const { return m_next.get(); }
87 void setNext(std::unique_ptr<ShadowData> shadow) { m_next = WTFMove(shadow); }
88
89 void adjustRectForShadow(LayoutRect&, int additionalOutlineSize = 0) const;
90 void adjustRectForShadow(FloatRect&, int additionalOutlineSize = 0) const;
91
92private:
93 IntPoint m_location;
94 int m_radius; // This is the "blur radius", or twice the standard deviation of the Gaussian blur.
95 int m_spread;
96 Color m_color;
97 ShadowStyle m_style;
98 bool m_isWebkitBoxShadow;
99 std::unique_ptr<ShadowData> m_next;
100};
101
102} // namespace WebCore
103