Skip to content

Commit

Permalink
Refactoring for CefWindowInfo. Use CefWindowInfo.Create() to create, …
Browse files Browse the repository at this point in the history
…instead of default ctor!
  • Loading branch information
dmitry-azaraev committed Jan 15, 2013
1 parent 9e45ced commit dba0059
Show file tree
Hide file tree
Showing 18 changed files with 544 additions and 238 deletions.
6 changes: 3 additions & 3 deletions CefGlue.Demo.GtkSharp/Control/CefWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ protected override void OnRealized()

ChildVisible = true;

var windowInfo = new CefWindowInfo();
var windowInfo = CefWindowInfo.Create();
switch (CefRuntime.Platform)
{
case CefRuntimePlatform.Windows:
windowInfo.Parent = gdk_win32_drawable_get_handle(GdkWindow.Handle);
windowInfo.ParentHandle = gdk_win32_drawable_get_handle(GdkWindow.Handle);
// set windowInfo - x, y, width, height ?
break;

case CefRuntimePlatform.Linux:
Console.WriteLine("REALIZED - RAW = {0}, HANDLE = {1}", Raw, Handle);
windowInfo.Parent = Handle;
windowInfo.ParentHandle = Handle;
break;

case CefRuntimePlatform.MacOSX:
Expand Down
5 changes: 5 additions & 0 deletions CefGlue.Demo.GtkSharp/MainViewImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,10 @@ public CefBrowser CurrentBrowser
return navBox.GetBrowser();
}
}

public void NewWebView(string url, bool transparent)
{
throw new NotImplementedException();
}
}
}
1 change: 1 addition & 0 deletions CefGlue.Demo.WinForms/CefGlue.Demo.WinForms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Control\CefWebView.cs" />
<Compile Include="Control\NativeMethods.cs" />
<Compile Include="Control\SetWindowPosFlags.cs" />
<Compile Include="Control\CefWebBrowser.cs">
Expand Down
4 changes: 2 additions & 2 deletions CefGlue.Demo.WinForms/Control/CefWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ protected override void OnHandleCreated(EventArgs e)
}
else
{
var windowInfo = new CefWindowInfo();
windowInfo.Parent = Handle;
var windowInfo = CefWindowInfo.Create();
windowInfo.SetAsChild(Handle, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height });

_core.Create(windowInfo);
}
Expand Down
59 changes: 59 additions & 0 deletions CefGlue.Demo.WinForms/Control/CefWebView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace Xilium.CefGlue.Demo
{
using System;
using System.Collections.Generic;
using System.Text;
using WebBrowser = Xilium.CefGlue.Demo.Browser.WebBrowser;
using System.Windows.Forms;
using Xilium.CefGlue.Platform.Windows;
using System.Runtime.InteropServices;

public class CefWebView
{
private bool _handleCreated;
private WebBrowser _core;
private IntPtr _browserWindowHandle;

public CefWebView(string url, bool transparent = false)
{
_core = new WebBrowser(this, new CefBrowserSettings(), url ?? "about:blank");
_core.Created += new EventHandler(BrowserCreated);

var windowInfo = CefWindowInfo.Create();
windowInfo.SetAsPopup(IntPtr.Zero, null);
windowInfo.Name = url;
if (transparent)
{
windowInfo.SetTransparentPainting(true);
windowInfo.Width = 500;
windowInfo.Height = 500;
windowInfo.Style = WindowStyle.WS_POPUP | WindowStyle.WS_VISIBLE;
}

_core.Create(windowInfo);
}

private void BrowserCreated(object sender, EventArgs e)
{
var handle = _core.CefBrowser.GetHost().GetWindowHandle();

//MARGINS mgMarInset = new MARGINS { leftWidth = -1, rightWidth = -1, topHeight = -1, bottomHeight = -1 };
//DwmExtendFrameIntoClientArea(handle, ref mgMarInset);
}

[DllImport("dwmapi.dll")]
private static extern int DwmIsCompositionEnabled(out bool enabled);

[DllImport("dwmapi.dll", PreserveSig = true)]
private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);

[StructLayout(LayoutKind.Sequential)]
internal struct MARGINS
{
public int leftWidth;
public int rightWidth;
public int topHeight;
public int bottomHeight;
}
}
}
5 changes: 5 additions & 0 deletions CefGlue.Demo.WinForms/MainViewImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,10 @@ public CefBrowser CurrentBrowser
return navBox.GetBrowser();
}
}

public void NewWebView(string url, bool transparent)
{
var view = new CefWebView(url, transparent);
}
}
}
14 changes: 14 additions & 0 deletions CefGlue.Demo/DemoApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ private MenuItem[] CreateMainMenu()
new MenuItem("Samples", new [] {
new MenuItem(new Command("Scheme Handler: Dump Request", SchemeHandlerDumpRequestCommand)),
new MenuItem(new Command("Send Process Message", SendProcessMessageCommand)),
new MenuItem(new Command("Popup Window", PopupWindowCommand)),
new MenuItem(new Command("Transparent Popup Window", TransparentPopupWindowCommand)),
}),
new MenuItem("Help", new [] {
new MenuItem(new Command("About", HelpAboutCommand)),
Expand Down Expand Up @@ -158,6 +160,18 @@ private void SendProcessMessageCommand(object sender, EventArgs e)
}
}

private void PopupWindowCommand(object sender, EventArgs e)
{
var url = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(new Uri(typeof(DemoApp).Assembly.CodeBase).LocalPath), "transparency.html");
MainView.NewWebView(url, false);
}

private void TransparentPopupWindowCommand(object sender, EventArgs e)
{
var url = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(new Uri(typeof(DemoApp).Assembly.CodeBase).LocalPath), "transparency.html");
MainView.NewWebView(url, true);
}

private void HelpAboutCommand(object sender, EventArgs e)
{
// throw new NotImplementedException();
Expand Down
2 changes: 2 additions & 0 deletions CefGlue.Demo/IMainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public interface IMainView : IDisposable
void NavigateTo(string url);

CefBrowser CurrentBrowser { get; }

void NewWebView(string url, bool transparent);
}
}
4 changes: 2 additions & 2 deletions CefGlue.WindowsForms/CefWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ protected override void OnHandleCreated(EventArgs e)
}
else
{
var windowInfo = new CefWindowInfo();
windowInfo.Parent = Handle;
var windowInfo = CefWindowInfo.Create();
windowInfo.SetAsChild(Handle, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height });

var client = new CefWebClient(this);

Expand Down
7 changes: 5 additions & 2 deletions CefGlue/CefGlue.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
<Compile Include="Interop\Classes.g\cef_web_plugin_unstable_callback_t.g.cs" />
<Compile Include="Interop\Structs\cef_geoposition_t.cs" />
<Compile Include="Interop\Structs\cef_key_event_t.cs" />
<Compile Include="Platform\Linux\CefWindowInfoLinuxImpl.cs" />
<Compile Include="Platform\Mac\CefWindowInfoMacImpl.cs" />
<Compile Include="Platform\Windows\CefWindowInfoWindowsImpl.cs" />
<Compile Include="Platform\Windows\WindowStyles.cs" />
<Compile Include="Platform\Windows\WindowStylesEx.cs" />
<Compile Include="Structs\CefCookie.cs" />
<Compile Include="Structs\CefGeoposition.cs" />
<Compile Include="Structs\CefKeyEvent.cs" />
Expand All @@ -291,8 +296,6 @@
<Compile Include="Structs\CefBrowserSettings.cs" />
<Compile Include="Interop\_Platform\NativeMethods.cs" />
<Compile Include="Interop\_Platform\RECT.cs" />
<Compile Include="Interop\_Platform\WindowStyles.cs" />
<Compile Include="Interop\_Platform\WindowStylesEx.cs" />
<None Include="..\Xilium.CefGlue.snk">
<Link>Properties\Xilium.CefGlue.snk</Link>
</None>
Expand Down
2 changes: 1 addition & 1 deletion CefGlue/Classes.Handlers/CefLifeSpanHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private int on_before_popup(cef_life_span_handler_t* self, cef_browser_t* parent

var m_parentBrowser = CefBrowser.FromNative(parentBrowser);
var m_popupFeatures = new CefPopupFeatures(popupFeatures);
var m_windowInfo = new CefWindowInfo(windowInfo);
var m_windowInfo = CefWindowInfo.FromNative(windowInfo);
var m_url = cef_string_t.ToString(url);
var m_client = CefClient.FromNative(*client);
var m_settings = new CefBrowserSettings(settings);
Expand Down
17 changes: 14 additions & 3 deletions CefGlue/Interop/Structs/cef_window_info_t.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ static cef_window_info_t_windows()

public static void Free(cef_window_info_t_windows* ptr)
{
Marshal.FreeHGlobal((IntPtr)ptr);
if (ptr != null)
{
libcef.string_clear(&ptr->window_name);
Marshal.FreeHGlobal((IntPtr)ptr);
}
}
#endregion
}
Expand All @@ -81,7 +85,10 @@ static cef_window_info_t_linux()

public static void Free(cef_window_info_t_linux* ptr)
{
Marshal.FreeHGlobal((IntPtr)ptr);
if (ptr != null)
{
Marshal.FreeHGlobal((IntPtr)ptr);
}
}
#endregion
}
Expand Down Expand Up @@ -118,7 +125,11 @@ static cef_window_info_t_mac()

public static void Free(cef_window_info_t_mac* ptr)
{
Marshal.FreeHGlobal((IntPtr)ptr);
if (ptr != null)
{
libcef.string_clear(&ptr->window_name);
Marshal.FreeHGlobal((IntPtr)ptr);
}
}
#endregion
}
Expand Down
112 changes: 112 additions & 0 deletions CefGlue/Platform/Linux/CefWindowInfoLinuxImpl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
namespace Xilium.CefGlue.Platform
{
using System;
using System.Collections.Generic;
using System.Text;
using Xilium.CefGlue;
using Xilium.CefGlue.Interop;
using Xilium.CefGlue.Platform.Windows;

internal unsafe sealed class CefWindowInfoLinuxImpl : CefWindowInfo
{
private cef_window_info_t_linux* _self;

public CefWindowInfoLinuxImpl()
: base(true)
{
_self = cef_window_info_t_linux.Alloc();
}

public CefWindowInfoLinuxImpl(cef_window_info_t* ptr)
: base(false)
{
if (CefRuntime.Platform != CefRuntimePlatform.Linux)
throw new InvalidOperationException();

_self = (cef_window_info_t_linux*)ptr;
}

internal override cef_window_info_t* GetNativePointer()
{
return (cef_window_info_t*)_self;
}

protected internal override void DisposeNativePointer()
{
cef_window_info_t_linux.Free(_self);
_self = null;
}

public override IntPtr ParentHandle
{
get { ThrowIfDisposed(); return _self->parent_widget; }
set { ThrowIfDisposed(); _self->parent_widget = value; }
}

public override IntPtr Handle
{
get { ThrowIfDisposed(); return _self->widget; }
set { ThrowIfDisposed(); _self->widget = value; }
}

public override string Name
{
get { return default(string); }
set { }
}

public override int X
{
get { return default(int); }
set { }
}

public override int Y
{
get { return default(int); }
set { }
}

public override int Width
{
get { return default(int); }
set { }
}

public override int Height
{
get { return default(int); }
set { }
}

public override WindowStyle Style
{
get { return default(WindowStyle); }
set { }
}

public override WindowStyleEx StyleEx
{
get { return default(WindowStyleEx); }
set { }
}

public override IntPtr MenuHandle
{
get { return default(IntPtr); }
set { }
}

public override bool WindowRenderingDisabled
{
get { return default(bool); }
set { }
}

public override bool TransparentPainting
{
get { return default(bool); }
set { }
}
}
}
Loading

0 comments on commit dba0059

Please sign in to comment.