1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWebKitCtrl - embeddable web kit control
4 // Author: Jethro Grassie / Kevin Ollivier
8 // Copyright: (c) Jethro Grassie / Kevin Ollivier
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "webkit.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18 #include "wx/splitter.h"
27 #include "wx/cocoa/autorelease.h"
29 #include "wx/osx/uma.h"
30 #include <Carbon/Carbon.h>
31 #include <WebKit/WebKit.h>
32 #include <WebKit/HIWebView.h>
33 #include <WebKit/CarbonUtils.h>
36 #include "wx/html/webkit.h"
38 #define DEBUG_WEBKIT_SIZING 0
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 IMPLEMENT_DYNAMIC_CLASS(wxWebKitCtrl, wxControl)
46 BEGIN_EVENT_TABLE(wxWebKitCtrl, wxControl)
47 EVT_SIZE(wxWebKitCtrl::OnSize)
50 // ----------------------------------------------------------------------------
51 // Carbon Events handlers
52 // ----------------------------------------------------------------------------
54 // prototype for function in src/mac/carbon/toplevel.cpp
55 void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent );
57 static const EventTypeSpec eventList[] =
59 //{ kEventClassControl, kEventControlTrack } ,
60 { kEventClassMouse, kEventMouseUp },
61 { kEventClassMouse, kEventMouseDown },
62 { kEventClassMouse, kEventMouseMoved },
63 { kEventClassMouse, kEventMouseDragged },
65 { kEventClassKeyboard, kEventRawKeyDown } ,
66 { kEventClassKeyboard, kEventRawKeyRepeat } ,
67 { kEventClassKeyboard, kEventRawKeyUp } ,
68 { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
70 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
71 { kEventClassTextInput, kEventTextInputUpdateActiveInputArea } ,
73 #if DEBUG_WEBKIT_SIZING == 1
74 { kEventClassControl, kEventControlBoundsChanged } ,
78 // mix this in from window.cpp
79 pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
81 // NOTE: This is mostly taken from KeyboardEventHandler in toplevel.cpp, but
82 // that expects the data pointer is a top-level window, so I needed to change
83 // that in this case. However, once 2.8 is out, we should factor out the common logic
84 // among the two functions and merge them.
85 static pascal OSStatus wxWebKitKeyEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
87 OSStatus result = eventNotHandledErr ;
88 wxMacCarbonEvent cEvent( event ) ;
90 wxWebKitCtrl* thisWindow = (wxWebKitCtrl*) data ;
91 wxWindow* focus = thisWindow ;
93 unsigned char charCode ;
101 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
104 ByteCount dataSize = 0 ;
105 if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr )
108 int numChars = dataSize / sizeof( UniChar) + 1;
110 UniChar* charBuf = buf ;
112 if ( numChars * 2 > 4 )
113 charBuf = new UniChar[ numChars ] ;
114 GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ;
115 charBuf[ numChars - 1 ] = 0;
117 #if SIZEOF_WCHAR_T == 2
118 uniChar = charBuf[0] ;
120 wxMBConvUTF16 converter ;
121 converter.MB2WC( uniChar , (const char*)charBuf , 2 ) ;
124 if ( numChars * 2 > 4 )
129 GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode );
130 GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
131 GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers );
132 GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &point );
134 UInt32 message = (keyCode << 8) + charCode;
135 switch ( GetEventKind( event ) )
137 case kEventRawKeyRepeat :
138 case kEventRawKeyDown :
140 WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ;
141 WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
142 wxTheApp->MacSetCurrentEvent( event , handler ) ;
143 if ( /* focus && */ wxTheApp->MacSendKeyDownEvent(
144 focus , message , modifiers , when , point.h , point.v , uniChar[0] ) )
148 wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
152 case kEventRawKeyUp :
153 if ( /* focus && */ wxTheApp->MacSendKeyUpEvent(
154 focus , message , modifiers , when , point.h , point.v , uniChar[0] ) )
160 case kEventRawKeyModifiersChanged :
162 wxKeyEvent event(wxEVT_KEY_DOWN);
164 event.m_shiftDown = modifiers & shiftKey;
165 event.m_controlDown = modifiers & controlKey;
166 event.m_altDown = modifiers & optionKey;
167 event.m_metaDown = modifiers & cmdKey;
172 event.m_uniChar = uniChar[0] ;
175 event.SetTimestamp(when);
176 event.SetEventObject(focus);
178 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & controlKey )
180 event.m_keyCode = WXK_CONTROL ;
181 event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
182 focus->GetEventHandler()->ProcessEvent( event ) ;
184 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & shiftKey )
186 event.m_keyCode = WXK_SHIFT ;
187 event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
188 focus->GetEventHandler()->ProcessEvent( event ) ;
190 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & optionKey )
192 event.m_keyCode = WXK_ALT ;
193 event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
194 focus->GetEventHandler()->ProcessEvent( event ) ;
196 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & cmdKey )
198 event.m_keyCode = WXK_COMMAND ;
199 event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
200 focus->GetEventHandler()->ProcessEvent( event ) ;
203 wxApp::s_lastModifiers = modifiers ;
214 static pascal OSStatus wxWebKitCtrlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
216 OSStatus result = eventNotHandledErr ;
218 wxMacCarbonEvent cEvent( event ) ;
220 ControlRef controlRef ;
221 wxWebKitCtrl* thisWindow = (wxWebKitCtrl*) data ;
222 wxNonOwnedWindow* tlw = NULL;
224 tlw = thisWindow->MacGetTopLevelWindow();
226 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
228 wxWindow* currentMouseWindow = thisWindow ;
230 if ( wxApp::s_captureWindow )
231 currentMouseWindow = wxApp::s_captureWindow;
233 switch ( GetEventClass( event ) )
235 case kEventClassKeyboard:
237 result = wxWebKitKeyEventHandler(handler, event, data);
241 case kEventClassTextInput:
243 result = wxMacUnicodeTextEventHandler(handler, event, data);
247 case kEventClassMouse:
249 switch ( GetEventKind( event ) )
251 case kEventMouseDragged :
252 case kEventMouseMoved :
253 case kEventMouseDown :
256 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
257 SetupMouseEvent( wxevent , cEvent ) ;
259 currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
260 wxevent.SetEventObject( currentMouseWindow ) ;
261 wxevent.SetId( currentMouseWindow->GetId() ) ;
263 if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) )
268 break; // this should enable WebKit to fire mouse dragged and mouse up events...
278 result = CallNextEventHandler(handler, event);
282 DEFINE_ONE_SHOT_HANDLER_GETTER( wxWebKitCtrlEventHandler )
285 // ----------------------------------------------------------------------------
287 // ----------------------------------------------------------------------------
289 IMPLEMENT_DYNAMIC_CLASS( wxWebKitStateChangedEvent, wxCommandEvent )
291 DEFINE_EVENT_TYPE( wxEVT_WEBKIT_STATE_CHANGED )
293 wxWebKitStateChangedEvent::wxWebKitStateChangedEvent( wxWindow* win )
295 SetEventType( wxEVT_WEBKIT_STATE_CHANGED);
298 SetEventObject( win );
303 IMPLEMENT_DYNAMIC_CLASS( wxWebKitBeforeLoadEvent, wxCommandEvent )
305 DEFINE_EVENT_TYPE( wxEVT_WEBKIT_BEFORE_LOAD )
307 wxWebKitBeforeLoadEvent::wxWebKitBeforeLoadEvent( wxWindow* win )
310 SetEventType( wxEVT_WEBKIT_BEFORE_LOAD);
313 SetEventObject( win );
319 IMPLEMENT_DYNAMIC_CLASS( wxWebKitNewWindowEvent, wxCommandEvent )
321 DEFINE_EVENT_TYPE( wxEVT_WEBKIT_NEW_WINDOW )
323 wxWebKitNewWindowEvent::wxWebKitNewWindowEvent( wxWindow* win )
325 SetEventType( wxEVT_WEBKIT_NEW_WINDOW);
328 SetEventObject( win );
335 //---------------------------------------------------------
336 // helper functions for NSString<->wxString conversion
337 //---------------------------------------------------------
339 inline wxString wxStringWithNSString(NSString *nsstring)
342 return wxString([nsstring UTF8String], wxConvUTF8);
344 return wxString([nsstring lossyCString]);
345 #endif // wxUSE_UNICODE
348 inline NSString* wxNSStringWithWxString(const wxString &wxstring)
351 return [NSString stringWithUTF8String: wxstring.mb_str(wxConvUTF8)];
353 return [NSString stringWithCString: wxstring.c_str() length:wxstring.Len()];
354 #endif // wxUSE_UNICODE
357 inline int wxNavTypeFromWebNavType(int type){
358 if (type == WebNavigationTypeLinkClicked)
359 return wxWEBKIT_NAV_LINK_CLICKED;
361 if (type == WebNavigationTypeFormSubmitted)
362 return wxWEBKIT_NAV_FORM_SUBMITTED;
364 if (type == WebNavigationTypeBackForward)
365 return wxWEBKIT_NAV_BACK_NEXT;
367 if (type == WebNavigationTypeReload)
368 return wxWEBKIT_NAV_RELOAD;
370 if (type == WebNavigationTypeFormResubmitted)
371 return wxWEBKIT_NAV_FORM_RESUBMITTED;
373 return wxWEBKIT_NAV_OTHER;
376 @interface MyFrameLoadMonitor : NSObject
378 wxWebKitCtrl* webKitWindow;
381 - initWithWxWindow: (wxWebKitCtrl*)inWindow;
385 @interface MyPolicyDelegate : NSObject
387 wxWebKitCtrl* webKitWindow;
390 - initWithWxWindow: (wxWebKitCtrl*)inWindow;
394 // ----------------------------------------------------------------------------
395 // creation/destruction
396 // ----------------------------------------------------------------------------
398 bool wxWebKitCtrl::Create(wxWindow *parent,
400 const wxString& strURL,
402 const wxSize& size, long style,
403 const wxValidator& validator,
404 const wxString& name)
407 m_currentURL = strURL;
408 //m_pageTitle = _("Untitled Page");
410 //still needed for wxCocoa??
414 if (size.x == wxDefaultCoord || size.y == wxDefaultCoord)
416 m_parent->GetClientSize(&width, &height);
417 sizeInstance.x = width;
418 sizeInstance.y = height;
422 sizeInstance.x = size.x;
423 sizeInstance.y = size.y;
426 // now create and attach WebKit view...
428 wxControl::Create(parent, m_windowID, pos, sizeInstance, style , validator , name);
429 SetSize(pos.x, pos.y, sizeInstance.x, sizeInstance.y);
431 wxTopLevelWindowCocoa *topWin = wxDynamicCast(this, wxTopLevelWindowCocoa);
432 NSWindow* nsWin = topWin->GetNSWindow();
434 rect.origin.x = pos.x;
435 rect.origin.y = pos.y;
436 rect.size.width = sizeInstance.x;
437 rect.size.height = sizeInstance.y;
438 m_webView = (WebView*)[[WebView alloc] initWithFrame:rect frameName:@"webkitFrame" groupName:@"webkitGroup"];
439 SetNSView(m_webView);
440 [m_cocoaNSView release];
442 if(m_parent) m_parent->CocoaAddChild(this);
443 SetInitialFrameRect(pos,sizeInstance);
445 m_macIsUserPane = false;
446 wxControl::Create(parent, winID, pos, size, style , validator , name);
447 m_peer = new wxMacControl(this);
449 HIWebViewCreate( m_peer->GetControlRefAddr() );
451 m_webView = (WebView*) HIWebViewGetWebView( m_peer->GetControlRef() );
453 MacPostControlCreate(pos, size);
454 HIViewSetVisible( m_peer->GetControlRef(), true );
455 [m_webView setHidden:false];
456 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
457 if ( UMAGetSystemVersion() >= 0x1030 )
458 HIViewChangeFeatures( m_peer->GetControlRef() , kHIViewIsOpaque , 0 ) ;
460 InstallControlEventHandler( m_peer->GetControlRef() , GetwxWebKitCtrlEventHandlerUPP(),
461 GetEventTypeCount(eventList), eventList, this,
462 (EventHandlerRef *)&m_webKitCtrlEventHandler);
466 // Register event listener interfaces
467 MyFrameLoadMonitor* myFrameLoadMonitor = [[MyFrameLoadMonitor alloc] initWithWxWindow: this];
468 [m_webView setFrameLoadDelegate:myFrameLoadMonitor];
470 // this is used to veto page loads, etc.
471 MyPolicyDelegate* myPolicyDelegate = [[MyPolicyDelegate alloc] initWithWxWindow: this];
472 [m_webView setPolicyDelegate:myPolicyDelegate];
474 LoadURL(m_currentURL);
478 wxWebKitCtrl::~wxWebKitCtrl()
480 MyFrameLoadMonitor* myFrameLoadMonitor = [m_webView frameLoadDelegate];
481 MyPolicyDelegate* myPolicyDelegate = [m_webView policyDelegate];
482 [m_webView setFrameLoadDelegate: nil];
483 [m_webView setPolicyDelegate: nil];
485 if (myFrameLoadMonitor)
486 [myFrameLoadMonitor release];
488 if (myPolicyDelegate)
489 [myPolicyDelegate release];
492 // ----------------------------------------------------------------------------
494 // ----------------------------------------------------------------------------
496 void wxWebKitCtrl::LoadURL(const wxString &url)
501 [[m_webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:wxNSStringWithWxString(url)]]];
506 bool wxWebKitCtrl::CanGoBack(){
510 return [m_webView canGoBack];
513 bool wxWebKitCtrl::CanGoForward(){
517 return [m_webView canGoForward];
520 bool wxWebKitCtrl::GoBack(){
524 bool result = [(WebView*)m_webView goBack];
528 bool wxWebKitCtrl::GoForward(){
532 bool result = [(WebView*)m_webView goForward];
536 void wxWebKitCtrl::Reload(){
540 [[m_webView mainFrame] reload];
543 void wxWebKitCtrl::Stop(){
547 [[m_webView mainFrame] stopLoading];
550 bool wxWebKitCtrl::CanGetPageSource(){
554 WebDataSource* dataSource = [[m_webView mainFrame] dataSource];
555 return ( [[dataSource representation] canProvideDocumentSource] );
558 wxString wxWebKitCtrl::GetPageSource(){
560 if (CanGetPageSource()){
561 WebDataSource* dataSource = [[m_webView mainFrame] dataSource];
562 return wxStringWithNSString( [[dataSource representation] documentSource] );
565 return wxEmptyString;
568 wxString wxWebKitCtrl::GetSelection(){
570 return wxEmptyString;
572 NSString* selectedText = [[m_webView selectedDOMRange] toString];
573 return wxStringWithNSString( selectedText );
576 bool wxWebKitCtrl::CanIncreaseTextSize(){
580 if ([m_webView canMakeTextLarger])
586 void wxWebKitCtrl::IncreaseTextSize(){
590 if (CanIncreaseTextSize())
591 [m_webView makeTextLarger:(WebView*)m_webView];
594 bool wxWebKitCtrl::CanDecreaseTextSize(){
598 if ([m_webView canMakeTextSmaller])
604 void wxWebKitCtrl::DecreaseTextSize(){
608 if (CanDecreaseTextSize())
609 [m_webView makeTextSmaller:(WebView*)m_webView];
612 void wxWebKitCtrl::SetPageSource(const wxString& source, const wxString& baseUrl){
616 [[m_webView mainFrame] loadHTMLString:(NSString*)wxNSStringWithWxString( source ) baseURL:[NSURL URLWithString:wxNSStringWithWxString( baseUrl )]];
620 void wxWebKitCtrl::Print(bool showPrompt){
624 id view = [[[m_webView mainFrame] frameView] documentView];
625 NSPrintOperation *op = [NSPrintOperation printOperationWithView:view printInfo: [NSPrintInfo sharedPrintInfo]];
627 [op setShowsPrintPanel: showPrompt];
628 // in my tests, the progress bar always freezes and it stops the whole print operation.
629 // do not turn this to true unless there is a workaround for the bug.
630 [op setShowsProgressPanel: false];
636 void wxWebKitCtrl::MakeEditable(bool enable){
640 [m_webView setEditable:enable ];
643 bool wxWebKitCtrl::IsEditable(){
647 return [m_webView isEditable];
650 int wxWebKitCtrl::GetScrollPos(){
651 id result = [[m_webView windowScriptObject] evaluateWebScript:@"document.body.scrollTop"];
652 return [result intValue];
655 void wxWebKitCtrl::SetScrollPos(int pos){
660 javascript.Printf(wxT("document.body.scrollTop = %d;"), pos);
661 [[m_webView windowScriptObject] evaluateWebScript:(NSString*)wxNSStringWithWxString( javascript )];
664 wxString wxWebKitCtrl::RunScript(const wxString& javascript){
666 return wxEmptyString;
668 id result = [[m_webView windowScriptObject] evaluateWebScript:(NSString*)wxNSStringWithWxString( javascript )];
670 NSString* resultAsString;
671 wxString resultAsWxString = wxEmptyString;
672 NSString* className = NSStringFromClass([result class]);
673 if ([className isEqualToString:@"NSCFNumber"])
674 resultAsString = [NSString stringWithFormat:@"%@", result];
675 else if ([className isEqualToString:@"NSCFString"])
676 resultAsString = result;
677 else if ([className isEqualToString:@"NSCFBoolean"]){
678 if ([result boolValue])
679 resultAsString = @"true";
681 resultAsString = @"false";
683 else if ([className isEqualToString:@"WebScriptObject"])
684 resultAsString = [result stringRepresentation];
686 fprintf(stderr, "wxWebKitCtrl::RunScript - Unexpected return type: %s!\n", [className UTF8String]);
688 resultAsWxString = wxStringWithNSString( resultAsString );
689 return resultAsWxString;
692 void wxWebKitCtrl::OnSize(wxSizeEvent &event){
693 // This is a nasty hack because WebKit seems to lose its position when it is embedded
694 // in a control that is not itself the content view for a TLW.
695 // I put it in OnSize because these calcs are not perfect, and in fact are basically
696 // guesses based on reverse engineering, so it's best to give people the option of
697 // overriding OnSize with their own calcs if need be.
698 // I also left some test debugging print statements as a convenience if a(nother)
701 wxWindow* tlw = MacGetTopLevelWindow();
703 NSRect frame = [(WebView*)m_webView frame];
704 NSRect bounds = [(WebView*)m_webView bounds];
706 #if DEBUG_WEBKIT_SIZING
707 fprintf(stderr,"Carbon window x=%d, y=%d, width=%d, height=%d\n", GetPosition().x, GetPosition().y, GetSize().x, GetSize().y);
708 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);
709 fprintf(stderr, "Cocoa window bounds x=%G, y=%G, width=%G, height=%G\n", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
712 // This must be the case that Apple tested with, because well, in this one case
713 // we don't need to do anything! It just works. ;)
714 if (GetParent() == tlw){
718 // since we no longer use parent coordinates, we always want 0,0.
726 #if DEBUG_WEBKIT_SIZING
727 printf("Before conversion, origin is: x = %d, y = %d\n", x, y);
730 // NB: In most cases, when calling HIViewConvertRect, what people want is to use GetRootControl(),
731 // and this tripped me up at first. But in fact, what we want is the root view, because we need to
732 // make the y origin relative to the very top of the window, not its contents, since we later flip
733 // the y coordinate for Cocoa.
734 HIViewConvertRect (&rect, m_peer->GetControlRef(),
735 HIViewGetRoot( (WindowRef) MacGetTopLevelWindowRef() ) );
737 x = (int)rect.origin.x;
738 y = (int)rect.origin.y;
740 #if DEBUG_WEBKIT_SIZING
741 printf("Moving Cocoa frame origin to: x = %d, y = %d\n", x, y);
745 //flip the y coordinate to convert to Cocoa coordinates
746 y = tlw->GetSize().y - ((GetSize().y) + y);
749 #if DEBUG_WEBKIT_SIZING
750 printf("y = %d after flipping value\n", y);
755 [(WebView*)m_webView setFrame:frame];
758 [(WebView*)m_webView display];
762 void wxWebKitCtrl::MacVisibilityChanged(){
763 bool isHidden = !IsControlVisible( m_peer->GetControlRef());
765 [(WebView*)m_webView display];
767 [m_webView setHidden:isHidden];
770 //------------------------------------------------------------
771 // Listener interfaces
772 //------------------------------------------------------------
774 // NB: I'm still tracking this down, but it appears the Cocoa window
775 // still has these events fired on it while the Carbon control is being
776 // destroyed. Therefore, we must be careful to check both the existence
777 // of the Carbon control and the event handler before firing events.
779 @implementation MyFrameLoadMonitor
781 - initWithWxWindow: (wxWebKitCtrl*)inWindow
784 webKitWindow = inWindow; // non retained
788 - (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
790 if (webKitWindow && frame == [sender mainFrame]){
791 NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString];
792 wxWebKitStateChangedEvent thisEvent(webKitWindow);
793 thisEvent.SetState(wxWEBKIT_STATE_NEGOTIATING);
794 thisEvent.SetURL( wxStringWithNSString( url ) );
795 if (webKitWindow->GetEventHandler())
796 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
800 - (void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame
802 if (webKitWindow && frame == [sender mainFrame]){
803 NSString *url = [[[[frame dataSource] request] URL] absoluteString];
804 wxWebKitStateChangedEvent thisEvent(webKitWindow);
805 thisEvent.SetState(wxWEBKIT_STATE_TRANSFERRING);
806 thisEvent.SetURL( wxStringWithNSString( url ) );
807 if (webKitWindow->GetEventHandler())
808 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
812 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
814 if (webKitWindow && frame == [sender mainFrame]){
815 NSString *url = [[[[frame dataSource] request] URL] absoluteString];
816 wxWebKitStateChangedEvent thisEvent(webKitWindow);
817 thisEvent.SetState(wxWEBKIT_STATE_STOP);
818 thisEvent.SetURL( wxStringWithNSString( url ) );
819 if (webKitWindow->GetEventHandler())
820 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
824 - (void)webView:(WebView *)sender didFailLoadWithError:(NSError*) error forFrame:(WebFrame *)frame
828 if (webKitWindow && frame == [sender mainFrame]){
829 NSString *url = [[[[frame dataSource] request] URL] absoluteString];
830 wxWebKitStateChangedEvent thisEvent(webKitWindow);
831 thisEvent.SetState(wxWEBKIT_STATE_FAILED);
832 thisEvent.SetURL( wxStringWithNSString( url ) );
833 if (webKitWindow->GetEventHandler())
834 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
838 - (void)webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError*) error forFrame:(WebFrame *)frame
842 if (webKitWindow && frame == [sender mainFrame]){
843 NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString];
844 wxWebKitStateChangedEvent thisEvent(webKitWindow);
845 thisEvent.SetState(wxWEBKIT_STATE_FAILED);
846 thisEvent.SetURL( wxStringWithNSString( url ) );
847 if (webKitWindow->GetEventHandler())
848 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
852 - (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame
854 if (webKitWindow && frame == [sender mainFrame]){
855 webKitWindow->SetPageTitle(wxStringWithNSString( title ));
860 @implementation MyPolicyDelegate
862 - initWithWxWindow: (wxWebKitCtrl*)inWindow
865 webKitWindow = inWindow; // non retained
869 - (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener
874 wxWebKitBeforeLoadEvent thisEvent(webKitWindow);
876 // Get the navigation type.
877 NSNumber *n = [actionInformation objectForKey:WebActionNavigationTypeKey];
878 int actionType = [n intValue];
879 thisEvent.SetNavigationType( wxNavTypeFromWebNavType(actionType) );
881 NSString *url = [[request URL] absoluteString];
882 thisEvent.SetURL( wxStringWithNSString( url ) );
884 if (webKitWindow && webKitWindow->GetEventHandler())
885 webKitWindow->GetEventHandler()->ProcessEvent(thisEvent);
887 if (thisEvent.IsCancelled())
893 - (void)webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id < WebPolicyDecisionListener >)listener
895 wxWebKitNewWindowEvent thisEvent(webKitWindow);
897 NSString *url = [[request URL] absoluteString];
898 thisEvent.SetURL( wxStringWithNSString( url ) );
899 thisEvent.SetTargetName( wxStringWithNSString( frameName ) );
901 if (webKitWindow && webKitWindow->GetEventHandler())
902 webKitWindow->GetEventHandler()->ProcessEvent(thisEvent);
908 #endif //wxUSE_WEBKIT