From c09dcfbb342fa46bf5ee4e6fc4cf3cac4dfc66cb Mon Sep 17 00:00:00 2001 From: fddima Date: Thu, 9 Dec 2010 23:40:32 +0200 Subject: [PATCH] Ready event added. Also after when browser ready it is automatically resize it to control size. (Dirty commit, may not compiles). --- CefSharp/BrowserControl.cpp | 12 ++++++++++-- CefSharp/BrowserControl.h | 7 ++++++- CefSharp/HandlerAdapter.cpp | 2 ++ CefSharp/HandlerAdapter.h | 11 ++++++++--- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CefSharp/BrowserControl.cpp b/CefSharp/BrowserControl.cpp index 9bed2b9da..0c6bfef0c 100644 --- a/CefSharp/BrowserControl.cpp +++ b/CefSharp/BrowserControl.cpp @@ -64,9 +64,17 @@ namespace CefSharp throw gcnew Exception("RunScript Exception:" + _jsError); } + void BrowserControl::OnReady(EventArgs^ e) + { + OnSizeChanged(this, EventArgs::Empty); + + // todo: raise Ready event with control begininvoke + Ready(this, e); + } + void BrowserControl::OnHandleCreated(EventArgs^ e) { - if(DesignMode == false) + if (DesignMode == false) { _handlerAdapter = new HandlerAdapter(this); CefRefPtr ptr = _handlerAdapter.get(); @@ -87,7 +95,7 @@ namespace CefSharp void BrowserControl::OnSizeChanged(EventArgs^ e) { - if(DesignMode == false) + if (DesignMode == false && _handlerAdapter != nullptr && _handlerAdapter->GetIsReady()) { HWND hWnd = static_cast(Handle.ToPointer()); RECT rect; diff --git a/CefSharp/BrowserControl.h b/CefSharp/BrowserControl.h index 97648b64e..59901696a 100644 --- a/CefSharp/BrowserControl.h +++ b/CefSharp/BrowserControl.h @@ -30,11 +30,15 @@ namespace CefSharp String^ _jsResult; String^ _jsError; + //TODO: add manual event to signal browser ready + protected: - virtual void OnHandleCreated(EventArgs^ e) override; virtual void OnSizeChanged(EventArgs^ e) override; + protected internal: + virtual void OnReady(EventArgs^ e); + internal: void SetTitle(String^ title); @@ -108,6 +112,7 @@ namespace CefSharp } virtual event PropertyChangedEventHandler^ PropertyChanged; + event EventHandler^ Ready; event ConsoleMessageEventHandler^ ConsoleMessage; }; diff --git a/CefSharp/HandlerAdapter.cpp b/CefSharp/HandlerAdapter.cpp index 0b0e34d6e..52a171a87 100644 --- a/CefSharp/HandlerAdapter.cpp +++ b/CefSharp/HandlerAdapter.cpp @@ -15,6 +15,8 @@ namespace CefSharp { _browserHwnd = browser->GetWindowHandle(); _cefBrowser = browser; + + _browserControl->OnReady(EventArgs::Empty); } return RV_CONTINUE; } diff --git a/CefSharp/HandlerAdapter.h b/CefSharp/HandlerAdapter.h index 4655bda11..3e94a2359 100644 --- a/CefSharp/HandlerAdapter.h +++ b/CefSharp/HandlerAdapter.h @@ -14,9 +14,10 @@ namespace CefSharp HWND _browserHwnd; CefRefPtr _cefBrowser; - void ThrowIfCefBrowserIsNotReady() + private: + void ThrowIfIsNotReady() { - if (_cefBrowser == nullptr) + if (!GetIsReady()) { //TODO: make own exception type? throw gcnew InvalidOperationException("CefBrowser is not ready."); @@ -63,9 +64,13 @@ namespace CefSharp HWND GetBrowserHwnd() { return _browserHwnd; } CefRefPtr GetCefBrowser() { - ThrowIfCefBrowserIsNotReady(); + ThrowIfIsNotReady(); return _cefBrowser; } + bool GetIsReady() + { + return _cefBrowser != nullptr; + } }; }; \ No newline at end of file