forked from cefsharp/CefSharp.OutOfProcess
-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/add wpf offscreen browser #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Sebbstar
wants to merge
12
commits into
master
Choose a base branch
from
feat/add-wpf-offscreen-browser
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f26fd1b
Merge branch 'feat/wpf-offscreen-browser'
sebastian1203721 5c6443f
minor
sebastian1203721 c498fee
fix
sebastian1203721 eca0e64
cleanup
sebastian1203721 34e0c6a
revert
sebastian1203721 0ecc37c
remove plattformtarget attributes
sebastian1203721 a29ee5e
remove unused code, whitespace
sebastian1203721 b6f704f
minor
sebastian1203721 6478234
renormalize
sebastian1203721 dd71e81
minor
sebastian1203721 ebd394e
revert whitespace change
sebastian1203721 ea46d2c
review
sebastian1203721 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule CefSharp.Dom
updated
11 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
CefSharp.OutOfProcess.BrowserProcess/CefSharp.OutOfProcess.BrowserProcess.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
CefSharp.OutOfProcess.BrowserProcess/CefSharp.WPF.Internals/RectStruct.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright © 2018 The CefSharp Authors. All rights reserved. | ||
| // | ||
| // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
| using CefSharp.Structs; | ||
|
|
||
| namespace CefSharp.Wpf.Internals | ||
| { | ||
| /// <summary> | ||
| /// The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle. | ||
| /// </summary> | ||
| /// <see cref="https://docs.microsoft.com/en-us/previous-versions/dd162897(v=vs.85)"/> | ||
| /// <remarks> | ||
| /// By convention, the right and bottom edges of the rectangle are normally considered exclusive. | ||
| /// In other words, the pixel whose coordinates are ( right, bottom ) lies immediately outside of the the rectangle. | ||
| /// For example, when RECT is passed to the FillRect function, the rectangle is filled up to, but not including, | ||
| /// the right column and bottom row of pixels. This structure is identical to the RECTL structure. | ||
| /// </remarks> | ||
| [StructLayout(LayoutKind.Sequential)] | ||
| public struct RectStruct | ||
| { | ||
| /// <summary> | ||
| /// The x-coordinate of the upper-left corner of the rectangle. | ||
| /// </summary> | ||
| public int Left; | ||
|
|
||
| /// <summary> | ||
| /// The y-coordinate of the upper-left corner of the rectangle. | ||
| /// </summary> | ||
| public int Top; | ||
|
|
||
| /// <summary> | ||
| /// The x-coordinate of the lower-right corner of the rectangle. | ||
| /// </summary> | ||
| public int Right; | ||
|
|
||
| /// <summary> | ||
| /// The y-coordinate of the lower-right corner of the rectangle. | ||
| /// </summary> | ||
| public int Bottom; | ||
|
|
||
| public static implicit operator Rect(RectStruct rect) | ||
| { | ||
| return new Rect(0, 0, rect.Right - rect.Left, rect.Bottom - rect.Top); | ||
| } | ||
| } | ||
| } |
119 changes: 119 additions & 0 deletions
119
CefSharp.OutOfProcess.BrowserProcess/OffscreenOutOfProcessChromiumWebBrowser.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| using CefSharp.Internals; | ||
| using System; | ||
| using CefSharp.OutOfProcess.Interface; | ||
| using CefSharp.Structs; | ||
| using CefSharp.Enums; | ||
|
|
||
| namespace CefSharp.OutOfProcess.BrowserProcess | ||
| { | ||
| /// <summary> | ||
| /// An ChromiumWebBrowser instance specifically for hosting CEF out of process | ||
| /// </summary> | ||
| public class OffscreenOutOfProcessChromiumWebBrowser : OutOfProcessChromiumWebBrowser, IRenderWebBrowser | ||
| { | ||
| private readonly RenderHandler renderHandler; | ||
| private readonly RenderHandler popupRenderHandler; | ||
|
|
||
| public OffscreenOutOfProcessChromiumWebBrowser(IOutOfProcessHostRpc outOfProcessServer, int id, string address = "", IRequestContext requestContext = null) | ||
| : base(outOfProcessServer, id, address, requestContext, true) | ||
| { | ||
| renderHandler = new RenderHandler($"0render_{Id}_"); | ||
| popupRenderHandler = new RenderHandler($"0render_{Id}_popup_"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The dpi scale factor, if the browser has already been initialized | ||
| /// you must manually call IBrowserHost.NotifyScreenInfoChanged for the | ||
| /// browser to be notified of the change. | ||
| /// </summary> | ||
| public float DpiScaleFactor { get; set; } = 1; | ||
|
|
||
| internal CefSharp.Structs.Rect ViewRect { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the ScreenInfo - currently used to get the DPI scale factor. | ||
| /// </summary> | ||
| /// <returns>ScreenInfo containing the current DPI scale factor</returns> | ||
| ScreenInfo? IRenderWebBrowser.GetScreenInfo() => GetScreenInfo(); | ||
|
|
||
| /// <summary> | ||
| /// Gets the ScreenInfo - currently used to get the DPI scale factor. | ||
| /// </summary> | ||
| /// <returns>ScreenInfo containing the current DPI scale factor</returns> | ||
| protected virtual ScreenInfo? GetScreenInfo() | ||
| { | ||
| CefSharp.Structs.Rect rect = new CefSharp.Structs.Rect(); | ||
| CefSharp.Structs.Rect availableRect = new CefSharp.Structs.Rect(); | ||
|
|
||
| if (DpiScaleFactor > 1.0) | ||
| { | ||
| rect = rect.ScaleByDpi(DpiScaleFactor); | ||
| availableRect = availableRect.ScaleByDpi(DpiScaleFactor); | ||
| } | ||
|
|
||
| var screenInfo = new ScreenInfo | ||
| { | ||
| DeviceScaleFactor = DpiScaleFactor, | ||
| Rect = rect, | ||
| AvailableRect = availableRect, | ||
| }; | ||
|
|
||
| return screenInfo; | ||
| } | ||
|
|
||
| Structs.Rect IRenderWebBrowser.GetViewRect() => ViewRect; | ||
|
|
||
| bool IRenderWebBrowser.GetScreenPoint(int viewX, int viewY, out int screenX, out int screenY) | ||
| { | ||
| screenX = ViewRect.X + viewX; | ||
| screenY = ViewRect.Y + viewY; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void IRenderWebBrowser.OnAcceleratedPaint(PaintElementType type, Structs.Rect dirtyRect, IntPtr sharedHandle) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| void IRenderWebBrowser.OnPaint(PaintElementType type, Structs.Rect dirtyRect, IntPtr buffer, int width, int height) | ||
| { | ||
| var dirtyRectCopy = new Interface.Rect(dirtyRect.X, dirtyRect.Y, dirtyRect.Width, dirtyRect.Height); | ||
| string file = type == PaintElementType.Popup | ||
| ? popupRenderHandler.OnPaint(buffer, width, height) | ||
| : renderHandler.OnPaint(buffer, width, height); | ||
|
|
||
| OutofProcessHostRpc.NotifyPaint(Id, type == PaintElementType.Popup, dirtyRectCopy, width, height, file); | ||
| } | ||
|
|
||
| void IRenderWebBrowser.OnCursorChange(IntPtr cursor, CursorType type, CursorInfo customCursorInfo) | ||
| { | ||
| // not implemented | ||
| } | ||
|
|
||
| bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask mask, int x, int y) | ||
| { | ||
| // not implemented | ||
| return false; | ||
| } | ||
|
|
||
| void IRenderWebBrowser.UpdateDragCursor(DragOperationsMask operation) | ||
| { | ||
| // not implemented | ||
| } | ||
|
|
||
| void IRenderWebBrowser.OnPopupShow(bool show) => OutofProcessHostRpc.NotifyPopupShow(Id, show); | ||
|
|
||
| void IRenderWebBrowser.OnPopupSize(CefSharp.Structs.Rect rect) => OutofProcessHostRpc.NotifyPopupSize(Id, new Interface.Rect(rect.X, rect.Y, rect.Width, rect.Height)); | ||
|
|
||
| void IRenderWebBrowser.OnImeCompositionRangeChanged(Structs.Range selectedRange, CefSharp.Structs.Rect[] characterBounds) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| void IRenderWebBrowser.OnVirtualKeyboardRequested(IBrowser browser, TextInputMode inputMode) | ||
| { | ||
| // not implemented | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hier meckert er bei mir, weil rect nicht initalisiert wurde