/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/webview_webkit.mm
-// Purpose: wxOSXWebKitCtrl - embeddable web kit control,
+// Purpose: wxWebViewWebKit - embeddable web kit control,
// OS X implementation of web view component
// Author: Jethro Grassie / Kevin Ollivier / Marianne Gagnon
// Modified by:
// FIXME: find cleaner way to find the wxWidgets ID of a webview than this hack
#include <map>
-std::map<WebView*, wxOSXWebKitCtrl*> wx_webviewctrls;
+std::map<WebView*, wxWebViewWebKit*> wx_webviewctrls;
#define DEBUG_WEBKIT_SIZING 0
// macros
// ----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxOSXWebKitCtrl, wxControl)
+IMPLEMENT_DYNAMIC_CLASS(wxWebViewWebKit, wxControl)
-BEGIN_EVENT_TABLE(wxOSXWebKitCtrl, wxControl)
+BEGIN_EVENT_TABLE(wxWebViewWebKit, wxControl)
#if defined(__WXMAC__) && wxOSX_USE_CARBON
- EVT_SIZE(wxOSXWebKitCtrl::OnSize)
+ EVT_SIZE(wxWebViewWebKit::OnSize)
#endif
END_EVENT_TABLE()
OSStatus result = eventNotHandledErr ;
wxMacCarbonEvent cEvent( event ) ;
- wxOSXWebKitCtrl* thisWindow = (wxOSXWebKitCtrl*) data ;
+ wxWebViewWebKit* thisWindow = (wxWebViewWebKit*) data ;
wxWindow* focus = thisWindow ;
unsigned char charCode ;
return result ;
}
-static pascal OSStatus wxOSXWebKitCtrlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+static pascal OSStatus wxWebViewWebKitEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{
OSStatus result = eventNotHandledErr ;
wxMacCarbonEvent cEvent( event ) ;
ControlRef controlRef ;
- wxOSXWebKitCtrl* thisWindow = (wxOSXWebKitCtrl*) data ;
+ wxWebViewWebKit* thisWindow = (wxWebViewWebKit*) data ;
wxNonOwnedWindow* tlw = NULL;
if (thisWindow)
tlw = thisWindow->MacGetTopLevelWindow();
return result ;
}
-DEFINE_ONE_SHOT_HANDLER_GETTER( wxOSXWebKitCtrlEventHandler )
+DEFINE_ONE_SHOT_HANDLER_GETTER( wxWebViewWebKitEventHandler )
#endif
@interface MyFrameLoadMonitor : NSObject
{
- wxOSXWebKitCtrl* webKitWindow;
+ wxWebViewWebKit* webKitWindow;
}
-- initWithWxWindow: (wxOSXWebKitCtrl*)inWindow;
+- initWithWxWindow: (wxWebViewWebKit*)inWindow;
@end
@interface MyPolicyDelegate : NSObject
{
- wxOSXWebKitCtrl* webKitWindow;
+ wxWebViewWebKit* webKitWindow;
}
-- initWithWxWindow: (wxOSXWebKitCtrl*)inWindow;
+- initWithWxWindow: (wxWebViewWebKit*)inWindow;
@end
// creation/destruction
// ----------------------------------------------------------------------------
-bool wxOSXWebKitCtrl::Create(wxWindow *parent,
+bool wxWebViewWebKit::Create(wxWindow *parent,
wxWindowID winID,
const wxString& strURL,
const wxPoint& pos,
HIViewChangeFeatures( m_peer->GetControlRef() , kHIViewIsOpaque , 0 ) ;
#endif
InstallControlEventHandler(m_peer->GetControlRef(),
- GetwxOSXWebKitCtrlEventHandlerUPP(),
+ GetwxWebViewWebKitEventHandlerUPP(),
GetEventTypeCount(eventList), eventList, this,
(EventHandlerRef *)&m_webKitCtrlEventHandler);
#else
return true;
}
-wxOSXWebKitCtrl::~wxOSXWebKitCtrl()
+wxWebViewWebKit::~wxWebViewWebKit()
{
MyFrameLoadMonitor* myFrameLoadMonitor = [m_webView frameLoadDelegate];
MyPolicyDelegate* myPolicyDelegate = [m_webView policyDelegate];
// public methods
// ----------------------------------------------------------------------------
-void wxOSXWebKitCtrl::InternalLoadURL(const wxString &url)
+void wxWebViewWebKit::InternalLoadURL(const wxString &url)
{
if( !m_webView )
return;
[NSURL URLWithString:wxNSStringWithWxString(url)]]];
}
-bool wxOSXWebKitCtrl::CanGoBack()
+bool wxWebViewWebKit::CanGoBack()
{
if ( !m_webView )
return false;
return [m_webView canGoBack];
}
-bool wxOSXWebKitCtrl::CanGoForward()
+bool wxWebViewWebKit::CanGoForward()
{
if ( !m_webView )
return false;
return [m_webView canGoForward];
}
-void wxOSXWebKitCtrl::GoBack()
+void wxWebViewWebKit::GoBack()
{
if ( !m_webView )
return;
//return result;
}
-void wxOSXWebKitCtrl::GoForward()
+void wxWebViewWebKit::GoForward()
{
if ( !m_webView )
return;
//return result;
}
-void wxOSXWebKitCtrl::Reload(wxWebViewReloadFlags flags)
+void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags)
{
if ( !m_webView )
return;
}
}
-void wxOSXWebKitCtrl::Stop()
+void wxWebViewWebKit::Stop()
{
if ( !m_webView )
return;
[[m_webView mainFrame] stopLoading];
}
-bool wxOSXWebKitCtrl::CanGetPageSource()
+bool wxWebViewWebKit::CanGetPageSource()
{
if ( !m_webView )
return false;
return ( [[dataSource representation] canProvideDocumentSource] );
}
-wxString wxOSXWebKitCtrl::GetPageSource()
+wxString wxWebViewWebKit::GetPageSource()
{
if (CanGetPageSource())
return wxEmptyString;
}
-wxString wxOSXWebKitCtrl::GetSelection()
+wxString wxWebViewWebKit::GetSelection()
{
if ( !m_webView )
return wxEmptyString;
return wxStringWithNSString( selectedText );
}
-bool wxOSXWebKitCtrl::CanIncreaseTextSize()
+bool wxWebViewWebKit::CanIncreaseTextSize()
{
if ( !m_webView )
return false;
return false;
}
-void wxOSXWebKitCtrl::IncreaseTextSize()
+void wxWebViewWebKit::IncreaseTextSize()
{
if ( !m_webView )
return;
[m_webView makeTextLarger:(WebView*)m_webView];
}
-bool wxOSXWebKitCtrl::CanDecreaseTextSize()
+bool wxWebViewWebKit::CanDecreaseTextSize()
{
if ( !m_webView )
return false;
return false;
}
-void wxOSXWebKitCtrl::DecreaseTextSize()
+void wxWebViewWebKit::DecreaseTextSize()
{
if ( !m_webView )
return;
[m_webView makeTextSmaller:(WebView*)m_webView];
}
-void wxOSXWebKitCtrl::Print()
+void wxWebViewWebKit::Print()
{
// TODO: allow specifying the "show prompt" parameter in Print() ?
[op runOperation];
}
-void wxOSXWebKitCtrl::MakeEditable(bool enable)
+void wxWebViewWebKit::MakeEditable(bool enable)
{
if ( !m_webView )
return;
[m_webView setEditable:enable ];
}
-bool wxOSXWebKitCtrl::IsEditable()
+bool wxWebViewWebKit::IsEditable()
{
if ( !m_webView )
return false;
return [m_webView isEditable];
}
-void wxOSXWebKitCtrl::SetZoomType(wxWebViewZoomType zoomType)
+void wxWebViewWebKit::SetZoomType(wxWebViewZoomType zoomType)
{
// there is only one supported zoom type at the moment so this setter
// does nothing beyond checking sanity
wxASSERT(zoomType == wxWEB_VIEW_ZOOM_TYPE_TEXT);
}
-wxWebViewZoomType wxOSXWebKitCtrl::GetZoomType() const
+wxWebViewZoomType wxWebViewWebKit::GetZoomType() const
{
// for now that's the only one that is supported
// FIXME: does the default zoom type change depending on webkit versions? :S
return wxWEB_VIEW_ZOOM_TYPE_TEXT;
}
-bool wxOSXWebKitCtrl::CanSetZoomType(wxWebViewZoomType type) const
+bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType type) const
{
switch (type)
{
}
}
-int wxOSXWebKitCtrl::GetScrollPos()
+int wxWebViewWebKit::GetScrollPos()
{
id result = [[m_webView windowScriptObject]
evaluateWebScript:@"document.body.scrollTop"];
return [result intValue];
}
-void wxOSXWebKitCtrl::SetScrollPos(int pos)
+void wxWebViewWebKit::SetScrollPos(int pos)
{
if ( !m_webView )
return;
(NSString*)wxNSStringWithWxString( javascript )];
}
-wxString wxOSXWebKitCtrl::GetSelectedText()
+wxString wxWebViewWebKit::GetSelectedText()
{
NSString* selection = [[m_webView selectedDOMRange] markupString];
if (!selection) return wxEmptyString;
return wxStringWithNSString(selection);
}
-wxString wxOSXWebKitCtrl::RunScript(const wxString& javascript)
+wxString wxWebViewWebKit::RunScript(const wxString& javascript)
{
if ( !m_webView )
return wxEmptyString;
return wxStringWithNSString( resultAsString );
}
-void wxOSXWebKitCtrl::OnSize(wxSizeEvent &event)
+void wxWebViewWebKit::OnSize(wxSizeEvent &event)
{
#if defined(__WXMAC_) && wxOSX_USE_CARBON
// This is a nasty hack because WebKit seems to lose its position when it is
#endif
}
-void wxOSXWebKitCtrl::MacVisibilityChanged(){
+void wxWebViewWebKit::MacVisibilityChanged(){
#if defined(__WXMAC__) && wxOSX_USE_CARBON
bool isHidden = !IsControlVisible( m_peer->GetControlRef());
if (!isHidden)
#endif
}
-void wxOSXWebKitCtrl::LoadUrl(const wxString& url)
+void wxWebViewWebKit::LoadUrl(const wxString& url)
{
InternalLoadURL(url);
}
-wxString wxOSXWebKitCtrl::GetCurrentURL()
+wxString wxWebViewWebKit::GetCurrentURL()
{
return wxStringWithNSString([m_webView mainFrameURL]);
}
-wxString wxOSXWebKitCtrl::GetCurrentTitle()
+wxString wxWebViewWebKit::GetCurrentTitle()
{
return GetPageTitle();
}
-float wxOSXWebKitCtrl::GetWebkitZoom()
+float wxWebViewWebKit::GetWebkitZoom()
{
return [m_webView textSizeMultiplier];
}
-void wxOSXWebKitCtrl::SetWebkitZoom(float zoom)
+void wxWebViewWebKit::SetWebkitZoom(float zoom)
{
[m_webView setTextSizeMultiplier:zoom];
}
-wxWebViewZoom wxOSXWebKitCtrl::GetZoom()
+wxWebViewZoom wxWebViewWebKit::GetZoom()
{
float zoom = GetWebkitZoom();
return wxWEB_VIEW_ZOOM_MEDIUM;
}
-void wxOSXWebKitCtrl::SetZoom(wxWebViewZoom zoom)
+void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom)
{
// arbitrary way to map our common zoom enum to float zoom
switch (zoom)
}
-void wxOSXWebKitCtrl::SetPage(const wxString& src, const wxString& baseUrl)
+void wxWebViewWebKit::SetPage(const wxString& src, const wxString& baseUrl)
{
if ( !m_webView )
return;
@implementation MyFrameLoadMonitor
-- initWithWxWindow: (wxOSXWebKitCtrl*)inWindow
+- initWithWxWindow: (wxWebViewWebKit*)inWindow
{
[super init];
webKitWindow = inWindow; // non retained
@implementation MyPolicyDelegate
-- initWithWxWindow: (wxOSXWebKitCtrl*)inWindow
+- initWithWxWindow: (wxWebViewWebKit*)inWindow
{
[super init];
webKitWindow = inWindow; // non retained