Scott Kostyshak wrote:

> On Mon, Jun 2, 2014 at 2:52 PM, Georg Baum
> <georg.b...@post.rwth-aachen.de> wrote:
> 
> You are correct. What I listed was the difference between Chromium
> (which does not work) and Firefox (which does work). If you want me to
> list all the MIME types, let me know.

No, I don't need that, it is enough to know that image/png is also on the 
clipboard.

>> I think it is sensible to try to detect pure image contents on the
>> clipboard, however I don't think we should hard code any browser specific
>> stuff. What I could imagine is to inspect the text/HTML further: If
>> (after cleaning) the only tag in the body is <img>, and if the clipboard
>> contains image contents as well, then ignore the HTML for pasting without
>> argument and prefer the image.
> 
> I like this idea. Where should this be done? The place where Qt is
> used to get the text is inGuiClipboard::getAsText at
> 
> case PlainTextType:
> str = qApp->clipboard()->text(QClipboard::Clipboard)
> .normalized(QString::NormalizationForm_C);
> 
> I guess the idea is we should never get to this point?

I think it needs to be done in two places: In GuiClipboard and in 
Text::dispatch() (or a new service routine called from there). The reason 
for this is that I don't want to change the behaviour of the special pasting 
methods: If somebody explicitly says he wants to paste text, then he should 
get the image link.
Attached is a sketch of the idea, without the actual HTML parsing part to 
find out whether the whole body conatins only an <img> tag, and without any 
documentation.


Georg
diff --git a/src/Text3.cpp b/src/Text3.cpp
index b78ba15..cd360bf 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -1272,15 +1272,20 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		// without argument?
 		string const arg = to_utf8(cmd.argument());
 		if (arg.empty()) {
-			bool tryGraphics = true;
+			bool tryGraphics = false;
 			if (theClipboard().isInternal())
 				pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
 			else if (theClipboard().hasTextContents()) {
-				if (pasteClipboardText(cur, bv->buffer().errorList("Paste"),
-				                       true, Clipboard::AnyTextType))
-					tryGraphics = false;
-			}
-			if (tryGraphics && theClipboard().hasGraphicsContents())
+				bool const hasGraphics = theClipboard().hasGraphicsContents();
+				if (hasGraphics &&
+				    !theClipboard().hasTextContents(Clipboard::AnyTextTypeNotOnlyImageLink))
+					tryGraphics = true;
+				else if (!pasteClipboardText(cur, bv->buffer().errorList("Paste"),
+				                             true, Clipboard::AnyTextType))
+					tryGraphics = hasGraphics;
+			} else
+				tryGraphics = theClipboard().hasGraphicsContents();
+			if (tryGraphics)
 				pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
 		} else if (isStrUnsignedInt(arg)) {
 			// we have a numerical argument
diff --git a/src/frontends/Clipboard.h b/src/frontends/Clipboard.h
index faf4e0a..0dafed6 100644
--- a/src/frontends/Clipboard.h
+++ b/src/frontends/Clipboard.h
@@ -48,6 +48,7 @@ public:
 		HtmlTextType,
 		LaTeXTextType,
 		LyXTextType,
+		AnyTextTypeNotOnlyImageLink,
 	};
 
 	/**
diff --git a/src/frontends/qt4/GuiClipboard.cpp b/src/frontends/qt4/GuiClipboard.cpp
index d96dd26..2cbd2d7 100644
--- a/src/frontends/qt4/GuiClipboard.cpp
+++ b/src/frontends/qt4/GuiClipboard.cpp
@@ -378,6 +378,7 @@ docstring const GuiClipboard::getAsText(TextType type) const
 	case AnyTextType:
 	case LyXOrPlainTextType:
 	case PlainTextType:
+	case AnyTextTypeNotOnlyImageLink:
 		str = qApp->clipboard()->text(QClipboard::Clipboard)
 				.normalized(QString::NormalizationForm_C);
 		break;
@@ -465,6 +466,8 @@ bool GuiClipboard::hasTextContents(Clipboard::TextType type) const
 	case LaTeXTextType:
 		return cache_.hasFormat(latexMimeType()) ||
 		       cache_.hasFormat(texMimeType());
+	case AnyTextTypeNotOnlyImageLink:
+		return has_text_contents_not_only_image_link_;
 	}
 	// shut up compiler
 	return false;
@@ -568,6 +571,15 @@ void GuiClipboard::on_dataChanged()
 
 	has_text_contents_ = hasTextContents();
 	has_graphics_contents_ = hasGraphicsContents();
+	has_text_contents_not_only_image_link_ = hasTextContents(LyXOrPlainTextType) ||
+		hasTextContents(LaTeXTextType);
+	if (!has_text_contents_not_only_image_link_ && hasTextContents(HtmlTextType)) {
+		QString subtype = "html";
+		QString str = qApp->clipboard()->text(subtype, QClipboard::Clipboard)
+				.normalized(QString::NormalizationForm_C);
+		str = tidyHtml(str);
+		// Now use some XML parser to find out whether <body> contains more than <img>
+	}
 }
 
 
diff --git a/src/frontends/qt4/GuiClipboard.h b/src/frontends/qt4/GuiClipboard.h
index 392f059..b0dff0c 100644
--- a/src/frontends/qt4/GuiClipboard.h
+++ b/src/frontends/qt4/GuiClipboard.h
@@ -87,6 +87,7 @@ private Q_SLOTS:
 
 private:
 	bool plaintext_clipboard_empty_;
+	bool has_text_contents_not_only_image_link_;
 	bool has_text_contents_;
 	bool has_graphics_contents_;
 	/// the cached mime data used to describe the information

Reply via email to