private void WebBrowserOnLoad(object sender, DomEventArgs domEventArgs) { if (OnLoad != null) { OnLoad(sender, null); } }
public void Click_AfterMouseUpAndMouseDownEvents_ExpectedJavascriptHandlerRun() { browser.TestLoadHtml( @"<input type=""text"" id=""txtbox"" value=""text"" onmousedown=""this.value = 'mousedowned';"" onmouseup=""this.value = 'mouseuped';"" onclick=""this.value = 'clicked';""/>"); GeckoInputElement element = (GeckoInputElement)browser.Document.GetHtmlElementById("txtbox"); DomEventArgs ev = browser.Document.CreateEvent("MouseEvent"); var webEvent = new Event(browser.Window.DomWindow, ev.DomEvent as nsISupports); webEvent.InitEvent("mousedown", true, true); element.GetEventTarget().DispatchEvent(ev); Assert.AreEqual("mousedowned", element.Value); webEvent.InitEvent("mouseup", true, true); element.GetEventTarget().DispatchEvent(ev); Assert.AreEqual("mouseuped", element.Value); element.Click(); Assert.AreEqual("clicked", element.Value); }
/// <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"))); } }
protected override void OnDomFocus(object sender, DomEventArgs e) { if (!InFocus) { base.OnDomFocus(sender, e); OnGotFocus(null); } }
public void CreateEvent_VariousEvents_ExpectedWrapperTypesProduced(string eventName, Type expectedWrapperType) { browser.TestLoadHtml("hello world"); var eventArg = browser.Document.CreateEvent(eventName); Assert.NotNull(DomEventArgs.Create(eventArg.DomEvent)); Assert.AreEqual(expectedWrapperType, DomEventArgs.Create(eventArg.DomEvent).GetType()); }
private void OnEditImageMetdata(DomEventArgs ge) { var imageElement = GetImageNode(ge); if (imageElement == null) { return; } string fileName = imageElement.GetAttribute("src").Replace("%20", " "); var path = Path.Combine(_model.CurrentBook.FolderPath, fileName); using (var imageInfo = PalasoImage.FromFile(path)) { bool looksOfficial = imageInfo.Metadata != null && !string.IsNullOrEmpty(imageInfo.Metadata.CollectionUri); if (looksOfficial) { MessageBox.Show(imageInfo.Metadata.GetSummaryParagraph("en")); return; } Logger.WriteEvent("Showing Metadata Editor For Image"); using (var dlg = new Palaso.UI.WindowsForms.ClearShare.WinFormsUI.MetadataEditorDialog(imageInfo.Metadata)) { if (DialogResult.OK == dlg.ShowDialog()) { imageInfo.Metadata = dlg.Metadata; imageInfo.SaveUpdatedMetadataIfItMakesSense(); imageInfo.Metadata.StoreAsExemplar(Metadata.FileCategory.Image); //update so any overlays on the image are brough up to data var editor = new PageEditingModel(); editor.UpdateMetdataAttributesOnImgElement(imageElement, imageInfo); var answer = MessageBox.Show(LocalizationManager.GetString("EditTab.copyImageIPMetdataQuestion", "Copy this information to all other pictures in this book?", "get this after you edit the metadata of an image"), LocalizationManager.GetString("EditTab.titleOfCopyIPToWholeBooksDialog", "Picture Intellectual Property Information"), MessageBoxButtons.YesNo); if (answer == DialogResult.Yes) { Cursor = Cursors.WaitCursor; try { _model.CopyImageMetadataToWholeBook(dlg.Metadata); // There might be more than one image on this page. Update overlays. _model.RefreshDisplayOfCurrentPage(); } catch (Exception e) { ErrorReport.NotifyUserOfProblem(e, "There was a problem copying the metadata to all the images."); } Cursor = Cursors.Default; } } } } //_model.SaveNow(); //doesn't work: _browser1.WebBrowser.Reload(); }
protected override void OnDomBlur(object sender, DomEventArgs e) { if (_inFocus) { _inFocus = false; if (ListLostFocus != null) { ListLostFocus.Invoke(this, null); } } }
private void geckoWebBrowser1_ReadyStateChange(object sender, DomEventArgs e) { var accFormBox = geckoWebBrowser1.Document.GetElementById("account_form_box"); foreach (var accChild in accFormBox.ChildNodes) { if (accChild == null) { continue; } if (accChild.NodeType != NodeType.Element) { continue; } var joinRow = accChild as GeckoHtmlElement; if (!(joinRow?.ClassName?.Contains("join_form") ?? false)) { continue; } foreach (var jRowChild in joinRow.ChildNodes) { if (jRowChild == null) { continue; } if (jRowChild.NodeType != NodeType.Element) { continue; } var jForm = jRowChild as GeckoHtmlElement; if (jForm == null) { continue; } if (!(jForm.ClassName?.Contains("form_row") ?? false)) { continue; } if (jForm.ChildNodes .Where(x => x != null && x.NodeType == NodeType.Element) .Select(x => x as GeckoHtmlElement) .Any(x => x?.Id?.ToLower()?.Contains("captcha_entry") ?? false)) { continue; } joinRow.RemoveChild(jRowChild); } } }
protected virtual void OnDomBlur(object sender, DomEventArgs e) { if (_inFocus) { _inFocus = false; #if DEBUG //Debug.WriteLine("OnDomBlur"); #endif if (UserLostFocus != null) { UserLostFocus.Invoke(this, null); } } }
void OnBrowser_DomClick(object sender, DomEventArgs e) { Debug.Assert(!InvokeRequired); //this helps with a weird condition: make a new page, click in the text box, go over to another program, click in the box again. //it loses its focus. _browser.WebBrowserFocus.Activate(); //trying to help the disappearing cursor problem EventHandler handler = OnBrowserClick; if (handler != null) { handler(this, e); } }
protected override void OnDomFocus(object sender, DomEventArgs e) { var content = (GeckoUListElement)_browser.Document.GetElementById("main"); if (content != null) { // 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. if (!_inFocus) { _focusElement = (GeckoHtmlElement)content; base.OnDomFocus(sender, e); } } }
private void BrowserDomClick(object sender, DomEventArgs e) { try { if (sender == null || e == null || e.Target == null) { return; } var clicked = e.Target.CastToGeckoElement(); if (clicked == null) { return; } switch (_currentWindow) { case (int)CurrentWindow.Main: MainClick(clicked); break; case (int)CurrentWindow.Dependent: DependentClick(clicked); break; case (int)CurrentWindow.EnterNumber: EnterNumberClick(clicked); _timer.Change(TimerDelay, Timeout.Infinite); break; case (int)CurrentWindow.Pay: PayClick(clicked); break; case (int)CurrentWindow.Encashment: EncashmentClick(clicked); break; case (int)CurrentWindow.MakeEncashment: MakeEncashmentClick(clicked); break; } } catch (Exception exception) { Log.Error(exception); } }
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); }
public static void RemoveEventListener <T>(string domEvent, Action <T> listener, bool useCapture = false) { var domEventType = DomEventArgs.TypeOf(domEvent); var listenerType = typeof(T); if (listenerType != domEventType) { throw new InvalidOperationException($"Invalid listner type ({listenerType}) for this dom event type ({domEventType})"); } if (domEventType == typeof(DomKeyboardEventArgs)) { var action = (listener as Action <DomKeyboardEventArgs>) !; var ids = DomKeyboardEvent.RemoveListener(action, ElementName, useCapture ? TrueUseCapture : FalseUseCapture); BitButil.RemoveEventListener(ElementName, domEvent, ids, useCapture); } }
private void OnBrowser_DomClick(object sender, DomEventArgs ge) { if (this.DesignModeAtAll()) { return; } if (ge.Target == null) { return; } if (ge.Target.CastToGeckoElement().TagName == "A") { var url = ge.Target.CastToGeckoElement().GetAttribute("href"); System.Diagnostics.Process.Start(url); ge.Handled = true; //don't let the browser navigate itself } }
/// <summary> /// When you receive a OnBrowserClick and have determined that nothing was clicked on that the c# needs to pay attention to, /// pass it on to this method. It will either let the browser handle it normally, or redirect it to the operating system /// so that it can open the file or external website itself. /// </summary> public void HandleLinkClick(GeckoAnchorElement anchor, DomEventArgs eventArgs, string workingDirectoryForFileLinks) { Debug.Assert(!InvokeRequired); if (anchor.Href.ToLower().StartsWith("http")) //will cover https also { Process.Start(anchor.Href); eventArgs.Handled = true; return; } if (anchor.Href.ToLower().StartsWith("file")) //links to files are handled externally if we can tell they aren't html/javascript related { // TODO: at this point spaces in the file name will cause the link to fail. // That seems to be a problem in the DomEventArgs.Target.CastToGeckoElement() method. var href = anchor.Href; var path = href.Replace("file:///", ""); if (new List <string>(new[] { ".pdf", ".odt", ".doc", ".docx", ".txt" }).Contains(Path.GetExtension(path).ToLower())) { eventArgs.Handled = true; Process.Start(new ProcessStartInfo() { FileName = path, WorkingDirectory = workingDirectoryForFileLinks }); return; } eventArgs.Handled = false; //let gecko handle it return; } else if (anchor.Href.ToLower().StartsWith("mailto")) { eventArgs.Handled = true; Process.Start(anchor.Href); //let the system open the email program Debug.WriteLine("Opening email program " + anchor.Href); } else { ErrorReport.NotifyUserOfProblem("Bloom did not understand this link: " + anchor.Href); eventArgs.Handled = true; } }
private void OnSubmitClicked(object sender, DomEventArgs e) { Task.Run(() => { string login = string.Empty; string password = string.Empty; IDocument document = browser1.MainFrame.Document; login = ((IInputElement)document.GetElementById("login")).Value; password = ((IInputElement)document.GetElementById("password")).Value; Application.Current.Dispatcher.BeginInvoke(new Action(() => { MessageBox.Show(this, "Login: "******"\nPassword: "******"Data"); })); }); }
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(); } } }
public void DispatchEvent(DomEventArgs @event) { _target.Instance.DispatchEvent(@event.DomEvent); }
protected override void OnDomBlur(object sender, DomEventArgs e) { base.OnDomBlur(sender, e); OnLostFocus(null); }
private void geckoWebBrowser1_DomContentChanged(object sender, DomEventArgs e) { BrowserChanged(sender, e); }
private void geckoWebBrowser1_Load(object sender, DomEventArgs e) { textbox_navigate.Text = geckoWebBrowser1.Url.AbsoluteUri; label_statusbrowser.Text = geckoWebBrowser1.StatusText; // clickad(); }
/// <summary> /// GECKO BROWSER: Browser content has completely loaded. /// </summary> private void BrowserOnDomContentLoaded(object sender, DomEventArgs domEventArgs) { _messaging.OnConsumerReadyEvent(); }
private void OnPasteImage(DomEventArgs ge) { if (!_model.CanChangeImages()) { MessageBox.Show( LocalizationManager.GetString("EditTab.CantPasteImageLocked", "Sorry, this book is locked down so that images cannot be changed.")); return; } Image clipboardImage = null; try { clipboardImage = GetImageFromClipboard(); if (clipboardImage == null) { MessageBox.Show( LocalizationManager.GetString("EditTab.NoImageFoundOnClipboard", "Before you can paste an image, copy one onto your 'clipboard', from another program.")); return; } var target = (GeckoHtmlElement)ge.Target.CastToGeckoElement(); if (target.ClassName.Contains("licenseImage")) { return; } var imageElement = GetImageNode(ge); if (imageElement == null) { return; } Cursor = Cursors.WaitCursor; //nb: later, code closer to the the actual book folder will //improve this file name. Taglib# requires an extension that matches the file content type, however. using (var temp = TempFile.WithExtension("png")) { clipboardImage.Save(temp.Path, ImageFormat.Png); // using (var progressDialog = new ProgressDialogBackground()) // { // progressDialog.ShowAndDoWork((progress, args) => // { // ImageUpdater.CompressImage(temp.Path, progress); // }); // } using (var palasoImage = PalasoImage.FromFile(temp.Path)) { _model.ChangePicture(imageElement, palasoImage, new NullProgress()); } } } catch (Exception error) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "The program had trouble getting an image from the clipboard."); } finally { if (clipboardImage != null) { clipboardImage.Dispose(); } } Cursor = Cursors.Default; }
private void geckoWebBrowser1_DOMContentLoaded(object sender, DomEventArgs e) { progressbar_browser.Value = 0; }
private void OnChangeImage(DomEventArgs ge) { var imageElement = GetImageNode(ge); if (imageElement == null) { return; } string currentPath = imageElement.GetAttribute("src").Replace("%20", " "); if (!CheckIfLockedAndWarn(currentPath)) { return; } var target = (GeckoHtmlElement)ge.Target.CastToGeckoElement(); if (target.ClassName.Contains("licenseImage")) { return; } Cursor = Cursors.WaitCursor; var imageInfo = new PalasoImage(); var existingImagePath = Path.Combine(_model.CurrentBook.FolderPath, currentPath); //don't send the placeholder to the imagetoolbox... we get a better user experience if we admit we don't have an image yet. if (!currentPath.ToLower().Contains("placeholder") && File.Exists(existingImagePath)) { try { imageInfo = PalasoImage.FromFile(existingImagePath); } catch (Exception) { //todo: log this } } ; Logger.WriteEvent("Showing ImageToolboxDialog Editor Dialog"); using (var dlg = new ImageToolboxDialog(imageInfo, null)) { if (DialogResult.OK == dlg.ShowDialog()) { // var path = MakePngOrJpgTempFileForImage(dlg.ImageInfo.Image); try { _model.ChangePicture(imageElement, dlg.ImageInfo, new NullProgress()); } catch (System.IO.IOException error) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, error.Message); } catch (ApplicationException error) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, error.Message); } catch (Exception error) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "Bloom had a problem including that image"); } } } Logger.WriteMinorEvent("Emerged from ImageToolboxDialog Editor Dialog"); Cursor = Cursors.Default; }
private void UIActivePageElement_DomContentChanged(object sender, DomEventArgs e) { currentPage.Text = UIActivePageElement.DocumentTitle; }