/// <summary> /// Set the page ranges. /// </summary> /// <remarks> /// See also the original CEF documentation in /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_print_settings_capi.h">cef/include/capi/cef_print_settings_capi.h</see>. /// </remarks> public void SetPageRanges(CfxRange[] ranges) { UIntPtr ranges_length; IntPtr[] ranges_ptrs; if (ranges != null) { ranges_length = (UIntPtr)ranges.Length; ranges_ptrs = new IntPtr[ranges.Length]; for (int i = 0; i < ranges.Length; ++i) { ranges_ptrs[i] = CfxRange.Unwrap(ranges[i]); } } else { ranges_length = UIntPtr.Zero; ranges_ptrs = null; } PinnedObject ranges_pinned = new PinnedObject(ranges_ptrs); int ranges_nomem; CfxApi.PrintSettings.cfx_print_settings_set_page_ranges(NativePtr, ranges_length, ranges_pinned.PinnedPtr, out ranges_nomem); ranges_pinned.Free(); if (ranges_nomem != 0) { throw new OutOfMemoryException(); } }
/// <summary> /// Begins a new composition or updates the existing composition. Blink has a /// special node (a composition node) that allows the input function to change /// text without affecting other DOM nodes. |text| is the optional text that /// will be inserted into the composition node. |underlines| is an optional set /// of ranges that will be underlined in the resulting text. /// |replacementRange| is an optional range of the existing text that will be /// replaced. |selectionRange| is an optional range of the resulting text that /// will be selected after insertion or replacement. The |replacementRange| /// value is only used on OS X. /// /// This function may be called multiple times as the composition changes. When /// the client is done making changes the composition should either be canceled /// or completed. To cancel the composition call ImeCancelComposition. To /// complete the composition call either ImeCommitText or /// ImeFinishComposingText. Completion is usually signaled when: /// A. The client receives a WM_IME_COMPOSITION message with a GCS_RESULTSTR /// flag (on Windows), or; /// B. The client receives a "commit" signal of GtkIMContext (on Linux), or; /// C. insertText of NSTextInput is called (on Mac). /// /// This function is only used when window rendering is disabled. /// </summary> /// <remarks> /// See also the original CEF documentation in /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_browser_capi.h">cef/include/capi/cef_browser_capi.h</see>. /// </remarks> public void ImeSetComposition(string text, CfxCompositionUnderline[] underlines, CfxRange replacementRange, CfxRange selectionRange) { var text_pinned = new PinnedString(text); UIntPtr underlines_length; IntPtr[] underlines_ptrs; if (underlines != null) { underlines_length = (UIntPtr)underlines.Length; underlines_ptrs = new IntPtr[underlines.Length]; for (int i = 0; i < underlines.Length; ++i) { underlines_ptrs[i] = CfxCompositionUnderline.Unwrap(underlines[i]); } } else { underlines_length = UIntPtr.Zero; underlines_ptrs = null; } PinnedObject underlines_pinned = new PinnedObject(underlines_ptrs); int underlines_nomem; CfxApi.BrowserHost.cfx_browser_host_ime_set_composition(NativePtr, text_pinned.Obj.PinnedPtr, text_pinned.Length, underlines_length, underlines_pinned.PinnedPtr, out underlines_nomem, CfxRange.Unwrap(replacementRange), CfxRange.Unwrap(selectionRange)); text_pinned.Obj.Free(); underlines_pinned.Free(); if (underlines_nomem != 0) { throw new OutOfMemoryException(); } }
/// <summary> /// Execute the function using the specified V8 context. |object| is the /// receiver ('this' object) of the function. If |object| is NULL the specified /// context's global object will be used. |arguments| is the list of arguments /// that will be passed to the function. Returns the function return value on /// success. Returns NULL if this function is called incorrectly or an /// exception is thrown. /// </summary> /// <remarks> /// See also the original CEF documentation in /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_v8_capi.h">cef/include/capi/cef_v8_capi.h</see>. /// </remarks> public CfxV8Value ExecuteFunctionWithContext(CfxV8Context context, CfxV8Value @object, CfxV8Value[] arguments) { int arguments_length; IntPtr[] arguments_ptrs; if (arguments != null) { arguments_length = arguments.Length; arguments_ptrs = new IntPtr[arguments_length]; for (int i = 0; i < arguments_length; ++i) { arguments_ptrs[i] = CfxV8Value.Unwrap(arguments[i]); } } else { arguments_length = 0; arguments_ptrs = null; } PinnedObject arguments_pinned = new PinnedObject(arguments_ptrs); var __retval = CfxApi.cfx_v8value_execute_function_with_context(NativePtr, CfxV8Context.Unwrap(context), CfxV8Value.Unwrap(@object), arguments_length, arguments_pinned.PinnedPtr); arguments_pinned.Free(); return(CfxV8Value.Wrap(__retval)); }
/// <summary> /// Execute the function using the current V8 context. This function should /// only be called from within the scope of a CfxV8Handler or /// CfxV8Accessor callback, or in combination with calling enter() and /// exit() on a stored CfxV8Context reference. |object| is the receiver /// ('this' object) of the function. If |object| is NULL the current context's /// global object will be used. |arguments| is the list of arguments that will /// be passed to the function. Returns the function return value on success. /// Returns NULL if this function is called incorrectly or an exception is /// thrown. /// </summary> /// <remarks> /// See also the original CEF documentation in /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_v8_capi.h">cef/include/capi/cef_v8_capi.h</see>. /// </remarks> public CfxV8Value ExecuteFunction(CfxV8Value @object, CfxV8Value[] arguments) { UIntPtr arguments_length; IntPtr[] arguments_ptrs; if (arguments != null) { arguments_length = (UIntPtr)arguments.Length; arguments_ptrs = new IntPtr[arguments.Length]; for (int i = 0; i < arguments.Length; ++i) { arguments_ptrs[i] = CfxV8Value.Unwrap(arguments[i]); } } else { arguments_length = UIntPtr.Zero; arguments_ptrs = null; } PinnedObject arguments_pinned = new PinnedObject(arguments_ptrs); var __retval = CfxApi.V8Value.cfx_v8value_execute_function(NativePtr, CfxV8Value.Unwrap(@object), arguments_length, arguments_pinned.PinnedPtr); arguments_pinned.Free(); return(CfxV8Value.Wrap(__retval)); }
/// <summary> /// Creates a new object that is not owned by any other object. The specified /// |data| will be copied. /// </summary> public static CfxBinaryValue Create(byte[] data) { if (data == null || data.Length == 0) { throw new ArgumentException("Data is null or zero length", "data"); } var po = new PinnedObject(data); var retval = CfxBinaryValue.Create(po.PinnedPtr, (ulong)data.LongLength); po.Free(); return(retval); }
// Must be called explicitly, otherwise leaks internal void Free() { if (managedArgv == null) { return; } argvPinned.Free(); for (int i = 0; i < managedArgv.Length; ++i) { System.Runtime.InteropServices.Marshal.FreeHGlobal(managedArgv[i]); } managedArgv = null; }
/// <summary> /// Read uncompressed file contents into the specified buffer. Returns /// 0 if at the end of file, or the number of bytes read. /// Throws an exception if an error occurred. /// </summary> public int ReadFile(byte[] buffer) { if (buffer == null || buffer.Length == 0) { throw new ArgumentException("Buffer can't be null or zero length.", "buffer"); } var pb = new PinnedObject(buffer); var retval = CfxApi.cfx_zip_reader_read_file(NativePtr, pb.PinnedPtr, buffer.Length); pb.Free(); if (retval < 0) { throw new CfxException("Failed to read from zip file"); } return(retval); }
/// <summary> /// Read up to (buffer.Length - bufferOffset) bytes into |buffer|. Reading begins at /// the specified byte dataOffset. Writing begins at the /// specified byte bufferOffset. /// Returns the number of bytes read. /// </summary> public int GetData(byte[] buffer, int bufferOffset, int dataOffset) { if (buffer == null || buffer.Length == 0) { throw new ArgumentException("Buffer is null or zero length.", "buffer"); } var maxBytes = buffer.Length - bufferOffset; if (maxBytes <= 0) { throw new ArgumentException("bufferOffset >= buffer.Length.", "bufferOffset"); } var po = new PinnedObject(buffer); var retval = CfxApi.BinaryValue.cfx_binary_value_get_data(NativePtr, po.PinnedPtr + bufferOffset, (UIntPtr)maxBytes, (UIntPtr)dataOffset); po.Free(); return((int)retval); }
/// <summary> /// Retrieve the page ranges. /// </summary> /// <remarks> /// See also the original CEF documentation in /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_print_settings_capi.h">cef/include/capi/cef_print_settings_capi.h</see>. /// </remarks> public CfxRange[] GetPageRanges() { var rangesCount = CfxApi.PrintSettings.cfx_print_settings_get_page_ranges_count(NativePtr); IntPtr[] pp = new IntPtr[(ulong)rangesCount]; PinnedObject pp_pinned = new PinnedObject(pp); int ranges_nomem; CfxApi.PrintSettings.cfx_print_settings_get_page_ranges(NativePtr, ref rangesCount, pp_pinned.PinnedPtr, out ranges_nomem); pp_pinned.Free(); if (ranges_nomem != 0) { throw new OutOfMemoryException(); } var retval = new CfxRange[(ulong)rangesCount]; for (ulong i = 0; i < (ulong)rangesCount; ++i) { retval[i] = CfxRange.WrapOwned(pp[i]); } return(retval); }