OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/LayoutBox.h" | 5 #include "core/layout/LayoutBox.h" |
6 | 6 |
7 #include "core/html/HTMLElement.h" | 7 #include "core/html/HTMLElement.h" |
8 #include "core/layout/ImageQualityController.h" | 8 #include "core/layout/ImageQualityController.h" |
9 #include "core/layout/LayoutTestHelper.h" | 9 #include "core/layout/LayoutTestHelper.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 class LayoutBoxTest : public RenderingTest { | 14 class LayoutBoxTest : public RenderingTest { |
15 }; | 15 }; |
16 | 16 |
17 TEST_F(LayoutBoxTest, BackgroundObscuredInRect) | 17 TEST_F(LayoutBoxTest, BackgroundObscuredInRect) |
18 { | 18 { |
19 setBodyInnerHTML("<style>.column { width: 295.4px; padding-left: 10.4px; } .
white-background { background: red; position: relative; overflow: hidden; border
-radius: 1px; }" | 19 setBodyInnerHTML("<style>.column { width: 295.4px; padding-left: 10.4px; } .
white-background { background: red; position: relative; overflow: hidden; border
-radius: 1px; }" |
20 ".black-background { height: 100px; background: black; color: white; } <
/style>" | 20 ".black-background { height: 100px; background: black; color: white; } <
/style>" |
21 "<div class='column'> <div> <div id='target' class='white-background'> <
div class='black-background'></div> </div> </div> </div>"); | 21 "<div class='column'> <div> <div id='target' class='white-background'> <
div class='black-background'></div> </div> </div> </div>"); |
22 LayoutObject* layoutObject = getLayoutObjectByElementId("target"); | 22 LayoutObject* layoutObject = getLayoutObjectByElementId("target"); |
23 ASSERT_TRUE(layoutObject); | 23 ASSERT_TRUE(layoutObject); |
24 ASSERT_TRUE(layoutObject->backgroundIsKnownToBeObscured()); | 24 ASSERT_TRUE(layoutObject->backgroundIsKnownToBeObscured()); |
25 } | 25 } |
26 | 26 |
| 27 TEST_F(LayoutBoxTest, BackgroundRect) |
| 28 { |
| 29 setBodyInnerHTML("<style>div { position: absolute; width: 100px; height: 100
px; padding: 10px; border: 10px solid black; overflow: scroll; }" |
| 30 "#target1 { background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUg
) border-box, green content-box;}" |
| 31 "#target2 { background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUg
) content-box, green local border-box;}" |
| 32 "#target3 { background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUg
) content-box, rgba(0, 255, 0, 0.5) border-box;}" |
| 33 "#target4 { background-image: url(data:image/png;base64,iVBORw0KGgoAAAAN
SUhEUg), none;" |
| 34 " background-clip: content-box, border-box;" |
| 35 " background-blend-mode: normal, multiply;" |
| 36 " background-color: green; }" |
| 37 "#target5 { background: none border-box, green content-box;}" |
| 38 "#target6 { background: green content-box local; }" |
| 39 "</style>" |
| 40 "<div id='target1'></div>" |
| 41 "<div id='target2'></div>" |
| 42 "<div id='target3'></div>" |
| 43 "<div id='target4'></div>" |
| 44 "<div id='target5'></div>" |
| 45 "<div id='target6'></div>"); |
| 46 |
| 47 // #target1's opaque background color only fills the content box but its tra
nslucent image extends to the borders. |
| 48 LayoutBox* layoutBox = toLayoutBox(getLayoutObjectByElementId("target1")); |
| 49 EXPECT_EQ(LayoutRect(20, 20, 100, 100), layoutBox->backgroundRect(Background
KnownOpaqueRect)); |
| 50 EXPECT_EQ(LayoutRect(0, 0, 140, 140), layoutBox->backgroundRect(BackgroundCl
ipRect)); |
| 51 |
| 52 // #target2's background color is opaque but only fills the padding-box beca
use it has local attachment. |
| 53 // This eclipses the content-box image. |
| 54 layoutBox = toLayoutBox(getLayoutObjectByElementId("target2")); |
| 55 EXPECT_EQ(LayoutRect(10, 10, 120, 120), layoutBox->backgroundRect(Background
KnownOpaqueRect)); |
| 56 EXPECT_EQ(LayoutRect(10, 10, 120, 120), layoutBox->backgroundRect(Background
ClipRect)); |
| 57 |
| 58 // #target3's background color is not opaque so we only have a clip rect. |
| 59 layoutBox = toLayoutBox(getLayoutObjectByElementId("target3")); |
| 60 EXPECT_TRUE(layoutBox->backgroundRect(BackgroundKnownOpaqueRect).isEmpty()); |
| 61 EXPECT_EQ(LayoutRect(0, 0, 140, 140), layoutBox->backgroundRect(BackgroundCl
ipRect)); |
| 62 |
| 63 // #target4's background color has a blend mode so it isn't opaque. |
| 64 layoutBox = toLayoutBox(getLayoutObjectByElementId("target4")); |
| 65 EXPECT_TRUE(layoutBox->backgroundRect(BackgroundKnownOpaqueRect).isEmpty()); |
| 66 EXPECT_EQ(LayoutRect(0, 0, 140, 140), layoutBox->backgroundRect(BackgroundCl
ipRect)); |
| 67 |
| 68 // #target5's solid background only covers the content-box but it has a "non
e" background |
| 69 // covering the border box. |
| 70 layoutBox = toLayoutBox(getLayoutObjectByElementId("target5")); |
| 71 EXPECT_EQ(LayoutRect(20, 20, 100, 100), layoutBox->backgroundRect(Background
KnownOpaqueRect)); |
| 72 EXPECT_EQ(LayoutRect(0, 0, 140, 140), layoutBox->backgroundRect(BackgroundCl
ipRect)); |
| 73 |
| 74 // Because it can scroll due to local attachment, the opaque local backgroun
d in #target6 |
| 75 // is treated as padding box for the clip rect, but remains the content box
for the known |
| 76 // opaque rect. |
| 77 layoutBox = toLayoutBox(getLayoutObjectByElementId("target6")); |
| 78 EXPECT_EQ(LayoutRect(20, 20, 100, 100), layoutBox->backgroundRect(Background
KnownOpaqueRect)); |
| 79 EXPECT_EQ(LayoutRect(10, 10, 120, 120), layoutBox->backgroundRect(Background
ClipRect)); |
| 80 } |
| 81 |
27 } // namespace blink | 82 } // namespace blink |
OLD | NEW |