예제 #1
0
        private FREObject SetVisible(FREContext ctx, uint argc, FREObject[] argv)
        {
            try {
                var visible = argv[0].AsBool();
                WinApi.ShowWindow(_webViewWindow,
                                  visible ? ShowWindowCommands.SW_SHOWNORMAL : ShowWindowCommands.SW_HIDE);
                WinApi.UpdateWindow(_webViewWindow);
            }
            catch (Exception e) {
                return(new FreException(e).RawValue);
            }

            return(FREObject.Zero);
        }
예제 #2
0
        private FREObject SetViewPort(FREContext ctx, uint argc, FREObject[] argv)
        {
            System.Windows.Rect viewPort;
            try {
                viewPort = argv[0].AsRect();
            }
            catch (Exception e) {
                return(new FreException(e).RawValue);
            }

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


            _view.ScaleFactor = _scaleFactor;

            var tmpX      = Convert.ToInt32(viewPort.X * _scaleFactor);
            var tmpY      = Convert.ToInt32(viewPort.Y * _scaleFactor);
            var tmpWidth  = Convert.ToInt32(viewPort.Width * _scaleFactor);
            var tmpHeight = Convert.ToInt32(viewPort.Height * _scaleFactor);

            var updateWidth  = false;
            var updateHeight = false;
            var updateX      = false;
            var updateY      = false;

            if (tmpWidth != _view.ViewWidth)
            {
                _view.ViewWidth = tmpWidth;
                updateWidth     = true;
            }

            if (tmpHeight != _view.ViewHeight)
            {
                _view.ViewHeight = tmpHeight;
                updateHeight     = true;
            }

            if (tmpX != _view.X)
            {
                _view.X = tmpX;
                updateX = true;
            }

            if (tmpY != _view.Y)
            {
                _view.Y = tmpY;
                updateY = true;
            }

            if (!updateX && !updateY && !updateWidth && !updateHeight)
            {
                return(FREObject.Zero);
            }
            var flags = (WindowPositionFlags)0;

            if (!updateWidth && !updateHeight)
            {
                flags |= WindowPositionFlags.SWP_NOSIZE;
            }

            if (!updateX && !updateY)
            {
                flags |= WindowPositionFlags.SWP_NOMOVE;
            }

            WinApi.SetWindowPos(_webViewWindow, new Hwnd(0), _view.X, _view.Y, _view.ViewWidth, _view.ViewHeight,
                                flags);
            WinApi.UpdateWindow(_webViewWindow);
            return(FREObject.Zero);
        }