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:
@@ -145,6 +145,7 @@ public:
|
|||||||
virtual bool HasSelection();
|
virtual bool HasSelection();
|
||||||
virtual void SelectAll();
|
virtual void SelectAll();
|
||||||
virtual wxString GetSelectedText();
|
virtual wxString GetSelectedText();
|
||||||
|
virtual wxString GetSelectedHTML();
|
||||||
|
|
||||||
/** FIXME: hack to work around signals being received too early */
|
/** FIXME: hack to work around signals being received too early */
|
||||||
bool m_ready;
|
bool m_ready;
|
||||||
|
@@ -102,6 +102,7 @@ public:
|
|||||||
virtual bool HasSelection();
|
virtual bool HasSelection();
|
||||||
virtual void DeleteSelection();
|
virtual void DeleteSelection();
|
||||||
virtual wxString GetSelectedText();
|
virtual wxString GetSelectedText();
|
||||||
|
virtual wxString GetSelectedHTML();
|
||||||
|
|
||||||
|
|
||||||
// ---- IE-specific methods
|
// ---- IE-specific methods
|
||||||
|
@@ -107,6 +107,7 @@ public:
|
|||||||
virtual bool HasSelection() { return false };
|
virtual bool HasSelection() { return false };
|
||||||
virtual void SelectAll() {};
|
virtual void SelectAll() {};
|
||||||
virtual wxString GetSelectedText();
|
virtual wxString GetSelectedText();
|
||||||
|
virtual wxString GetSelectedHTML() { return ""; }
|
||||||
|
|
||||||
// ---- methods not from the parent (common) interface
|
// ---- methods not from the parent (common) interface
|
||||||
wxString RunScript(const wxString& javascript);
|
wxString RunScript(const wxString& javascript);
|
||||||
|
@@ -288,6 +288,7 @@ public:
|
|||||||
virtual bool HasSelection() = 0;
|
virtual bool HasSelection() = 0;
|
||||||
virtual void DeleteSelection() = 0;
|
virtual void DeleteSelection() = 0;
|
||||||
virtual wxString GetSelectedText() = 0;
|
virtual wxString GetSelectedText() = 0;
|
||||||
|
virtual wxString GetSelectedHTML() = 0;
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// void EnableJavascript(bool enabled); // maybe?
|
// void EnableJavascript(bool enabled); // maybe?
|
||||||
|
@@ -393,6 +393,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void DeleteSelection() = 0;
|
virtual void DeleteSelection() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the currently selected HTML, if any.
|
||||||
|
*/
|
||||||
|
virtual wxString GetSelectedHTML() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the currently selected text, if any.
|
Returns the currently selected text, if any.
|
||||||
*/
|
*/
|
||||||
|
@@ -743,6 +743,31 @@ wxString wxWebViewWebKit::GetSelectedText()
|
|||||||
wxConvUTF8);
|
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
|
// static
|
||||||
wxVisualAttributes
|
wxVisualAttributes
|
||||||
wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||||
|
@@ -614,6 +614,35 @@ wxString wxWebViewIE::GetSelectedText()
|
|||||||
return selected;
|
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)
|
bool wxWebViewIE::CanExecCommand(wxString command)
|
||||||
{
|
{
|
||||||
IHTMLDocument2* document = GetDocument();
|
IHTMLDocument2* document = GetDocument();
|
||||||
|
Reference in New Issue
Block a user