Skip to content
Permalink
Browse files

Merge branch 't/10438' into major

  • Loading branch information...
Reinmar committed May 21, 2013
2 parents e2e0049 + 260015a commit b83e32f7b2c706a42594ee5d7983c441ca38b576
Showing with 81 additions and 59 deletions.
  1. +81 −19 core/selection.js
  2. +0 −40 plugins/wysiwygarea/plugin.js
@@ -179,6 +179,44 @@
}
}

// Read the comments in selection constructor.
function fixInitialSelection( root, nativeSel, doFocus ) {
// It may happen that setting proper selection will
// cause focus to be fired (even without actually focusing root).
// Cancel it because focus shouldn't be fired when retriving selection. (#10115)
var listener = root.on( 'focus', function( evt ) {
evt.cancel();
}, null, null, -100 );

// FF && Webkit.
if ( !CKEDITOR.env.ie ) {
var range = new CKEDITOR.dom.range( root );
range.moveToElementEditStart( root );

var nativeRange = root.getDocument().$.createRange();
nativeRange.setStart( range.startContainer.$, range.startOffset );
nativeRange.collapse( 1 );

nativeSel.removeAllRanges();
nativeSel.addRange( nativeRange );
}
else {
// IE in specific case may also fire selectionchange.
// We cannot block bubbling selectionchange, so at least we
// can prevent from falling into inf recursion caused by fix for #9699
// (see wysiwygarea plugin).
// http://dev.ckeditor.com/ticket/10438#comment:13
var listener2 = root.getDocument().on( 'selectionchange', function( evt ) {
evt.cancel();
}, null, null, -100 );
}

doFocus && root.focus();

listener.removeListener();
listener2 && listener2.removeListener();
}

// Setup all editor instances for the necessary selection hooks.
CKEDITOR.on( 'instanceCreated', function( ev ) {
var editor = ev.editor;
@@ -695,9 +733,11 @@
* is restrained to, only selection spans within the target element is considered as valid.
*/
CKEDITOR.dom.selection = function( target ) {
var isElement = target instanceof CKEDITOR.dom.element;
var isElement = target instanceof CKEDITOR.dom.element,
root;

this.document = target instanceof CKEDITOR.dom.document ? target : target.getDocument();
this.root = isElement ? target : this.document.getBody();
this.root = root = isElement ? target : this.document.getBody();
this.isLocked = 0;
this._ = {
cache: {}
@@ -707,24 +747,46 @@
// on the editable element while still having no selection
// available. We normalize it here by replicating the
// behavior of other browsers.
//
// Webkit's condition covers also the case when editable hasn't been focused
// at all. Thanks to this hack Webkit always has selection in the right place.
//
// On FF and IE we only fix the first case, when editable was activated
// but the selection is broken - usually this happens after setData if editor was focused.

var sel = isMSSelection ? this.document.$.selection : this.document.getWindow().$.getSelection();

if ( CKEDITOR.env.webkit ) {
var sel = this.document.getWindow().$.getSelection();
if ( sel.type == 'None' && this.document.getActive().equals( this.root ) || sel.type == 'Caret' && sel.anchorNode.nodeType == CKEDITOR.NODE_DOCUMENT ) {
var range = new CKEDITOR.dom.range( this.root );
range.moveToPosition( this.root, CKEDITOR.POSITION_AFTER_START );
var nativeRange = this.document.$.createRange();
nativeRange.setStart( range.startContainer.$, range.startOffset );
nativeRange.collapse( 1 );

// It may happen that setting proper selection will
// cause focus to be fired. Cancel it because focus
// shouldn't be fired when retriving selection. (#10115)
var listener = this.root.on( 'focus', function( evt ) {
evt.cancel();
}, null, null, -100 );
sel.addRange( nativeRange );
listener.removeListener();
if ( sel.type == 'None' && this.document.getActive().equals( root ) || sel.type == 'Caret' && sel.anchorNode.nodeType == CKEDITOR.NODE_DOCUMENT )
fixInitialSelection( root, sel );
}
else if ( CKEDITOR.env.gecko ) {
if ( sel && this.document.getActive().equals( root ) &&
sel.anchorNode && sel.anchorNode.nodeType == CKEDITOR.NODE_DOCUMENT )
fixInitialSelection( root, sel, true );
}
else if ( CKEDITOR.env.ie ) {
var active;

// IE8,9 throw unspecified error when trying to access document.$.activeElement.
try {
active = this.document.getActive();
} catch ( e ) {}

// IEs 9+.
if ( !isMSSelection ) {
var anchorNode = sel && sel.anchorNode;

if ( anchorNode )
anchorNode = new CKEDITOR.dom.node( anchorNode );

if ( active && active.equals( this.document.getDocumentElement() ) &&
anchorNode && ( root.equals( anchorNode ) || root.contains( anchorNode ) ) )
fixInitialSelection( root, null, true );
}
// IEs 7&8.
else if ( sel.type == 'None' && active && active.equals( this.document.getDocumentElement() ) )
fixInitialSelection( root, null, true );
}

// Check whether browser focus is really inside of the editable element.
@@ -749,7 +811,7 @@
}

// Selection out of concerned range, empty the selection.
if ( !( rangeParent && ( this.root.equals( rangeParent ) || this.root.contains( rangeParent ) ) ) ) {
if ( !( rangeParent && ( root.equals( rangeParent ) || root.contains( rangeParent ) ) ) ) {
this._.cache.type = CKEDITOR.SELECTION_NONE;
this._.cache.startElement = null;
this._.cache.selectedElement = null;
@@ -187,10 +187,6 @@
});
}

// Gecko needs a key event to 'wake up' editing when the document is
// empty. (#3864, #5781)
CKEDITOR.env.gecko && CKEDITOR.tools.setTimeout( activateEditing, 0, this, editor );

// ## START : disableNativeTableHandles and disableObjectResizing settings.

// Enable dragging of position:absolute elements in IE.
@@ -530,42 +526,6 @@
}, 0 );
}

function activateEditing( editor ) {
if ( editor.readOnly )
return;

var win = editor.window,
doc = editor.document,
body = doc.getBody(),
bodyFirstChild = body.getFirst(),
bodyChildsNum = body.getChildren().count();

if ( !bodyChildsNum || bodyChildsNum == 1 && bodyFirstChild.type == CKEDITOR.NODE_ELEMENT && bodyFirstChild.hasAttribute( '_moz_editor_bogus_node' ) ) {
restoreDirty( editor );

// Memorize scroll position to restore it later (#4472).
var hostDocument = CKEDITOR.document;
var hostDocumentElement = hostDocument.getDocumentElement();
var scrollTop = hostDocumentElement.$.scrollTop;
var scrollLeft = hostDocumentElement.$.scrollLeft;

// Simulating keyboard character input by dispatching a keydown of white-space text.
var keyEventSimulate = doc.$.createEvent( "KeyEvents" );
keyEventSimulate.initKeyEvent( 'keypress', true, true, win.$, false, false, false, false, 0, 32 );
doc.$.dispatchEvent( keyEventSimulate );

if ( scrollTop != hostDocumentElement.$.scrollTop || scrollLeft != hostDocumentElement.$.scrollLeft )
hostDocument.getWindow().$.scrollTo( scrollLeft, scrollTop );

// Restore the original document status by placing the cursor before a bogus br created (#5021).
bodyChildsNum && body.getFirst().remove();
doc.getBody().appendBogus();
var nativeRange = editor.createRange();
nativeRange.setStartAt( body, CKEDITOR.POSITION_AFTER_START );
nativeRange.select();
}
}

function iframeCssFixes() {
var css = [];

0 comments on commit b83e32f

Please sign in to comment.
You can’t perform that action at this time.