From 417f01fd59e83ff8339ec4edaab88829487c08bc Mon Sep 17 00:00:00 2001 From: anthony taranto Date: Thu, 23 Feb 2012 15:08:50 -0800 Subject: [PATCH] add CefSharp.Example to house shared code --- CefSharp.Example/CefSharp.Example.csproj | 58 +++++++++++++ CefSharp.Example/ExamplePresenter.cs | 81 +++++++++++++++++++ CefSharp.Example/IExampleView.cs | 19 +++++ CefSharp.Example/Properties/AssemblyInfo.cs | 11 +++ CefSharp.WinForms/WebView.h | 14 ++-- CefSharp.Wpf/WebView.h | 14 ++-- .../CefSharp.Wpf.Example.csproj | 4 + CefSharp.WpfExample/MainWindow.xaml | 18 ++--- CefSharp.WpfExample/MainWindow.xaml.cs | 77 +++++++++++++++++- CefSharp.sln | 12 +++ CefSharp/IWebBrowser.h | 9 +++ 11 files changed, 293 insertions(+), 24 deletions(-) create mode 100644 CefSharp.Example/CefSharp.Example.csproj create mode 100644 CefSharp.Example/ExamplePresenter.cs create mode 100644 CefSharp.Example/IExampleView.cs create mode 100644 CefSharp.Example/Properties/AssemblyInfo.cs diff --git a/CefSharp.Example/CefSharp.Example.csproj b/CefSharp.Example/CefSharp.Example.csproj new file mode 100644 index 000000000..6fa330117 --- /dev/null +++ b/CefSharp.Example/CefSharp.Example.csproj @@ -0,0 +1,58 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4} + Library + Properties + CefSharp.Example + CefSharp.Example + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + + + + + + + + {7B495581-2271-4F41-9476-ACB86E8C864F} + CefSharp + + + + + \ No newline at end of file diff --git a/CefSharp.Example/ExamplePresenter.cs b/CefSharp.Example/ExamplePresenter.cs new file mode 100644 index 000000000..46c6b8144 --- /dev/null +++ b/CefSharp.Example/ExamplePresenter.cs @@ -0,0 +1,81 @@ +using System; +using System.ComponentModel; + +namespace CefSharp.Example +{ + public class ExamplePresenter + { + private readonly IWebBrowser model; + private readonly IExampleView view; + private readonly Action gui_invoke; + + public ExamplePresenter(IWebBrowser model, IExampleView view, + Action gui_invoke) + { + this.model = model; + this.view = view; + this.gui_invoke = gui_invoke; + + this.model.PropertyChanged += model_PropertyChanged; + + this.view.ExitActivated += view_ExitActivated; + this.view.ForwardActivated += view_ForwardActivated; + this.view.BackActivated += view_BackActivated; + this.view.UrlActivated += view_UrlActivated; + } + + private void model_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + string @string; + bool @bool; + + switch (e.PropertyName) + { + case "Title": + @string = model.Title; + gui_invoke(() => view.SetTitle(@string)); + break; + case "Tooltip": + @string = model.Tooltip; + gui_invoke(() => view.SetTooltip(@string)); + break; + case "Address": + @string = model.Address; + gui_invoke(() => view.SetAddress(@string)); + break; + case "CanGoBack": + @bool = model.CanGoBack; + gui_invoke(() => view.SetCanGoBack(@bool)); + break; + case "CanGoForward": + @bool = model.CanGoForward; + gui_invoke(() => view.SetCanGoForward(@bool)); + break; + case "IsLoading": + @bool = model.IsLoading; + gui_invoke(() => view.SetIsLoading(@bool)); + break; + } + } + + private void view_UrlActivated(object sender, string url) + { + model.Load(url); + } + + private void view_BackActivated(object sender, EventArgs e) + { + model.Back(); + } + + private void view_ForwardActivated(object sender, EventArgs e) + { + model.Forward(); + } + + private void view_ExitActivated(object sender, EventArgs e) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/CefSharp.Example/IExampleView.cs b/CefSharp.Example/IExampleView.cs new file mode 100644 index 000000000..876dd9ccc --- /dev/null +++ b/CefSharp.Example/IExampleView.cs @@ -0,0 +1,19 @@ +using System; + +namespace CefSharp.Example +{ + public interface IExampleView + { + event Action UrlActivated; + event EventHandler BackActivated; + event EventHandler ForwardActivated; + event EventHandler ExitActivated; + + void SetTitle(string title); + void SetTooltip(string tooltip); + void SetAddress(string address); + void SetCanGoBack(bool can_go_back); + void SetCanGoForward(bool can_go_forward); + void SetIsLoading(bool is_loading); + } +} \ No newline at end of file diff --git a/CefSharp.Example/Properties/AssemblyInfo.cs b/CefSharp.Example/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..6255d85e0 --- /dev/null +++ b/CefSharp.Example/Properties/AssemblyInfo.cs @@ -0,0 +1,11 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("CefSharp.Example")] +[assembly: AssemblyCompany("Anthony Taranto")] +[assembly: AssemblyProduct("CefSharp.Example")] +[assembly: AssemblyCopyright("Copyright © 2012")] + +[assembly: AssemblyVersion("0.9.*")] +[assembly: ComVisible(false)] diff --git a/CefSharp.WinForms/WebView.h b/CefSharp.WinForms/WebView.h index 331602fdc..a6d4bd8b4 100644 --- a/CefSharp.WinForms/WebView.h +++ b/CefSharp.WinForms/WebView.h @@ -150,13 +150,13 @@ namespace WinForms virtual void OnInitialized(); - void Load(String^ url); - void Stop(); - void Back(); - void Forward(); - void Reload(); - void Reload(bool ignoreCache); - void Print(); + virtual void Load(String^ url); + virtual void Stop(); + virtual void Back(); + virtual void Forward(); + virtual void Reload(); + virtual void Reload(bool ignoreCache); + virtual void Print(); void ExecuteScript(String^ script); String^ EvaluateScript(String^ script); diff --git a/CefSharp.Wpf/WebView.h b/CefSharp.Wpf/WebView.h index 380b82835..8822d41b2 100644 --- a/CefSharp.Wpf/WebView.h +++ b/CefSharp.Wpf/WebView.h @@ -163,13 +163,13 @@ namespace CefSharp virtual void OnInitialized(); - void Load(String^ url); - void Stop(); - void Back(); - void Forward(); - void Reload(); - void Reload(bool ignoreCache); - void Print(); + virtual void Load(String^ url); + virtual void Stop(); + virtual void Back(); + virtual void Forward(); + virtual void Reload(); + virtual void Reload(bool ignoreCache); + virtual void Print(); void ExecuteScript(String^ script); String^ EvaluateScript(String^ script); diff --git a/CefSharp.WpfExample/CefSharp.Wpf.Example.csproj b/CefSharp.WpfExample/CefSharp.Wpf.Example.csproj index b2d3ad864..1587b8aab 100644 --- a/CefSharp.WpfExample/CefSharp.Wpf.Example.csproj +++ b/CefSharp.WpfExample/CefSharp.Wpf.Example.csproj @@ -67,6 +67,10 @@ + + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4} + CefSharp.Example + {C944B6A6-7CAF-4101-B81B-2DE47296FC40} CefSharp.Wpf diff --git a/CefSharp.WpfExample/MainWindow.xaml b/CefSharp.WpfExample/MainWindow.xaml index 018534d61..60086154c 100644 --- a/CefSharp.WpfExample/MainWindow.xaml +++ b/CefSharp.WpfExample/MainWindow.xaml @@ -6,27 +6,27 @@ - + - - - + + + - - + + - - + + - + diff --git a/CefSharp.WpfExample/MainWindow.xaml.cs b/CefSharp.WpfExample/MainWindow.xaml.cs index 9347faf3c..4b933a50e 100644 --- a/CefSharp.WpfExample/MainWindow.xaml.cs +++ b/CefSharp.WpfExample/MainWindow.xaml.cs @@ -6,11 +6,84 @@ using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Threading; +using CefSharp.Example; namespace CefSharp.Wpf.Example { - public partial class MainWindow : Window + public partial class MainWindow : Window, IExampleView { + public event Action UrlActivated; + public event EventHandler BackActivated; + public event EventHandler ForwardActivated; + public event EventHandler ExitActivated; + + private WebView web_view; + + public MainWindow() + { + InitializeComponent(); + } + + private void Window_SourceInitialized(object sender, EventArgs e) + { + Settings settings = new Settings(); + if (!CEF.Initialize(settings)) + { + return; + } + + var source = PresentationSource.FromVisual(sender as Visual) as HwndSource; + web_view = new WebView(source, "https://github.com/ataranto/CefSharp"); + + this.frame.Content = web_view; + new ExamplePresenter(web_view, this, invoke => { }); + } + + public void SetTitle(string title) + { + Title = title; + } + + public void SetTooltip(string tooltip) + { + + } + + public void SetAddress(string address) + { + urlTextBox.Text = address; + } + + public void SetCanGoBack(bool can_go_back) + { + backButton.IsEnabled = can_go_back; + } + + public void SetCanGoForward(bool can_go_forward) + { + forwardButton.IsEnabled = can_go_forward; + } + + public void SetIsLoading(bool is_loading) + { + + } + + private void urlTextBox_KeyDown(object sender, KeyEventArgs e) + { + if (e.Key != Key.Enter) + { + return; + } + + var handler = UrlActivated; + if (handler) + { + handler(this, urlTextBox.Text); + } + } + + /* private WebView browser; public MainWindow() @@ -174,5 +247,7 @@ namespace CefSharp.Wpf.Example { browser.Load("http://getfirebug.com/firebuglite"); } + */ + } } diff --git a/CefSharp.sln b/CefSharp.sln index 397ae4898..8265b9576 100644 --- a/CefSharp.sln +++ b/CefSharp.sln @@ -13,6 +13,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CefSharp.Wpf", "CefSharp.Wp EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CefSharp.WinForms.Example", "CefSharp.WinFormsExample\CefSharp.WinForms.Example.csproj", "{C043FFF7-5F71-4FFC-989A-E09E18548589}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CefSharp.Example", "CefSharp.Example\CefSharp.Example.csproj", "{A4394E7B-1155-43A6-989E-8AB72DDDC9E4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -83,6 +85,16 @@ Global {C043FFF7-5F71-4FFC-989A-E09E18548589}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {C043FFF7-5F71-4FFC-989A-E09E18548589}.Release|Mixed Platforms.Build.0 = Release|Any CPU {C043FFF7-5F71-4FFC-989A-E09E18548589}.Release|Win32.ActiveCfg = Release|Any CPU + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4}.Debug|Win32.ActiveCfg = Debug|Any CPU + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4}.Release|Any CPU.Build.0 = Release|Any CPU + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {A4394E7B-1155-43A6-989E-8AB72DDDC9E4}.Release|Win32.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CefSharp/IWebBrowser.h b/CefSharp/IWebBrowser.h index 1396d8bfd..e98bbb993 100644 --- a/CefSharp/IWebBrowser.h +++ b/CefSharp/IWebBrowser.h @@ -28,6 +28,15 @@ namespace CefSharp property IAfterResponse^ AfterResponseHandler; void OnInitialized(); + + void Load(String^ url); + void Stop(); + void Back(); + void Forward(); + void Reload(); + void Reload(bool ignoreCache); + void Print(); + void SetNavState(bool isLoading, bool canGoBack, bool canGoForward); void OnFrameLoadStart();