Add the ability to enable / disable and check for the editable property of a rendering engine. Implement for all three backends and extend the sample, document and unit test.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68193 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Steve Lamerton 2011-07-08 19:34:56 +00:00
parent 3ce14be7b9
commit c7cbe308f6
10 changed files with 86 additions and 8 deletions

View File

@ -134,6 +134,10 @@ public:
virtual void Undo();
virtual void Redo();
//Editing functions
virtual void SetEditable(bool enable = true);
virtual bool IsEditable();
/** FIXME: hack to work around signals being received too early */
bool m_ready;

View File

@ -93,6 +93,10 @@ public:
virtual void Undo();
virtual void Redo();
//Editing functions
virtual void SetEditable(bool enable = true);
virtual bool IsEditable();
// ---- IE-specific methods
// FIXME: I seem to be able to access remote webpages even in offline mode...

View File

@ -97,6 +97,10 @@ public:
virtual void Cut();
virtual void Copy();
virtual void Paste();
//Editing functions
void SetEditable(bool enable = true);
bool IsEditable();
// ---- methods not from the parent (common) interface
wxString GetSelectedText();
@ -108,9 +112,6 @@ public:
void SetScrollPos(int pos);
int GetScrollPos();
void MakeEditable(bool enable = true);
bool IsEditable();
wxString GetSelection();
bool CanIncreaseTextSize();

View File

@ -281,13 +281,13 @@ public:
SetPage(stream.GetString(), baseUrl);
}
virtual void SetEditable(bool enable = true) = 0;
virtual bool IsEditable() = 0;
// TODO:
// wxString GetSelection(); // maybe?
// void SetSelection(...); // maybe?
// void MakeEditable(bool enable = true); // maybe?
// bool IsEditable(); // maybe?
// void EnableJavascript(bool enabled); // maybe?
// wxString RunScript(const wxString& javascript); // maybe?

View File

@ -229,7 +229,12 @@ public:
/**
Returns whether the web control is currently busy (e.g. loading a page).
*/
virtual bool IsBusy() = 0;
virtual bool IsBusy() = 0;
/**
Returns whether the web control is currently editable
*/
virtual bool IsEditable() = 0;
/**
Load a web page from a URL
@ -251,6 +256,13 @@ public:
@param flags A bit array that may optionally contain reload options.
*/
virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0;
/**
Set the editable property of the web control. Enabling allows the user
to edit the page even if the @c contenteditable attribute is not set.
The exact capabilities vary with the backend being used.
*/
virtual void SetEditable(bool enable = true) = 0;
/**
Set the displayed page source to the contents of the given string.

View File

@ -76,6 +76,7 @@ public:
void OnPaste(wxCommandEvent& evt);
void OnUndo(wxCommandEvent& evt);
void OnRedo(wxCommandEvent& evt);
void OnMode(wxCommandEvent& evt);
private:
wxTextCtrl* m_url;
@ -102,6 +103,7 @@ private:
wxMenuItem* m_edit_paste;
wxMenuItem* m_edit_undo;
wxMenuItem* m_edit_redo;
wxMenuItem* m_edit_mode;
wxTimer* m_timer;
int m_animation_angle;
@ -213,6 +215,8 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
editmenu->AppendSeparator();
m_edit_undo = editmenu->Append(wxID_ANY, _("Undo"));
m_edit_redo = editmenu->Append(wxID_ANY, _("Redo"));
editmenu->AppendSeparator();
m_edit_mode = editmenu->AppendCheckItem(wxID_ANY, _("Edit Mode"));
m_tools_menu->AppendSeparator();
m_tools_menu->AppendSubMenu(editmenu, "Edit");
@ -279,6 +283,8 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
wxCommandEventHandler(WebFrame::OnUndo), NULL, this );
Connect(m_edit_redo->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(WebFrame::OnRedo), NULL, this );
Connect(m_edit_mode->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(WebFrame::OnMode), NULL, this );
}
void WebFrame::OnAnimationTimer(wxTimerEvent& evt)
@ -428,6 +434,12 @@ void WebFrame::OnRedo(wxCommandEvent& evt)
m_browser->Redo();
}
void WebFrame::OnMode(wxCommandEvent& evt)
{
m_browser->SetEditable(m_edit_mode->IsChecked());
}
/**
* Callback invoked when there is a request to load a new page (for instance
* when the user clicks a link)

View File

@ -702,6 +702,16 @@ bool wxWebViewWebKit::IsBusy()
*/
}
void wxWebViewWebKit::SetEditable(bool enable)
{
webkit_web_view_set_editable(WEBKIT_WEB_VIEW(web_view), enable);
}
bool wxWebViewWebKit::IsEditable()
{
return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(web_view));
}
// static
wxVisualAttributes
wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))

View File

@ -544,6 +544,26 @@ void wxWebViewIE::Redo()
ExecCommand("Redo");
}
void wxWebViewIE::SetEditable(bool enable)
{
IHTMLDocument2* document = GetDocument();
if( enable )
document->put_designMode(SysAllocString(L"On"));
else
document->put_designMode(SysAllocString(L"Off"));
}
bool wxWebViewIE::IsEditable()
{
IHTMLDocument2* document = GetDocument();
BSTR mode;
document->get_designMode(&mode);
if(wxString(mode) == "On")
return true;
else
return false;
}
bool wxWebViewIE::CanExecCommand(wxString command)
{
IHTMLDocument2* document = GetDocument();

View File

@ -660,7 +660,7 @@ void wxWebViewWebKit::Print()
[op runOperation];
}
void wxWebViewWebKit::MakeEditable(bool enable)
void wxWebViewWebKit::SetEditable(bool enable)
{
if ( !m_webView )
return;

View File

@ -40,6 +40,7 @@ private:
CPPUNIT_TEST( HistoryEnable );
CPPUNIT_TEST( HistoryClear );
CPPUNIT_TEST( HistoryList );
CPPUNIT_TEST( Editable );
CPPUNIT_TEST_SUITE_END();
void Title();
@ -48,6 +49,7 @@ private:
void HistoryEnable();
void HistoryClear();
void HistoryList();
void Editable();
void LoadUrl(const wxString& url, int times = 1);
wxWebView* m_browser;
@ -166,4 +168,17 @@ void WebTestCase::HistoryList()
CPPUNIT_ASSERT_EQUAL(2, m_browser->GetBackwardHistory().size());
}
void WebTestCase::Editable()
{
CPPUNIT_ASSERT(!m_browser->IsEditable());
m_browser->SetEditable(true);
CPPUNIT_ASSERT(m_browser->IsEditable());
m_browser->SetEditable(false);
CPPUNIT_ASSERT(!m_browser->IsEditable());
}
#endif //wxUSE_WEB