Exemplo n.º 1
0
            /// <summary>
            /// Inserts a rule at the specified position in the collection.  The return value is the index in the list where the item was actually inserted,
            /// or -1 if the rule contains syntax errors and could not be added to the collection.
            /// </summary>
            /// <param name="index"></param>
            /// <param name="rule"></param>
            public int Insert(int index, string rule)
            {
                if (IsReadOnly)
                {
                    throw new InvalidOperationException("This collection is read-only.");
                }
                else if (index < 0 || index > Count)
                {
                    throw new ArgumentOutOfRangeException("index");
                }
                else if (string.IsNullOrEmpty(rule))
                {
                    return(-1);
                }

                const int NS_ERROR_DOM_SYNTAX_ERR = unchecked ((int)0x8053000c);

                using (AutoJSContext context = new AutoJSContext(GetJSContext()))
                {
                    context.PushCompartmentScope((nsISupports)StyleSheet._DomStyleSheet);
                    var val = context.EvaluateScriptBypassingSomeSecurityRestrictions(String.Format("this.insertRule('{0}',{1});", rule, index));
                    return(val.ToInteger());
                }

                return(index);
            }
Exemplo n.º 2
0
 nsIDOMCSSRuleList GetRuleList()
 {
     using (AutoJSContext context = new AutoJSContext(GetJSContext()))
     {
         context.PushCompartmentScope((nsISupports)StyleSheet._DomStyleSheet);
         var val = context.EvaluateScriptBypassingSomeSecurityRestrictions("this.cssRules;");
         return((nsIDOMCSSRuleList)val.ToObject());
     }
 }
Exemplo n.º 3
0
            /// <summary>
            /// Removes all rules from the collection.
            /// </summary>
            public void Clear()
            {
                if (IsReadOnly && Count > 0)
                {
                    throw new InvalidOperationException("This collection is read-only.");
                }

                using (AutoJSContext context = new AutoJSContext(GetJSContext()))
                {
                    context.PushCompartmentScope((nsISupports)StyleSheet._DomStyleSheet);
                    for (int i = Count - 1; i >= 0; i--)
                    {
                        context.EvaluateScriptBypassingSomeSecurityRestrictions(String.Format("deleteRule({0});", i));
                    }
                }
            }
Exemplo n.º 4
0
            /// <summary>
            /// Removes a specific rule from the collection.
            /// </summary>
            /// <param name="index"></param>
            public void RemoveAt(int index)
            {
                if (IsReadOnly)
                {
                    throw new InvalidOperationException("This collection is read-only.");
                }
                else if (index < 0 || index >= Count)
                {
                    throw new ArgumentOutOfRangeException("index");
                }

                using (AutoJSContext context = new AutoJSContext(GetJSContext()))
                {
                    context.PushCompartmentScope((nsISupports)StyleSheet._DomStyleSheet);
                    var val = context.EvaluateScriptBypassingSomeSecurityRestrictions(String.Format("DeleteRule({0});", index));
                }
            }