Index: /CKEditor/branches/features/pasting/_source/plugins/clipboard/plugin.js
===================================================================
--- /CKEditor/branches/features/pasting/_source/plugins/clipboard/plugin.js	(revision 4205)
+++ /CKEditor/branches/features/pasting/_source/plugins/clipboard/plugin.js	(revision 4206)
@@ -127,5 +127,9 @@
 				if ( editor.fire( 'beforePaste' ) )
 					event.cancel();
-
+				// Simulate native 'paste' event for Opera/Firefox2. 
+				else if( CKEDITOR.env.opera 
+						 || CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
+					editor.document.getBody().fire( 'paste' );
+					
 				setTimeout( function()
 					{
@@ -148,4 +152,72 @@
 	};
 
+	// Allow to peek clipboard content by redirecting the
+	// pasting content into a temporary bin and grab the content of it.
+	function getPasteBin( evt, callback ) {
+
+		var doc = this.document;
+
+		// Avoid recursions on 'paste' event for IE.
+		if( CKEDITOR.env.ie && doc.getById( 'cke_pastebin' ) )
+			return;
+
+		var sel = this.getSelection(),
+			range = new CKEDITOR.dom.range( doc );
+
+		// Create container to paste into
+		var pastebin = CKEDITOR.dom.element.createFromHtml( '<div id="cke_pastebin">&nbsp;</div>', doc );
+		doc.getBody().append( pastebin );
+
+		// Position the bin exactly at the position of the selected element
+		// to avoid any subsequent document scroll.
+		var position = sel.getStartElement().getDocumentPosition();
+		pastebin.setStyles( {
+			position : 'absolute',
+			left : '-1000px',
+			top : position.y + 'px',
+			width : '1px',
+			height : '1px',
+			overflow : 'hidden'
+		} );
+
+		if ( CKEDITOR.env.ie )
+		{
+			// Select the container
+			var ieRange = doc.getBody().$.createTextRange();
+			ieRange.moveToElementText( pastebin.$ );
+			// Re-direct the paste target, will fire another 'paste' event.
+			ieRange.execCommand( 'Paste' );
+			pastebin.remove();
+			evt.data.preventDefault();
+			callback( pastebin );
+		}
+		else
+		{
+			var bms = sel.createBookmarks();
+			range.selectNodeContents( pastebin );
+			range.select();
+			// Wait a while and grab the pasted contents
+			window.setTimeout( function() {
+
+				pastebin.remove();
+
+				// Grab the HTML contents
+				// We need to look for a apple style wrapper on webkit it also adds a div wrapper if you copy/paste the body of the editor.
+				// Remove hidden div and restore selection
+				var bogusSpan;
+				pastebin = ( CKEDITOR.env.webkit
+						 && ( bogusSpan = pastebin.getFirst() )
+						 && ( bogusSpan.is && bogusSpan.hasClass( 'Apple-style-span' ) ) ?
+						  bogusSpan : pastebin );
+
+				// Restore the old selection
+				sel.selectBookmarks( bms );
+				callback( pastebin );
+
+			}, 0 );
+		}
+	};
+
+
 	// Register the plugin.
 	CKEDITOR.plugins.add( 'clipboard',
@@ -153,4 +225,10 @@
 			init : function( editor )
 			{
+				// Provide default 'html' paste handler. 
+				editor.on( 'paste', function( evt )
+				{
+					editor.insertHtml( evt.data[ 'html' ] );
+				} );
+
 				function addButtonCommand( buttonName, commandName, command, ctxMenuOrder )
 				{
@@ -185,4 +263,25 @@
 				editor.on( 'key', onKey, editor );
 
+				if( editor.config.autoDetectPaste )
+					editor.on( 'contentDom', function()
+					{
+						var body = editor.document.getBody();
+						body.on( 'paste', function( evt )
+						{
+							getPasteBin.call( editor, evt, function ( pasteBin )
+							{
+								var html = pasteBin.getHtml(),
+									dataTransfer =
+									{
+										'html' : html
+									};
+								
+								editor.fire( 'paste', dataTransfer );
+								editor.fire( 'saveSnapshot' );		// Save after paste
+							} );
+						} );
+
+					} );
+
 				// If the "contextmenu" plugin is loaded, register the listeners.
 				if ( editor.contextMenu )
@@ -207,2 +306,12 @@
 		});
 })();
+
+/**
+ * Whether to automatically choose the right format when pasting based on the
+ * detection of content text OR just leave it to the browser's default paste behavior.
+ * @type Boolean
+ * @default true
+ * @example
+ * config.autoDetectPaste = false;
+ */
+CKEDITOR.config.autoDetectPaste = true;
Index: /CKEditor/branches/features/pasting/_source/plugins/pastefromword/dialogs/pastefromword.js
===================================================================
--- /CKEditor/branches/features/pasting/_source/plugins/pastefromword/dialogs/pastefromword.js	(revision 4205)
+++ /CKEditor/branches/features/pasting/_source/plugins/pastefromword/dialogs/pastefromword.js	(revision 4206)
@@ -28,121 +28,4 @@
 				+ '};'
 				+ '</script><style>body { margin: 3px; height: 95%; } </style><body></body>',
-		cleanWord : function( editor, html, ignoreFont, removeStyles )
-		{
-			// Remove comments [SF BUG-1481861].
-			html = html.replace(/<\!--[\s\S]*?-->/g, '' ) ;
-
-			html = html.replace(/<o:p>\s*<\/o:p>/g, '') ;
-			html = html.replace(/<o:p>[\s\S]*?<\/o:p>/g, '&nbsp;') ;
-
-			// Remove mso-xxx styles.
-			html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ;
-
-			// Remove margin styles.
-			html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*;/gi, '' ) ;
-			html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*"/gi, "\"" ) ;
-
-			html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, '' ) ;
-			html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;
-
-			html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
-
-			html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;
-
-			html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;
-
-			html = html.replace( /\s*tab-stops:[^;"]*;?/gi, '' ) ;
-			html = html.replace( /\s*tab-stops:[^"]*/gi, '' ) ;
-
-			// Remove FONT face attributes.
-			if ( ignoreFont )
-			{
-				html = html.replace( /\s*face="[^"]*"/gi, '' ) ;
-				html = html.replace( /\s*face=[^ >]*/gi, '' ) ;
-
-				html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, '' ) ;
-			}
-
-			// Remove Class attributes
-			html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
-
-			// Remove styles.
-			if ( removeStyles )
-				html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
-
-			// Remove style, meta and link tags
-			html = html.replace( /<STYLE[^>]*>[\s\S]*?<\/STYLE[^>]*>/gi, '' ) ;
-			html = html.replace( /<(?:META|LINK)[^>]*>\s*/gi, '' ) ;
-
-			// Remove empty styles.
-			html =  html.replace( /\s*style="\s*"/gi, '' ) ;
-
-			html = html.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;
-
-			html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;
-
-			// Remove Lang attributes
-			html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
-
-			html = html.replace( /<SPAN\s*>([\s\S]*?)<\/SPAN>/gi, '$1' ) ;
-
-			html = html.replace( /<FONT\s*>([\s\S]*?)<\/FONT>/gi, '$1' ) ;
-
-			// Remove XML elements and declarations
-			html = html.replace(/<\\?\?xml[^>]*>/gi, '' ) ;
-
-			// Remove w: tags with contents.
-			html = html.replace( /<w:[^>]*>[\s\S]*?<\/w:[^>]*>/gi, '' ) ;
-
-			// Remove Tags with XML namespace declarations: <o:p><\/o:p>
-			html = html.replace(/<\/?\w+:[^>]*>/gi, '' ) ;
-
-			html = html.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;
-
-			html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;
-
-			// Remove "display:none" tags.
-			html = html.replace( /<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none[\s\S]*?<\/\1>/ig, '' ) ;
-
-			// Remove language tags
-			html = html.replace( /<(\w[^>]*) language=([^ |>]*)([^>]*)/gi, "<$1$3") ;
-
-			// Remove onmouseover and onmouseout events (from MS Word comments effect)
-			html = html.replace( /<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi, "<$1$3") ;
-			html = html.replace( /<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi, "<$1$3") ;
-
-			if ( editor.config.pasteFromWordKeepsStructure )
-			{
-				// The original <Hn> tag send from Word is something like this: <Hn style="margin-top:0px;margin-bottom:0px">
-				html = html.replace( /<H(\d)([^>]*)>/gi, '<h$1>' ) ;
-
-				// Word likes to insert extra <font> tags, when using MSIE. (Wierd).
-				html = html.replace( /<(H\d)><FONT[^>]*>([\s\S]*?)<\/FONT><\/\1>/gi, '<$1>$2<\/$1>' );
-				html = html.replace( /<(H\d)><EM>([\s\S]*?)<\/EM><\/\1>/gi, '<$1>$2<\/$1>' );
-			}
-			else
-			{
-				html = html.replace( /<H1([^>]*)>/gi, '<div$1><b><font size="6">' ) ;
-				html = html.replace( /<H2([^>]*)>/gi, '<div$1><b><font size="5">' ) ;
-				html = html.replace( /<H3([^>]*)>/gi, '<div$1><b><font size="4">' ) ;
-				html = html.replace( /<H4([^>]*)>/gi, '<div$1><b><font size="3">' ) ;
-				html = html.replace( /<H5([^>]*)>/gi, '<div$1><b><font size="2">' ) ;
-				html = html.replace( /<H6([^>]*)>/gi, '<div$1><b><font size="1">' ) ;
-
-				html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ;
-
-				// Transform <P> to <DIV>
-				var re = new RegExp( '(<P)([^>]*>[\\s\\S]*?)(<\/P>)', 'gi' ) ;	// Different because of a IE 5.0 error
-				html = html.replace( re, '<div$2<\/div>' ) ;
-
-				// Remove empty tags (three times, just to be sure).
-				// This also removes any empty anchor
-				html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
-				html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
-				html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
-			}
-
-			return html ;
-		},
 		onShow : function()
 		{
@@ -214,4 +97,5 @@
 			}
 		},
+		cleanWord : CKEDITOR.plugins.pastefromword.cleanWord,
 		onOk : function()
 		{
@@ -304,3 +188,3 @@
 		]
 	};
-} );
+	} );
Index: /CKEditor/branches/features/pasting/_source/plugins/pastefromword/plugin.js
===================================================================
--- /CKEditor/branches/features/pasting/_source/plugins/pastefromword/plugin.js	(revision 4205)
+++ /CKEditor/branches/features/pasting/_source/plugins/pastefromword/plugin.js	(revision 4206)
@@ -10,4 +10,6 @@
 		// Register the command.
 		editor.addCommand( 'pastefromword', new CKEDITOR.dialogCommand( 'pastefromword' ) );
+		// Register the dialog.
+		CKEDITOR.dialog.add( 'pastefromword', this.path + 'dialogs/pastefromword.js' );
 
 		// Register the toolbar button.
@@ -18,8 +20,147 @@
 			} );
 
-		// Register the dialog.
-		CKEDITOR.dialog.add( 'pastefromword', this.path + 'dialogs/pastefromword.js' );
+		var config = editor.config;
+		editor.on( 'paste', function( evt )
+		{
+			var mswordHtml;
+			// MS-WORD format sniffing.
+			if ( ( mswordHtml = evt.data[ 'html' ] )
+				 && /(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/.test( mswordHtml ) )
+			{
+				// Perform cleaning with default configuration.
+				editor.insertHtml(
+					CKEDITOR.plugins.pastefromword.cleanWord(
+						editor, mswordHtml,
+						config.pasteFromWordIgnoreFontFace,
+						config.pasteFromWordRemoveStyle));
+
+				// Cancel other html paste handlers.
+				evt.cancel();
+			}
+		}, null, null, 9 );
+
 	}
 } );
+
+CKEDITOR.plugins.pastefromword =
+{
+	cleanWord : function( editor, html, ignoreFont, removeStyles )
+	{
+		// Remove comments [SF BUG-1481861].
+		html = html.replace(/<\!--[\s\S]*?-->/g, '' ) ;
+
+		html = html.replace(/<o:p>\s*<\/o:p>/g, '') ;
+		html = html.replace(/<o:p>[\s\S]*?<\/o:p>/g, '&nbsp;') ;
+
+		// Remove mso-xxx styles.
+		html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ;
+
+		// Remove margin styles.
+		html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*;/gi, '' ) ;
+		html = html.replace( /\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*"/gi, "\"" ) ;
+
+		html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, '' ) ;
+		html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;
+
+		html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
+
+		html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;
+
+		html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;
+
+		html = html.replace( /\s*tab-stops:[^;"]*;?/gi, '' ) ;
+		html = html.replace( /\s*tab-stops:[^"]*/gi, '' ) ;
+
+		// Remove FONT face attributes.
+		if ( ignoreFont )
+		{
+			html = html.replace( /\s*face="[^"]*"/gi, '' ) ;
+			html = html.replace( /\s*face=[^ >]*/gi, '' ) ;
+
+			html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, '' ) ;
+		}
+
+		// Remove Class attributes
+		html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
+
+		// Remove styles.
+		if ( removeStyles )
+			html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
+
+		// Remove style, meta and link tags
+		html = html.replace( /<STYLE[^>]*>[\s\S]*?<\/STYLE[^>]*>/gi, '' ) ;
+		html = html.replace( /<(?:META|LINK)[^>]*>\s*/gi, '' ) ;
+
+		// Remove empty styles.
+		html =  html.replace( /\s*style="\s*"/gi, '' ) ;
+
+		html = html.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;
+
+		html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;
+
+		// Remove Lang attributes
+		html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
+
+		html = html.replace( /<SPAN\s*>([\s\S]*?)<\/SPAN>/gi, '$1' ) ;
+
+		html = html.replace( /<FONT\s*>([\s\S]*?)<\/FONT>/gi, '$1' ) ;
+
+		// Remove XML elements and declarations
+		html = html.replace(/<\\?\?xml[^>]*>/gi, '' ) ;
+
+		// Remove w: tags with contents.
+		html = html.replace( /<w:[^>]*>[\s\S]*?<\/w:[^>]*>/gi, '' ) ;
+
+		// Remove Tags with XML namespace declarations: <o:p><\/o:p>
+		html = html.replace(/<\/?\w+:[^>]*>/gi, '' ) ;
+
+		html = html.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;
+
+		html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;
+
+		// Remove "display:none" tags.
+		html = html.replace( /<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none[\s\S]*?<\/\1>/ig, '' ) ;
+
+		// Remove language tags
+		html = html.replace( /<(\w[^>]*) language=([^ |>]*)([^>]*)/gi, "<$1$3") ;
+
+		// Remove onmouseover and onmouseout events (from MS Word comments effect)
+		html = html.replace( /<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi, "<$1$3") ;
+		html = html.replace( /<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi, "<$1$3") ;
+
+		if ( editor.config.pasteFromWordKeepsStructure )
+		{
+			// The original <Hn> tag send from Word is something like this: <Hn style="margin-top:0px;margin-bottom:0px">
+			html = html.replace( /<H(\d)([^>]*)>/gi, '<h$1>' ) ;
+
+			// Word likes to insert extra <font> tags, when using MSIE. (Wierd).
+			html = html.replace( /<(H\d)><FONT[^>]*>([\s\S]*?)<\/FONT><\/\1>/gi, '<$1>$2<\/$1>' );
+			html = html.replace( /<(H\d)><EM>([\s\S]*?)<\/EM><\/\1>/gi, '<$1>$2<\/$1>' );
+		}
+		else
+		{
+			html = html.replace( /<H1([^>]*)>/gi, '<div$1><b><font size="6">' ) ;
+			html = html.replace( /<H2([^>]*)>/gi, '<div$1><b><font size="5">' ) ;
+			html = html.replace( /<H3([^>]*)>/gi, '<div$1><b><font size="4">' ) ;
+			html = html.replace( /<H4([^>]*)>/gi, '<div$1><b><font size="3">' ) ;
+			html = html.replace( /<H5([^>]*)>/gi, '<div$1><b><font size="2">' ) ;
+			html = html.replace( /<H6([^>]*)>/gi, '<div$1><b><font size="1">' ) ;
+
+			html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ;
+
+			// Transform <P> to <DIV>
+			var re = new RegExp( '(<P)([^>]*>[\\s\\S]*?)(<\/P>)', 'gi' ) ;	// Different because of a IE 5.0 error
+			html = html.replace( re, '<div$2<\/div>' ) ;
+
+			// Remove empty tags (three times, just to be sure).
+			// This also removes any empty anchor
+			html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
+			html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
+			html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
+		}
+
+		return html ;
+	}
+}
 
 /**
