public void Write(string parsedSourceCode,
            IList<Scope> scopes,
            IStyleSheet styleSheet,
            TextWriter textWriter)
        {
            var styleInsertions = new List<TextInsertion>();

            foreach (Scope scope in scopes)
                GetStyleInsertionsForCapturedStyle(scope, styleInsertions);

            styleInsertions.SortStable((x, y) => x.Index.CompareTo(y.Index));

            int offset = 0;

            foreach (TextInsertion styleInsertion in styleInsertions)
            {
                textWriter.Write(HttpUtility.HtmlEncode(parsedSourceCode.Substring(offset, styleInsertion.Index - offset)));
                if (string.IsNullOrEmpty(styleInsertion.Text))
                    BuildSpanForCapturedStyle(styleInsertion.Scope, styleSheet, textWriter);
                else
                    textWriter.Write(styleInsertion.Text);
                offset = styleInsertion.Index;
            }

            textWriter.Write(HttpUtility.HtmlEncode(parsedSourceCode.Substring(offset)));
        }
        public override Task LoadAsync(IConfiguration configuration, IResourceLoader loader)
        {
            var link = Link;
            var request = link.CreateRequestFor(Url);
            var download = loader.DownloadAsync(request);
            SetDownload(download);

            return link.ProcessResponse(download, response =>
            {
                var type = link.Type ?? MimeTypeNames.Css;
                var engine = configuration.GetStyleEngine(type);

                if (engine != null)
                {
                    var options = new StyleOptions
                    {
                        Element = link,
                        IsDisabled = link.IsDisabled,
                        IsAlternate = link.RelationList.Contains(Keywords.Alternate),
                        Configuration = configuration
                    };

                    _sheet = engine.ParseStylesheet(response, options);
                    _sheet.Media.MediaText = link.Media ?? String.Empty;
                }
            });
        }
        /// <summary>
        /// Colorizes source code using the specified language, formatter, and 
        /// style sheet.
        /// </summary>
        /// <param name="sourceCode">The source code to colorize.</param>
        /// <param name="language">The language to use to colorize the source 
        /// code.</param>
        /// <param name="formatter">The formatter to use to colorize the source 
        /// code.</param>
        /// <param name="styleSheet">The style sheet to use to colorize the 
        /// source code.</param>
        public void Colorize(string sourceCode, ILanguage language, IFormatter formatter, IStyleSheet styleSheet)
        {
            Guard.ArgNotNull(language, "language");
            Guard.ArgNotNull(formatter, "formatter");
            Guard.ArgNotNull(styleSheet, "styleSheet");

            languageParser.Parse(sourceCode, language, (parsedSourceCode, captures) => formatter.Write(parsedSourceCode, captures, styleSheet));
        }
    public void Write(string parsedSourceCode, IList<Scope> scopes, IStyleSheet styleSheet)
    {
      var styleInsertions = new List<TextInsertion>();

      int offset = 0;
      bool lastScopeWasComment = false;

      foreach (Scope scope in scopes)
      {
        string t = parsedSourceCode.Substring(scope.Index, scope.Length);
        //                    .Replace("\r\n", "\n")
        //                    .Replace("\r", "\n");
        offset = scope.Index + scope.Length;
        if (!string.IsNullOrEmpty(t))
        {
          Inline run = new Run { Text = t.Replace("\r", string.Empty) };
          if (scope != null && styleSheet.Styles.Contains(scope.Name))
          {
            Style style = styleSheet.Styles[scope.Name];
            run.Foreground = new SolidColorBrush(style.Foreground);
            run.FontWeight = style.FontWeight;
          }
          lastScopeWasComment = (scope != null && scope.Name == "Comment");
          _text.Inlines.Add(run);
        }
      }
      string left = parsedSourceCode
          .Substring(offset)
          .Replace("\r\n", "\n")
          .Replace("\r", "\n");
      if (!string.IsNullOrEmpty(left))
      {
        for (int i = left.IndexOf("\n"); i >= 0; i = left.IndexOf("\n"))
        {
          if (i > 0)
          {
            Inline tby = new Run { Text = left.Substring(0, i) };
            _text.Inlines.Add(tby);
          }

          left = left.Substring(i + 1);
          if (lastScopeWasComment)
          {
            lastScopeWasComment = false;
          }
          else
          {
            _text.Inlines.Add(new LineBreak());
          }
        }

        if (!string.IsNullOrEmpty(left))
        {
          Inline nrun = new Run { Text = left };
          _text.Inlines.Add(nrun);
        }
      }
    }
        public void WriteHeader(IStyleSheet styleSheet,
            TextWriter textWriter)
        {
            Guard.ArgNotNull(styleSheet, "styleSheet");
            Guard.ArgNotNull(textWriter, "textWriter");

            WriteHeaderDivStart(styleSheet, textWriter);
            WriteHeaderPreStart(textWriter);
            textWriter.WriteLine();
        }
 public static void ReloadBackgroundImage(this IStyleHelper helper, IStyleSheet styleSheet, IBound bound, Control control)
 {
     IBackgroundImage image;
     if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path))
     {
         var imageCache = styleSheet.GetCache<ImageCache>();
         using (BitmapDrawable background = imageCache.GetImage(image.Path, bound.Width, bound.Height))
             control.SetBackground(background);
     }
 }
        public void WriteFooter(IStyleSheet styleSheet,
            ILanguage language,
            TextWriter textWriter)
        {
            Guard.ArgNotNull(styleSheet, "styleSheet");
            Guard.ArgNotNull(textWriter, "textWriter");

            textWriter.WriteLine();
            WriteHeaderPreEnd(textWriter);
            WriteHeaderDivEnd(textWriter);
        }
        protected override IBound LayoutChildren(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
        {
            float[] borders;
            IBound bound = ControlsContext.Current.CreateLayoutBehaviour(stylesheet, this)
                .Vertical(ContainerBehaviour.Childrens, styleBound, maxBound, out borders, true);

            if (ContainerBehaviour.Childrens.Count > 0)
                Behavour.SetBorders(borders);

            Behavour.ScrollingArea = bound.Height;
            return bound;
        }
Beispiel #9
0
        public string Colorize(string sourceCode, ILanguage language, IFormatter formatter, IStyleSheet styleSheet)
        {
            var buffer = new StringBuilder(sourceCode.Length * 2);

            using (TextWriter writer = new StringWriter(buffer))
            {
                Colorize(sourceCode, language, formatter, styleSheet, writer);

                writer.Flush();
            }

            return buffer.ToString();
        }
        private static void BuildSpanForCapturedStyle(Scope scope,
            IStyleSheet styleSheet,
            TextWriter writer)
        {
            string cssClassName = "";

            if (styleSheet.Styles.Contains(scope.Name))
            {
                Style style = styleSheet.Styles[scope.Name];

                cssClassName = style.CssClassName;
            }

            WriteElementStart("span", cssClassName, writer);
        }
        public static bool BackgroundChanged(this IStyleHelper helper
            , IStyleSheet styleSheet, IBound bound, out Drawable background, bool whithoutImage = false)
        {
            if (!whithoutImage)
            {
                IBackgroundImage image;
                if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path))
                {
                    background = styleSheet.GetCache<ImageCache>().GetImage(image.Path, bound.Width, bound.Height);
                    return true;
                }

                // if control has background image, we have to ignore background color
                if (!string.IsNullOrWhiteSpace(image.Path))
                {
                    background = null;
                    return false;
                }
            }

            IBackgroundColor backgroundColor;
            IBorderStyle borderStyle;
            IBorderWidth borderWidth;
            IBorderColor borderColor;
            IBorderRadius borderRadius;
            if (helper.TryGet(out backgroundColor) | helper.TryGet(out borderStyle) | helper.TryGet(out borderWidth)
                | helper.TryGet(out borderColor) | helper.TryGet(out borderRadius))
            {
                if (borderStyle.Style == BorderStyleValues.Solid)
                {
                    var shape = new GradientDrawable();
                    var width = (int)Math.Round(borderWidth.Value);
                    Color color = borderColor.ToColorOrTransparent();

                    shape.SetShape(ShapeType.Rectangle);
                    shape.SetColor(backgroundColor.ToColorOrTransparent());
                    shape.SetCornerRadius(borderRadius.Radius);
                    shape.SetStroke(width, color);
                    background = shape;
                }
                else
                    background = new ColorDrawable(backgroundColor.ToColorOrTransparent());
                return true;
            }

            background = null;
            return false;
        }
        private static void BuildSpanForCapturedStyle(Scope scope,
            IStyleSheet styleSheet,
            TextWriter writer)
        {
            Color foreground = Color.Empty;
            Color background = Color.Empty;

            if (styleSheet.Styles.Contains(scope.Name)) {
                Style style = styleSheet.Styles[scope.Name];

                foreground = style.Foreground;
                background = style.Background;
            }

            WriteElementStart("span", foreground, background, writer);
        }
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            // https://developer.chrome.com/multidevice/webview/pixelperfect

            //Native.css.screen
            // jsc, haw can i do conditional css?

            // Uncaught SyntaxError: Failed to execute 'insertRule' on 'CSSStyleSheet': Failed to parse the rule 'html@media screen and (min-width: 1000px){/**/}'.

            //Native.css["@media screen and (min-width: 1000px)"].style.backgroundColor = "yellow";

            // Uncaught SyntaxError: Failed to execute 'insertRule' on 'CSSMediaRule': the rule 'and (min-width: 1000px)  { /**/ }' is invalid and cannot be parsed. 


            //var s = new CSSStyleSheet();
            var s = new IStyleSheet();

            // android webview does not respect this

                // how does it work with shadowdom?
            s.Owner.media = "screen and (min-width: 1000px)";

            // jsc should have an orientation example for it
            // how would this look like as LINQ expression?
            // css + linq to sql knowledge needed
            s[IHTMLElement.HTMLElementEnum.body].style.backgroundColor = "yellow";

            Native.body.css.before.With(
                async ss =>
                {
                    while (true)
                    {
                        ss.contentText = new { Native.window.Width }.ToString();

                        await Native.window.async.onresize;

                    }
                }
            );
            //IStyleSheet.all[CSSMediaTypes.screen]["and (min-width: 1000px) "].style.backgroundColor = "yellow";


        }
        private static void BuildSpanForCapturedStyle(Scope scope,
            IStyleSheet styleSheet,
            TextWriter writer)
        {
            Color foreground = Color.Empty;
            Color background = Color.Empty;
            bool italic = false;
            bool bold = false;

            if (styleSheet.Styles.Contains(scope.Name))
            {
                Style style = styleSheet.Styles[scope.Name];

                foreground = style.Foreground;
                background = style.Background;
                italic = style.Italic;
                bold = style.Bold;
            }

            WriteElementStart(writer, "span", foreground, background, italic, bold);
        }
Beispiel #15
0
 public LayoutBehaviour(IStyleSheet stylesheet, ILayoutable container)
 {
     _stylesheet = stylesheet;
     _container  = container;
 }
Beispiel #16
0
        public void Write(string parsedSourceCode,
                          IList <Scope> scopes,
                          IStyleSheet styleSheet)
        {
            var styleInsertions = new List <TextInsertion>();

            int  offset = 0;
            bool lastScopeWasComment = false;
            int  lastoffset          = 0;

            foreach (Scope scope in scopes)
            {
                if (lastoffset < scope.Index)
                {
                    string space = parsedSourceCode.Substring(lastoffset, scope.Index - lastoffset);
                    Inline run   = new Run {
                        Text = space.Replace("\r", string.Empty)
                    };
                    _text.Inlines.Add(run);
                }
                string t = parsedSourceCode.Substring(scope.Index, scope.Length);
                lastoffset = scope.Index + scope.Length;
//                    .Replace("\r\n", "\n")
//                    .Replace("\r", "\n");
                offset = scope.Index + scope.Length;
                if (!string.IsNullOrEmpty(t))
                {
                    Inline run = new Run {
                        Text = t.Replace("\r", string.Empty)
                    };
                    if (scope != null && styleSheet.Styles.Contains(scope.Name))
                    {
                        Style style = styleSheet.Styles[scope.Name];
                        run.Foreground = new SolidColorBrush(style.Foreground);
                    }
                    lastScopeWasComment = (scope != null && scope.Name == "Comment");
                    _text.Inlines.Add(run);
                }
            }
            string left = parsedSourceCode
                          .Substring(offset)
                          .Replace("\r\n", "\n")
                          .Replace("\r", "\n");

            if (!string.IsNullOrEmpty(left))
            {
                for (int i = left.IndexOf("\n"); i >= 0; i = left.IndexOf("\n"))
                {
                    if (i > 0)
                    {
                        Inline tby = new Run {
                            Text = left.Substring(0, i)
                        };
                        _text.Inlines.Add(tby);
                    }

                    left = left.Substring(i + 1);
                    if (lastScopeWasComment)
                    {
                        lastScopeWasComment = false;
                    }
                    else
                    {
                        _text.Inlines.Add(new LineBreak());
                    }
                }

                if (!string.IsNullOrEmpty(left))
                {
                    Inline nrun = new Run {
                        Text = left
                    };
                    _text.Inlines.Add(nrun);
                }
            }
        }
Beispiel #17
0
        public void Write(string parsedSourceCode,
                          IList <Scope> scopes,
                          IStyleSheet styleSheet)
        {
            var styleInsertions = new List <TextInsertion>();

            int offset = 0;

            foreach (Scope scope in scopes)
            {
                string t = parsedSourceCode.Substring(
                    scope.Index,
                    scope.Length);
                offset = scope.Index + scope.Length;
                if (!string.IsNullOrEmpty(t))
                {
                    UIElement e;
                    TextBlock tb = CreateText(t);
                    e = tb;
                    if (scope != null && styleSheet.Styles.Contains(scope.Name))
                    {
                        Style style = styleSheet.Styles[scope.Name];
                        tb.Foreground = new SolidColorBrush(style.Foreground);

                        //if (scope.Name == "Comment")
                        //{
                        //    tb.Margin = new Thickness(0);
                        //    Border b = new Border
                        //    {
                        //        Margin = new Thickness(-1, -1, -1, 1),
                        //        Background = new SolidColorBrush(Colors.Yellow),
                        //    };
                        //    b.Child = tb;
                        //    e = b;
                        //}
                    }

                    _currentLine.Children.Add(e);
                }
            }

            string left = parsedSourceCode.Substring(offset).Replace("\r\n", "\n");

            if (!string.IsNullOrEmpty(left))
            {
                for (int i = left.IndexOf("\n"); i >= 0; i = left.IndexOf("\n"))
                {
                    if (i > 0)
                    {
                        TextBlock tby = CreateText(left.Substring(0, i));
                        _currentLine.Children.Add(tby);
                    }

                    left = left.Substring(i + 1);
                    StartNewLine();
                }

                if (!string.IsNullOrEmpty(left))
                {
                    _currentLine.Children.Add(CreateText(left));
                }
            }
        }
Beispiel #18
0
        // Public members

        public ToolStripRenderer(IStyleSheet styleSheet, IStyleRenderer styleRenderer)
        {
            this.styleSheet    = styleSheet;
            this.styleRenderer = styleRenderer;
        }
Beispiel #19
0
 public VisualsSceneLayout(Func <IGraphScene <TItem, TEdge> > handler, IStyleSheet stylesheet)
     : base(handler, stylesheet)
 {
     this.EdgeRouter = new NearestAnchorRouter <TItem, TEdge>();
 }
Beispiel #20
0
        // Public members

        public ListViewRenderer(IStyleSheet styleSheet, IStyleRenderer styleRenderer)
        {
            this.styleSheet    = styleSheet;
            this.styleRenderer = styleRenderer;
        }
Beispiel #21
0
        private static void BuildSpanForCapturedStyle(Scope scope,
                                                        IStyleSheet styleSheet)
        {
            Color foreground = Colors.Black;
            Color background = Colors.Transparent;

            if (styleSheet.Styles.Contains(scope.Name))
            {
                Style style = styleSheet.Styles[scope.Name];

                foreground = style.Foreground;
                background = style.Background;
            }

            WriteElementStart("span", foreground, background);
        }
Beispiel #22
0
        public void Write(string parsedSourceCode,
                          IList<Scope> scopes,
                          IStyleSheet styleSheet)
        {
            var styleInsertions = new List<TextInsertion>();

            int offset = 0;

            foreach (Scope scope in scopes)
            {
                string t = parsedSourceCode.Substring(
                    scope.Index,
                    scope.Length);
                offset = scope.Index + scope.Length;
                if (!string.IsNullOrEmpty(t))
                {
                    UIElement e;
                    TextBlock tb = CreateText(t);
                    e = tb;
                    if (scope != null && styleSheet.Styles.Contains(scope.Name))
                    {
                        Style style = styleSheet.Styles[scope.Name];
                        tb.Foreground = new SolidColorBrush(style.Foreground);

                        //if (scope.Name == "Comment")
                        //{
                        //    tb.Margin = new Thickness(0);
                        //    Border b = new Border
                        //    {
                        //        Margin = new Thickness(-1, -1, -1, 1),
                        //        Background = new SolidColorBrush(Colors.Yellow),
                        //    };
                        //    b.Child = tb;
                        //    e = b;
                        //}
                    }

                    _currentLine.Children.Add(e);
                }

            }

            string left = parsedSourceCode.Substring(offset).Replace("\r\n", "\n");
            if (!string.IsNullOrEmpty(left))
            {
                for (int i = left.IndexOf("\n"); i >= 0; i = left.IndexOf("\n"))
                {
                    if (i > 0)
                    {
                        TextBlock tby = CreateText(left.Substring(0, i));
                        _currentLine.Children.Add(tby);
                    }

                    left = left.Substring(i + 1);
                    StartNewLine();
                }

                if (!string.IsNullOrEmpty(left))
                {
                    _currentLine.Children.Add(CreateText(left));
                }
            }
        }
Beispiel #23
0
        public string Colorize(string sourceCode, ILanguage language, IFormatter formatter, IStyleSheet styleSheet)
        {
            var buffer = new StringBuilder(sourceCode.Length * 2);

            using (TextWriter writer = new StringWriter(buffer))
            {
                Colorize(sourceCode, language, formatter, styleSheet, writer);

                writer.Flush();
            }

            return(buffer.ToString());
        }
Beispiel #24
0
 public void WriteFooter(IStyleSheet styleSheet, ILanguage language, TextWriter textWriter)
 {
     textWriter.Write(builder.ToString());
 }
Beispiel #25
0
 public void WriteHeader(IStyleSheet styleSheet, ILanguage language, TextWriter textWriter)
 {
 }
Beispiel #26
0
        public static Action <Context> Render(IShape shape, Size size, UiState uiState, IStyleSheet styleSheet)
        {
            if (styleSheet == null)
            {
                styleSheet = Registry.Pooled <StyleSheets> ().DefaultStyleSheet;
            }

            shape.Size = size;
            var layout  = new ShapeLayout(styleSheet);
            var painter = layout.GetPainter(shape.GetType());

            painter.Style = layout.GetStyle(shape, uiState);
            painter.Shape = shape;
            return(ctx => painter.Render(new ContextSurface {
                Context = ctx
            }));
        }
Beispiel #27
0
 protected abstract IBound LayoutChildren(IStyleSheet stylesheet, IBound styleBound, IBound maxBound);
Beispiel #28
0
 void UpdateSheet()
 {
     if (_sheet != null)
         _sheet = CreateSheet();
 }
Beispiel #29
0
 protected override IBound LayoutChildren(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
 {
     if (ContainerBehaviour.Childrens.Count == 1)
         return ControlsContext.Current.CreateLayoutBehaviour(stylesheet, this).Screen(ContainerBehaviour.Childrens[0], maxBound);
     return styleBound;
 }
Beispiel #30
0
        private static void WriteHeaderDivStart(IStyleSheet styleSheet)
        {
            Color foreground = Colors.Transparent;
            Color background = Colors.Transparent;

            if (styleSheet.Styles.Contains(ScopeName.PlainText))
            {
                Style plainTextStyle = styleSheet.Styles[ScopeName.PlainText];

                foreground = plainTextStyle.Foreground;
                background = plainTextStyle.Background;
            }

            WriteElementStart("div", foreground, background);
        }
        void UpdateType(String value)
        {
            if (_current == null || _current.IsFaulted || _current.IsCompleted == false || _current.Result == null)
                return;

            var type = value ?? MimeTypes.Css;
            var config = Owner.Options;
            var engine = config.GetStyleEngine(type);

            if (engine != null && RelationList.Contains(Keywords.StyleSheet))
            {
                var options = new StyleOptions
                {
                    Element = this,
                    Title = Title,
                    IsDisabled = IsDisabled,
                    IsAlternate = RelationList.Contains(Keywords.Alternate),
                    Configuration = config
                };

                using (var response = _current.Result)
                {
                    try { _sheet = engine.ParseStylesheet(response, options); }
                    catch { /* Do not care here */ }
                }
            }
        }
Beispiel #32
0
 // ReSharper disable once RedundantOverridenMember
 protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
 {
     // nope
     return(base.Apply(stylesheet, styleBound, maxBound));
 }
        //public const string Alias = "Class1";
        //public const string DefaultData = "Class1Data";


        /// <summary>
        /// Creates a new control
        /// </summary>
        /// <param name="DataElement">The hidden data element</param>
        public SimpleRollover()
        {
            // wallpapers at http://labnol.blogspot.com/2006/11/download-windows-vista-wallpapers.html

            // * broken at the moment
            #region AnimateCharacterColors
            System.Func<string, INode> AnimateCharacterColors =
                (text) =>
                {
                    var s = new IHTMLSpan();

                    var l = new global::System.Collections.Generic.List<IHTMLSpan>();

                    foreach (char c in text)
                    {
                        var y = new string(c, 1);
                        var x = new IHTMLSpan(y);

                        if (y == " ")
                        {
                            s.appendChild(" ");
                        }
                        else
                        {
                            l.Add(x);


                            s.appendChild(x);
                        }


                    }



                    new Timer(
                        t =>
                        {
                            var len = l.Count + 40;

                            if (t.Counter % len < l.Count)
                            {
                                if (t.Counter % (len * 2) < l.Count)
                                {
                                    l[t.Counter % len].style.visibility = IStyle.VisibilityEnum.hidden;
                                }
                                else
                                {
                                    l[t.Counter % len].style.visibility = IStyle.VisibilityEnum.visible;
                                }
                            }



                        }, 6000, 200);


                    return s;
                };
            #endregion
            // */

            var u = new IHTMLDiv();

            //u.style.backgroundColor = Color.Green;
            u.style.position = IStyle.PositionEnum.absolute;
            u.style.left = "0";
            u.style.top = "0";
            u.style.height = "100%";
            u.style.width = "100%";
            u.style.overflow = IStyle.OverflowEnum.auto;

            var styles = new XStyles
            {
                dark = new IStyleSheet(),
                light = new IStyleSheet(),
                switchbutton = new IHTMLAnchor("", "day/night"),
                counter = 0
            };



            styles.switchbutton.onclick +=
                ev =>
                {
                    ev.PreventDefault();

                    styles.counter++;


                    if (styles.counter % 2 == 1)
                    {
                        styles.dark.disabled = false;
                        styles.light.disabled = true;
                    }
                    else
                    {
                        styles.dark.disabled = true;
                        styles.light.disabled = false;
                    }
                };


            var ad = new IHTMLDiv(
                            new IHTMLSpan(
                                 AnimateCharacterColors(
                                "this application was written in c# and then translated to javascript by jsc to run in your browser"
                                 )
                            ),
                            new IHTMLAnchor("http://zproxy.wordpress.com", "visit blog"),
                            new IHTMLAnchor("http://jsc.sf.net", "get more examples"),
                            styles.switchbutton
                         )
                         {
                             className = "ad1"
                         };

            u.appendChild(ad);

            var sheet = new IStyleSheet();

            sheet.AddRule(".ad1",
                r =>
                {
                    r.style.marginTop = "1em";
                    r.style.color = Color.White;
                    r.style.fontFamily = IStyle.FontFamilyEnum.Verdana;
                }
            );


            sheet.AddRule(".ad1 > *",
                r =>
                {
                    r.style.padding = "1em";

                    r.style.marginTop = "1em";
                }
            );

            sheet.AddRule(".ad1 > span",
                r =>
                {
                    r.style.Float = IStyle.FloatEnum.right;
                }
            );

            sheet.AddRule(".ad1 > a",
                r =>
                {
                    r.style.Float = IStyle.FloatEnum.left;
                    r.style.color = Color.White;

                    r.style.textDecoration = "none";
                }
            );

            sheet.AddRule(".ad1 a:hover",
                r =>
                {
                    r.style.color = Color.Yellow;
                }
            );



            sheet.AddRule("html",
                r =>
                {

                    r.style.overflow = IStyle.OverflowEnum.hidden;
                }
            );

            sheet.AddRule("body",
                r =>
                {
                    r.style.overflow = IStyle.OverflowEnum.hidden;

                    r.style.padding = "0";
                    r.style.margin = "0";

                    //r.style.backgroundImage = "url(assets/vista.jpg)";

                }
            );


            styles.dark.AddRule("body").style.backgroundColor = JSColor.Black;
            styles.dark.AddRule("body").style.backgroundPosition = "center top";

            styles.light.AddRule("body").style.backgroundColor = JSColor.Black;
            styles.light.AddRule("body").style.backgroundPosition = "center top";


            new global::SimpleRollover.HTML.Images.FromAssets.vistax().ToBackground(
                styles.dark.AddRule("body").style, false
            );

            new global::SimpleRollover.HTML.Images.FromAssets.vista().ToBackground(
                styles.dark.AddRule(".effect1").style
            );

            styles.dark.AddRule(".moon1").style.backgroundColor = Color.Yellow;

            new global::SimpleRollover.HTML.Images.FromAssets.vista().ToBackground(
                styles.light.AddRule("body").style, false
            );

            new global::SimpleRollover.HTML.Images.FromAssets.vistax().ToBackground(
                 styles.light.AddRule(".effect1").style
            );
            styles.light.AddRule(".moon1").style.backgroundColor = Color.Red;


            sheet.AddRule(".special1",
                r =>
                {
                    r.style.background = "none";
                    r.style.border = "0";
                    r.style.width = "100%";
                    r.style.marginTop = "4em";


                }
            );

            sheet.AddRule(".content1",
                r =>
                {
                    r.style.backgroundColor = Color.White;

                    r.style.padding = "1em";
                    r.style.marginLeft = "4em";
                    r.style.marginRight = "4em";
                    r.style.Opacity = 0.5;
                    r.style.border = "1px solid gray";
                }
            );

            sheet.AddRule(".special1 img", "border: 0", 0);
            sheet.AddRule(".special1:hover", "background: url(" + new global::SimpleRollover.HTML.Images.FromAssets.Untitled_3().src + ") repeat-x", 1);

            sheet.AddRule(".special1 .hot").style.display = IStyle.DisplayEnum.none;
            sheet.AddRule(".special1:hover .hot").style.display = IStyle.DisplayEnum.inline;

            sheet.AddRule(".special1 .cold", "display: inline;", 1);
            sheet.AddRule(".special1:hover .cold", "display: none;", 1);


            var states = new XState[] { }.AsEnumerable();

            //    new XState { 
            //        Show = default(System.Action), 
            //        Hide = default(System.Action), 
            //        Selected = false } 
            //}.Where(p => false);


            Action<IHTMLImage, IHTMLImage, string> Spawn =
                async (icold, ihot, i2) =>
                {
                    var cold = await icold;
                    var hot = await ihot;

                    //((IHTMLImage)i[0]).InvokeOnComplete(cold =>
                    //((IHTMLImage)i[1]).InvokeOnComplete(hot =>
                    //     {
                    cold.className = "cold";
                    hot.className = "hot";


                    var btn = new IHTMLButton()
                        {
                            className = "special1"
                        };

                    btn.appendChild(cold, hot);

                    var content = new IHTMLElement(IHTMLElement.HTMLElementEnum.pre);

                    content.innerHTML = "...";
                    content.className = "content1";

                    var tween = new TweenDataDouble();
                    var tween_max = 16;

                    tween.ValueChanged +=
                        delegate
                        {
                            content.style.Opacity = tween.Value / tween_max;
                            content.style.height = tween.Value + "em";

                            content.style.overflow = IStyle.OverflowEnum.hidden;

                        };

                    tween.Done += delegate
                    {
                        if (tween.Value > 0)
                            content.style.overflow = IStyle.OverflowEnum.auto;
                    };

                    tween.Value = 0;

                    var state = new XState
                       {
                           Show = (System.Action)(() =>
                                               {
                                                   tween.Value = tween_max;
                                               }
                           ),
                           Hide = (System.Action)(() => tween.Value = 0),
                           Selected = false
                       };

                    //try
                    //{
                    //    new IXMLHttpRequest(HTTPMethodEnum.GET, i[2],
                    //       request => content.innerHTML = request.responseText
                    //    );
                    //}
                    //catch
                    //{
                    content.innerText = i2;
                    //}

                    states = states.Concat(new[] { state });

                    btn.onclick +=
                        delegate
                        {
                            foreach (var v in states)
                            {
                                if (v == state)
                                {

                                    v.Selected = !v.Selected;

                                    if (v.Selected)
                                    {
                                        v.Show();
                                    }
                                    else
                                    {
                                        v.Hide();
                                    }

                                }
                                else
                                {
                                    v.Selected = false;
                                    v.Hide();
                                }
                            }
                        };

                    u.appendChild(btn, content);




                };


            SpawnCursor();


            u.AttachToDocument();

            Spawn(
                new global::SimpleRollover.HTML.Images.FromAssets.Untitled_1_03(),
                new global::SimpleRollover.HTML.Images.FromAssets.Untitled_2_03(),
                "This application was written in C#."
            );

            Spawn(
                new global::SimpleRollover.HTML.Images.FromAssets.Untitled_1_07(),
                new global::SimpleRollover.HTML.Images.FromAssets.Untitled_2_07(),

                 "This application was cross compiled into JavaScript."
            );


        }
Beispiel #34
0
 protected override IBound LayoutChildren(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
 {
     return ControlsContext.Current.CreateLayoutBehaviour(stylesheet, this)
         .Dock(ContainerBehaviour.Childrens, styleBound, maxBound);
 }
Beispiel #35
0
 public SyntaxHighlightingExtension(IStyleSheet customCss = null)
 {
     _customCss = customCss;
 }
        private static void WriteHeaderDivStart(IStyleSheet styleSheet,
            TextWriter writer)
        {
            Color foreground = Color.Empty;
            Color background = Color.Empty;

            if (styleSheet.Styles.Contains(ScopeName.PlainText))
            {
                Style plainTextStyle = styleSheet.Styles[ScopeName.PlainText];

                foreground = plainTextStyle.Foreground;
                background = plainTextStyle.Background;
            }

            WriteElementStart(writer, "div", foreground, background );
        }
Beispiel #37
0
 private async Task CreateSheetAsync(IStyleEngine engine, IBrowsingContext context)
 {
     var cancel = CancellationToken.None;
     var response = VirtualResponse.Create(res => res.Content(TextContent).Address(default(Url)));
     var options = new StyleOptions(context)
     {
         Element = this,
         IsDisabled = IsDisabled,
         IsAlternate = false
     };
     var task = engine.ParseStylesheetAsync(response, options, cancel);
     _sheet = await task.ConfigureAwait(false);
 }
Beispiel #38
0
 protected override IBound LayoutChildren(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
 {
     float[] borders;
     return(ControlsContext.Current.CreateLayoutBehaviour(stylesheet, this)
            .Horizontal(ContainerBehaviour.Childrens, styleBound, maxBound, out borders));
 }
Beispiel #39
0
        public void Write(string parsedSourceCode, IList <Scope> scopes, IStyleSheet styleSheet)
        {
            var styleInsertions = new List <TextInsertion>();

            int  offset = 0;
            bool lastScopeWasComment = false;

            foreach (Scope scope in scopes)
            {
                string t = parsedSourceCode.Substring(scope.Index, scope.Length);
                if (string.IsNullOrEmpty(t))
                {
                    continue;
                }

                //                    .Replace("\r\n", "\n")
                //                    .Replace("\r", "\n");
                offset = scope.Index + scope.Length;

                var text = t.Replace("\r", string.Empty);
                // temp solution - adding spaces between words
                if (offset < parsedSourceCode.Length - 1 && (parsedSourceCode[offset] == ' ' || parsedSourceCode[offset] == '\r'))
                {
                    text += " ";
                }

                Inline run = new Run {
                    Text = text
                };
                if (styleSheet.Styles.Contains(scope.Name))
                {
                    var style = styleSheet.Styles[scope.Name];
                    run.Foreground = new SolidColorBrush(style.Foreground);
                    run.FontWeight = style.FontWeight;
                }
                lastScopeWasComment = (scope.Name == "Comment");
                _text.Inlines.Add(run);
            }
            string left = parsedSourceCode
                          .Substring(offset)
                          .Replace("\r\n", "\n")
                          .Replace("\r", "\n");

            if (!string.IsNullOrEmpty(left))
            {
                for (int i = left.IndexOf("\n"); i >= 0; i = left.IndexOf("\n"))
                {
                    if (i > 0)
                    {
                        Inline tby = new Run {
                            Text = left.Substring(0, i)
                        };
                        _text.Inlines.Add(tby);
                    }

                    left = left.Substring(i + 1);
                    if (lastScopeWasComment)
                    {
                        lastScopeWasComment = false;
                    }
                    else
                    {
                        _text.Inlines.Add(new LineBreak());
                    }
                }

                if (!string.IsNullOrEmpty(left))
                {
                    Inline nrun = new Run {
                        Text = left
                    };
                    _text.Inlines.Add(nrun);
                }
            }
        }
Beispiel #40
0
 protected override IBound LayoutChildren(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
 {
     float[] borders;
     return ControlsContext.Current.CreateLayoutBehaviour(stylesheet, this)
         .Vertical(ContainerBehaviour.Childrens, styleBound, maxBound, out borders);
 }
 private static void WriteHeaderDivStart(IStyleSheet styleSheet,
                                         ILanguage language,
                                         TextWriter writer)
 {
     WriteElementStart("div", language.CssClassName, writer);
 }
Beispiel #42
0
        protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
        {
            var bound = StyleSheetContext.Current.CreateBound(BitBrowserApp.Current.Width, BitBrowserApp.Current.Height);
            base.Apply(stylesheet, bound, bound);

            //background color
            _view.SetBackgroundColor(Android.Graphics.Color.White);

            if (OnLoad != null)
                OnLoad.Execute();

            Frame = ControlsContext.Current.CreateRectangle(0, 0, bound);

            return bound;
        }
 public void WriteFooter(IStyleSheet styleSheet, TextWriter textWriter)
 {
 }
 public SelectionBehaviour(Color? selectedColor, Control control, IStyleSheet stylesheet)
 {
     _control = control;
     _stylesheet = stylesheet;
     SelectedColor = selectedColor;
 }
 public void WriteHeader(IStyleSheet styleSheet, TextWriter textWriter)
 {
 }
Beispiel #46
0
        void FinishLoading(Task<IResponse> task)
        {
            var type = Type ?? MimeTypes.Css;
            var config = Owner.Options;
            var engine = config.GetStyleEngine(type);

            if (task.IsCompleted && task.IsFaulted == false)
            {
                using (var response = task.Result)
                {
                    if (engine != null && RelationList.Contains(Keywords.StyleSheet))
                    {
                        var options = new StyleOptions
                        {
                            Element = this,
                            Title = Title,
                            IsDisabled = IsDisabled,
                            IsAlternate = RelationList.Contains(Keywords.Alternate),
                            Configuration = config
                        };

                        if (response != null)
                        {
                            try { _sheet = engine.ParseStylesheet(response, options); }
                            catch { /* Do not care here */ }
                        }
                    }
                }
            }

            this.FireLoadOrErrorEvent(task);
        }
 /// <summary>
 /// Gets the associated document of the sheet if any.
 /// </summary>
 /// <param name="sheet">The sheet.</param>
 /// <returns>The associated document, if any.</returns>
 public static IDocument GetDocument(this IStyleSheet sheet)
 {
     return(sheet?.OwnerNode?.Owner);
 }