1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/htmlctrl/webkit/webkit.mm
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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14 #include "wx/splitter.h"
23 #include "wx/cocoa/autorelease.h"
25 #include "wx/osx/private.h"
27 #include <WebKit/WebKit.h>
28 #include <WebKit/HIWebView.h>
29 #include <WebKit/CarbonUtils.h>
32 #include "wx/html/webkit.h"
34 #define DEBUG_WEBKIT_SIZING 0
36 extern WXDLLEXPORT_DATA(const char) wxWebKitCtrlNameStr[] = "webkitctrl";
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 IMPLEMENT_DYNAMIC_CLASS(wxWebKitCtrl, wxControl)
44 BEGIN_EVENT_TABLE(wxWebKitCtrl, wxControl)
45 #if defined(__WXMAC__) && wxOSX_USE_CARBON
46 EVT_SIZE(wxWebKitCtrl::OnSize)
50 #if defined(__WXOSX__) && wxOSX_USE_CARBON
52 // ----------------------------------------------------------------------------
53 // Carbon Events handlers
54 // ----------------------------------------------------------------------------
56 // prototype for function in src/osx/carbon/nonownedwnd.cpp
57 void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent );
59 static const EventTypeSpec eventList[] =
61 //{ kEventClassControl, kEventControlTrack } ,
62 { kEventClassMouse, kEventMouseUp },
63 { kEventClassMouse, kEventMouseDown },
64 { kEventClassMouse, kEventMouseMoved },
65 { kEventClassMouse, kEventMouseDragged },
67 { kEventClassKeyboard, kEventRawKeyDown } ,
68 { kEventClassKeyboard, kEventRawKeyRepeat } ,
69 { kEventClassKeyboard, kEventRawKeyUp } ,
70 { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
72 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
73 { kEventClassTextInput, kEventTextInputUpdateActiveInputArea } ,
75 #if DEBUG_WEBKIT_SIZING == 1
76 { kEventClassControl, kEventControlBoundsChanged } ,
80 // mix this in from window.cpp
81 pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
83 // NOTE: This is mostly taken from KeyboardEventHandler in toplevel.cpp, but
84 // that expects the data pointer is a top-level window, so I needed to change
85 // that in this case. However, once 2.8 is out, we should factor out the common logic
86 // among the two functions and merge them.
87 static pascal OSStatus wxWebKitKeyEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
89 OSStatus result = eventNotHandledErr ;
90 wxMacCarbonEvent cEvent( event ) ;
92 wxWebKitCtrl* thisWindow = (wxWebKitCtrl*) data ;
93 wxWindow* focus = thisWindow ;
95 unsigned char charCode ;
102 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
105 ByteCount dataSize = 0 ;
106 if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr )
109 int numChars = dataSize / sizeof( UniChar) + 1;
111 UniChar* charBuf = buf ;
113 if ( numChars * 2 > 4 )
114 charBuf = new UniChar[ numChars ] ;
115 GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ;
116 charBuf[ numChars - 1 ] = 0;
118 #if SIZEOF_WCHAR_T == 2
119 uniChar = charBuf[0] ;
121 wxMBConvUTF16 converter ;
122 converter.MB2WC( uniChar , (const char*)charBuf , 2 ) ;
125 if ( numChars * 2 > 4 )
130 GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode );
131 GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
132 GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers );
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 , uniChar[0] ) )
148 wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
152 case kEventRawKeyUp :
153 if ( /* focus && */ wxTheApp->MacSendKeyUpEvent(
154 focus , message , modifiers , when , uniChar[0] ) )
160 case kEventRawKeyModifiersChanged :
162 wxKeyEvent event(wxEVT_KEY_DOWN);
164 event.m_shiftDown = modifiers & shiftKey;
165 event.m_rawControlDown = modifiers & controlKey;
166 event.m_altDown = modifiers & optionKey;
167 event.m_controlDown = modifiers & cmdKey;
170 event.m_uniChar = uniChar[0] ;
173 event.SetTimestamp(when);
174 event.SetEventObject(focus);
176 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & controlKey )
178 event.m_keyCode = WXK_RAW_CONTROL ;
179 event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
180 focus->GetEventHandler()->ProcessEvent( event ) ;
182 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & shiftKey )
184 event.m_keyCode = WXK_SHIFT ;
185 event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
186 focus->GetEventHandler()->ProcessEvent( event ) ;
188 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & optionKey )
190 event.m_keyCode = WXK_ALT ;
191 event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
192 focus->GetEventHandler()->ProcessEvent( event ) ;
194 if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & cmdKey )
196 event.m_keyCode = WXK_CONTROL ;
197 event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
198 focus->GetEventHandler()->ProcessEvent( event ) ;
201 wxApp::s_lastModifiers = modifiers ;
212 static pascal OSStatus wxWebKitCtrlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
214 OSStatus result = eventNotHandledErr ;
216 wxMacCarbonEvent cEvent( event ) ;
218 ControlRef controlRef ;
219 wxWebKitCtrl* thisWindow = (wxWebKitCtrl*) data ;
220 wxNonOwnedWindow* tlw = NULL;
222 tlw = thisWindow->MacGetTopLevelWindow();
224 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
226 wxWindow* currentMouseWindow = thisWindow ;
228 if ( wxApp::s_captureWindow )
229 currentMouseWindow = wxApp::s_captureWindow;
231 switch ( GetEventClass( event ) )
233 case kEventClassKeyboard:
235 result = wxWebKitKeyEventHandler(handler, event, data);
239 case kEventClassTextInput:
241 result = wxMacUnicodeTextEventHandler(handler, event, data);
245 case kEventClassMouse:
247 switch ( GetEventKind( event ) )
249 case kEventMouseDragged :
250 case kEventMouseMoved :
251 case kEventMouseDown :
254 wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
255 SetupMouseEvent( wxevent , cEvent ) ;
257 currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
258 wxevent.SetEventObject( currentMouseWindow ) ;
259 wxevent.SetId( currentMouseWindow->GetId() ) ;
261 if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) )
266 break; // this should enable WebKit to fire mouse dragged and mouse up events...
276 result = CallNextEventHandler(handler, event);
280 DEFINE_ONE_SHOT_HANDLER_GETTER( wxWebKitCtrlEventHandler )
284 // ----------------------------------------------------------------------------
286 // ----------------------------------------------------------------------------
288 IMPLEMENT_DYNAMIC_CLASS( wxWebKitStateChangedEvent, wxCommandEvent )
290 wxDEFINE_EVENT( wxEVT_WEBKIT_STATE_CHANGED, wxWebKitStateChangedEvent );
292 wxWebKitStateChangedEvent::wxWebKitStateChangedEvent( wxWindow* win )
294 SetEventType( wxEVT_WEBKIT_STATE_CHANGED);
297 SetEventObject( win );
302 IMPLEMENT_DYNAMIC_CLASS( wxWebKitBeforeLoadEvent, wxCommandEvent )
304 wxDEFINE_EVENT( wxEVT_WEBKIT_BEFORE_LOAD, wxWebKitBeforeLoadEvent );
306 wxWebKitBeforeLoadEvent::wxWebKitBeforeLoadEvent( wxWindow* win )
309 SetEventType( wxEVT_WEBKIT_BEFORE_LOAD);
312 SetEventObject( win );
318 IMPLEMENT_DYNAMIC_CLASS( wxWebKitNewWindowEvent, wxCommandEvent )
320 wxDEFINE_EVENT( wxEVT_WEBKIT_NEW_WINDOW, wxWebKitNewWindowEvent );
322 wxWebKitNewWindowEvent::wxWebKitNewWindowEvent( wxWindow* win )
324 SetEventType( wxEVT_WEBKIT_NEW_WINDOW);
327 SetEventObject( win );
334 //---------------------------------------------------------
335 // helper functions for NSString<->wxString conversion
336 //---------------------------------------------------------
338 inline wxString wxStringWithNSString(NSString *nsstring)
341 return wxString([nsstring UTF8String], wxConvUTF8);
343 return wxString([nsstring lossyCString]);
344 #endif // wxUSE_UNICODE
347 inline NSString* wxNSStringWithWxString(const wxString &wxstring)
350 return [NSString stringWithUTF8String: wxstring.mb_str(wxConvUTF8)];
352 return [NSString stringWithCString: wxstring.c_str() length:wxstring.Len()];
353 #endif // wxUSE_UNICODE
356 inline int wxNavTypeFromWebNavType(int type){
357 if (type == WebNavigationTypeLinkClicked)
358 return wxWEBKIT_NAV_LINK_CLICKED;
360 if (type == WebNavigationTypeFormSubmitted)
361 return wxWEBKIT_NAV_FORM_SUBMITTED;
363 if (type == WebNavigationTypeBackForward)
364 return wxWEBKIT_NAV_BACK_NEXT;
366 if (type == WebNavigationTypeReload)
367 return wxWEBKIT_NAV_RELOAD;
369 if (type == WebNavigationTypeFormResubmitted)
370 return wxWEBKIT_NAV_FORM_RESUBMITTED;
372 return wxWEBKIT_NAV_OTHER;
375 @interface MyFrameLoadMonitor : NSObject
377 wxWebKitCtrl* webKitWindow;
380 - initWithWxWindow: (wxWebKitCtrl*)inWindow;
384 @interface MyPolicyDelegate : NSObject
386 wxWebKitCtrl* webKitWindow;
389 - initWithWxWindow: (wxWebKitCtrl*)inWindow;
393 // ----------------------------------------------------------------------------
394 // creation/destruction
395 // ----------------------------------------------------------------------------
397 bool wxWebKitCtrl::Create(wxWindow *parent,
399 const wxString& strURL,
401 const wxSize& size, long style,
402 const wxValidator& validator,
403 const wxString& name)
405 m_currentURL = strURL;
406 //m_pageTitle = _("Untitled Page");
408 //still needed for wxCocoa??
412 if (size.x == wxDefaultCoord || size.y == wxDefaultCoord)
414 m_parent->GetClientSize(&width, &height);
415 sizeInstance.x = width;
416 sizeInstance.y = height;
420 sizeInstance.x = size.x;
421 sizeInstance.y = size.y;
424 // now create and attach WebKit view...
427 wxControl::Create(parent, m_windowID, pos, sizeInstance, style , validator , name);
428 SetSize(pos.x, pos.y, sizeInstance.x, sizeInstance.y);
430 wxTopLevelWindowCocoa *topWin = wxDynamicCast(this, wxTopLevelWindowCocoa);
431 NSWindow* nsWin = topWin->GetNSWindow();
433 rect.origin.x = pos.x;
434 rect.origin.y = pos.y;
435 rect.size.width = sizeInstance.x;
436 rect.size.height = sizeInstance.y;
437 m_webView = (WebView*)[[WebView alloc] initWithFrame:rect frameName:@"webkitFrame" groupName:@"webkitGroup"];
438 SetNSView(m_webView);
439 [m_cocoaNSView release];
441 if(m_parent) m_parent->CocoaAddChild(this);
442 SetInitialFrameRect(pos,sizeInstance);
445 wxControl::Create(parent, winID, pos, size, style , validator , name);
447 wxMacControl* peer = new wxMacControl(this);
449 HIWebViewCreate( peer->GetControlRefAddr() );
451 m_webView = (WebView*) HIWebViewGetWebView( peer->GetControlRef() );
453 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
454 if ( UMAGetSystemVersion() >= 0x1030 )
455 HIViewChangeFeatures( peer->GetControlRef() , kHIViewIsOpaque , 0 ) ;
457 InstallControlEventHandler( peer->GetControlRef() , GetwxWebKitCtrlEventHandlerUPP(),
458 GetEventTypeCount(eventList), eventList, this,
459 (EventHandlerRef *)&m_webKitCtrlEventHandler);
463 NSRect r = wxOSXGetFrameForControl( this, pos , size ) ;
464 m_webView = [[WebView alloc] initWithFrame:r frameName:@"webkitFrame" groupName:@"webkitGroup"];
466 SetPeer(new wxWidgetCocoaImpl( this, m_webView ));
468 MacPostControlCreate(pos, size);
470 HIViewSetVisible( GetPeer()->GetControlRef(), true );
472 [m_webView setHidden:false];
476 // Register event listener interfaces
477 MyFrameLoadMonitor* myFrameLoadMonitor = [[MyFrameLoadMonitor alloc] initWithWxWindow: this];
478 [m_webView setFrameLoadDelegate:myFrameLoadMonitor];
480 // this is used to veto page loads, etc.
481 MyPolicyDelegate* myPolicyDelegate = [[MyPolicyDelegate alloc] initWithWxWindow: this];
482 [m_webView setPolicyDelegate:myPolicyDelegate];
484 LoadURL(m_currentURL);
488 wxWebKitCtrl::~wxWebKitCtrl()
490 MyFrameLoadMonitor* myFrameLoadMonitor = [m_webView frameLoadDelegate];
491 MyPolicyDelegate* myPolicyDelegate = [m_webView policyDelegate];
492 [m_webView setFrameLoadDelegate: nil];
493 [m_webView setPolicyDelegate: nil];
495 if (myFrameLoadMonitor)
496 [myFrameLoadMonitor release];
498 if (myPolicyDelegate)
499 [myPolicyDelegate release];
502 // ----------------------------------------------------------------------------
504 // ----------------------------------------------------------------------------
506 void wxWebKitCtrl::LoadURL(const wxString &url)
511 [[m_webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:wxNSStringWithWxString(url)]]];
516 bool wxWebKitCtrl::CanGoBack(){
520 return [m_webView canGoBack];
523 bool wxWebKitCtrl::CanGoForward(){
527 return [m_webView canGoForward];
530 bool wxWebKitCtrl::GoBack(){
534 bool result = [(WebView*)m_webView goBack];
538 bool wxWebKitCtrl::GoForward(){
542 bool result = [(WebView*)m_webView goForward];
546 void wxWebKitCtrl::Reload(){
550 [[m_webView mainFrame] reload];
553 void wxWebKitCtrl::Stop(){
557 [[m_webView mainFrame] stopLoading];
560 bool wxWebKitCtrl::CanGetPageSource(){
564 WebDataSource* dataSource = [[m_webView mainFrame] dataSource];
565 return ( [[dataSource representation] canProvideDocumentSource] );
568 wxString wxWebKitCtrl::GetPageSource(){
570 if (CanGetPageSource()){
571 WebDataSource* dataSource = [[m_webView mainFrame] dataSource];
572 return wxStringWithNSString( [[dataSource representation] documentSource] );
575 return wxEmptyString;
578 wxString wxWebKitCtrl::GetSelection(){
580 return wxEmptyString;
582 NSString* selectedText = [[m_webView selectedDOMRange] toString];
583 return wxStringWithNSString( selectedText );
586 bool wxWebKitCtrl::CanIncreaseTextSize(){
590 if ([m_webView canMakeTextLarger])
596 void wxWebKitCtrl::IncreaseTextSize(){
600 if (CanIncreaseTextSize())
601 [m_webView makeTextLarger:(WebView*)m_webView];
604 bool wxWebKitCtrl::CanDecreaseTextSize(){
608 if ([m_webView canMakeTextSmaller])
614 void wxWebKitCtrl::DecreaseTextSize(){
618 if (CanDecreaseTextSize())
619 [m_webView makeTextSmaller:(WebView*)m_webView];
622 void wxWebKitCtrl::SetPageSource(const wxString& source, const wxString& baseUrl){
626 [[m_webView mainFrame] loadHTMLString:(NSString*)wxNSStringWithWxString( source ) baseURL:[NSURL URLWithString:wxNSStringWithWxString( baseUrl )]];
630 void wxWebKitCtrl::Print(bool showPrompt){
634 id view = [[[m_webView mainFrame] frameView] documentView];
635 NSPrintOperation *op = [NSPrintOperation printOperationWithView:view printInfo: [NSPrintInfo sharedPrintInfo]];
637 [op setShowsPrintPanel: showPrompt];
638 // in my tests, the progress bar always freezes and it stops the whole print operation.
639 // do not turn this to true unless there is a workaround for the bug.
640 [op setShowsProgressPanel: false];
646 void wxWebKitCtrl::MakeEditable(bool enable){
650 [m_webView setEditable:enable ];
653 bool wxWebKitCtrl::IsEditable(){
657 return [m_webView isEditable];
660 int wxWebKitCtrl::GetScrollPos(){
661 id result = [[m_webView windowScriptObject] evaluateWebScript:@"document.body.scrollTop"];
662 return [result intValue];
665 void wxWebKitCtrl::SetScrollPos(int pos){
670 javascript.Printf(wxT("document.body.scrollTop = %d;"), pos);
671 [[m_webView windowScriptObject] evaluateWebScript:(NSString*)wxNSStringWithWxString( javascript )];
674 wxString wxWebKitCtrl::RunScript(const wxString& javascript){
676 return wxEmptyString;
678 id result = [[m_webView windowScriptObject] evaluateWebScript:(NSString*)wxNSStringWithWxString( javascript )];
680 NSString* resultAsString;
681 if ([result isKindOfClass:[NSNumber class]]){
682 // __NSCFBoolean is a subclass of NSNumber
683 if (strcmp([result objCType], @encode(BOOL)) == 0){
684 if ([result boolValue])
685 resultAsString = @"true";
687 resultAsString = @"false";
690 resultAsString = [NSString stringWithFormat:@"%@", result];
692 else if ([result isKindOfClass:[NSString class]])
693 resultAsString = result;
694 else if ([result isKindOfClass:[WebScriptObject class]])
695 resultAsString = [result stringRepresentation];
697 return wxString(); // This can happen, see e.g. #12361.
699 return wxStringWithNSString( resultAsString );
702 void wxWebKitCtrl::OnSize(wxSizeEvent &event){
703 #if defined(__WXMAC__) && wxOSX_USE_CARBON
704 // This is a nasty hack because WebKit seems to lose its position when it is embedded
705 // in a control that is not itself the content view for a TLW.
706 // I put it in OnSize because these calcs are not perfect, and in fact are basically
707 // guesses based on reverse engineering, so it's best to give people the option of
708 // overriding OnSize with their own calcs if need be.
709 // I also left some test debugging print statements as a convenience if a(nother)
712 wxWindow* tlw = MacGetTopLevelWindow();
714 NSRect frame = [(WebView*)m_webView frame];
715 NSRect bounds = [(WebView*)m_webView bounds];
717 #if DEBUG_WEBKIT_SIZING
718 fprintf(stderr,"Carbon window x=%d, y=%d, width=%d, height=%d\n", GetPosition().x, GetPosition().y, GetSize().x, GetSize().y);
719 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);
720 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);
723 // This must be the case that Apple tested with, because well, in this one case
724 // we don't need to do anything! It just works. ;)
725 if (GetParent() == tlw){
729 // since we no longer use parent coordinates, we always want 0,0.
737 #if DEBUG_WEBKIT_SIZING
738 printf("Before conversion, origin is: x = %d, y = %d\n", x, y);
741 // NB: In most cases, when calling HIViewConvertRect, what people want is to use GetRootControl(),
742 // and this tripped me up at first. But in fact, what we want is the root view, because we need to
743 // make the y origin relative to the very top of the window, not its contents, since we later flip
744 // the y coordinate for Cocoa.
745 HIViewConvertRect (&rect, GetPeer()->GetControlRef(),
746 HIViewGetRoot( (WindowRef) MacGetTopLevelWindowRef() ) );
748 x = (int)rect.origin.x;
749 y = (int)rect.origin.y;
751 #if DEBUG_WEBKIT_SIZING
752 printf("Moving Cocoa frame origin to: x = %d, y = %d\n", x, y);
756 //flip the y coordinate to convert to Cocoa coordinates
757 y = tlw->GetSize().y - ((GetSize().y) + y);
760 #if DEBUG_WEBKIT_SIZING
761 printf("y = %d after flipping value\n", y);
766 [(WebView*)m_webView setFrame:frame];
769 [(WebView*)m_webView display];
774 void wxWebKitCtrl::MacVisibilityChanged(){
775 #if defined(__WXMAC__) && wxOSX_USE_CARBON
776 bool isHidden = !IsControlVisible( GetPeer()->GetControlRef());
778 [(WebView*)m_webView display];
780 [m_webView setHidden:isHidden];
784 //------------------------------------------------------------
785 // Listener interfaces
786 //------------------------------------------------------------
788 // NB: I'm still tracking this down, but it appears the Cocoa window
789 // still has these events fired on it while the Carbon control is being
790 // destroyed. Therefore, we must be careful to check both the existence
791 // of the Carbon control and the event handler before firing events.
793 @implementation MyFrameLoadMonitor
795 - initWithWxWindow: (wxWebKitCtrl*)inWindow
798 webKitWindow = inWindow; // non retained
802 - (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
804 if (webKitWindow && frame == [sender mainFrame]){
805 NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString];
806 wxWebKitStateChangedEvent thisEvent(webKitWindow);
807 thisEvent.SetState(wxWEBKIT_STATE_NEGOTIATING);
808 thisEvent.SetURL( wxStringWithNSString( url ) );
809 if (webKitWindow->GetEventHandler())
810 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
814 - (void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame
816 if (webKitWindow && frame == [sender mainFrame]){
817 NSString *url = [[[[frame dataSource] request] URL] absoluteString];
818 wxWebKitStateChangedEvent thisEvent(webKitWindow);
819 thisEvent.SetState(wxWEBKIT_STATE_TRANSFERRING);
820 thisEvent.SetURL( wxStringWithNSString( url ) );
821 if (webKitWindow->GetEventHandler())
822 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
826 - (void)webView:(WebView *)sender didFinishLoadForFrame:(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_STOP);
832 thisEvent.SetURL( wxStringWithNSString( url ) );
833 if (webKitWindow->GetEventHandler())
834 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
838 - (void)webView:(WebView *)sender didFailLoadWithError:(NSError*) error forFrame:(WebFrame *)frame
842 if (webKitWindow && frame == [sender mainFrame]){
843 NSString *url = [[[[frame dataSource] 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 didFailProvisionalLoadWithError:(NSError*) error forFrame:(WebFrame *)frame
856 if (webKitWindow && frame == [sender mainFrame]){
857 NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString];
858 wxWebKitStateChangedEvent thisEvent(webKitWindow);
859 thisEvent.SetState(wxWEBKIT_STATE_FAILED);
860 thisEvent.SetURL( wxStringWithNSString( url ) );
861 if (webKitWindow->GetEventHandler())
862 webKitWindow->GetEventHandler()->ProcessEvent( thisEvent );
866 - (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame
868 if (webKitWindow && frame == [sender mainFrame]){
869 webKitWindow->SetPageTitle(wxStringWithNSString( title ));
874 @implementation MyPolicyDelegate
876 - initWithWxWindow: (wxWebKitCtrl*)inWindow
879 webKitWindow = inWindow; // non retained
883 - (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener
888 wxWebKitBeforeLoadEvent thisEvent(webKitWindow);
890 // Get the navigation type.
891 NSNumber *n = [actionInformation objectForKey:WebActionNavigationTypeKey];
892 int actionType = [n intValue];
893 thisEvent.SetNavigationType( wxNavTypeFromWebNavType(actionType) );
895 NSString *url = [[request URL] absoluteString];
896 thisEvent.SetURL( wxStringWithNSString( url ) );
898 if (webKitWindow && webKitWindow->GetEventHandler())
899 webKitWindow->GetEventHandler()->ProcessEvent(thisEvent);
901 if (thisEvent.IsCancelled())
907 - (void)webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id < WebPolicyDecisionListener >)listener
910 wxUnusedVar(actionInformation);
911 wxWebKitNewWindowEvent thisEvent(webKitWindow);
913 NSString *url = [[request URL] absoluteString];
914 thisEvent.SetURL( wxStringWithNSString( url ) );
915 thisEvent.SetTargetName( wxStringWithNSString( frameName ) );
917 if (webKitWindow && webKitWindow->GetEventHandler())
918 webKitWindow->GetEventHandler()->ProcessEvent(thisEvent);
924 #endif //wxUSE_WEBKIT