+ // Figure out the element position relative to the specified window.\r
+ function screenPos( element, refWin )\r
+ {\r
+ var pos = { x: 0, y: 0 };\r
+\r
+ if ( !( element.is( isQuirks ? 'body' : 'html' ) ) )\r
+ {\r
+ var box = element.$.getBoundingClientRect();\r
+ pos.x = box.left, pos.y = box.top;\r
+ }\r
+\r
+ var win = element.getWindow();\r
+ if ( !win.equals( refWin ) )\r
+ {\r
+ var outerPos = screenPos( CKEDITOR.dom.element.get( win.$.frameElement ), refWin );\r
+ pos.x += outerPos.x, pos.y += outerPos.y;\r
+ }\r
+\r
+ return pos;\r
+ }\r
+\r
+ // calculated margin size.\r
+ function margin( element, side )\r
+ {\r
+ return parseInt( element.getComputedStyle( 'margin-' + side ) || 0, 10 ) || 0;\r
+ }\r
+\r
+ var win = parent.getWindow();\r
+\r
+ var thisPos = screenPos( this, win ),\r
+ parentPos = screenPos( parent, win ),\r
+ eh = this.$.offsetHeight,\r
+ ew = this.$.offsetWidth,\r
+ ch = parent.$.clientHeight,\r
+ cw = parent.$.clientWidth,\r
+ lt,\r
+ br;\r
+\r
+ // Left-top margins.\r
+ lt =\r
+ {\r
+ x : thisPos.x - margin( this, 'left' ) - parentPos.x || 0,\r
+ y : thisPos.y - margin( this, 'top' ) - parentPos.y|| 0\r
+ };\r
+\r
+ // Bottom-right margins.\r
+ br =\r
+ {\r
+ x : thisPos.x + ew + margin( this, 'right' ) - ( ( parentPos.x ) + cw ) || 0,\r
+ y : thisPos.y + eh + margin( this, 'bottom' ) - ( ( parentPos.y ) + ch ) || 0\r
+ };\r
+\r
+ // 1. Do the specified alignment as much as possible;\r
+ // 2. Otherwise be smart to scroll only the minimum amount;\r
+ // 3. Never cut at the top;\r
+ // 4. DO NOT scroll when already visible.\r
+ if ( lt.y < 0 || br.y > 0 )\r
+ {\r
+ scrollBy( 0,\r
+ alignToTop === true ? lt.y :\r
+ alignToTop === false ? br.y :\r
+ lt.y < 0 ? lt.y : br.y );\r
+ }\r