예제 #1
0
        protected override void OnSizeChanged(EventArgs e)
        {
            VirtualDevice device = Device;

            if (device != null)
            {
                float xScale = 1;
                float yScale = 1;
                float ppd    = OffscreenGraphics.PixelsPerDip;

                CefRect viewportRect = device.ViewportRect;
                viewportRect.Scale(OffscreenGraphics.PixelsPerDip);
                Rectangle clientRect = this.ClientRectangle;
                if (viewportRect.Height > clientRect.Height)
                {
                    yScale = Math.Max(clientRect.Height - 6.0f, 1.0f) / viewportRect.Height;
                }

                if (viewportRect.Width > clientRect.Width)
                {
                    xScale = Math.Max(clientRect.Width - 6.0f, 1.0f) / viewportRect.Width;
                }

                device.Scale = Math.Min(xScale, yScale);

                CefRect bounds = device.GetBounds(ppd);
                device.X = (int)(((clientRect.Width - bounds.Width) >> 1) / ppd);
                device.Y = (int)(((clientRect.Height - bounds.Height) >> 1) / ppd);

                CefInvalidate();
            }

            base.OnSizeChanged(e);
        }
 public TextFoundRoutedEventArgs(int identifier, int count, CefRect selectionRect, int index, bool finalUpdate)
     : base(WebView.TextFoundEvent)
 {
     this.ID            = identifier;
     this.Count         = count;
     this.SelectionRect = selectionRect;
     this.Index         = index;
     this.FinalUpdate   = finalUpdate;
 }
예제 #3
0
        protected virtual CefPoint PointToViewport(CefPoint point)
        {
            float         scale    = OffscreenGraphics.PixelsPerDip;
            VirtualDevice viewport = Device;

            if (viewport != null)
            {
                scale = scale * viewport.Scale;
            }
            CefRect viewportRect = GetViewportRect();

            return(new CefPoint((int)((point.X - viewportRect.X) / scale), (int)((point.Y - viewportRect.Y) / scale)));
        }
예제 #4
0
 private EX9.Texture CreateTexture(CefBrowser browser, Device device)
 {
     // TODO: Fix exceptions on start up.
     lock (FTextureResource)
     {
         var usage         = Usage.None & ~Usage.AutoGenerateMipMap;
         var texture       = new EX9.Texture(device, FSize.Width, FSize.Height, 1, usage, Format.A8R8G8B8, Pool.Default);
         var sysmemTexture = new EX9.Texture(device, FSize.Width, FSize.Height, 1, usage, Format.A8R8G8B8, Pool.SystemMemory);
         texture.Tag = sysmemTexture;
         var rect = new CefRect(0, 0, FSize.Width, FSize.Height);
         FBrowser.Invalidate(rect);
         return(texture);
     }
 }
예제 #5
0
 public void SetPopup(bool visible, CefRect bounds)
 {
     if (visible)
     {
         _popupBounds = bounds.ToRectangle();
     }
     else
     {
         lock (_syncRoot)
         {
             PopupPixels = null;
         }
     }
 }
예제 #6
0
 public void SetPopup(PopupShowEventArgs e)
 {
     if (e.Visible)
     {
         _popupBounds = e.Bounds;
     }
     else
     {
         lock (_syncRoot)
         {
             PopupPixels?.Dispose();
             PopupPixels = null;
         }
     }
 }
예제 #7
0
            public Int32Rect GetDirtyRectangle()
            {
                if (_dirtyRects.Count == 0)
                {
                    return(new Int32Rect());
                }
                CefRect   r         = _dirtyRects[0];
                Int32Rect dirtyRect = new Int32Rect(r.X, r.Y, r.Width, r.Height);

                for (int i = 1; i < _dirtyRects.Count; i++)
                {
                    dirtyRect.Union(_dirtyRects[i]);
                }
                return(dirtyRect);
            }
예제 #8
0
        protected CefRect GetViewportRect()
        {
            CefRect       viewportRect;
            VirtualDevice device = Device;

            if (device == null)
            {
                viewportRect = new CefRect(0, 0, this.Width, this.Height);
                viewportRect.Scale(OffscreenGraphics.PixelsPerDip);
                return(viewportRect);
            }
            else
            {
                return(device.GetBounds(OffscreenGraphics.PixelsPerDip));
            }
        }
예제 #9
0
 private EX9.Texture CreateTexture(CefBrowser browser, Device device)
 {
     // TODO: Fix exceptions on start up.
     lock (FTextures)
     {
         var usage = Usage.None & ~Usage.AutoGenerateMipMap;
         var pool  = Pool.Managed;
         if (device is DeviceEx)
         {
             usage = Usage.Dynamic & ~Usage.AutoGenerateMipMap;
             pool  = Pool.Default;
         }
         var texture = new EX9.Texture(device, FSize.Width, FSize.Height, 1, usage, Format.A8R8G8B8, pool);
         var rect    = new CefRect(0, 0, FSize.Width, FSize.Height);
         FBrowser.Invalidate(rect);
         FTextures.Add(texture);
         return(texture);
     }
 }
예제 #10
0
 protected internal unsafe override bool GetRootScreenRect(CefBrowser browser, ref CefRect rect)
 {
     return(_implementation.GetRootScreenRect(browser, ref rect));
 }
예제 #11
0
 internal protected virtual void GetViewRect(CefBrowser browser, ref CefRect rect)
 {
     rect = WebView.GetCefViewBounds();
 }
예제 #12
0
 internal protected virtual bool GetRootScreenRect(CefBrowser browser, ref CefRect rect)
 {
     rect = WebView.GetCefRootBounds();
     return(!rect.IsNullSize);
 }
예제 #13
0
 internal protected virtual void OnPopupSize(CefBrowser browser, CefRect rect)
 {
     WebView.RaisePopupShow(new PopupShowEventArgs(rect));
 }
예제 #14
0
 public OffscreenGraphics()
 {
     _syncRoot = new object();
     _bounds   = new CefRect(0, 0, 1, 1);
 }
예제 #15
0
        public unsafe CefRect Draw(CefPaintEventArgs e)
        {
            float         ppd    = OffscreenGraphics.PixelsPerDip;
            VirtualDevice device = this.Device;

            CefRect[] dirtyRects = e.DirtyRects;
            if (dirtyRects.Length == 0)
            {
                return(new CefRect());
            }

            CefRect r           = dirtyRects[0];
            CefRect invalidRect = new CefRect(r.X, r.Y, r.Width, r.Height);

            for (int i = 1; i < dirtyRects.Length; i++)
            {
                invalidRect.Union(dirtyRects[i]);
            }

            if (device != null)
            {
                invalidRect.Scale(device.Scale * ppd / device.DevicePixelRatio);
            }

            if (e.PaintElementType == CefPaintElementType.Popup)
            {
                invalidRect.Offset(_popupBounds.X, _popupBounds.Y);
            }

            if (invalidRect.IsNullSize)
            {
                return(new CefRect());
            }

            lock (_syncRoot)
            {
                int width  = e.Width;
                int height = e.Height;

                if (device != null)
                {
                    if (e.PaintElementType == CefPaintElementType.View)
                    {
                        width  = (int)(_bounds.Width * device.Scale * ppd);
                        height = (int)(_bounds.Height * device.Scale * ppd);
                    }
                    else if (e.PaintElementType == CefPaintElementType.Popup)
                    {
                        width  = (int)(e.Width / device.DevicePixelRatio * device.Scale * ppd);
                        height = (int)(e.Height / device.DevicePixelRatio * device.Scale * ppd);
                    }
                }

                PixelBuffer pixelBuffer;
                if (e.PaintElementType == CefPaintElementType.View)
                {
                    if (ViewPixels == null || ViewPixels.Width != width || ViewPixels.Height != height)
                    {
                        if (ViewPixels != null)
                        {
                            ViewPixels.Dispose();
                        }

                        ViewPixels = new PixelBuffer(width, height);
                    }
                    pixelBuffer = ViewPixels;
                }
                else if (e.PaintElementType == CefPaintElementType.Popup)
                {
                    if (PopupPixels == null || PopupPixels.Width != width || PopupPixels.Height != height)
                    {
                        if (PopupPixels != null)
                        {
                            PopupPixels.Dispose();
                        }
                        PopupPixels = new PixelBuffer(width, height);
                    }
                    pixelBuffer = PopupPixels;
                }
                else
                {
                    return(new CefRect());
                }

                if (e.Width == pixelBuffer.Width && e.Height == pixelBuffer.Height)
                {
                    long bufferSize = pixelBuffer.Source.ByteCount;
                    Buffer.MemoryCopy(e.Buffer.ToPointer(), pixelBuffer.Source.GetPixels().ToPointer(), bufferSize, bufferSize);
                }
                else
                {
                    using (var canvas = new SKCanvas(pixelBuffer.Source))
                        using (var paint = new SKPaint())
                        {
                            canvas.Clear();
                            paint.FilterQuality = SKFilterQuality.Medium;
                            using (var source = new SKBitmap())
                            {
                                source.InstallPixels(new SKImageInfo(e.Width, e.Height, SKColorType.Bgra8888, SKAlphaType.Opaque), e.Buffer);
                                canvas.DrawBitmap(source, new SKRect(0, 0, pixelBuffer.Width, pixelBuffer.Height), paint);
                            }
                            canvas.Flush();
                        }
                }
            }

            invalidRect.Inflate(2, 2);
            return(invalidRect);
        }
예제 #16
0
 protected override bool GetViewRect(CefBrowser browser, out CefRect rect)
 {
     return(base.GetViewRect(browser, out rect));
 }
예제 #17
0
 protected override bool GetViewRect(CefBrowser browser, out CefRect rect)
 {
     Shell.Instance.Logger.Log(LogType.Debug, string.Format("GetViewRect"));
     return(base.GetViewRect(browser, out rect));
 }
 internal protected virtual void OnFindResult(CefBrowser browser, int identifier, int count, CefRect selectionRect, int activeMatchOrdinal, bool finalUpdate)
 {
     WebView.RaiseTextFound(new TextFoundEventArgs(identifier, count, selectionRect, activeMatchOrdinal, finalUpdate));
 }
예제 #19
0
 public override bool GetRootScreenRect(CefBrowser browser, ref CefRect rect)
 {
     return(_implementation.GetRootScreenRect(browser, ref rect));
 }
예제 #20
0
 protected internal unsafe override void GetViewRect(CefBrowser browser, ref CefRect rect)
 {
     _implementation.GetViewRect(browser, ref rect);
 }
예제 #21
0
        protected virtual bool PointInViewport(int x, int y)
        {
            CefRect viewportRect = GetViewportRect();

            return(viewportRect.X <= x && x <= viewportRect.Right && viewportRect.Y <= y && y <= viewportRect.Bottom);
        }
예제 #22
0
 public override void GetViewRect(CefBrowser browser, ref CefRect rect)
 {
     _implementation.GetViewRect(browser, ref rect);
 }
예제 #23
0
 public override void OnPopupSize(CefBrowser browser, CefRect rect)
 {
     _implementation.OnPopupSize(browser, rect);
 }
예제 #24
0
 protected internal unsafe override void OnPopupSize(CefBrowser browser, CefRect rect)
 {
     _implementation.OnPopupSize(browser, rect);
 }
예제 #25
0
 /// <summary>
 /// Creates a <see cref="RECT"/> structure from the specified <see cref="CefRect"/> structure.
 /// </summary>
 /// <param name="rect">The <see cref="CefRect"/> to be converted.</param>
 /// <returns>The new <see cref="RECT"/> that this method creates.</returns>
 public static RECT FromCefRect(CefRect rect)
 {
     return(new RECT {
         Left = rect.X, Top = rect.Y, Right = rect.X + rect.Width, Bottom = rect.Y + rect.Height
     });
 }
예제 #26
0
 protected internal unsafe override void OnFindResult(CefBrowser browser, int identifier, int count, CefRect selectionRect, int activeMatchOrdinal, bool finalUpdate)
 {
     _implementation.OnFindResult(browser, identifier, count, selectionRect, activeMatchOrdinal, finalUpdate);
 }
예제 #27
0
        public CefRect Draw(CefPaintEventArgs e)
        {
            float         ppd    = OffscreenGraphics.PixelsPerDip;
            VirtualDevice device = this.Device;

            CefRect[] dirtyRects = e.DirtyRects;
            if (dirtyRects.Length == 0)
            {
                return(new CefRect());
            }

            CefRect r           = dirtyRects[0];
            CefRect invalidRect = new CefRect(r.X, r.Y, r.Width, r.Height);

            for (int i = 1; i < dirtyRects.Length; i++)
            {
                invalidRect.Union(dirtyRects[i]);
            }

            if (device != null)
            {
                invalidRect.Scale(device.Scale * ppd / device.DevicePixelRatio);
            }

            if (e.PaintElementType == CefPaintElementType.Popup)
            {
                invalidRect.Offset(_popupBounds.X, _popupBounds.Y);
            }

            if (invalidRect.IsNullSize)
            {
                return(new CefRect());
            }

            lock (_syncRoot)
            {
                int width  = e.Width;
                int height = e.Height;

                if (device != null)
                {
                    if (e.PaintElementType == CefPaintElementType.View)
                    {
                        width  = (int)(_bounds.Width * device.Scale * ppd);
                        height = (int)(_bounds.Height * device.Scale * ppd);
                    }
                    else if (e.PaintElementType == CefPaintElementType.Popup)
                    {
                        width  = (int)(e.Width / device.DevicePixelRatio * device.Scale * ppd);
                        height = (int)(e.Height / device.DevicePixelRatio * device.Scale * ppd);
                    }
                }

                PixelBuffer pixelBuffer;
                if (e.PaintElementType == CefPaintElementType.View)
                {
                    if (ViewPixels == null || ViewPixels.Width != width || ViewPixels.Height != height)
                    {
                        if (ViewPixels != null)
                        {
                            ViewPixels.Dispose();
                        }

                        ViewPixels = new PixelBuffer(width, height);
                    }
                    pixelBuffer = ViewPixels;
                }
                else if (e.PaintElementType == CefPaintElementType.Popup)
                {
                    if (PopupPixels == null || PopupPixels.Width != width || PopupPixels.Height != height)
                    {
                        if (PopupPixels != null)
                        {
                            PopupPixels.Dispose();
                        }
                        PopupPixels = new PixelBuffer(width, height);
                    }
                    pixelBuffer = PopupPixels;
                }
                else
                {
                    return(new CefRect());
                }

                using (Graphics g = Graphics.FromImage(pixelBuffer.Source))
                {
                    Color background = this.Background;
                    if (background.A > 0)
                    {
                        using (var brush = new SolidBrush(background))
                        {
                            g.FillRectangle(brush, 0, 0, width, height);
                        }
                    }

                    using (var bitmap = new Bitmap(e.Width, e.Height, e.Width << 2, PixelFormat.Format32bppArgb, e.Buffer))
                    {
                        if (e.Width != width || e.Height != height)
                        {
                            g.CompositingQuality = CompositingQuality.HighSpeed;
                            g.InterpolationMode  = this.InterpolationMode;
                            g.DrawImage(bitmap, 0, 0, width, height);
                        }
                        else
                        {
                            g.DrawImage(bitmap, 0, 0);
                        }
                        g.Flush();
                    }
                }
            }

            invalidRect.Inflate(2, 2);
            return(invalidRect);
        }