public void AddSimpleSelector(StyleSelectorPart[] parts, StyleSelectorRelationship previousRelationsip)
        {
            StyleSelector styleSelector = new StyleSelector();

            styleSelector.parts = parts;
            styleSelector.previousRelationship = previousRelationsip;
            StyleSheetBuilder.Log("Add simple selector " + styleSelector);
            this.m_CurrentSelectors.Add(styleSelector);
        }
示例#2
0
 public QueryBuilder(VisualElement visualElement)
     : this()
 {
     m_Element        = visualElement;
     m_Parts          = null;
     m_StyleSelectors = null;
     m_Relationship   = StyleSelectorRelationship.None;
     m_Matchers       = new List <RuleMatcher>();
     pseudoStatesMask = negatedPseudoStatesMask = 0;
 }
示例#3
0
 public QueryBuilder(VisualElement visualElement)
 {
     this                  = default(UQuery.QueryBuilder <T>);
     this.m_Element        = visualElement;
     this.m_Parts          = null;
     this.m_StyleSelectors = null;
     this.m_Relationship   = StyleSelectorRelationship.None;
     this.m_Matchers       = new List <RuleMatcher>();
     this.pseudoStatesMask = (this.negatedPseudoStatesMask = 0);
 }
示例#4
0
 private UQuery.QueryBuilder <T2> AddRelationship <T2>(StyleSelectorRelationship relationship) where T2 : VisualElement
 {
     UQuery.QueryBuilder <T2> result = new UQuery.QueryBuilder <T2>(this.m_Element);
     result.m_Matchers              = this.m_Matchers;
     result.m_Parts                 = this.m_Parts;
     result.m_StyleSelectors        = this.m_StyleSelectors;
     result.m_Relationship          = ((relationship != StyleSelectorRelationship.None) ? relationship : this.m_Relationship);
     result.pseudoStatesMask        = this.pseudoStatesMask;
     result.negatedPseudoStatesMask = this.negatedPseudoStatesMask;
     return(result);
 }
示例#5
0
 private QueryBuilder <T2> AddRelationship <T2>(StyleSelectorRelationship relationship) where T2 : VisualElement
 {
     return(new QueryBuilder <T2>(m_Element)
     {
         m_Matchers = m_Matchers,
         m_Parts = m_Parts,
         m_StyleSelectors = m_StyleSelectors,
         m_Relationship = relationship == StyleSelectorRelationship.None ? m_Relationship : relationship,
         pseudoStatesMask = pseudoStatesMask,
         negatedPseudoStatesMask = negatedPseudoStatesMask
     });
 }
        void VisitComplexSelector(ComplexSelector complexSelector)
        {
            int fullSpecificity = CSSSpec.GetSelectorSpecificity(complexSelector.ToString());

            if (fullSpecificity == 0)
            {
                m_Errors.AddInternalError("Failed to calculate selector specificity " + complexSelector);
                return;
            }

            using (m_Builder.BeginComplexSelector(fullSpecificity))
            {
                StyleSelectorRelationship relationShip = StyleSelectorRelationship.None;

                foreach (CombinatorSelector selector in complexSelector)
                {
                    StyleSelectorPart[] parts;

                    string simpleSelector = ExtractSimpleSelector(selector.Selector);

                    if (string.IsNullOrEmpty(simpleSelector))
                    {
                        m_Errors.AddInternalError("Expected simple selector inside complex selector " + simpleSelector);
                        return;
                    }

                    if (CheckSimpleSelector(simpleSelector, out parts))
                    {
                        m_Builder.AddSimpleSelector(parts, relationShip);

                        // Read relation for next element
                        switch (selector.Delimiter)
                        {
                        case Combinator.Child:
                            relationShip = StyleSelectorRelationship.Child;
                            break;

                        case Combinator.Descendent:
                            relationShip = StyleSelectorRelationship.Descendent;
                            break;

                        default:
                            m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidComplexSelectorDelimiter, complexSelector.ToString());
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
        public void AddSimpleSelector(StyleSelectorPart[] parts, StyleSelectorRelationship previousRelationsip)
        {
            Debug.Assert(m_BuilderState == BuilderState.ComplexSelector);
            var selector = new StyleSelector();

            selector.parts = parts;
            selector.previousRelationship = previousRelationsip;

            Log("Add simple selector " + selector);

            m_CurrentSelectors.Add(selector);
        }
示例#8
0
 private UQuery.QueryBuilder <T2> AddRelationship <T2>(StyleSelectorRelationship relationship) where T2 : VisualElement
 {
     return(new UQuery.QueryBuilder <T2>(this.m_Element)
     {
         m_Matchers = this.m_Matchers,
         m_Parts = this.m_Parts,
         m_StyleSelectors = this.m_StyleSelectors,
         m_Relationship = relationship,
         pseudoStatesMask = this.pseudoStatesMask,
         negatedPseudoStatesMask = this.negatedPseudoStatesMask
     });
 }
        public void AddSimpleSelector(StyleSelectorPart[] parts, StyleSelectorRelationship previousRelationsip)
        {
            Debug.Assert(this.m_BuilderState == StyleSheetBuilder.BuilderState.ComplexSelector);
            StyleSelector styleSelector = new StyleSelector();

            styleSelector.parts = parts;
            styleSelector.previousRelationship = previousRelationsip;
            string        arg_38_0 = "Add simple selector ";
            StyleSelector expr_2C  = styleSelector;

            StyleSheetBuilder.Log(arg_38_0 + ((expr_2C != null) ? expr_2C.ToString() : null));
            this.m_CurrentSelectors.Add(styleSelector);
        }
示例#10
0
        private void VisitComplexSelector(ComplexSelector complexSelector)
        {
            int selectorSpecificity = CSSSpec.GetSelectorSpecificity(complexSelector.ToString());

            if (selectorSpecificity == 0)
            {
                this.m_Errors.AddInternalError("Failed to calculate selector specificity " + complexSelector);
            }
            else
            {
                using (this.m_Builder.BeginComplexSelector(selectorSpecificity))
                {
                    StyleSelectorRelationship previousRelationsip = StyleSelectorRelationship.None;
                    foreach (CombinatorSelector current in complexSelector)
                    {
                        string text = this.ExtractSimpleSelector(current.Selector);
                        if (string.IsNullOrEmpty(text))
                        {
                            this.m_Errors.AddInternalError("Expected simple selector inside complex selector " + text);
                            break;
                        }
                        StyleSelectorPart[] parts;
                        if (!this.CheckSimpleSelector(text, out parts))
                        {
                            break;
                        }
                        this.m_Builder.AddSimpleSelector(parts, previousRelationsip);
                        Combinator delimiter = current.Delimiter;
                        if (delimiter != Combinator.Child)
                        {
                            if (delimiter != Combinator.Descendent)
                            {
                                this.m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidComplexSelectorDelimiter, complexSelector.ToString());
                                break;
                            }
                            previousRelationsip = StyleSelectorRelationship.Descendent;
                        }
                        else
                        {
                            previousRelationsip = StyleSelectorRelationship.Child;
                        }
                    }
                }
            }
        }
        public static void ToUssString(StyleSelectorRelationship previousRelationship, StyleSelectorPart[] parts, StringBuilder sb)
        {
            if (previousRelationship != StyleSelectorRelationship.None)
            {
                sb.Append(previousRelationship == StyleSelectorRelationship.Child ? " > " : " ");
            }
            foreach (var selectorPart in parts)
            {
                switch (selectorPart.type)
                {
                case StyleSelectorType.Wildcard:
                    sb.Append('*');
                    break;

                case StyleSelectorType.Type:
                    sb.Append(selectorPart.value);
                    break;

                case StyleSelectorType.Class:
                    sb.Append('.');
                    sb.Append(selectorPart.value);
                    break;

                case StyleSelectorType.PseudoClass:
                    sb.Append(':');
                    sb.Append(selectorPart.value);
                    break;

                case StyleSelectorType.ID:
                    sb.Append('#');
                    sb.Append(selectorPart.value);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
示例#12
0
        private void DrawMatchingRules()
        {
            if (UIElementsDebugger.s_MatchedRulesExtractor.selectedElementStylesheets != null && UIElementsDebugger.s_MatchedRulesExtractor.selectedElementStylesheets.Count > 0)
            {
                EditorGUILayout.LabelField(UIElementsDebugger.Styles.stylesheetsContent, UIElementsDebugger.Styles.KInspectorTitle, new GUILayoutOption[0]);
                foreach (string current in UIElementsDebugger.s_MatchedRulesExtractor.selectedElementStylesheets)
                {
                    if (GUILayout.Button(current, new GUILayoutOption[0]))
                    {
                        InternalEditorUtility.OpenFileAtLineExternal(current, 0);
                    }
                }
            }
            if (UIElementsDebugger.s_MatchedRulesExtractor.selectedElementRules != null && UIElementsDebugger.s_MatchedRulesExtractor.selectedElementRules.Count > 0)
            {
                EditorGUILayout.LabelField(UIElementsDebugger.Styles.selectorsContent, UIElementsDebugger.Styles.KInspectorTitle, new GUILayoutOption[0]);
                int num = 0;
                foreach (MatchedRulesExtractor.MatchedRule current2 in UIElementsDebugger.s_MatchedRulesExtractor.selectedElementRules)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    for (int i = 0; i < current2.ruleMatcher.complexSelector.selectors.Length; i++)
                    {
                        StyleSelector             styleSelector        = current2.ruleMatcher.complexSelector.selectors[i];
                        StyleSelectorRelationship previousRelationship = styleSelector.previousRelationship;
                        if (previousRelationship != StyleSelectorRelationship.Child)
                        {
                            if (previousRelationship == StyleSelectorRelationship.Descendent)
                            {
                                stringBuilder.Append(" ");
                            }
                        }
                        else
                        {
                            stringBuilder.Append(" > ");
                        }
                        for (int j = 0; j < styleSelector.parts.Length; j++)
                        {
                            StyleSelectorPart styleSelectorPart = styleSelector.parts[j];
                            switch (styleSelectorPart.type)
                            {
                            case StyleSelectorType.Class:
                                stringBuilder.Append(".");
                                break;

                            case StyleSelectorType.PseudoClass:
                            case StyleSelectorType.RecursivePseudoClass:
                                stringBuilder.Append(":");
                                break;

                            case StyleSelectorType.ID:
                                stringBuilder.Append("#");
                                break;
                            }
                            stringBuilder.Append(styleSelectorPart.value);
                        }
                    }
                    StyleProperty[] properties = current2.ruleMatcher.complexSelector.rule.properties;
                    bool            flag       = this.m_CurFoldout.Contains(num);
                    EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    bool flag2 = EditorGUILayout.Foldout(this.m_CurFoldout.Contains(num), new GUIContent(stringBuilder.ToString()), true);
                    if (current2.displayPath != null && GUILayout.Button(current2.displayPath, EditorStyles.miniButton, new GUILayoutOption[]
                    {
                        GUILayout.MaxWidth(150f)
                    }))
                    {
                        InternalEditorUtility.OpenFileAtLineExternal(current2.fullPath, current2.lineNumber);
                    }
                    EditorGUILayout.EndHorizontal();
                    if (flag && !flag2)
                    {
                        this.m_CurFoldout.Remove(num);
                    }
                    else if (!flag && flag2)
                    {
                        this.m_CurFoldout.Add(num);
                    }
                    if (flag2)
                    {
                        EditorGUI.indentLevel++;
                        for (int k = 0; k < properties.Length; k++)
                        {
                            string text = current2.ruleMatcher.sheet.ReadAsString(properties[k].values[0]);
                            EditorGUILayout.LabelField(new GUIContent(properties[k].name), new GUIContent(text), new GUILayoutOption[0]);
                        }
                        EditorGUI.indentLevel--;
                    }
                    num++;
                }
            }
        }