/// <summary> /// Invokes the on cef asynchronous. /// </summary> /// <param name="action">The action.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">action</exception> internal Task InvokeOnCefAsync(Action action) { if (action == null) { throw new ArgumentNullException("action"); } var taskCompletionSource = new TaskCompletionSource <object>(); if (IsMultiThreadedMessageLoop) { return(InvokeOnMainAsync(action)); } CefUtility.ExecuteTask(CefThreadId.UI, () => { try { action(); taskCompletionSource.SetResult(null); } catch (Exception e) { taskCompletionSource.SetException(e); } }); return(taskCompletionSource.Task); }
/// <summary> /// Handles the GotFocus event of the Form control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void Form_GotFocus(object sender, EventArgs e) { if (CefBrowser != null) { CefUtility.ExecuteTask(CefThreadId.UI, () => { CefBrowser.GetHost().SetFocus(true); }); } }
/// <summary> /// Handles the Move event of the Form control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void Form_Move(object sender, EventArgs e) { if (CefBrowser != null) { CefUtility.ExecuteTask(CefThreadId.UI, () => { CefBrowser.GetHost().NotifyMoveOrResizeStarted(); }); } }
/// <summary> /// Handles the Resize event of the Window control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void Window_Resize(object sender, EventArgs e) { if (CefBrowser != null) { CefUtility.ExecuteTask(CefThreadId.UI, () => { var display = NativeMethods.get_xdisplay(); if (Form.WindowState != FormWindowState.Minimized) { // resize the browser NativeMethods.XResizeWindow(display, CefBrowser.GetHost().GetWindowHandle(), (uint)Form.ClientSize.Width, (uint)Form.ClientSize.Height); } }); } }
/// <summary> /// Parses the cef v8 value. /// </summary> /// <param name="value">The value.</param> /// <returns></returns> private JToken ParseCefV8Value(CefV8Value value) { if (value == null) { return(null); } return(CefUtility.RunInContext(Context, () => { if (value.IsInt) { return JToken.FromObject(value.GetIntValue()); } if (value.IsUInt) { return JToken.FromObject(value.GetUIntValue()); } if (value.IsDouble) { return JToken.FromObject(value.GetDoubleValue()); } if (value.IsBool) { return JToken.FromObject(value.GetBoolValue()); } if (value.IsDate) { return JToken.FromObject(value.GetDateValue()); } if (value.IsString) { return JToken.FromObject(value.GetStringValue()); } if (value.IsUndefined) { return JValue.CreateUndefined(); } if (value.IsArray) { var array = new JArray(); for (var i = 0; i < value.GetArrayLength(); i++) { array.Add(ParseCefV8Value(value.GetValue(i))); } return array; } if (value.IsObject) { var obj = new JObject(); foreach (var propertyName in value.GetKeys()) { obj.Add(propertyName, ParseCefV8Value(value.GetValue(propertyName))); } return obj; } return JValue.CreateNull(); })); }