Implement GetSelectedHTML for the ie and gtk webkit backends and document.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68226 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Steve Lamerton
2011-07-11 18:26:07 +00:00
parent 3dffc2aea2
commit 0fe8a1b6ca
7 changed files with 63 additions and 0 deletions

View File

@@ -145,6 +145,7 @@ public:
virtual bool HasSelection();
virtual void SelectAll();
virtual wxString GetSelectedText();
virtual wxString GetSelectedHTML();
/** FIXME: hack to work around signals being received too early */
bool m_ready;

View File

@@ -102,6 +102,7 @@ public:
virtual bool HasSelection();
virtual void DeleteSelection();
virtual wxString GetSelectedText();
virtual wxString GetSelectedHTML();
// ---- IE-specific methods

View File

@@ -107,6 +107,7 @@ public:
virtual bool HasSelection() { return false };
virtual void SelectAll() {};
virtual wxString GetSelectedText();
virtual wxString GetSelectedHTML() { return ""; }
// ---- methods not from the parent (common) interface
wxString RunScript(const wxString& javascript);

View File

@@ -288,6 +288,7 @@ public:
virtual bool HasSelection() = 0;
virtual void DeleteSelection() = 0;
virtual wxString GetSelectedText() = 0;
virtual wxString GetSelectedHTML() = 0;
// TODO:
// void EnableJavascript(bool enabled); // maybe?

View File

@@ -393,6 +393,11 @@ public:
*/
virtual void DeleteSelection() = 0;
/**
Returns the currently selected HTML, if any.
*/
virtual wxString GetSelectedHTML() = 0;
/**
Returns the currently selected text, if any.
*/

View File

@@ -743,6 +743,31 @@ wxString wxWebViewWebKit::GetSelectedText()
wxConvUTF8);
}
wxString wxWebViewWebKit::GetSelectedHTML()
{
WebKitDOMDocument* doc;
WebKitDOMDOMWindow* win;
WebKitDOMDOMSelection* sel;
WebKitDOMRange* range;
WebKitDOMElement* div;
WebKitDOMDocumentFragment* clone;
WebKitDOMHTMLElement* html;
doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view));
win = webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc));
sel = webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win));
range = webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel),
0, NULL);
div = webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc), "div", NULL);
clone = webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range), NULL);
webkit_dom_node_append_child(&div->parent_instance, &clone->parent_instance, NULL);
html = (WebKitDOMHTMLElement*)div;
return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html)),
wxConvUTF8);
}
// static
wxVisualAttributes
wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))

View File

@@ -614,6 +614,35 @@ wxString wxWebViewIE::GetSelectedText()
return selected;
}
wxString wxWebViewIE::GetSelectedHTML()
{
IHTMLDocument2* document = GetDocument();
IHTMLSelectionObject* selection;
wxString selected;
HRESULT hr = document->get_selection(&selection);
if(SUCCEEDED(hr))
{
IDispatch* disrange;
hr = selection->createRange(&disrange);
if(SUCCEEDED(hr))
{
IHTMLTxtRange* range;
hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range);
if(SUCCEEDED(hr))
{
BSTR text;
range->get_htmlText(&text);
selected = wxString(text);
range->Release();
}
disrange->Release();
}
selection->Release();
}
document->Release();
return selected;
}
bool wxWebViewIE::CanExecCommand(wxString command)
{
IHTMLDocument2* document = GetDocument();