+ // When content doc is in standards mode, IE doesn't focus the editor when\r
+ // clicking at the region below body (on html element) content, we emulate\r
+ // the normal behavior on old IEs. (#1659, #7932)\r
+ if ( ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat )\r
+ && doc.$.compatMode != 'BackCompat' )\r
+ {\r
+ function moveRangeToPoint( range, x, y )\r
+ {\r
+ // Error prune in IE7. (#9034, #9110)\r
+ try { range.moveToPoint( x, y ); } catch ( e ) {}\r
+ }\r
+\r
+ html.on( 'mousedown', function( evt )\r
+ {\r
+ // Expand the text range along with mouse move.\r
+ function onHover( evt )\r
+ {\r
+ evt = evt.data.$;\r
+ if ( textRng )\r
+ {\r
+ // Read the current cursor.\r
+ var rngEnd = body.$.createTextRange();\r
+\r
+ moveRangeToPoint( rngEnd, evt.x, evt.y );\r
+\r
+ // Handle drag directions.\r
+ textRng.setEndPoint(\r
+ textRng.compareEndPoints( 'StartToStart', rngEnd ) < 0 ?\r
+ 'EndToEnd' :\r
+ 'StartToStart',\r
+ rngEnd );\r
+\r
+ // Update selection with new range.\r
+ textRng.select();\r
+ }\r
+ }\r
+\r
+ evt = evt.data.$;\r
+\r
+ // We're sure that the click happens at the region\r
+ // below body, but not on scrollbar.\r
+ if ( evt.y < html.$.clientHeight\r
+ && evt.y > body.$.offsetTop + body.$.clientHeight\r
+ && evt.x < html.$.clientWidth )\r
+ {\r
+ // Start to build the text range.\r
+ var textRng = body.$.createTextRange();\r
+ moveRangeToPoint( textRng, evt.x, evt.y );\r
+\r
+ html.on( 'mousemove', onHover );\r
+\r
+ html.on( 'mouseup', function( evt )\r
+ {\r
+ html.removeListener( 'mousemove', onHover );\r
+ evt.removeListener();\r
+\r
+ // Make it in effect on mouse up. (#9022)\r
+ textRng.select();\r
+ } );\r
+ }\r
+ });\r
+ }\r
+\r
+ // It's much simpler for IE8, we just need to reselect the reported range.\r
+ if ( CKEDITOR.env.ie8 )\r
+ {\r
+ html.on( 'mouseup', function( evt )\r
+ {\r
+ // The event is not fired when clicking on the scrollbars,\r
+ // so we can safely check the following to understand\r
+ // whether the empty space following <body> has been clicked.\r
+ if ( evt.data.getTarget().getName() == 'html' )\r
+ {\r
+ var sel = CKEDITOR.document.$.selection,\r
+ range = sel.createRange();\r
+ // The selection range is reported on host, but actually it should applies to the content doc.\r
+ if ( sel.type != 'None' && range.parentElement().ownerDocument == doc.$ )\r
+ range.select();\r
+ }\r
+ } );\r
+ }\r