mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 11:42:36 +00:00
CefWpfWebBrowser inherits from ContentControl, embeds Image control to manage stretch/sizing
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<CefRefPtr<CefClient>>(ptr), toNative(address), settings);
|
||||
}
|
||||
|
||||
virtual void OnApplyTemplate() override;
|
||||
|
||||
void Load(String^ url);
|
||||
void WaitForLoadCompletion();
|
||||
void WaitForLoadCompletion(int timeout);
|
||||
|
||||
Reference in New Issue
Block a user