Child windows support
Coherent UI allows clients to choose which child(popup) windows should be opened and which should not. Whenever Coherent UI detects a new window to be opened, a callback for the View Listener is executed. This callback method should return a boolean value that either allows or disallows the creation of the new window. If the child window is to be allowed, the client must supply some initialization data (e.g. the width and height of the new window) and a new View Listener that is responsible for the child window's callbacks.
- Warning
- Currently child windows are not compatible with on-demand views. Trying to open a child window in an on-demand view might result in blocking the client application.
Child windows creation events in C++
When a new child window is to be opened, the client is notified via the Coherent::UI::ViewListener::OnCanCreateChildWindow
event. The client is supplied with the opener and target URLs so she can do some filtering based on them. If the creation should be disallowed, the client should just return false in the callback. If is should be allowed, the client should return true and fill in the Coherent::UI::ChildViewInfo
structure with the needed data. This data is a Coherent::UI::ViewInfo
structure and a Coherent::UI::ViewListenerBase
which should be a newly created View Listener that will receive the notifications for the new window.
Example (C++)
{
public:
{
if (!AllowChildWindowRequest(openerUrl, targetUrl))
{
return false;
}
std::unique_ptr<ChildWindowExampleViewListener> listener(new ChildWindowExampleViewListener());
childViewInfo.Listener = listener.get();
g_ViewListenersCollection.push_back(std::move(listener));
childViewInfo.NewViewInfo->Width = 1280;
childViewInfo.NewViewInfo->Height = 720;
childViewInfo.NewViewInfo->UsesSharedMemory = true;
childViewInfo.NewViewInfo->IsTransparent = false;
childViewInfo.NewViewInfo->SupportClickThrough = false;
#ifndef COHERENT_UI_LIMITED_VERSION
childViewInfo.NewViewInfo->TargetFrameRate = 60;
childViewInfo.NewViewInfo->IsOnDemand = false;
childViewInfo.NewViewInfo->ControlTimeOnDemand = false;
#endif
return true;
}
private:
bool AllowChildWindowRequest(const wchar_t* openerUrl, const wchar_t* targetUrl)
{
bool allow = true;
return allow;
}
};
Child windows creation events in C#
When a new child window is to be opened, the client is notified via the Coherent.UI.ViewListener.OnCanCreateChildWindow
event. The client is supplied with the opener and target URLs so she can do some filtering based on them. If the creation should be disallowed, the client should just return false in the callback. If is should be allowed, the client should return true and fill in the Coherent.UI.ChildViewInfo
structure with the needed data. This data is a Coherent.UI.ViewInfo
structure and a Coherent.UI.ViewListenerBase
which should be a newly created View Listener that will receive the notifications for the new window.
Example (C#)
{
{
Console.WriteLine("{0} trying to open popup: {1}", openerUrl, targetUrl);
var listener = new ChildWindowExampleViewListener();
childViewInfo.Listener = listener;
g_ViewListenersCollection.Add(listener);
childViewInfo.NewViewInfo.Width = 1280;
childViewInfo.NewViewInfo.Height = 720;
childViewInfo.NewViewInfo.UsesSharedMemory = false;
return true;
}
private bool AllowChildWindowRequest(string openerUrl, string targetUrl)
{
bool allow = true;
return allow;
}
}
Child windows creation events for .NET controls
When a new child window is to be opened, the client is notified via the BrowserViewControl's
PopupWindowRequested
event. The client is supplied with the opener and target URLs so she can do some filtering based on them. By default new window requests are disallowed so if you do nothing in the event handler, no new windows will be created. If the creation should be allowed, the client should call the BrowserViewControl.PopupWindowResponse.Allow
method. This method will return a new instance of a BrowserViewControl
that the client can place in a suitable location in the form.
Example (.NET Windows Forms control)
public partial class MainForm : Form
{
private void viewControlWinForms1_PopupWindowRequested(string openerUrl, string targetUrl, BrowserViewControl.PopupWindowResponse response)
{
if (AllowPopup(openerUrl, targetUrl))
{
BrowserViewControl ctrl = response.Allow();
this.Controls.Add(ctrl);
this.components.Add(ctrl);
}
}
private void InitializeComponent()
{
this.viewControlWinForms1.PopupWindowRequested += new Coherent.UI.Windows.Forms.BrowserViewControl.PopupWindowRequestHandler(this.viewControlWinForms1_PopupWindowRequested);
}
}
Example (.NET WPF control)
public partial class MainWindow : Window
{
private void viewControl_PopupWindowRequested(string openerUrl, string targetUrl, BrowserViewControl.PopupWindowResponse response)
{
if (AllowPopup(openerUrl, targetUrl))
{
BrowserViewControl ctrl = response.Allow();
this.gridMain.Children.Add(ctrl);
var rowDef = new RowDefinition();
rowDef.Height = new GridLength(1, GridUnitType.Star);
this.gridMain.RowDefinitions.Add(rowDef);
Grid.SetRow(ctrl, this.gridMain.RowDefinitions.Count - 1);
}
}
}
<coui:BrowserViewControl Name="viewControl" ViewWidth="640" ViewHeight="480" InitialUrl="http://www.w3schools.com/js/js_popup.asp"
Grid.Column="0" Grid.Row="2" PopupWindowRequested="viewControl_PopupWindowRequested" UsesOwnUISystem="True" />
Example (.NET GTK# control)
public partial class MainWindow: Gtk.Window
{
private System.Collections.Generic.List<IDisposable> m_TrackedComponents;
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
m_TrackedComponents = new System.Collections.Generic.List<IDisposable>();
m_TrackedComponents.Add(viewControl1);
m_TrackedComponents.Add(viewControl2);
}
private void CleanTrackedComponents()
{
foreach (IDisposable item in m_TrackedComponents) {
item.Dispose();
}
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
CleanTrackedComponents();
Application.Quit ();
a.RetVal = true;
}
protected void OnNewWindow (string openerUrl, string targetUrl, Coherent.UI.Mono.Gtk.BrowserViewControl.PopupWindowResponse response)
{
if (AllowPopup(openerUrl, targetUrl))
{
BrowserViewControl ctrl = response.Allow();
m_TrackedComponents.Add(ctrl);
this.fixed1.Put(ctrl, 10, 40);
ctrl.Show();
}
}
protected virtual void Build ()
{
this.DeleteEvent += new global::Gtk.DeleteEventHandler (this.OnDeleteEvent);
this.viewControl1.PopupWindowRequested += new global::Coherent.UI.Mono.Gtk.BrowserViewControl.PopupWindowRequestHandler (this.OnNewWindow);
}
}