Skip to content

Commit 9b4d68b

Browse files
committed
WPF - Allow overriding of IRenderWebBrowser implementation methods
- Add additional protected virtual methods so deriving classes can override
1 parent e1b0d07 commit 9b4d68b

File tree

1 file changed

+50
-19
lines changed

1 file changed

+50
-19
lines changed

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,21 @@ protected virtual Rect GetViewRect()
758758
return viewRect;
759759
}
760760

761+
/// <inheritdoc />
761762
bool IRenderWebBrowser.GetScreenPoint(int viewX, int viewY, out int screenX, out int screenY)
763+
{
764+
return GetScreenPoint(viewX, viewY, out screenX, out screenY);
765+
}
766+
767+
/// <summary>
768+
/// Called to retrieve the translation from view coordinates to actual screen coordinates.
769+
/// </summary>
770+
/// <param name="viewX">x</param>
771+
/// <param name="viewY">y</param>
772+
/// <param name="screenX">screen x</param>
773+
/// <param name="screenY">screen y</param>
774+
/// <returns>Return true if the screen coordinates were provided.</returns>
775+
protected virtual bool GetScreenPoint(int viewX, int viewY, out int screenX, out int screenY)
762776
{
763777
screenX = 0;
764778
screenY = 0;
@@ -779,6 +793,12 @@ bool IRenderWebBrowser.GetScreenPoint(int viewX, int viewY, out int screenX, out
779793
return true;
780794
}
781795

796+
/// <inheritdoc />
797+
bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask allowedOps, int x, int y)
798+
{
799+
return StartDragging(dragData, allowedOps, x, y);
800+
}
801+
782802
/// <summary>
783803
/// Called when the user starts dragging content in the web view.
784804
/// OS APIs that run a system message loop may be used within the StartDragging call.
@@ -790,7 +810,7 @@ bool IRenderWebBrowser.GetScreenPoint(int viewX, int viewY, out int screenX, out
790810
/// <param name="x">is the drag start location in screen coordinates</param>
791811
/// <param name="y">is the drag start location in screen coordinates</param>
792812
/// <returns>Return true to handle the drag operation.</returns>
793-
bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask allowedOps, int x, int y)
813+
protected virtual bool StartDragging(IDragData dragData, DragOperationsMask allowedOps, int x, int y)
794814
{
795815
var dataObject = new DataObject();
796816

@@ -833,6 +853,7 @@ bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask allo
833853
return true;
834854
}
835855

856+
/// <inheritdoc />
836857
void IRenderWebBrowser.UpdateDragCursor(DragOperationsMask operation)
837858
{
838859
UpdateDragCursor(operation);
@@ -847,13 +868,7 @@ protected virtual void UpdateDragCursor(DragOperationsMask operation)
847868
currentDragDropEffects = operation.GetDragEffects();
848869
}
849870

850-
/// <summary>
851-
/// Called when an element has been rendered to the shared texture handle.
852-
/// This method is only called when <see cref="IWindowInfo.SharedTextureEnabled"/> is set to true
853-
/// </summary>
854-
/// <param name="type">indicates whether the element is the view or the popup widget.</param>
855-
/// <param name="dirtyRect">contains the set of rectangles in pixel coordinates that need to be repainted</param>
856-
/// <param name="sharedHandle">is the handle for a D3D11 Texture2D that can be accessed via ID3D11Device using the OpenSharedResource method.</param>
871+
/// <inheritdoc />
857872
void IRenderWebBrowser.OnAcceleratedPaint(PaintElementType type, Rect dirtyRect, IntPtr sharedHandle)
858873
{
859874
OnAcceleratedPaint(type == PaintElementType.Popup, dirtyRect, sharedHandle);
@@ -871,14 +886,7 @@ protected virtual void OnAcceleratedPaint(bool isPopup, Rect dirtyRect, IntPtr s
871886
RenderHandler?.OnAcceleratedPaint(isPopup, dirtyRect, sharedHandle);
872887
}
873888

874-
/// <summary>
875-
/// Called when an element should be painted.
876-
/// </summary>
877-
/// <param name="type">indicates whether the element is the view or the popup widget.</param>
878-
/// <param name="dirtyRect">contains the set of rectangles in pixel coordinates that need to be repainted</param>
879-
/// <param name="buffer">The bitmap will be will be width * height *4 bytes in size and represents a BGRA image with an upper-left origin</param>
880-
/// <param name="width">width</param>
881-
/// <param name="height">height</param>
889+
/// <inheritdoc />
882890
void IRenderWebBrowser.OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height)
883891
{
884892
OnPaint(type == PaintElementType.Popup, dirtyRect, buffer, width, height);
@@ -918,11 +926,17 @@ protected virtual void OnPaint(bool isPopup, Rect dirtyRect, IntPtr buffer, int
918926
RenderHandler?.OnPaint(isPopup, dirtyRect, buffer, width, height, img);
919927
}
920928

929+
/// <inheritdoc />
930+
void IRenderWebBrowser.OnPopupSize(Rect rect)
931+
{
932+
OnPopupSize(rect);
933+
}
934+
921935
/// <summary>
922936
/// Sets the popup size and position.
923937
/// </summary>
924938
/// <param name="rect">The popup rectangle (size and position).</param>
925-
void IRenderWebBrowser.OnPopupSize(Rect rect)
939+
protected virtual void OnPopupSize(Rect rect)
926940
{
927941
UiThreadRunAsync(() => SetPopupSizeAndPositionImpl(rect));
928942
}
@@ -932,17 +946,32 @@ void IRenderWebBrowser.OnPopupSize(Rect rect)
932946
/// </summary>
933947
/// <param name="isOpen">if set to <c>true</c> [is open].</param>
934948
void IRenderWebBrowser.OnPopupShow(bool isOpen)
949+
{
950+
OnPopupShow(isOpen);
951+
}
952+
953+
/// <summary>
954+
/// Sets the popup is open.
955+
/// </summary>
956+
/// <param name="isOpen">if set to <c>true</c> [is open].</param>
957+
protected virtual void OnPopupShow(bool isOpen)
935958
{
936959
UiThreadRunAsync(() => { popupImage.Visibility = isOpen ? Visibility.Visible : Visibility.Hidden; });
937960
}
938961

962+
/// <inheritdoc />
963+
void IRenderWebBrowser.OnCursorChange(IntPtr handle, CursorType type, CursorInfo customCursorInfo)
964+
{
965+
OnCursorChange(handle, type, customCursorInfo);
966+
}
967+
939968
/// <summary>
940969
/// Sets the cursor.
941970
/// </summary>
942971
/// <param name="handle">The handle.</param>
943972
/// <param name="type">The type.</param>
944973
/// <param name="customCursorInfo">custom cursor information</param>
945-
void IRenderWebBrowser.OnCursorChange(IntPtr handle, CursorType type, CursorInfo customCursorInfo)
974+
protected virtual void OnCursorChange(IntPtr handle, CursorType type, CursorInfo customCursorInfo)
946975
{
947976
//Custom cursors are handled differently, for now keep standard ones executing
948977
//in an async fashion
@@ -966,6 +995,7 @@ void IRenderWebBrowser.OnCursorChange(IntPtr handle, CursorType type, CursorInfo
966995
}
967996
}
968997

998+
/// <inheritdoc />
969999
void IRenderWebBrowser.OnImeCompositionRangeChanged(Range selectedRange, Rect[] characterBounds)
9701000
{
9711001
OnImeCompositionRangeChanged(selectedRange, characterBounds);
@@ -985,6 +1015,7 @@ protected virtual void OnImeCompositionRangeChanged(Range selectedRange, Rect[]
9851015
}
9861016
}
9871017

1018+
/// <inheritdoc />
9881019
void IRenderWebBrowser.OnVirtualKeyboardRequested(IBrowser browser, TextInputMode inputMode)
9891020
{
9901021
OnVirtualKeyboardRequested(browser, inputMode);
@@ -1077,7 +1108,7 @@ partial void OnAfterBrowserCreated(IBrowser browser)
10771108
}
10781109
});
10791110

1080-
if(initialFocus)
1111+
if (initialFocus)
10811112
{
10821113
browser.GetHost()?.SendFocusEvent(true);
10831114
}

0 commit comments

Comments
 (0)