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, FractionalPaintOffset) |
| 922 { |
| 923 setBodyInnerHTML( |
| 924 "<style>" |
| 925 " * { margin: 0; }" |
| 926 " div { position: absolute; }" |
| 927 "</style>" |
| 928 "<div id='a' style='width: 70px; height: 70px; left: 0.1px; top: 0.3px;'
>" |
| 929 " <div id='b' style='width: 40px; height: 40px; left: 0.5px; top: 11.1p
x;'></div>" |
| 930 "</div>" |
| 931 ); |
| 932 |
| 933 ObjectPaintProperties* aProperties = document().getElementById("a")->layoutO
bject()->objectPaintProperties(); |
| 934 LayoutPoint aPaintOffset = LayoutPoint(FloatPoint(0.1, 0.3)); |
| 935 EXPECT_EQ(aPaintOffset, aProperties->localBorderBoxProperties()->paintOffset
); |
| 936 |
| 937 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 938 LayoutPoint bPaintOffset = aPaintOffset + LayoutPoint(FloatPoint(0.5, 11.1))
; |
| 939 EXPECT_EQ(bPaintOffset, bProperties->localBorderBoxProperties()->paintOffset
); |
| 940 } |
| 941 |
| 942 TEST_F(PaintPropertyTreeBuilderTest, PaintOffsetWithBasicPixelSnapping) |
| 943 { |
| 944 setBodyInnerHTML( |
| 945 "<style>" |
| 946 " * { margin: 0; }" |
| 947 " div { position: relative; }" |
| 948 "</style>" |
| 949 "<div id='a' style='width: 70px; height: 70px; left: 0.3px; top: 0.3px;'
>" |
| 950 " <div id='b' style='width: 40px; height: 40px; transform: translateZ(0
);'>" |
| 951 " <div id='c' style='width: 40px; height: 40px; left: 0.1px; top: 0.1
px;'></div>" |
| 952 " </div>" |
| 953 "</div>" |
| 954 ); |
| 955 |
| 956 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 957 EXPECT_EQ(TransformationMatrix().translate3d(0, 0, 0), bProperties->transfor
m()->matrix()); |
| 958 // The paint offset transform should be snapped from (0.3,0.3) to (0,0). |
| 959 EXPECT_EQ(TransformationMatrix().translate(0, 0), bProperties->transform()->
parent()->matrix()); |
| 960 // The residual subpixel adjustment should be (0.3,0.3) - (0,0) = (0.3,0.3). |
| 961 LayoutPoint subpixelAccumulation = LayoutPoint(FloatPoint(0.3, 0.3)); |
| 962 EXPECT_EQ(subpixelAccumulation, bProperties->localBorderBoxProperties()->pai
ntOffset); |
| 963 |
| 964 // c should be painted starting at subpixelAccumulation + (0.1,0.1) = (0.4,0
.4). |
| 965 LayoutPoint cPaintOffset = subpixelAccumulation + LayoutPoint(FloatPoint(0.1
, 0.1)); |
| 966 ObjectPaintProperties* cProperties = document().getElementById("c")->layoutO
bject()->objectPaintProperties(); |
| 967 EXPECT_EQ(cPaintOffset, cProperties->localBorderBoxProperties()->paintOffset
); |
| 968 } |
| 969 |
| 970 TEST_F(PaintPropertyTreeBuilderTest, PaintOffsetWithPixelSnappingThroughTransfor
m) |
| 971 { |
| 972 setBodyInnerHTML( |
| 973 "<style>" |
| 974 " * { margin: 0; }" |
| 975 " div { position: relative; }" |
| 976 "</style>" |
| 977 "<div id='a' style='width: 70px; height: 70px; left: 0.7px; top: 0.7px;'
>" |
| 978 " <div id='b' style='width: 40px; height: 40px; transform: translateZ(0
);'>" |
| 979 " <div id='c' style='width: 40px; height: 40px; left: 0.7px; top: 0.7
px;'></div>" |
| 980 " </div>" |
| 981 "</div>" |
| 982 ); |
| 983 |
| 984 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 985 EXPECT_EQ(TransformationMatrix().translate3d(0, 0, 0), bProperties->transfor
m()->matrix()); |
| 986 // The paint offset transform should be snapped from (0.7,0.7) to (1,1). |
| 987 EXPECT_EQ(TransformationMatrix().translate(1, 1), bProperties->transform()->
parent()->matrix()); |
| 988 // The residual subpixel adjustment should be (0.7,0.7) - (1,1) = (-0.3,-0.3
). |
| 989 LayoutPoint subpixelAccumulation = LayoutPoint(LayoutPoint(FloatPoint(0.7, 0
.7)) - LayoutPoint(1, 1)); |
| 990 EXPECT_EQ(subpixelAccumulation, bProperties->localBorderBoxProperties()->pai
ntOffset); |
| 991 |
| 992 // c should be painted starting at subpixelAccumulation + (0.7,0.7) = (0.4,0
.4). |
| 993 LayoutPoint cPaintOffset = subpixelAccumulation + LayoutPoint(FloatPoint(0.7
, 0.7)); |
| 994 ObjectPaintProperties* cProperties = document().getElementById("c")->layoutO
bject()->objectPaintProperties(); |
| 995 EXPECT_EQ(cPaintOffset, cProperties->localBorderBoxProperties()->paintOffset
); |
| 996 } |
| 997 |
| 998 TEST_F(PaintPropertyTreeBuilderTest, PaintOffsetWithPixelSnappingThroughMultiple
Transforms) |
| 999 { |
| 1000 setBodyInnerHTML( |
| 1001 "<style>" |
| 1002 " * { margin: 0; }" |
| 1003 " div { position: relative; }" |
| 1004 "</style>" |
| 1005 "<div id='a' style='width: 70px; height: 70px; left: 0.7px; top: 0.7px;'
>" |
| 1006 " <div id='b' style='width: 40px; height: 40px; transform: translate3d(
5px, 7px, 0);'>" |
| 1007 " <div id='c' style='width: 40px; height: 40px; transform: translate3
d(11px, 13px, 0);'>" |
| 1008 " <div id='d' style='width: 40px; height: 40px; left: 0.7px; top: 0
.7px;'></div>" |
| 1009 " </div>" |
| 1010 " </div>" |
| 1011 "</div>" |
| 1012 ); |
| 1013 |
| 1014 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 1015 EXPECT_EQ(TransformationMatrix().translate3d(5, 7, 0), bProperties->transfor
m()->matrix()); |
| 1016 // The paint offset transform should be snapped from (0.7,0.7) to (1,1). |
| 1017 EXPECT_EQ(TransformationMatrix().translate(1, 1), bProperties->transform()->
parent()->matrix()); |
| 1018 // The residual subpixel adjustment should be (0.7,0.7) - (1,1) = (-0.3,-0.3
). |
| 1019 LayoutPoint subpixelAccumulation = LayoutPoint(LayoutPoint(FloatPoint(0.7, 0
.7)) - LayoutPoint(1, 1)); |
| 1020 EXPECT_EQ(subpixelAccumulation, bProperties->localBorderBoxProperties()->pai
ntOffset); |
| 1021 |
| 1022 ObjectPaintProperties* cProperties = document().getElementById("c")->layoutO
bject()->objectPaintProperties(); |
| 1023 EXPECT_EQ(TransformationMatrix().translate3d(11, 13, 0), cProperties->transf
orm()->matrix()); |
| 1024 // The paint offset should be (-0.3,-0.3) but the paint offset transform sho
uld still be at |
| 1025 // (0,0) because it should be snapped. |
| 1026 EXPECT_EQ(TransformationMatrix().translate(0, 0), cProperties->transform()->
parent()->matrix()); |
| 1027 // The residual subpixel adjustment should still be (-0.3,-0.3). |
| 1028 EXPECT_EQ(subpixelAccumulation, cProperties->localBorderBoxProperties()->pai
ntOffset); |
| 1029 |
| 1030 // d should be painted starting at subpixelAccumulation + (0.7,0.7) = (0.4,0
.4). |
| 1031 LayoutPoint dPaintOffset = subpixelAccumulation + LayoutPoint(FloatPoint(0.7
, 0.7)); |
| 1032 ObjectPaintProperties* dProperties = document().getElementById("d")->layoutO
bject()->objectPaintProperties(); |
| 1033 EXPECT_EQ(dPaintOffset, dProperties->localBorderBoxProperties()->paintOffset
); |
| 1034 } |
| 1035 |
| 1036 TEST_F(PaintPropertyTreeBuilderTest, PaintOffsetWithPixelSnappingWithFixedPos) |
| 1037 { |
| 1038 setBodyInnerHTML( |
| 1039 "<style>" |
| 1040 " * { margin: 0; }" |
| 1041 "</style>" |
| 1042 "<div id='a' style='width: 70px; height: 70px; left: 0.7px; position: re
lative;'>" |
| 1043 " <div id='b' style='width: 40px; height: 40px; transform: translateZ(0
); position: relative;'>" |
| 1044 " <div id='fixed' style='width: 40px; height: 40px; position: fixed;'
>" |
| 1045 " <div id='d' style='width: 40px; height: 40px; left: 0.7px; positi
on: relative;'></div>" |
| 1046 " </div>" |
| 1047 " </div>" |
| 1048 "</div>" |
| 1049 ); |
| 1050 |
| 1051 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 1052 EXPECT_EQ(TransformationMatrix().translate(0, 0), bProperties->transform()->
matrix()); |
| 1053 // The paint offset transform should be snapped from (0.7,0) to (1,0). |
| 1054 EXPECT_EQ(TransformationMatrix().translate(1, 0), bProperties->transform()->
parent()->matrix()); |
| 1055 // The residual subpixel adjustment should be (0.7,0) - (1,0) = (-0.3,0). |
| 1056 LayoutPoint subpixelAccumulation = LayoutPoint(LayoutPoint(FloatPoint(0.7, 0
)) - LayoutPoint(1, 0)); |
| 1057 EXPECT_EQ(subpixelAccumulation, bProperties->localBorderBoxProperties()->pai
ntOffset); |
| 1058 |
| 1059 ObjectPaintProperties* fixedProperties = document().getElementById("fixed")-
>layoutObject()->objectPaintProperties(); |
| 1060 // The residual subpixel adjustment should still be (-0.3,0). |
| 1061 EXPECT_EQ(subpixelAccumulation, fixedProperties->localBorderBoxProperties()-
>paintOffset); |
| 1062 |
| 1063 // d should be painted starting at subpixelAccumulation + (0.7,0) = (0.4,0). |
| 1064 LayoutPoint dPaintOffset = subpixelAccumulation + LayoutPoint(FloatPoint(0.7
, 0)); |
| 1065 ObjectPaintProperties* dProperties = document().getElementById("d")->layoutO
bject()->objectPaintProperties(); |
| 1066 EXPECT_EQ(dPaintOffset, dProperties->localBorderBoxProperties()->paintOffset
); |
| 1067 } |
| 1068 |
921 } // namespace blink | 1069 } // namespace blink |
OLD | NEW |