void nsIDOMEventListener.HandleEvent(nsIDOMEvent e)
        {
            if (e == null)
            {
                return;
            }

            OnHandleDomEvent(DomEventArgs.Create(e));
        }
Exemplo n.º 2
0
        private void OnCutImage(DomEventArgs ge)
        {
            // NB: bloomImages.js contains code that prevents us arriving here
            // if our image is simply the placeholder flower
            if(!_model.CanChangeImages())
            {
                MessageBox.Show(
                    LocalizationManager.GetString("EditTab.CantPasteImageLocked",
                        "Sorry, this book is locked down so that images cannot be changed."));
                return;
            }

            var bookFolderPath = _model.CurrentBook.FolderPath;

            if(CopyImageToClipboard(ge, bookFolderPath)) // returns 'true' if successful
            {
                // Replace current image with placeHolder.png
                var path = Path.Combine(bookFolderPath, "placeHolder.png");
                using(var palasoImage = PalasoImage.FromFileRobustly(path))
                {
                    _model.ChangePicture(GetImageNode(ge), palasoImage, new NullProgress());
                }
            }
        }
Exemplo n.º 3
0
        private void OnChangeImage(DomEventArgs ge)
        {
            if(!_model.CanChangeImages())
            {
                MessageBox.Show(
                    LocalizationManager.GetString("EditTab.CantPasteImageLocked",
                        "Sorry, this book is locked down so that images cannot be changed."));
                return;
            }

            var imageElement = GetImageNode(ge);
            if(imageElement == null)
                return;
            string currentPath = HtmlDom.GetImageElementUrl(imageElement).NotEncoded;

            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.ToLowerInvariant().Contains("placeholder") && RobustFile.Exists(existingImagePath))
            {
                try
                {
                    imageInfo = PalasoImage.FromFileRobustly(existingImagePath);
                }
                catch(Exception e)
                {
                    Logger.WriteMinorEvent("Not able to load image for ImageToolboxDialog: " + e.Message);
                }
            }
            Logger.WriteEvent("Showing ImageToolboxDialog Editor Dialog");
            // Check memory for the benefit of developers.  The user won't see anything.
            SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(true, "about to choose picture", false);
            // Deep in the ImageToolboxDialog, when the user asks to see images from the ArtOfReading,
            // We need to use the Gecko version of the thumbnail viewer, since the original ListView
            // one has a sticky scroll bar in applications that are using Gecko.  On Linux, we also
            // need to use the Gecko version of the text box.  Except that the Gecko version of the
            // text box totally freezes the system if the user is using LinuxMint/cinnamon (ie, Wasta).
            // See https://jira.sil.org/browse/BL-1147.
            ThumbnailViewer.UseWebViewer = true;
            if(SIL.PlatformUtilities.Platform.IsUnix &&
               !(SIL.PlatformUtilities.Platform.IsWasta || SIL.PlatformUtilities.Platform.IsCinnamon))
            {
                TextInputBox.UseWebTextBox = true;
            }
            using(var dlg = new ImageToolboxDialog(imageInfo, null))
            {
                var searchLanguage = Settings.Default.ImageSearchLanguage;
                if(String.IsNullOrWhiteSpace(searchLanguage))
                {
                    // Pass in the current UI language.  We want only the main language part of the tag.
                    // (for example, "zh-Hans" should pass in as "zh".)
                    searchLanguage = Settings.Default.UserInterfaceLanguage;
                    var idx = searchLanguage.IndexOfAny(new char[] {'-', '_'});
                    if(idx > 0)
                        searchLanguage = searchLanguage.Substring(0, idx);
                }

                dlg.SearchLanguage = searchLanguage;
                var result = dlg.ShowDialog();
                // Check memory for the benefit of developers.  The user won't see anything.
                SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(true, "picture chosen or canceled", false);
                if(DialogResult.OK == result && dlg.ImageInfo != null)
                {
                    // var path = MakePngOrJpgTempFileForImage(dlg.ImageInfo.Image);
                    SaveChangedImage(imageElement, dlg.ImageInfo, "Bloom had a problem including that image");
                    // Warn the user if we're starting to use too much memory.
                    SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(true, "picture chosen and saved", true);
                }

                // If the user changed the search language for art of reading, remember their change. But if they didn't
                // touch it, don't remember it. Instead, let it continue to track the UI language so that if
                // they are new and just haven't got around to setting the main UI Language,
                // AOR can automatically start using that when they do.
                if(searchLanguage != dlg.SearchLanguage)
                {
                    //store their language selection even if they hit "cancel"
                    Settings.Default.ImageSearchLanguage = dlg.SearchLanguage;
                    Settings.Default.Save();
                }
            }
            Logger.WriteMinorEvent("Emerged from ImageToolboxDialog Editor Dialog");
            Cursor = Cursors.Default;
            imageInfo.Dispose(); // ensure memory doesn't leak
        }
Exemplo n.º 4
0
        private static bool CopyImageToClipboard(DomEventArgs ge, string bookFolderPath)
        {
            var imageElement = GetImageNode(ge);
            if(imageElement != null)
            {
                var url = HtmlDom.GetImageElementUrl(imageElement);
                if(String.IsNullOrEmpty(url.NotEncoded))
                    return false;

                var path = Path.Combine(bookFolderPath, url.NotEncoded);
                try
                {
                    using(var image = PalasoImage.FromFileRobustly(path))
                    {
                        PortableClipboard.CopyImageToClipboard(image);
                    }
                    return true;
                }
                catch (NotImplementedException)
                {
                    var msg = LocalizationManager.GetDynamicString("Bloom", "ImageToClipboard",
                        "Copying an image to the clipboard is not yet implemented in Bloom for Linux.",
                        "message for messagebox warning to user");
                    var header = LocalizationManager.GetDynamicString("Bloom", "NotImplemented",
                        "Not Yet Implemented", "header for messagebox warning to user");
                    MessageBox.Show(msg, header);
                }
                catch (ExternalException e)
                {
                    Logger.WriteEvent("CopyImageToClipboard -> ExternalException: " + e.Message);
                    var msg = LocalizationManager.GetDynamicString("Bloom", "EditTab.Image.CopyImageFailed",
                        "Bloom had problems using your computer's clipboard. Some other program may be interfering.") +
                        Environment.NewLine + Environment.NewLine +
                        LocalizationManager.GetDynamicString("Bloom", "EditTab.Image.TryRestart",
                        "Try closing other programs and restart your computer if necessary.");
                    MessageBox.Show(msg);
                }
                catch (Exception e)
                {
                    Debug.Fail(e.Message);
                    Logger.WriteEvent("CopyImageToClipboard:" + e.Message);
                }
            }
            return false;
        }
Exemplo n.º 5
0
 private void geckoWebBrowser1_DomContentChanged(object sender, DomEventArgs e)
 {
     BrowserChanged(sender, e);
 }
		/// <summary>Raises the <see cref="DOMContentLoadedEvent"/> event.</summary>
		/// <param name="e">The data for the event.</param>
		protected virtual void OnDOMContentLoaded(DomEventArgs e) {
			var evnt = (EventHandler<DomEventArgs>)Events[DOMContentLoadedEvent];
			if (evnt != null)
				evnt(this, e);
		}
		/// <summary>Raises the <see cref="DomBlur"/> event.</summary>
		/// <param name="e">The data for the event.</param>
		protected virtual void OnDomBlur(DomEventArgs e)
		{
			var evnt = (EventHandler<DomEventArgs>)Events[DomBlurEvent];
			if (evnt != null) evnt(this, e);
		}
Exemplo n.º 8
0
        /// <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.ToLowerInvariant().StartsWith("http")) //will cover https also
            {
                Process.Start(anchor.Href);
                eventArgs.Handled = true;
                return;
            }
            if (anchor.Href.ToLowerInvariant().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).ToLowerInvariant()))
                {
                    eventArgs.Handled = true;
                    Process.Start(new ProcessStartInfo()
                    {
                        FileName = path,
                        WorkingDirectory = workingDirectoryForFileLinks
                    });
                    return;
                }
                eventArgs.Handled = false; //let gecko handle it
                return;
            }
            else if (anchor.Href.ToLowerInvariant().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;
            }
        }
 /// <summary>Raises the <see cref="DomSubmit"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnDomSubmit(DomEventArgs e)
 {
     RaiseEvent(new RoutedEventArgs(DomSubmitEvent, e));
 }
Exemplo n.º 10
0
        protected virtual void OnHandleDomEvent(DomEventArgs e)
        {
            switch (e.Type)
            {
            case "keydown":
                OnDomKeyDown((DomKeyEventArgs)e);
                break;

            case "keyup":
                OnDomKeyUp((DomKeyEventArgs)e);
                break;

            case "keypress":
                OnDomKeyPress((DomKeyEventArgs)e);
                break;

            case "mousedown":
                OnDomMouseDown((DomMouseEventArgs)e);
                break;

            case "mouseup":
                OnDomMouseUp((DomMouseEventArgs)e);
                break;

            case "mousemove":
                OnDomMouseMove((DomMouseEventArgs)e);
                break;

            case "mouseover":
                OnDomMouseOver((DomMouseEventArgs)e);
                break;

            case "mouseout":
                OnDomMouseOut((DomMouseEventArgs)e);
                break;

            case "click":
                OnDomClick((DomMouseEventArgs)e);
                break;

            case "dblclick":
                OnDomDoubleClick((DomMouseEventArgs)e);
                break;

            case "submit":
                OnDomSubmit(e);
                break;

            case "compositionstart":
                OnDomCompositionStart(e);
                break;

            case "compositionend":
                OnDomCompositionEnd(e);
                break;

            case "contextmenu":
                OnDomContextMenu((DomMouseEventArgs)e);
                break;

            case "DOMMouseScroll":
                OnDomMouseScroll((DomMouseEventArgs)e);
                break;

            case "focus":
                OnDomFocus(e);
                break;

            case "blur":
                OnDomBlur(e);
                break;

            case "load":
                OnLoad(e);
                break;

            case "DOMContentLoaded":
                OnDOMContentLoaded(e);
                break;

            case "readystatechange":
                OnReadyStateChange(e);
                break;

            case "change":
                OnDomContentChanged(e);
                break;

            case "hashchange":
                OnHashChange((DomHashChangeEventArgs)e);
                break;

            case "dragstart":
                OnDomDragStart((DomDragEventArgs)e);
                break;

            case "dragenter":
                OnDomDragEnter((DomDragEventArgs)e);
                break;

            case "dragover":
                OnDomDragOver((DomDragEventArgs)e);
                break;

            case "dragleave":
                OnDomDragLeave((DomDragEventArgs)e);
                break;

            case "drag":
                OnDomDrag((DomDragEventArgs)e);
                break;

            case "drop":
                OnDomDrop((DomDragEventArgs)e);
                break;

            case "dragend":
                OnDomDragEnd((DomDragEventArgs)e);
                break;

            case "mozfullscreenchange":     //TODO: change to "fullscreenchange" after prefix removed
                OnFullscreenChange(e);
                break;
            }
            if (e is DomMessageEventArgs)
            {
                Action <string>     action;
                DomMessageEventArgs mea = (DomMessageEventArgs)e;
                if (_messageEventListeners.TryGetValue(e.Type, out action))
                {
                    action.Invoke(mea.Message);
                }
            }

            if (e != null && e.Cancelable && e.Handled)
            {
                e.PreventDefault();
            }
        }
Exemplo n.º 11
0
 /// <summary>Raises the <see cref="FullscreenChange"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnFullscreenChange(DomEventArgs e)
 {
     RaiseEvent(new RoutedEventArgs(FullscreenChangeEvent, e));
 }
Exemplo n.º 12
0
 /// <summary>Raises the <see cref="DomSubmit"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnDomSubmit(DomEventArgs e)
 {
     var evnt = (EventHandler<DomEventArgs>)_eventList[DomSubmitEvent];
     if (evnt != null) evnt(this, e);
 }
Exemplo n.º 13
0
 /// <summary>Raises the <see cref="DomDoubleClick"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnDomDoubleClick(DomEventArgs e)
 {
     var evnt = (EventHandler<DomEventArgs>)_eventList[DomDoubleClickEvent];
     if (evnt != null) evnt(this, e);
 }
Exemplo n.º 14
0
 /// <summary>Raises the <see cref="DomContentChanged"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnDomContentChanged(DomEventArgs e)
 {
     var evnt = (EventHandler<DomEventArgs>)_eventList[DomContentChangedEvent];
     if (evnt != null) evnt(this, e);
 }
Exemplo n.º 15
0
        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;
            }

            PalasoImage 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: Taglib# requires an extension that matches the file content type.
                if(ImageUtils.AppearsToBeJpeg(clipboardImage))
                {
                    if(ShouldBailOutBecauseUserAgreedNotToUseJpeg(clipboardImage))
                        return;
                    Logger.WriteMinorEvent("[Paste Image] Pasting jpeg image {0}", clipboardImage.OriginalFilePath);
                    _model.ChangePicture(imageElement, clipboardImage, new NullProgress());
                }
                else
                {
                    //At this point, it could be a bmp, tiff, or PNG. We want it to be a PNG.
                    if(clipboardImage.OriginalFilePath == null) //they pasted an image, not a path
                    {
                        Logger.WriteMinorEvent("[Paste Image] Pasting image directly from clipboard (e.g. screenshot)");
                        _model.ChangePicture(imageElement, clipboardImage, new NullProgress());
                    }
                    //they pasted a path to a png
                    else if(Path.GetExtension(clipboardImage.OriginalFilePath).ToLowerInvariant() == ".png")
                    {
                        Logger.WriteMinorEvent("[Paste Image] Pasting png file {0}", clipboardImage.OriginalFilePath);
                        _model.ChangePicture(imageElement, clipboardImage, new NullProgress());
                    }
                    else // they pasted a path to some other bitmap format
                    {
                        var pathToPngVersion = Path.Combine(Path.GetTempPath(),
                            Path.GetFileNameWithoutExtension(clipboardImage.FileName) + ".png");
                        Logger.WriteMinorEvent("[Paste Image] Saving {0} ({1}) as {2} and converting to PNG", clipboardImage.FileName,
                            clipboardImage.OriginalFilePath, pathToPngVersion);
                        if(RobustFile.Exists(pathToPngVersion))
                        {
                            RobustFile.Delete(pathToPngVersion);
                        }
                        using(var temp = TempFile.TrackExisting(pathToPngVersion))
                        {
                            SIL.IO.RobustIO.SaveImage(clipboardImage.Image, pathToPngVersion, ImageFormat.Png);

                            using(var palasoImage = PalasoImage.FromFileRobustly(temp.Path))
                            {
                                _model.ChangePicture(imageElement, palasoImage, new NullProgress());
                            }
                        }
                    }
                }
            }
            catch(Exception error)
            {
                SIL.Reporting.ErrorReport.NotifyUserOfProblem(error, "The program had trouble getting an image from the clipboard.");
            }
            finally
            {
                if(clipboardImage != null)
                    clipboardImage.Dispose();
            }
            Cursor = Cursors.Default;
        }
Exemplo n.º 16
0
 /// <summary>Raises the <see cref="DomCompositionEnd"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnDomCompositionEnd(DomEventArgs e)
 {
     RaiseEvent(new RoutedEventArgs(DomCompositionEndEvent, e));
 }
Exemplo n.º 17
0
        /// <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" ) ) );
            }
        }
Exemplo n.º 18
0
 /// <summary>Raises the <see cref="DomFocus"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnDomFocus(DomEventArgs e)
 {
     RaiseEvent(new RoutedEventArgs(DomFocusEvent, e));
 }
Exemplo n.º 19
0
 /// <summary>Raises the <see cref="DomCompositionStart"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnDomCompositionStart(DomEventArgs e)
 {
     var evnt = (EventHandler<DomEventArgs>)_eventList[DomCompositionStartEvent];
     if (evnt != null) evnt(this, e);
 }
Exemplo n.º 20
0
 /// <summary>Raises the <see cref="DomBlur"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnDomBlur(DomEventArgs e)
 {
     RaiseEvent(new RoutedEventArgs(DomBlurEvent, e));
 }
Exemplo n.º 21
0
		/// <summary>Raises the <see cref="LoadEvent"/> event.</summary>
		/// <param name="e">The data for the event.</param>
		protected virtual void OnLoad(DomEventArgs e)
		{
			var evnt = (EventHandler<DomEventArgs>)Events[LoadEvent];
			if (evnt != null) evnt(this, e);
		}
Exemplo n.º 22
0
 /// <summary>Raises the <see cref="LoadEvent"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnLoad(DomEventArgs e)
 {
     RaiseEvent(new RoutedEventArgs(LoadEvent, e));
 }
Exemplo n.º 23
0
		/// <summary>Raises the <see cref="ReadyStateChangeEvent"/> event.</summary>
		/// <param name="e">The data for the event.</param>
		protected virtual void OnReadyStateChange(DomEventArgs e) {
			var evnt = (EventHandler<DomEventArgs>)Events[ReadyStateChangeEvent];
			if (evnt != null)
				evnt(this, e);
		}
Exemplo n.º 24
0
 /// <summary>Raises the <see cref="DOMContentLoadedEvent"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnDOMContentLoaded(DomEventArgs e)
 {
     RaiseEvent(new RoutedEventArgs(DOMContentLoadedEvent, e));
 }
Exemplo n.º 25
0
        public DomEventArgs CreateEvent(string name)
        {
            var e = Doc.Value.CreateEvent(name);

            return(e.Wrap(Window, (x, y) => DomEventArgs.Create(y)));
        }
Exemplo n.º 26
0
 /// <summary>Raises the <see cref="ReadyStateChangeEvent"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnReadyStateChange(DomEventArgs e)
 {
     RaiseEvent(new RoutedEventArgs(ReadyStateChangeEvent, e));
 }
Exemplo n.º 27
0
        private static GeckoHtmlElement GetImageNode(DomEventArgs ge)
        {
            var target = (GeckoHtmlElement) ge.Target.CastToGeckoElement();
            var imageContainer = target.Parent;
            if(imageContainer.OuterHtml.Contains("background-image"))
                return imageContainer; // using a background-image instead of child <img> element
            foreach(var node in imageContainer.ChildNodes)
            {
                var imageElement = node as GeckoHtmlElement;
                if(imageElement != null && (imageElement.TagName.ToLowerInvariant() == "img" ||
                                            imageElement.OuterHtml.Contains("background-image")))
                {
                    return imageElement;
                }
            }

            Debug.Fail("Could not find image element");
            return null;
        }
Exemplo n.º 28
0
 /// <summary>Raises the <see cref="DomContentChanged"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnDomContentChanged(DomEventArgs e)
 {
     RaiseEvent(new RoutedEventArgs(DomContentChangedEvent, e));
 }
Exemplo n.º 29
0
        private void OnCopyImage(DomEventArgs ge)
        {
            // NB: bloomImages.js contains code that prevents us arriving here
            // if our image is simply the placeholder flower

            CopyImageToClipboard(ge, _model.CurrentBook.FolderPath);
        }
Exemplo n.º 30
0
        /// <summary>Performs actions on browser when DOM content loaded.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="domEventArgs">The dom event args.</param>
        private void BrowserOnDomContentLoaded(object sender, DomEventArgs domEventArgs)
        {
            if (!this.config.IsAlternativeWindow)
            {
                Task.Factory.StartNew(() =>
                {
                    Thread.Sleep(3000);
                    var posX = this.config.Position.PosX;
                    var posY = this.config.Position.PosY;
                    Cursor.Position = new Point(posX, posY);
                    Cursor.Position = new Point(posX + 50, posY + 50);
                });
            }

            this.Zoom(this.config.ZoomLevel, false);
            var document = ((GeckoWebBrowser)sender).Document;
            const char Seperator = '=';
            var splitIndex = document.Cookie.IndexOf(Seperator);
            if (document.Cookie.Contains(Seperator))
            {
                var name = document.Cookie.Substring(0, splitIndex);
                var value = document.Cookie.Substring(splitIndex + 1, document.Cookie.Length - name.Length - 1);
                this.DocumentCookies.Add(new Cookie(name, value, "/", document.Domain));
            }

            this.DomContentLoaded = true;
        }
Exemplo n.º 31
0
        private void OnEditImageMetdata(DomEventArgs ge)
        {
            var imageElement = GetImageNode(ge);
            if(imageElement == null)
                return;
            string fileName = HtmlDom.GetImageElementUrl(imageElement).NotEncoded;

            //enhance: this all could be done without loading the image into memory
            //could just deal with the metadata
            //e.g., var metadata = Metadata.FromFile(path)
            var path = Path.Combine(_model.CurrentBook.FolderPath, fileName);
            PalasoImage imageInfo = null;
            try
            {
                imageInfo = PalasoImage.FromFileRobustly(path);
            }
            catch(TagLib.CorruptFileException e)
            {
                ErrorReport.NotifyUserOfProblem(e,
                    "Bloom ran into a problem while trying to read the metadata portion of this image, " + path);
                return;
            }

            using(imageInfo)
            {
                var hasMetadata = !(imageInfo.Metadata == null || imageInfo.Metadata.IsEmpty);
                if(hasMetadata)
                {
                    // If we have metadata with an official collectionUri or we are translating a shell
                    // just give a summary of the metadata
                    var looksOfficial = !string.IsNullOrEmpty(imageInfo.Metadata.CollectionUri);
                    if(looksOfficial || !_model.CanEditCopyrightAndLicense)
                    {
                        MessageBox.Show(imageInfo.Metadata.GetSummaryParagraph("en"));
                        return;
                    }
                }
                else
                {
                    // If we don't have metadata, but we are translating a shell
                    // don't allow the metadata to be edited
                    if(!_model.CanEditCopyrightAndLicense)
                    {
                        MessageBox.Show(LocalizationManager.GetString("EditTab.CannotChangeCopyright",
                            "Sorry, the copyright and license for this book cannot be changed."));
                        return;
                    }
                }
                // Otherwise, bring up the dialog to edit the metadata
                Logger.WriteEvent("Showing Metadata Editor For Image");
                using(var dlg = new SIL.Windows.Forms.ClearShare.WinFormsUI.MetadataEditorDialog(imageInfo.Metadata))
                {
                    if(DialogResult.OK == dlg.ShowDialog())
                    {
                        imageInfo.Metadata = dlg.Metadata;
                        imageInfo.Metadata.StoreAsExemplar(Metadata.FileCategory.Image);
                        //update so any overlays on the image are brought up to data
                        PageEditingModel.UpdateMetadataAttributesOnImage(new ElementProxy(imageElement), imageInfo);
                        imageElement.Click(); //wake up javascript to update overlays
                        SaveChangedImage(imageElement, imageInfo, "Bloom had a problem updating the image metadata");

                        var answer =
                            MessageBox.Show(
                                LocalizationManager.GetString("EditTab.CopyImageIPMetadataQuestion",
                                    "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, MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button2);
                        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();
        }
Exemplo n.º 32
0
		protected virtual void OnHandleDomEvent(DomEventArgs e)
		{
			switch (e.Type)
			{
				case "keydown":
					OnDomKeyDown((DomKeyEventArgs)e);
					break;
				case "keyup":
					OnDomKeyUp((DomKeyEventArgs)e);
					break;
				case "keypress":
					OnDomKeyPress((DomKeyEventArgs)e);
					break;
				case "mousedown":
					OnDomMouseDown((DomMouseEventArgs)e);
					break;
				case "mouseup":
					OnDomMouseUp((DomMouseEventArgs)e);
					break;
				case "mousemove":
					OnDomMouseMove((DomMouseEventArgs)e);
					break;
				case "mouseover":
					OnDomMouseOver((DomMouseEventArgs)e);
					break;
				case "mouseout":
					OnDomMouseOut((DomMouseEventArgs)e);
					break;
				case "click":
					OnDomClick((DomMouseEventArgs)e);
					break;
				case "dblclick":
					OnDomDoubleClick((DomMouseEventArgs)e);
					break;
				case "submit":
					OnDomSubmit(e);
					break;
				case "compositionstart":
					OnDomCompositionStart(e);
					break;
				case "compositionend":
					OnDomCompositionEnd(e);
					break;
				case "contextmenu":
					OnDomContextMenu((DomMouseEventArgs)e);
					break;
				case "DOMMouseScroll":
					OnDomMouseScroll((DomMouseEventArgs)e);
					break;
				case "focus":
					OnDomFocus(e);
					break;
				case "blur":
					OnDomBlur(e);
					break;
				case "load":
					OnLoad(e);
					break;
				case "DOMContentLoaded":
					OnDOMContentLoaded(e);
					break;
				case "readystatechange":
					OnReadyStateChange(e);
					break;
				case "change":
					OnDomContentChanged(e);
					break;
				case "hashchange":
					OnHashChange((DomHashChangeEventArgs)e);
					break;
				case "dragstart":
					OnDomDragStart((DomDragEventArgs)e);
					break;
				case "dragenter":
					OnDomDragEnter((DomDragEventArgs)e);
					break;
				case "dragover":
					OnDomDragOver((DomDragEventArgs)e);
					break;
				case "dragleave":
					OnDomDragLeave((DomDragEventArgs)e);
					break;
				case "drag":
					OnDomDrag((DomDragEventArgs)e);
					break;
				case "drop":
					OnDomDrop((DomDragEventArgs)e);
					break;
				case "dragend":
					OnDomDragEnd((DomDragEventArgs)e);
					break;
				case "mozfullscreenchange": 
					OnFullscreenChange(e);
					break;
			}
			if (e is DomMessageEventArgs)
			{
				Action<string> action;
				DomMessageEventArgs mea = (DomMessageEventArgs)e;
				if (_messageEventListeners.TryGetValue(e.Type, out action))
				{
					action.Invoke(mea.Message);
				}
			}

			if (e != null && e.Cancelable && e.Handled)
				e.PreventDefault();
		}
Exemplo n.º 33
0
 public void browser_Load(object sender, Gecko.DomEventArgs e)
 {
     txtUrl.Text = e.Target.ToString();
 }
Exemplo n.º 34
0
		/// <summary>Raises the <see cref="FullscreenChange"/> event.</summary>
		/// <param name="e">The data for the event.</param>
		protected virtual void OnFullscreenChange(DomEventArgs e)
		{
			var evnt = (EventHandler<DomEventArgs>)Events[FullscreenChangeEvent];
			if (evnt != null) evnt(this, e);
		}
Exemplo n.º 35
0
 void browser_DomClick(object sender, DomEventArgs e)
 {
     GeckoElement clicked = e.Target.CastToGeckoElement();
     if (clicked.TagName == "INPUT" || clicked.TagName == "SELECT")
     {
         browser.WebBrowserFocus.Activate();
     }
     else
     {
         browser.WebBrowserFocus.Deactivate();
     }
 }
Exemplo n.º 36
0
		/// <summary>Raises the <see cref="DomCompositionEnd"/> event.</summary>
		/// <param name="e">The data for the event.</param>
		protected virtual void OnDomCompositionEnd(DomEventArgs e)
		{
			var evnt = (EventHandler<DomEventArgs>)Events[DomCompositionEndEvent];
			if (evnt != null) evnt(this, e);
		}
Exemplo n.º 37
0
        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);
        }
Exemplo n.º 38
0
        /// <summary>Performs actions on browser when DOM content loaded.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="domEventArgs">The dom event args.</param>
        private void BrowserOnDomContentLoaded(object sender, DomEventArgs domEventArgs)
        {
            if (!this.config.IsAlternativeWindow)
            {
                Task.Factory.StartNew(() =>
                {
                    Thread.Sleep(3000);
                    var posX = this.config.Position.PosX;
                    var posY = this.config.Position.PosY;
                    Cursor.Position = new Point(posX, posY);
                    Cursor.Position = new Point(posX + 50, posY + 50);
                });
            }

            this.Zoom(this.config.ZoomLevel, false);
            var document = ((GeckoWebBrowser)sender).Document;
            const char Seperator = '=';
            var splitIndex = document.Cookie.IndexOf(Seperator);
            if (document.Cookie.Contains(Seperator))
            {
                var name = document.Cookie.Substring(0, splitIndex);
                var value = document.Cookie.Substring(splitIndex + 1, document.Cookie.Length - name.Length - 1);
                this.DocumentCookies.Add(new Cookie(name, value, "/", document.Domain));
            }

            // Code for possible future work
            // if (!this.DomContentLoaded)
            // {
            //    // https://developer.mozilla.org/en-US/docs/Web/Events
            //    // https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
            //    ((GeckoWebBrowser)sender).AddMessageEventListener("message", this.Action, false);
            //    ((GeckoWebBrowser)sender).AddMessageEventListener("onmessage", this.Action, false);
            // }
            this.DomContentLoaded = true;
        }