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/LayoutObject.h" | 5 #include "core/layout/LayoutObject.h" |
6 | 6 |
7 #include "core/layout/LayoutTestHelper.h" | 7 #include "core/layout/LayoutTestHelper.h" |
8 #include "core/layout/LayoutView.h" | 8 #include "core/layout/LayoutView.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 class LayoutObjectTest : public RenderingTest { | 13 class LayoutObjectTest : public RenderingTest { |
| 14 public: |
| 15 LayoutObjectTest() |
| 16 : RenderingTest(SingleChildFrameLoaderClient::create()) {} |
14 protected: | 17 protected: |
15 LayoutView& layoutView() const { return *document().layoutView(); } | 18 LayoutView& layoutView() const { return *document().layoutView(); } |
16 }; | 19 }; |
17 | 20 |
18 TEST_F(LayoutObjectTest, LayoutDecoratedNameCalledWithPositionedObject) | 21 TEST_F(LayoutObjectTest, LayoutDecoratedNameCalledWithPositionedObject) |
19 { | 22 { |
20 setBodyInnerHTML("<div id='div' style='position: fixed'>test</div>"); | 23 setBodyInnerHTML("<div id='div' style='position: fixed'>test</div>"); |
21 Element* div = document().getElementById(AtomicString("div")); | 24 Element* div = document().getElementById(AtomicString("div")); |
22 ASSERT(div); | 25 ASSERT(div); |
23 LayoutObject* obj = div->layoutObject(); | 26 LayoutObject* obj = div->layoutObject(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 LayoutObject* layoutObject = bodyLayoutObject->slowFirstChild()->slowFirstCh
ild(); | 102 LayoutObject* layoutObject = bodyLayoutObject->slowFirstChild()->slowFirstCh
ild(); |
100 | 103 |
101 // Sanity check: Make sure we don't generate anonymous objects. | 104 // Sanity check: Make sure we don't generate anonymous objects. |
102 EXPECT_EQ(nullptr, bodyLayoutObject->slowFirstChild()->nextSibling()); | 105 EXPECT_EQ(nullptr, bodyLayoutObject->slowFirstChild()->nextSibling()); |
103 EXPECT_EQ(nullptr, layoutObject->slowFirstChild()); | 106 EXPECT_EQ(nullptr, layoutObject->slowFirstChild()); |
104 EXPECT_EQ(nullptr, layoutObject->nextSibling()); | 107 EXPECT_EQ(nullptr, layoutObject->nextSibling()); |
105 | 108 |
106 EXPECT_EQ(layoutObject->containingBlock(), bodyLayoutObject); | 109 EXPECT_EQ(layoutObject->containingBlock(), bodyLayoutObject); |
107 } | 110 } |
108 | 111 |
109 TEST_F(LayoutObjectTest, MapToVisibleRectInAncestorSpace) | 112 TEST_F(LayoutObjectTest, LayoutTextMapToVisibleRectInAncestorSpace) |
110 { | 113 { |
111 setBodyInnerHTML( | 114 setBodyInnerHTML( |
112 "<div id='container' style='overflow: scroll; will-change: transform; wi
dth: 50px; height: 50px'>" | 115 "<style>body { margin: 0; }</style>" |
| 116 "<div id='container' style='overflow: scroll; width: 50px; height: 50px'
>" |
113 " <span><img style='width: 20px; height: 100px'></span>" | 117 " <span><img style='width: 20px; height: 100px'></span>" |
114 " text text text text text text text" | 118 " text text text text text text text" |
115 "</div>"); | 119 "</div>"); |
| 120 |
116 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); | 121 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); |
117 LayoutText* text = toLayoutText(container->lastChild()); | 122 LayoutText* text = toLayoutText(container->lastChild()); |
118 | 123 |
119 container->setScrollTop(LayoutUnit(50)); | 124 container->setScrollTop(LayoutUnit(50)); |
120 LayoutRect rect(0, 60, 20, 20); | 125 LayoutRect rect(0, 60, 20, 80); |
121 text->mapToVisibleRectInAncestorSpace(container, rect, nullptr); | 126 EXPECT_TRUE(text->mapToVisibleRectInAncestorSpace(container, rect, nullptr))
; |
122 EXPECT_TRUE(rect == LayoutRect(0, 10, 20, 20)); | 127 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80)); |
| 128 |
| 129 rect = LayoutRect(0, 60, 80, 0); |
| 130 EXPECT_TRUE(text->mapToVisibleRectInAncestorSpace(container, rect, nullptr,
EdgeInclusive)); |
| 131 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); |
| 132 } |
| 133 |
| 134 TEST_F(LayoutObjectTest, LayoutInlineMapToVisibleRectInAncestorSpace) |
| 135 { |
| 136 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 137 setBodyInnerHTML( |
| 138 "<style>body { margin: 0; }</style>" |
| 139 "<div id='container' style='overflow: scroll; width: 50px; height: 50px'
>" |
| 140 " <span><img style='width: 20px; height: 100px'></span>" |
| 141 " <span id=leaf></span></div>"); |
| 142 |
| 143 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); |
| 144 LayoutObject* leaf = container->lastChild(); |
| 145 |
| 146 container->setScrollTop(LayoutUnit(50)); |
| 147 LayoutRect rect(0, 60, 20, 80); |
| 148 EXPECT_TRUE(leaf->mapToVisibleRectInAncestorSpace(container, rect, nullptr))
; |
| 149 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80)); |
| 150 |
| 151 rect = LayoutRect(0, 60, 80, 0); |
| 152 EXPECT_TRUE(leaf->mapToVisibleRectInAncestorSpace(container, rect, nullptr,
EdgeInclusive)); |
| 153 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); |
| 154 } |
| 155 |
| 156 TEST_F(LayoutObjectTest, LayoutViewMapToVisibleRectInAncestorSpace) |
| 157 { |
| 158 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 159 setBodyInnerHTML( |
| 160 "<style>body { margin: 0; }</style>" |
| 161 "<div id=frameContainer>" |
| 162 " <iframe id=frame src='http://test.com' width='50' height='50' frameBo
rder='0'></iframe>" |
| 163 "</div>"); |
| 164 |
| 165 Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0
; }</style><span><img style='width: 20px; height: 100px'></span>text text text")
; |
| 166 frameDocument.updateLayout(); |
| 167 |
| 168 LayoutBlock* frameContainer = toLayoutBlock(getLayoutObjectByElementId("fram
eContainer")); |
| 169 LayoutBlock* frameBody = toLayoutBlock(frameDocument.body()->layoutObject())
; |
| 170 LayoutText* frameText = toLayoutText(frameBody->lastChild()); |
| 171 |
| 172 // This case involves clipping: frame height is 50, y-coordinate of result r
ect is 13, |
| 173 // so height should be clipped to (50 - 13) == 37. |
| 174 frameDocument.view()->setScrollPosition(DoublePoint(0, 47), ProgrammaticScro
ll); |
| 175 LayoutRect rect(4, 60, 20, 80); |
| 176 EXPECT_TRUE(frameText->mapToVisibleRectInAncestorSpace(frameContainer, rect,
nullptr)); |
| 177 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); |
| 178 |
| 179 rect = LayoutRect(4, 60, 0, 80); |
| 180 EXPECT_TRUE(frameText->mapToVisibleRectInAncestorSpace(frameContainer, rect,
nullptr, EdgeInclusive)); |
| 181 EXPECT_EQ(rect, LayoutRect(4, 13, 0, 37)); |
123 } | 182 } |
124 | 183 |
125 } // namespace blink | 184 } // namespace blink |
OLD | NEW |