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/mac/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 wxTopLevelWindowMac* 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);
296 SetEventObject( win );
300 IMPLEMENT_DYNAMIC_CLASS( wxWebKitBeforeLoadEvent, wxCommandEvent )
302 DEFINE_EVENT_TYPE( wxEVT_WEBKIT_BEFORE_LOAD )
304 wxWebKitBeforeLoadEvent::wxWebKitBeforeLoadEvent( wxWindow* win )
307 SetEventType( wxEVT_WEBKIT_BEFORE_LOAD);
308 SetEventObject( win );
312 //---------------------------------------------------------
313 // helper functions for NSString<->wxString conversion
314 //---------------------------------------------------------
316 inline wxString wxStringWithNSString(NSString *nsstring)
319 return wxString([nsstring UTF8String], wxConvUTF8);
321 return wxString([nsstring lossyCString]);
322 #endif // wxUSE_UNICODE
325 inline NSString* wxNSStringWithWxString(const wxString &wxstring)
328 return [NSString stringWithUTF8String: wxstring.mb_str(wxConvUTF8)];
330 return [NSString stringWithCString: wxstring.c_str() length:wxstring.Len()];
331 #endif // wxUSE_UNICODE
334 inline int wxNavTypeFromWebNavType(int type){
335 if (type == WebNavigationTypeLinkClicked)
336 return wxWEBKIT_NAV_LINK_CLICKED;
338 if (type == WebNavigationTypeFormSubmitted)
339 return wxWEBKIT_NAV_FORM_SUBMITTED;
341 if (type == WebNavigationTypeBackForward)
342 return wxWEBKIT_NAV_BACK_NEXT;
344 if (type == WebNavigationTypeReload)
345 return wxWEBKIT_NAV_RELOAD;
347 if (type == WebNavigationTypeFormResubmitted)
348 return wxWEBKIT_NAV_FORM_RESUBMITTED;
350 return wxWEBKIT_NAV_OTHER;
353 @interface MyFrameLoadMonitor : NSObject
355 wxWebKitCtrl* webKitWindow;
358 - initWithWxWindow: (wxWebKitCtrl*)inWindow;
362 @interface MyPolicyDelegate : NSObject
364 wxWebKitCtrl* webKitWindow;
367 - initWithWxWindow: (wxWebKitCtrl*)inWindow;
371 // ----------------------------------------------------------------------------
372 // creation/destruction
373 // ----------------------------------------------------------------------------
375 bool wxWebKitCtrl::Create(wxWindow *parent,
377 const wxString& strURL,
379 const wxSize& size, long style,
380 const wxValidator& validator,
381 const wxString& name)
384 m_currentURL = strURL;
385 //m_pageTitle = _("Untitled Page");
387 //still needed for wxCocoa??
391 if (size.x == wxDefaultCoord || size.y == wxDefaultCoord)
393 m_parent->GetClientSize(&width, &height);
394 sizeInstance.x = width;
395 sizeInstance.y = height;
399 sizeInstance.x = size.x;
400 sizeInstance.y = size.y;
403 // now create and attach WebKit view...
405 wxControl::Create(parent, m_windowID, pos, sizeInstance, style , validator , name);
406 SetSize(pos.x, pos.y, sizeInstance.x, sizeInstance.y);
408 wxTopLevelWindowCocoa *topWin = wxDynamicCast(this, wxTopLevelWindowCocoa);
409 NSWindow* nsWin = topWin->GetNSWindow();
411 rect.origin.x = pos.x;
412 rect.origin.y = pos.y;
413 rect.size.width = sizeInstance.x;
414 rect.size.height = sizeInstance.y;
415 m_webView = (WebView*)[[WebView alloc] initWithFrame:rect frameName:@"webkitFrame" groupName:@"webkitGroup"];
416 SetNSView(m_webView);
417 [m_cocoaNSView release];
419 if(m_parent) m_parent->CocoaAddChild(this);
420 SetInitialFrameRect(pos,sizeInstance);
422 m_macIsUserPane = false;
423 wxControl::Create(parent, winID, pos, size, style , validator , name);
424 m_peer = new wxMacControl(this);
426 HIWebViewCreate( m_peer->GetControlRefAddr() );
428 m_webView = (WebView*) HIWebViewGetWebView( m_peer->GetControlRef() );
430 MacPostControlCreate(pos, size);
431 HIViewSetVisible( m_peer->GetControlRef(), true );
432 [m_webView setHidden:false];
433 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
434 if ( UMAGetSystemVersion() >= 0x1030 )
435 HIViewChangeFeatures( m_peer->GetControlRef() , kHIViewIsOpaque , 0 ) ;
437 InstallControlEventHandler( m_peer->GetControlRef() , GetwxWebKitCtrlEventHandlerUPP(),
438 GetEventTypeCount(eventList), eventList, this,
439 (EventHandlerRef *)&m_webKitCtrlEventHandler);
443 // Register event listener interfaces
444 MyFrameLoadMonitor* myFrameLoadMonitor = [[MyFrameLoadMonitor alloc] initWithWxWindow: this];
445 [m_webView setFrameLoadDelegate:myFrameLoadMonitor];
447 // this is used to veto page loads, etc.
448 MyPolicyDelegate* myPolicyDelegate = [[MyPolicyDelegate alloc] initWithWxWindow: this];
449 [m_webView setPolicyDelegate:myPolicyDelegate];
451 LoadURL(m_currentURL);
455 wxWebKitCtrl::~wxWebKitCtrl()
460 // ----------------------------------------------------------------------------
462 // ----------------------------------------------------------------------------
464 void wxWebKitCtrl::LoadURL(const wxString &url)
469 [[m_webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:wxNSStringWithWxString(url)]]];
474 bool wxWebKitCtrl::CanGoBack(){
478 return [m_webView canGoBack];
481 bool wxWebKitCtrl::CanGoForward(){
485 return [m_webView canGoForward];
488 bool wxWebKitCtrl::GoBack(){
492 bool result = [(WebView*)m_webView goBack];
496 bool wxWebKitCtrl::GoForward(){
500 bool result = [(WebView*)m_webView goForward];
504 void wxWebKitCtrl::Reload(){
508 [[m_webView mainFrame] reload];
511 void wxWebKitCtrl::Stop(){
515 [[m_webView mainFrame] stopLoading];
518 bool wxWebKitCtrl::CanGetPageSource(){
522 WebDataSource* dataSource = [[m_webView mainFrame] dataSource];
523 return ( [[dataSource representation] canProvideDocumentSource] );
526 wxString wxWebKitCtrl::GetPageSource(){
528 if (CanGetPageSource()){
529 WebDataSource* dataSource = [[m_webView mainFrame] dataSource];
530 return wxStringWithNSString( [[dataSource representation] documentSource] );
533 return wxEmptyString;
536 wxString wxWebKitCtrl::GetSelection(){
538 return wxEmptyString;
540 NSString* selectedText = [[m_webView selectedDOMRange] toString];
541 return wxStringWithNSString( selectedText );
544 bool wxWebKitCtrl::CanIncreaseTextSize(){
548 if ([m_webView canMakeTextLarger])
554 void wxWebKitCtrl::IncreaseTextSize(){
558 if (CanIncreaseTextSize())
559 [m_webView makeTextLarger:(WebView*)m_webView];
562 bool wxWebKitCtrl::CanDecreaseTextSize(){
566 if ([m_webView canMakeTextSmaller])
572 void wxWebKitCtrl::DecreaseTextSize(){
576 if (CanDecreaseTextSize())
577 [m_webView makeTextSmaller:(WebView*)m_webView];
580 void wxWebKitCtrl::SetPageSource(const wxString& source, const wxString& baseUrl){
584 [[m_webView mainFrame] loadHTMLString:(NSString*)wxNSStringWithWxString( source ) baseURL:[NSURL URLWithString:wxNSStringWithWxString( baseUrl )]];
588 void wxWebKitCtrl::Print(bool showPrompt){
592 id view = [[[m_webView mainFrame] frameView] documentView];
593 NSPrintOperation *op = [NSPrintOperation printOperationWithView:view printInfo: [NSPrintInfo sharedPrintInfo]];
595 [op setShowsPrintPanel: showPrompt];
596 // in my tests, the progress bar always freezes and it stops the whole print operation.
597 // do not turn this to true unless there is a workaround for the bug.
598 [op setShowsProgressPanel: false];
604 void wxWebKitCtrl::MakeEditable(bool enable){
608 [m_webView setEditable:enable ];
611 bool wxWebKitCtrl::IsEditable(){
615 return [m_webView isEditable];
618 int wxWebKitCtrl::GetScrollPos(){
619 id result = [[m_webView windowScriptObject] evaluateWebScript:@"document.body.scrollTop"];
620 return [result intValue];
623 void wxWebKitCtrl::SetScrollPos(int pos){
628 javascript.Printf(wxT("document.body.scrollTop = %d;"), pos);
629 [[m_webView windowScriptObject] evaluateWebScript:(NSString*)wxNSStringWithWxString( javascript )];
632 wxString wxWebKitCtrl::RunScript(const wxString& javascript){
634 return wxEmptyString;
636 id result = [[m_webView windowScriptObject] evaluateWebScript:(NSString*)wxNSStringWithWxString( javascript )];
638 NSString* resultAsString;
639 wxString resultAsWxString = wxEmptyString;
640 NSString* className = NSStringFromClass([result class]);
641 if ([className isEqualToString:@"NSCFNumber"])
642 resultAsString = [NSString stringWithFormat:@"%@", result];
643 else if ([className isEqualToString:@"NSCFString"])
644 resultAsString = result;
645 else if ([className isEqualToString:@"NSCFBoolean"]){
646 if ([result boolValue])
647 resultAsString = @"true";
649 resultAsString = @"false";
651 else if ([className isEqualToString:@"WebScriptObject"])
652 resultAsString = [result stringRepresentation];
654 fprintf(stderr, "wxWebKitCtrl::RunScript - Unexpected return type: %s!\n", [className UTF8String]);
656 resultAsWxString = wxStringWithNSString( resultAsString );
657 return resultAsWxString;
660 void wxWebKitCtrl::OnSize(wxSizeEvent &event){
661 // This is a nasty hack because WebKit seems to lose its position when it is embedded
662 // in a control that is not itself the content view for a TLW.
663 // I put it in OnSize because these calcs are not perfect, and in fact are basically
664 // guesses based on reverse engineering, so it's best to give people the option of
665 // overriding OnSize with their own calcs if need be.
666 // I also left some test debugging print statements as a convenience if a(nother)
669 wxWindow* tlw = MacGetTopLevelWindow();
671 NSRect frame = [m_webView frame];
672 NSRect bounds = [m_webView bounds];
674 #if DEBUG_WEBKIT_SIZING
675 fprintf(stderr,"Carbon window x=%d, y=%d, width=%d, height=%d\n", GetPosition().x, GetPosition().y, GetSize().x, GetSize().y);
676 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);
677 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);
680 // This must be the case that Apple tested with, because well, in this one case
681 // we don't need to do anything! It just works. ;)
682 if (GetParent() == tlw){
686 // since we no longer use parent coordinates, we always want 0,0.
694 #if DEBUG_WEBKIT_SIZING
695 printf("Before conversion, origin is: x = %d, y = %d\n", x, y);
698 // NB: In most cases, when calling HIViewConvertRect, what people want is to use GetRootControl(),
699 // and this tripped me up at first. But in fact, what we want is the root view, because we need to
700 // make the y origin relative to the very top of the window, not its contents, since we later flip
701 // the y coordinate for Cocoa.
702 HIViewConvertRect (&rect, m_peer->GetControlRef(),
703 HIViewGetRoot( (WindowRef) MacGetTopLevelWindowRef() ) );
705 x = (int)rect.origin.x;
706 y = (int)rect.origin.y;
708 #if DEBUG_WEBKIT_SIZING
709 printf("Moving Cocoa frame origin to: x = %d, y = %d\n", x, y);
713 //flip the y coordinate to convert to Cocoa coordinates
714 y = tlw->GetSize().y - ((GetSize().y) + y);
717 #if DEBUG_WEBKIT_SIZING
718 printf("y = %d after flipping value\n", y);
723 [m_webView setFrame:frame];
726 [(WebView*)m_webView display];
730 void wxWebKitCtrl::MacVisibilityChanged(){
731 bool isHidden = !IsControlVisible( m_peer->GetControlRef());
733 [(WebView*)m_webView display];
735 [m_webView setHidden:isHidden];
738 //------------------------------------------------------------
739 // Listener interfaces
740 //------------------------------------------------------------
742 // NB: I'm still tracking this down, but it appears the Cocoa window
743 // still has these events fired on it while the Carbon control is being
744 // destroyed. Therefore, we must be careful to check both the existence
745 // of the Carbon control and the event handler before firing events.
747 @implementation MyFrameLoadMonitor
749 - initWithWxWindow: (wxWebKitCtrl*)inWindow
752 webKitWindow = inWindow; // non retained
756 - (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
758 if (webKitWindow && frame == [sender mainFrame]){
759 NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString];
760 wxWebKitStateChangedEvent thisEvent(webKitWindow);
761 thisEvent.SetState(wxWEBKIT_STATE_NEGOTIATING);
762 thisEvent.SetURL( wxStringWithNSString( url ) );
763 if (webKitWindow->GetEventHandler())
764 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
768 - (void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame
770 if (webKitWindow && frame == [sender mainFrame]){
771 NSString *url = [[[[frame dataSource] request] URL] absoluteString];
772 wxWebKitStateChangedEvent thisEvent(webKitWindow);
773 thisEvent.SetState(wxWEBKIT_STATE_TRANSFERRING);
774 thisEvent.SetURL( wxStringWithNSString( url ) );
775 if (webKitWindow->GetEventHandler())
776 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
780 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
782 if (webKitWindow && frame == [sender mainFrame]){
783 NSString *url = [[[[frame dataSource] request] URL] absoluteString];
784 wxWebKitStateChangedEvent thisEvent(webKitWindow);
785 thisEvent.SetState(wxWEBKIT_STATE_STOP);
786 thisEvent.SetURL( wxStringWithNSString( url ) );
787 if (webKitWindow->GetEventHandler())
788 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
792 - (void)webView:(WebView *)sender didFailLoadWithError:(NSError*) error forFrame:(WebFrame *)frame
796 if (webKitWindow && frame == [sender mainFrame]){
797 NSString *url = [[[[frame dataSource] request] URL] absoluteString];
798 wxWebKitStateChangedEvent thisEvent(webKitWindow);
799 thisEvent.SetState(wxWEBKIT_STATE_FAILED);
800 thisEvent.SetURL( wxStringWithNSString( url ) );
801 if (webKitWindow->GetEventHandler())
802 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
806 - (void)webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError*) error forFrame:(WebFrame *)frame
810 if (webKitWindow && frame == [sender mainFrame]){
811 NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString];
812 wxWebKitStateChangedEvent thisEvent(webKitWindow);
813 thisEvent.SetState(wxWEBKIT_STATE_FAILED);
814 thisEvent.SetURL( wxStringWithNSString( url ) );
815 if (webKitWindow->GetEventHandler())
816 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
820 - (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame
822 if (webKitWindow && frame == [sender mainFrame]){
823 webKitWindow->SetPageTitle(wxStringWithNSString( title ));
828 @implementation MyPolicyDelegate
830 - initWithWxWindow: (wxWebKitCtrl*)inWindow
833 webKitWindow = inWindow; // non retained
837 - (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener
842 wxWebKitBeforeLoadEvent thisEvent(webKitWindow);
844 // Get the navigation type.
845 NSNumber *n = [actionInformation objectForKey:WebActionNavigationTypeKey];
846 int actionType = [n intValue];
847 thisEvent.SetNavigationType( wxNavTypeFromWebNavType(actionType) );
849 NSString *url = [[request URL] absoluteString];
850 thisEvent.SetURL( wxStringWithNSString( url ) );
852 if (webKitWindow && webKitWindow->GetEventHandler())
853 webKitWindow->GetEventHandler()->ProcessEvent(thisEvent);
855 if (thisEvent.IsCancelled())
863 #endif //wxUSE_WEBKIT