/// <summary> /// Get a bitmap of the current browsers Window. /// Works on Visible or InVisible windows. /// </summary> /// <param name="xOffset"></param> /// <param name="yOffset"></param> /// <param name="width">Width length of returned bitmap in pixels</param> /// <param name="height">Height length of returned bitmap in pixels</param> /// <returns></returns> /// <throws>ArgumentException if width or height is zero</throws> public Bitmap GetBitmap(uint xOffset, uint yOffset, uint width, uint height) { if (width == 0) throw new ArgumentException("width"); if (height == 0) throw new ArgumentException("height"); // Use of the canvas technique was inspired by: the abduction! firefox plugin by Rowan Lewis // https://addons.mozilla.org/en-US/firefox/addon/abduction/ // Some opertations fail without a proper JSContext. using (AutoJSContext jsContext = new AutoJSContext()) { GeckoCanvasElement canvas = (GeckoCanvasElement)m_browser.Document.CreateElement("canvas"); canvas.Width = width; canvas.Height = height; nsIDOMHTMLCanvasElement canvasPtr = (nsIDOMHTMLCanvasElement)canvas.DomObject; nsIDOMCanvasRenderingContext2D context; using (nsAString str = new nsAString("2d")) { context = (nsIDOMCanvasRenderingContext2D)canvasPtr.MozGetIPCContext(str); } using (nsAString color = new nsAString("rgb(255,255,255)")) { context.DrawWindow((nsIDOMWindow)m_browser.Window.DomWindow, xOffset, yOffset, width, height, color, 0); } string data = canvas.toDataURL("image/png"); byte[] bytes = Convert.FromBase64String(data.Substring("data:image/png;base64,".Length)); return (Bitmap)Bitmap.FromStream(new System.IO.MemoryStream(bytes)); } }
public void InsertData(uint offset, string arg) { using (nsAString str = new nsAString(arg)) { DomComment.InsertData(offset, str); } }
public void ReplaceData(uint offset, uint count, string arg) { using (nsAString str = new nsAString(arg)) { DomComment.ReplaceData(offset, count, str); } }
public static string Get(StringAttributeUnicode getter) { using (nsAString str = new nsAString()) { getter(str); return str.ToString(); } }
public string SubstringData(uint offset, uint count) { using (nsAString retval = new nsAString()) { DomComment.SubstringData(offset, count, retval); return retval.ToString(); } }
public static void Set(StringAttributeUnicode setter, string value) { using (nsAString str = new nsAString()) { if (!string.IsNullOrEmpty(value)) str.SetData(value); setter(str); } }
/// <summary> /// Add a C# listner to the xpcom listner. This is done by wrappinig the xpcom event. /// </summary> /// <param name="Type">The name of the eventtype, for e.g 'MyCustomEvent'. This must be the same as the EventName in the JavaScript.</param> /// <param name="Handler">The handler for this event</param> public void AddEventListener(string Type, EventHandler<DOMJSONStringEventArgs> Handler) { RouteEventHandler Listener = new RouteEventHandler(Handler); if (oEventListeners.ContainsKey(Handler.Method.GetHashCode()) == true && oEventTypes.ContainsKey(Handler.Method.GetHashCode())) { oEventListeners.Remove(Handler.Method.GetHashCode()); oEventTypes.Remove(Handler.Method.GetHashCode()); } oEventListeners.Add(Handler.Method.GetHashCode(), Listener); nsAString nsType = new nsAString(Type); oEventTypes.Add(Handler.Method.GetHashCode(), nsType); (oDomWindow as nsIDOMEventTarget).AddEventListener(nsType, Listener, false, false, 0); }
void nsIDOMEventListener.HandleEvent(nsIDOMEvent e) { nsAString jsEventName = new nsAString(); nsAString attribute = new nsAString(JS_ELEMENT_NAME); nsAString value = new nsAString(); nsIDOMElement target = e.GetTargetAttribute() as nsIDOMElement; target.GetAttribute(attribute, value); e.GetTypeAttribute(jsEventName); DOMJSONStringEventArgs eArgs = new DOMJSONStringEventArgs(jsEventName, value); if (this.handler != null) this.handler(target, eArgs); jsEventName.Dispose(); attribute.Dispose(); value.Dispose(); }
public bool Confirm(nsAString text) { throw new NotImplementedException(); }
/// <summary> /// Returns a set of elements with the given class name. When called on the document object, the complete document is searched, including the root node. /// </summary> /// <param name="classes"></param> /// <returns></returns> public GeckoNodeCollection GetElementsByClassName(string classes) { using (nsAString str = new nsAString(classes)) return(new GeckoNodeCollection(((nsIDOMDocument)DomDocument).GetElementsByClassName(str))); }
public nsIVariant ShowModalDialog(nsAString aURI, nsIVariant aArgs, nsAString aOptions) { throw new NotImplementedException(); }
public void Atob(nsAString aAsciiString, nsAString retval) { throw new NotImplementedException(); }
static extern int NS_StringContainerInit(nsAString container);
public void SetStatusAttribute(nsAString aStatus) { throw new NotImplementedException(); }
public nsIDOMMediaQueryList MatchMedia(nsAString media_query_list) { throw new NotImplementedException(); }
public nsIDOMCSSStyleDeclaration GetComputedStyle(nsIDOMElement elt, nsAString pseudoElt) { throw new NotImplementedException(); }
static extern int NS_StringContainerFinish(nsAString container);
static extern int NS_StringGetData(nsAString str, out IntPtr data, IntPtr nullTerm);
static extern int NS_StringSetData(nsAString str, string data, int length);
public void GetDefaultStatusAttribute(nsAString aDefaultStatus) { throw new NotImplementedException(); }
public nsIDOMWindow OpenDialog(nsAString url, nsAString name, nsAString options, nsISupports aExtraArgument) { throw new NotImplementedException(); }
public nsIDOMWindow Open(nsAString url, nsAString name, nsAString options) { throw new NotImplementedException(); }
public void Prompt(nsAString aMessage, nsAString aInitial, nsAString retval) { throw new NotImplementedException(); }
public void PostMessage(IntPtr message, nsAString targetOrigin) { throw new NotImplementedException(); }
public void SetNameAttribute(nsAString aName) { throw new NotImplementedException(); }
public void Alert(nsAString text) { throw new NotImplementedException(); }
public void UpdateCommands(nsAString action) { throw new NotImplementedException(); }
public void Btoa(nsAString aBase64Data, nsAString retval) { throw new NotImplementedException(); }
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.GetTargetNode() == 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(); }; GeckoDocument doc = GeckoDocument.Create((nsIDOMHTMLDocument)info.GetTargetNode().GetOwnerDocument()); string viewSourceUrl = (doc == null) ? null : Convert.ToString(doc.Url); MenuItem mnuViewSource = new MenuItem("View Source"); mnuViewSource.Enabled = !string.IsNullOrEmpty(viewSourceUrl); mnuViewSource.Click += delegate { ViewSource(viewSourceUrl); }; string properties = (doc != null && doc.Url == Document.Url) ? "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(mnuProperties); } // get image urls Uri backgroundImageSrc = null, imageSrc = null; nsIURI src; if (info.GetBackgroundImageSrc(out src) == 0) { backgroundImageSrc = new Uri(new nsURI(src).Spec); } if (info.GetImageSrc(out src) == 0) { imageSrc = new Uri(new nsURI(src).Spec); } // 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; using (nsAString str = new nsAString()) { if (info.GetAssociatedLink(str) == 0) { associatedLink = str.ToString(); } } GeckoContextMenuEventArgs e = new GeckoContextMenuEventArgs( PointToClient(MousePosition), menu, associatedLink, backgroundImageSrc, imageSrc, GeckoNode.Create(Xpcom.QueryInterface<nsIDOMNode>(info.GetTargetNode())) ); OnShowContextMenu(e); if (e.ContextMenu != null && e.ContextMenu.MenuItems.Count > 0) { e.ContextMenu.Show(this, e.Location); } }
public bool Find(nsAString str, bool caseSensitive, bool backwards, bool wrapAround, bool wholeWord, bool searchInFrames, bool showDialog) { throw new NotImplementedException(); }
void nsIDOMEventListener.HandleEvent(nsIDOMEvent e) { string type; using (nsAString str = new nsAString()) { e.GetType(str); type = str.ToString(); } GeckoDomEventArgs ea = null; switch (type) { case "keydown": OnDomKeyDown((GeckoDomKeyEventArgs)(ea = new GeckoDomKeyEventArgs((nsIDOMKeyEvent)e))); break; case "keyup": OnDomKeyUp((GeckoDomKeyEventArgs)(ea = new GeckoDomKeyEventArgs((nsIDOMKeyEvent)e))); break; case "mousedown": OnDomMouseDown((GeckoDomMouseEventArgs)(ea = new GeckoDomMouseEventArgs((nsIDOMMouseEvent)e))); break; case "mouseup": OnDomMouseUp((GeckoDomMouseEventArgs)(ea = new GeckoDomMouseEventArgs((nsIDOMMouseEvent)e))); break; case "mousemove": OnDomMouseMove((GeckoDomMouseEventArgs)(ea = new GeckoDomMouseEventArgs((nsIDOMMouseEvent)e))); break; case "mouseover": OnDomMouseOver((GeckoDomMouseEventArgs)(ea = new GeckoDomMouseEventArgs((nsIDOMMouseEvent)e))); break; case "mouseout": OnDomMouseOut((GeckoDomMouseEventArgs)(ea = new GeckoDomMouseEventArgs((nsIDOMMouseEvent)e))); break; case "click": OnDomClick(ea = new GeckoDomEventArgs(e)); break; case "submit": OnDomSubmit(ea = new GeckoDomEventArgs(e)); break; } if (ea != null && ea.Cancelable && ea.Handled) e.PreventDefault(); }