OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "core/layout/style/ShadowList.h" | |
33 | |
34 #include "platform/geometry/FloatRect.h" | |
35 #include "wtf/OwnPtr.h" | |
36 | |
37 namespace blink { | |
38 | |
39 FloatRectOutsets ShadowList::rectOutsetsIncludingOriginal() const | |
40 { | |
41 FloatRectOutsets outsets; | |
42 for (const ShadowData& shadow : shadows()) { | |
43 if (shadow.style() == Inset) | |
44 continue; | |
45 outsets.unite(shadow.rectOutsets()); | |
46 } | |
47 return outsets; | |
48 } | |
49 | |
50 void ShadowList::adjustRectForShadow(LayoutRect& rect) const | |
51 { | |
52 rect.expand(rectOutsetsIncludingOriginal()); | |
53 } | |
54 | |
55 void ShadowList::adjustRectForShadow(FloatRect& rect) const | |
56 { | |
57 rect.expand(rectOutsetsIncludingOriginal()); | |
58 } | |
59 | |
60 PassRefPtr<ShadowList> ShadowList::blend(const ShadowList* from, const ShadowLis
t* to, double progress) | |
61 { | |
62 size_t fromLength = from ? from->shadows().size() : 0; | |
63 size_t toLength = to ? to->shadows().size() : 0; | |
64 if (!fromLength && !toLength) | |
65 return nullptr; | |
66 | |
67 ShadowDataVector shadows; | |
68 | |
69 DEFINE_STATIC_LOCAL(ShadowData, defaultShadowData, (FloatPoint(), 0, 0, Norm
al, Color::transparent)); | |
70 DEFINE_STATIC_LOCAL(ShadowData, defaultInsetShadowData, (FloatPoint(), 0, 0,
Inset, Color::transparent)); | |
71 | |
72 size_t maxLength = std::max(fromLength, toLength); | |
73 for (size_t i = 0; i < maxLength; ++i) { | |
74 const ShadowData* fromShadow = i < fromLength ? &from->shadows()[i] : 0; | |
75 const ShadowData* toShadow = i < toLength ? &to->shadows()[i] : 0; | |
76 if (!fromShadow) | |
77 fromShadow = toShadow->style() == Inset ? &defaultInsetShadowData :
&defaultShadowData; | |
78 else if (!toShadow) | |
79 toShadow = fromShadow->style() == Inset ? &defaultInsetShadowData :
&defaultShadowData; | |
80 shadows.append(toShadow->blend(*fromShadow, progress)); | |
81 } | |
82 | |
83 return ShadowList::adopt(shadows); | |
84 } | |
85 | |
86 PassOwnPtr<DrawLooperBuilder> ShadowList::createDrawLooper(DrawLooperBuilder::Sh
adowAlphaMode alphaMode, bool isHorizontal) const | |
87 { | |
88 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(); | |
89 for (size_t i = shadows().size(); i--; ) { | |
90 const ShadowData& shadow = shadows()[i]; | |
91 float shadowX = isHorizontal ? shadow.x() : shadow.y(); | |
92 float shadowY = isHorizontal ? shadow.y() : -shadow.x(); | |
93 drawLooperBuilder->addShadow(FloatSize(shadowX, shadowY), shadow.blur(),
shadow.color(), | |
94 DrawLooperBuilder::ShadowRespectsTransforms, alphaMode); | |
95 } | |
96 drawLooperBuilder->addUnmodifiedContent(); | |
97 return drawLooperBuilder.release(); | |
98 } | |
99 | |
100 } // namespace blink | |
OLD | NEW |