Repository navigation
Expand file tree
/
Copy pathDefaultRenderHandler.cs
More file actions
146 lines (114 loc) · 4.03 KB
/
Copy pathDefaultRenderHandler.cs
File metadata and controls
146 lines (114 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// 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;
using CefSharp.Enums;
using CefSharp.Structs;
using Point = System.Drawing.Point;
using Size = System.Drawing.Size;
namespace CefSharp.OffScreen
{
public class DefaultRenderHandler : IRenderHandler
{
private ChromiumWebBrowser browser;
private Size popupSize;
private Point popupPosition;
/// <summary>
/// Need a lock because the caller may be asking for the bitmap
/// while Chromium async rendering has returned on another thread.
/// </summary>
public readonly object BitmapLock = new object();
/// <summary>
/// Gets or sets a value indicating whether the popup is open.
/// </summary>
/// <value>
/// <c>true</c> if popup is opened; otherwise, <c>false</c>.
/// </value>
public bool PopupOpen { get; protected set; }
/// <summary>
/// Contains the last bitmap buffer. Direct access
/// to the underlying buffer - there is no locking when trying
/// to access directly, use <see cref="BitmapBuffer.BitmapLock" /> where appropriate.
/// </summary>
/// <value>The bitmap.</value>
public BitmapBuffer BitmapBuffer { get; private set; }
/// <summary>
/// The popup Bitmap.
/// </summary>
public BitmapBuffer PopupBuffer { get; private set; }
/// <summary>
/// Gets the size of the popup.
/// </summary>
public Size PopupSize
{
get { return popupSize; }
}
/// <summary>
/// Gets the popup position.
/// </summary>
public Point PopupPosition
{
get { return popupPosition; }
}
public DefaultRenderHandler(ChromiumWebBrowser browser)
{
this.browser = browser;
popupPosition = new Point();
popupSize = new Size();
BitmapBuffer = new BitmapBuffer(BitmapLock);
PopupBuffer = new BitmapBuffer(BitmapLock);
}
public void Dispose()
{
browser = null;
}
public virtual ScreenInfo? GetScreenInfo()
{
var screenInfo = new ScreenInfo { DeviceScaleFactor = 1.0F };
return screenInfo;
}
public virtual Rect? GetViewRect()
{
//TODO: See if this can be refactored and remove browser reference
var size = browser.Size;
var viewRect = new Rect(0, 0, size.Width, size.Height);
return viewRect;
}
public virtual bool GetScreenPoint(int viewX, int viewY, out int screenX, out int screenY)
{
screenX = viewX;
screenY = viewY;
return false;
}
public virtual void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height)
{
var isPopup = type == PaintElementType.Popup;
var bitmapBuffer = isPopup ? PopupBuffer : BitmapBuffer;
bitmapBuffer.UpdateBuffer(width, height, buffer, dirtyRect);
}
public virtual void OnCursorChange(IntPtr cursor, CursorType type, CursorInfo customCursorInfo)
{
}
public virtual bool StartDragging(IDragData dragData, DragOperationsMask mask, int x, int y)
{
return false;
}
public virtual void UpdateDragCursor(DragOperationsMask operation)
{
}
public virtual void OnPopupShow(bool show)
{
PopupOpen = show;
}
public virtual void OnPopupSize(Rect rect)
{
popupPosition.X = rect.X;
popupPosition.Y = rect.Y;
popupSize.Width = rect.Width;
popupSize.Height = rect.Height;
}
public virtual void OnImeCompositionRangeChanged(Range selectedRange, Rect[] characterBounds)
{
}
}
}