コード例 #1
0
ファイル: StyleSheet.cs プロジェクト: jmonasterio/xgc3
 public Selector Copy()
 {
     Selector s = new Selector();
     s.Selects = this.Selects;
     s.Type = this.Type;
     foreach (KeyValuePair<string, Instance> pair in Children)
     {
         s.Children.Add(pair.Key, pair.Value);
     }
     return s;
 }
コード例 #2
0
ファイル: StyleSheet.cs プロジェクト: jmonasterio/xgc3
 /// <summary>
 /// 
 /// </summary>
 /// <param name="src">Style to merge into THIS one.</param>
 /// <param name="selector">Which particular selector to merge</param>
 public void Merge(Selector s)
 {
     foreach (KeyValuePair<string, Instance> pair in s.Children)
     {
         if (this.Children.ContainsKey(pair.Key))
         {
             this.Children[pair.Key] = pair.Value;
         }
         else
         {
             this.Children.Add(pair.Key, pair.Value);
         }
     }
 }
コード例 #3
0
ファイル: StyleSheet.cs プロジェクト: jmonasterio/xgc3
        /// <summary>
        /// First implementation is a very simple cascade:
        /// (1) Apply universal styles, if applicable.
        /// (2) If found, apply styles
        /// </summary>
        /// <param name="instance"></param>
        public void ApplyStyleCascadeToInstance( Instance instance )
        {
            // Create selector by building up cascade
            Selector selectorToApply = new Selector();

            // Start with all universal selectors
            // TODO: Why do this on every call? Can't we precalculate the universal ones?
            foreach( Selector selector in m_UniversalStyle.Children.Convert<Selector>())
            {
                selectorToApply.Merge( selector as Selector);
            }

            // Replace with type styles, if applicable
            if (m_StylesForType.Children.ContainsKey(instance.GetSimpleClassName()))
            {
                selectorToApply.Merge(m_StylesForType.Children[instance.GetSimpleClassName()] as Selector);
            }

            // CssClass attribute styles override all previous
            if (m_StylesForCssClass.Children.ContainsKey(instance.CssClass))
            {
                selectorToApply.Merge(m_StylesForCssClass.Children[instance.CssClass] as Selector);
            }

            // Id attributes override all previous
            if (m_StylesForId.Children.ContainsKey(instance.Name))
            {
                selectorToApply.Merge(m_StylesForId.Children[instance.Name] as Selector);
            }

            // We now have a list of styles to apply to this instance, but not all of them
            //  may be real properties of the instance. Try each one.
            selectorToApply.Apply(instance);
        }