OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/layout/LayoutInline.h" |
| 6 #include "core/layout/LayoutTestHelper.h" |
| 7 #include "core/layout/LayoutView.h" |
| 8 #include "platform/geometry/TransformState.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 class MapLocalToAncestorTest : public RenderingTest { |
| 14 public: |
| 15 FloatPoint mapLocalToAncestor(const LayoutObject*, const LayoutBoxModelObjec
t* ancestor, FloatPoint, MapCoordinatesFlags = 0) const; |
| 16 FloatQuad mapLocalToAncestor(const LayoutObject*, const LayoutBoxModelObject
* ancestor, FloatQuad, MapCoordinatesFlags = 0) const; |
| 17 }; |
| 18 |
| 19 // One note about tests here that operate on LayoutInline and LayoutText objects
: |
| 20 // mapLocalToAncestor() expects such objects to pass their static location and s
ize (relatively to |
| 21 // the border edge of their container) to mapLocalToAncestor() via the Transform
State |
| 22 // argument. mapLocalToAncestor() is then only expected to make adjustments for |
| 23 // relative-positioning, container-specific characteristics (such as writing mod
e roots, multicol), |
| 24 // and so on. This in contrast to LayoutBox objects, where the TransformState pa
ssed is relative to |
| 25 // the box itself, not the container. |
| 26 |
| 27 FloatPoint MapLocalToAncestorTest::mapLocalToAncestor(const LayoutObject* object
, const LayoutBoxModelObject* ancestor, FloatPoint point, MapCoordinatesFlags mo
de) const |
| 28 { |
| 29 TransformState transformState(TransformState::ApplyTransformDirection, point
); |
| 30 object->mapLocalToAncestor(ancestor, transformState, mode); |
| 31 transformState.flatten(); |
| 32 return transformState.lastPlanarPoint(); |
| 33 } |
| 34 |
| 35 FloatQuad MapLocalToAncestorTest::mapLocalToAncestor(const LayoutObject* object,
const LayoutBoxModelObject* ancestor, FloatQuad quad, MapCoordinatesFlags mode)
const |
| 36 { |
| 37 TransformState transformState(TransformState::ApplyTransformDirection, quad.
boundingBox().center(), quad); |
| 38 object->mapLocalToAncestor(ancestor, transformState, mode); |
| 39 transformState.flatten(); |
| 40 return transformState.lastPlanarQuad(); |
| 41 } |
| 42 |
| 43 TEST_F(MapLocalToAncestorTest, SimpleText) |
| 44 { |
| 45 setBodyInnerHTML("<div id='container'><br>text</div>"); |
| 46 |
| 47 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 48 LayoutObject* text = toLayoutBlockFlow(container)->lastChild(); |
| 49 ASSERT_TRUE(text->isText()); |
| 50 FloatPoint mappedPoint = mapLocalToAncestor(text, container, FloatPoint(10,
30)); |
| 51 EXPECT_EQ(FloatPoint(10, 30), mappedPoint); |
| 52 } |
| 53 |
| 54 TEST_F(MapLocalToAncestorTest, SimpleInline) |
| 55 { |
| 56 setBodyInnerHTML("<div><span id='target'>text</span></div>"); |
| 57 |
| 58 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 59 FloatPoint mappedPoint = mapLocalToAncestor(target, toLayoutBoxModelObject(t
arget->parent()), FloatPoint(10, 10)); |
| 60 EXPECT_EQ(FloatPoint(10, 10), mappedPoint); |
| 61 } |
| 62 |
| 63 TEST_F(MapLocalToAncestorTest, SimpleBlock) |
| 64 { |
| 65 setBodyInnerHTML( |
| 66 "<div style='margin:666px; border:8px solid; padding:7px;'>" |
| 67 " <div id='target' style='margin:10px; border:666px; padding:666px;'>
</div>" |
| 68 "</div>"); |
| 69 |
| 70 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 71 FloatPoint mappedPoint = mapLocalToAncestor(target, toLayoutBoxModelObject(t
arget->parent()), FloatPoint(100, 100)); |
| 72 EXPECT_EQ(FloatPoint(125, 125), mappedPoint); |
| 73 } |
| 74 |
| 75 TEST_F(MapLocalToAncestorTest, TextInRelPosInline) |
| 76 { |
| 77 setBodyInnerHTML("<div><span style='position:relative; left:7px; top:4px;'><
br id='sibling'>text</span></div>"); |
| 78 |
| 79 LayoutObject* br = getLayoutObjectByElementId("sibling"); |
| 80 LayoutObject* text = br->nextSibling(); |
| 81 ASSERT_TRUE(text->isText()); |
| 82 FloatPoint mappedPoint = mapLocalToAncestor(text, text->containingBlock(), F
loatPoint(10, 30)); |
| 83 EXPECT_EQ(FloatPoint(17, 34), mappedPoint); |
| 84 } |
| 85 |
| 86 TEST_F(MapLocalToAncestorTest, RelposInline) |
| 87 { |
| 88 setBodyInnerHTML("<span id='target' style='position:relative; left:50px; top
:100px;'>text</span>"); |
| 89 |
| 90 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 91 FloatPoint mappedPoint = mapLocalToAncestor(target, toLayoutBoxModelObject(t
arget->parent()), FloatPoint(10, 10)); |
| 92 EXPECT_EQ(FloatPoint(60, 110), mappedPoint); |
| 93 } |
| 94 |
| 95 TEST_F(MapLocalToAncestorTest, RelposInlineInRelposInline) |
| 96 { |
| 97 setBodyInnerHTML( |
| 98 "<div style='padding-left:10px;'>" |
| 99 " <span style='position:relative; left:5px; top:6px;'>" |
| 100 " <span id='target' style='position:relative; left:50px; top:100p
x;'>text</span>" |
| 101 " </span>" |
| 102 "</div>"); |
| 103 |
| 104 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 105 LayoutInline* parent = toLayoutInline(target->parent()); |
| 106 LayoutBlockFlow* containingBlock = toLayoutBlockFlow(parent->parent()); |
| 107 |
| 108 FloatPoint mappedPoint = mapLocalToAncestor(target, containingBlock, FloatPo
int(20, 10)); |
| 109 EXPECT_EQ(FloatPoint(75, 116), mappedPoint); |
| 110 |
| 111 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 112 mappedPoint = mapLocalToAncestor(target, parent, FloatPoint(20, 10)); |
| 113 EXPECT_EQ(FloatPoint(70, 110), mappedPoint); |
| 114 |
| 115 mappedPoint = mapLocalToAncestor(parent, containingBlock, mappedPoint); |
| 116 EXPECT_EQ(FloatPoint(75, 116), mappedPoint); |
| 117 } |
| 118 |
| 119 TEST_F(MapLocalToAncestorTest, RelPosBlock) |
| 120 { |
| 121 setBodyInnerHTML( |
| 122 "<div id='container' style='margin:666px; border:8px solid; padding:7px;
'>" |
| 123 " <div id='middle' style='margin:30px; border:1px solid;'>" |
| 124 " <div id='target' style='position:relative; left:50px; top:50px;
margin:10px; border:666px; padding:666px;'></div>" |
| 125 " </div>" |
| 126 "</div>"); |
| 127 |
| 128 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 129 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 130 |
| 131 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 132 EXPECT_EQ(FloatPoint(106, 106), mappedPoint); |
| 133 |
| 134 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 135 LayoutBox* middle = toLayoutBox(getLayoutObjectByElementId("middle")); |
| 136 |
| 137 mappedPoint = mapLocalToAncestor(target, middle, FloatPoint()); |
| 138 EXPECT_EQ(FloatPoint(61, 61), mappedPoint); |
| 139 |
| 140 mappedPoint = mapLocalToAncestor(middle, container, mappedPoint); |
| 141 EXPECT_EQ(FloatPoint(106, 106), mappedPoint); |
| 142 } |
| 143 |
| 144 TEST_F(MapLocalToAncestorTest, AbsPos) |
| 145 { |
| 146 setBodyInnerHTML( |
| 147 "<div id='container' style='position:relative; margin:666px; border:8px
solid; padding:7px;'>" |
| 148 " <div id='staticChild' style='margin:30px; padding-top:666px;'>" |
| 149 " <div style='padding-top:666px;'></div>" |
| 150 " <div id='target' style='position:absolute; left:-1px; top:-1px;
margin:10px; border:666px; padding:666px;'></div>" |
| 151 " </div>" |
| 152 "</div>"); |
| 153 |
| 154 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 155 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 156 |
| 157 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 158 EXPECT_EQ(FloatPoint(17, 17), mappedPoint); |
| 159 |
| 160 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 161 LayoutBox* staticChild = toLayoutBox(getLayoutObjectByElementId("staticChild
")); |
| 162 |
| 163 mappedPoint = mapLocalToAncestor(target, staticChild, FloatPoint()); |
| 164 EXPECT_EQ(FloatPoint(-28, -28), mappedPoint); |
| 165 |
| 166 mappedPoint = mapLocalToAncestor(staticChild, container, mappedPoint); |
| 167 EXPECT_EQ(FloatPoint(17, 17), mappedPoint); |
| 168 } |
| 169 |
| 170 TEST_F(MapLocalToAncestorTest, AbsPosAuto) |
| 171 { |
| 172 setBodyInnerHTML( |
| 173 "<div id='container' style='position:absolute; margin:666px; border:8px
solid; padding:7px;'>" |
| 174 " <div id='staticChild' style='margin:30px; padding-top:5px;'>" |
| 175 " <div style='padding-top:20px;'></div>" |
| 176 " <div id='target' style='position:absolute; margin:10px; border:
666px; padding:666px;'></div>" |
| 177 " </div>" |
| 178 "</div>"); |
| 179 |
| 180 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 181 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 182 |
| 183 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 184 EXPECT_EQ(FloatPoint(55, 80), mappedPoint); |
| 185 |
| 186 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 187 LayoutBox* staticChild = toLayoutBox(getLayoutObjectByElementId("staticChild
")); |
| 188 |
| 189 mappedPoint = mapLocalToAncestor(target, staticChild, FloatPoint()); |
| 190 EXPECT_EQ(FloatPoint(10, 35), mappedPoint); |
| 191 |
| 192 mappedPoint = mapLocalToAncestor(staticChild, container, mappedPoint); |
| 193 EXPECT_EQ(FloatPoint(55, 80), mappedPoint); |
| 194 } |
| 195 |
| 196 TEST_F(MapLocalToAncestorTest, FixedPos) |
| 197 { |
| 198 // Assuming BODY margin of 8px. |
| 199 setBodyInnerHTML( |
| 200 "<div id='container' style='position:absolute; margin:4px; border:5px so
lid; padding:7px;'>" |
| 201 " <div id='staticChild' style='padding-top:666px;'>" |
| 202 " <div style='padding-top:666px;'></div>" |
| 203 " <div id='target' style='position:fixed; left:-1px; top:-1px; ma
rgin:10px; border:666px; padding:666px;'></div>" |
| 204 " </div>" |
| 205 "</div>"); |
| 206 |
| 207 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 208 LayoutBox* staticChild = toLayoutBox(getLayoutObjectByElementId("staticChild
")); |
| 209 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 210 LayoutBox* body = container->parentBox(); |
| 211 LayoutBox* html = body->parentBox(); |
| 212 LayoutBox* view = html->parentBox(); |
| 213 ASSERT_TRUE(view->isLayoutView()); |
| 214 |
| 215 FloatPoint mappedPoint = mapLocalToAncestor(target, view, FloatPoint()); |
| 216 EXPECT_EQ(FloatPoint(9, 9), mappedPoint); |
| 217 |
| 218 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 219 mappedPoint = mapLocalToAncestor(target, staticChild, FloatPoint()); |
| 220 EXPECT_EQ(FloatPoint(-15, -15), mappedPoint); |
| 221 |
| 222 mappedPoint = mapLocalToAncestor(staticChild, container, mappedPoint); |
| 223 EXPECT_EQ(FloatPoint(-3, -3), mappedPoint); |
| 224 |
| 225 mappedPoint = mapLocalToAncestor(container, body, mappedPoint); |
| 226 EXPECT_EQ(FloatPoint(1, 1), mappedPoint); |
| 227 |
| 228 mappedPoint = mapLocalToAncestor(body, html, mappedPoint); |
| 229 EXPECT_EQ(FloatPoint(9, 9), mappedPoint); |
| 230 |
| 231 mappedPoint = mapLocalToAncestor(html, view, mappedPoint); |
| 232 EXPECT_EQ(FloatPoint(9, 9), mappedPoint); |
| 233 } |
| 234 |
| 235 TEST_F(MapLocalToAncestorTest, FixedPosAuto) |
| 236 { |
| 237 // Assuming BODY margin of 8px. |
| 238 setBodyInnerHTML( |
| 239 "<div id='container' style='position:absolute; margin:3px; border:8px so
lid; padding:7px;'>" |
| 240 " <div id='staticChild' style='padding-top:5px;'>" |
| 241 " <div style='padding-top:20px;'></div>" |
| 242 " <div id='target' style='position:fixed; margin:10px; border:666
px; padding:666px;'></div>" |
| 243 " </div>" |
| 244 "</div>"); |
| 245 |
| 246 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 247 LayoutBox* staticChild = toLayoutBox(getLayoutObjectByElementId("staticChild
")); |
| 248 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 249 LayoutBox* body = container->parentBox(); |
| 250 LayoutBox* html = body->parentBox(); |
| 251 LayoutBox* view = html->parentBox(); |
| 252 ASSERT_TRUE(view->isLayoutView()); |
| 253 |
| 254 FloatPoint mappedPoint = mapLocalToAncestor(target, target->containingBlock(
), FloatPoint()); |
| 255 EXPECT_EQ(FloatPoint(36, 61), mappedPoint); |
| 256 |
| 257 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 258 mappedPoint = mapLocalToAncestor(target, staticChild, FloatPoint()); |
| 259 EXPECT_EQ(FloatPoint(10, 35), mappedPoint); |
| 260 |
| 261 mappedPoint = mapLocalToAncestor(staticChild, container, mappedPoint); |
| 262 EXPECT_EQ(FloatPoint(25, 50), mappedPoint); |
| 263 |
| 264 mappedPoint = mapLocalToAncestor(container, body, mappedPoint); |
| 265 EXPECT_EQ(FloatPoint(28, 53), mappedPoint); |
| 266 |
| 267 mappedPoint = mapLocalToAncestor(body, html, mappedPoint); |
| 268 EXPECT_EQ(FloatPoint(36, 61), mappedPoint); |
| 269 |
| 270 mappedPoint = mapLocalToAncestor(html, view, mappedPoint); |
| 271 EXPECT_EQ(FloatPoint(36, 61), mappedPoint); |
| 272 } |
| 273 |
| 274 TEST_F(MapLocalToAncestorTest, FixedPosInFixedPos) |
| 275 { |
| 276 // Assuming BODY margin of 8px. |
| 277 setBodyInnerHTML( |
| 278 "<div id='container' style='position:absolute; margin:4px; border:5px so
lid; padding:7px;'>" |
| 279 " <div id='staticChild' style='padding-top:666px;'>" |
| 280 " <div style='padding-top:666px;'></div>" |
| 281 " <div id='outerFixed' style='position:fixed; left:100px; top:100
px; margin:10px; border:666px; padding:666px;'>" |
| 282 " <div id='target' style='position:fixed; left:-1px; top:-1px
; margin:10px; border:666px; padding:666px;'></div>" |
| 283 " </div>" |
| 284 " </div>" |
| 285 "</div>"); |
| 286 |
| 287 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 288 LayoutBox* outerFixed = toLayoutBox(getLayoutObjectByElementId("outerFixed")
); |
| 289 LayoutBox* staticChild = toLayoutBox(getLayoutObjectByElementId("staticChild
")); |
| 290 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 291 LayoutBox* body = container->parentBox(); |
| 292 LayoutBox* html = body->parentBox(); |
| 293 LayoutBox* view = html->parentBox(); |
| 294 ASSERT_TRUE(view->isLayoutView()); |
| 295 |
| 296 FloatPoint mappedPoint = mapLocalToAncestor(target, view, FloatPoint()); |
| 297 EXPECT_EQ(FloatPoint(9, 9), mappedPoint); |
| 298 |
| 299 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 300 mappedPoint = mapLocalToAncestor(target, outerFixed, FloatPoint()); |
| 301 EXPECT_EQ(FloatPoint(-101, -101), mappedPoint); |
| 302 |
| 303 mappedPoint = mapLocalToAncestor(outerFixed, staticChild, mappedPoint); |
| 304 EXPECT_EQ(FloatPoint(-15, -15), mappedPoint); |
| 305 |
| 306 mappedPoint = mapLocalToAncestor(staticChild, container, mappedPoint); |
| 307 EXPECT_EQ(FloatPoint(-3, -3), mappedPoint); |
| 308 |
| 309 mappedPoint = mapLocalToAncestor(container, body, mappedPoint); |
| 310 EXPECT_EQ(FloatPoint(1, 1), mappedPoint); |
| 311 |
| 312 mappedPoint = mapLocalToAncestor(body, html, mappedPoint); |
| 313 EXPECT_EQ(FloatPoint(9, 9), mappedPoint); |
| 314 |
| 315 mappedPoint = mapLocalToAncestor(html, view, mappedPoint); |
| 316 EXPECT_EQ(FloatPoint(9, 9), mappedPoint); |
| 317 } |
| 318 |
| 319 TEST_F(MapLocalToAncestorTest, MulticolWithText) |
| 320 { |
| 321 setBodyInnerHTML( |
| 322 "<div id='multicol' style='-webkit-columns:2; -webkit-column-gap:20px; w
idth:400px; line-height:50px; padding:5px;'>" |
| 323 " <br id='sibling'>" |
| 324 " text" |
| 325 "</div>"); |
| 326 |
| 327 LayoutObject* target = getLayoutObjectByElementId("sibling")->nextSibling(); |
| 328 ASSERT_TRUE(target->isText()); |
| 329 LayoutBox* flowThread = toLayoutBox(target->parent()); |
| 330 ASSERT_TRUE(flowThread->isLayoutFlowThread()); |
| 331 LayoutBox* multicol = toLayoutBox(getLayoutObjectByElementId("multicol")); |
| 332 |
| 333 FloatPoint mappedPoint = mapLocalToAncestor(target, flowThread, FloatPoint(1
0, 70)); |
| 334 EXPECT_EQ(FloatPoint(220, 20), mappedPoint); |
| 335 |
| 336 mappedPoint = mapLocalToAncestor(flowThread, multicol, mappedPoint); |
| 337 EXPECT_EQ(FloatPoint(225, 25), mappedPoint); |
| 338 } |
| 339 |
| 340 TEST_F(MapLocalToAncestorTest, MulticolWithInline) |
| 341 { |
| 342 setBodyInnerHTML( |
| 343 "<div id='multicol' style='-webkit-columns:2; -webkit-column-gap:20px; w
idth:400px; line-height:50px; padding:5px;'>" |
| 344 " <span id='target'><br>text</span>" |
| 345 "</div>"); |
| 346 |
| 347 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 348 LayoutBox* flowThread = toLayoutBox(target->parent()); |
| 349 ASSERT_TRUE(flowThread->isLayoutFlowThread()); |
| 350 LayoutBox* multicol = toLayoutBox(getLayoutObjectByElementId("multicol")); |
| 351 |
| 352 FloatPoint mappedPoint = mapLocalToAncestor(target, flowThread, FloatPoint(1
0, 70)); |
| 353 EXPECT_EQ(FloatPoint(220, 20), mappedPoint); |
| 354 |
| 355 mappedPoint = mapLocalToAncestor(flowThread, multicol, mappedPoint); |
| 356 EXPECT_EQ(FloatPoint(225, 25), mappedPoint); |
| 357 } |
| 358 |
| 359 TEST_F(MapLocalToAncestorTest, MulticolWithBlock) |
| 360 { |
| 361 setBodyInnerHTML( |
| 362 "<div id='container' style='-webkit-columns:3; -webkit-column-gap:0; col
umn-fill:auto; width:300px; height:100px; border:8px solid; padding:7px;'>" |
| 363 " <div style='height:110px;'></div>" |
| 364 " <div id='target' style='margin:10px; border:13px; padding:13px;'></
div>" |
| 365 "</div>"); |
| 366 |
| 367 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 368 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 369 |
| 370 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 371 EXPECT_EQ(FloatPoint(125, 35), mappedPoint); |
| 372 |
| 373 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 374 LayoutBox* flowThread = target->parentBox(); |
| 375 ASSERT_TRUE(flowThread->isLayoutFlowThread()); |
| 376 |
| 377 mappedPoint = mapLocalToAncestor(target, flowThread, FloatPoint()); |
| 378 EXPECT_EQ(FloatPoint(110, 20), mappedPoint); |
| 379 |
| 380 mappedPoint = mapLocalToAncestor(flowThread, container, mappedPoint); |
| 381 EXPECT_EQ(FloatPoint(125, 35), mappedPoint); |
| 382 } |
| 383 |
| 384 TEST_F(MapLocalToAncestorTest, MulticolWithAbsPosInRelPos) |
| 385 { |
| 386 setBodyInnerHTML( |
| 387 "<div id='multicol' style='-webkit-columns:3; -webkit-column-gap:0; colu
mn-fill:auto; width:300px; height:100px; border:8px solid; padding:7px;'>" |
| 388 " <div style='height:110px;'></div>" |
| 389 " <div id='relpos' style='position:relative; left:4px; top:4px;'>" |
| 390 " <div id='target' style='position:absolute; left:15px; top:15px;
margin:10px; border:13px; padding:13px;'></div>" |
| 391 " </div>" |
| 392 "</div>"); |
| 393 |
| 394 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 395 LayoutBox* multicol = toLayoutBox(getLayoutObjectByElementId("multicol")); |
| 396 |
| 397 FloatPoint mappedPoint = mapLocalToAncestor(target, multicol, FloatPoint()); |
| 398 EXPECT_EQ(FloatPoint(144, 54), mappedPoint); |
| 399 |
| 400 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 401 LayoutBox* relpos = toLayoutBox(getLayoutObjectByElementId("relpos")); |
| 402 LayoutBox* flowThread = relpos->parentBox(); |
| 403 ASSERT_TRUE(flowThread->isLayoutFlowThread()); |
| 404 |
| 405 mappedPoint = mapLocalToAncestor(target, relpos, FloatPoint()); |
| 406 EXPECT_EQ(FloatPoint(25, 25), mappedPoint); |
| 407 |
| 408 mappedPoint = mapLocalToAncestor(relpos, flowThread, mappedPoint); |
| 409 EXPECT_EQ(FloatPoint(129, 39), mappedPoint); |
| 410 |
| 411 mappedPoint = mapLocalToAncestor(flowThread, multicol, mappedPoint); |
| 412 EXPECT_EQ(FloatPoint(144, 54), mappedPoint); |
| 413 } |
| 414 |
| 415 TEST_F(MapLocalToAncestorTest, MulticolWithAbsPosNotContained) |
| 416 { |
| 417 setBodyInnerHTML( |
| 418 "<div id='container' style='position:relative; margin:666px; border:7px
solid; padding:3px;'>" |
| 419 " <div id='multicol' style='-webkit-columns:3; -webkit-column-gap:0;
column-fill:auto; width:300px; height:100px; border:8px solid; padding:7px;'>" |
| 420 " <div style='height:110px;'></div>" |
| 421 " <div id='target' style='position:absolute; left:-1px; top:-1px;
margin:10px; border:13px; padding:13px;'></div>" |
| 422 " </div>" |
| 423 "</div>"); |
| 424 |
| 425 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 426 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 427 |
| 428 // The multicol container isn't in the containing block chain of the abspos
#target. |
| 429 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 430 EXPECT_EQ(FloatPoint(16, 16), mappedPoint); |
| 431 |
| 432 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 433 LayoutBox* multicol = toLayoutBox(getLayoutObjectByElementId("multicol")); |
| 434 LayoutBox* flowThread = target->parentBox(); |
| 435 ASSERT_TRUE(flowThread->isLayoutFlowThread()); |
| 436 |
| 437 mappedPoint = mapLocalToAncestor(target, flowThread, FloatPoint()); |
| 438 EXPECT_EQ(FloatPoint(-9, -9), mappedPoint); |
| 439 |
| 440 mappedPoint = mapLocalToAncestor(flowThread, multicol, mappedPoint); |
| 441 EXPECT_EQ(FloatPoint(6, 6), mappedPoint); |
| 442 |
| 443 mappedPoint = mapLocalToAncestor(multicol, container, mappedPoint); |
| 444 EXPECT_EQ(FloatPoint(16, 16), mappedPoint); |
| 445 } |
| 446 |
| 447 TEST_F(MapLocalToAncestorTest, FlippedBlocksWritingModeWithText) |
| 448 { |
| 449 setBodyInnerHTML( |
| 450 "<div style='-webkit-writing-mode:vertical-rl;'>" |
| 451 " <div style='width:13px;'></div>" |
| 452 " <div style='width:200px; height:400px; line-height:50px;'>" |
| 453 " <br id='sibling'>text" |
| 454 " </div>" |
| 455 " <div style='width:5px;'></div>" |
| 456 "</div>"); |
| 457 |
| 458 LayoutObject* br = getLayoutObjectByElementId("sibling"); |
| 459 LayoutObject* text = br->nextSibling(); |
| 460 ASSERT_TRUE(text->isText()); |
| 461 |
| 462 // Map to the nearest container. Flipping should occur. |
| 463 FloatPoint mappedPoint = mapLocalToAncestor(text, text->containingBlock(), F
loatPoint(75, 10), ApplyContainerFlip); |
| 464 EXPECT_EQ(FloatPoint(125, 10), mappedPoint); |
| 465 |
| 466 // Map to a container further up in the tree. Flipping should still occur on
the nearest |
| 467 // container. LayoutObject::mapLocalToAncestor() is called recursively until
the ancestor is |
| 468 // reached, and the ApplyContainerFlip flag is cleared after having processe
d the innermost |
| 469 // object. |
| 470 mappedPoint = mapLocalToAncestor(text, text->containingBlock()->containingBl
ock(), FloatPoint(75, 10), ApplyContainerFlip); |
| 471 EXPECT_EQ(FloatPoint(130, 10), mappedPoint); |
| 472 |
| 473 // If the ApplyContainerFlip flag isn't specified, no flipping should take p
lace. |
| 474 mappedPoint = mapLocalToAncestor(text, text->containingBlock()->containingBl
ock(), FloatPoint(75, 10)); |
| 475 EXPECT_EQ(FloatPoint(80, 10), mappedPoint); |
| 476 } |
| 477 |
| 478 TEST_F(MapLocalToAncestorTest, FlippedBlocksWritingModeWithInline) |
| 479 { |
| 480 setBodyInnerHTML( |
| 481 "<div style='-webkit-writing-mode:vertical-rl;'>" |
| 482 " <div style='width:13px;'></div>" |
| 483 " <div style='width:200px; height:400px; line-height:50px;'>" |
| 484 " <span>" |
| 485 " <span id='target'><br>text</span>" |
| 486 " </span>" |
| 487 " </div>" |
| 488 " <div style='width:7px;'></div>" |
| 489 "</div>"); |
| 490 |
| 491 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 492 ASSERT_TRUE(target); |
| 493 |
| 494 // First map to the parent SPAN. Nothing special should happen, since flippi
ng occurs at the nearest container. |
| 495 FloatPoint mappedPoint = mapLocalToAncestor(target, toLayoutBoxModelObject(t
arget->parent()), FloatPoint(75, 10), ApplyContainerFlip); |
| 496 EXPECT_EQ(FloatPoint(75, 10), mappedPoint); |
| 497 |
| 498 // Continue to the nearest container. Flipping should occur. |
| 499 mappedPoint = mapLocalToAncestor(toLayoutBoxModelObject(target->parent()), t
arget->containingBlock(), mappedPoint, ApplyContainerFlip); |
| 500 EXPECT_EQ(FloatPoint(125, 10), mappedPoint); |
| 501 |
| 502 // Now map from the innermost inline to the nearest container in one go. |
| 503 mappedPoint = mapLocalToAncestor(target, target->containingBlock(), FloatPoi
nt(75, 10), ApplyContainerFlip); |
| 504 EXPECT_EQ(FloatPoint(125, 10), mappedPoint); |
| 505 |
| 506 // Map to a container further up in the tree. Flipping should still only occ
ur on the nearest container. |
| 507 mappedPoint = mapLocalToAncestor(target, target->containingBlock()->containi
ngBlock(), FloatPoint(75, 10), ApplyContainerFlip); |
| 508 EXPECT_EQ(FloatPoint(132, 10), mappedPoint); |
| 509 |
| 510 // If the ApplyContainerFlip flag isn't specified, no flipping should take p
lace. |
| 511 mappedPoint = mapLocalToAncestor(target, target->containingBlock()->containi
ngBlock(), FloatPoint(75, 10)); |
| 512 EXPECT_EQ(FloatPoint(82, 10), mappedPoint); |
| 513 } |
| 514 |
| 515 TEST_F(MapLocalToAncestorTest, FlippedBlocksWritingModeWithBlock) |
| 516 { |
| 517 setBodyInnerHTML( |
| 518 "<div id='container' style='-webkit-writing-mode:vertical-rl; border:8px
solid; padding:7px; width:200px; height:200px;'>" |
| 519 " <div id='middle' style='border:1px solid;'>" |
| 520 " <div style='width:30px;'></div>" |
| 521 " <div id='target' style='margin:6px; width:25px;'></div>" |
| 522 " </div>" |
| 523 "</div>"); |
| 524 |
| 525 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 526 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 527 |
| 528 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 529 EXPECT_EQ(FloatPoint(153, 22), mappedPoint); |
| 530 |
| 531 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 532 LayoutBox* middle = toLayoutBox(getLayoutObjectByElementId("middle")); |
| 533 |
| 534 mappedPoint = mapLocalToAncestor(target, middle, FloatPoint()); |
| 535 EXPECT_EQ(FloatPoint(7, 7), mappedPoint); |
| 536 |
| 537 mappedPoint = mapLocalToAncestor(middle, container, mappedPoint); |
| 538 EXPECT_EQ(FloatPoint(153, 22), mappedPoint); |
| 539 } |
| 540 |
| 541 TEST_F(MapLocalToAncestorTest, Table) |
| 542 { |
| 543 setBodyInnerHTML( |
| 544 "<style>td { padding: 2px; }</style>" |
| 545 "<div id='container' style='border:3px solid;'>" |
| 546 " <table style='margin:9px; border:5px solid; border-spacing:10px;'>" |
| 547 " <thead>" |
| 548 " <tr>" |
| 549 " <td>" |
| 550 " <div style='width:100px; height:100px;'></div>" |
| 551 " </td>" |
| 552 " </tr>" |
| 553 " </thead>" |
| 554 " <tbody>" |
| 555 " <tr>" |
| 556 " <td>" |
| 557 " <div style='width:100px; height:100px;'></div>" |
| 558 " </td>" |
| 559 " </tr>" |
| 560 " <tr>" |
| 561 " <td>" |
| 562 " <div style='width:100px; height:100px;'></div>" |
| 563 " </td>" |
| 564 " <td>" |
| 565 " <div id='target' style='width:100px; height:10px;'>
</div>" |
| 566 " </td>" |
| 567 " </tr>" |
| 568 " </tbody>" |
| 569 " </table>" |
| 570 "</div>"); |
| 571 |
| 572 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 573 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 574 |
| 575 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 576 EXPECT_EQ(FloatPoint(143, 302), mappedPoint); |
| 577 |
| 578 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 579 LayoutBox* td = target->parentBox(); |
| 580 ASSERT_TRUE(td->isTableCell()); |
| 581 mappedPoint = mapLocalToAncestor(target, td, FloatPoint()); |
| 582 // Cells are middle-aligned by default. |
| 583 EXPECT_EQ(FloatPoint(2, 47), mappedPoint); |
| 584 |
| 585 LayoutBox* tr = td->parentBox(); |
| 586 ASSERT_TRUE(tr->isTableRow()); |
| 587 mappedPoint = mapLocalToAncestor(td, tr, mappedPoint); |
| 588 EXPECT_EQ(FloatPoint(126, 47), mappedPoint); |
| 589 |
| 590 LayoutBox* tbody = tr->parentBox(); |
| 591 ASSERT_TRUE(tbody->isTableSection()); |
| 592 mappedPoint = mapLocalToAncestor(tr, tbody, mappedPoint); |
| 593 EXPECT_EQ(FloatPoint(126, 161), mappedPoint); |
| 594 |
| 595 LayoutBox* table = tbody->parentBox(); |
| 596 ASSERT_TRUE(table->isTable()); |
| 597 mappedPoint = mapLocalToAncestor(tbody, table, mappedPoint); |
| 598 EXPECT_EQ(FloatPoint(131, 290), mappedPoint); |
| 599 |
| 600 mappedPoint = mapLocalToAncestor(table, container, mappedPoint); |
| 601 EXPECT_EQ(FloatPoint(143, 302), mappedPoint); |
| 602 } |
| 603 |
| 604 static bool floatValuesAlmostEqual(float expected, float actual) |
| 605 { |
| 606 return fabs(expected - actual) < 0.01; |
| 607 } |
| 608 |
| 609 static bool floatQuadsAlmostEqual(const FloatQuad& expected, const FloatQuad& ac
tual) |
| 610 { |
| 611 return floatValuesAlmostEqual(expected.p1().x(), actual.p1().x()) |
| 612 && floatValuesAlmostEqual(expected.p1().y(), actual.p1().y()) |
| 613 && floatValuesAlmostEqual(expected.p2().x(), actual.p2().x()) |
| 614 && floatValuesAlmostEqual(expected.p2().y(), actual.p2().y()) |
| 615 && floatValuesAlmostEqual(expected.p3().x(), actual.p3().x()) |
| 616 && floatValuesAlmostEqual(expected.p3().y(), actual.p3().y()) |
| 617 && floatValuesAlmostEqual(expected.p4().x(), actual.p4().x()) |
| 618 && floatValuesAlmostEqual(expected.p4().y(), actual.p4().y()); |
| 619 } |
| 620 |
| 621 // If comparison fails, pretty-print the error using EXPECT_EQ() |
| 622 #define EXPECT_FLOAT_QUAD_EQ(expected, actual) \ |
| 623 do { \ |
| 624 if (!floatQuadsAlmostEqual(expected, actual)) { \ |
| 625 EXPECT_EQ(expected, actual); \ |
| 626 } \ |
| 627 } while (false) |
| 628 |
| 629 |
| 630 TEST_F(MapLocalToAncestorTest, Transforms) |
| 631 { |
| 632 setBodyInnerHTML( |
| 633 "<div id='container'>" |
| 634 " <div id='outerTransform' style='transform:rotate(45deg); width:200p
x; height:200px;'>" |
| 635 " <div id='innerTransform' style='transform:rotate(45deg); width:
200px; height:200px;'>" |
| 636 " <div id='target' style='width:200px; height:200px;'></div>" |
| 637 " </div>" |
| 638 " </div>" |
| 639 "</div>"); |
| 640 |
| 641 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 642 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 643 |
| 644 const FloatQuad initialQuad(FloatPoint(0, 0), FloatPoint(200, 0), FloatPoint
(200, 200), FloatPoint(0, 200)); |
| 645 FloatQuad mappedQuad = mapLocalToAncestor(target, container, initialQuad, Us
eTransforms); |
| 646 EXPECT_FLOAT_QUAD_EQ(FloatQuad(FloatPoint(200, 0), FloatPoint(200, 200), Flo
atPoint(0, 200), FloatPoint(0, 0)), mappedQuad); |
| 647 |
| 648 // Walk each ancestor in the chain separately, to verify each step on the wa
y. |
| 649 LayoutBox* innerTransform = toLayoutBox(getLayoutObjectByElementId("innerTra
nsform")); |
| 650 LayoutBox* outerTransform = toLayoutBox(getLayoutObjectByElementId("outerTra
nsform")); |
| 651 |
| 652 mappedQuad = mapLocalToAncestor(target, innerTransform, initialQuad, UseTran
sforms); |
| 653 EXPECT_FLOAT_QUAD_EQ(FloatQuad(FloatPoint(0, 0), FloatPoint(200, 0), FloatPo
int(200, 200), FloatPoint(0, 200)), mappedQuad); |
| 654 |
| 655 mappedQuad = mapLocalToAncestor(innerTransform, outerTransform, mappedQuad,
UseTransforms); |
| 656 // Clockwise rotation by 45 degrees. |
| 657 EXPECT_FLOAT_QUAD_EQ(FloatQuad(FloatPoint(100, -41.42), FloatPoint(241.42, 1
00), FloatPoint(100, 241.42), FloatPoint(-41.42, 100)), mappedQuad); |
| 658 |
| 659 mappedQuad = mapLocalToAncestor(outerTransform, container, mappedQuad, UseTr
ansforms); |
| 660 // Another clockwise rotation by 45 degrees. So now 90 degrees in total. |
| 661 EXPECT_FLOAT_QUAD_EQ(FloatQuad(FloatPoint(200, 0), FloatPoint(200, 200), Flo
atPoint(0, 200), FloatPoint(0, 0)), mappedQuad); |
| 662 } |
| 663 |
| 664 } // namespace blink |
OLD | NEW |