Exemple #1
0
        public unsafe static Cursor Create(ref CefCursorInfo cursorInfo)
        {
            CefSize size = cursorInfo.Size;

            if (size.Width > 0 && size.Height > 0 && cursorInfo.Buffer != IntPtr.Zero)
            {
                try
                {
                    var bufferSize       = size.Width * size.Height * 4;
                    int ICON_HEADER_SIZE = sizeof(ICONDIR);
                    var stream           = new MemoryStream();
                    {
                        DpiScale dpi    = OffscreenGraphics.DpiScale;
                        var      source = BitmapSource.Create(size.Width, size.Height, dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Bgra32, null, cursorInfo.Buffer, bufferSize, size.Width << 2);
                        if (stream.Seek(ICON_HEADER_SIZE, SeekOrigin.Begin) != ICON_HEADER_SIZE)
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            stream.Write(new byte[ICON_HEADER_SIZE], 0, ICON_HEADER_SIZE);
                        }

                        var png = new PngBitmapEncoder();
                        png.Frames.Add(BitmapFrame.Create(source));
                        png.Save(stream);
                        stream.Seek(0, SeekOrigin.Begin);
                    }

                    CefPoint hotSpot = cursorInfo.Hotspot;

                    var icon = new ICONDIR();
                    icon.IconType    = 2;
                    icon.ImagesCount = 1;
                    icon.Width       = (byte)size.Width;
                    icon.Height      = (byte)size.Height;
                    icon.HotSpotX    = (short)hotSpot.X;
                    icon.HotSpotY    = (short)hotSpot.Y;
                    icon.BytesInRes  = (int)stream.Length - ICON_HEADER_SIZE;
                    icon.ImageOffset = ICON_HEADER_SIZE;

                    using (var iconHead = new UnmanagedMemoryStream(icon._data, ICON_HEADER_SIZE))
                    {
                        iconHead.CopyTo(stream);
                        stream.Seek(0, SeekOrigin.Begin);
                    }

                    return(new Cursor(stream));
                }
                catch (AccessViolationException) { throw; }
                catch { }
            }
            return(Cursors.Arrow);
        }
Exemple #2
0
 ///  <summary>
 ///         Creates a new <see cref="BrowserProcessCEFClient"/> instance
 ///  </summary>
 ///  <param name="size">The size of the window</param>
 ///  <param name="proxySettings"></param>
 public BrowserProcessCEFClient(CefSize size, ProxySettings proxySettings)
 {
     //Setup our handlers
     loadHandler     = new BrowserProcessCEFLoadHandler(this);
     renderHandler   = new BrowserProcessCEFRenderHandler(size);
     lifespanHandler = new BrowserProcessCEFLifespanHandler();
     lifespanHandler.AfterCreated += cefBrowser =>
     {
         browser     = cefBrowser;
         browserHost = cefBrowser.GetHost();
         mainFrame   = cefBrowser.GetMainFrame();
     };
     displayHandler = new BrowserProcessCEFDisplayHandler();
     requestHandler = new BrowserProcessCEFRequestHandler(proxySettings);
 }
Exemple #3
0
        public unsafe static Cursor Create(ref CefCursorInfo cursorInfo)
        {
            CefSize size = cursorInfo.Size;

            if (size.Width > 0 && size.Height > 0 && cursorInfo.Buffer != IntPtr.Zero)
            {
                try
                {
                    CefPoint hotSpot = cursorInfo.Hotspot;
                    using (var bitmap = new Bitmap(PixelFormat.Bgra8888, AlphaFormat.Premul, cursorInfo.Buffer,
                                                   new PixelSize(size.Width, size.Height), OffscreenGraphics.DpiScale.Dpi, size.Width * 4))
                    {
                        return(new Cursor(bitmap, new PixelPoint(hotSpot.X, hotSpot.Y)));
                    }
                }
                catch (AccessViolationException) { throw; }
                catch { }
            }
            return(Cursor.Default);
        }
Exemple #4
0
        /// <summary>
        /// Creates new instance of the <see cref="Cursor"/> class.
        /// </summary>
        /// <param name="cursorInfo">The cursor information.</param>
        /// <returns>A new <see cref="Cursor"/> that this method creates.</returns>
        public static Cursor Create(ref CefCursorInfo cursorInfo)
        {
            CefSize size       = cursorInfo.Size;
            Bitmap  bitmap     = null;
            IntPtr  iconHandle = IntPtr.Zero;

            try
            {
                if (size.Width > 0 && size.Height > 0 && cursorInfo.Buffer != IntPtr.Zero)
                {
                    bitmap     = new Bitmap(size.Width, size.Height, 4 * size.Width, PixelFormat.Format32bppArgb, cursorInfo.Buffer);
                    iconHandle = bitmap.GetHicon();
                    if (iconHandle != IntPtr.Zero && NativeMethods.GetIconInfo(iconHandle, out ICONINFO iconInfo))
                    {
                        iconInfo.Hotspot = cursorInfo.Hotspot;
                        iconInfo.IsIcon  = false;
                        IntPtr cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo);
                        if (cursorHandle == IntPtr.Zero)
                        {
                            return(Cursors.Default);
                        }

                        return(new CustomCursor(cursorHandle)._cursor);
                    }
                }
            }
            catch (AccessViolationException) { throw; }
            catch { }
            finally
            {
                if (iconHandle != IntPtr.Zero)
                {
                    NativeMethods.DestroyIcon(iconHandle);
                }
                bitmap?.Dispose();
            }
            return(Cursors.Default);
        }
Exemple #5
0
        public static Cursor Create(ref CefCursorInfo cursorInfo)
        {
            if (cursorInfo.Buffer == IntPtr.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(cursorInfo));
            }

            CefSize size = cursorInfo.Size;

            using (var bitmap = new Bitmap(size.Width, size.Height, 4 * size.Width, System.Drawing.Imaging.PixelFormat.Format32bppArgb, cursorInfo.Buffer))
            {
                IntPtr iconHandle = bitmap.GetHicon();
                try
                {
                    if (NativeMethods.GetIconInfo(iconHandle, out ICONINFO iconInfo))
                    {
                        iconInfo.Hotspot = cursorInfo.Hotspot;
                        iconInfo.IsIcon  = false;
                        IntPtr cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo);
                        if (cursorHandle == IntPtr.Zero)
                        {
                            return(Cursors.Default);
                        }

                        return(new CustomCursor(cursorHandle)._cursor);
                    }
                    else
                    {
                        return(Cursors.Default);
                    }
                }
                finally
                {
                    NativeMethods.DestroyIcon(iconHandle);
                }
            }
        }
Exemple #6
0
 public override bool OnAutoResize(CefBrowser browser, CefSize newSize)
 {
     return(_implementation.OnAutoResize(browser, newSize));
 }
Exemple #7
0
 public BrowserProcessCEFRenderHandler(CefSize size)
 {
     cefSize    = size;
     pixels     = new byte[size.Width * size.Height * 4];
     pixelsLock = new object();
 }
 /// <summary>
 /// Enable notifications of auto resize via CefDisplayHandler::OnAutoResize.
 /// Notifications are disabled by default. |min_size| and |max_size| define the
 /// range of allowed sizes.
 /// </summary>
 public void SetAutoResizeEnabled(bool enabled, CefSize minSize, CefSize maxSize)
 {
     BrowserHost?.SetAutoResizeEnabled(enabled, minSize, maxSize);
 }
 protected override bool OnAutoResize(CefBrowser browser, ref CefSize newSize)
 {
     return(base.OnAutoResize(browser, ref newSize));
 }
Exemple #10
0
 protected internal unsafe override bool OnAutoResize(CefBrowser browser, CefSize newSize)
 {
     return(_implementation.OnAutoResize(browser, newSize));
 }
 /// <summary>
 /// Called when auto-resize is enabled via CefBrowserHost::SetAutoResizeEnabled and the contents have auto-resized.
 /// </summary>
 /// <param name="browser"></param>
 /// <param name="newSize">
 /// The desired size in view coordinates.
 /// </param>
 /// <returns>
 /// Return true if the resize was handled or false for default handling.
 /// </returns>
 internal protected virtual bool OnAutoResize(CefBrowser browser, CefSize newSize)
 {
     return(false);
 }