Ticket #3804: 3804_3.patch
File 3804_3.patch, 4.5 KB (added by , 15 years ago) |
---|
-
_source/tests/core/dom/element.html
506 506 var element = new CKEDITOR.dom.element( document.getElementsByTagName( 'small' )[0] ); 507 507 assert.isTrue( element.hasAttributes() ); 508 508 }, 509 509 510 test_getDocumentPosition : function() 511 { 512 // Assign the page location of the element. 513 YAHOO.util.Dom.setXY('DocPositionTarget', [ 350, 450 ] ); 514 var pos = CKEDITOR.document.getById( 'DocPositionTarget' ).getDocumentPosition(); 515 if ( !CKEDITOR.env.ie ) 516 { 517 assert.areEqual( 350, pos.x, 'Position coordinates:x relative to document doesn\'t match.' ); 518 assert.areEqual( 450, pos.y, 'Position coordinates:y relative to document doesn\'t match.' ); 519 } 520 else 521 { 522 assert.isTrue( pos.x == 348 || pos.x == 349, 'Position coordinates:x relative to document doesn\'t match.' ); 523 assert.areEqual( 448, pos.y, 'Position coordinates:y relative to document doesn\'t match.' ); 524 } 525 }, 526 510 527 name : document.title 511 528 }; 512 529 })() ); 513 530 514 531 //]]> 515 532 </script> 533 <style type="text/css" media="screen"> 534 #test-computed { 535 width:50%; 536 margin:auto; 537 padding:10px; 538 z-index: 2; 539 } 540 .scroll 541 { 542 overflow: visible; 543 } 544 .block1 545 { 546 width: 100%; 547 height: 100px; 548 background-color: blue; 549 text-align: center; 550 } 551 .block2 552 { 553 margin: auto; 554 width: 200px; 555 height: 200px; 556 background-color: green; 557 position : relative; 558 } 559 .block3 560 { 561 position: absolute; 562 float:right; 563 width: 300px; 564 height: 300px; 565 background-color: black; 566 } 567 .block4 568 { 569 position: absolute; 570 left: 50px; 571 right: 50px; 572 width: 400px; 573 height: 400px; 574 background-color: pink; 575 } 576 #DocPositionTarget 577 { 578 background-color: red; 579 } 580 </style> 516 581 </head> 517 582 <body> 518 583 <textarea id="test1" rows="10" cols="80"></textarea> … … 536 601 B</div> 537 602 <big>Test</big> 538 603 <small title="Testing">Test</small> 604 605 <div class="block1 scroll" id="block1"><div class="block2 scroll" id="block2"><div class="block3 scroll" id="block3"><div class="block4 scroll" id="block4"><div id="DocPositionTarget">target</div></div></div></div></div> 606 539 607 </body> 540 608 </html> -
_source/core/dom/element.js
1099 1099 getDocumentPosition : function( refDocument ) 1100 1100 { 1101 1101 var x = 0, y = 0, 1102 body = this.getDocument().getBody(); 1102 body = this.getDocument().getBody(), 1103 quirks = this.getDocument().$.compatMode == 'BackCompat'; 1103 1104 1105 var doc = this.getDocument(); 1106 1104 1107 if ( document.documentElement[ "getBoundingClientRect" ] ) 1105 1108 { 1106 1109 var box = this.$.getBoundingClientRect(), 1107 doc = this.getDocument().$, 1108 docElem = doc.documentElement, 1109 clientTop = docElem.clientTop || body.$.clientTop || 0, 1110 clientLeft = docElem.clientLeft || body.$.clientLeft || 0; 1110 $doc = doc.$, 1111 $docElem = $doc.documentElement; 1111 1112 1112 x = box.left + ( !CKEDITOR.env.quirks && docElem.scrollLeft || body.$.scrollLeft ); 1113 x -= clientLeft; 1114 y = box.top + ( !CKEDITOR.env.quirks && docElem.scrollTop || body.$.scrollTop ); 1115 y -= clientTop; 1113 var clientTop = $docElem.clientTop || body.$.clientTop || 0, 1114 clientLeft = $docElem.clientLeft || body.$.clientLeft || 0, 1115 needAdjustScrollAndBorders = true; 1116 1117 if ( CKEDITOR.env.ie ) 1118 { 1119 var inDocElem = doc.getDocumentElement().contains( this ), 1120 inBody = doc.getBody().contains( this ); 1121 1122 needAdjustScrollAndBorders = ( quirks && inBody ) || ( !quirks && inDocElem ); 1123 } 1124 1125 if ( needAdjustScrollAndBorders ) 1126 { 1127 x = box.left + ( !quirks && $docElem.scrollLeft || body.$.scrollLeft ); 1128 x -= clientLeft; 1129 y = box.top + ( !quirks && $docElem.scrollTop || body.$.scrollTop ); 1130 y -= clientTop; 1131 } 1116 1132 } 1117 1133 else 1118 1134 { … … 1161 1177 { 1162 1178 // In Firefox, we'll endup one pixel before the element positions, 1163 1179 // so we must add it here. 1164 if ( CKEDITOR.env.gecko && ! CKEDITOR.env.quirks )1180 if ( CKEDITOR.env.gecko && !quirks ) 1165 1181 { 1166 1182 x += this.$.clientLeft ? 1 : 0; 1167 1183 y += this.$.clientTop ? 1 : 0;