Skip to content

Commit

Permalink
Merge branch 't/13879'
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand committed Nov 4, 2015
2 parents 0f9d081 + a27c239 commit 0f7494b
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 19 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
@@ -1,4 +1,4 @@
CKEditor 4 Changelog
CKEditor 4 Changelog
====================

## CKEditor 4.5.5
Expand All @@ -12,6 +12,7 @@ Fixed Issues:
* [#13887](https://dev.ckeditor.com/ticket/13887): Fixed: Link target now supports wider ASCII character range. Thanks to [SamZiemer](https://github.com/SamZiemer)!
* [#13790](https://dev.ckeditor.com/ticket/13790): Fixed: Allow for the iframe having been removed already. Thanks to [Stefan Rijnhart](https://github.com/StefanRijnhart)!
* [#13803](https://dev.ckeditor.com/ticket/13803): Fixed: Allow the editor to be destroyed before being fully initialized. Thanks to [Cyril Fluck](https://github.com/cyril-sf)!
* [#13879](http://dev.ckeditor.com/ticket/13879): Fixed: Preventing [`editor.drop`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-drop) event.
* [#12848](http://dev.ckeditor.com/ticket/12848): Fixed: Opening find dialog in [read-only](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-property-readOnly) mode will no longer throw an exception.
* [#12189](http://dev.ckeditor.com/ticket/12189): Fixed: Link plugin dialog does not display subject of email links if subject parameter is not lowercase.
* [#13361](http://dev.ckeditor.com/ticket/13361): Fixed: Images fail when site path includes parentheses because background-image path needs single-quotes around URL value.
Expand Down
9 changes: 7 additions & 2 deletions plugins/clipboard/plugin.js
@@ -1,4 +1,4 @@
/**
/**
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/
Expand Down Expand Up @@ -1340,6 +1340,11 @@
// -------------- DROP --------------

editable.attachListener( dropTarget, 'drop', function( evt ) {
// Do nothing if event was already prevented. (#13879)
if ( evt.data.$.defaultPrevented ) {
return;
}

// Cancel native drop.
evt.data.preventDefault();

Expand All @@ -1364,7 +1369,7 @@

// Fire drop.
fireDragEvent( evt, dragRange, dropRange );
} );
}, null, null, 9999 );

// Create dataTransfer or get it, if it was created before.
editable.attachListener( editor, 'drop', clipboard.initDragDataTransfer, clipboard, null, 1 );
Expand Down
59 changes: 43 additions & 16 deletions tests/plugins/clipboard/drop.js
Expand Up @@ -90,23 +90,26 @@ function drop( editor, evt, config, onDrop, onFinish ) {

finishListener = function() {
resume( function() {
// Drop event asserts
assert.areSame( 1, values.dropEventCounter, 'There should be always one drop.' );
assert.isTrue( values.dropInstanceOfDataTransfer, 'On drop: dropEvt.data.dataTransfer should be instance of dataTransfer.' );
if ( config.expectedText && isCustomDataTypesSupported ) {
assert.areSame( config.expectedText, values.dropDataText, 'On drop: text data should match.' );
}
if ( config.expectedHtml ) {
// isInnerHtmlMatching remove space from the end of strings we compare, adding 'x' fix this problem.
assert.isInnerHtmlMatching( 'x' + config.expectedHtml + 'x', 'x' + values.dropDataHtml + 'x', 'On drop: HTML data should match.' );
}
assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start container should match.' );
assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start offset should match.' );
if ( !config.expectedDropPrevented ) {
// Drop event asserts
assert.areSame( 1, values.dropEventCounter, 'There should be always one drop.' );

assert.isTrue( values.dropInstanceOfDataTransfer, 'On drop: dropEvt.data.dataTransfer should be instance of dataTransfer.' );
if ( config.expectedText && isCustomDataTypesSupported ) {
assert.areSame( config.expectedText, values.dropDataText, 'On drop: text data should match.' );
}
if ( config.expectedHtml ) {
// isInnerHtmlMatching remove space from the end of strings we compare, adding 'x' fix this problem.
assert.isInnerHtmlMatching( 'x' + config.expectedHtml + 'x', 'x' + values.dropDataHtml + 'x', 'On drop: HTML data should match.' );
}
assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start container should match.' );
assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start offset should match.' );

assert.isTrue( values.dropNativeEventMatch, 'On drop: native event should match.' );
// Check that it's the mocked drop target created by the mockDropEvent().
assert.areSame( CKEDITOR.NODE_TEXT, values.dropTarget.type, 'On drop: drop target node type should match.' );
assert.areSame( 'targetMock', values.dropTarget.getText(), 'On drop: drop target should match.' );
assert.isTrue( values.dropNativeEventMatch, 'On drop: native event should match.' );
// Check that it's the mocked drop target created by the mockDropEvent().
assert.areSame( CKEDITOR.NODE_TEXT, values.dropTarget.type, 'On drop: drop target node type should match.' );
assert.areSame( 'targetMock', values.dropTarget.getText(), 'On drop: drop target should match.' );
}

// Paste event asserts
assert.areSame( expectedBeforePasteEventCount, values.beforePasteEventCounter, 'Before paste event should be called ' + expectedBeforePasteEventCount + ' time(s).' );
Expand Down Expand Up @@ -630,6 +633,30 @@ var testsForMultipleEditor = {
}, function() {
assert.areSame( '<p class="p">^foo</p>', bender.tools.getHtmlWithSelection( editor ), 'after drop' );
} );
},

// #13879
'test prevent drop': function( editor, bot ) {
var evt = bender.tools.mockDropEvent();

// Simulate calling evt.data.preventDefault.
evt.$.defaultPrevented = true;

bot.setHtmlWithSelection( '<p class="p">^foo</p>' );
editor.resetUndo();

drag( editor, evt );

drop( editor, evt, {
dropContainer: editor.editable().findOne( '.p' ).getChild( 0 ),
dropOffset: 0,
expectedPasteEventCount: 0,
expectedDropPrevented: true
}, function() {
return true;
}, function() {
assert.areSame( '<p class="p">^foo</p>', bender.tools.getHtmlWithSelection( editor ), 'after drop' );
} );
}
},
testsForOneEditor = {
Expand Down
36 changes: 36 additions & 0 deletions tests/plugins/clipboard/manual/preventdrop.html
@@ -0,0 +1,36 @@
<head>
<style type="text/css">
h2 {
margin: 10px 0px 4px 0px;
padding: 0;
font-size: 14px;
}
</style>
</head>
<div>
<h2>Helpers</h2>
<div id="helpers">
<textarea style="width:49%; height:50px; float: left;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In commodo vulputate tempor. Sed <b>at</b> elit.</textarea>
<div style="width:49%; height:50px; float: right;">
<img height="40" alt="CKEditor logo" src="%BASE_PATH%_assets/logo.png" />
</div>
<div style="clear:both;"></div>
</div>
</div>
<div>
<h2>Editor</h2>
<div id="editor">
<p>I'm working!</p>
</div>
</div>
<script>
CKEDITOR.replace( 'editor', {
on: {
instanceReady: function( evt ) {
evt.editor.document.on( 'drop', function( evt ) {
evt.data.preventDefault();
} );
}
}
} );
</script>
9 changes: 9 additions & 0 deletions tests/plugins/clipboard/manual/preventdrop.md
@@ -0,0 +1,9 @@
@bender-ui: collapsed
@bender-tags: 4.5.5, tc, 13879, clipboard
@bender-ckeditor-plugins: clipboard, wysiwygarea, toolbar, image2

1. Drag and drop text into the editor.
2. Drag and drop image into the editor.

**Expected:**
* Text and image aren't pasted into the editor.

0 comments on commit 0f7494b

Please sign in to comment.