| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/layout/LayoutTestHelper.h" | 5 #include "core/layout/LayoutTestHelper.h" |
| 6 #include "core/layout/LayoutTreeAsText.h" | 6 #include "core/layout/LayoutTreeAsText.h" |
| 7 #include "core/layout/api/LayoutViewItem.h" | 7 #include "core/layout/api/LayoutViewItem.h" |
| 8 #include "core/paint/ObjectPaintProperties.h" | 8 #include "core/paint/ObjectPaintProperties.h" |
| 9 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 9 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 10 #include "platform/testing/UnitTestHelpers.h" | 10 #include "platform/testing/UnitTestHelpers.h" |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 " <div style='position: relative; top: 100px; left: 100px'>" | 911 " <div style='position: relative; top: 100px; left: 100px'>" |
| 912 " <div id='spanner' style='column-span: all; opacity: 0.5; width: 100
px; height: 100px;'></div>" | 912 " <div id='spanner' style='column-span: all; opacity: 0.5; width: 100
px; height: 100px;'></div>" |
| 913 " </div>" | 913 " </div>" |
| 914 "</div>" | 914 "</div>" |
| 915 ); | 915 ); |
| 916 | 916 |
| 917 LayoutObject& spanner = *getLayoutObjectByElementId("spanner"); | 917 LayoutObject& spanner = *getLayoutObjectByElementId("spanner"); |
| 918 EXPECT_EQ(LayoutPoint(55, 44), spanner.objectPaintProperties()->localBorderB
oxProperties()->paintOffset); | 918 EXPECT_EQ(LayoutPoint(55, 44), spanner.objectPaintProperties()->localBorderB
oxProperties()->paintOffset); |
| 919 } | 919 } |
| 920 | 920 |
| 921 TEST_F(PaintPropertyTreeBuilderTest, PaintOffsetWithBasicPixelSnapping) |
| 922 { |
| 923 setBodyInnerHTML( |
| 924 "<style>" |
| 925 " * { margin: 0; }" |
| 926 " div { position: relative; }" |
| 927 "</style>" |
| 928 "<div id='a' style='width: 70px; height: 70px; left: 0.3px; top: 0.3px;'
>" |
| 929 " <div id='b' style='width: 40px; height: 40px; transform: translateZ(0
);'>" |
| 930 " <div id='c' style='width: 40px; height: 40px; left: 0.1px; top: 0.1
px;'></div>" |
| 931 " </div>" |
| 932 "</div>" |
| 933 ); |
| 934 |
| 935 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 936 EXPECT_EQ(TransformationMatrix().translate3d(0, 0, 0), bProperties->transfor
m()->matrix()); |
| 937 // The paint offset transform should be snapped from (0.3,0.3) to (0,0). |
| 938 EXPECT_EQ(TransformationMatrix().translate(0, 0), bProperties->transform()->
parent()->matrix()); |
| 939 // The residual subpixel adjustment should be (0.3,0.3) - (0,0) = (0.3,0.3). |
| 940 LayoutPoint subpixelAccumulation = LayoutPoint(FloatPoint(0.3, 0.3)); |
| 941 EXPECT_EQ(subpixelAccumulation, bProperties->localBorderBoxProperties()->pai
ntOffset); |
| 942 |
| 943 // c should be painted starting at subpixelAccumulation + (0.1,0.1) = (0.4,0
.4). |
| 944 LayoutPoint cPaintOffset = subpixelAccumulation + LayoutPoint(FloatPoint(0.1
, 0.1)); |
| 945 ObjectPaintProperties* cProperties = document().getElementById("c")->layoutO
bject()->objectPaintProperties(); |
| 946 EXPECT_EQ(cPaintOffset, cProperties->localBorderBoxProperties()->paintOffset
); |
| 947 } |
| 948 |
| 949 TEST_F(PaintPropertyTreeBuilderTest, PaintOffsetWithPixelSnappingThroughTransfor
m) |
| 950 { |
| 951 setBodyInnerHTML( |
| 952 "<style>" |
| 953 " * { margin: 0; }" |
| 954 " div { position: relative; }" |
| 955 "</style>" |
| 956 "<div id='a' style='width: 70px; height: 70px; left: 0.7px; top: 0.7px;'
>" |
| 957 " <div id='b' style='width: 40px; height: 40px; transform: translateZ(0
);'>" |
| 958 " <div id='c' style='width: 40px; height: 40px; left: 0.7px; top: 0.7
px;'></div>" |
| 959 " </div>" |
| 960 "</div>" |
| 961 ); |
| 962 |
| 963 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 964 EXPECT_EQ(TransformationMatrix().translate3d(0, 0, 0), bProperties->transfor
m()->matrix()); |
| 965 // The paint offset transform should be snapped from (0.7,0.7) to (1,1). |
| 966 EXPECT_EQ(TransformationMatrix().translate(1, 1), bProperties->transform()->
parent()->matrix()); |
| 967 // The residual subpixel adjustment should be (0.7,0.7) - (1,1) = (-0.3,-0.3
). |
| 968 LayoutPoint subpixelAccumulation = LayoutPoint(LayoutPoint(FloatPoint(0.7, 0
.7)) - LayoutPoint(1, 1)); |
| 969 EXPECT_EQ(subpixelAccumulation, bProperties->localBorderBoxProperties()->pai
ntOffset); |
| 970 |
| 971 // c should be painted starting at subpixelAccumulation + (0.7,0.7) = (0.4,0
.4). |
| 972 LayoutPoint cPaintOffset = subpixelAccumulation + LayoutPoint(FloatPoint(0.7
, 0.7)); |
| 973 ObjectPaintProperties* cProperties = document().getElementById("c")->layoutO
bject()->objectPaintProperties(); |
| 974 EXPECT_EQ(cPaintOffset, cProperties->localBorderBoxProperties()->paintOffset
); |
| 975 } |
| 976 |
| 977 TEST_F(PaintPropertyTreeBuilderTest, PaintOffsetWithPixelSnappingThroughMultiple
Transforms) |
| 978 { |
| 979 setBodyInnerHTML( |
| 980 "<style>" |
| 981 " * { margin: 0; }" |
| 982 " div { position: relative; }" |
| 983 "</style>" |
| 984 "<div id='a' style='width: 70px; height: 70px; left: 0.7px; top: 0.7px;'
>" |
| 985 " <div id='b' style='width: 40px; height: 40px; transform: translate3d(
5px, 7px, 0);'>" |
| 986 " <div id='c' style='width: 40px; height: 40px; transform: translate3
d(11px, 13px, 0);'>" |
| 987 " <div id='d' style='width: 40px; height: 40px; left: 0.7px; top: 0
.7px;'></div>" |
| 988 " </div>" |
| 989 " </div>" |
| 990 "</div>" |
| 991 ); |
| 992 |
| 993 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 994 EXPECT_EQ(TransformationMatrix().translate3d(5, 7, 0), bProperties->transfor
m()->matrix()); |
| 995 // The paint offset transform should be snapped from (0.7,0.7) to (1,1). |
| 996 EXPECT_EQ(TransformationMatrix().translate(1, 1), bProperties->transform()->
parent()->matrix()); |
| 997 // The residual subpixel adjustment should be (0.7,0.7) - (1,1) = (-0.3,-0.3
). |
| 998 LayoutPoint subpixelAccumulation = LayoutPoint(LayoutPoint(FloatPoint(0.7, 0
.7)) - LayoutPoint(1, 1)); |
| 999 EXPECT_EQ(subpixelAccumulation, bProperties->localBorderBoxProperties()->pai
ntOffset); |
| 1000 |
| 1001 ObjectPaintProperties* cProperties = document().getElementById("c")->layoutO
bject()->objectPaintProperties(); |
| 1002 EXPECT_EQ(TransformationMatrix().translate3d(11, 13, 0), cProperties->transf
orm()->matrix()); |
| 1003 // The paint offset should be (-0.3,-0.3) but the paint offset transform sho
uld still be at |
| 1004 // (0,0) because it should be snapped. |
| 1005 EXPECT_EQ(TransformationMatrix().translate(0, 0), cProperties->transform()->
parent()->matrix()); |
| 1006 // The residual subpixel adjustment should still be (-0.3,-0.3). |
| 1007 EXPECT_EQ(subpixelAccumulation, cProperties->localBorderBoxProperties()->pai
ntOffset); |
| 1008 |
| 1009 // d should be painted starting at subpixelAccumulation + (0.7,0.7) = (0.4,0
.4). |
| 1010 LayoutPoint dPaintOffset = subpixelAccumulation + LayoutPoint(FloatPoint(0.7
, 0.7)); |
| 1011 ObjectPaintProperties* dProperties = document().getElementById("d")->layoutO
bject()->objectPaintProperties(); |
| 1012 EXPECT_EQ(dPaintOffset, dProperties->localBorderBoxProperties()->paintOffset
); |
| 1013 } |
| 1014 |
| 921 } // namespace blink | 1015 } // namespace blink |
| OLD | NEW |