mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 12:09:40 +00:00
Adding .Net enum of CefThreadId (mostly to be able to call .ToString()).
Added license headers on new files. Remove sync version of GetZoomLevel on ManagedCefBrowserAdapter. Updated callers to call GetZoomLevelAsync() but in a blocking sync manner. Added CurrentlyOn/EnsureOn static methods to CefTaskScheduler.
This commit is contained in:
@@ -1,32 +1,31 @@
|
||||
// Copyright © 2010-2015 The CefSharp Project. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
#include "Stdafx.h"
|
||||
#include "Cef.h"
|
||||
|
||||
double ManagedCefBrowserAdapter::GetZoomLevel()
|
||||
{
|
||||
CefTaskScheduler::EnsureOn(TID_UI, "ManagedCefBrowserAdapter::GetZoomLevel");
|
||||
|
||||
auto browser = _clientAdapter->GetCefBrowser();
|
||||
|
||||
if (browser != nullptr)
|
||||
{
|
||||
auto host = browser->GetHost();
|
||||
if (CefCurrentlyOn(TID_UI))
|
||||
{
|
||||
return host->GetZoomLevel();
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Add an async version of GetZoomLevel at some point.
|
||||
// NOTE: Use of ManualResetEvent is required here in order
|
||||
// for simple marshaling of some kind of synchronization primitive
|
||||
// to the callback.
|
||||
Task<double>^ task = Cef::UIThreadTaskFactory->StartNew(gcnew Func<double>(this, &ManagedCefBrowserAdapter::GetZoomLevel));
|
||||
task->Wait();
|
||||
return task->Result;
|
||||
}
|
||||
return host->GetZoomLevel();
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
Task<double>^ ManagedCefBrowserAdapter::GetZoomLevelAsync()
|
||||
{
|
||||
if (CefCurrentlyOn(TID_UI))
|
||||
{
|
||||
TaskCompletionSource<double>^ taskSource = gcnew TaskCompletionSource<double>();
|
||||
taskSource->SetResult(GetZoomLevel());
|
||||
return taskSource->Task;
|
||||
}
|
||||
return Cef::UIThreadTaskFactory->StartNew(gcnew Func<double>(this, &ManagedCefBrowserAdapter::GetZoomLevel));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user