// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include <WebKit/WebKit.h>
#include <WebKit/HIWebView.h>
#include <WebKit/CarbonUtils.h>
#include <WebKit/WebKit.h>
#include <WebKit/HIWebView.h>
#include <WebKit/CarbonUtils.h>
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxWebKitCtrl, wxControl)
BEGIN_EVENT_TABLE(wxWebKitCtrl, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxWebKitCtrl, wxControl)
BEGIN_EVENT_TABLE(wxWebKitCtrl, wxControl)
// ----------------------------------------------------------------------------
// Carbon Events handlers
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Carbon Events handlers
// ----------------------------------------------------------------------------
void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent );
static const EventTypeSpec eventList[] =
void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent );
static const EventTypeSpec eventList[] =
{ kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseMoved },
{ kEventClassMouse, kEventMouseDragged },
{ kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseMoved },
{ kEventClassMouse, kEventMouseDragged },
{ kEventClassKeyboard, kEventRawKeyDown } ,
{ kEventClassKeyboard, kEventRawKeyRepeat } ,
{ kEventClassKeyboard, kEventRawKeyUp } ,
{ kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
{ kEventClassKeyboard, kEventRawKeyDown } ,
{ kEventClassKeyboard, kEventRawKeyRepeat } ,
{ kEventClassKeyboard, kEventRawKeyUp } ,
{ kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
{ kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
{ kEventClassTextInput, kEventTextInputUpdateActiveInputArea } ,
{ kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
{ kEventClassTextInput, kEventTextInputUpdateActiveInputArea } ,
#if DEBUG_WEBKIT_SIZING == 1
{ kEventClassControl, kEventControlBoundsChanged } ,
#endif
#if DEBUG_WEBKIT_SIZING == 1
{ kEventClassControl, kEventControlBoundsChanged } ,
#endif
if (thisWindow)
tlw = thisWindow->MacGetTopLevelWindow();
cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
if (thisWindow)
tlw = thisWindow->MacGetTopLevelWindow();
cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
case kEventClassTextInput:
{
result = wxMacUnicodeTextEventHandler(handler, event, data);
break;
}
case kEventClassTextInput:
{
result = wxMacUnicodeTextEventHandler(handler, event, data);
break;
}
{
wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
SetupMouseEvent( wxevent , cEvent ) ;
{
wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
SetupMouseEvent( wxevent , cEvent ) ;
currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
wxevent.SetEventObject( currentMouseWindow ) ;
wxevent.SetId( currentMouseWindow->GetId() ) ;
currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
wxevent.SetEventObject( currentMouseWindow ) ;
wxevent.SetId( currentMouseWindow->GetId() ) ;
wxWebKitStateChangedEvent::wxWebKitStateChangedEvent( wxWindow* win )
{
SetEventType( wxEVT_WEBKIT_STATE_CHANGED);
wxWebKitStateChangedEvent::wxWebKitStateChangedEvent( wxWindow* win )
{
SetEventType( wxEVT_WEBKIT_STATE_CHANGED);
wxWebKitBeforeLoadEvent::wxWebKitBeforeLoadEvent( wxWindow* win )
{
m_cancelled = false;
SetEventType( wxEVT_WEBKIT_BEFORE_LOAD);
wxWebKitBeforeLoadEvent::wxWebKitBeforeLoadEvent( wxWindow* win )
{
m_cancelled = false;
SetEventType( wxEVT_WEBKIT_BEFORE_LOAD);
+
+IMPLEMENT_DYNAMIC_CLASS( wxWebKitNewWindowEvent, wxCommandEvent )
+
+wxDEFINE_EVENT( wxEVT_WEBKIT_NEW_WINDOW, wxWebKitNewWindowEvent );
+
+wxWebKitNewWindowEvent::wxWebKitNewWindowEvent( wxWindow* win )
+{
+ SetEventType( wxEVT_WEBKIT_NEW_WINDOW);
+ if ( win )
+ {
+ SetEventObject( win );
+ SetId(win->GetId());
+ }
+}
+
+
+
//---------------------------------------------------------
// helper functions for NSString<->wxString conversion
//---------------------------------------------------------
//---------------------------------------------------------
// helper functions for NSString<->wxString conversion
//---------------------------------------------------------
inline int wxNavTypeFromWebNavType(int type){
if (type == WebNavigationTypeLinkClicked)
return wxWEBKIT_NAV_LINK_CLICKED;
inline int wxNavTypeFromWebNavType(int type){
if (type == WebNavigationTypeLinkClicked)
return wxWEBKIT_NAV_LINK_CLICKED;
#ifdef __WXCOCOA__
wxControl::Create(parent, m_windowID, pos, sizeInstance, style , validator , name);
SetSize(pos.x, pos.y, sizeInstance.x, sizeInstance.y);
#ifdef __WXCOCOA__
wxControl::Create(parent, m_windowID, pos, sizeInstance, style , validator , name);
SetSize(pos.x, pos.y, sizeInstance.x, sizeInstance.y);
if(m_parent) m_parent->CocoaAddChild(this);
SetInitialFrameRect(pos,sizeInstance);
#else
if(m_parent) m_parent->CocoaAddChild(this);
SetInitialFrameRect(pos,sizeInstance);
#else
wxControl::Create(parent, winID, pos, size, style , validator , name);
wxControl::Create(parent, winID, pos, size, style , validator , name);
- m_webView = (WebView*) HIWebViewGetWebView( m_peer->GetControlRef() );
-
- MacPostControlCreate(pos, size);
- HIViewSetVisible( m_peer->GetControlRef(), true );
- [m_webView setHidden:false];
GetEventTypeCount(eventList), eventList, this,
(EventHandlerRef *)&m_webKitCtrlEventHandler);
GetEventTypeCount(eventList), eventList, this,
(EventHandlerRef *)&m_webKitCtrlEventHandler);
+
+ SetPeer(peer);
+#else
+ NSRect r = wxOSXGetFrameForControl( this, pos , size ) ;
+ m_webView = [[WebView alloc] initWithFrame:r frameName:@"webkitFrame" groupName:@"webkitGroup"];
+
+ SetPeer(new wxWidgetCocoaImpl( this, m_webView ));
+#endif
+ MacPostControlCreate(pos, size);
+#if wxOSX_USE_CARBON
+ HIViewSetVisible( GetPeer()->GetControlRef(), true );
+#endif
+ [m_webView setHidden:false];
#endif
// Register event listener interfaces
MyFrameLoadMonitor* myFrameLoadMonitor = [[MyFrameLoadMonitor alloc] initWithWxWindow: this];
[m_webView setFrameLoadDelegate:myFrameLoadMonitor];
#endif
// Register event listener interfaces
MyFrameLoadMonitor* myFrameLoadMonitor = [[MyFrameLoadMonitor alloc] initWithWxWindow: this];
[m_webView setFrameLoadDelegate:myFrameLoadMonitor];
// this is used to veto page loads, etc.
MyPolicyDelegate* myPolicyDelegate = [[MyPolicyDelegate alloc] initWithWxWindow: this];
[m_webView setPolicyDelegate:myPolicyDelegate];
// this is used to veto page loads, etc.
MyPolicyDelegate* myPolicyDelegate = [[MyPolicyDelegate alloc] initWithWxWindow: this];
[m_webView setPolicyDelegate:myPolicyDelegate];
+ MyFrameLoadMonitor* myFrameLoadMonitor = [m_webView frameLoadDelegate];
+ MyPolicyDelegate* myPolicyDelegate = [m_webView policyDelegate];
+ [m_webView setFrameLoadDelegate: nil];
+ [m_webView setPolicyDelegate: nil];
+
+ if (myFrameLoadMonitor)
+ [myFrameLoadMonitor release];
+
+ if (myPolicyDelegate)
+ [myPolicyDelegate release];
NSString* selectedText = [[m_webView selectedDOMRange] toString];
return wxStringWithNSString( selectedText );
}
NSString* selectedText = [[m_webView selectedDOMRange] toString];
return wxStringWithNSString( selectedText );
}
-
- id view = [[[m_webView mainFrame] frameView] documentView];
- NSPrintOperation *op = [NSPrintOperation printOperationWithView:view printInfo: [NSPrintInfo sharedPrintInfo]];
+
+ id view = [[[m_webView mainFrame] frameView] documentView];
+ NSPrintOperation *op = [NSPrintOperation printOperationWithView:view printInfo: [NSPrintInfo sharedPrintInfo]];
if (showPrompt){
[op setShowsPrintPanel: showPrompt];
// in my tests, the progress bar always freezes and it stops the whole print operation.
// do not turn this to true unless there is a workaround for the bug.
[op setShowsProgressPanel: false];
}
if (showPrompt){
[op setShowsPrintPanel: showPrompt];
// in my tests, the progress bar always freezes and it stops the whole print operation.
// do not turn this to true unless there is a workaround for the bug.
[op setShowsProgressPanel: false];
}
int wxWebKitCtrl::GetScrollPos(){
id result = [[m_webView windowScriptObject] evaluateWebScript:@"document.body.scrollTop"];
return [result intValue];
int wxWebKitCtrl::GetScrollPos(){
id result = [[m_webView windowScriptObject] evaluateWebScript:@"document.body.scrollTop"];
return [result intValue];
javascript.Printf(wxT("document.body.scrollTop = %d;"), pos);
[[m_webView windowScriptObject] evaluateWebScript:(NSString*)wxNSStringWithWxString( javascript )];
}
wxString wxWebKitCtrl::RunScript(const wxString& javascript){
if ( !m_webView )
javascript.Printf(wxT("document.body.scrollTop = %d;"), pos);
[[m_webView windowScriptObject] evaluateWebScript:(NSString*)wxNSStringWithWxString( javascript )];
}
wxString wxWebKitCtrl::RunScript(const wxString& javascript){
if ( !m_webView )
NSString* className = NSStringFromClass([result class]);
if ([className isEqualToString:@"NSCFNumber"])
resultAsString = [NSString stringWithFormat:@"%@", result];
NSString* className = NSStringFromClass([result class]);
if ([className isEqualToString:@"NSCFNumber"])
resultAsString = [NSString stringWithFormat:@"%@", result];
else if ([className isEqualToString:@"WebScriptObject"])
resultAsString = [result stringRepresentation];
else
else if ([className isEqualToString:@"WebScriptObject"])
resultAsString = [result stringRepresentation];
else
// This is a nasty hack because WebKit seems to lose its position when it is embedded
// in a control that is not itself the content view for a TLW.
// I put it in OnSize because these calcs are not perfect, and in fact are basically
// This is a nasty hack because WebKit seems to lose its position when it is embedded
// in a control that is not itself the content view for a TLW.
// I put it in OnSize because these calcs are not perfect, and in fact are basically
#if DEBUG_WEBKIT_SIZING
fprintf(stderr,"Carbon window x=%d, y=%d, width=%d, height=%d\n", GetPosition().x, GetPosition().y, GetSize().x, GetSize().y);
fprintf(stderr, "Cocoa window frame x=%G, y=%G, width=%G, height=%G\n", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
#if DEBUG_WEBKIT_SIZING
fprintf(stderr,"Carbon window x=%d, y=%d, width=%d, height=%d\n", GetPosition().x, GetPosition().y, GetSize().x, GetSize().y);
fprintf(stderr, "Cocoa window frame x=%G, y=%G, width=%G, height=%G\n", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
// NB: In most cases, when calling HIViewConvertRect, what people want is to use GetRootControl(),
// and this tripped me up at first. But in fact, what we want is the root view, because we need to
// NB: In most cases, when calling HIViewConvertRect, what people want is to use GetRootControl(),
// and this tripped me up at first. But in fact, what we want is the root view, because we need to
- // make the y origin relative to the very top of the window, not its contents, since we later flip
- // the y coordinate for Cocoa.
- HIViewConvertRect (&rect, m_peer->GetControlRef(),
+ // make the y origin relative to the very top of the window, not its contents, since we later flip
+ // the y coordinate for Cocoa.
+ HIViewConvertRect (&rect, GetPeer()->GetControlRef(),
if (webKitWindow && frame == [sender mainFrame]){
NSString *url = [[[[frame dataSource] request] URL] absoluteString];
wxWebKitStateChangedEvent thisEvent(webKitWindow);
if (webKitWindow && frame == [sender mainFrame]){
NSString *url = [[[[frame dataSource] request] URL] absoluteString];
wxWebKitStateChangedEvent thisEvent(webKitWindow);
if (webKitWindow && frame == [sender mainFrame]){
NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString];
wxWebKitStateChangedEvent thisEvent(webKitWindow);
if (webKitWindow && frame == [sender mainFrame]){
NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString];
wxWebKitStateChangedEvent thisEvent(webKitWindow);
- // Get the navigation type.
- NSNumber *n = [actionInformation objectForKey:WebActionNavigationTypeKey];
+ // Get the navigation type.
+ NSNumber *n = [actionInformation objectForKey:WebActionNavigationTypeKey];
if (webKitWindow && webKitWindow->GetEventHandler())
webKitWindow->GetEventHandler()->ProcessEvent(thisEvent);
if (webKitWindow && webKitWindow->GetEventHandler())
webKitWindow->GetEventHandler()->ProcessEvent(thisEvent);
+- (void)webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id < WebPolicyDecisionListener >)listener
+{
+ wxUnusedVar(sender);
+ wxUnusedVar(actionInformation);
+ wxWebKitNewWindowEvent thisEvent(webKitWindow);
+
+ NSString *url = [[request URL] absoluteString];
+ thisEvent.SetURL( wxStringWithNSString( url ) );
+ thisEvent.SetTargetName( wxStringWithNSString( frameName ) );
+
+ if (webKitWindow && webKitWindow->GetEventHandler())
+ webKitWindow->GetEventHandler()->ProcessEvent(thisEvent);
+
+ [listener use];
+}