Example #1
1
		protected GeckoElement GetParentTable(GeckoElement element)
		{
			while (element != null && element.TagName.ToLowerInvariant() != "table".ToLowerInvariant())
				element = element.ParentElement as GeckoElement;

			return element;
		}
        public static void UpdateMetadataAttributesOnImage(GeckoElement img, PalasoImage imageInfo)
        {
            //see also Book.UpdateMetadataAttributesOnImage(), which does the same thing but on the document itself, not the browser dom
            img.SetAttribute("data-copyright",
                             String.IsNullOrEmpty(imageInfo.Metadata.CopyrightNotice) ? "" : imageInfo.Metadata.CopyrightNotice);

            img.SetAttribute("data-creator", String.IsNullOrEmpty(imageInfo.Metadata.Creator) ? "" : imageInfo.Metadata.Creator);

            img.SetAttribute("data-license", imageInfo.Metadata.License == null ? "" : imageInfo.Metadata.License.ToString());
        }
 public static Rectangle[] GetClientRects( GeckoElement element )
 {
     nsIDOMClientRectList domRects = element.DOMElement.GetClientRects();
     var ret = WinFormsConverter.WrapDomClientRectList( domRects );
     // TODO - check code for memory leaks
     //Marshal.ReleaseComObject( domRects );
     return ret;
 }
 /// <summary>
 /// UI specific implementation extension method GetBoundingClientRect()
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 public static System.Drawing.Rectangle GetBoundingClientRect( GeckoElement element )
 {
     nsIDOMClientRect domRect = element.DOMElement.GetBoundingClientRect();
     if ( domRect == null ) return Rectangle.Empty;
     var r = WinFormsConverter.WrapDomClientRect(domRect);
     Marshal.ReleaseComObject( domRect );
     return r;
 }
Example #5
0
		protected void ModifyElements(GeckoElement element, string tagName, Action<GeckoElement> mod)
		{
			while (element != null)
			{
				if (element.TagName == tagName)
				{
					mod(element);
				}
				ModifyElements(element.FirstChild as GeckoHtmlElement, tagName, mod);
				element = (element.NextSibling as GeckoHtmlElement);
			}
		}
Example #6
0
        public GeckoElement CreateElement(string namespaceUri, string qualifiedName)
        {
            if (string.IsNullOrEmpty(namespaceUri))
            {
                throw new ArgumentException("namespaceUri");
            }
            if (string.IsNullOrEmpty(qualifiedName))
            {
                throw new ArgumentException("qualifiedName");
            }

            var native = nsString.Pass <nsIDOMElement>(_domDocument.CreateElementNS, namespaceUri, qualifiedName);

            return(GeckoElement.Create(( nsIDOMHTMLElement )native));
        }
        private void Init()
        {
            if (!_isInitialized)
            {
                _isInitialized = true;
                GeckoDomDocument doc = webNav.Instance.GetDocumentAttribute()
                                       .Wrap(GeckoDocument.CreateDomDocumentWraper);
                GeckoElement rootElement = doc.DocumentElement;
                while (rootElement.FirstChild != null)
                {
                    rootElement.RemoveChild(rootElement.FirstChild);
                }


                // Use of the canvas technique was inspired by: the abduction! firefox plugin by Rowan Lewis
                // https://addons.mozilla.org/en-US/firefox/addon/abduction/

                uint flags = (uint)(nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_DO_NOT_FLUSH
                                    //| nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_DRAW_VIEW
                                    | nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_ASYNC_DECODE_IMAGES
                                    | nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_USE_WIDGET_LAYERS);

                string func = @"
function drawWindow(window, x, y, w, h, canvas, ctx)
{
	try {
		canvas = window.document.createElement('canvas');
		canvas.width = w;
		canvas.height = h;
		ctx = canvas.getContext('2d');
		ctx.drawWindow(window, x, y, w, h, 'rgb(255,255,255)', "         + flags.ToString() + @");
		return canvas.toDataURL('image/png');
	} catch(e) {
		return e + ''
	}
}
";

                var button = doc.CreateElement("button");
                button.SetAttribute("oncommand",
                                    func +
                                    @"this.setUserData('drawResult', drawWindow(this.getUserData('window'), this.getUserData('x'), this.getUserData('y'), this.getUserData('w'), this.getUserData('h')), null)");
                rootElement.AppendChild(button);

                command = Xpcom.QueryInterface <nsIDOMXULElement>(button.DOMElement).AsComPtr();
            }
        }
        internal static GeckoNode CreateNodeWrapper(nsIDOMNode domObject)
        {
            // if null -> return null
            if (domObject == null)
            {
                return(null);
            }
            var nodeType = ( NodeType )domObject.GetNodeTypeAttribute();

            // by nodeType we can find proper wrapper faster, than perform QueryInterface
            switch (nodeType)
            {
            case NodeType.Element:
                nsIDOMHTMLElement element = Xpcom.QueryInterface <nsIDOMHTMLElement>(domObject);
                if (element != null)
                {
                    return(GeckoElement.Create(element));
                }
                break;

            case NodeType.Attribute:
                nsIDOMAttr attr = Xpcom.QueryInterface <nsIDOMAttr>(domObject);
                if (attr != null)
                {
                    return(GeckoAttribute.CreateAttributeWrapper(attr));
                }
                break;

            case NodeType.Comment:
                nsIDOMComment comment = Xpcom.QueryInterface <nsIDOMComment>(domObject);
                if (comment != null)
                {
                    return(GeckoComment.CreateCommentWrapper(comment));
                }
                break;

            case NodeType.DocumentFragment:
                nsIDOMDocumentFragment fragment = Xpcom.QueryInterface <nsIDOMDocumentFragment>(domObject);
                if (fragment != null)
                {
                    return(DOM.DocumentFragment.CreateDocumentFragmentWrapper(fragment));
                }
                break;
            }
            // if fast method is unsuccessful try old method :)
            return(OldCreateWrapper(domObject));
        }
Example #9
0
		protected bool TryGetHvo(GeckoElement element, out int hvo)
		{
			while (element != null)
			{
				switch (element.TagName.ToLowerInvariant())
				{
					case "table":
					case "span":
					case "th":
					case "td":
						string id = element.GetAttribute("id");
						if (!string.IsNullOrEmpty(id))
							return int.TryParse(id, out hvo);
						break;
				}
				element = element.ParentElement;
			}

			hvo = 0;
			return false;
		}
 private GeckoNode GetFirstChildWithClass(GeckoElement parentElement, string targetClass)
 {
     // Something here can be null when adding pages very quickly, possibly because something
     // is incompletely constructed or in the course of being disposed? So be very careful.
     if (parentElement == null || parentElement.ChildNodes == null)
         return null;
     var targetWithSpaces = " " + targetClass + " "; // search for this to avoid partial word matches
     return parentElement.ChildNodes.FirstOrDefault(e =>
     {
         var ge = e as GeckoElement;
         if (ge == null)
             return false;
         var attr = ge.Attributes["class"];
         if (attr == null)
             return false;
         var content = " " + attr.TextContent + " "; // wrapping spaces allow us to find targetWithSpaces at start or end
         if (content == null)
             return false;
         return content.Contains(targetWithSpaces);
     });
 }
Example #11
0
 protected void DisplayElements(GeckoElement g)
 {
     while (g != null)
     {
         Console.WriteLine("tag = {0} value = {1}", g.TagName, g.TextContent);
         DisplayElements(g.FirstChild as GeckoHtmlElement);
         g = (g.NextSibling as GeckoHtmlElement);
     }
 }
Example #12
0
 private void RememberSourceTabChoice(GeckoElement target)
 {
     //"<a class="sourceTextTab" href="#tpi">Tok Pisin</a>"
     var start = 1+ target.OuterHtml.IndexOf("#");
     var end = target.OuterHtml.IndexOf("\">");
     Settings.Default.LastSourceLanguageViewed = target.OuterHtml.Substring(start, end - start);
 }
Example #13
0
        public void UpdateMetdataAttributesOnImgElement(GeckoElement img, PalasoImage imageInfo)
        {
            UpdateMetadataAttributesOnImage(img, imageInfo);

            img.Click(); //wake up javascript to update overlays
        }
Example #14
0
 public void ChangePicture(string bookFolderPath, GeckoElement img, PalasoImage imageInfo, IProgress progress)
 {
     var imageFileName = ProcessAndCopyImage(imageInfo, bookFolderPath);
     img.SetAttribute("src", imageFileName);
     UpdateMetdataAttributesOnImgElement(img, imageInfo);
 }
Example #15
0
        public void ChangePicture(GeckoElement img, PalasoImage imageInfo, IProgress progress)
        {
            try
            {
                Logger.WriteMinorEvent("Starting ChangePicture {0}...", imageInfo.FileName);
                var editor = new PageEditingModel();
                editor.ChangePicture(_bookSelection.CurrentSelection.FolderPath, img, imageInfo, progress);

                //we have to save so that when asked by the thumbnailer, the book will give the proper image
                SaveNow();
                //but then, we need the non-cleaned version back there
                _view.UpdateSingleDisplayedPage(_pageSelection.CurrentSelection);

                _view.UpdateThumbnailAsync(_pageSelection.CurrentSelection);
                Logger.WriteMinorEvent("Finished ChangePicture {0} (except for async thumbnail) ...", imageInfo.FileName);
                Analytics.Track("Change Picture");
                Logger.WriteEvent("ChangePicture {0}...", imageInfo.FileName);

            }
            catch (Exception e)
            {
                ErrorReport.NotifyUserOfProblem(e, "Could not change the picture");
            }
        }
Example #16
0
 /// <summary>
 /// Returns the element visible at the given point, relative to the upper-left-most visible point in the document.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public GeckoElement ElementFromPoint(int x, int y)
 {
     return(GeckoElement.Create((nsIDOMHTMLElement)_domDocument.ElementFromPoint(x, y)));
 }