+ // When content doc is in standards mode, IE doesn't produce text selection\r
+ // when click on the region outside of body, we emulate\r
+ // the correct behavior here. (#1659, #7932, # 9097)\r
+ if ( doc.$.compatMode != 'BackCompat' )\r
+ {\r
+ if ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat )\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
+ startRng.compareEndPoints( 'StartToStart', rngEnd ) < 0 ?\r
+ 'EndToEnd' :\r
+ 'StartToStart',\r
+ rngEnd );\r
+\r
+ // Update selection with new range.\r
+ textRng.select();\r
+ }\r
+ }\r
+\r
+ function removeListeners()\r
+ {\r
+ outerDoc.removeListener( 'mouseup', onSelectEnd );\r
+ html.removeListener( 'mouseup', onSelectEnd );\r
+ }\r
+\r
+ function onSelectEnd()\r
+ {\r
+\r
+ html.removeListener( 'mousemove', onHover );\r
+ removeListeners();\r
+\r
+ // Make it in effect on mouse up. (#9022)\r
+ textRng.select();\r
+ }\r
+\r
+ evt = evt.data;\r
+\r
+ // We're sure that the click happens at the region\r
+ // outside body, but not on scrollbar.\r
+ if ( evt.getTarget().is( 'html' ) &&\r
+ evt.$.x < html.$.clientWidth &&\r
+ evt.$.y < html.$.clientHeight )\r
+ {\r
+ // Start to build the text range.\r
+ var textRng = body.$.createTextRange();\r
+ moveRangeToPoint( textRng, evt.$.x, evt.$.y );\r
+ // Records the dragging start of the above text range.\r
+ var startRng = textRng.duplicate();\r
+\r
+ html.on( 'mousemove', onHover );\r
+ outerDoc.on( 'mouseup', onSelectEnd );\r
+ html.on( 'mouseup', onSelectEnd );\r
+ }\r
+ });\r
+ }\r