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 13 matching lines...) Expand all Loading... |
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
27 * OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * OF THE POSSIBILITY OF SUCH DAMAGE. |
28 */ | 28 */ |
29 | 29 |
30 #include "core/layout/shapes/BoxShape.h" | 30 #include "core/layout/shapes/BoxShape.h" |
31 | 31 |
32 #include "platform/geometry/FloatRoundedRect.h" | 32 #include "platform/geometry/FloatRoundedRect.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include <memory> |
34 | 35 |
35 namespace blink { | 36 namespace blink { |
36 | 37 |
37 class BoxShapeTest : public ::testing::Test { | 38 class BoxShapeTest : public ::testing::Test { |
38 protected: | 39 protected: |
39 BoxShapeTest() { } | 40 BoxShapeTest() { } |
40 | 41 |
41 PassOwnPtr<Shape> createBoxShape(const FloatRoundedRect& bounds, float shape
Margin) | 42 std::unique_ptr<Shape> createBoxShape(const FloatRoundedRect& bounds, float
shapeMargin) |
42 { | 43 { |
43 return Shape::createLayoutBoxShape(bounds, TopToBottomWritingMode, shape
Margin); | 44 return Shape::createLayoutBoxShape(bounds, TopToBottomWritingMode, shape
Margin); |
44 } | 45 } |
45 }; | 46 }; |
46 | 47 |
47 namespace { | 48 namespace { |
48 | 49 |
49 #define TEST_EXCLUDED_INTERVAL(shapePtr, lineTop, lineHeight, expectedLeft, expe
ctedRight) \ | 50 #define TEST_EXCLUDED_INTERVAL(shapePtr, lineTop, lineHeight, expectedLeft, expe
ctedRight) \ |
50 {
\ | 51 {
\ |
51 LineSegment segment = shapePtr->getExcludedInterval(lineTop, lineHeight);
\ | 52 LineSegment segment = shapePtr->getExcludedInterval(lineTop, lineHeight);
\ |
(...skipping 14 matching lines...) Expand all Loading... |
66 * so the shapeMarginBoundingBox rectangle is 120x70 at -10,-10: | 67 * so the shapeMarginBoundingBox rectangle is 120x70 at -10,-10: |
67 * | 68 * |
68 * -10,-10 110,-10 | 69 * -10,-10 110,-10 |
69 * +--------+ | 70 * +--------+ |
70 * | | | 71 * | | |
71 * +--------+ | 72 * +--------+ |
72 * -10,60 60,60 | 73 * -10,60 60,60 |
73 */ | 74 */ |
74 TEST_F(BoxShapeTest, zeroRadii) | 75 TEST_F(BoxShapeTest, zeroRadii) |
75 { | 76 { |
76 OwnPtr<Shape> shape = createBoxShape(FloatRoundedRect(0, 0, 100, 50), 10); | 77 std::unique_ptr<Shape> shape = createBoxShape(FloatRoundedRect(0, 0, 100, 50
), 10); |
77 EXPECT_FALSE(shape->isEmpty()); | 78 EXPECT_FALSE(shape->isEmpty()); |
78 | 79 |
79 EXPECT_EQ(LayoutRect(-10, -10, 120, 70), shape->shapeMarginLogicalBoundingBo
x()); | 80 EXPECT_EQ(LayoutRect(-10, -10, 120, 70), shape->shapeMarginLogicalBoundingBo
x()); |
80 | 81 |
81 // A BoxShape's bounds include the top edge but not the bottom edge. | 82 // A BoxShape's bounds include the top edge but not the bottom edge. |
82 // Similarly a "line", specified as top,height to the overlap methods, | 83 // Similarly a "line", specified as top,height to the overlap methods, |
83 // is defined as top <= y < top + height. | 84 // is defined as top <= y < top + height. |
84 | 85 |
85 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(LayoutUnit(-9), LayoutUnit(
1))); | 86 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(LayoutUnit(-9), LayoutUnit(
1))); |
86 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(LayoutUnit(-10), LayoutUnit
())); | 87 EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(LayoutUnit(-10), LayoutUnit
())); |
(...skipping 24 matching lines...) Expand all Loading... |
111 * y=15 +--| |-+ y=20 | 112 * y=15 +--| |-+ y=20 |
112 * | | | 113 * | | |
113 * | | | 114 * | | |
114 * y=85 + -| |- + y=70 | 115 * y=85 + -| |- + y=70 |
115 * (--+---------+--) | 116 * (--+---------+--) |
116 * (25, 15) x=25 x=80 (20, 30) | 117 * (25, 15) x=25 x=80 (20, 30) |
117 */ | 118 */ |
118 TEST_F(BoxShapeTest, getIntervals) | 119 TEST_F(BoxShapeTest, getIntervals) |
119 { | 120 { |
120 const FloatRoundedRect::Radii cornerRadii(FloatSize(10, 15), FloatSize(10, 2
0), FloatSize(25, 15), FloatSize(20, 30)); | 121 const FloatRoundedRect::Radii cornerRadii(FloatSize(10, 15), FloatSize(10, 2
0), FloatSize(25, 15), FloatSize(20, 30)); |
121 OwnPtr<Shape> shape = createBoxShape(FloatRoundedRect(IntRect(0, 0, 100, 100
), cornerRadii), 0); | 122 std::unique_ptr<Shape> shape = createBoxShape(FloatRoundedRect(IntRect(0, 0,
100, 100), cornerRadii), 0); |
122 EXPECT_FALSE(shape->isEmpty()); | 123 EXPECT_FALSE(shape->isEmpty()); |
123 | 124 |
124 EXPECT_EQ(LayoutRect(0, 0, 100, 100), shape->shapeMarginLogicalBoundingBox()
); | 125 EXPECT_EQ(LayoutRect(0, 0, 100, 100), shape->shapeMarginLogicalBoundingBox()
); |
125 | 126 |
126 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(10), LayoutUnit(95), 0, 100); | 127 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(10), LayoutUnit(95), 0, 100); |
127 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(5), LayoutUnit(25), 0, 100); | 128 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(5), LayoutUnit(25), 0, 100); |
128 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(15), LayoutUnit(6), 0, 100); | 129 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(15), LayoutUnit(6), 0, 100); |
129 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(20), LayoutUnit(50), 0, 100); | 130 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(20), LayoutUnit(50), 0, 100); |
130 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(69), LayoutUnit(5), 0, 100); | 131 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(69), LayoutUnit(5), 0, 100); |
131 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(85), LayoutUnit(10), 0, 97.320511f)
; | 132 TEST_EXCLUDED_INTERVAL(shape, LayoutUnit(85), LayoutUnit(10), 0, 97.320511f)
; |
132 } | 133 } |
133 | 134 |
134 } // anonymous namespace | 135 } // anonymous namespace |
135 | 136 |
136 } // namespace blink | 137 } // namespace blink |
OLD | NEW |