From bfcbbfc15f5b05a6ce91ae2e7fa7678474458607 Mon Sep 17 00:00:00 2001 From: anthony taranto Date: Wed, 8 Jun 2011 19:38:49 -0700 Subject: [PATCH] CefWpfWebBrowser inherits from ContentControl, embeds Image control to manage stretch/sizing --- CefSharp/CefWpfWebBrowser.cpp | 24 ++++++++++++++++++++---- CefSharp/CefWpfWebBrowser.h | 10 +++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CefSharp/CefWpfWebBrowser.cpp b/CefSharp/CefWpfWebBrowser.cpp index ffc9ab061..3d6c51739 100644 --- a/CefSharp/CefWpfWebBrowser.cpp +++ b/CefSharp/CefWpfWebBrowser.cpp @@ -176,6 +176,22 @@ namespace CefSharp _browserInitialized->WaitOne(); } + void CefWpfWebBrowser::OnApplyTemplate() + { + ContentControl::OnApplyTemplate(); + + _image = (Image^)GetTemplateChild("PART_Image"); + + if (_image == nullptr) + { + Content = _image = gcnew Image(); + + _image->Stretch = Stretch::None; + _image->HorizontalAlignment = System::Windows::HorizontalAlignment::Left; + _image->VerticalAlignment = System::Windows::VerticalAlignment::Top; + } + } + Size CefWpfWebBrowser::ArrangeOverride(Size size) { try @@ -187,19 +203,19 @@ namespace CefSharp // ArrangeOverride may be called one or more times before Cef is initialized } - return Image::ArrangeOverride(size); + return ContentControl::ArrangeOverride(size); } void CefWpfWebBrowser::OnGotFocus(RoutedEventArgs^ e) { _clientAdapter->GetCefBrowser()->SendFocusEvent(true); - Image::OnGotFocus(e); + ContentControl::OnGotFocus(e); } void CefWpfWebBrowser::OnLostFocus(RoutedEventArgs^ e) { _clientAdapter->GetCefBrowser()->SendFocusEvent(false); - Image::OnLostFocus(e); + ContentControl::OnLostFocus(e); } void CefWpfWebBrowser::OnMouseMove(MouseEventArgs^ e) @@ -337,7 +353,7 @@ namespace CefSharp _bitmap->PixelWidth != _width || _bitmap->PixelHeight != _height) { - Source = _bitmap = gcnew WriteableBitmap(_width, _height, 96 * _transform.M11, 96 * _transform.M22, PixelFormats::Bgr32, nullptr); + _image->Source = _bitmap = gcnew WriteableBitmap(_width, _height, 96 * _transform.M11, 96 * _transform.M22, PixelFormats::Bgr32, nullptr); } Int32Rect rect; diff --git a/CefSharp/CefWpfWebBrowser.h b/CefSharp/CefWpfWebBrowser.h index 515a2b7c7..88cda64af 100644 --- a/CefSharp/CefWpfWebBrowser.h +++ b/CefSharp/CefWpfWebBrowser.h @@ -21,7 +21,8 @@ using namespace System::Threading; namespace CefSharp { - public ref class CefWpfWebBrowser sealed : public Image, ICefWebBrowser + [TemplatePart(Name="PART_Browser", Type=System::Windows::Controls::Image::typeid)] + public ref class CefWpfWebBrowser sealed : public ContentControl, ICefWebBrowser { bool _canGoForward; bool _canGoBack; @@ -40,6 +41,8 @@ namespace CefSharp RtzCountdownEvent^ _loadCompleted; ManualResetEvent^ _browserInitialized; + Image^ _image; + Matrix _transform; int _width, _height; void *_buffer; @@ -65,8 +68,7 @@ namespace CefSharp Focusable = true; FocusVisualStyle = nullptr; - //Stretch = System::Windows::Media::Stretch::None; - //StretchDirection = System::Windows::Controls::StretchDirection::DownOnly; + if (!CEF::IsInitialized) { @@ -92,6 +94,8 @@ namespace CefSharp CefBrowser::CreateBrowser(window, static_cast>(ptr), toNative(address), settings); } + virtual void OnApplyTemplate() override; + void Load(String^ url); void WaitForLoadCompletion(); void WaitForLoadCompletion(int timeout);