Beispiel #1
0
        static void OnJavaScriptNativeMap(IWebBrowser browser, JsQueryEventArgs args)
        {
            MapResult result = null;
            var       info   = This.GetBrowserInfo(browser);

            try
            {
                var json    = args.Request;
                var mapInfo = JsonConvert.DeserializeObject <MapActionInfo>(json);
                var context = new JsNativeInvokeContext(info, mapInfo, (typeName) => NativeTypeDic.ContainsKey(typeName) ? NativeTypeDic[typeName] : null);
                result = JsNativeInvokeHandleFactory.This.CreateHandle(context).Handle();
                if (result == null)
                {
                    browser.ResponseJsQuery(args.WebView, args.QueryId, args.CustomMsg, "OK");
                    return;
                }
                var resultJson = JsonConvert.SerializeObject(result);
                browser.ResponseJsQuery(args.WebView, args.QueryId, args.CustomMsg, resultJson);
            }
            catch (Exception ex)
            {
                if (result != null && result.Data.DataType == MapDataType.NativeObjectId)
                {
                    info.DestroyNativeObject(((NativeObjectInfo)result.Data.Value).Id, false);
                }
                result = new MapResult {
                    Status = false, Data = new MapDataInfo {
                        DataType = MapDataType.Value, Value = ex.Message
                    }
                };
                var resultJson = JsonConvert.SerializeObject(result).Replace("\\r", "").Replace("\\n", "");
                browser.ResponseJsQuery(args.WebView, args.QueryId, args.CustomMsg, resultJson);
            }
        }
Beispiel #2
0
        static void OnDeleteNativeObject(IWebBrowser browser, JsQueryEventArgs args)
        {
            var info     = This.GetBrowserInfo(browser);
            var hashCode = long.Parse(args.Request);

            info.DestroyNativeObject(hashCode, false);
            browser.ResponseJsQuery(args.WebView, args.QueryId, args.CustomMsg, "OK");
        }
Beispiel #3
0
 static long jsOnQueryFunction(IntPtr es, IntPtr param)
 {
     if (jsQuery != null)
     {
         JsQueryEventArgs args = new JsQueryEventArgs();
         args.CustomMsg = jsToInt(es, jsArg(es, 0));
         args.Request   = jsToString(es, jsArg(es, 1));
         args.QueryId   = idSeed_;
         args.WebView   = jsGetWebView(es);
         var func     = jsArg(es, 2);
         var funcName = $"MbQueryCallback_{idSeed_}";
         args.Func = funcName;
         jsSetGlobal(es, funcName, func);
         idSeed_++;
         jsQuery(jsGetWebView(es), args);
     }
     return(jsUndefined());
 }
Beispiel #4
0
        void OnRegisterNativeMap(IWebBrowser browser, JsQueryEventArgs args)
        {
            var regInfo        = JsonConvert.DeserializeObject <RegisterNativeMapInfo>(args.Request);
            var nativeTypeName = regInfo.NativeTypeName;
            var b         = nativeTypeName.IndexOf("<");
            var isGeneric = b != -1;

            if (isGeneric)
            {
                var tmps = nativeTypeName.Split(',');
                nativeTypeName = $"{nativeTypeName.Substring(0,b)}`{tmps.Length}";
            }
            var jsTypeName = regInfo.JsTypeName;

            if (!NativeTypeDic.ContainsKey(nativeTypeName))
            {
                NativeTypeDic.Add(nativeTypeName, jsTypeName);
            }
            var info = GetBrowserInfo(browser);

            browser.ResponseJsQuery(args.WebView, args.QueryId, args.CustomMsg, "OK");
        }
Beispiel #5
0
        void OnShowContextMenu(IWebBrowser webbrowser, JsQueryEventArgs args)
        {
            var menuInfo = JsonConvert.DeserializeObject <ShowContextMenuForTneFormInfo>(args.Request);
            var wbinfo   = GetBrowserInfo(webbrowser);
            var tneForm  = wbinfo.GetNativeObject(menuInfo.TneFormId, false) as TneForm;
            var menuForm = new TneForm(menuInfo.Url);

            menuForm.SizeAble      = false;
            menuForm.ShowInTaskBar = false;
            menuForm.StartPosition = StartPosition.Manual;
            menuForm.TopMost       = true;
            menuForm.KillFocus    += (sender, eventArgs) =>
            {
                menuForm.Close();
            };
            menuForm.Parent = tneForm;
            var x = tneForm.X + menuInfo.X;
            var y = tneForm.Y + menuInfo.Y;

            if (menuInfo.X == -1 && menuInfo.Y == -1)
            {
                var point = new NativeMethods.POINT();
                NativeMethods.GetCursorPos(ref point);
                x = point.x;
                y = point.y;
            }
            RECT rect    = new RECT();
            var  rectPtr = Marshal.AllocHGlobal(Marshal.SizeOf <RECT>());

            Marshal.StructureToPtr(rect, rectPtr, true);
            NativeMethods.SystemParametersInfoW(NativeMethods.SPI_GETWORKAREA, 0, rectPtr, 0);
            rect = Marshal.PtrToStructure <RECT>(rectPtr);
            Marshal.FreeHGlobal(rectPtr);
            int cx = rect.right - rect.left;
            int cy = rect.bottom - rect.top;

            if (x + menuInfo.Width > cx)
            {
                x = x - menuInfo.Width;
                if (x < 0)
                {
                    x = 0;
                }
            }
            if (y + menuInfo.Height > cy)
            {
                y = y - menuInfo.Height;
                if (y < 0)
                {
                    y = 0;
                }
            }

            menuForm.X       = x;
            menuForm.Y       = y;
            menuForm.Width   = menuInfo.Width;
            menuForm.Height  = menuInfo.Height;
            menuForm.TopMost = true;
            menuForm.Show();
            webbrowser.ResponseJsQuery(webbrowser.WebView, args.QueryId, args.CustomMsg, "OK");
        }