/** * * Find all matching style declarations for an IAdvancedStyleClient * component. The result is sorted in terms of specificity, but the * declaration order is preserved. * * Param: object - an IAdvancedStyleClient instance of the component to * match. * Param: styleDeclarations - an optional Array of additional * CSSStyleDeclarations to be included in the sorted matches. * * Returns: An Array of matching style declarations sorted by specificity. */ private static List <StyleDeclaration> GetMatchingStyleDeclarations(IStyleClient client, List <StyleDeclaration> styleDeclarations) { /*if (client.GetType().FullName == "Assets.eDriven.Skins.ImageButtonSkin") * Debug.Log("GetMatchingStyleDeclarations for: " + client);*/ StyleManager styleManager = StyleManager.Instance; if (null == styleDeclarations) { styleDeclarations = new List <StyleDeclaration>(); } // First, look for universal selectors List <StyleDeclaration> universalDecls = styleManager.GetStyleDeclarations("*"); /* ?? * new List<StyleDeclaration>(); // TODO: "*"*/ List <StyleDeclaration> list = MatchStyleDeclarations(universalDecls, client); styleDeclarations.AddRange(list); // Next, look for type selectors (includes ActionScript supertype matches) // If we also had universal selectors, concatenate them with our type // selectors and then resort by specificity... if (styleDeclarations.Count > 0) { //Debug.Log("first"); list = client.GetClassStyleDeclarations(); list.AddRange(styleDeclarations); styleDeclarations = list; styleDeclarations = SortOnSpecificity(styleDeclarations); } else { //Debug.Log("second"); // Otherwise, we only have type selectors (which are already sorted) styleDeclarations = client.GetClassStyleDeclarations(); #region Monitor //#if DEBUG // if (null != TYPE_TO_MONITOR) // { // if (client.GetType() == TYPE_TO_MONITOR) // Debug.Log(string.Format(@"*** {0}: //{1}", TYPE_TO_MONITOR, ListUtil<StyleDeclaration>.Format(styleDeclarations))); // } //#endif #endregion } return(styleDeclarations); }
public static Type TYPE_TO_MONITOR; // = typeof(ImageButtonSkin); // ReSharper restore MemberCanBePrivate.Global // ReSharper restore FieldCanBeMadeReadOnly.Global // ReSharper restore UnassignedField.Global // ReSharper restore InconsistentNaming // ReSharper restore UnusedMember.Global #endif /** * * Implements the getClassStyleDeclarations() logic * for Component and TextBase. * The 'object' parameter will be one or the other. */ internal static List <StyleDeclaration> GetClassStyleDeclarations(IStyleClient client) { /*if (client.GetType().FullName == "Assets.eDriven.Skins.ImageButtonSkin") * Debug.Log("GetMatchingStyleDeclarations for: " + client);*/ StyleManager styleManager = StyleManager.Instance; //bool qualified = true; string className = client.GetType().FullName; //IStyleClient advancedObject = client as IStyleClient; OrderedObject <bool> typeHierarchy = TypeHierarchyHelper.GetTypeHierarchy(client.GetType()); //, qualified); List <string> types = typeHierarchy.Keys; int typeCount = types.Count; //Debug.Log("typeCount for " + client + ": " + typeHierarchy); List <StyleDeclaration> classDecls = null; /*if (styleManager.TypeSelectorCache.ContainsKey(className)) * classDecls = styleManager.TypeSelectorCache[className];*/ /*if (null != classDecls) * return classDecls;*/ classDecls = new List <StyleDeclaration>(); // Loop over the type hierarhcy starting at the base type and work // down the chain of subclasses. for (int i = typeCount - 1; i >= 0; i--) { string type = types[i]; //.toString(); && TODO?? //Debug.Log("Getting decls for " + type); List <StyleDeclaration> decls = styleManager.GetStyleDeclarations(type); if (null != decls) { //Debug.Log(" ->" + decls.Count); var matchingDecls = MatchStyleDeclarations(decls, client); if (null != matchingDecls) { classDecls.AddRange(matchingDecls); } } } #region Monitor //#if DEBUG // if (null != TYPE_TO_MONITOR) // { // if (client.GetType() == TYPE_TO_MONITOR) // Debug.Log(string.Format(@"### {0} classDecls ### //{1}", TYPE_TO_MONITOR, ListUtil<StyleDeclaration>.Format(classDecls))); // } //#endif #endregion classDecls = SortOnSpecificity(classDecls); //classDecls.Sort(SpecificitySort); // = SortOnSpecificity(classDecls); #region Monitor //#if DEBUG // if (null != TYPE_TO_MONITOR) // { // if (client.GetType() == TYPE_TO_MONITOR) // Debug.Log(string.Format(@"### {0} classDecls 2 ### //{1}", TYPE_TO_MONITOR, ListUtil<StyleDeclaration>.Format(classDecls))); // } //#endif #endregion #region Always advanced - NO caching! /*if (styleManager.HasAdvancedSelectors()/* && advancedObject != null#1#) * { * // Advanced selectors may result in more than one match per type so * // we sort based on specificity, but we preserve the declaration * // order for equal selectors. * classDecls = SortOnSpecificity(classDecls); * } * else * { * // Cache the simple type declarations for this class * styleManager.TypeSelectorCache[className] = classDecls; * }*/ #endregion return(classDecls); }