Skip to content

Commit f487f2b

Browse files
committed
IBrowserHost - Add GetZoomLevel
Can be called directly on the CEF UI thread
1 parent aab505a commit f487f2b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CefSharp.Core/Internals/CefBrowserHostWrapper.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ void CefBrowserHostWrapper::SetZoomLevel(double zoomLevel)
108108
_browserHost->SetZoomLevel(zoomLevel);
109109
}
110110

111+
double CefBrowserHostWrapper::GetZoomLevel()
112+
{
113+
ThrowIfDisposed();
114+
115+
if (CefCurrentlyOn(TID_UI))
116+
{
117+
118+
return _browserHost->GetZoomLevel();
119+
}
120+
121+
throw gcnew InvalidOperationException("This method can only be called directly on the CEF UI Thread. Use GetZoomLevelAsync or use Cef.UIThreadTaskFactory to marshal the call onto the CEF UI Thread.");
122+
123+
}
124+
111125
Task<double>^ CefBrowserHostWrapper::GetZoomLevelAsync()
112126
{
113127
ThrowIfDisposed();

CefSharp.Core/Internals/CefBrowserHostWrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace CefSharp
4646
virtual void Print();
4747
virtual void PrintToPdf(String^ path, PdfPrintSettings^ settings, IPrintToPdfCallback^ callback);
4848
virtual void SetZoomLevel(double zoomLevel);
49+
virtual double GetZoomLevel();
4950
virtual Task<double>^ GetZoomLevelAsync();
5051
virtual IntPtr GetWindowHandle();
5152
virtual void CloseBrowser(bool forceClose);

CefSharp/IBrowserHost.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,14 @@ public interface IBrowserHost : IDisposable
118118
IntPtr GetWindowHandle();
119119

120120
/// <summary>
121-
/// Get the current zoom level. The default zoom level is 0.0. This method can only be called on the CEF UI thread.
121+
/// Gets the current zoom level. The default zoom level is 0.0. This method can only be called on the CEF UI thread.
122+
/// </summary>
123+
/// <returns>zoom level (default is 0.0)</returns>
124+
double GetZoomLevel();
125+
126+
/// <summary>
127+
/// Get the current zoom level. The default zoom level is 0.0. This method executes GetZoomLevel on the CEF UI thread
128+
/// in an async fashion.
122129
/// </summary>
123130
/// <returns> a <see cref="Task{Double}"/> that when executed returns the zoom level as a double.</returns>
124131
Task<double> GetZoomLevelAsync();

0 commit comments

Comments
 (0)