From 4297893b616c0f3f9bf7917bcea5750564bfd732 Mon Sep 17 00:00:00 2001 From: "treverj@tjdiversified.com" Date: Wed, 3 Dec 2014 09:25:46 -0600 Subject: [PATCH] Code cleanup and changes based on comments --- CefSharp.Core/ManagedCefBrowserAdapter.h | 57 +++++++++++------------- CefSharp.WinForms/ChromiumWebBrowser.cs | 2 +- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.h b/CefSharp.Core/ManagedCefBrowserAdapter.h index c6685955f..b60ba5bdc 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.h +++ b/CefSharp.Core/ManagedCefBrowserAdapter.h @@ -26,6 +26,8 @@ namespace CefSharp JavascriptObjectRepository^ _javaScriptObjectRepository; protected: + + virtual void DoDispose(bool isDisposing) override { Close(); @@ -43,6 +45,7 @@ namespace CefSharp DisposableResource::DoDispose(isDisposing); }; + public: ManagedCefBrowserAdapter(IWebBrowserInternal^ webBrowserInternal) { @@ -471,38 +474,32 @@ namespace CefSharp *(CefBrowserSettings*)browserSettings->_internalBrowserSettings, NULL); } - void Resize(int width, int height) - { - CefWindowHandle hwnd = _renderClientAdapter->TryGetCefHost()->GetWindowHandle(); - if (hwnd) { - if (width <= 0 && height <= 0) { - // For windowed browsers when the frame window is minimized set the - // browser window size to 0x0 to reduce resource usage. - SetWindowPos(hwnd, NULL, - 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); - } - else { - // Resize the window and address bar to match the new frame size. - RECT rect; - GetClientRect(hwnd, &rect); - HDWP hdwp = BeginDeferWindowPos(1); - hdwp = DeferWindowPos(hdwp, hwnd, NULL, - 0, 0, width, - height, SWP_NOZORDER); - EndDeferWindowPos(hdwp); - } - } - } + void Resize(int width, int height) + { + HWND browserHwnd = _renderClientAdapter->GetBrowserHwnd(); + if (browserHwnd) { + if (width == 0 && height == 0) + { + // For windowed browsers when the frame window is minimized set the + // browser window size to 0x0 to reduce resource usage. + SetWindowPos(browserHwnd, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); + } + else + { + SetWindowPos(browserHwnd, NULL, 0, 0, width, height, SWP_NOZORDER); + } + } + } - void NotifyMoveOrResizeStarted() - { - auto cefHost = _renderClientAdapter->TryGetCefHost(); + void NotifyMoveOrResizeStarted() + { + auto cefHost = _renderClientAdapter->TryGetCefHost(); - if (cefHost != nullptr) - { - cefHost->NotifyMoveOrResizeStarted(); - } - } + if (cefHost != nullptr) + { + cefHost->NotifyMoveOrResizeStarted(); + } + } void RegisterJsObject(String^ name, Object^ object) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 559de14ac..47bf407f1 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -34,6 +34,7 @@ namespace CefSharp.WinForms public bool CanReload { get; private set; } public bool IsBrowserInitialized { get; private set; } + public double ZoomLevel { get { return managedCefBrowserAdapter.GetZoomLevel(); } @@ -348,7 +349,6 @@ namespace CefSharp.WinForms protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); - ResizeBrowser(); }