add CefSharp.Example to house shared code

This commit is contained in:
anthony taranto
2012-02-23 15:08:50 -08:00
parent d165d56a40
commit 417f01fd59
11 changed files with 293 additions and 24 deletions
+58
View File
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A4394E7B-1155-43A6-989E-8AB72DDDC9E4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CefSharp.Example</RootNamespace>
<AssemblyName>CefSharp.Example</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ExamplePresenter.cs" />
<Compile Include="IExampleView.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CefSharp\CefSharp.vcproj">
<Project>{7B495581-2271-4F41-9476-ACB86E8C864F}</Project>
<Name>CefSharp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
+81
View File
@@ -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<Action> gui_invoke;
public ExamplePresenter(IWebBrowser model, IExampleView view,
Action<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();
}
}
}
+19
View File
@@ -0,0 +1,19 @@
using System;
namespace CefSharp.Example
{
public interface IExampleView
{
event Action<object, string> 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);
}
}
@@ -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)]
+7 -7
View File
@@ -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);
+7 -7
View File
@@ -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);
@@ -67,6 +67,10 @@
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CefSharp.Example\CefSharp.Example.csproj">
<Project>{A4394E7B-1155-43A6-989E-8AB72DDDC9E4}</Project>
<Name>CefSharp.Example</Name>
</ProjectReference>
<ProjectReference Include="..\CefSharp.Wpf\CefSharp.Wpf.vcproj">
<Project>{C944B6A6-7CAF-4101-B81B-2DE47296FC40}</Project>
<Name>CefSharp.Wpf</Name>
+9 -9
View File
@@ -6,27 +6,27 @@
<DockPanel>
<Menu Height="22" DockPanel.Dock="Top">
<MenuItem Header="File">
<MenuItem Header="Exit" Name="exitMenuItem" Click="exitMenuItem_Click" />
<MenuItem Header="Exit" Name="exitMenuItem" />
</MenuItem>
<MenuItem Header="Tests">
<MenuItem Header="Test Resource Load Handler" />
<MenuItem Header="Test Execute Javascript" Name="executeJsMenuItem" Click="executeJsMenuItem_Click" />
<MenuItem Header="Test Evaluate JavaScript" Name="evaluateJsMenuItem" Click="evaluateJsMenuItem_Click" />
<MenuItem Header="Test Evaluate Arbitrary JavaScript" Name="evaluateArbiraryJsMenuItem" Click="evaluateArbiraryJsMenuItem_Click"/>
<MenuItem Header="Test Execute Javascript" Name="executeJsMenuItem" />
<MenuItem Header="Test Evaluate JavaScript" Name="evaluateJsMenuItem" />
<MenuItem Header="Test Evaluate Arbitrary JavaScript" Name="evaluateArbiraryJsMenuItem" />
<MenuItem Header="Test Scheme Handler" />
<MenuItem Header="Test Console Messages" />
<MenuItem Header="Test Bind CLR Object to JavaScript" />
</MenuItem>
<MenuItem Header="Bookmarks">
<MenuItem Header="CefSharp Home" Name="homeMenuItem" Click="homeMenuItem_Click" />
<MenuItem Header="FireBug Lite" Name="fireBugMenuItem" Click="fireBugMenuItem_Click" />
<MenuItem Header="CefSharp Home" Name="homeMenuItem" />
<MenuItem Header="FireBug Lite" Name="fireBugMenuItem" />
</MenuItem>
</Menu>
<DockPanel VerticalAlignment="Top" DockPanel.Dock="Top">
<Button Height="23" Name="backButton" Width="75" Click="backButton_Click" IsEnabled="False">Back</Button>
<Button Height="23" Name="forwardButton" Width="75" Click="forwardButton_Click" IsEnabled="False">Forward</Button>
<Button Height="23" Name="backButton" Width="75" IsEnabled="False">Back</Button>
<Button Height="23" Name="forwardButton" Width="75" IsEnabled="False">Forward</Button>
<Button Height="23" Name="goStopButton" Width="75" DockPanel.Dock="Right" Click="goStopButton_Click">Go</Button>
<Button Height="23" Name="goStopButton" Width="75" DockPanel.Dock="Right">Go</Button>
<TextBox Height="23" Name="urlTextBox" KeyDown="urlTextBox_KeyDown" />
</DockPanel>
<DockPanel VerticalAlignment="Top" DockPanel.Dock="Top">
+76 -1
View File
@@ -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<object, string> 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");
}
*/
}
}
+12
View File
@@ -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
+9
View File
@@ -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();