OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 2 * Copyright (C) 2013 Adobe Systems Incorporated. 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above | 8 * 1. Redistributions of source code must retain the above |
9 * copyright notice, this list of conditions and the following | 9 * copyright notice, this list of conditions and the following |
10 * disclaimer. | 10 * disclaimer. |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "platform/geometry/RoundedRect.h" | 34 #include "platform/geometry/RoundedRect.h" |
35 | 35 |
36 #include <gtest/gtest.h> | 36 #include <gtest/gtest.h> |
37 | 37 |
38 namespace WebCore { | 38 namespace WebCore { |
39 | 39 |
40 class BoxShapeTest : public ::testing::Test { | 40 class BoxShapeTest : public ::testing::Test { |
41 protected: | 41 protected: |
42 BoxShapeTest() { } | 42 BoxShapeTest() { } |
43 | 43 |
44 PassOwnPtr<Shape> createBoxShape(const RoundedRect& bounds, float shapeMargi
n, float shapePadding) | 44 PassOwnPtr<Shape> createBoxShape(const RoundedRect& bounds, float shapeMargi
n) |
45 { | 45 { |
46 return Shape::createBoxShape(bounds, TopToBottomWritingMode, Length(shap
eMargin, Fixed), Length(shapePadding, Fixed)); | 46 return Shape::createLayoutBoxShape(bounds, TopToBottomWritingMode, Lengt
h(shapeMargin, Fixed)); |
47 } | 47 } |
48 }; | 48 }; |
49 | 49 |
50 } // namespace WebCore | 50 } // namespace WebCore |
51 | 51 |
52 namespace { | 52 namespace { |
53 | 53 |
54 using namespace WebCore; | 54 using namespace WebCore; |
55 | 55 |
56 #define TEST_EXCLUDED_INTERVAL(shapePtr, lineTop, lineHeight, expectedLeft, expe
ctedRight) \ | 56 #define TEST_EXCLUDED_INTERVAL(shapePtr, lineTop, lineHeight, expectedLeft, expe
ctedRight) \ |
57 {
\ | 57 {
\ |
58 SegmentList result;
\ | 58 SegmentList result;
\ |
59 shapePtr->getExcludedIntervals(lineTop, lineHeight, result);
\ | 59 shapePtr->getExcludedIntervals(lineTop, lineHeight, result);
\ |
60 EXPECT_EQ(1u, result.size());
\ | 60 EXPECT_EQ(1u, result.size());
\ |
61 if (result.size() == 1u) {
\ | 61 if (result.size() == 1u) {
\ |
62 EXPECT_FLOAT_EQ(expectedLeft, result[0].logicalLeft);
\ | 62 EXPECT_FLOAT_EQ(expectedLeft, result[0].logicalLeft);
\ |
63 EXPECT_FLOAT_EQ(expectedRight, result[0].logicalRight);
\ | 63 EXPECT_FLOAT_EQ(expectedRight, result[0].logicalRight);
\ |
64 }
\ | 64 }
\ |
65 } | 65 } |
66 | 66 |
67 #define TEST_NO_EXCLUDED_INTERVAL(shapePtr, lineTop, lineHeight) \ | 67 #define TEST_NO_EXCLUDED_INTERVAL(shapePtr, lineTop, lineHeight) \ |
68 { \ | 68 { \ |
69 SegmentList result; \ | 69 SegmentList result; \ |
70 shapePtr->getExcludedIntervals(lineTop, lineHeight, result); \ | 70 shapePtr->getExcludedIntervals(lineTop, lineHeight, result); \ |
71 EXPECT_EQ(0u, result.size()); \ | 71 EXPECT_EQ(0u, result.size()); \ |
72 } | 72 } |
73 | 73 |
74 #define TEST_INCLUDED_INTERVAL(shapePtr, lineTop, lineHeight, expectedLeft, expe
ctedRight) \ | |
75 {
\ | |
76 SegmentList result;
\ | |
77 shapePtr->getIncludedIntervals(lineTop, lineHeight, result);
\ | |
78 EXPECT_EQ(1u, result.size());
\ | |
79 if (result.size() == 1u) {
\ | |
80 EXPECT_FLOAT_EQ(expectedLeft, result[0].logicalLeft);
\ | |
81 EXPECT_FLOAT_EQ(expectedRight, result[0].logicalRight);
\ | |
82 }
\ | |
83 } | |
84 | |
85 #define TEST_NO_INCLUDED_INTERVAL(shapePtr, lineTop, lineHeight) \ | |
86 { \ | |
87 SegmentList result; \ | |
88 shapePtr->getIncludedIntervals(lineTop, lineHeight, result); \ | |
89 EXPECT_EQ(0u, result.size()); \ | |
90 } | |
91 | |
92 /* The BoxShape is based on a 100x50 rectangle at 0,0. The shape-margin value is
10, | 74 /* The BoxShape is based on a 100x50 rectangle at 0,0. The shape-margin value is
10, |
93 * so the shapeMarginBoundingBox rectangle is 120x70 at -10,-10: | 75 * so the shapeMarginBoundingBox rectangle is 120x70 at -10,-10: |
94 * | 76 * |
95 * -10,-10 110,-10 | 77 * -10,-10 110,-10 |
96 * +--------+ | 78 * +--------+ |
97 * | | | 79 * | | |
98 * +--------+ | 80 * +--------+ |
99 * -10,60 60,60 | 81 * -10,60 60,60 |
100 * | |
101 * The shape-padding value is 20, so the shapePaddingBoundingBox | |
102 * rectangle is 60x10 at 20,20: | |
103 * | |
104 * 20,20 80,20 | |
105 * +--------+ | |
106 * | | | |
107 * +--------+ | |
108 * 20,30 80,30 | |
109 */ | 82 */ |
110 TEST_F(BoxShapeTest, zeroRadii) | 83 TEST_F(BoxShapeTest, zeroRadii) |
111 { | 84 { |
112 OwnPtr<Shape> shape = createBoxShape(RoundedRect(0, 0, 100, 50), 10, 20); | 85 OwnPtr<Shape> shape = createBoxShape(RoundedRect(0, 0, 100, 50), 10); |
113 EXPECT_FALSE(shape->isEmpty()); | 86 EXPECT_FALSE(shape->isEmpty()); |
114 | 87 |
115 EXPECT_EQ(LayoutRect(-10, -10, 120, 70), shape->shapeMarginLogicalBoundingBo
x()); | 88 EXPECT_EQ(LayoutRect(-10, -10, 120, 70), shape->shapeMarginLogicalBoundingBo
x()); |
116 EXPECT_EQ(LayoutRect(20, 20, 60, 10), shape->shapePaddingLogicalBoundingBox(
)); | |
117 | 89 |
118 // A BoxShape's bounds include the top edge but not the bottom edge. | 90 // A BoxShape's bounds include the top edge but not the bottom edge. |
119 // Similarly a "line", specified as top,height to the overlap methods, | 91 // Similarly a "line", specified as top,height to the overlap methods, |
120 // is defined as top <= y < top + height. | 92 // is defined as top <= y < top + height. |
121 | 93 |
122 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(-9, 1)); | 94 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(-9, 1)); |
123 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(-10, 0)); | 95 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(-10, 0)); |
124 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(-10, 200)); | 96 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(-10, 200)); |
125 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(5, 10)); | 97 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(5, 10)); |
126 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(59, 1)); | 98 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(59, 1)); |
127 | 99 |
128 EXPECT_FALSE(shape->lineOverlapsShapeMarginBounds(-12, 2)); | 100 EXPECT_FALSE(shape->lineOverlapsShapeMarginBounds(-12, 2)); |
129 EXPECT_FALSE(shape->lineOverlapsShapeMarginBounds(60, 1)); | 101 EXPECT_FALSE(shape->lineOverlapsShapeMarginBounds(60, 1)); |
130 EXPECT_FALSE(shape->lineOverlapsShapeMarginBounds(100, 200)); | 102 EXPECT_FALSE(shape->lineOverlapsShapeMarginBounds(100, 200)); |
131 | 103 |
132 TEST_EXCLUDED_INTERVAL(shape, -9, 1, -10, 110); | 104 TEST_EXCLUDED_INTERVAL(shape, -9, 1, -10, 110); |
133 TEST_EXCLUDED_INTERVAL(shape, -10, 0, -10, 110); | 105 TEST_EXCLUDED_INTERVAL(shape, -10, 0, -10, 110); |
134 TEST_EXCLUDED_INTERVAL(shape, -10, 200, -10, 110); | 106 TEST_EXCLUDED_INTERVAL(shape, -10, 200, -10, 110); |
135 TEST_EXCLUDED_INTERVAL(shape, 5, 10, -10, 110); | 107 TEST_EXCLUDED_INTERVAL(shape, 5, 10, -10, 110); |
136 TEST_EXCLUDED_INTERVAL(shape, 59, 1, -10, 110); | 108 TEST_EXCLUDED_INTERVAL(shape, 59, 1, -10, 110); |
137 | 109 |
138 TEST_NO_EXCLUDED_INTERVAL(shape, -12, 2); | 110 TEST_NO_EXCLUDED_INTERVAL(shape, -12, 2); |
139 TEST_NO_EXCLUDED_INTERVAL(shape, 60, 1); | 111 TEST_NO_EXCLUDED_INTERVAL(shape, 60, 1); |
140 TEST_NO_EXCLUDED_INTERVAL(shape, 100, 200); | 112 TEST_NO_EXCLUDED_INTERVAL(shape, 100, 200); |
141 | |
142 EXPECT_TRUE(shape->lineOverlapsShapePaddingBounds(21, 1)); | |
143 EXPECT_TRUE(shape->lineOverlapsShapePaddingBounds(20, 0)); | |
144 EXPECT_TRUE(shape->lineOverlapsShapePaddingBounds(-10, 200)); | |
145 EXPECT_TRUE(shape->lineOverlapsShapePaddingBounds(25, 35)); | |
146 EXPECT_TRUE(shape->lineOverlapsShapePaddingBounds(29, 1)); | |
147 | |
148 EXPECT_FALSE(shape->lineOverlapsShapePaddingBounds(18, 2)); | |
149 EXPECT_FALSE(shape->lineOverlapsShapePaddingBounds(30, 1)); | |
150 EXPECT_FALSE(shape->lineOverlapsShapePaddingBounds(100, 200)); | |
151 | |
152 // A BoxShape only includes a line if the lines's top and | |
153 // bottom fit within the shapePaddingLogicalBoundingBox: | |
154 // top >= box.y && top + height <= box.maxY | |
155 | |
156 TEST_INCLUDED_INTERVAL(shape, 21, 1, 20, 80); | |
157 TEST_INCLUDED_INTERVAL(shape, 20, 0, 20, 80); | |
158 TEST_INCLUDED_INTERVAL(shape, 20, 10, 20, 80); | |
159 TEST_INCLUDED_INTERVAL(shape, 25, 5, 20, 80); | |
160 TEST_INCLUDED_INTERVAL(shape, 29, 1, 20, 80); | |
161 | |
162 TEST_NO_INCLUDED_INTERVAL(shape, 18, 2); | |
163 TEST_NO_INCLUDED_INTERVAL(shape, 30, 1); | |
164 TEST_NO_INCLUDED_INTERVAL(shape, 100, 200); | |
165 TEST_NO_INCLUDED_INTERVAL(shape, 19, 10); | |
166 TEST_NO_INCLUDED_INTERVAL(shape, 20, 100); | |
167 } | 113 } |
168 | 114 |
169 /* BoxShape geometry for this test. Corner radii are in parens, x and y intercep
ts | 115 /* BoxShape geometry for this test. Corner radii are in parens, x and y intercep
ts |
170 * for the elliptical corners are noted. The rectangle itself is at 0,0 with wid
th and height 100. | 116 * for the elliptical corners are noted. The rectangle itself is at 0,0 with wid
th and height 100. |
171 * | 117 * |
172 * (10, 15) x=10 x=90 (10, 20) | 118 * (10, 15) x=10 x=90 (10, 20) |
173 * (--+---------+--) | 119 * (--+---------+--) |
174 * y=15 +--| |-+ y=20 | 120 * y=15 +--| |-+ y=20 |
175 * | | | 121 * | | |
176 * | | | 122 * | | |
177 * y=85 + -| |- + y=70 | 123 * y=85 + -| |- + y=70 |
178 * (--+---------+--) | 124 * (--+---------+--) |
179 * (25, 15) x=25 x=80 (20, 30) | 125 * (25, 15) x=25 x=80 (20, 30) |
180 */ | 126 */ |
181 TEST_F(BoxShapeTest, getIntervals) | 127 TEST_F(BoxShapeTest, getIntervals) |
182 { | 128 { |
183 const RoundedRect::Radii cornerRadii(IntSize(10, 15), IntSize(10, 20), IntSi
ze(25, 15), IntSize(20, 30)); | 129 const RoundedRect::Radii cornerRadii(IntSize(10, 15), IntSize(10, 20), IntSi
ze(25, 15), IntSize(20, 30)); |
184 OwnPtr<Shape> shape = createBoxShape(RoundedRect(IntRect(0, 0, 100, 100), co
rnerRadii), 0, 0); | 130 OwnPtr<Shape> shape = createBoxShape(RoundedRect(IntRect(0, 0, 100, 100), co
rnerRadii), 0); |
185 EXPECT_FALSE(shape->isEmpty()); | 131 EXPECT_FALSE(shape->isEmpty()); |
186 | 132 |
187 EXPECT_EQ(LayoutRect(0, 0, 100, 100), shape->shapeMarginLogicalBoundingBox()
); | 133 EXPECT_EQ(LayoutRect(0, 0, 100, 100), shape->shapeMarginLogicalBoundingBox()
); |
188 EXPECT_EQ(LayoutRect(0, 0, 100, 100), shape->shapePaddingLogicalBoundingBox(
)); | |
189 | |
190 TEST_INCLUDED_INTERVAL(shape, 5, 25, 2.5464401f, 96.61438f); | |
191 TEST_INCLUDED_INTERVAL(shape, 15, 1, 0, 99.682457f); | |
192 TEST_INCLUDED_INTERVAL(shape, 20, 50, 0, 100); | |
193 TEST_INCLUDED_INTERVAL(shape, 85, 10, 6.3661003f, 91.05542f); | |
194 | 134 |
195 TEST_EXCLUDED_INTERVAL(shape, 10, 95, 0, 100); | 135 TEST_EXCLUDED_INTERVAL(shape, 10, 95, 0, 100); |
196 TEST_EXCLUDED_INTERVAL(shape, 5, 25, 0, 100); | 136 TEST_EXCLUDED_INTERVAL(shape, 5, 25, 0, 100); |
197 TEST_EXCLUDED_INTERVAL(shape, 15, 6, 0, 100); | 137 TEST_EXCLUDED_INTERVAL(shape, 15, 6, 0, 100); |
198 TEST_EXCLUDED_INTERVAL(shape, 20, 50, 0, 100); | 138 TEST_EXCLUDED_INTERVAL(shape, 20, 50, 0, 100); |
199 TEST_EXCLUDED_INTERVAL(shape, 69, 5, 0, 100); | 139 TEST_EXCLUDED_INTERVAL(shape, 69, 5, 0, 100); |
200 TEST_EXCLUDED_INTERVAL(shape, 85, 10, 0, 97.320511f); | 140 TEST_EXCLUDED_INTERVAL(shape, 85, 10, 0, 97.320511f); |
201 } | 141 } |
202 | 142 |
203 } // namespace | 143 } // namespace |
OLD | NEW |