/// <summary>Raises the <see cref="ShowContextMenu"/> event.</summary>
        /// <param name="e">The data for the event.</param>
        protected virtual void OnShowContextMenu(GeckoContextMenuEventArgs e)
        {
            var evnt = (EventHandler <GeckoContextMenuEventArgs>)Events[ShowContextMenuEvent];

            if (evnt != null)
            {
                evnt(this, e);
            }
        }
コード例 #2
0
ファイル: Browser.cs プロジェクト: BloomBooks/BloomDesktop
 private MenuItem AddOpenPageInFFItem(GeckoContextMenuEventArgs e)
 {
     return e.ContextMenu.MenuItems.Add(
         LocalizationManager.GetString("Browser.OpenPageInFirefox", "Open Page in Firefox (which must be in the PATH environment variable)"),
         OnOpenPageInSystemBrowser);
 }
コード例 #3
0
ファイル: Browser.cs プロジェクト: BloomBooks/BloomDesktop
 private void AddOtherMenuItemsForDebugging(GeckoContextMenuEventArgs e)
 {
     e.ContextMenu.MenuItems.Add("Open about:memory window", OnOpenAboutMemory);
     e.ContextMenu.MenuItems.Add("Open about:config window", OnOpenAboutConfig);
     e.ContextMenu.MenuItems.Add("Open about:cache window", OnOpenAboutCache);
 }
コード例 #4
0
ファイル: Browser.cs プロジェクト: BloomBooks/BloomDesktop
        void OnShowContextMenu(object sender, GeckoContextMenuEventArgs e)
        {
            MenuItem FFMenuItem = null;
            Debug.Assert(!InvokeRequired);
            if (ContextMenuProvider != null)
            {
                var replacesStdMenu = ContextMenuProvider(e);
            #if DEBUG
                FFMenuItem = AddOpenPageInFFItem(e);
            #endif

                if (replacesStdMenu)
                    return; // only the provider's items
            }
            var m = e.ContextMenu.MenuItems.Add("Edit Stylesheets in Stylizer", OnOpenPageInStylizer);
            m.Enabled = !string.IsNullOrEmpty(GetPathToStylizer());

            if(FFMenuItem == null)
                AddOpenPageInFFItem(e);
            #if DEBUG
            AddOtherMenuItemsForDebugging(e);
            #endif

            e.ContextMenu.MenuItems.Add(LocalizationManager.GetString("Browser.CopyTroubleshootingInfo", "Copy Troubleshooting Information"), OnGetTroubleShootingInformation);
        }
コード例 #5
0
ファイル: Browser.cs プロジェクト: jorik041/BloomDesktop
        void OnShowContextMenu(object sender, GeckoContextMenuEventArgs e)
        {
            var m = e.ContextMenu.MenuItems.Add("Edit Stylesheets in Stylizer", new EventHandler(OnOpenPageInStylizer));
            m.Enabled = !string.IsNullOrEmpty(GetPathToStylizer());

            e.ContextMenu.MenuItems.Add("Open Page in System Browser", new EventHandler(OnOpenPageInSystemBrowser));

            e.ContextMenu.MenuItems.Add("Copy Troubleshooting Information", new EventHandler(OnGetTroubleShootingInformation));
        }
コード例 #6
0
		/// <summary>Raises the <see cref="ShowContextMenu"/> event.</summary>
		/// <param name="e">The data for the event.</param>
		protected virtual void OnShowContextMenu( GeckoContextMenuEventArgs e )
		{
			var evnt = ( EventHandler<GeckoContextMenuEventArgs> ) Events[ ShowContextMenuEvent ];
			if ( evnt != null ) evnt( this, e );
		}
コード例 #7
0
		void nsIContextMenuListener2.OnShowContextMenu(uint aContextFlags, nsIContextMenuInfo info)
		{
			// if we don't have a target node, we can't do anything by default.  this happens in XUL forms (i.e. about:config)
			if (info.GetTargetNodeAttribute() == null)
				return;
			
			ContextMenu menu = new ContextMenu();
			
			// no default items are added when the context menu is disabled
			if (!this.NoDefaultContextMenu)
			{
				List<MenuItem> optionals = new List<MenuItem>();
				
				if (this.CanUndo || this.CanRedo)
				{
					optionals.Add(new MenuItem("Undo", delegate { Undo(); }));
					optionals.Add(new MenuItem("Redo", delegate { Redo(); }));
					
					optionals[0].Enabled = this.CanUndo;
					optionals[1].Enabled = this.CanRedo;
				}
				else
				{
					optionals.Add(new MenuItem("Back", delegate { GoBack(); }));
					optionals.Add(new MenuItem("Forward", delegate { GoForward(); }));
					
					optionals[0].Enabled = this.CanGoBack;
					optionals[1].Enabled = this.CanGoForward;
				}
				
				optionals.Add(new MenuItem("-"));
				
				if (this.CanCopyImageContents)
					optionals.Add(new MenuItem("Copy Image Contents", delegate { CopyImageContents(); }));
				
				if (this.CanCopyImageLocation)
					optionals.Add(new MenuItem("Copy Image Location", delegate { CopyImageLocation(); }));
				
				if (this.CanCopyLinkLocation)
					optionals.Add(new MenuItem("Copy Link Location", delegate { CopyLinkLocation(); }));
				
				if (this.CanCopySelection)
					optionals.Add(new MenuItem("Copy Selection", delegate { CopySelection(); }));
				
				MenuItem mnuSelectAll = new MenuItem("Select All");
				mnuSelectAll.Click += delegate { SelectAll(); };

				GeckoDomDocument doc = GeckoDomDocument.CreateDomDocumentWraper(info.GetTargetNodeAttribute().GetOwnerDocumentAttribute());

				string viewSourceUrl = (doc == null) ? null : Convert.ToString(doc.Uri);
				
				MenuItem mnuViewSource = new MenuItem("View Source");
				mnuViewSource.Enabled = !string.IsNullOrEmpty(viewSourceUrl);
				mnuViewSource.Click += delegate { ViewSource(viewSourceUrl); };

				MenuItem mnuOpenInSystemBrowser = new MenuItem("View In System Browser");//nice for debugging with firefox/firebug
				mnuOpenInSystemBrowser.Enabled = !string.IsNullOrEmpty(viewSourceUrl);
				mnuOpenInSystemBrowser.Click += delegate { ViewInSystemBrowser(viewSourceUrl); };


				string properties = (doc != null && doc.Uri == Document.Uri) ? "Page Properties" : "IFRAME Properties";
				
				MenuItem mnuProperties = new MenuItem(properties);
				mnuProperties.Enabled = doc != null;
				mnuProperties.Click += delegate { ShowPageProperties(doc); };
				
				menu.MenuItems.AddRange(optionals.ToArray());
				menu.MenuItems.Add(mnuSelectAll);
				menu.MenuItems.Add("-");
				menu.MenuItems.Add(mnuViewSource);
				menu.MenuItems.Add(mnuOpenInSystemBrowser);
				menu.MenuItems.Add(mnuProperties);
			}

			// get image urls
			Uri backgroundImageSrc = null, imageSrc = null;
			nsIURI src;
			try
			{
				src = info.GetBackgroundImageSrcAttribute();
				backgroundImageSrc = src.ToUri();
				Marshal.ReleaseComObject( src );
			}
			catch (COMException comException)
			{
				if ((comException.ErrorCode & 0xFFFFFFFF) != 0x80004005)
					throw comException;
			}

			try
			{
				src = info.GetImageSrcAttribute();
				if ( src != null )
				{
					imageSrc = src.ToUri();
					Marshal.ReleaseComObject( src );
				}
			}
			catch (COMException comException)
			{
				if ((comException.ErrorCode & 0xFFFFFFFF) != 0x80004005)
					throw comException;
			}
			
			// get associated link.  note that this needs to be done manually because GetAssociatedLink returns a non-zero
			// result when no associated link is available, so an exception would be thrown by nsString.Get()
			string associatedLink = null;
			try
			{
				using (nsAString str = new nsAString())
				{
					info.GetAssociatedLinkAttribute(str);
					associatedLink = str.ToString();
				}
			}
			catch (COMException comException) { }			
			
			GeckoContextMenuEventArgs e = new GeckoContextMenuEventArgs(
				PointToClient(MousePosition), menu, associatedLink, backgroundImageSrc, imageSrc,
				GeckoNode.Create(Xpcom.QueryInterface<nsIDOMNode>(info.GetTargetNodeAttribute()))
				);
			
			OnShowContextMenu(e);
			
			if (e.ContextMenu != null && e.ContextMenu.MenuItems.Count > 0)
			{
#if GTK
				// When using GTK we can't use SWF to display the context menu: SWF displays
				// the context menu and then tries to track the mouse so that it knows when to
				// close the context menu. However, GTK intercepts the mouse click before SWF gets
				// it, so the menu never closes. Instead we display a GTK menu and translate
				// the SWF menu items into Gtk.MenuItems.
				// TODO: currently this code only handles text menu items. Would be nice to also
				// translate images etc.
				var popupMenu = new Gtk.Menu();

				foreach (MenuItem swfMenuItem in e.ContextMenu.MenuItems)
				{
					var gtkMenuItem = new Gtk.MenuItem(swfMenuItem.Text);
					gtkMenuItem.Sensitive = swfMenuItem.Enabled;
					MenuItem origMenuItem = swfMenuItem;
					gtkMenuItem.Activated += (sender, ev) => origMenuItem.PerformClick();
					popupMenu.Append(gtkMenuItem);
				}
				popupMenu.ShowAll();
				popupMenu.Popup();
#else
				e.ContextMenu.Show(this, e.Location);
#endif
			}
		}
コード例 #8
0
        void nsIContextMenuListener2.OnShowContextMenu(uint aContextFlags, nsIContextMenuInfo info)
        {
            // if we don't have a target node, we can't do anything by default.  this happens in XUL forms (i.e. about:config)
            if (info.GetTargetNodeAttribute() == null)
                return;

            ContextMenu menu = new ContextMenu();

            // no default items are added when the context menu is disabled
            if (!this.NoDefaultContextMenu)
            {
                List<MenuItem> optionals = new List<MenuItem>();

                if (this.CanUndo || this.CanRedo)
                {
                    optionals.Add(new MenuItem("Undo", delegate { Undo(); }));
                    optionals.Add(new MenuItem("Redo", delegate { Redo(); }));

                    optionals[0].Enabled = this.CanUndo;
                    optionals[1].Enabled = this.CanRedo;
                }
                else
                {
                    optionals.Add(new MenuItem("Back", delegate { GoBack(); }));
                    optionals.Add(new MenuItem("Forward", delegate { GoForward(); }));

                    optionals[0].Enabled = this.CanGoBack;
                    optionals[1].Enabled = this.CanGoForward;
                }

                optionals.Add(new MenuItem("-"));

                if (this.CanCopyImageContents)
                    optionals.Add(new MenuItem("Copy Image Contents", delegate { CopyImageContents(); }));

                if (this.CanCopyImageLocation)
                    optionals.Add(new MenuItem("Copy Image Location", delegate { CopyImageLocation(); }));

                if (this.CanCopyLinkLocation)
                    optionals.Add(new MenuItem("Copy Link Location", delegate { CopyLinkLocation(); }));

                if (this.CanCopySelection)
                    optionals.Add(new MenuItem("Copy Selection", delegate { CopySelection(); }));

                MenuItem mnuSelectAll = new MenuItem("Select All");
                mnuSelectAll.Click += delegate { SelectAll(); };

                GeckoDomDocument doc = GeckoDomDocument.CreateDomDocumentWraper(info.GetTargetNodeAttribute().GetOwnerDocumentAttribute());

                string viewSourceUrl = (doc == null) ? null : Convert.ToString(doc.Uri);

                MenuItem mnuViewSource = new MenuItem("View Source");
                mnuViewSource.Enabled = !string.IsNullOrEmpty(viewSourceUrl);
                mnuViewSource.Click += delegate { ViewSource(viewSourceUrl); };

                MenuItem mnuOpenInSystemBrowser = new MenuItem("View In System Browser");//nice for debugging with firefox/firebug
                mnuOpenInSystemBrowser.Enabled = !string.IsNullOrEmpty(viewSourceUrl);
                mnuOpenInSystemBrowser.Click += delegate { ViewInSystemBrowser(viewSourceUrl); };


                string properties = (doc != null && doc.Uri == Document.Uri) ? "Page Properties" : "IFRAME Properties";

                MenuItem mnuProperties = new MenuItem(properties);
                mnuProperties.Enabled = doc != null;
                mnuProperties.Click += delegate { ShowPageProperties(doc); };

                menu.MenuItems.AddRange(optionals.ToArray());
                menu.MenuItems.Add(mnuSelectAll);
                menu.MenuItems.Add("-");
                menu.MenuItems.Add(mnuViewSource);
                menu.MenuItems.Add(mnuOpenInSystemBrowser);
                menu.MenuItems.Add(mnuProperties);
            }

            // get image urls
            Uri backgroundImageSrc = null, imageSrc = null;
            nsIURI src;
            try
            {
                src = info.GetBackgroundImageSrcAttribute();
                backgroundImageSrc = Xpcom.ToUri(src);
                //backgroundImageSrc = src.ToUri();
                Xpcom.FreeComObject(ref src);
            }
            catch (COMException comException)
            {
                if ((comException.ErrorCode & 0xFFFFFFFF) != 0x80004005)
                    throw comException;
            }

            try
            {
                src = info.GetBackgroundImageSrcAttribute();
                backgroundImageSrc = Xpcom.ToUri(src);
                //backgroundImageSrc = src.ToUri();
                Xpcom.FreeComObject(ref src);

                src = info.GetImageSrcAttribute();
                imageSrc = Xpcom.ToUri(src);
                //imageSrc = src.ToUri();
                Xpcom.FreeComObject(ref src);
            }
            catch (COMException comException)
            {
                if ((comException.ErrorCode & 0xFFFFFFFF) != 0x80004005)
                    throw comException;
            }

            // get associated link.  note that this needs to be done manually because GetAssociatedLink returns a non-zero
            // result when no associated link is available, so an exception would be thrown by nsString.Get()
            string associatedLink = null;
            try
            {
                using (nsAString str = new nsAString())
                {
                    info.GetAssociatedLinkAttribute(str);
                    associatedLink = str.ToString();
                }
            }
            catch (COMException comException) { }

            GeckoContextMenuEventArgs e = new GeckoContextMenuEventArgs(
                PointToClient(MousePosition),
                menu,
                associatedLink,
                backgroundImageSrc,
                imageSrc,
                // why????
                GeckoNode.Create(Xpcom.QueryInterface<nsIDOMNode>(info.GetTargetNodeAttribute()))
                );

            OnShowContextMenu(e);

            if (e.ContextMenu != null && e.ContextMenu.MenuItems.Count > 0)
            {
                e.ContextMenu.Show(this, e.Location);
            }
        }
コード例 #9
0
 void _browser_ShowContextMenu(object sender, GeckoContextMenuEventArgs e)
 {
 }