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

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: all working! Created 7 years 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 18 matching lines...) Expand all
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" 35 #include "platform/geometry/LayoutRect.h"
36 36
37 namespace WebCore { 37 namespace WebCore {
38 38
39 static inline void calculateShadowExtent(const ShadowList* shadowList, int addit ionalOutlineSize, int& shadowLeft, int& shadowRight, int& shadowTop, int& shadow Bottom) 39 static inline void calculateShadowExtent(const ShadowList* shadowList, LayoutUni t additionalOutlineSize, LayoutUnit& shadowLeft, LayoutUnit& shadowRight, Layout Unit& shadowTop, LayoutUnit& shadowBottom)
40 { 40 {
41 ASSERT(shadowList); 41 ASSERT(shadowList);
42 size_t shadowCount = shadowList->shadows().size(); 42 size_t shadowCount = shadowList->shadows().size();
43 for (size_t i = 0; i < shadowCount; ++i) { 43 for (size_t i = 0; i < shadowCount; ++i) {
44 const ShadowData& shadow = shadowList->shadows()[i]; 44 const ShadowData& shadow = shadowList->shadows()[i];
45 if (shadow.style() == Inset) 45 if (shadow.style() == Inset)
46 continue; 46 continue;
47 int blurAndSpread = shadow.blur() + shadow.spread() + additionalOutlineS ize; 47 LayoutUnit blurAndSpread = shadow.blur() + shadow.spread() + additionalO utlineSize;
48 shadowLeft = std::min(shadow.x() - blurAndSpread, shadowLeft); 48 shadowLeft = std::min(shadow.x() - blurAndSpread, shadowLeft);
49 shadowRight = std::max(shadow.x() + blurAndSpread, shadowRight); 49 shadowRight = std::max(shadow.x() + blurAndSpread, shadowRight);
50 shadowTop = std::min(shadow.y() - blurAndSpread, shadowTop); 50 shadowTop = std::min(shadow.y() - blurAndSpread, shadowTop);
51 shadowBottom = std::max(shadow.y() + blurAndSpread, shadowBottom); 51 shadowBottom = std::max(shadow.y() + blurAndSpread, shadowBottom);
52 } 52 }
53 } 53 }
54 54
55 void ShadowList::adjustRectForShadow(LayoutRect& rect, int additionalOutlineSize ) const 55 void ShadowList::adjustRectForShadow(LayoutRect& rect, LayoutUnit additionalOutl ineSize) const
56 { 56 {
57 int shadowLeft = 0; 57 LayoutUnit shadowLeft = 0;
58 int shadowRight = 0; 58 LayoutUnit shadowRight = 0;
59 int shadowTop = 0; 59 LayoutUnit shadowTop = 0;
60 int shadowBottom = 0; 60 LayoutUnit shadowBottom = 0;
61 calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom); 61 calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom);
62 62
63 rect.move(shadowLeft, shadowTop); 63 rect.move(shadowLeft, shadowTop);
64 rect.setWidth(rect.width() - shadowLeft + shadowRight); 64 rect.setWidth(rect.width() - shadowLeft + shadowRight);
65 rect.setHeight(rect.height() - shadowTop + shadowBottom); 65 rect.setHeight(rect.height() - shadowTop + shadowBottom);
66 } 66 }
67 67
68 void ShadowList::adjustRectForShadow(FloatRect& rect, int additionalOutlineSize) const 68 void ShadowList::adjustRectForShadow(FloatRect& rect, LayoutUnit additionalOutli neSize) const
69 { 69 {
70 int shadowLeft = 0; 70 LayoutUnit shadowLeft = 0;
71 int shadowRight = 0; 71 LayoutUnit shadowRight = 0;
72 int shadowTop = 0; 72 LayoutUnit shadowTop = 0;
73 int shadowBottom = 0; 73 LayoutUnit shadowBottom = 0;
74 calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom); 74 calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom);
75 75
76 rect.move(shadowLeft, shadowTop); 76 rect.move(shadowLeft, shadowTop);
77 rect.setWidth(rect.width() - shadowLeft + shadowRight); 77 rect.setWidth(rect.width() - shadowLeft + shadowRight);
78 rect.setHeight(rect.height() - shadowTop + shadowBottom); 78 rect.setHeight(rect.height() - shadowTop + shadowBottom);
79 } 79 }
80 80
81 PassRefPtr<ShadowList> ShadowList::blend(const ShadowList* from, const ShadowLis t* to, double progress) 81 PassRefPtr<ShadowList> ShadowList::blend(const ShadowList* from, const ShadowLis t* to, double progress)
82 { 82 {
83 size_t fromLength = from ? from->shadows().size() : 0; 83 size_t fromLength = from ? from->shadows().size() : 0;
84 size_t toLength = to ? to->shadows().size() : 0; 84 size_t toLength = to ? to->shadows().size() : 0;
85 if (!fromLength && !toLength) 85 if (!fromLength && !toLength)
86 return 0; 86 return 0;
87 87
88 ShadowDataVector shadows; 88 ShadowDataVector shadows;
89 89
90 DEFINE_STATIC_LOCAL(ShadowData, defaultShadowData, (IntPoint(), 0, 0, Normal , Color::transparent)); 90 DEFINE_STATIC_LOCAL(ShadowData, defaultShadowData, (LayoutPoint(), 0, 0, Nor mal, Color::transparent));
91 DEFINE_STATIC_LOCAL(ShadowData, defaultInsetShadowData, (IntPoint(), 0, 0, I nset, Color::transparent)); 91 DEFINE_STATIC_LOCAL(ShadowData, defaultInsetShadowData, (LayoutPoint(), 0, 0 , Inset, Color::transparent));
92 92
93 size_t maxLength = std::max(fromLength, toLength); 93 size_t maxLength = std::max(fromLength, toLength);
94 for (size_t i = 0; i < maxLength; ++i) { 94 for (size_t i = 0; i < maxLength; ++i) {
95 const ShadowData* fromShadow = i < fromLength ? &from->shadows()[i] : 0; 95 const ShadowData* fromShadow = i < fromLength ? &from->shadows()[i] : 0;
96 const ShadowData* toShadow = i < toLength ? &to->shadows()[i] : 0; 96 const ShadowData* toShadow = i < toLength ? &to->shadows()[i] : 0;
97 if (!fromShadow) 97 if (!fromShadow)
98 fromShadow = toShadow->style() == Inset ? &defaultInsetShadowData : &defaultShadowData; 98 fromShadow = toShadow->style() == Inset ? &defaultInsetShadowData : &defaultShadowData;
99 else if (!toShadow) 99 else if (!toShadow)
100 toShadow = fromShadow->style() == Inset ? &defaultInsetShadowData : &defaultShadowData; 100 toShadow = fromShadow->style() == Inset ? &defaultInsetShadowData : &defaultShadowData;
101 shadows.append(toShadow->blend(*fromShadow, progress)); 101 shadows.append(toShadow->blend(*fromShadow, progress));
102 } 102 }
103 103
104 return ShadowList::adopt(shadows); 104 return ShadowList::adopt(shadows);
105 } 105 }
106 106
107 } // namespace WebCore 107 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698