Ejemplo n.º 1
0
 private void SaveCustomizedCssRules(GeckoStyleSheet userModifiedStyleSheet)
 {
     try
     {
         /* why are we bothering to walk through the rules instead of just copying the html of the style tag? Because that doesn't
          * actually get updated when the javascript edits the stylesheets of the page. Well, the <style> tag gets created, but
          * rules don't show up inside of it. So
          * this won't work: _editDom.GetElementsByTagName("head")[0].InnerText = userModifiedStyleSheet.OwnerNode.OuterHtml;
          */
         var styles = new StringBuilder();
         styles.AppendLine("<style title='userModifiedStyles' type='text/css'>");
         foreach (var cssRule in userModifiedStyleSheet.CssRules)
         {
             styles.AppendLine(cssRule.CssText);
         }
         styles.AppendLine("</style>");
         Debug.WriteLine("*User Modified Stylesheet in browser:" + styles);
         _pageEditDom.GetElementsByTagName("head")[0].InnerXml = styles.ToString();
     }
     catch (GeckoJavaScriptException jsex)
     {
         /* We are attempting to catch and ignore all JavaScript errors encountered here,
          * specifically addEventListener errors and JSError (BL-279, BL-355, et al.).
          */
         Logger.WriteEvent("GeckoJavaScriptException (" + jsex.Message + "). We're swallowing it but listing it here in the log.");
         Debug.Fail("GeckoJavaScriptException(" + jsex.Message + "). In Release version, this would not show.");
     }
 }
Ejemplo n.º 2
0
        public bool ShowPdf(string pdfFile)
        {
#if !__MonoCS__
            if (Settings.Default.UseAdobePdfViewer)
            {
                return(((AdobeReaderControl)_pdfViewerControl).ShowPdf(pdfFile));
            }
#endif

            var url = string.Format("{0}{1}?file=/bloom/{2}", Bloom.web.ServerBase.PathEndingInSlash,
                                    FileLocator.GetFileDistributedWithApplication("pdf/web/viewer.html"), pdfFile);

            var browser = ((GeckoWebBrowser)_pdfViewerControl);
            browser.Navigate(url);
            browser.DocumentCompleted += (sender, args) =>
            {
                // We want to suppress several of the buttons that the control normally shows.
                // It's nice if we don't have to modify the html and related files, because they are unzipped from a package we install
                // from a source I'm not sure we control, and installed into a directory we can't modify at runtime.
                // A workaround is to tweak the stylesheet to hide them. The actual buttons (and two menu items) are easily
                // hidden by ID.
                // Unfortunately we're getting rid of a complete group in the pull-down menu, which leaves an ugly pair of
                // adjacent separators. And the separators don't have IDs so we can't easily select just one to hide.
                // Fortunately there are no other divs in the parent (besides the separator) so we just hide the second one.
                // This is unfortunately rather fragile and may not do exactly what we want if the viewer.html file
                // defining the pdfjs viewer changes.
                GeckoStyleSheet stylesheet = browser.Document.StyleSheets.First();
                stylesheet.CssRules.Add("#openFile, #print, #download, #viewBookmark, #pageRotateCw, #pageRotateCcw, #secondaryToolbarButtonContainer div:nth-of-type(2)  {display: none}");
            };
            return(true);
        }
Ejemplo n.º 3
0
        public void GetCssRules_DoesNotThrowException()
        {
            GeckoStyleSheet styleSheet = _browser.Document.StyleSheets.First();

            GeckoStyleSheet.StyleRuleCollection cssRules = null;
            Assert.DoesNotThrow(() => { cssRules = styleSheet.CssRules; });
            Assert.DoesNotThrow(() => { cssRules.Insert(0, "#blanc { color: white }"); });
            Assert.DoesNotThrow(() => { cssRules.RemoveAt(0); });
            Assert.DoesNotThrow(() => { cssRules.Clear(); });
        }
        public void OwnerNode()
        {
            _browser.Navigate("www.google.com");
            _browser.NavigateFinishedNotifier.BlockUntilNavigationFinished();


            GeckoStyleSheet styleSheet = _browser.Document.StyleSheets.First();
            var             ownerNode  = styleSheet.OwnerNode;

            Assert.AreEqual("STYLE", ownerNode.NodeName);
        }
        public void CssRules_Enumerate_DoesNotThrowException()
        {
            _browser.Navigate("www.google.com");
            _browser.NavigateFinishedNotifier.BlockUntilNavigationFinished();


            GeckoStyleSheet styleSheet = _browser.Document.StyleSheets.First();

            foreach (var rule in styleSheet.CssRules)
            {
                Assert.NotNull(rule);
                Assert.DoesNotThrow(() => { var unused = rule.CssText; });
                Assert.DoesNotThrow(() => { var unused = rule.StyleCssText; });
            }
        }
Ejemplo n.º 6
0
 private void SaveCustomizedCssRules(GeckoStyleSheet userModifiedStyleSheet)
 {
     try
     {
         /* why are we bothering to walk through the rules instead of just copying the html of the style tag? Because that doesn't
          * actually get updated when the javascript edits the stylesheets of the page. Well, the <style> tag gets created, but
          * rules don't show up inside of it. So
          * this won't work: _editDom.GetElementsByTagName("head")[0].InnerText = userModifiedStyleSheet.OwnerNode.OuterHtml;
          */
         var styles = new StringBuilder();
         styles.AppendLine("<style title='userModifiedStyles' type='text/css'>");
         foreach (var cssRule in userModifiedStyleSheet.CssRules)
         {
             styles.AppendLine(cssRule.CssText);
         }
         styles.AppendLine("</style>");
         //Debug.WriteLine("*User Modified Stylesheet in browser:" + styles);
         _pageEditDom.GetElementsByTagName("head")[0].InnerXml = styles.ToString();
     }
     catch (GeckoJavaScriptException jsex)
     {
         /* We are attempting to catch and ignore all JavaScript errors encountered here,
          * specifically addEventListener errors and JSError (BL-279, BL-355, et al.).
          */
         Logger.WriteEvent("GeckoJavaScriptException (" + jsex.Message + "). We're swallowing it but listing it here in the log.");
         Debug.Fail("GeckoJavaScriptException(" + jsex.Message + "). In Release version, this would not show.");
     }
 }
Ejemplo n.º 7
0
        public bool ShowPdf(string pdfFile)
        {
            _pdfPath = pdfFile;
#if !__MonoCS__
            var arc = _pdfViewerControl as AdobeReaderControl;
            if (arc != null)             // We haven't yet had a problem displaying with Acrobat...
            {
                if (arc.ShowPdf(pdfFile))
                {
                    return(true);                    // success using acrobat
                }
                // Acrobat not working (probably not installed). Switch to using Gecko to display PDF.
                UpdatePdfViewer(new GeckoWebBrowser());
                // and continue to show it using that.
            }
#endif
            // Escaping the filename twice for characters like # is needed in order to get the
            // pdf filename through Geckofx/xulrunner to our local server on Linux.  This is to
            // prevent the filename from being cut short at the # character.  As far as I can
            // tell, Linux xulrunner strips one level of escaping on input, then before passing
            // the query on to the localhost server it truncates the query portion at the first
            // # it sees.  The localhost processor expects one level of encoding, and we deal
            // with having a # in the query (file path) there without any problem.  You may
            // regard this double escaping as a hack to get around the Linux xulrunner which
            // behaves differently than the Windows xulrunner.  It is an exception to the rule
            // of matching EscapeCharsForHttp() with UnescapeCharsForHttp().  See a comment in
            // https://jira.sil.org/browse/BL-951 for a description of the buggy program
            // behavior without this hack.
            var file = pdfFile;
            if (SIL.PlatformUtilities.Platform.IsUnix)
            {
                file = file.EscapeCharsForHttp().EscapeCharsForHttp();
            }
            var url = string.Format("{0}{1}?file=/bloom/{2}",
                                    Bloom.Api.ServerBase.ServerUrlWithBloomPrefixEndingInSlash,
                                    FileLocator.GetFileDistributedWithApplication("pdf/web/viewer.html"),
                                    file);

            var browser = ((GeckoWebBrowser)_pdfViewerControl);
            browser.Navigate(url);
            browser.DocumentCompleted += (sender, args) =>
            {
                // We want to suppress several of the buttons that the control normally shows.
                // It's nice if we don't have to modify the html and related files, because they are unzipped from a package we install
                // from a source I'm not sure we control, and installed into a directory we can't modify at runtime.
                // A workaround is to tweak the stylesheet to hide them. The actual buttons (and two menu items) are easily
                // hidden by ID.
                // Unfortunately we're getting rid of a complete group in the pull-down menu, which leaves an ugly pair of
                // adjacent separators. And the separators don't have IDs so we can't easily select just one to hide.
                // Fortunately there are no other divs in the parent (besides the separator) so we just hide the second one.
                // This is unfortunately rather fragile and may not do exactly what we want if the viewer.html file
                // defining the pdfjs viewer changes.
                GeckoStyleSheet stylesheet = browser.Document.StyleSheets.First();
                stylesheet.CssRules.Add("#toolbarViewerRight, #viewOutline, #viewAttachments, #viewThumbnail, #viewFind {display: none}");
                stylesheet.CssRules.Add("#previous, #next, #pageNumberLabel, #pageNumber, #numPages {display: none}");
                stylesheet.CssRules.Add("#toolbarViewerLeft .splitToolbarButtonSeparator {display: none}");

#if !__MonoCS__
                if (!_haveShownAdobeReaderRecommendation)
                {
                    _haveShownAdobeReaderRecommendation = true;
                    var message = LocalizationManager.GetString("PublishTab.Notifications.AdobeReaderRecommendation",
                                                                "This PDF viewer can be improved by installing the free Adobe Reader on this computer.");
                    RunJavaScript("toastr.remove();" +
                                  "toastr.options = { 'positionClass': 'toast-bottom-right','timeOut': '15000'};" +
                                  "toastr['info']('" + message + "')");
                }
#endif
            };
            return(true);
        }