Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: Source/core/rendering/style/ShadowList.cpp

Issue 23241010: Support subpixel values for text-shadow and box-shadow (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: addressed review comments Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/rendering/style/ShadowList.h" 32 #include "core/rendering/style/ShadowList.h"
33 33
34 #include "platform/geometry/FloatRect.h" 34 #include "platform/geometry/FloatRect.h"
35 #include "platform/geometry/LayoutRect.h"
36 35
37 namespace WebCore { 36 namespace WebCore {
38 37
39 static inline void calculateShadowExtent(const ShadowList* shadowList, int addit ionalOutlineSize, int& shadowLeft, int& shadowRight, int& shadowTop, int& shadow Bottom) 38 static inline void calculateShadowExtent(const ShadowList* shadowList, float add itionalOutlineSize, float& shadowLeft, float& shadowRight, float& shadowTop, flo at& shadowBottom)
40 { 39 {
41 ASSERT(shadowList); 40 ASSERT(shadowList);
42 size_t shadowCount = shadowList->shadows().size(); 41 size_t shadowCount = shadowList->shadows().size();
43 for (size_t i = 0; i < shadowCount; ++i) { 42 for (size_t i = 0; i < shadowCount; ++i) {
44 const ShadowData& shadow = shadowList->shadows()[i]; 43 const ShadowData& shadow = shadowList->shadows()[i];
45 if (shadow.style() == Inset) 44 if (shadow.style() == Inset)
46 continue; 45 continue;
47 int blurAndSpread = shadow.blur() + shadow.spread() + additionalOutlineS ize; 46 float blurAndSpread = shadow.blur() + shadow.spread() + additionalOutlin eSize;
48 shadowLeft = std::min(shadow.x() - blurAndSpread, shadowLeft); 47 shadowLeft = std::min(shadow.x() - blurAndSpread, shadowLeft);
49 shadowRight = std::max(shadow.x() + blurAndSpread, shadowRight); 48 shadowRight = std::max(shadow.x() + blurAndSpread, shadowRight);
50 shadowTop = std::min(shadow.y() - blurAndSpread, shadowTop); 49 shadowTop = std::min(shadow.y() - blurAndSpread, shadowTop);
51 shadowBottom = std::max(shadow.y() + blurAndSpread, shadowBottom); 50 shadowBottom = std::max(shadow.y() + blurAndSpread, shadowBottom);
52 } 51 }
53 } 52 }
54 53
55 void ShadowList::adjustRectForShadow(LayoutRect& rect, int additionalOutlineSize ) const 54 void ShadowList::adjustRectForShadow(LayoutRect& rect, float additionalOutlineSi ze) const
56 { 55 {
57 int shadowLeft = 0; 56 FloatRect floatRect(rect);
58 int shadowRight = 0; 57 adjustRectForShadow(floatRect);
59 int shadowTop = 0; 58 rect = LayoutRect(floatRect);
60 int shadowBottom = 0; 59 }
60
61 void ShadowList::adjustRectForShadow(FloatRect& rect, float additionalOutlineSiz e) const
62 {
63 float shadowLeft = 0;
64 float shadowRight = 0;
65 float shadowTop = 0;
66 float shadowBottom = 0;
61 calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom); 67 calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom);
62 68
63 rect.move(shadowLeft, shadowTop); 69 rect.move(shadowLeft, shadowTop);
64 rect.setWidth(rect.width() - shadowLeft + shadowRight);
65 rect.setHeight(rect.height() - shadowTop + shadowBottom);
66 }
67
68 void ShadowList::adjustRectForShadow(FloatRect& rect, int additionalOutlineSize) const
69 {
70 int shadowLeft = 0;
71 int shadowRight = 0;
72 int shadowTop = 0;
73 int shadowBottom = 0;
74 calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom);
75
76 rect.move(shadowLeft, shadowTop);
77 rect.setWidth(rect.width() - shadowLeft + shadowRight); 70 rect.setWidth(rect.width() - shadowLeft + shadowRight);
78 rect.setHeight(rect.height() - shadowTop + shadowBottom); 71 rect.setHeight(rect.height() - shadowTop + shadowBottom);
79 } 72 }
80 73
81 PassRefPtr<ShadowList> ShadowList::blend(const ShadowList* from, const ShadowLis t* to, double progress) 74 PassRefPtr<ShadowList> ShadowList::blend(const ShadowList* from, const ShadowLis t* to, double progress)
82 { 75 {
83 size_t fromLength = from ? from->shadows().size() : 0; 76 size_t fromLength = from ? from->shadows().size() : 0;
84 size_t toLength = to ? to->shadows().size() : 0; 77 size_t toLength = to ? to->shadows().size() : 0;
85 if (!fromLength && !toLength) 78 if (!fromLength && !toLength)
86 return 0; 79 return 0;
87 80
88 ShadowDataVector shadows; 81 ShadowDataVector shadows;
89 82
90 DEFINE_STATIC_LOCAL(ShadowData, defaultShadowData, (IntPoint(), 0, 0, Normal , Color::transparent)); 83 DEFINE_STATIC_LOCAL(ShadowData, defaultShadowData, (FloatPoint(), 0, 0, Norm al, Color::transparent));
91 DEFINE_STATIC_LOCAL(ShadowData, defaultInsetShadowData, (IntPoint(), 0, 0, I nset, Color::transparent)); 84 DEFINE_STATIC_LOCAL(ShadowData, defaultInsetShadowData, (FloatPoint(), 0, 0, Inset, Color::transparent));
92 85
93 size_t maxLength = std::max(fromLength, toLength); 86 size_t maxLength = std::max(fromLength, toLength);
94 for (size_t i = 0; i < maxLength; ++i) { 87 for (size_t i = 0; i < maxLength; ++i) {
95 const ShadowData* fromShadow = i < fromLength ? &from->shadows()[i] : 0; 88 const ShadowData* fromShadow = i < fromLength ? &from->shadows()[i] : 0;
96 const ShadowData* toShadow = i < toLength ? &to->shadows()[i] : 0; 89 const ShadowData* toShadow = i < toLength ? &to->shadows()[i] : 0;
97 if (!fromShadow) 90 if (!fromShadow)
98 fromShadow = toShadow->style() == Inset ? &defaultInsetShadowData : &defaultShadowData; 91 fromShadow = toShadow->style() == Inset ? &defaultInsetShadowData : &defaultShadowData;
99 else if (!toShadow) 92 else if (!toShadow)
100 toShadow = fromShadow->style() == Inset ? &defaultInsetShadowData : &defaultShadowData; 93 toShadow = fromShadow->style() == Inset ? &defaultInsetShadowData : &defaultShadowData;
101 shadows.append(toShadow->blend(*fromShadow, progress)); 94 shadows.append(toShadow->blend(*fromShadow, progress));
102 } 95 }
103 96
104 return ShadowList::adopt(shadows); 97 return ShadowList::adopt(shadows);
105 } 98 }
106 99
107 } // namespace WebCore 100 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/style/ShadowList.h ('k') | Source/platform/animation/AnimationUtilities.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698