2010-05-27 Jb Evain <jbevain@novell.com>
[mcs.git] / class / Mono.WebBrowser / Mono.Mozilla / Callback.cs
blob87e01ace3b87a0353cf4643d0cff4344f1dc7cf6
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2007 Novell, Inc.
22 // Authors:
23 // Andreia Gaita (avidigal@novell.com)
26 #undef debug
28 using System;
29 using System.Text;
30 using System.Runtime.InteropServices;
31 using System.Diagnostics;
33 namespace Mono.Mozilla {
35 using Mono.WebBrowser;
36 using Mono.WebBrowser.DOM;
38 internal class Callback
40 WebBrowser owner;
41 string currentUri;
42 bool calledLoadStarted;
44 public Callback (WebBrowser owner)
46 this.owner = owner;
50 #region Events
52 public void OnWidgetLoaded ()
54 #if debug
55 OnGeneric ("OnWidgetLoaded");
56 #endif
60 public void OnStateChange (nsIWebProgress progress, nsIRequest request, Int32 status, UInt32 state)
62 if (!owner.created)
63 owner.created = true;
65 #if debug
66 //OnGeneric ("OnStateChange");
68 System.Text.StringBuilder s = new System.Text.StringBuilder ();
69 if ((state & (uint) StateFlags.Start) != 0) {
70 s.Append ("Start\t");
72 if ((state & (uint) StateFlags.Redirecting) != 0) {
73 s.Append ("Redirecting\t");
75 if ((state & (uint) StateFlags.Transferring) != 0) {
76 s.Append ("Transferring\t");
78 if ((state & (uint) StateFlags.Negotiating) != 0) {
79 s.Append ("Negotiating\t");
81 if ((state & (uint) StateFlags.Stop) != 0) {
82 s.Append ("Stop\t");
84 if ((state & (uint) StateFlags.IsRequest) != 0) {
85 s.Append ("Request\t");
87 if ((state & (uint) StateFlags.IsDocument) != 0) {
88 s.Append ("Document\t");
90 if ((state & (uint) StateFlags.IsNetwork) != 0) {
91 s.Append ("Network\t");
93 if ((state & (uint) StateFlags.IsWindow) != 0) {
94 s.Append ("Window\t");
96 Console.Error.WriteLine (s.ToString ());
97 #endif
99 bool _start = (state & (uint) StateFlags.Start) != 0;
100 bool _negotiating = (state & (uint) StateFlags.Negotiating) != 0;
101 bool _transferring = (state & (uint) StateFlags.Transferring) != 0;
102 bool _redirecting = (state & (uint) StateFlags.Redirecting) != 0;
103 bool _stop = (state & (uint) StateFlags.Stop) != 0;
104 bool _request = (state & (uint) StateFlags.IsRequest) != 0;
105 bool _document = (state & (uint) StateFlags.IsDocument) != 0;
106 bool _network = (state & (uint) StateFlags.IsNetwork) != 0;
107 bool _window = (state & (uint) StateFlags.IsWindow) != 0;
109 if (_start && _request && _document && !calledLoadStarted) {
110 nsIDOMWindow win;
111 progress.getDOMWindow (out win);
112 nsIChannel channel = (nsIChannel) request;
113 nsIURI uri;
114 channel.getURI (out uri);
115 if (uri == null)
116 currentUri = "about:blank";
117 else {
118 AsciiString spec = new AsciiString (String.Empty);
119 uri.getSpec (spec.Handle);
120 currentUri = spec.ToString ();
123 calledLoadStarted = true;
124 LoadStartedEventHandler eh = (LoadStartedEventHandler) (owner.Events [WebBrowser.LoadStartedEvent]);
125 if (eh != null) {
127 AsciiString name = new AsciiString (String.Empty);
128 win.getName (name.Handle);
130 LoadStartedEventArgs e = new LoadStartedEventArgs (currentUri, name.ToString ());
131 eh (this, e);
132 if (e.Cancel)
133 request.cancel (2152398850); //NS_BINDING_ABORTED
135 return;
139 if (_document && _request && _transferring) {
140 nsIDOMWindow win;
141 progress.getDOMWindow (out win);
142 nsIChannel channel = (nsIChannel) request;
143 nsIURI uri;
144 channel.getURI (out uri);
145 if (uri == null)
146 currentUri = "about:blank";
147 else {
148 AsciiString spec = new AsciiString (String.Empty);
149 uri.getSpec (spec.Handle);
150 currentUri = spec.ToString ();
153 nsIDOMWindow topWin;
154 win.getTop (out topWin);
155 if (topWin == null || topWin.GetHashCode () == win.GetHashCode ()) {
156 owner.Reset ();
157 nsIDOMDocument doc;
158 win.getDocument (out doc);
159 if (doc != null)
160 owner.document = new Mono.Mozilla.DOM.Document (owner, doc);
163 LoadCommitedEventHandler eh = (LoadCommitedEventHandler) (owner.Events[WebBrowser.LoadCommitedEvent]);
164 if (eh != null) {
165 LoadCommitedEventArgs e = new LoadCommitedEventArgs (currentUri);
166 eh (this, e);
168 return;
171 if (_document && _request && _redirecting) {
172 nsIDOMWindow win;
173 progress.getDOMWindow (out win);
174 nsIChannel channel = (nsIChannel) request;
175 nsIURI uri;
176 channel.getURI (out uri);
177 if (uri == null)
178 currentUri = "about:blank";
179 else {
180 AsciiString spec = new AsciiString (String.Empty);
181 uri.getSpec (spec.Handle);
182 currentUri = spec.ToString ();
184 return;
187 if (_stop && !_request && !_document && _network && _window) {
188 calledLoadStarted = false;
189 LoadFinishedEventHandler eh1 = (LoadFinishedEventHandler) (owner.Events[WebBrowser.LoadFinishedEvent]);
190 if (eh1 != null) {
192 nsIDOMWindow win;
193 progress.getDOMWindow (out win);
194 LoadFinishedEventArgs e = new LoadFinishedEventArgs (currentUri);
195 eh1 (this, e);
198 return;
201 if (_stop && !_request && _document && !_network && !_window) {
202 nsIDOMWindow win;
203 progress.getDOMWindow (out win);
204 nsIDOMDocument doc;
205 win.getDocument (out doc);
206 if (doc != null) {
207 int hash = doc.GetHashCode ();
208 if (owner.documents.ContainsKey (hash)) {
209 DOM.Document document = owner.documents[hash] as DOM.Document;
211 EventHandler eh1 = (EventHandler)(document.Events[DOM.Document.LoadStoppedEvent]);
212 if (eh1 != null)
213 eh1 (this, null);
216 calledLoadStarted = false;
217 return;
219 #if debug
220 Console.Error.WriteLine ("{0} completed", s.ToString ());
221 #endif
224 public void OnProgress (nsIWebProgress progress, nsIRequest request, Int32 currentTotalProgress, Int32 maxTotalProgress)
226 #if debug
227 OnGeneric ("OnProgress");
228 #endif
229 ProgressChangedEventHandler eh = (ProgressChangedEventHandler) (owner.Events [Mono.Mozilla.WebBrowser.ProgressChangedEvent]);
230 if (eh != null) {
231 Mono.WebBrowser.ProgressChangedEventArgs e = new Mono.WebBrowser.ProgressChangedEventArgs (currentTotalProgress, maxTotalProgress);
232 eh (this, e);
236 public void OnLocationChanged (nsIWebProgress progress, nsIRequest request, nsIURI uri)
238 #if debug
239 OnGeneric ("OnLocationChanged");
240 #endif
243 public void OnStatusChange (nsIWebProgress progress, nsIRequest request, string message, Int32 status)
245 StatusChangedEventHandler eh = (StatusChangedEventHandler) (owner.Events[WebBrowser.StatusChangedEvent]);
246 if (eh != null) {
247 StatusChangedEventArgs e = new StatusChangedEventArgs (message, status);
248 eh (this, e);
252 public void OnSecurityChange (nsIWebProgress progress, nsIRequest request, uint status)
254 SecurityChangedEventHandler eh = (SecurityChangedEventHandler) (owner.Events[WebBrowser.SecurityChangedEvent]);
255 if (eh != null) {
256 SecurityLevel state = SecurityLevel.Insecure;
257 switch (status) {
258 case 4:
259 state = SecurityLevel.Insecure;
260 break;
261 case 1:
262 state = SecurityLevel.Mixed;
263 break;
264 case 2:
265 state = SecurityLevel.Secure;
266 break;
269 SecurityChangedEventArgs e = new SecurityChangedEventArgs (state);
270 eh (this, e);
274 public bool OnClientDomKeyDown (KeyInfo keyInfo, ModifierKeys modifiers, nsIDOMNode target)
276 #if debug
277 OnGeneric ("OnClientDomKeyDown");
278 Console.Error.WriteLine ("OnClientDomKeyDown");
279 #endif
280 INode node = new Mono.Mozilla.DOM.Node (owner, target);
281 string key = String.Intern (node.GetHashCode () + ":keydown");
282 EventHandler eh1 = (EventHandler) owner.DomEvents[key];
283 if (eh1 != null) {
284 EventArgs e1 = new EventArgs ();
285 eh1 (node, e1);
288 NodeEventHandler eh = (NodeEventHandler) (owner.Events[WebBrowser.KeyDownEvent]);
289 if (eh != null) {
290 NodeEventArgs e = new NodeEventArgs (node);
291 eh (this, e);
292 return true;
294 return false;
297 public bool OnClientDomKeyUp (KeyInfo keyInfo, ModifierKeys modifiers, nsIDOMNode target)
299 #if debug
300 OnGeneric ("OnClientDomKeyUp");
301 Console.Error.WriteLine ("OnClientDomKeyUp");
302 #endif
303 INode node = new Mono.Mozilla.DOM.Node (owner, target);
304 string key = String.Intern (node.GetHashCode () + ":keyup");
305 EventHandler eh1 = (EventHandler) owner.DomEvents[key];
306 if (eh1 != null) {
307 EventArgs e1 = new EventArgs ();
308 eh1 (node, e1);
311 NodeEventHandler eh = (NodeEventHandler) (owner.Events[WebBrowser.KeyUpEvent]);
312 if (eh != null) {
313 NodeEventArgs e = new NodeEventArgs (node);
314 eh (this, e);
315 return true;
317 return false;
320 public bool OnClientDomKeyPress (KeyInfo keyInfo, ModifierKeys modifiers, nsIDOMNode target)
322 #if debug
323 OnGeneric ("OnClientDomKeyPress");
324 Console.Error.WriteLine ("OnClientDomKeyPress");
325 #endif
326 INode node = new Mono.Mozilla.DOM.Node (owner, target);
327 string key = String.Intern (node.GetHashCode () + ":keypress");
328 EventHandler eh1 = (EventHandler) owner.DomEvents[key];
329 if (eh1 != null) {
330 EventArgs e1 = new EventArgs ();
331 eh1 (node, e1);
334 NodeEventHandler eh = (NodeEventHandler) (owner.Events[WebBrowser.KeyPressEvent]);
335 if (eh != null) {
336 NodeEventArgs e = new NodeEventArgs (node);
337 eh (this, e);
338 return true;
340 return false;
343 public bool OnClientMouseDown (MouseInfo mouseInfo, ModifierKeys modifiers, nsIDOMNode target)
345 #if debug
346 OnGeneric ("OnClientMouseDown");
347 Console.Error.WriteLine ("OnClientMouseDown");
348 #endif
349 INode node = new Mono.Mozilla.DOM.Node (owner, target);
350 string key = String.Intern (node.GetHashCode () + ":mousedown");
351 EventHandler eh1 = (EventHandler) owner.DomEvents[key];
352 if (eh1 != null) {
353 EventArgs e1 = new EventArgs ();
354 eh1 (node, e1);
357 NodeEventHandler eh = (NodeEventHandler) (owner.Events[WebBrowser.MouseDownEvent]);
358 if (eh != null) {
359 NodeEventArgs e = new NodeEventArgs (node);
360 eh (this, e);
361 return true;
363 return false;
366 public bool OnClientMouseUp (MouseInfo mouseInfo, ModifierKeys modifiers, nsIDOMNode target)
368 #if debug
369 OnGeneric ("OnClientMouseUp");
370 Console.Error.WriteLine ("OnClientMouseUp");
371 #endif
372 INode node = new Mono.Mozilla.DOM.Node (owner, target);
373 string key = String.Intern (node.GetHashCode () + ":mouseup");
374 EventHandler eh1 = (EventHandler) owner.DomEvents[key];
375 if (eh1 != null) {
376 EventArgs e1 = new EventArgs ();
377 eh1 (node, e1);
380 NodeEventHandler eh = (NodeEventHandler) (owner.Events[WebBrowser.MouseUpEvent]);
381 if (eh != null) {
382 NodeEventArgs e = new NodeEventArgs (node);
383 eh (this, e);
384 return true;
386 return false;
389 public bool OnClientMouseClick (MouseInfo mouseInfo, ModifierKeys modifiers, nsIDOMNode target)
391 #if debug
392 OnGeneric ("OnClientMouseClick");
393 Console.Error.WriteLine ("OnClientMouseClick");
394 #endif
395 INode node = new Mono.Mozilla.DOM.Node (owner, target);
396 string key = String.Intern (node.GetHashCode () + ":click");
397 EventHandler eh1 = (EventHandler) owner.DomEvents[key];
398 if (eh1 != null) {
399 EventArgs e1 = new EventArgs ();
400 eh1 (node, e1);
403 NodeEventHandler eh = (NodeEventHandler) (owner.Events[WebBrowser.MouseClickEvent]);
404 if (eh != null) {
405 NodeEventArgs e = new NodeEventArgs (node);
406 eh (this, e);
407 return true;
409 return false;
412 public bool OnClientMouseDoubleClick (MouseInfo mouseInfo, ModifierKeys modifiers, nsIDOMNode target)
414 #if debug
415 OnGeneric ("OnClientMouseDoubleClick");
416 Console.Error.WriteLine ("OnClientMouseDoubleClick");
417 #endif
418 INode node = new Mono.Mozilla.DOM.Node (owner, target);
419 string key = String.Intern (node.GetHashCode () + ":dblclick");
420 EventHandler eh1 = (EventHandler) owner.DomEvents[key];
421 if (eh1 != null) {
422 EventArgs e1 = new EventArgs ();
423 eh1 (node, e1);
426 NodeEventHandler eh = (NodeEventHandler) (owner.Events[WebBrowser.MouseDoubleClickEvent]);
427 if (eh != null) {
428 NodeEventArgs e = new NodeEventArgs (node);
429 eh (this, e);
430 return true;
432 return false;
435 public bool OnClientMouseOver (MouseInfo mouseInfo, ModifierKeys modifiers, nsIDOMNode target)
437 #if debug
438 OnGeneric ("OnClientMouseOver");
439 Console.Error.WriteLine ("OnClientMouseOver");
440 #endif
441 DOM.DOMObject helper = new DOM.DOMObject(this.owner);
442 INode node = helper.GetTypedNode (target);
443 string key = String.Intern (node.GetHashCode () + ":mouseover");
444 EventHandler eh1 = (EventHandler) owner.DomEvents[key];
445 if (eh1 != null) {
446 EventArgs e1 = new EventArgs ();
447 eh1 (node, e1);
450 NodeEventHandler eh = (NodeEventHandler) (owner.Events[WebBrowser.MouseEnterEvent]);
451 if (eh != null) {
452 NodeEventArgs e = new NodeEventArgs (node);
453 eh (node, e);
454 return true;
456 return false;
459 public bool OnClientMouseOut (MouseInfo mouseInfo, ModifierKeys modifiers, nsIDOMNode target)
461 #if debug
462 OnGeneric ("OnClientMouseOut");
463 Console.Error.WriteLine ("OnClientMouseOut");
464 #endif
465 INode node = new Mono.Mozilla.DOM.Node (owner, target);
466 string key = String.Intern (node.GetHashCode () + ":mouseout");
467 EventHandler eh1 = (EventHandler) owner.DomEvents[key];
468 if (eh1 != null) {
469 EventArgs e1 = new EventArgs ();
470 eh1 (node, e1);
473 NodeEventHandler eh = (NodeEventHandler) (owner.Events[WebBrowser.MouseLeaveEvent]);
474 if (eh != null) {
475 NodeEventArgs e = new NodeEventArgs (node);
476 eh (this, e);
477 return true;
479 return false;
482 public bool OnClientActivate ()
484 #if debug
485 OnGeneric ("OnClientActivate");
486 Console.Error.WriteLine ("OnClientActivate");
487 #endif
488 // TODO: Add WebBrowser.OnClientActivate implementation
489 return false;
492 public bool OnClientFocus ()
494 #if debug
495 OnGeneric ("OnClientFocus");
496 Console.Error.WriteLine ("OnClientFocus");
497 #endif
498 EventHandler eh = (EventHandler) (owner.Events[WebBrowser.FocusEvent]);
499 if (eh != null) {
500 EventArgs e = new EventArgs ();
501 eh (this, e);
503 return false;
506 public bool OnClientBlur ()
508 #if debug
509 OnGeneric ("OnClientBlur");
510 Console.Error.WriteLine ("OnClientBlur");
511 #endif
512 EventHandler eh = (EventHandler) (owner.Events[WebBrowser.BlurEvent]);
513 if (eh != null) {
514 EventArgs e = new EventArgs ();
515 eh (this, e);
517 return false;
520 public bool OnCreateNewWindow ()
522 bool ret = false;
524 #if debug
525 OnGeneric ("OnCreateNewWindow");
526 Console.Error.WriteLine ("OnCreateNewWindow");
527 #endif
528 CreateNewWindowEventHandler eh = (CreateNewWindowEventHandler) (owner.Events[WebBrowser.CreateNewWindowEvent]);
529 if (eh != null) {
530 CreateNewWindowEventArgs e = new CreateNewWindowEventArgs (false);
531 ret = eh (this, e);
533 return ret;
536 public void OnAlert (IntPtr title, IntPtr text)
538 #if debug
539 OnGeneric ("OnAlert");
540 Console.Error.WriteLine ("OnAlert");
541 #endif
542 AlertEventHandler eh = (AlertEventHandler) (owner.Events[WebBrowser.AlertEvent]);
543 if (eh != null) {
544 AlertEventArgs e = new AlertEventArgs ();
545 e.Type = DialogType.Alert;
546 if (title != IntPtr.Zero)
547 e.Title = Marshal.PtrToStringUni (title);
548 if (text != IntPtr.Zero)
549 e.Text = Marshal.PtrToStringUni (text);
550 eh (this, e);
554 public bool OnAlertCheck (IntPtr title, IntPtr text, IntPtr chkMsg, ref bool chkState)
556 #if debug
557 OnGeneric ("OnAlertCheck");
558 Console.Error.WriteLine ("OnAlertCheck");
559 #endif
560 AlertEventHandler eh = (AlertEventHandler) (owner.Events[WebBrowser.AlertEvent]);
561 if (eh != null) {
562 AlertEventArgs e = new AlertEventArgs ();
563 e.Type = DialogType.AlertCheck;
564 if (title != IntPtr.Zero)
565 e.Title = Marshal.PtrToStringUni (title);
566 if (text != IntPtr.Zero)
567 e.Text = Marshal.PtrToStringUni (text);
568 if (chkMsg != IntPtr.Zero)
569 e.CheckMessage = Marshal.PtrToStringUni (chkMsg);
570 e.CheckState = chkState;
571 eh (this, e);
572 return e.BoolReturn;
574 return false;
577 public bool OnConfirm (IntPtr title, IntPtr text)
579 #if debug
580 OnGeneric ("OnConfirm");
581 Console.Error.WriteLine ("OnConfirm");
582 #endif
583 AlertEventHandler eh = (AlertEventHandler) (owner.Events[WebBrowser.AlertEvent]);
584 if (eh != null) {
585 AlertEventArgs e = new AlertEventArgs ();
586 e.Type = DialogType.Confirm;
587 if (title != IntPtr.Zero)
588 e.Title = Marshal.PtrToStringUni (title);
589 if (text != IntPtr.Zero)
590 e.Text = Marshal.PtrToStringUni (text);
591 eh (this, e);
592 return e.BoolReturn;
594 return false;
597 public bool OnConfirmCheck (IntPtr title, IntPtr text, IntPtr chkMsg, ref bool chkState)
599 #if debug
600 OnGeneric ("OnConfirmCheck");
601 Console.Error.WriteLine ("OnConfirmCheck");
602 #endif
603 AlertEventHandler eh = (AlertEventHandler) (owner.Events[WebBrowser.AlertEvent]);
604 if (eh != null) {
605 AlertEventArgs e = new AlertEventArgs ();
606 e.Type = DialogType.ConfirmCheck;
607 if (title != IntPtr.Zero)
608 e.Title = Marshal.PtrToStringUni (title);
609 if (text != IntPtr.Zero)
610 e.Text = Marshal.PtrToStringUni (text);
611 if (chkMsg != IntPtr.Zero)
612 e.CheckMessage = Marshal.PtrToStringUni (chkMsg);
613 e.CheckState = chkState;
614 eh (this, e);
615 chkState = e.CheckState;
616 return e.BoolReturn;
618 return false;
621 public bool OnConfirmEx (IntPtr title, IntPtr text, DialogButtonFlags flags,
622 IntPtr title0, IntPtr title1, IntPtr title2,
623 IntPtr chkMsg, ref bool chkState, out Int32 retVal)
625 #if debug
626 OnGeneric ("OnConfirmEx");
627 Console.Error.WriteLine ("OnConfirmEx");
628 #endif
629 retVal = -1;
631 AlertEventHandler eh = (AlertEventHandler) (owner.Events[WebBrowser.AlertEvent]);
632 if (eh != null) {
633 AlertEventArgs e = new AlertEventArgs ();
634 e.Type = DialogType.ConfirmEx;
635 if (title != IntPtr.Zero)
636 e.Title = Marshal.PtrToStringUni (title);
637 if (text != IntPtr.Zero)
638 e.Text = Marshal.PtrToStringUni (text);
639 if (chkMsg != IntPtr.Zero)
640 e.CheckMessage = Marshal.PtrToStringUni (chkMsg);
641 e.CheckState = chkState;
642 eh (this, e);
643 chkState = e.CheckState;
644 return e.BoolReturn;
646 return false;
649 public bool OnPrompt (IntPtr title, IntPtr text, ref IntPtr retVal)
651 #if debug
652 OnGeneric ("OnPrompt");
653 Console.Error.WriteLine ("OnPrompt");
654 #endif
655 AlertEventHandler eh = (AlertEventHandler) (owner.Events[WebBrowser.AlertEvent]);
656 if (eh != null) {
657 AlertEventArgs e = new AlertEventArgs ();
658 e.Type = DialogType.Prompt;
659 if (title != IntPtr.Zero)
660 e.Title = Marshal.PtrToStringUni (title);
661 if (text != IntPtr.Zero)
662 e.Text = Marshal.PtrToStringUni (text);
663 if (retVal != IntPtr.Zero)
664 e.Text2 = Marshal.PtrToStringUni (retVal);
665 eh (this, e);
666 retVal = Marshal.StringToHGlobalUni (e.StringReturn);
667 return e.BoolReturn;
669 return false;
672 public bool OnPromptUsernameAndPassword (IntPtr title, IntPtr text, IntPtr chkMsg, ref bool chkState, out IntPtr username, out IntPtr password)
674 #if debug
675 OnGeneric ("OnPromptUsernameAndPassword");
676 Console.Error.WriteLine ("OnPromptUsernameAndPassword");
677 #endif
678 username = IntPtr.Zero;
679 password = IntPtr.Zero;
680 AlertEventHandler eh = (AlertEventHandler) (owner.Events[WebBrowser.AlertEvent]);
681 if (eh != null) {
682 AlertEventArgs e = new AlertEventArgs ();
683 e.Type = DialogType.PromptUsernamePassword;
684 if (title != IntPtr.Zero)
685 e.Title = Marshal.PtrToStringUni (title);
686 if (text != IntPtr.Zero)
687 e.Text = Marshal.PtrToStringUni (text);
688 if (chkMsg != IntPtr.Zero)
689 e.CheckMessage = Marshal.PtrToStringUni (chkMsg);
690 e.CheckState = chkState;
691 eh (this, e);
692 return e.BoolReturn;
694 return false;
697 public bool OnPromptPassword (IntPtr title, IntPtr text, IntPtr chkMsg, ref bool chkState, out IntPtr password)
699 #if debug
700 OnGeneric ("OnPromptPassword");
701 Console.Error.WriteLine ("OnPromptPassword");
702 #endif
703 password = IntPtr.Zero;
704 AlertEventHandler eh = (AlertEventHandler) (owner.Events[WebBrowser.AlertEvent]);
705 if (eh != null) {
706 AlertEventArgs e = new AlertEventArgs ();
707 e.Type = DialogType.PromptPassword;
708 if (title != IntPtr.Zero)
709 e.Title = Marshal.PtrToStringUni (title);
710 if (text != IntPtr.Zero)
711 e.Text = Marshal.PtrToStringUni (text);
712 if (chkMsg != IntPtr.Zero)
713 e.CheckMessage = Marshal.PtrToStringUni (chkMsg);
714 e.CheckState = chkState;
715 eh (this, e);
716 return e.BoolReturn;
718 return false;
721 public bool OnSelect (IntPtr title, IntPtr text, uint count, IntPtr list, out int retVal)
723 #if debug
724 OnGeneric ("OnSelect");
725 Console.Error.WriteLine ("OnSelect");
726 #endif
727 retVal = 0;
728 AlertEventHandler eh = (AlertEventHandler) (owner.Events[WebBrowser.AlertEvent]);
729 if (eh != null) {
730 AlertEventArgs e = new AlertEventArgs ();
731 e.Type = DialogType.Select;
732 if (title != IntPtr.Zero)
733 e.Title = Marshal.PtrToStringUni (title);
734 if (text != IntPtr.Zero)
735 e.Text = Marshal.PtrToStringUni (text);
736 eh (this, e);
737 return e.BoolReturn;
739 return false;
742 public void OnLoad ()
744 #if debug
745 OnGeneric ("OnLoad");
746 Console.Error.WriteLine ("OnLoad");
747 #endif
748 ((DOM.Window)owner.Window).OnLoad ();
751 public void OnUnload ()
753 #if debug
754 OnGeneric ("OnUnload");
755 Console.Error.WriteLine ("OnUnload");
756 #endif
757 ((DOM.Window)owner.Window).OnUnload ();
760 public void OnShowContextMenu (UInt32 contextFlags,
761 [MarshalAs (UnmanagedType.Interface)] nsIDOMEvent eve,
762 [MarshalAs (UnmanagedType.Interface)] nsIDOMNode node)
764 #if debug
765 OnGeneric ("OnShowContextMenu");
766 Console.Error.WriteLine ("OnShowContextMenu");
767 #endif
768 ContextMenuEventHandler eh = (ContextMenuEventHandler) (owner.Events[WebBrowser.ContextMenuEvent]);
770 if (eh != null) {
771 nsIDOMMouseEvent mouseEvent = (nsIDOMMouseEvent) eve;
772 int x, y;
773 mouseEvent.getClientX (out x);
774 mouseEvent.getClientY (out y);
775 ContextMenuEventArgs args = new ContextMenuEventArgs(x, y);
776 eh (owner, args);
781 public void OnGeneric (string type)
783 #if debug
784 // string t = Marshal.PtrToStringUni (type);
785 Console.Error.WriteLine ("Callback Generic:{0}", type);
786 #endif
787 EventHandler eh = (EventHandler) (owner.Events[WebBrowser.GenericEvent]);
788 if (eh != null) {
789 EventArgs e = new EventArgs ();
790 eh (type, e);
791 return;
793 return;
796 #endregion
800 #region Delegates
802 internal delegate void CallbackVoid ();
804 internal delegate void CallbackString (string arg1);
805 internal delegate void CallbackWString ([MarshalAs(UnmanagedType.LPWStr)] string arg1);
807 internal delegate void CallbackStringString (string arg1, string arg2);
808 internal delegate void CallbackStringInt (string arg1, Int32 arg2);
809 internal delegate void CallbackWStringInt ([MarshalAs (UnmanagedType.LPWStr)] string arg1, Int32 arg2);
810 internal delegate void CallbackStringIntInt (string arg1, Int32 arg2, Int32 arg3);
811 internal delegate void CallbackStringIntUint (string arg1, Int32 arg2, UInt32 arg3);
814 internal delegate void CallbackIntInt (Int32 arg1, Int32 arg2);
815 internal delegate void CallbackIntUint (Int32 arg2, UInt32 arg3);
817 internal delegate void CallbackUint (UInt32 arg1);
818 internal delegate void CallbackUintInt (UInt32 arg1, Int32 arg2);
820 internal delegate void CallbackPtrPtr (IntPtr arg1, IntPtr arg2);
822 //Don't have to worry about marshalling bool, PRBool seems very constant and uses 4 bit int underneath
823 internal delegate void CallbackBool (bool val);
825 internal delegate bool KeyCallback (KeyInfo keyInfo, ModifierKeys modifiers, [MarshalAs (UnmanagedType.Interface)] nsIDOMNode target);
826 internal delegate bool MouseCallback (MouseInfo mouseInfo, ModifierKeys modifiers, [MarshalAs (UnmanagedType.Interface)] nsIDOMNode target);
828 internal delegate void GenericCallback (IntPtr type);
831 internal delegate bool Callback2 ();
832 internal delegate bool Callback2String (string arg1);
835 internal delegate bool CallbackOnAlertCheck (IntPtr title, IntPtr text, IntPtr chkMsg, ref bool chkState);
836 internal delegate bool CallbackOnConfirm (IntPtr title, IntPtr text);
837 internal delegate bool CallbackOnConfirmCheck (IntPtr title, IntPtr text, IntPtr chkMsg, ref bool chkState);
838 internal delegate bool CallbackOnConfirmEx (IntPtr title, IntPtr text, Mono.WebBrowser.DialogButtonFlags flags,
839 IntPtr title0, IntPtr title1, IntPtr title2,
840 IntPtr chkMsg, ref bool chkState, out Int32 retVal);
841 internal delegate bool CallbackOnPrompt (IntPtr title, IntPtr text,
842 ref IntPtr retVal);
843 internal delegate bool CallbackOnPromptUsernameAndPassword
844 (IntPtr title, IntPtr text,
845 IntPtr chkMsg, ref bool chkState,
846 out IntPtr username, out IntPtr password);
847 internal delegate bool CallbackOnPromptPassword
848 (IntPtr title, IntPtr text,
849 IntPtr chkMsg, ref bool chkState,
850 out IntPtr password);
851 internal delegate bool CallbackOnSelect (IntPtr title, IntPtr text,
852 UInt32 count, IntPtr list,
853 out Int32 retVal);
855 internal delegate void CallbackOnLocationChanged ([MarshalAs (UnmanagedType.Interface)] nsIWebProgress progress,
856 [MarshalAs (UnmanagedType.Interface)] nsIRequest request,
857 [MarshalAs (UnmanagedType.Interface)] nsIURI uri);
859 internal delegate void CallbackOnStatusChange ([MarshalAs (UnmanagedType.Interface)] nsIWebProgress progress,
860 [MarshalAs (UnmanagedType.Interface)] nsIRequest request,
861 [MarshalAs (UnmanagedType.LPWStr)] string message, Int32 status);
863 internal delegate void CallbackOnSecurityChange ([MarshalAs (UnmanagedType.Interface)] nsIWebProgress progress,
864 [MarshalAs (UnmanagedType.Interface)] nsIRequest request,
865 uint status);
867 internal delegate void CallbackOnStateChange ([MarshalAs (UnmanagedType.Interface)] nsIWebProgress progress,
868 [MarshalAs (UnmanagedType.Interface)] nsIRequest request,
869 Int32 arg2, UInt32 arg3);
870 internal delegate void CallbackOnProgress ([MarshalAs (UnmanagedType.Interface)] nsIWebProgress progress,
871 [MarshalAs (UnmanagedType.Interface)] nsIRequest request,
872 Int32 arg2, Int32 arg3);
874 internal delegate void CallbackOnShowContextMenu (UInt32 contextFlags,
875 [MarshalAs (UnmanagedType.Interface)] nsIDOMEvent eve,
876 [MarshalAs (UnmanagedType.Interface)] nsIDOMNode node);
880 #endregion
883 #region Structs
885 [StructLayout (LayoutKind.Sequential)]
886 internal struct CallbackBinder {
888 public CallbackVoid OnWidgetLoaded;
890 public CallbackOnStateChange OnStateChange;
891 public CallbackOnProgress OnProgress;
892 public CallbackOnLocationChanged OnLocationChanged;
894 public CallbackOnStatusChange OnStatusChange;
895 public CallbackOnSecurityChange OnSecurityChange;
897 public KeyCallback OnKeyDown;
898 public KeyCallback OnKeyUp;
899 public KeyCallback OnKeyPress;
901 public MouseCallback OnMouseDown;
902 public MouseCallback OnMouseUp;
903 public MouseCallback OnMouseClick;
904 public MouseCallback OnMouseDoubleClick;
905 public MouseCallback OnMouseOver;
906 public MouseCallback OnMouseOut;
908 public Callback2 OnActivate;
909 public Callback2 OnFocus;
910 public Callback2 OnBlur;
912 public CallbackPtrPtr OnAlert;
913 public CallbackOnAlertCheck OnAlertCheck;
914 public CallbackOnConfirm OnConfirm;
915 public CallbackOnConfirmCheck OnConfirmCheck;
916 public CallbackOnConfirmEx OnConfirmEx;
917 public CallbackOnPrompt OnPrompt;
918 public CallbackOnPromptUsernameAndPassword OnPromptUsernameAndPassword;
919 public CallbackOnPromptPassword OnPromptPassword;
920 public CallbackOnSelect OnSelect;
922 public CallbackVoid OnLoad;
923 public CallbackVoid OnUnload;
925 public CallbackOnShowContextMenu OnShowContextMenu;
927 public CallbackWString OnGeneric;
929 internal CallbackBinder (Callback callback) {
930 this.OnWidgetLoaded = new CallbackVoid (callback.OnWidgetLoaded);
932 this.OnStateChange = new CallbackOnStateChange (callback.OnStateChange);
934 this.OnProgress = new CallbackOnProgress (callback.OnProgress);
935 this.OnLocationChanged = new CallbackOnLocationChanged (callback.OnLocationChanged);
936 this.OnStatusChange = new CallbackOnStatusChange (callback.OnStatusChange);
937 this.OnSecurityChange = new CallbackOnSecurityChange (callback.OnSecurityChange);
939 this.OnKeyDown = new KeyCallback (callback.OnClientDomKeyDown);
940 this.OnKeyUp = new KeyCallback (callback.OnClientDomKeyUp);
941 this.OnKeyPress = new KeyCallback (callback.OnClientDomKeyPress);
943 this.OnMouseDown = new MouseCallback (callback.OnClientMouseDown);
944 this.OnMouseUp = new MouseCallback (callback.OnClientMouseUp);
945 this.OnMouseClick = new MouseCallback (callback.OnClientMouseClick);
946 this.OnMouseDoubleClick = new MouseCallback (callback.OnClientMouseDoubleClick);
947 this.OnMouseOver = new MouseCallback (callback.OnClientMouseOver);
948 this.OnMouseOut = new MouseCallback (callback.OnClientMouseOut);
950 this.OnActivate = new Callback2 (callback.OnClientActivate);
951 this.OnFocus = new Callback2 (callback.OnClientFocus);
952 this.OnBlur = new Callback2 (callback.OnClientBlur);
954 this.OnAlert = new CallbackPtrPtr (callback.OnAlert);
955 this.OnAlertCheck = new CallbackOnAlertCheck (callback.OnAlertCheck);
956 this.OnConfirm = new CallbackOnConfirm (callback.OnConfirm);
957 this.OnConfirmCheck = new CallbackOnConfirmCheck (callback.OnConfirmCheck);
958 this.OnConfirmEx = new CallbackOnConfirmEx (callback.OnConfirmEx);
959 this.OnPrompt = new CallbackOnPrompt (callback.OnPrompt);
960 this.OnPromptUsernameAndPassword = new CallbackOnPromptUsernameAndPassword (callback.OnPromptUsernameAndPassword);
961 this.OnPromptPassword = new CallbackOnPromptPassword (callback.OnPromptPassword);
962 this.OnSelect = new CallbackOnSelect (callback.OnSelect);
964 this.OnLoad = new CallbackVoid (callback.OnLoad);
965 this.OnUnload = new CallbackVoid (callback.OnUnload);
967 this.OnShowContextMenu = new CallbackOnShowContextMenu (callback.OnShowContextMenu);
969 this.OnGeneric = new CallbackWString (callback.OnGeneric);
974 [StructLayout (LayoutKind.Sequential)]
975 internal struct SizeInfo
977 public UInt32 width;
978 public UInt32 height;
981 [StructLayout (LayoutKind.Sequential)]
982 internal struct ModifierKeys
984 public Int32 altKey;
985 public Int32 ctrlKey;
986 public Int32 metaKey;
987 public Int32 shiftKey;
990 [StructLayout (LayoutKind.Sequential)]
991 internal struct MouseInfo
993 public UInt16 button;
994 public Int32 clientX;
995 public Int32 clientY;
996 public Int32 screenX;
997 public Int32 screenY;
1000 [StructLayout (LayoutKind.Sequential)]
1001 internal struct KeyInfo
1003 public UInt32 charCode;
1004 public UInt32 keyCode;
1007 [Flags]
1008 internal enum StateFlags
1010 Start = 1,
1011 Redirecting = 2,
1012 Transferring = 4,
1013 Negotiating = 8,
1014 Stop = 16,
1015 IsRequest = 65536,
1016 IsDocument = 131072,
1017 IsNetwork = 262144,
1018 IsWindow = 524288,
1019 Restoring = 16777216,
1020 IsInsecure = 4,
1021 IsBroken = 1,
1022 IsSecure = 2,
1023 SecureHigh = 262144,
1024 SecureMed = 65536,
1025 SecureLow = 131072
1027 #endregion