Esempio n. 1
0
        private FREObject InitController(FREContext ctx, uint argc, FREObject[] argv)
        {
            // get a reference to the AIR Window HWND
            _airWindow = Process.GetCurrentProcess().MainWindowHandle;

            // Turn on FreSharp logging
            FreSharpLogger.GetInstance().Context = Context;

            return(FREObject.Zero);
        }
        private FREObject InitController(FREContext ctx, uint argc, FREObject[] argv)
        {
            if (argc < 1 || argv[0] == FREObject.Zero)
            {
                return(new FreArgException().RawValue);
            }
            var style = (TaskbarProgress.TaskbarStates)argv[0].AsInt();

            _airWindow = Process.GetCurrentProcess().MainWindowHandle;
            FreSharpLogger.GetInstance().Context = Context;
            TaskbarProgress.SetState(_airWindow, style);
            return(FREObject.Zero);
        }
Esempio n. 3
0
        private FREObject RunStringTests(FREContext ctx, uint argc, FREObject[] argv)
        {
            Warning("I am a test warning");
            Info("I am a test info");
            Trace(@"***********Start String test***********");
            if (argv[0] == FREObject.Zero)
            {
                return(FREObject.Zero);
            }

            FreSharpLogger.GetInstance().Context = Context;

            var airString = argv[0].AsString();

            Trace("String passed from AIR:", airString);
            DispatchEvent("MY_EVENT", "this is a test");

            const string sharpString = "I am a string from C# with UTF-8: Björk Guðmundsdóttir " +
                                       "Sinéad O’Connor 久保田  利伸 Михаил Горбачёв Садриддин Айнӣ " +
                                       "Tor Åge Bringsværd 章子怡 €";

            return(sharpString.ToFREObject());
        }
Esempio n. 4
0
        private FREObject InitView(FREContext ctx, uint argc, FREObject[] argv)
        {
            FreSharpLogger.GetInstance().Context = Context;
            _airWindow = Process.GetCurrentProcess().MainWindowHandle;
            if (_airWindow == Hwnd.Zero)
            {
                return(new FreException(
                           "Cannot find AIR window to attach webView to. Ensure you init the ANE AFTER your main Sprite is initialized. " +
                           "Please see https://forum.starling-framework.org/topic/webviewane-for-osx/page/7?replies=201#post-105524 for more details")
                       .RawValue);
            }

            bool useTransparentBackground;

            try {
                dynamic settings = new FreObjectSharp(argv[2]);
                _useEdge = settings.engine == 1;

                UrlRequestHeaderManager.GetInstance().PersistRequestHeaders = settings.persistRequestHeaders;
                dynamic    cefSettings = new FreObjectSharp(settings.cef);
                var        freUrl      = argv[0];
                UrlRequest initialUrl  = null;
                if (FreObjectTypeSharp.Null != freUrl.Type())
                {
                    initialUrl = new UrlRequest(freUrl, _useEdge);
                    UrlRequestHeaderManager.GetInstance().Add(initialUrl);
                }

                var viewPort = argv[1].AsRect();

                useTransparentBackground = settings.useTransparentBackground;
                FREArray clArr = cefSettings.commandLineArgs;

                var argsDict = new Dictionary <string, string>();
                foreach (var argFre in clArr)
                {
                    var key = argFre.GetProp("key").AsString();
                    var val = argFre.GetProp("value").AsString();
                    if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(val))
                    {
                        continue;
                    }
                    argsDict.Add(key, val);
                }

                ArrayList whiteList = settings.urlWhiteList.AsArrayList();
                ArrayList blackList = settings.urlBlackList.AsArrayList();

                _backgroundColor = argv[4].AsColor();
                var backgroundMediaColor = new System.Windows.Media.Color {
                    A = _backgroundColor.A,
                    R = _backgroundColor.R,
                    G = _backgroundColor.G,
                    B = _backgroundColor.B
                };

                _useHiDpi = settings.useHiDPI;

                if (Environment.OSVersion.Version.Major > 7)
                {
                    _scaleFactor = _useHiDpi ? WinApi.GetScaleFactor(_airWindow) : 1.0;
                }
                else
                {
                    _scaleFactor = _useHiDpi ? WinApi.GetScaleFactor() : 1.0;
                }

                if (_useEdge)
                {
                    EdgeView.Context = Context;
                    _view            = new EdgeView {
                        Background = new SolidColorBrush(backgroundMediaColor)
                    };
                }
                else
                {
                    CefView.Context = Context;
                    dynamic contextMenu = new FreObjectSharp(settings.contextMenu);
                    dynamic popup       = new FreObjectSharp(settings.popup);
                    dynamic dimensions  = new FreObjectSharp(popup.dimensions);

                    _view = new CefView {
                        Background          = new SolidColorBrush(backgroundMediaColor),
                        RemoteDebuggingPort = cefSettings.remoteDebuggingPort,
                        EnablePrintPreview  = cefSettings.enablePrintPreview,
                        CachePath           = cefSettings.cachePath,
                        DownloadPath        = settings.downloadPath,
                        EnableDownloads     = settings.enableDownloads,
                        CacheEnabled        = settings.cacheEnabled,
                        LogLevel            = cefSettings.logSeverity,
                        AcceptLanguageList  = cefSettings.acceptLanguageList,
                        Locale             = cefSettings.locale,
                        ContextMenuEnabled = contextMenu.enabled,
                        UserAgent          = settings.userAgent,
                        UserDataPath       = cefSettings.userDataPath,
                        CommandLineArgs    = argsDict,
                        PopupBehaviour     = (PopupBehaviour)popup.behaviour,
                        PopupDimensions    = new Tuple <int, int>(dimensions.width, dimensions.height),
                        ScaleFactor        = _scaleFactor
                    };
                }

                _view.InitialUrl = initialUrl;
                _view.WhiteList  = whiteList;
                _view.BlackList  = blackList;
                _view.X          = Convert.ToInt32(viewPort.X * _scaleFactor);
                _view.Y          = Convert.ToInt32(viewPort.Y * _scaleFactor);
                _view.ViewWidth  = Convert.ToInt32(viewPort.Width * _scaleFactor);
                _view.ViewHeight = Convert.ToInt32(viewPort.Height * _scaleFactor);
                _view.Init();
            }
            catch (Exception e) {
                return(new FreException(e).RawValue);
            }

            var parameters = new HwndSourceParameters();

            parameters.SetPosition(_view.X, _view.Y);
            parameters.SetSize(_view.ViewWidth, _view.ViewHeight);
            parameters.ParentWindow = _airWindow;
            parameters.WindowName   = "Cef Window";
            parameters.WindowStyle  = (int)WindowStyles.WS_CHILD;
            parameters.AcquireHwndFocusInMenuMode = true;

            if (useTransparentBackground && Environment.OSVersion.Version.Major > 7)
            {
                parameters.ExtendedWindowStyle      = (int)WindowExStyles.WS_EX_LAYERED;
                parameters.UsesPerPixelTransparency = true;
            }

            var source = _useEdge
                ? new HwndSource(parameters)
            {
                RootVisual = (EdgeView)_view
            }
                : new HwndSource(parameters)
            {
                RootVisual = (CefView)_view
            };

            if (useTransparentBackground && source.CompositionTarget != null)
            {
                source.CompositionTarget.BackgroundColor = Colors.Transparent;
            }

            _webViewWindow = source.Handle;

            MessageTouchDevice.RegisterTouchWindow(_webViewWindow);

            return(FREObject.Zero);
        }
Esempio n. 5
0
 private FREObject InitController(FREContext ctx, uint argc, FREObject[] argv)
 {
     FreSharpLogger.GetInstance().Context = Context;
     return(true.ToFREObject());
 }