Permalink
Browse files

Implemented ProgressChanged event

  • Loading branch information...
1 parent 3ee6265 commit 6272b43948f5d1aa15ed756825ee3cb851e7ba9d @herbmillerjr herbmillerjr committed Mar 14, 2011
@@ -138,7 +138,16 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
add { core.NewWindowCreated += value; }
remove { core.NewWindowCreated -= value; }
- }
+ }
+
+ /// <summary>
+ /// Occurs when the WebKitBrowser control has updated information on the download progress of a document it is navigating to.
+ /// </summary>
+ public event ProgressChangedEventHandler ProgressChanged
+ {
+ add { core.ProgressChanged += value; }
+ remove { core.ProgressChanged -= value; }
+ }
/// <summary>
/// Occurs when JavaScript requests an alert panel to be displayed via the alert() function.
@@ -167,6 +176,7 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
remove { core.ShowJavaScriptPromptPanel -= value; }
}
+
#endregion
#region Public properties
@@ -1,5 +1,6 @@
using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
+using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
@@ -20,7 +21,9 @@ public class WebKitBrowserCore : IWebKitBrowser
// private member variables...
private IWebView webView;
private IntPtr webViewHWND;
- private IWebKitBrowserHost host;
+ private IWebKitBrowserHost host;
+ private WebNotificationObserver webNotificationObserver;
+ private WebNotificationCenter webNotificationCenter;
// Note: we do not provide overridden Equals or GetHashCode methods for the
// WebDownload interface used as a key here - the default implementations should suffice
@@ -88,7 +91,12 @@ public class WebKitBrowserCore : IWebKitBrowser
/// <summary>
/// Occurs when the WebKitBrowser control creates a new window.
/// </summary>
- public event NewWindowCreatedEventHandler NewWindowCreated = delegate { };
+ public event NewWindowCreatedEventHandler NewWindowCreated = delegate { };
+
+ /// <summary>
+ /// Occurs when the WebKitBrowser control has updated information on the download progress of a document it is navigating to.
+ /// </summary>
+ public event ProgressChangedEventHandler ProgressChanged = delegate { };
/// <summary>
/// Occurs when JavaScript requests an alert panel to be displayed via the alert() function.
@@ -575,7 +583,12 @@ private void InitializeWebKit()
Marshal.AddRef(Marshal.GetIUnknownForObject(policyDelegate));
uiDelegate = new WebUIDelegate(this);
- Marshal.AddRef(Marshal.GetIUnknownForObject(uiDelegate));
+ Marshal.AddRef(Marshal.GetIUnknownForObject(uiDelegate));
+
+ webNotificationCenter = new WebNotificationCenter();
+ Marshal.AddRef(Marshal.GetIUnknownForObject(webNotificationCenter)); // TODO: find out if this is really needed
+ webNotificationObserver = new WebNotificationObserver();
+ webNotificationCenter.defaultCenter().addObserver(webNotificationObserver, "WebProgressEstimateChangedNotification", webView);
webView.setPolicyDelegate(policyDelegate);
webView.setFrameLoadDelegate(frameLoadDelegate);
@@ -614,7 +627,10 @@ private void InitializeWebKit()
uiDelegate.CreateWebViewWithRequest += new CreateWebViewWithRequestEvent(uiDelegate_CreateWebViewWithRequest);
uiDelegate.RunJavaScriptAlertPanelWithMessage += new RunJavaScriptAlertPanelWithMessageEvent(uiDelegate_RunJavaScriptAlertPanelWithMessage);
uiDelegate.RunJavaScriptConfirmPanelWithMessage += new RunJavaScriptConfirmPanelWithMessageEvent(uiDelegate_RunJavaScriptConfirmPanelWithMessage);
- uiDelegate.RunJavaScriptTextInputPanelWithPrompt += new RunJavaScriptTextInputPanelWithPromptEvent(uiDelegate_RunJavaScriptTextInputPanelWithPrompt);
+ uiDelegate.RunJavaScriptTextInputPanelWithPrompt += new RunJavaScriptTextInputPanelWithPromptEvent(uiDelegate_RunJavaScriptTextInputPanelWithPrompt);
+
+ // Notification events
+ webNotificationObserver.OnNotify += new OnNotifyEvent(webNotificationObserver_OnNotify);
activationContext.Deactivate();
}
@@ -648,7 +664,12 @@ private void WebKitBrowser_Load(object sender, EventArgs e)
}
IsScriptingEnabled = initialJavaScriptEnabled;
- }
+ }
+
+ private void WebKitBrowser_HandleDestroyed(object sender, EventArgs e)
+ {
+ webNotificationCenter.defaultCenter().removeObserver(webNotificationObserver, "WebProgressEstimateChangedNotification", webView);
+ }
#endregion
@@ -797,7 +818,17 @@ private string uiDelegate_RunJavaScriptTextInputPanelWithPrompt(WebView sender,
return args.ReturnValue;
}
- #endregion
+ #endregion
+
+ #region WebNotificationObserver event handlers
+
+ private void webNotificationObserver_OnNotify(IWebNotification notification)
+ {
+ ProgressChangedEventArgs args = new ProgressChangedEventArgs((int)(webView.estimatedProgress() * 100), null);
+ ProgressChanged(this, args);
+ }
+
+ #endregion
#region Public Methods
@@ -63,6 +63,7 @@
<Compile Include="WebKitDOMHTMLClasses.cs" />
<Compile Include="WebKitDownload.cs" />
<Compile Include="WebKitDownloadEvents.cs" />
+ <Compile Include="WebNotificationObserver.cs" />
<Compile Include="WebPolicyDelegate.cs" />
<Compile Include="WebResourceLoadDelegate.cs" />
<Compile Include="WebUIDelegate.cs" />
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using WebKit;
+using WebKit.Interop;
+
+namespace WebKit
+{
+ internal delegate void OnNotifyEvent(IWebNotification notification);
+
+ internal class WebNotificationObserver : IWebNotificationObserver
+ {
+ public event OnNotifyEvent OnNotify = delegate { };
+
+ #region webNotificationObserver Members
+
+ public void onNotify(IWebNotification notification)
+ {
+ OnNotify(notification);
+ }
+
+ #endregion
+ }
+}

0 comments on commit 6272b43

Please sign in to comment.