예제 #1
0
        public override bool GetBoolean(RenderableData context, CssProperty property)
        {
            string text = GetText(context, property);

            return(!string.IsNullOrEmpty(text) && text != "false" && text != "FALSE" && text != "0" && text != "no");
        }
예제 #2
0
 public override VectorPath GetPath(RenderableData context, CssProperty property)
 {
     return(SharedPath);
 }
예제 #3
0
 public override float GetDecimal(RenderableData context, CssProperty property)
 {
     // 100%
     return(1f);
 }
예제 #4
0
        /// <summary>Builds a Loonim filter from the given set of one or more CSS functions.</summary>
        public static void BuildFilter(Css.Value value, RenderableData context, FilterEventDelegate fe)
        {
            if (value is Css.Functions.UrlFunction)
            {
                // - (A URL to an SVG filter) (not supported yet here)
                // - A URL to a Loonim filter (with a property called source0)

                // Load it now!
                DataPackage dp = new DataPackage(value.Text, context.Document.basepath);

                dp.onload = delegate(UIEvent e){
                    // Got the data! Load a filter now:
                    SurfaceTexture st = null;

                    // Create:
                    st = new SurfaceTexture();

                    // Load it:
                    st.Load(dp.responseBytes);

                    // Run the callback:
                    fe(context, st);
                };

                // Send:
                dp.send();
            }
            else
            {
                Loonim.TextureNode first = null;
                Loonim.TextureNode last  = null;

                // - One or more filter functions
                if (value is Css.CssFunction)
                {
                    // Just one
                    first = last = value.ToLoonimNode(context);
                }
                else if (value is Css.ValueSet)
                {
                    // Many
                    for (int i = 0; i < value.Count; i++)
                    {
                        // Convert to a Loonim node:
                        Loonim.TextureNode next = value[i].ToLoonimNode(context);

                        if (next == null)
                        {
                            // Quit!
                            first = null;
                            last  = null;
                            break;
                        }

                        // Hook it on:
                        if (first == null)
                        {
                            first = last = next;
                        }
                        else
                        {
                            // Add it to the chain:
                            last.Sources[0] = next;
                            last            = next;
                        }
                    }
                }

                SurfaceTexture st = null;

                if (first != null)
                {
                    // Create the texture:
                    st               = new SurfaceTexture();
                    st["source0"]    = new Values.TextureValue(null);
                    st.Root          = first;
                    first.Sources[0] = new Loonim.Property(st, "source0");
                }

                // Run the callback now!
                fe(context, st);
            }
        }
예제 #5
0
 /// <summary>Gets the active font face for the given element.</summary>
 protected FontFace GetFontFace(RenderableData context)
 {
     return(context.computedStyle.FontFamilyX.GetFirstFace());
 }
예제 #6
0
 public override bool GetBoolean(RenderableData context, CssProperty property)
 {
     return(true);
 }
예제 #7
0
        /// <summary>Part of shrink-to-fit. Computes the maximum and minimum possible width for an element.
        /// This does not include the elements own padding/margin/border.</summary>
        public void GetWidthBounds(out float min, out float max)
        {
            min = 0f;
            max = 0f;

            // For each child, get its width bounds too.
            if (RenderData.FirstBox == null)
            {
                return;
            }

            if (childNodes_ != null)
            {
                // Current line:
                float cMin = 0f;
                float cMax = 0f;

                for (int i = 0; i < childNodes_.length; i++)
                {
                    Node child = childNodes_[i];

                    IRenderableNode renderable = (child as IRenderableNode);

                    if (renderable == null)
                    {
                        continue;
                    }

                    float bMin;
                    float bMax;

                    if (child is PowerUI.RenderableTextNode)
                    {
                        // Always get bounds:
                        renderable.GetWidthBounds(out bMin, out bMax);
                    }
                    else
                    {
                        // Get the first box from the render data:
                        RenderableData rd  = renderable.RenderData;
                        LayoutBox      box = rd.FirstBox;

                        if (box == null)
                        {
                            continue;
                        }

                        // If it's inline (or float) then it's additive to the current line.
                        if ((box.DisplayMode & DisplayMode.OutsideBlock) != 0 && box.FloatMode == FloatMode.None)
                        {
                            // Line break!
                            cMin = 0f;
                            cMax = 0f;
                        }

                        // Get an explicit width:
                        bool wasAuto;
                        bMin = rd.GetWidth(true, out wasAuto);

                        if (bMin == float.MinValue)
                        {
                            // Get the bounds:
                            renderable.GetWidthBounds(out bMin, out bMax);
                        }
                        else
                        {
                            bMax = bMin;
                        }

                        // Add margins etc:
                        float extraStyle = (
                            box.Border.Left + box.Border.Right +
                            box.Padding.Left + box.Padding.Right +
                            box.Margin.Left + box.Margin.Right
                            );

                        bMin += extraStyle;
                        bMax += extraStyle;
                    }

                    // Apply to line:
                    cMin += bMin;
                    cMax += bMax;

                    // Longest line?
                    if (cMin > min)
                    {
                        min = cMin;
                    }

                    if (cMax > max)
                    {
                        max = cMax;
                    }
                }
            }
        }
예제 #8
0
        /// <summary>Computes the box for the given context now.</summary>
        public BoxStyle Compute(Css.Value value, RenderableData context, int position)
        {
            // Result:
            BoxStyle result = new BoxStyle();

            if (value == null || position == PositionMode.Static)
            {
                // Ignore position for static elements (or if it's not declared).
                result.Top    = float.MaxValue;
                result.Bottom = float.MaxValue;
                result.Right  = float.MaxValue;
                result.Left   = float.MaxValue;
                return(result);
            }

            // Top and bottom:
            Css.Value a = value[0];
            Css.Value b = value[2];

            // Note that the default here is auto:
            bool aAuto = a.IsAuto;
            bool bAuto = b.IsAuto;

            if (aAuto || bAuto)
            {
                if (!aAuto)
                {
                    // Bottom is auto, top is a number.
                    result.Top    = a.GetDecimal(context, Top);
                    result.Bottom = float.MaxValue;
                }
                else if (!bAuto)
                {
                    // Top is auto, bottom is a number.
                    result.Bottom = b.GetDecimal(context, Bottom);
                    result.Top    = float.MaxValue;
                }
                else
                {
                    // Otherwise both auto => both undefined (0).
                    result.Top    = float.MaxValue;
                    result.Bottom = float.MaxValue;
                }
            }
            else
            {
                // Both have been declared. A special case for height is triggered here (absolute only).
                result.Top = a.GetDecimal(context, Top);

                // It'll only work for absolutes though:
                if (position == PositionMode.Absolute)
                {
                    result.Bottom = b.GetDecimal(context, Bottom);
                }
                else
                {
                    // Ignore bottom.
                    result.Bottom = float.MaxValue;
                }
            }

            // Right and left:
            a = value[1];
            b = value[3];

            // Note that the default here is auto:
            aAuto = a.IsAuto;
            bAuto = b.IsAuto;

            if (aAuto || bAuto)
            {
                if (!aAuto)
                {
                    // Left is auto, right is a number.
                    result.Right = a.GetDecimal(context, Right);
                    result.Left  = float.MaxValue;
                }
                else if (!bAuto)
                {
                    // Right is auto, left is a number.
                    result.Left  = b.GetDecimal(context, Left);
                    result.Right = float.MaxValue;
                }
                else
                {
                    // Otherwise both auto => both undefined (0).
                    result.Right = float.MaxValue;
                    result.Left  = float.MaxValue;
                }
            }
            else
            {
                // Both have been declared. A special case for width is triggered here (absolute only).
                result.Left = b.GetDecimal(context, Left);

                // It'll only work for absolutes though:
                if (position == PositionMode.Absolute)
                {
                    result.Right = a.GetDecimal(context, Right);
                }
                else
                {
                    // Ignore left.
                    result.Right = float.MaxValue;
                }
            }

            return(result);
        }
예제 #9
0
 public override float GetDecimal(RenderableData context, CssProperty property)
 {
     return(DirectionMode.RTL);
 }
예제 #10
0
 public override float GetDecimal(RenderableData context, CssProperty property)
 {
     return(700);
 }
예제 #11
0
 public override float GetDecimal(RenderableData context, CssProperty property)
 {
     return(FloatMode.Both);
 }
예제 #12
0
 public override bool GetBoolean(RenderableData context, CssProperty property)
 {
     return(!string.IsNullOrEmpty(RawValue) && RawValue != "0" && RawValue != "false" && RawValue != "no" && RawValue != "off");
 }
예제 #13
0
 public override string GetText(RenderableData context, CssProperty property)
 {
     return(RawValue);
 }
예제 #14
0
 public override float GetNormalValue(RenderableData context)
 {
     return(-1f);
 }
 public override float GetDecimal(RenderableData context, CssProperty property)
 {
     return(StrokeLineMode.Bevel);
 }