<commit_before>#include "stdafx.h"
#pragma once

#include "CefSharp.h"
#include "WpfClientAdapter.h"
#include "ICefWebBrowser.h"
#include "ConsoleMessageEventArgs.h"
#include "RtzCountdownEvent.h"

using namespace Microsoft::Win32::SafeHandles;
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Windows;
using namespace System::Windows::Controls;
using namespace System::Windows::Input;
using namespace System::Windows::Interop;
using namespace System::Windows::Media;
using namespace System::Windows::Media::Imaging;
using namespace System::Windows::Threading;
using namespace System::Threading;

namespace CefSharp
{
    [TemplatePart(Name="PART_Browser", Type=System::Windows::Controls::Image::typeid)]
    public ref class CefWpfWebBrowser sealed : public ContentControl, ICefWebBrowser
    {
        bool _canGoForward;
        bool _canGoBack;
        bool _isLoading;
		bool _shouldOpenLinksInExternalBrowser;

        String^ _address;
        String^ _title;
        String^ _jsResult;
        bool _jsError;

        IBeforePopup^ _beforePopupHandler;
        IBeforeResourceLoad^ _beforeResourceLoadHandler;
        IBeforeMenu^ _beforeMenuHandler;
        IAfterResponse^ _afterResponseHandler;
        MCefRefPtr<WpfClientAdapter> _clientAdapter;

        AutoResetEvent^ _runJsFinished;
        RtzCountdownEvent^ _loadCompleted;
        ManualResetEvent^ _browserInitialized;

        Image^ _image;

        Matrix _transform;
        int _width, _height;
        void *_buffer;
        WriteableBitmap^ _bitmap;

		double _contentWidth;
		double _contentHeight;

        bool _mouseIsDown;
        CefBrowser::MouseButtonType _depressedMouseButton;

    private:
        void SetCursor(SafeFileHandle^ handle);
        IntPtr SourceHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, bool% handled);
		void Setup(HwndSource^ source, String^ address);

    protected:
        virtual Size ArrangeOverride(Size size) override;
        virtual void OnGotFocus(RoutedEventArgs^ e) override;
        virtual void OnLostFocus(RoutedEventArgs^ e) override;
        virtual void OnMouseMove(System::Windows::Input::MouseEventArgs^ e) override;
        virtual void OnMouseLeave(System::Windows::Input::MouseEventArgs^ e) override;
        virtual void OnMouseWheel(MouseWheelEventArgs^ e) override;
        virtual void OnMouseDown(MouseButtonEventArgs^ e) override;
        virtual void OnMouseUp(MouseButtonEventArgs^ e) override;
        virtual void OnLostMouseCapture(MouseEventArgs^ e) override;

    public:
        CefWpfWebBrowser(HwndSource^ source, String^ address)
        {
			Setup(source, address);
        }

		CefWpfWebBrowser() {}

        virtual void OnApplyTemplate() override;

        void Load(String^ url);
        void Stop();
        void Back();
        void Forward();
        void Reload();
        void Reload(bool ignoreCache);
        void Print();
        String^ RunScript(String^ script, String^ scriptUrl, int startLine);
        String^ RunScript(String^ script, String^ scriptUrl, int startLine, int timeout);
		void UpdateContentSize(double width, double height);

        virtual void OnInitialized();

        virtual void SetTitle(String^ title);
        virtual void SetToolTip(String^ text);
        virtual void SetAddress(String^ address);
        virtual void SetNavState(bool isLoading, bool canGoBack, bool canGoForward);
        
        virtual void AddFrame(CefRefPtr<CefFrame> frame);
        virtual void FrameLoadComplete(CefRefPtr<CefFrame> frame);

        virtual void SetJsResult(String^ result);
        virtual void SetJsError();
        virtual void RaiseConsoleMessage(String^ message, String^ source, int line);

        virtual property IBeforePopup^ BeforePopupHandler
        {
            IBeforePopup^ get() { return _beforePopupHandler; }
            void set(IBeforePopup^ handler) { _beforePopupHandler = handler; }
        }

        virtual property IBeforeResourceLoad^ BeforeResourceLoadHandler
        {
            IBeforeResourceLoad^ get() { return _beforeResourceLoadHandler; }
            void set(IBeforeResourceLoad^ handler) { _beforeResourceLoadHandler = handler; }
        }

        virtual property IBeforeMenu^ BeforeMenuHandler
        {
            IBeforeMenu^ get() { return _beforeMenuHandler; }
            void set(IBeforeMenu^ handler) { _beforeMenuHandler = handler; }
        }

        virtual property IAfterResponse^ AfterResponseHandler
        {
            IAfterResponse^ get() { return _afterResponseHandler; }
            void set(IAfterResponse^ handler) { _afterResponseHandler = handler; }
        }

        property String^ Title
        {
            String^ get() { return _title; }
        }

        property String^ Address
        {
            String^ get() { return _address; }
        }

        property bool CanGoForward
        { 
            bool get() { return _canGoForward; } 
        }

        property bool CanGoBack
        { 
            bool get() { return _canGoBack; } 
        }

        property bool IsLoading
        {
            bool get() { return _isLoading; }
        }

		property double ContentWidth
		{
			double get() { return _contentWidth; }
		}

		property double ContentHeight
		{
			double get() { return _contentHeight; }
		}

        property bool IsInitialized
        {
            bool get()
            {
                return _clientAdapter.get() != nullptr && _clientAdapter->GetIsInitialized();
            }
        }

		property bool ShouldOpenLinksInExternalBrowser
		{
			virtual bool get() { return _shouldOpenLinksInExternalBrowser; }
			virtual void set(bool value) { _shouldOpenLinksInExternalBrowser = value; }
		}
<commit_msg>Expose the zoom level to C#<commit_after>#include "stdafx.h"
#pragma once

#include "CefSharp.h"
#include "WpfClientAdapter.h"
#include "ICefWebBrowser.h"
#include "ConsoleMessageEventArgs.h"
#include "RtzCountdownEvent.h"

using namespace Microsoft::Win32::SafeHandles;
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Windows;
using namespace System::Windows::Controls;
using namespace System::Windows::Input;
using namespace System::Windows::Interop;
using namespace System::Windows::Media;
using namespace System::Windows::Media::Imaging;
using namespace System::Windows::Threading;
using namespace System::Threading;

namespace CefSharp
{
    [TemplatePart(Name="PART_Browser", Type=System::Windows::Controls::Image::typeid)]
    public ref class CefWpfWebBrowser sealed : public ContentControl, ICefWebBrowser
    {
        bool _canGoForward;
        bool _canGoBack;
        bool _isLoading;
		bool _shouldOpenLinksInExternalBrowser;

        String^ _address;
        String^ _title;
        String^ _jsResult;
        bool _jsError;

        IBeforePopup^ _beforePopupHandler;
        IBeforeResourceLoad^ _beforeResourceLoadHandler;
        IBeforeMenu^ _beforeMenuHandler;
        IAfterResponse^ _afterResponseHandler;
        MCefRefPtr<WpfClientAdapter> _clientAdapter;

        AutoResetEvent^ _runJsFinished;
        RtzCountdownEvent^ _loadCompleted;
        ManualResetEvent^ _browserInitialized;

        Image^ _image;

        Matrix _transform;
        int _width, _height;
        void *_buffer;
        WriteableBitmap^ _bitmap;

		double _contentWidth;
		double _contentHeight;

        bool _mouseIsDown;
        CefBrowser::MouseButtonType _depressedMouseButton;

    private:
        void SetCursor(SafeFileHandle^ handle);
        IntPtr SourceHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, bool% handled);
		void Setup(HwndSource^ source, String^ address);

    protected:
        virtual Size ArrangeOverride(Size size) override;
        virtual void OnGotFocus(RoutedEventArgs^ e) override;
        virtual void OnLostFocus(RoutedEventArgs^ e) override;
        virtual void OnMouseMove(System::Windows::Input::MouseEventArgs^ e) override;
        virtual void OnMouseLeave(System::Windows::Input::MouseEventArgs^ e) override;
        virtual void OnMouseWheel(MouseWheelEventArgs^ e) override;
        virtual void OnMouseDown(MouseButtonEventArgs^ e) override;
        virtual void OnMouseUp(MouseButtonEventArgs^ e) override;
        virtual void OnLostMouseCapture(MouseEventArgs^ e) override;

    public:
        CefWpfWebBrowser(HwndSource^ source, String^ address)
        {
			Setup(source, address);
        }

		CefWpfWebBrowser() {}

        virtual void OnApplyTemplate() override;

        void Load(String^ url);
        void Stop();
        void Back();
        void Forward();
        void Reload();
        void Reload(bool ignoreCache);
        void Print();
        String^ RunScript(String^ script, String^ scriptUrl, int startLine);
        String^ RunScript(String^ script, String^ scriptUrl, int startLine, int timeout);
		void UpdateContentSize(double width, double height);

        virtual void OnInitialized();

        virtual void SetTitle(String^ title);
        virtual void SetToolTip(String^ text);
        virtual void SetAddress(String^ address);
        virtual void SetNavState(bool isLoading, bool canGoBack, bool canGoForward);
        
        virtual void AddFrame(CefRefPtr<CefFrame> frame);
        virtual void FrameLoadComplete(CefRefPtr<CefFrame> frame);

        virtual void SetJsResult(String^ result);
        virtual void SetJsError();
        virtual void RaiseConsoleMessage(String^ message, String^ source, int line);

        virtual property IBeforePopup^ BeforePopupHandler
        {
            IBeforePopup^ get() { return _beforePopupHandler; }
            void set(IBeforePopup^ handler) { _beforePopupHandler = handler; }
        }

        virtual property IBeforeResourceLoad^ BeforeResourceLoadHandler
        {
            IBeforeResourceLoad^ get() { return _beforeResourceLoadHandler; }
            void set(IBeforeResourceLoad^ handler) { _beforeResourceLoadHandler = handler; }
        }

        virtual property IBeforeMenu^ BeforeMenuHandler
        {
            IBeforeMenu^ get() { return _beforeMenuHandler; }
            void set(IBeforeMenu^ handler) { _beforeMenuHandler = handler; }
        }

        virtual property IAfterResponse^ AfterResponseHandler
        {
            IAfterResponse^ get() { return _afterResponseHandler; }
            void set(IAfterResponse^ handler) { _afterResponseHandler = handler; }
        }

        property String^ Title
        {
            String^ get() { return _title; }
        }

        property String^ Address
        {
            String^ get() { return _address; }
        }

        property bool CanGoForward
        { 
            bool get() { return _canGoForward; } 
        }

        property bool CanGoBack
        { 
            bool get() { return _canGoBack; } 
        }

        property bool IsLoading
        {
            bool get() { return _isLoading; }
        }

		property double ContentWidth
		{
			double get() { return _contentWidth; }
		}

		property double ContentHeight
		{
			double get() { return _contentHeight; }
		}

		property double ZoomLevel
		{
			double get() { 
				if (!this->IsInitialized) {
					return 1.0;
				}

				return _clientAdapter.get()->GetCefBrowser()->GetZoomLevel(); 
			}
			void set(double val) {
				if (!this->IsInitialized) {
					return;
				}
				
				_clientAdapter.get()->GetCefBrowser()->SetZoomLevel(val);
			}
		}

        property bool IsInitialized
        {
            bool get()
            {
                return _clientAdapter.get() != nullptr && _clientAdapter->GetIsInitialized();
            }
        }

		property bool ShouldOpenLinksInExternalBrowser
		{
			virtual bool get() { return _shouldOpenLinksInExternalBrowser; }
			virtual void set(bool value) { _shouldOpenLinksInExternalBrowser = value; }
		}

{'fraction_non_alphanumeric': 0.08212031973075305, 'fraction_numerical': 0.0005048380311316786, 'mean_word_length': 2.859090909090909, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4303058', 'n_tokens_mistral': 3253, 'n_tokens_neox': 3102, 'n_words': 813}