/// <summary> /// An example event handler for the DomClick event. /// Prevents a link click from navigating. /// </summary> private void StopLinksNavigating(object sender, DomEventArgs e) { if (sender == null) { return; } if (e == null) { return; } if (e.Target == null) { return; } var element = e.Target.CastToGeckoElement(); GeckoHtmlElement clicked = element as GeckoHtmlElement; if (clicked == null) { return; } // prevent clicking on Links from navigation to the if (clicked.TagName == "A") { e.Handled = true; MessageBox.Show(sender as IWin32Window, String.Format("You clicked on Link {0}", clicked.GetAttribute("href"))); } }
internal static GeckoCanvasElement CreateCanvasOfImageElement(IGeckoWebBrowser browser, GeckoHtmlElement element, float xOffset, float yOffset, float width, float height) { if (width == 0) throw new ArgumentException("width"); if (height == 0) throw new ArgumentException("height"); // Some opertations fail without a proper JSContext. using(var jsContext = new AutoJSContext(GlobalJSContextHolder.BackstageJSContext)) { GeckoCanvasElement canvas = (GeckoCanvasElement)browser.Document.CreateElement("canvas"); canvas.Width = (uint)width; canvas.Height = (uint)height; nsIDOMHTMLCanvasElement canvasPtr = (nsIDOMHTMLCanvasElement)canvas.DomObject; nsIDOMCanvasRenderingContext2D context; using (var str = new nsAString("2d")) { context = (nsIDOMCanvasRenderingContext2D)canvasPtr.MozGetIPCContext(str); } context.DrawImage((nsIDOMElement)element.DomObject, xOffset, yOffset, width, height, xOffset, yOffset, width, height, 6); return canvas; } }
private static string CopyImageElementToDataImageString(GeckoHtmlElement element, string imageFormat, float xOffset, float yOffset, float width, float height) { if (width == 0) { throw new ArgumentException("width"); } if (height == 0) { throw new ArgumentException("height"); } string data; using (var context = new AutoJSContext(element.Window)) { context.EvaluateScript(string.Format(@"(function(element, canvas, ctx) {{ canvas = element.ownerDocument.createElement('canvas'); canvas.width = {2}; canvas.height = {3}; ctx = canvas.getContext('2d'); ctx.drawImage(element, -{0}, -{1}); return canvas.toDataURL('{4}'); }} )(this)" , xOffset, yOffset, width, height, imageFormat), (nsISupports)(nsIDOMElement)element.DomObject, out data); } return(data); }
private static string CopyImageElementToDataImageString(GeckoHtmlElement element, string imageFormat, float xOffset, float yOffset, float width, float height) { if (width == 0) throw new ArgumentException("width"); if (height == 0) throw new ArgumentException("height"); string data; using (var context = new AutoJSContext()) { context.EvaluateScript(string.Format(@"(function(element, canvas, ctx) {{ canvas = element.ownerDocument.createElement('canvas'); canvas.width = {2}; canvas.height = {3}; ctx = canvas.getContext('2d'); ctx.drawImage(element, -{0}, -{1}); return canvas.toDataURL('{4}'); }} )(this)", xOffset, yOffset, width, height, imageFormat), (nsISupports)(nsIDOMElement)element.DomObject, out data); } return data; }
public GeckoElement GetElementByJQuery(string jQuery) { using (var autoContext = new AutoJSContext(_window)) { var jsValue = autoContext.EvaluateScript(jQuery, _window.DomWindow); if (!jsValue.IsObject) { return(null); } var nativeComObject = jsValue.ToComObject(autoContext.ContextPointer); var element = Xpcom.QueryInterface <nsIDOMHTMLElement>(nativeComObject); if (element != null) { return(GeckoHtmlElement.Create(element)); } if (!SpiderMonkey.JS_HasProperty(autoContext.ContextPointer, jsValue.AsPtr, "length")) { return(null); } var length = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, "length").ToInteger(); if (length == 0) { return(null); } return(CreateHtmlElementFromDom(autoContext, jsValue, 0)); } }
public void ChangePicture(string bookFolderPath, GeckoHtmlElement img, PalasoImage imageInfo, IProgress progress) { var imageFileName = ProcessAndCopyImage(imageInfo, bookFolderPath); img.SetAttribute("src", imageFileName); UpdateMetdataAttributesOnImgElement(img, imageInfo); }
public void CreateElement_EmptyDocument_HtmlElementReturned() { browser.TestLoadHtml(""); GeckoHtmlElement element = browser.DomDocument.CreateHtmlElement("div"); Assert.NotNull(element); Assert.AreEqual("div", element.TagName.ToLowerInvariant()); }
private void RememberSourceTabChoice(GeckoHtmlElement 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); }
private void geckoWebBrowser1_DomMouseDown(object sender, DomMouseEventArgs e) { GeckoHtmlElement elm = (GeckoHtmlElement)e.Target.CastToGeckoElement(); if (elm.ClassName.Contains("fullscreen")) { this.SetWindowState(FormWindowState.Maximized, false); } }
/// <summary> /// Need the GeckoWebBrowser , ImageElement , X-OffSet , Y-Offset (put 0.0F if you want offset), Width , height) /// Return the png image in data bytes[] /// </summary> public static byte[] ConvertGeckoImageElementToPng(IGeckoWebBrowser browser, GeckoHtmlElement element, float xOffset, float yOffset, float width, float height) { GeckoCanvasElement canvas = CreateCanvasOfImageElement(browser, element, xOffset, yOffset, width, height); string data = canvas.toDataURL("image/png"); byte[] bytes = Convert.FromBase64String(data.Substring("data:image/png;base64,".Length)); return bytes; }
private static GeckoElement CreateHtmlElementFromDom(AutoJSContext autoContext, JsVal jsValue, int elementIndex) { var elementIndexString = elementIndex.ToString(CultureInfo.InvariantCulture); var firstNativeDom = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, elementIndexString).ToComObject(autoContext.ContextPointer); var element = Xpcom.QueryInterface </* nsIDOMHTMLElement */ nsIDOMElement>(firstNativeDom); return(element == null ? null : GeckoHtmlElement.Create((mozIDOMWindowProxy)autoContext.Window, element)); }
/// <summary> /// Need the GeckoWebBrowser , ImageElement , X-OffSet , Y-Offset (put 0.0F if you want offset), Width , height) /// Return true if the image was copied in the ClipBoard /// </summary> public bool CopyGeckoImageElementToPng(IGeckoWebBrowser browser, GeckoHtmlElement element, float xOffset, float yOffset, float width, float height) { string data = CopyImageElementToDataImageString(element, "image/png", xOffset, yOffset, width, height); if (data == null || !data.StartsWith("data:image/png;base64,")) return false; byte[] bytes = Convert.FromBase64String(data.Substring("data:image/png;base64,".Length)); Clipboard.SetImage(System.Drawing.Image.FromStream(new System.IO.MemoryStream(bytes))); return Clipboard.ContainsImage(); }
private void markToolStripMenuItem_Click(object sender, EventArgs e) { GeckoHtmlElement obj = (GeckoHtmlElement)Browser_ContextMenu_RightClk.Tag; _vm_Alert = _services.GetInstance <I_VM_Alert>(); _vm_Alert.Alerts[_vm_Alert.Alerts.Count - 1].AlertValue = obj.InnerHtml; _vm_Alert.Alerts[_vm_Alert.Alerts.Count - 1].AlertHtml = obj.OuterHtml; //MessageBox.Show(obj.InnerHtml); }
/// <summary> /// Need the GeckoWebBrowser , ImageElement , X-OffSet , Y-Offset (put 0.0F if you want offset), Width , height) /// Return true if the image was copied in the ClipBoard /// </summary> public bool CopyGeckoImageElementToPng(IGeckoWebBrowser browser, GeckoHtmlElement element, float xOffset, float yOffset, float width, float height) { GeckoCanvasElement canvas = CreateCanvasOfImageElement(browser, element, xOffset, yOffset, width, height); string data = canvas.toDataURL("image/png"); byte[] bytes = Convert.FromBase64String(data.Substring("data:image/png;base64,".Length)); Clipboard.SetImage(System.Drawing.Image.FromStream(new System.IO.MemoryStream(bytes))); return Clipboard.ContainsImage(); }
/// <summary> /// Need the GeckoWebBrowser , ImageElement , X-OffSet , Y-Offset (put 0.0F if you want offset), Width , height) /// Return the png image in data bytes[] /// </summary> public static byte[] ConvertGeckoImageElementToPng(IGeckoWebBrowser browser, GeckoHtmlElement element, float xOffset, float yOffset, float width, float height) { string data = CopyImageElementToDataImageString(element, "image/png", xOffset, yOffset, width, height); if (data == null || !data.StartsWith("data:image/png;base64,")) throw new InvalidOperationException(); byte[] bytes = Convert.FromBase64String(data.Substring("data:image/png;base64,".Length)); return bytes; }
private int getEpisodeNumber(GeckoHtmlElement element) { string title = element.GetAttribute("href"); var reg = Regex.Match(title, "([Ss]([0-9][0-9])[Ee]([0-9][0-9]))"); if (!reg.Success) { reg = Regex.Match(title, @"(\d+)[x]([0-9][0-9])"); } return(int.Parse(reg.Groups[3].Value)); }
/// <summary> /// Need the GeckoWebBrowser , ImageElement , X-OffSet , Y-Offset (put 0.0F if you want offset), Width , height) /// Return the png image in data bytes[] /// </summary> public static byte[] ConvertGeckoImageElementToPng(IGeckoWebBrowser browser, GeckoHtmlElement element, float xOffset, float yOffset, float width, float height) { string data = CopyImageElementToDataImageString(element, "image/png", xOffset, yOffset, width, height); if (data == null || !data.StartsWith("data:image/png;base64,")) { throw new InvalidOperationException(); } byte[] bytes = Convert.FromBase64String(data.Substring("data:image/png;base64,".Length)); return(bytes); }
private void button2_Click(object sender, EventArgs e) { tabControl1.SelectedIndex = 1; GeckoHtmlElement element = null; var geckoDomElement = geckoWebBrowser1.Document.DocumentElement; if (geckoDomElement is GeckoHtmlElement) { element = (GeckoHtmlElement)geckoDomElement; var innerHtml = element.InnerHtml; textBox1.Text = innerHtml; } }
/// <summary> /// Dom单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void On_DomClick(object sender, DomMouseEventArgs e) { //屏蔽页面点击事件 e.PreventDefault(); e.StopPropagation(); var ele = e.CurrentTarget.CastToGeckoElement(); ele = e.Target.CastToGeckoElement(); GeckoHtmlElement geckoHtmlElement = (GeckoHtmlElement)ele; string searchElement = geckoHtmlElement.OuterHtml; if (!searchElement.Contains("firefinder-match-red")) { //在datagridview中显示选中行的内容 GeckoHtmlElement[] geckoHtmlEle = new GeckoHtmlElement[1]; geckoHtmlEle[0] = geckoHtmlElement; if (geckofxType.Equals(GeckofxWebbrowerType.General)) { InsertDataGridRow(dgv, geckoWebBrowser, geckoHtmlEle); } else if (geckofxType.Equals(GeckofxWebbrowerType.ListDetails)) { InsertDataGridRow(dgv, geckoWebBrowser, geckoHtmlEle); } else if (geckofxType.Equals(GeckofxWebbrowerType.UrlModel)) { try { GeckoAnchorElement d = (GeckoAnchorElement)geckoHtmlElement; string URL = d.Href; InsertDataGridRow(GeckofxWebbrowerType.UrlModel, dgv, geckoWebBrowser, geckoHtmlEle); } catch (Exception) { MessageBox.Show("请获取链接!"); return; } } ruleStyle.AddClass("firefinder-match-red", ele); } else { //在浏览器中标记红圈 ruleStyle.RemoveClass("firefinder-match-red", ele); } }
/// <summary> /// Need the GeckoWebBrowser , ImageElement , X-OffSet , Y-Offset (put 0.0F if you want offset), Width , height) /// Return true if the image was copied in the ClipBoard /// </summary> public bool CopyGeckoImageElementToPng(IGeckoWebBrowser browser, GeckoHtmlElement element, float xOffset, float yOffset, float width, float height) { string data = CopyImageElementToDataImageString(element, "image/png", xOffset, yOffset, width, height); if (data == null || !data.StartsWith("data:image/png;base64,")) { return(false); } byte[] bytes = Convert.FromBase64String(data.Substring("data:image/png;base64,".Length)); Clipboard.SetImage(System.Drawing.Image.FromStream(new System.IO.MemoryStream(bytes))); return(Clipboard.ContainsImage()); }
private Point GetAbsolutePosition(GeckoHtmlElement element) { var left = 0; var top = 0; var obj = element; while (obj.TagName.ToLower() != "body") { left += obj.OffsetLeft; top += obj.OffsetTop; obj = obj.OffsetParent; } return(new Point(left, top)); }
private void tm_XoaNoiDung_Tick(object sender, EventArgs e) { //xóa header GeckoHtmlElement nodeHeader = (Gecko.GeckoHtmlElement)web.Document.SelectSingle("//div[@id='header']"); if (nodeHeader != null) { nodeHeader.ParentNode.RemoveChild(nodeHeader); } //ẩn button soạn tin nhắn và khung tìm kiếm GeckoHtmlElement nodeButton = (Gecko.GeckoHtmlElement)web.Document.SelectFirst("//a[@data-sigil='touchable dialog-link']"); if (nodeButton != null) { nodeButton.ParentElement.ParentElement.SetAttribute("style", "display:none;"); } //ẩn các link folder tin nhắn GeckoHtmlElement nodeLink = (Gecko.GeckoHtmlElement)web.Document.SelectFirst("//div[@id='threadlist_rows']"); if (nodeLink != null) { ((Gecko.GeckoHtmlElement)nodeLink.NextSibling).SetAttribute("style", "display:none;"); } //ẩn button share GeckoHtmlElement nodeButton2 = (Gecko.GeckoHtmlElement)web.Document.SelectFirst("//select[@class='selectBtn touchable']"); if (nodeButton2 != null) { nodeButton2.ParentElement.SetAttribute("style", "display:none;"); } //ẩn khung nhập nội dung form GeckoHtmlElement nodeForm = (Gecko.GeckoHtmlElement)web.Document.SelectFirst("//textarea"); if (nodeForm != null) { nodeForm.ParentElement.ParentElement.SetAttribute("style", "display:none;"); } //vô hiệu hóa link vào profile trong hộp chat GeckoElementCollection arrA = web.Document.GetElementsByTagName("a"); foreach (GeckoElement a in arrA) { if (a.GetAttribute("class") == "actor-link") { a.SetAttribute("href", "#"); } } }
private void _okButton_Click(object sender, EventArgs e) { GeckoDocument doc = _browser.WebBrowser.Document; var body = doc.GetElementsByTagName("body").First(); GeckoHtmlElement div = doc.CreateElement("div") as GeckoHtmlElement; div.Id = "output"; body.AppendChild(div); _browser.RunJavaScript("gatherSettings()"); FormData = div.InnerHtml; DialogResult = DialogResult.OK; Close(); }
private void btnDk_Click_1(object sender, EventArgs e) { web1.Navigate("http://seakbz.tk/giphy.gif"); // web1.Navigate("http://220.231.117.235/ListPoint/listpoint_Brc1.asp",GeckoLoadFlags.); GeckoHtmlElement CSS = web1.Document.GetElementsByTagName("TABLE")[0]; CSS.SetAttribute("style", "background: red;"); if (web1.Url.ToString() == "http://220.231.117.235/dkmh/error.asp") { txtUsename.Text = "15150136"; txtPass.Text = "25081995a7"; web1.Navigate(URL_LOGIN); web1.DocumentCompleted += new EventHandler <Gecko.Events.GeckoDocumentCompletedEventArgs>(web_DienMatKhau); } }
public static string GetUrlByElementParent(Object objElement) { string URL; GeckoHtmlElement element = (GeckoHtmlElement)objElement; try { GeckoAnchorElement d = (GeckoAnchorElement)element.Parent; URL = d.Href; } catch (Exception) { URL = null; } return(URL); }
private static GeckoHtmlElement GetImageNode(DomEventArgs ge) { GeckoHtmlElement imageElement = null; var target = (GeckoHtmlElement)ge.Target.CastToGeckoElement(); foreach (var n in target.Parent.ChildNodes) { imageElement = n as GeckoHtmlElement; if (imageElement != null && imageElement.TagName.ToLower() == "img") { return(imageElement); } } Debug.Fail("Could not find image element"); return(null); }
private void btnLoadTinNhan_Click(object sender, EventArgs e) { if (btnLoadTinNhan.Text == "Tải tin nhắn") { if (txtTuLuc.Checked && txtDenLuc.Checked && txtDenLuc.Value >= txtTuLuc.Value) { ComponentFactory.Krypton.Toolkit.KryptonMessageBox.Show("Khoảng thời gian không hợp lệ!", "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } TrangThaiDangTai(false); tabMain.SelectedIndex = 1; btnLoadTinNhan.Text = "Dừng hoạt động"; web2.Document.Body.InnerHtml = ""; GeckoHtmlElement divRoot = web2.Document.CreateHtmlElement("div"); web2.Document.Body.AppendChild(divRoot); string style = "<style type='text/css'>"; style += ".msg{padding:5px;font-size:15px;color:#34495e;}"; style += ".user{border-top:1px solid #e5e5e5;margin-top:10px;padding-bottom:10px;padding-top:10px;font-size:16px;color:#2980b9;}"; style += ".time{margin-left:10px;font-style:italic;font-size:13px;color:#666;}"; style += ".time2{font-style:italic;font-size:15px;color:#999;margin-right:5px;float:left;}"; style += "</style>"; web2.Document.Head.InnerHtml = style; if (txtTuLuc.Checked) { double tuluc = (txtTuLuc.Value.AddHours(-7) - new DateTime(1970, 1, 1)).TotalMilliseconds; web.Navigate(web.Url.ToString() + "&last_message_timestamp=" + tuluc.ToString()); web.DocumentCompleted += new EventHandler <Gecko.Events.GeckoDocumentCompletedEventArgs>(web_BatDauLoadTinNhan); } else { BatDauLoadTinNhan(); } } else { btnLoadTinNhan.Text = "Tải tin nhắn"; isDangXuLyTinNhan = false; divLoadMore = null; TrangThaiDangTai(true); tm_XuLyTinNhan.Stop(); } }
private void geckoWebBrowser1_DomMouseOver(object sender, DomMouseEventArgs e) { try { element = (GeckoHtmlElement)geckoWebBrowser1.Document.ElementFromPoint(e.ClientX, e.ClientY); if (!this.elementStyles.ContainsKey(element)) { string style = element.Style.CssText; elementStyles.Add(element, style); element.SetAttribute("style", style + ";border-style: solid;border-color: #FF0000;"); richTextBox1.Text = element.TextContent.Trim(); richTextBox2.Text = element.TagName.Trim(); richTextBox3.Text = element.OuterHtml.Trim(); } } catch (Exception ex) { } }
public void Clear() { if (!IsTextBoxReady) { _cachedText = String.Empty; return; } GeckoHtmlElement element = GetTextBoxElement(); if (element is GeckoInputElement) { GetTextBoxElement().NodeValue = String.Empty; } else { element.InnerHtml = String.Empty; } }
private void SearchNext() { if (queuedSearches.Count == 0) { ExportToExcel(); MessageBox.Show("Search Completed! Data Exported to Selected Location.", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { currentSearch++; UpdateSearchStatus(); string strKeyword = queuedSearches[0].Split(':')[0]; string strCountry = queuedSearches[0].Split(':')[1]; if (!string.IsNullOrEmpty(strKeyword) && !string.IsNullOrEmpty(strCountry)) { Log.Information("Searching for Keyword '{0}' in Country '{1}'", strKeyword, strCountry); lbl_Search_Keyword.Text = strKeyword; lbl_Search_Country.Text = strCountry; currentCountry = strCountry; GeckoInputElement keyword = (GeckoInputElement)Browser.Document.GetElementById("memberKeywords"); GeckoHtmlElement country = (GeckoHtmlElement)Browser.Document.GetElementById("memberIdCountry"); GeckoHtmlElement submit = (GeckoHtmlElement)Browser.Document.GetElementById("searchConnections"); keyword.Click(); keyword.Focus(); keyword.Value = strKeyword; this.Focus(); Browser.Focus(); country.Focus(); SendKeys.SendWait(strCountry); submit.Focus(); submit.Click(); } queuedSearches.RemoveAt(0); } }
protected int SetControlHeightByMeasuringInternalHtmlControlHeight(GeckoHtmlElement htmlControl) { #if PORT var newHeight = htmlControl.offsetHeight + 1; Height = newHeight; if (Parent is TableLayoutPanel) { const int paddingValue = 5; var tableLayoutPanel = (TableLayoutPanel)Parent; int row = tableLayoutPanel.GetRow(this); tableLayoutPanel.RowStyles[row] = new RowStyle(SizeType.Absolute, newHeight + paddingValue); } return(newHeight); #else var newHeight = htmlControl.OffsetHeight; Height = newHeight; return(newHeight); #endif }
protected virtual void Closing() { this.Load -= _loadHandler; this.BackColorChanged -= _backColorChangedHandler; this.ForeColorChanged -= _foreColorChangedHandler; _focusElement = null; if (_timer != null) { _timer.Stop(); _timer = null; } if (_browser != null) { _browser.DomKeyDown -= _domKeyDownHandler; _browser.DomKeyUp -= _domKeyUpHandler; _browser.DomFocus -= _domFocusHandler; _browser.DomBlur -= _domBlurHandler; _browser.DocumentCompleted -= _domDocumentCompletedHandler; #if __MonoCS__ _browser.DomClick -= _domClickHandler; _browser.Dispose(); _browser = null; #else if (Xpcom.IsInitialized) { _browser.Dispose(); _browser = null; } #endif } _loadHandler = null; _domKeyDownHandler = null; _domKeyUpHandler = null; _domFocusHandler = null; _domDocumentCompletedHandler = null; #if __MonoCS__ _domClickHandler = null; #endif }
public GeckoElement GetElementByJQuery(string jQuery) { JsVal jsValue; using (var autoContext = new AutoJSContext()) { autoContext.PushCompartmentScope((nsISupports)m_Window.Document.DomObject); jsValue = autoContext.EvaluateScript(jQuery); if (jsValue.IsObject) { var nativeComObject = jsValue.ToComObject(autoContext.ContextPointer); var element = Xpcom.QueryInterface <nsIDOMHTMLElement>(nativeComObject); if (element != null) { return(GeckoHtmlElement.Create(element)); } if (!SpiderMonkey.JS_HasProperty(autoContext.ContextPointer, jsValue.AsPtr, "length")) { return(null); } var length = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, "length").ToInteger(); if (length == 0) { return(null); } var firstNativeDom = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, "0").ToComObject(autoContext.ContextPointer); element = Xpcom.QueryInterface <nsIDOMHTMLElement>(firstNativeDom); if (element != null) { return(GeckoHtmlElement.Create(element)); } } } return(null); }
public void ChangePicture(GeckoHtmlElement 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"); } }
public IEnumerable <GeckoElement> GetElementsByJQuery(string jQuery) { JsVal jsValue; var elements = new List <GeckoElement>(); using (var autoContext = new AutoJSContext()) { autoContext.PushCompartmentScope((nsISupports)m_Window.Document.DomObject); jsValue = autoContext.EvaluateScript(jQuery); if (!jsValue.IsObject) { return(elements); } if (!SpiderMonkey.JS_HasProperty(autoContext.ContextPointer, jsValue.AsPtr, "length")) { return(null); } var length = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, "length").ToInteger(); if (length == 0) { return(null); } for (var elementIndex = 0; elementIndex < length; elementIndex++) { var firstNativeDom = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, elementIndex.ToString(CultureInfo.InvariantCulture)).ToComObject(autoContext.ContextPointer); var element = Xpcom.QueryInterface <nsIDOMHTMLElement>(firstNativeDom); if (element != null) { elements.Add(GeckoHtmlElement.Create(element)); } } } return(elements); }
protected virtual void OnDomFocus(object sender, DomEventArgs e) { if (!_browserDocumentLoaded) { return; } // Only handle DomFocus that occurs on a Element. // This is Important or it will mess with IME keyboard focus. if (e == null || e.Target == null || e.Target.CastToGeckoElement() == null) { return; } var content = _browser.Document.GetElementById("main"); if (content != null) { if ((content is GeckoHtmlElement) && (!_inFocus)) { // The following is required because we get two in focus events every time this // is entered. This is normal for Gecko. But I don't want to be constantly // refocussing. _inFocus = true; #if DEBUG //Debug.WriteLine("OnDomFocus"); #endif EnsureFocusedGeckoControlHasInputFocus(); if (_browser != null) { _browser.SetInputFocus(); } _focusElement = (GeckoHtmlElement)content; ChangeFocus(); } } }
/// <summary> /// Perform the equivalent of: /// window.getComputedStyle(aElement, aPseudoElement). /// getPropertyValue(aPropertyName) /// except that, when the link whose presence in history is allowed to /// influence aElement's style is visited, get the value the property /// would have if allowed all properties to change as a result of /// :visited selectors (except for cases where getComputedStyle uses /// data from the frame). /// /// This is easier to implement than adding our property restrictions /// to this API, and is sufficient for the present testing /// requirements (which are essentially testing 'color'). /// </summary> public string GetVisitedDependentComputedStyle(GeckoHtmlElement aElement, string aPseudoElement, string aPropertyName) { throw new NotImplementedException(); }
public void add(GeckoHtmlElement element, GeckoHtmlElement before) { DOMHTMLElement.Add(element.DomObject as nsIDOMHTMLElement, before.DomObject as nsIVariant); }
void wbBrowser_DomContextMenu(object sender, DomMouseEventArgs e) { if (e.Button.ToString().IndexOf("Right") != -1) { contextMenuBrowser.Show(Cursor.Position); GeckoWebBrowser wb = (GeckoWebBrowser)GetCurrentWB(); if (wb != null) { htmlElm = wb.Document.ElementFromPoint(e.ClientX, e.ClientY); } } }
private string GetXpath(GeckoHtmlElement ele) { string xpath = ""; while (ele != null) { int ind = GetXpathIndex(ele); if (ind > 1) xpath = "/" + ele.TagName.ToLower() + "[" + ind + "]" + xpath; else xpath = "/" + ele.TagName.ToLower() + xpath; ele = ele.Parent; } return xpath; }
void SaveChangedImage(GeckoHtmlElement imageElement, PalasoImage imageInfo, string exceptionMsg) { try { if(ShouldBailOutBecauseUserAgreedNotToUseJpeg(imageInfo)) return; _model.ChangePicture(imageElement, imageInfo, new NullProgress()); } catch(System.IO.IOException error) { ErrorReport.NotifyUserOfProblem(error, error.Message); } catch(ApplicationException error) { ErrorReport.NotifyUserOfProblem(error, error.Message); } catch(Exception error) { ErrorReport.NotifyUserOfProblem(error, exceptionMsg); } }
/// <summary> /// Gets the url for the image, either from an img element or any other element that has /// an inline style with background-image set. /// </summary> public static UrlPathString GetImageElementUrl(GeckoHtmlElement imageElement) { return GetImageElementUrl(new ElementProxy(imageElement)); }
public void ChangePicture(GeckoHtmlElement img, PalasoImage imageInfo, IProgress progress) { try { Logger.WriteMinorEvent("Starting ChangePicture {0}...", imageInfo.FileName); var editor = new PageEditingModel(); editor.ChangePicture(CurrentBook.FolderPath, new ElementProxy(img), imageInfo, progress); // We need to save so that when asked by the thumbnailer, the book will give the proper image SaveNow(); // BL-3717: if we cleanup unused image files whenever we change a picture then Cut can lose // all of an image's metadata (because the actual file is missing from the book folder when we go to // paste in the image that was copied onto the clipboard, which doesn't have metadata.) // Let's only do this on ExpensiveIntialization() when loading a book. //CurrentBook.Storage.CleanupUnusedImageFiles(); // But after saving, 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) { var msg = LocalizationManager.GetString("Errors.ProblemImportingPicture","Bloom had a problem importing this picture."); ErrorReport.NotifyUserOfProblem(e, msg+Environment.NewLine+e.Message); } }
protected void UpdateUrlAbsolute(GeckoDocument doc, GeckoHtmlElement ele) { string link = doc.Url.GetLeftPart(UriPartial.Authority); var eleColec = ele.GetElementsByTagName("IMG"); foreach (GeckoHtmlElement it in eleColec) { if (!it.GetAttribute("src").StartsWith("http://")) it.SetAttribute("src", link + it.GetAttribute("src")); } eleColec = ele.GetElementsByTagName("A"); foreach (GeckoHtmlElement it in eleColec) { if (!it.GetAttribute("href").StartsWith("http://")) it.SetAttribute("href", link + it.GetAttribute("href")); } }
private int GetXpathIndex(GeckoHtmlElement ele) { if (ele.Parent == null) return 0; int ind = 0, indEle = 0; string tagName = ele.TagName; GeckoNodeCollection elecol = ele.Parent.ChildNodes; foreach (GeckoNode it in elecol) { if (it.NodeName == tagName) { ind++; if (it.TextContent == ele.TextContent) indEle = ind; } } if (ind > 1) return indEle; return 0; }
public ElementProxy(GeckoHtmlElement element) { _geckoElement = element; }
/// <summary> /// Focus the element aElement. The element should be in the same document /// that the window is displaying. Pass null to blur the element, if any, /// that currently has focus, and focus the document. /// /// Cannot be accessed from unprivileged context (not content-accessible) /// Will throw a DOM security error if called without UniversalXPConnect /// privileges. /// /// @param aElement the element to focus /// /// Do not use this method. Just use element.focus if available or /// nsIFocusManager::SetFocus instead. /// /// </summary> public void Focus(GeckoHtmlElement aElement) { throw new NotImplementedException(); }
/// <summary> /// Method for testing nsStyleAnimation::ComputeDistance. /// /// Returns the distance between the two values as reported by /// nsStyleAnimation::ComputeDistance for the given element and /// property. /// </summary> public double ComputeAnimationDistance(GeckoHtmlElement element, string property, string value1, string value2) { throw new NotImplementedException(); }
/// <summary> /// Check if any ThebesLayer painting has been done for this element, /// clears the painted flags if they have. /// </summary> public bool CheckAndClearPaintedState(GeckoHtmlElement aElement) { throw new NotImplementedException(); }