Chromium Code Reviews| 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/html/HTMLFrameOwnerElement.h" | |
|
dcheng
2016/11/17 08:49:58
So that line 223 can convert from HTMLFrameOwnerEl
| |
| 5 #include "core/layout/LayoutTestHelper.h" | 6 #include "core/layout/LayoutTestHelper.h" |
| 6 #include "core/layout/LayoutView.h" | 7 #include "core/layout/LayoutView.h" |
| 7 #include "core/layout/PaintInvalidationState.h" | 8 #include "core/layout/PaintInvalidationState.h" |
| 8 #include "core/paint/PaintLayer.h" | 9 #include "core/paint/PaintLayer.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 class VisualRectMappingTest : public RenderingTest { | 14 class VisualRectMappingTest : public RenderingTest { |
| 14 public: | 15 public: |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 layoutView(), layoutView()); | 114 layoutView(), layoutView()); |
| 114 | 115 |
| 115 rect = LayoutRect(0, 60, 80, 0); | 116 rect = LayoutRect(0, 60, 80, 0); |
| 116 EXPECT_TRUE( | 117 EXPECT_TRUE( |
| 117 leaf->mapToVisualRectInAncestorSpace(container, rect, EdgeInclusive)); | 118 leaf->mapToVisualRectInAncestorSpace(container, rect, EdgeInclusive)); |
| 118 rect.move(-container->scrolledContentOffset()); | 119 rect.move(-container->scrolledContentOffset()); |
| 119 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); | 120 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); |
| 120 } | 121 } |
| 121 | 122 |
| 122 TEST_F(VisualRectMappingTest, LayoutView) { | 123 TEST_F(VisualRectMappingTest, LayoutView) { |
| 124 setChildFrameHTML( | |
| 125 "<style>body { margin: 0; }</style><span><img style='width: 20px; " | |
| 126 "height: 100px'></span>text text text"); | |
| 127 | |
| 123 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 128 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 124 setBodyInnerHTML( | 129 setBodyInnerHTML( |
| 125 "<style>body { margin: 0; }</style>" | 130 "<style>body { margin: 0; }</style>" |
| 126 "<div id=frameContainer>" | 131 "<div id=frameContainer>" |
| 127 " <iframe id=frame src='http://test.com' width='50' height='50' " | 132 " <iframe src='http://test.com' width='50' height='50' " |
| 128 "frameBorder='0'></iframe>" | 133 "frameBorder='0'></iframe>" |
| 129 "</div>"); | 134 "</div>"); |
| 130 | 135 |
| 131 Document& frameDocument = setupChildIframe( | |
| 132 "frame", | |
| 133 "<style>body { margin: 0; }</style><span><img style='width: 20px; " | |
| 134 "height: 100px'></span>text text text"); | |
| 135 document().view()->updateAllLifecyclePhases(); | 136 document().view()->updateAllLifecyclePhases(); |
| 136 | 137 |
| 137 LayoutBlock* frameContainer = | 138 LayoutBlock* frameContainer = |
| 138 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); | 139 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); |
| 139 LayoutBlock* frameBody = toLayoutBlock(frameDocument.body()->layoutObject()); | 140 LayoutBlock* frameBody = |
| 141 toLayoutBlock(childDocument().body()->layoutObject()); | |
| 140 LayoutText* frameText = toLayoutText(frameBody->lastChild()); | 142 LayoutText* frameText = toLayoutText(frameBody->lastChild()); |
| 141 | 143 |
| 142 // This case involves clipping: frame height is 50, y-coordinate of result | 144 // This case involves clipping: frame height is 50, y-coordinate of result |
| 143 // rect is 13, so height should be clipped to (50 - 13) == 37. | 145 // rect is 13, so height should be clipped to (50 - 13) == 37. |
| 144 frameDocument.view()->setScrollOffset(ScrollOffset(0, 47), | 146 childDocument().view()->setScrollOffset(ScrollOffset(0, 47), |
| 145 ProgrammaticScroll); | 147 ProgrammaticScroll); |
| 146 LayoutRect originalRect(4, 60, 20, 80); | 148 LayoutRect originalRect(4, 60, 20, 80); |
| 147 LayoutRect rect = originalRect; | 149 LayoutRect rect = originalRect; |
| 148 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect)); | 150 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect)); |
| 149 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); | 151 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); |
| 150 | 152 |
| 151 rect = originalRect; | 153 rect = originalRect; |
| 152 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 154 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 153 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); | 155 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); |
| 154 checkPaintInvalidationStateRectMapping(rect, originalRect, *frameText, | 156 checkPaintInvalidationStateRectMapping(rect, originalRect, *frameText, |
| 155 layoutView(), layoutView()); | 157 layoutView(), layoutView()); |
| 156 | 158 |
| 157 rect = LayoutRect(4, 60, 0, 80); | 159 rect = LayoutRect(4, 60, 0, 80); |
| 158 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect, | 160 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect, |
| 159 EdgeInclusive)); | 161 EdgeInclusive)); |
| 160 EXPECT_EQ(rect, LayoutRect(4, 13, 0, 37)); | 162 EXPECT_EQ(rect, LayoutRect(4, 13, 0, 37)); |
| 161 } | 163 } |
| 162 | 164 |
| 163 TEST_F(VisualRectMappingTest, LayoutViewSubpixelRounding) { | 165 TEST_F(VisualRectMappingTest, LayoutViewSubpixelRounding) { |
| 166 setChildFrameHTML( | |
| 167 "<style>body { margin: 0; }</style><div id='target' style='position: " | |
| 168 "relative; width: 100px; height: 100px; left: 0.5px'>"); | |
| 169 | |
| 164 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 170 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 165 setBodyInnerHTML( | 171 setBodyInnerHTML( |
| 166 "<style>body { margin: 0; }</style>" | 172 "<style>body { margin: 0; }</style>" |
| 167 "<div id=frameContainer style='position: relative; left: 0.5px'>" | 173 "<div id=frameContainer style='position: relative; left: 0.5px'>" |
| 168 " <iframe id=frame style='position: relative; left: 0.5px' " | 174 " <iframe style='position: relative; left: 0.5px' " |
| 169 "src='http://test.com' width='200' height='200' frameBorder='0'></iframe>" | 175 "src='http://test.com' width='200' height='200' frameBorder='0'></iframe>" |
| 170 "</div>"); | 176 "</div>"); |
| 171 | 177 |
| 172 Document& frameDocument = setupChildIframe( | |
| 173 "frame", | |
| 174 "<style>body { margin: 0; }</style><div id='target' style='position: " | |
| 175 "relative; width: 100px; height: 100px; left: 0.5px'>"); | |
| 176 document().view()->updateAllLifecyclePhases(); | 178 document().view()->updateAllLifecyclePhases(); |
| 177 | 179 |
| 178 LayoutBlock* frameContainer = | 180 LayoutBlock* frameContainer = |
| 179 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); | 181 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); |
| 180 LayoutObject* target = frameDocument.getElementById("target")->layoutObject(); | 182 LayoutObject* target = |
| 183 childDocument().getElementById("target")->layoutObject(); | |
| 181 LayoutRect rect(0, 0, 100, 100); | 184 LayoutRect rect(0, 0, 100, 100); |
| 182 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(frameContainer, rect)); | 185 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(frameContainer, rect)); |
| 183 // When passing from the iframe to the parent frame, the rect of (0.5, 0, 100, | 186 // When passing from the iframe to the parent frame, the rect of (0.5, 0, 100, |
| 184 // 100) is expanded to (0, 0, 100, 100), and then offset by the 0.5 offset of | 187 // 100) is expanded to (0, 0, 100, 100), and then offset by the 0.5 offset of |
| 185 // frameContainer. | 188 // frameContainer. |
| 186 EXPECT_EQ(LayoutRect(LayoutPoint(DoublePoint(0.5, 0)), LayoutSize(101, 100)), | 189 EXPECT_EQ(LayoutRect(LayoutPoint(DoublePoint(0.5, 0)), LayoutSize(101, 100)), |
| 187 rect); | 190 rect); |
| 188 } | 191 } |
| 189 | 192 |
| 190 TEST_F(VisualRectMappingTest, LayoutViewDisplayNone) { | 193 TEST_F(VisualRectMappingTest, LayoutViewDisplayNone) { |
| 194 setChildFrameHTML( | |
| 195 "<style>body { margin: 0; }</style><div " | |
| 196 "style='width:100px;height:100px;'></div>"); | |
| 197 | |
| 191 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 198 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 192 setBodyInnerHTML( | 199 setBodyInnerHTML( |
| 193 "<style>body { margin: 0; }</style>" | 200 "<style>body { margin: 0; }</style>" |
| 194 "<div id=frameContainer>" | 201 "<div id=frameContainer>" |
| 195 " <iframe id=frame src='http://test.com' width='50' height='50' " | 202 " <iframe src='http://test.com' width='50' height='50' " |
| 196 "frameBorder='0'></iframe>" | 203 "frameBorder='0'></iframe>" |
| 197 "</div>"); | 204 "</div>"); |
| 198 | 205 |
| 199 Document& frameDocument = | |
| 200 setupChildIframe("frame", | |
| 201 "<style>body { margin: 0; }</style><div " | |
| 202 "style='width:100px;height:100px;'></div>"); | |
| 203 document().view()->updateAllLifecyclePhases(); | 206 document().view()->updateAllLifecyclePhases(); |
| 204 | 207 |
| 205 LayoutBlock* frameContainer = | 208 LayoutBlock* frameContainer = |
| 206 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); | 209 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); |
| 207 LayoutBlock* frameBody = toLayoutBlock(frameDocument.body()->layoutObject()); | 210 LayoutBlock* frameBody = |
| 211 toLayoutBlock(childDocument().body()->layoutObject()); | |
| 208 LayoutBlock* frameDiv = toLayoutBlock(frameBody->lastChild()); | 212 LayoutBlock* frameDiv = toLayoutBlock(frameBody->lastChild()); |
| 209 | 213 |
| 210 // This part is copied from the LayoutView test, just to ensure that the | 214 // This part is copied from the LayoutView test, just to ensure that the |
| 211 // mapped rect is valid before display:none is set on the iframe. | 215 // mapped rect is valid before display:none is set on the iframe. |
| 212 frameDocument.view()->setScrollOffset(ScrollOffset(0, 47), | 216 childDocument().view()->setScrollOffset(ScrollOffset(0, 47), |
| 213 ProgrammaticScroll); | 217 ProgrammaticScroll); |
| 214 LayoutRect originalRect(4, 60, 20, 80); | 218 LayoutRect originalRect(4, 60, 20, 80); |
| 215 LayoutRect rect = originalRect; | 219 LayoutRect rect = originalRect; |
| 216 EXPECT_TRUE(frameDiv->mapToVisualRectInAncestorSpace(frameContainer, rect)); | 220 EXPECT_TRUE(frameDiv->mapToVisualRectInAncestorSpace(frameContainer, rect)); |
| 217 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); | 221 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); |
| 218 | 222 |
| 219 Element* frameElement = document().getElementById("frame"); | 223 Element* frameElement = childDocument().localOwner(); |
| 220 frameElement->setInlineStyleProperty(CSSPropertyDisplay, "none"); | 224 frameElement->setInlineStyleProperty(CSSPropertyDisplay, "none"); |
| 221 document().view()->updateAllLifecyclePhases(); | 225 document().view()->updateAllLifecyclePhases(); |
| 222 | 226 |
| 223 rect = originalRect; | 227 rect = originalRect; |
| 224 EXPECT_FALSE(frameDiv->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 228 EXPECT_FALSE(frameDiv->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 225 EXPECT_EQ(rect, LayoutRect()); | 229 EXPECT_EQ(rect, LayoutRect()); |
| 226 } | 230 } |
| 227 | 231 |
| 228 TEST_F(VisualRectMappingTest, SelfFlippedWritingMode) { | 232 TEST_F(VisualRectMappingTest, SelfFlippedWritingMode) { |
| 229 setBodyInnerHTML( | 233 setBodyInnerHTML( |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 691 LayoutRect targetVisualRect = target->localVisualRect(); | 695 LayoutRect targetVisualRect = target->localVisualRect(); |
| 692 EXPECT_EQ(LayoutRect(0, 0, 400, 400), targetVisualRect); | 696 EXPECT_EQ(LayoutRect(0, 0, 400, 400), targetVisualRect); |
| 693 LayoutRect rect = targetVisualRect; | 697 LayoutRect rect = targetVisualRect; |
| 694 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 698 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 695 EXPECT_EQ(LayoutRect(0, 0, 200, 200), rect); | 699 EXPECT_EQ(LayoutRect(0, 0, 200, 200), rect); |
| 696 checkPaintInvalidationStateRectMapping(rect, targetVisualRect, *target, | 700 checkPaintInvalidationStateRectMapping(rect, targetVisualRect, *target, |
| 697 layoutView(), layoutView()); | 701 layoutView(), layoutView()); |
| 698 } | 702 } |
| 699 | 703 |
| 700 } // namespace blink | 704 } // namespace blink |
| OLD | NEW |