コード例 #1
0
ファイル: ContextMenu.cs プロジェクト: zhiy0122/WebGalEngine
        public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame,
                                   IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
#if DEBUG
            return(false);
#else
            return(true);
#endif
        }
コード例 #2
0
 public bool RunContextMenu(IWebBrowser browserControl,
                            IBrowser browser,
                            IFrame frame,
                            IContextMenuParams parameters,
                            IMenuModel model,
                            IRunContextMenuCallback callback)
 {
     return(true);
 }
コード例 #3
0
 /// <inheritdoc />
 public bool RunContextMenu(IWebBrowser chromiumWebBrowser,
                            IBrowser browser,
                            IFrame frame,
                            IContextMenuParams parameters,
                            IMenuModel model,
                            IRunContextMenuCallback callback)
 {
     return(false);
 }
コード例 #4
0
ファイル: MenuHandler.cs プロジェクト: huoxudong125/CefSharp
        bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            return false;

            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            ////IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread
            //var menuItems = GetMenuItems(model);

            //chromiumWebBrowser.Dispatcher.Invoke(() =>
            //{
            //    var menu = new ContextMenu
            //    {
            //        IsOpen = true
            //    };

            //    RoutedEventHandler handler = null;

            //    handler = (s, e) =>
            //    {
            //        menu.Closed -= handler;

            //        //If the callback has been disposed then it's already been executed
            //        //so don't call Cancel
            //        if(!callback.IsDisposed)
            //        {
            //            callback.Cancel();
            //        }
            //    };

            //    menu.Closed += handler;

            //    foreach (var item in menuItems)
            //    {
            //        menu.Items.Add(new MenuItem
            //        {
            //            Header = item.Item1,
            //            Command = new RelayCommand(() => { callback.Continue(item.Item2, CefEventFlags.None); })
            //        });
            //    }
            //    chromiumWebBrowser.ContextMenu = menu;
            //});

            //return true;
        }
コード例 #5
0
ファイル: CefSharpWrapper.cs プロジェクト: WildGenie/actools
        public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model,
                                   IRunContextMenuCallback callback)
        {
            callback.Dispose();

            ActionExtension.InvokeInMainThread(() => {
                var menu = new ContextMenu {
                    Items =
                    {
                        new MenuItem {
                            Header  = "Back",
                            Command = new DelegateCommand(browser.GoBack, () => browser.CanGoBack)
                        },
                        new MenuItem {
                            Header  = "Forward",
                            Command = new DelegateCommand(browser.GoForward, () => browser.CanGoForward)
                        },
                        new MenuItem {
                            Header  = "Refresh",
                            Command = new DelegateCommand(() => browser.Reload(true))
                        },
                        new Separator(),
                        new MenuItem {
                            Header  = "Select All",
                            Command = new DelegateCommand(() => browser.FocusedFrame.SelectAll())
                        },
                        new MenuItem {
                            Header           = "Open Page In Default Browser",
                            Command          = new DelegateCommand <string>(WindowsHelper.ViewInBrowser),
                            CommandParameter = frame.Url
                        },
                    }
                };

                menu.IsOpen = true;
            });

            return(true);
        }
コード例 #6
0
ファイル: CefSharpWrapper.cs プロジェクト: gro-ove/actools
        public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model,
                IRunContextMenuCallback callback) {
            callback.Dispose();

            Application.Current.Dispatcher.Invoke(() => {
                var menu = new ContextMenu {
                    Items = {
                        new MenuItem {
                            Header = "Back",
                            Command = new DelegateCommand(browser.GoBack, () => browser.CanGoBack)
                        },
                        new MenuItem {
                            Header = "Forward",
                            Command = new DelegateCommand(browser.GoForward, () => browser.CanGoForward)
                        },
                        new MenuItem {
                            Header = "Refresh",
                            Command = new DelegateCommand(() => browser.Reload(true))
                        },
                        new Separator(),
                        new MenuItem {
                            Header = "Select All",
                            Command = new DelegateCommand(() => browser.FocusedFrame.SelectAll())
                        },
                        new MenuItem {
                            Header = "Open Page In Default Browser",
                            Command = new DelegateCommand<string>(WindowsHelper.ViewInBrowser),
                            CommandParameter = frame.Url
                        },
                    }
                };

                menu.IsOpen = true;
            });
            
            return true;
        }
コード例 #7
0
        public override bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            var menuItems = GetMenuItems(model).ToList();

            var linkUrl       = parameters.LinkUrl;
            var selectionText = parameters.SelectionText;

            wfChromiumWebBrowser.Dispatcher.Invoke(() =>
            {
                var menu = new ContextMenu {
                    IsOpen = true
                };

                RoutedEventHandler handler = null;
                handler = (s, e) =>
                {
                    menu.Closed -= handler;
                    if (!callback.IsDisposed)
                    {
                        callback.Cancel();
                    }
                };
                menu.Closed += handler;

                foreach (var item in menuItems)
                {
                    string header = string.Empty;

                    if (item.commandId == CefMenuCommand.NotFound)
                    {
                        menu.Items.Add(new Separator());
                        continue;
                    }

                    switch (item.commandId)
                    {
                    case CefMenuCommand.Back:
                        {
                            header = LanguageManager.GetString("menu_back");
                            break;
                        }

                    case CefMenuCommand.Forward:
                        {
                            header = LanguageManager.GetString("menu_forward");
                            break;
                        }

                    case CefMenuCommand.Cut:
                        {
                            header = LanguageManager.GetString("menu_cut");
                            break;
                        }

                    case CefMenuCommand.Copy:
                        {
                            header = LanguageManager.GetString("menu_copy");
                            break;
                        }

                    case CefMenuCommand.Paste:
                        {
                            header = LanguageManager.GetString("menu_paste");
                            break;
                        }

                    case CefMenuCommand.Print:
                        {
                            header = LanguageManager.GetString("menu_print");
                            break;
                        }

                    case CefMenuCommand.ViewSource:
                        {
                            header = LanguageManager.GetString("menu_viewSource");
                            break;
                        }

                    case CefMenuCommand.Undo:
                        {
                            header = LanguageManager.GetString("menu_undo");
                            break;
                        }

                    case CefMenuCommand.StopLoad:
                        {
                            header = LanguageManager.GetString("menu_stop");
                            break;
                        }

                    case CefMenuCommand.SelectAll:
                        {
                            header = LanguageManager.GetString("menu_selectAll");
                            break;
                        }

                    case CefMenuCommand.Redo:
                        {
                            header = LanguageManager.GetString("menu_redo");
                            break;
                        }

                    case CefMenuCommand.Find:
                        {
                            header = LanguageManager.GetString("menu_find");
                            break;
                        }

                    case CefMenuCommand.AddToDictionary:
                        {
                            header = LanguageManager.GetString("menu_addToDictionary");
                            break;
                        }

                    case CefMenuCommand.Reload:
                        {
                            header = LanguageManager.GetString("menu_reload");
                            break;
                        }

                    case CefMenuCommand.ReloadNoCache:
                        {
                            header = LanguageManager.GetString("menu_reloadNoCache");
                            break;
                        }

                    case OpenInNewWindow:
                        {
                            header = string.Format(LanguageManager.GetString(item.header), linkUrl);
                            break;
                        }

                    case Search:
                        {
                            var tmp = selectionText.Length > 32 ? selectionText.Substring(0, 32) + "..." : selectionText;
                            header  = string.Format(LanguageManager.GetString(item.header), tmp.Replace('\n', ' '));
                            break;
                        }

                    default:
                        {
                            header = item.header;
                            break;
                        }
                    }

                    menu.Items.Add(new MenuItem
                    {
                        Header  = header,
                        Command = new DelegateCommand
                        {
                            CanExecute = item.isEnable,
                            Execute    = obj => callback.Continue(item.commandId, CefEventFlags.None)
                        }
                    });
                }

                wfChromiumWebBrowser.ContextMenu = menu;
            });

            return(true);
        }
コード例 #8
0
 public bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     // Suppress the context menu.
     return(true);
 }
コード例 #9
0
 public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters,
     IMenuModel model, IRunContextMenuCallback callback)
 {
     return true;
 }
コード例 #10
0
ファイル: MenuHandler.cs プロジェクト: ZCLLemon/ColorsWin
        bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            // return true;

            //绘制了一遍菜单栏  所以初始化的时候不必绘制菜单栏,再此处绘制即可
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            chromiumWebBrowser.Dispatcher.Invoke(() =>
            {
                var menu = new ContextMenu
                {
                    IsOpen = true
                };

                RoutedEventHandler handler = null;

                handler = (s, e) =>
                {
                    menu.Closed -= handler;

                    //If the callback has been disposed then it's already been executed
                    //so don't call Cancel
                    if (!callback.IsDisposed)
                    {
                        callback.Cancel();
                    }
                };

                menu.Closed += handler;

                menu.Items.Add(new MenuItem
                {
                    Header = "最小化",
                    // Command = new CustomCommand(MinWindow)
                });
                menu.Items.Add(new MenuItem
                {
                    Header = "关闭",
                    //  Command = new CustomCommand(CloseWindow)
                });
                chromiumWebBrowser.ContextMenu = menu;
            });

            return(true);
        }
コード例 #11
0
            public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
            {
                return(false);

                //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

                ////IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread
                //var menuItems = GetMenuItems(model);

                //chromiumWebBrowser.Dispatcher.Invoke(() =>
                //{
                //    var menu = new ContextMenu
                //    {
                //        IsOpen = true
                //    };

                //    RoutedEventHandler handler = null;

                //    handler = (s, e) =>
                //    {
                //        menu.Closed -= handler;

                //        //If the callback has been disposed then it's already been executed
                //        //so don't call Cancel
                //        if(!callback.IsDisposed)
                //        {
                //            callback.Cancel();
                //        }
                //    };

                //    menu.Closed += handler;

                //    foreach (var item in menuItems)
                //    {
                //        menu.Items.Add(new MenuItem
                //        {
                //            Header = item.Item1,
                //            Command = new RelayCommand(() => { callback.Continue(item.Item2, CefEventFlags.None); })
                //        });
                //    }
                //    chromiumWebBrowser.ContextMenu = menu;
                //});

                //return true;
            }
コード例 #12
0
 bool IContextMenuHandler.RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     return(RunContextMenu(chromiumWebBrowser, browser, frame, parameters, model, callback));
 }
コード例 #13
0
 /// <summary>
 /// The run context menu.
 /// </summary>
 /// <param name="browserControl">
 /// The browser control.
 /// </param>
 /// <param name="browser">
 /// The browser.
 /// </param>
 /// <param name="frame">
 /// The frame.
 /// </param>
 /// <param name="parameters">
 /// The parameters.
 /// </param>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <param name="callback">
 /// The callback.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     return(false);
 }
コード例 #14
0
ファイル: Login.cs プロジェクト: vikingLee/huotao-client-dot
 public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     model.SetEnabled(CefMenuCommand.Cut, false);
     return(false);
 }
コード例 #15
0
ファイル: MenuHandler.cs プロジェクト: willy2358/AniBox
 public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     //throw new NotImplementedException();
     return(true);
 }
コード例 #16
0
ファイル: MenuHandler.cs プロジェクト: GerHobbelt/CefSharp
        bool IContextMenuHandler.RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            //NOTE: Return false to use the built in Context menu - in WPF this requires you integrate into your existing message loop, read the General Usage Guide for more details
            //https://github.com/cefsharp/CefSharp/wiki/General-Usage#multithreadedmessageloop
            //return false;

            var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser;

            //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread
            var menuItems = GetMenuItems(model).ToList();

            webBrowser.Dispatcher.Invoke(() =>
            {
                var menu = new ContextMenu
                {
                    IsOpen = true
                };

                RoutedEventHandler handler = null;

                handler = (s, e) =>
                {
                    menu.Closed -= handler;

                    //If the callback has been disposed then it's already been executed
                    //so don't call Cancel
                    if (!callback.IsDisposed)
                    {
                        callback.Cancel();
                    }
                };

                menu.Closed += handler;

                foreach (var item in menuItems)
                {
                    if (item.Item2 == CefMenuCommand.NotFound && string.IsNullOrWhiteSpace(item.Item1))
                    {
                        menu.Items.Add(new Separator());
                        continue;
                    }

                    menu.Items.Add(new MenuItem
                    {
                        Header    = item.Item1.Replace("&", "_"),
                        IsEnabled = item.Item3,
                        Command   = new RelayCommand(() =>
                        {
                            //BUG: CEF currently not executing callbacks correctly so we manually map the commands below
                            //see https://github.com/cefsharp/CefSharp/issues/1767
                            //The following line worked in previous versions, it doesn't now, so custom EXAMPLE below
                            //callback.Continue(item.Item2, CefEventFlags.None);

                            //NOTE: Note all menu item options below have been tested, you can work out the rest
                            switch (item.Item2)
                            {
                            case CefMenuCommand.Back:
                                {
                                    browser.GoBack();
                                    break;
                                }

                            case CefMenuCommand.Forward:
                                {
                                    browser.GoForward();
                                    break;
                                }

                            case CefMenuCommand.Cut:
                                {
                                    browser.FocusedFrame.Cut();
                                    break;
                                }

                            case CefMenuCommand.Copy:
                                {
                                    browser.FocusedFrame.Copy();
                                    break;
                                }

                            case CefMenuCommand.Paste:
                                {
                                    browser.FocusedFrame.Paste();
                                    break;
                                }

                            case CefMenuCommand.Print:
                                {
                                    browser.GetHost().Print();
                                    break;
                                }

                            case CefMenuCommand.ViewSource:
                                {
                                    browser.FocusedFrame.ViewSource();
                                    break;
                                }

                            case CefMenuCommand.Undo:
                                {
                                    browser.FocusedFrame.Undo();
                                    break;
                                }

                            case CefMenuCommand.StopLoad:
                                {
                                    browser.StopLoad();
                                    break;
                                }

                            case CefMenuCommand.SelectAll:
                                {
                                    browser.FocusedFrame.SelectAll();
                                    break;
                                }

                            case CefMenuCommand.Redo:
                                {
                                    browser.FocusedFrame.Redo();
                                    break;
                                }

                            case CefMenuCommand.Find:
                                {
                                    browser.GetHost().Find(0, parameters.SelectionText, true, false, false);
                                    break;
                                }

                            case CefMenuCommand.AddToDictionary:
                                {
                                    browser.GetHost().AddWordToDictionary(parameters.MisspelledWord);
                                    break;
                                }

                            case CefMenuCommand.Reload:
                                {
                                    browser.Reload();
                                    break;
                                }

                            case CefMenuCommand.ReloadNoCache:
                                {
                                    browser.Reload(ignoreCache: true);
                                    break;
                                }

                            case (CefMenuCommand)26501:
                                {
                                    browser.GetHost().ShowDevTools();
                                    break;
                                }

                            case (CefMenuCommand)26502:
                                {
                                    browser.GetHost().CloseDevTools();
                                    break;
                                }
                            }
                        })
                    });
                }
                webBrowser.ContextMenu = menu;
            });

            return(true);
        }
コード例 #17
0
        bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread
            var menuItems = GetMenuItems(model).ToList();

            chromiumWebBrowser.Dispatcher.Invoke(() =>
            {
                var menu = new ContextMenu
                {
                    IsOpen = true
                };

                RoutedEventHandler handler = null;

                handler = (s, e) =>
                {
                    menu.Closed -= handler;

                    //If the callback has been disposed then it's already been executed
                    //so don't call Cancel
                    if (!callback.IsDisposed)
                    {
                        callback.Cancel();
                    }
                };

                menu.Closed += handler;

                foreach (var item in menuItems)
                {
                    if (item.Item2 == CefMenuCommand.NotFound && string.IsNullOrWhiteSpace(item.Item1))
                    {
                        menu.Items.Add(new Separator());
                        continue;
                    }

                    menu.Items.Add(new MenuItem
                    {
                        Header    = item.Item1.Replace("&", "_"),
                        IsEnabled = item.Item3,
                        Command   = new RelayCommand(x => _menuSetup(item.Item2))
                    });
                }
                chromiumWebBrowser.ContextMenu = menu;
            });

            return(true);
        }
コード例 #18
0
        bool IContextMenuHandler.RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            //绘制了一遍菜单栏  所以初始化的时候不必绘制菜单栏,再此处绘制即可
            var WebBrowser = (ChromiumWebBrowser)chromiumWebBrowser;

            WebBrowser.Invoke(new Action(() =>
            {
            }));
            var menu = new ContextMenu();

            //var menu = new ContextMenu
            //{
            //    IsOpen = true
            //};

            //RoutedEventHandler handler = null;

            //handler = (s, e) =>
            //{
            //    menu.Closed -= handler;

            //    //If the callback has been disposed then it's already been executed
            //    //so don't call Cancel
            //    if (!callback.IsDisposed)
            //    {
            //        callback.Cancel();
            //    }
            //};



            //menu.Closed += handler;

            var mi = new MenuItem();

            mi.Text   = "最小化";
            mi.Click += Mi_Click;

            menu.MenuItems.Add(mi);
            //menu.Items.Add(new MenuItem
            //{
            //    Header = "关闭",
            //    Command = new CustomCommand(CloseWindow)
            //});
            WebBrowser.ContextMenu = menu;



            return(true);
        }
コード例 #19
0
 public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     Console.WriteLine(@"RunContextMenu");
     return(false);
 }
コード例 #20
0
        bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;



            chromiumWebBrowser.Dispatcher.Invoke(new Action(() =>
            {
                var menu = new ContextMenu
                {
                    IsOpen = true
                };

                RoutedEventHandler handler = null;

                handler = (s, e) =>
                {
                    menu.Closed -= handler;

                    if (!callback.IsDisposed)
                    {
                        callback.Cancel();
                    }
                };

                menu.Closed += handler;

                var showDevOp = new MenuItem
                {
                    Header = "Show DevTools",
                };

                showDevOp.Click += delegate(object obj, RoutedEventArgs ev)
                {
                    chromiumWebBrowser.ShowDevTools();
                };

                menu.Items.Add(showDevOp);


                chromiumWebBrowser.ContextMenu = menu;
            }));

            return(true);
        }
コード例 #21
0
 public bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     if (ctxMenuCallback == null)
     {
         // Suppress the context menu.
         return(true);
     }
     else
     {
         return(ctxMenuCallback(parameters.XCoord, parameters.YCoord));
     }
 }
コード例 #22
0
        bool IContextMenuHandler.RunContextMenu(
            IWebBrowser chromiumWebBrowser,
            IBrowser browser,
            IFrame frame,
            IContextMenuParams parameters,
            IMenuModel model,
            IRunContextMenuCallback callback)
        {
            //NOTE: Return false to use the built in Context menu -
            // in WPF this requires you integrate into your existing message loop,
            // read the General Usage Guide for more details
            //https://github.com/cefsharp/CefSharp/wiki/General-Usage#multithreadedmessageloop
            //return false;

            var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser;

            //IMenuModel is only valid in the context of this method,
            // so need to read the values before invoking on the UI thread
            var menuItems = GetMenuItems(model).ToList();

            webBrowser.Dispatcher.Invoke(() =>
            {
                var menu = new ContextMenu
                {
                    IsOpen = true
                };

                RoutedEventHandler handler = null;

                handler = (s, e) =>
                {
                    menu.Closed -= handler;

                    //If the callback has been disposed then it's already been executed
                    //so don't call Cancel
                    if (!callback.IsDisposed)
                    {
                        callback.Cancel();
                    }
                };

                menu.Closed += handler;

                foreach (var item in menuItems)
                {
                    if (item.Item2 == CefMenuCommand.NotFound &&
                        string.IsNullOrWhiteSpace(item.Item1))
                    {
                        menu.Items.Add(new Separator());
                        continue;
                    }

                    menu.Items.Add(new MenuItem
                    {
                        Header    = item.Item1.Replace("&", "_"),
                        IsEnabled = item.Item3,
                        Command   = new RelayCommand(() =>
                                                     ProcessMenu(item, browser, parameters),
                                                     keepTargetAlive: true)
                    });
                }
                webBrowser.ContextMenu = menu;
            });

            return(true);
        }
コード例 #23
0
 public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     return(false);//返回true则不显示,返回false则显示
 }
コード例 #24
0
        public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            var webBrowser = (ChromiumWebBrowser)browserControl;

            model.SetEnabled(CefMenuCommand.Back, webBrowser.CanGoBack);
            model.SetEnabled(CefMenuCommand.Forward, webBrowser.CanGoForward);
            model.SetEnabled(CefMenuCommand.SelectAll, webBrowser.CanSelect);

            //var menuItems = GetMenuItems(model).ToList();

            //menuItems.ForEach(m =>
            //{
            //    if(m.Item3 == CefMenuCommand.Back)
            //    {
            //        if (!webBrowser.CanGoBack)
            //        {

            //        }
            //    }
            //});

            #region MyRegion

            //webBrowser.Invoke(new Action(() =>
            //{
            //    foreach (var item in menuItems)
            //    {
            //        switch (item.Item2)
            //        {
            //            case CefMenuCommand.Back:
            //                {
            //                    //browser.GoBack();
            //                    break;
            //                }
            //            case CefMenuCommand.Forward:
            //                {
            //                    //browser.GoForward();
            //                    break;
            //                }
            //            case CefMenuCommand.Cut:
            //                {
            //                    //browser.FocusedFrame.Cut();
            //                    break;
            //                }
            //            case CefMenuCommand.Copy:
            //                {
            //                    //browser.FocusedFrame.Copy();
            //                    break;
            //                }
            //            case CefMenuCommand.Paste:
            //                {
            //                    //browser.FocusedFrame.Paste();
            //                    break;
            //                }
            //            case CefMenuCommand.Print:
            //                {
            //                    //browser.GetHost().Print();
            //                    break;
            //                }
            //            case CefMenuCommand.ViewSource:
            //                {
            //                    //browser.FocusedFrame.ViewSource();
            //                    break;
            //                }
            //            case CefMenuCommand.Undo:
            //                {
            //                    //browser.FocusedFrame.Undo();
            //                    break;
            //                }
            //            case CefMenuCommand.StopLoad:
            //                {
            //                    //browser.StopLoad();
            //                    break;
            //                }
            //            case CefMenuCommand.SelectAll:
            //                {
            //                    //browser.FocusedFrame.SelectAll();
            //                    break;
            //                }
            //            case CefMenuCommand.Redo:
            //                {
            //                    //browser.FocusedFrame.Redo();
            //                    break;
            //                }
            //            case CefMenuCommand.Find:
            //                {
            //                    //browser.GetHost().Find(0, parameters.SelectionText, true, false, false);
            //                    break;
            //                }
            //            case CefMenuCommand.AddToDictionary:
            //                {
            //                    //browser.GetHost().AddWordToDictionary(parameters.MisspelledWord);
            //                    break;
            //                }
            //            case CefMenuCommand.Reload:
            //                {
            //                    //browser.Reload();
            //                    break;
            //                }
            //            case CefMenuCommand.ReloadNoCache:
            //                {
            //                    //browser.Reload(ignoreCache: true);
            //                    break;
            //                }
            //            case (CefMenuCommand)26501:
            //                {
            //                    //browser.GetHost().ShowDevTools();
            //                    break;
            //                }
            //            case (CefMenuCommand)26502:
            //                {
            //                    //browser.GetHost().CloseDevTools();
            //                    break;
            //                }
            //        }
            //    }
            //}));

            #endregion

            return(false); // 弹出
        }
コード例 #25
0
ファイル: MenuHandler.cs プロジェクト: tankyx/actools
        bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model,
                                                IRunContextMenuCallback callback)
        {
            if (model.Count == 0)
            {
                // No menu if 0 items (flash)
                return(true);
            }

            var chromium = (ChromiumWebBrowser)browserControl;

            //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread
            var menuItems = GetMenuItems(model);

            ActionExtension.InvokeInMainThread(() => {
                var contextMenu = new ContextMenu();

                if (menuItems.ArrayContains(CefMenuCommand.Cut))
                {
                    contextMenu.Items.Add(new MenuItem {
                        Header = "Cut", Command = chromium.CutCommand
                    });
                }

                if (menuItems.ArrayContains(CefMenuCommand.Copy))
                {
                    contextMenu.Items.Add(new MenuItem {
                        Header = "Copy", Command = chromium.CopyCommand
                    });
                }

                if (menuItems.ArrayContains(CefMenuCommand.Paste))
                {
                    contextMenu.Items.Add(new MenuItem {
                        Header = "Paste", Command = chromium.PasteCommand
                    });
                }

                if (contextMenu.Items.Count > 1)
                {
                    contextMenu.Items.Add(new Separator());
                }

                if (menuItems.ArrayContains(CefMenuCommand.SelectAll))
                {
                    contextMenu.Items.Add(new MenuItem {
                        Header = "Select all", Command = chromium.SelectAllCommand
                    });
                }

                if (contextMenu.Items.Count > 0)
                {
                    contextMenu.Items.Add(new Separator());
                }

                contextMenu.Items.Add(new MenuItem {
                    Header = "Back", Command = new DelegateCommand(browser.GoBack, () => !browser.IsDisposed && browser.CanGoBack)
                });
                contextMenu.Items.Add(new MenuItem {
                    Header = "Forward", Command = new DelegateCommand(browser.GoForward, () => !browser.IsDisposed && browser.CanGoForward)
                });
                contextMenu.Items.Add(new MenuItem {
                    Header = "Refresh", Command = new DelegateCommand(() => browser.Reload(true))
                });
                contextMenu.Items.Add(new Separator());
                contextMenu.Items.Add(new MenuItem {
                    Header           = "Open page in default browser",
                    Command          = new DelegateCommand <string>(WindowsHelper.ViewInBrowser),
                    CommandParameter = frame.Url
                });
                contextMenu.Items.Add(new MenuItem {
                    Header  = "Show developer tools",
                    Command = new DelegateCommand(() => browser.ShowDevTools())
                });

                chromium.ContextMenu = contextMenu;
                contextMenu.IsOpen   = true;
            });

            callback.Cancel();
            return(true);
        }
コード例 #26
0
 public bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters,
                            IMenuModel model, IRunContextMenuCallback callback)
 {
     return(false);
     //throw new System.NotImplementedException();
 }
コード例 #27
0
ファイル: MenuHandler.cs プロジェクト: zLulus/BarrageDemo
        bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            //return false;

            //绘制了一遍菜单栏  所以初始化的时候不必绘制菜单栏,再此处绘制即可
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread
            //var menuItems = GetMenuItems(model);

            chromiumWebBrowser.Dispatcher.Invoke(() =>
            {
                var menu = new ContextMenu
                {
                    IsOpen = true
                };

                RoutedEventHandler handler = null;

                handler = (s, e) =>
                {
                    menu.Closed -= handler;

                    //If the callback has been disposed then it's already been executed
                    //so don't call Cancel
                    if (!callback.IsDisposed)
                    {
                        callback.Cancel();
                    }
                };

                menu.Closed += handler;

                //foreach (var item in menuItems)
                //{
                //    menu.Items.Add(new MenuItem
                //    {
                //        Header = item.Item1,
                //        Command = MinWindow
                //    });
                //}
                menu.Items.Add(new MenuItem
                {
                    Header  = "最小化",
                    Command = new CustomCommand(MinWindow)
                });
                menu.Items.Add(new MenuItem
                {
                    Header  = "关闭",
                    Command = new CustomCommand(CloseWindow)
                });
                chromiumWebBrowser.ContextMenu = menu;
            });

            return(true);

            //以下方法是,获取初始化的菜单栏,对其进行加载,稍微有点问题,事件不响应
            //参考:https://github.com/cefsharp/CefSharp/issues/1795
            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            ////IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread
            //var menuItems = GetMenuItems(model);

            //chromiumWebBrowser.Dispatcher.Invoke(() =>
            //{
            //    var menu = new ContextMenu
            //    {
            //        IsOpen = true
            //    };

            //    RoutedEventHandler handler = null;

            //    handler = (s, e) =>
            //    {
            //        menu.Closed -= handler;

            //        //If the callback has been disposed then it's already been executed
            //        //so don't call Cancel
            //        if (!callback.IsDisposed)
            //        {
            //            callback.Cancel();
            //        }
            //    };

            //    menu.Closed += handler;

            //    foreach (var item in menuItems)
            //    {
            //        menu.Items.Add(new MenuItem
            //        {
            //            Header = item.Item1,
            //            Command = new RelayCommand(() => { callback.Continue(item.Item2, CefEventFlags.LeftMouseButton); })
            //        });
            //    }
            //    chromiumWebBrowser.ContextMenu = menu;

            //});

            //return true;
        }
コード例 #28
0
 public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     // show default menu
     return(false);
 }
コード例 #29
0
 bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     return false;
 }
コード例 #30
0
ファイル: MenuHandler.cs プロジェクト: hlinfocc/MyAppBrowser
 bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     //return false 才可以弹出;如果需要完完全全对右键菜单进行重构的话,这里也可以实现,实现菜单命令的处理过程;;
     return(false);
 }
コード例 #31
0
ファイル: TabView.xaml.cs プロジェクト: ysjyga/WebExpress
        bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread
            var menuItems = GetMenuItems(model);

            chromiumWebBrowser.Dispatcher.Invoke(() =>
            {
                var menu = new ContextMenu
                {
                    IsOpen = true
                };

                RoutedEventHandler handler = null;

                handler = (s, e) =>
                {
                    menu.Closed -= handler;

                    //If the callback has been disposed then it's already been executed
                    //so don't call Cancel
                    if (!callback.IsDisposed)
                    {
                        callback.Cancel();
                    }
                };

                menu.Closed += handler;

                foreach (var item in menuItems)
                {
                    menu.Items.Add(new MenuItem
                    {
                        Header  = item.Item1,
                        Command = new RelayCommand(() => { callback.Continue(item.Item2, CefEventFlags.None); })
                    });
                }
                chromiumWebBrowser.ContextMenu = menu;
            });

            return(true);
        }
コード例 #32
0
 public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters,
                            IMenuModel model, IRunContextMenuCallback callback)
 {
     return(!_settings.EnableDebugMenu);
 }
コード例 #33
0
        /// <inheritdoc/>
        protected override bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser;

            //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread
            var menuItems             = GetMenuItems(model);
            var dictionarySuggestions = parameters.DictionarySuggestions;
            var xCoord         = parameters.XCoord;
            var yCoord         = parameters.YCoord;
            var misspelledWord = parameters.MisspelledWord;
            var selectionText  = parameters.SelectionText;

            webBrowser.UiThreadRunAsync(() =>
            {
                var menu = new ContextMenu
                {
                    IsOpen    = true,
                    Placement = PlacementMode.Mouse
                };

                RoutedEventHandler handler = null;

                handler = (s, e) =>
                {
                    menu.Closed -= handler;

                    //If the callback has been disposed then it's already been executed
                    //so don't call Cancel
                    if (!callback.IsDisposed)
                    {
                        callback.Cancel();
                    }
                };

                menu.Closed += handler;

                foreach (var item in menuItems)
                {
                    if (item.CommandId == CefMenuCommand.NotFound)
                    {
                        continue;
                    }

                    if (item.IsSeperator)
                    {
                        menu.Items.Add(new Separator());

                        continue;
                    }

                    var menuItem = new MenuItem
                    {
                        Header      = item.Label.Replace("&", "_"),
                        IsEnabled   = item.IsEnabled,
                        IsChecked   = item.IsChecked.GetValueOrDefault(),
                        IsCheckable = item.IsChecked.HasValue,
                        Command     = new DelegateCommand(() =>
                        {
                            //BUG: CEF currently not executing callbacks correctly so we manually map the commands below
                            //see https://github.com/cefsharp/CefSharp/issues/1767
                            //The following line worked in previous versions, it doesn't now, so custom handling below
                            //callback.Continue(item.Item2, CefEventFlags.None);
                            ExecuteCommand(browser, new ContextMenuExecuteModel(item.CommandId, dictionarySuggestions, xCoord, yCoord, selectionText, misspelledWord));
                        }),
                    };

                    //TODO: Make this recursive and remove duplicate code
                    if (item.SubMenus != null && item.SubMenus.Count > 0)
                    {
                        foreach (var subItem in item.SubMenus)
                        {
                            if (subItem.CommandId == CefMenuCommand.NotFound)
                            {
                                continue;
                            }

                            if (subItem.IsSeperator)
                            {
                                menu.Items.Add(new Separator());

                                continue;
                            }

                            var subMenuItem = new MenuItem
                            {
                                Header      = subItem.Label.Replace("&", "_"),
                                IsEnabled   = subItem.IsEnabled,
                                IsChecked   = subItem.IsChecked.GetValueOrDefault(),
                                IsCheckable = subItem.IsChecked.HasValue,
                                Command     = new DelegateCommand(() =>
                                {
                                    //BUG: CEF currently not executing callbacks correctly so we manually map the commands below
                                    //see https://github.com/cefsharp/CefSharp/issues/1767
                                    //The following line worked in previous versions, it doesn't now, so custom handling below
                                    //callback.Continue(item.Item2, CefEventFlags.None);
                                    ExecuteCommand(browser, new ContextMenuExecuteModel(subItem.CommandId, dictionarySuggestions, xCoord, yCoord, selectionText, misspelledWord));
                                }),
                            };

                            menuItem.Items.Add(subMenuItem);
                        }
                    }

                    menu.Items.Add(menuItem);
                }
                webBrowser.ContextMenu = menu;
            });

            return(true);
        }
コード例 #34
0
 public bool RunContextMenu(IWebBrowser browserControl, CefSharp.IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
 {
     return false;
 }