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:
parent
3ce14be7b9
commit
c7cbe308f6
@ -134,6 +134,10 @@ public:
|
|||||||
virtual void Undo();
|
virtual void Undo();
|
||||||
virtual void Redo();
|
virtual void Redo();
|
||||||
|
|
||||||
|
//Editing functions
|
||||||
|
virtual void SetEditable(bool enable = true);
|
||||||
|
virtual bool IsEditable();
|
||||||
|
|
||||||
/** 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;
|
||||||
|
|
||||||
|
@ -93,6 +93,10 @@ public:
|
|||||||
virtual void Undo();
|
virtual void Undo();
|
||||||
virtual void Redo();
|
virtual void Redo();
|
||||||
|
|
||||||
|
//Editing functions
|
||||||
|
virtual void SetEditable(bool enable = true);
|
||||||
|
virtual bool IsEditable();
|
||||||
|
|
||||||
// ---- IE-specific methods
|
// ---- IE-specific methods
|
||||||
|
|
||||||
// FIXME: I seem to be able to access remote webpages even in offline mode...
|
// FIXME: I seem to be able to access remote webpages even in offline mode...
|
||||||
|
@ -97,6 +97,10 @@ public:
|
|||||||
virtual void Cut();
|
virtual void Cut();
|
||||||
virtual void Copy();
|
virtual void Copy();
|
||||||
virtual void Paste();
|
virtual void Paste();
|
||||||
|
|
||||||
|
//Editing functions
|
||||||
|
void SetEditable(bool enable = true);
|
||||||
|
bool IsEditable();
|
||||||
|
|
||||||
// ---- methods not from the parent (common) interface
|
// ---- methods not from the parent (common) interface
|
||||||
wxString GetSelectedText();
|
wxString GetSelectedText();
|
||||||
@ -108,9 +112,6 @@ public:
|
|||||||
void SetScrollPos(int pos);
|
void SetScrollPos(int pos);
|
||||||
int GetScrollPos();
|
int GetScrollPos();
|
||||||
|
|
||||||
void MakeEditable(bool enable = true);
|
|
||||||
bool IsEditable();
|
|
||||||
|
|
||||||
wxString GetSelection();
|
wxString GetSelection();
|
||||||
|
|
||||||
bool CanIncreaseTextSize();
|
bool CanIncreaseTextSize();
|
||||||
|
@ -281,13 +281,13 @@ public:
|
|||||||
SetPage(stream.GetString(), baseUrl);
|
SetPage(stream.GetString(), baseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void SetEditable(bool enable = true) = 0;
|
||||||
|
virtual bool IsEditable() = 0;
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// wxString GetSelection(); // maybe?
|
// wxString GetSelection(); // maybe?
|
||||||
// void SetSelection(...); // maybe?
|
// void SetSelection(...); // maybe?
|
||||||
|
|
||||||
// void MakeEditable(bool enable = true); // maybe?
|
|
||||||
// bool IsEditable(); // maybe?
|
|
||||||
|
|
||||||
// void EnableJavascript(bool enabled); // maybe?
|
// void EnableJavascript(bool enabled); // maybe?
|
||||||
// wxString RunScript(const wxString& javascript); // maybe?
|
// wxString RunScript(const wxString& javascript); // maybe?
|
||||||
|
|
||||||
|
@ -229,7 +229,12 @@ public:
|
|||||||
/**
|
/**
|
||||||
Returns whether the web control is currently busy (e.g. loading a page).
|
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
|
Load a web page from a URL
|
||||||
@ -251,6 +256,13 @@ public:
|
|||||||
@param flags A bit array that may optionally contain reload options.
|
@param flags A bit array that may optionally contain reload options.
|
||||||
*/
|
*/
|
||||||
virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0;
|
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.
|
Set the displayed page source to the contents of the given string.
|
||||||
|
@ -76,6 +76,7 @@ public:
|
|||||||
void OnPaste(wxCommandEvent& evt);
|
void OnPaste(wxCommandEvent& evt);
|
||||||
void OnUndo(wxCommandEvent& evt);
|
void OnUndo(wxCommandEvent& evt);
|
||||||
void OnRedo(wxCommandEvent& evt);
|
void OnRedo(wxCommandEvent& evt);
|
||||||
|
void OnMode(wxCommandEvent& evt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxTextCtrl* m_url;
|
wxTextCtrl* m_url;
|
||||||
@ -102,6 +103,7 @@ private:
|
|||||||
wxMenuItem* m_edit_paste;
|
wxMenuItem* m_edit_paste;
|
||||||
wxMenuItem* m_edit_undo;
|
wxMenuItem* m_edit_undo;
|
||||||
wxMenuItem* m_edit_redo;
|
wxMenuItem* m_edit_redo;
|
||||||
|
wxMenuItem* m_edit_mode;
|
||||||
|
|
||||||
wxTimer* m_timer;
|
wxTimer* m_timer;
|
||||||
int m_animation_angle;
|
int m_animation_angle;
|
||||||
@ -213,6 +215,8 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
|
|||||||
editmenu->AppendSeparator();
|
editmenu->AppendSeparator();
|
||||||
m_edit_undo = editmenu->Append(wxID_ANY, _("Undo"));
|
m_edit_undo = editmenu->Append(wxID_ANY, _("Undo"));
|
||||||
m_edit_redo = editmenu->Append(wxID_ANY, _("Redo"));
|
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->AppendSeparator();
|
||||||
m_tools_menu->AppendSubMenu(editmenu, "Edit");
|
m_tools_menu->AppendSubMenu(editmenu, "Edit");
|
||||||
@ -279,6 +283,8 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
|
|||||||
wxCommandEventHandler(WebFrame::OnUndo), NULL, this );
|
wxCommandEventHandler(WebFrame::OnUndo), NULL, this );
|
||||||
Connect(m_edit_redo->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
Connect(m_edit_redo->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
||||||
wxCommandEventHandler(WebFrame::OnRedo), NULL, this );
|
wxCommandEventHandler(WebFrame::OnRedo), NULL, this );
|
||||||
|
Connect(m_edit_mode->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
||||||
|
wxCommandEventHandler(WebFrame::OnMode), NULL, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebFrame::OnAnimationTimer(wxTimerEvent& evt)
|
void WebFrame::OnAnimationTimer(wxTimerEvent& evt)
|
||||||
@ -428,6 +434,12 @@ void WebFrame::OnRedo(wxCommandEvent& evt)
|
|||||||
m_browser->Redo();
|
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
|
* Callback invoked when there is a request to load a new page (for instance
|
||||||
* when the user clicks a link)
|
* when the user clicks a link)
|
||||||
|
@ -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
|
// static
|
||||||
wxVisualAttributes
|
wxVisualAttributes
|
||||||
wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||||
|
@ -544,6 +544,26 @@ void wxWebViewIE::Redo()
|
|||||||
ExecCommand("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)
|
bool wxWebViewIE::CanExecCommand(wxString command)
|
||||||
{
|
{
|
||||||
IHTMLDocument2* document = GetDocument();
|
IHTMLDocument2* document = GetDocument();
|
||||||
|
@ -660,7 +660,7 @@ void wxWebViewWebKit::Print()
|
|||||||
[op runOperation];
|
[op runOperation];
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWebViewWebKit::MakeEditable(bool enable)
|
void wxWebViewWebKit::SetEditable(bool enable)
|
||||||
{
|
{
|
||||||
if ( !m_webView )
|
if ( !m_webView )
|
||||||
return;
|
return;
|
||||||
|
@ -40,6 +40,7 @@ private:
|
|||||||
CPPUNIT_TEST( HistoryEnable );
|
CPPUNIT_TEST( HistoryEnable );
|
||||||
CPPUNIT_TEST( HistoryClear );
|
CPPUNIT_TEST( HistoryClear );
|
||||||
CPPUNIT_TEST( HistoryList );
|
CPPUNIT_TEST( HistoryList );
|
||||||
|
CPPUNIT_TEST( Editable );
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
void Title();
|
void Title();
|
||||||
@ -48,6 +49,7 @@ private:
|
|||||||
void HistoryEnable();
|
void HistoryEnable();
|
||||||
void HistoryClear();
|
void HistoryClear();
|
||||||
void HistoryList();
|
void HistoryList();
|
||||||
|
void Editable();
|
||||||
void LoadUrl(const wxString& url, int times = 1);
|
void LoadUrl(const wxString& url, int times = 1);
|
||||||
|
|
||||||
wxWebView* m_browser;
|
wxWebView* m_browser;
|
||||||
@ -166,4 +168,17 @@ void WebTestCase::HistoryList()
|
|||||||
CPPUNIT_ASSERT_EQUAL(2, m_browser->GetBackwardHistory().size());
|
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
|
#endif //wxUSE_WEB
|
||||||
|
Loading…
Reference in New Issue
Block a user