/// <summary> /// Obtains the path to be referenced for a particular match type. /// </summary> /// <param name="type">The match type</param> /// <returns>The url/path/web domain path reference</returns> public static String GetReference(SelectorType type) { String url = Http.RawUrl; String path = UrlCleaner.CleanWebPathHead(Http.RawPath); //+ //if (String.IsNullOrEmpty(type)) { return String.Empty; } //+ //type = type.ToLower(System.Globalization.CultureInfo.CurrentCulture); //+ if (type == SelectorType.Contains || type == SelectorType.StartsWith || type == SelectorType.EndsWith) { return url; } else if (type == SelectorType.PathContains || type == SelectorType.PathStartsWith || type == SelectorType.PathEquals) { return path; } else if (type == SelectorType.WebDomainPathStartsWith || type == SelectorType.WebDomainPathEquals) { String webDomainUri = NalariumContext.Current.WebDomain.FullUrl; //+ return UrlCleaner.CleanWebPathHead(url.Substring(webDomainUri.Length, url.Length - webDomainUri.Length)); } else { return String.Empty; } }
//- @GetQueryStringVariableMap -// public static Map GetQueryStringVariableMap(SelectorType type, String matchText, String target, out String newTarget) { newTarget = target; var ex = new Regex(UrlCleaner.CleanWebPathHead(matchText), RegexOptions.IgnoreCase); String path = GetReference(type); Match m = ex.Match(path); if (m.Groups.Count > 1) { for (Int32 i = 1; i < m.Groups.Count; i++) { Group g = m.Groups[i]; newTarget = newTarget.Replace("$" + i.ToString(CultureInfo.CurrentCulture), g.Value); } } String queryString = String.Empty; Map map = null; Int32 pageIndex = newTarget.IndexOf("?", StringComparison.OrdinalIgnoreCase); if (pageIndex > -1) { queryString = newTarget.Substring(pageIndex + 1, newTarget.Length - pageIndex - 1); map = new Map(); map.AddQueryString(queryString); } //+ return map; }
public Query(IWebDriver browser, string selector, SelectorType locator = SelectorType.Css, string text = null) { _browser = browser; Selector = selector; Locator = locator; Text = text; }
public Query(IWebDriver browser, ElementType selector, SelectorType locator = SelectorType.XPath, string text = null) { _browser = browser; Selector = selector.GetStringValue(); Locator = locator; Text = text; }
private HtmlStyle CreateHtmlStyleFromRule(string styleName, string value, SelectorType type) { styleName = styleName.Trim().Replace("\"", string.Empty).Replace("'", string.Empty); value = value.Trim(); bool important = false; //Replace this with regular expression int importantIndex = value.IndexOf("!important"); if (importantIndex > -1) { important = true; value = value.Replace("!important", string.Empty).Trim(); } if (string.IsNullOrEmpty(styleName) || string.IsNullOrEmpty(value)) { return null; } return new HtmlStyle(styleName, value, important, type); }
internal void SetSpecificity(SelectorType type) { switch (type) { case SelectorType.Element: elements += 1; break; case SelectorType.Class: case SelectorType.Attribute: case SelectorType.PseudoClass: classes += 1; break; case SelectorType.Identity: id += 1; break; case SelectorType.Inline: inline += 1; break; } }
/// <summary> /// Initializes a new instance of the <see cref="RecipientSelectorAttribute"/> class. /// </summary> /// <param name="expression">The expression.</param> /// <param name="selectorType">Type of the recipient selector.</param> /// <param name="name">The name.</param> protected SelectorAttribute(string expression, SelectorType selectorType, string name) { Expression = expression; SelectorType = selectorType; Name = name; }
private static void SetDoMatchCheckToNoneInSubTree(IDomElement <TDependencyObject, TDependencyProperty> domElement, StyleSheet styleSheet, SelectorType type) { if (domElement == null || !domElement.IsReady || !ReferenceEquals(domElement.StyleInfo.CurrentStyleSheet, styleSheet)) { return; } domElement.StyleInfo.DoMatchCheck = SelectorType.None; var children = type == SelectorType.VisualTree ? domElement.ChildNodes : domElement.LogicalChildNodes; foreach (var child in children) { SetDoMatchCheckToNoneInSubTree(child, styleSheet, type); } }
public Selector() { qualifiers = new List <Qualifier>(); type = SelectorType.Best; SelectEvalMethod(); }
/// <summary> /// 构造方法 /// </summary> /// <param name="type">选择器类型</param> /// <param name="expression">表达式</param> public PropertyDefine(SelectorType type, string expression) : base(type, expression) { }
/// <summary> /// Creates an endpoint for programmatic use in a component. /// </summary> /// <param name="type">Selector type.</param> /// <param name="text">URL text to match.</param> /// <param name="name">Endpoint type.</param> /// <param name="parameterMap">Parameter map to send to the endpoint.</param> /// <param name="requireSlash">true is slash is required, false if not.</param> /// <returns>EndpointData object.</returns> public static EndpointData Create(SelectorType type, String text, String name, Map parameterMap, Boolean requireSlash) { return new EndpointData { Type = name, Selector = type, RequireSlash = requireSlash, Text = text, TextWithoutSlash = GetTextWithoutSlash(text), ParameterMap = parameterMap }; }
public override IEnumerable <DependencyObject> GetChildren(DependencyObject element, SelectorType type) { var list = new List <DependencyObject>(); if (element == null) { return(list); } if (element == applicationDependencyObject) { return(Application.Current.Windows.Cast <Window>().ToList()); } if (type == SelectorType.VisualTree) { try { list.AddRange(GetVisualChildren(element)); } catch { } } else { list = GetLogicalChildren(element).ToList(); } return(list); }
protected virtual IList <IDomElement <TDependencyObject, TDependencyProperty> > GetChildNodes(SelectorType type) { return(treeNodeProvider .GetChildren(dependencyObject, type) .Select(x => treeNodeProvider.GetDomElement(x)) .ToList()); }
//--------------------------------------
/// <summary> /// Initializes a new instance of the <see cref="RecipientSelectorAttribute"/> class. /// </summary> /// <param name="expression">The expression.</param> /// <param name="selectorType">Type of the selector.</param> /// <param name="name">The name.</param> public RecipientSelectorAttribute(string expression, SelectorType selectorType, string name) : base(expression, selectorType, name) { }
/// <summary> /// Close the currently active selector. If it's partial (e.g. a descendant/child marker) then merge its into into the /// new selector created. /// </summary> /// <param name="selectorType"></param> /// <param name="combinatorType"></param> /// <param name="traversalType"></param> protected void StartNewSelector(SelectorType selectorType, CombinatorType combinatorType, TraversalType traversalType) { // if a selector was not finished, do not overwrite the existing combinator & traversal types, // as they could have been changed by a descendant or child selector. if (TryFinishSelector()) { Current.CombinatorType = combinatorType; Current.TraversalType = traversalType; } Current.SelectorType = selectorType; }
//- @Match -// /// <summary> /// Tests the specified text against the current url, path, or web domain path based on the specified match type. /// </summary> /// <param name="type">The match type.</param> /// <param name="text">The text to match.</param> /// <returns>true is there is a match, false if not</returns> public static Boolean Match(SelectorType type, String text) { if (text == "*") { return true; } //if (String.IsNullOrEmpty(type)) { return false; } if (String.IsNullOrEmpty(text)) { return false; } //+ //type = type.ToLower(System.Globalization.CultureInfo.CurrentCulture); text = UrlCleaner.CleanWebPathHead(text).ToLower(CultureInfo.CurrentCulture); text = text.Replace("~", ConfigAccessor.ApplicationSettings("Domain", false)); //+ String reference = GetReference(type).ToLower(CultureInfo.CurrentCulture); if (type == SelectorType.Contains || type == SelectorType.PathContains) { return MatchContains(reference, text); } else if (type == SelectorType.StartsWith || type == SelectorType.PathStartsWith || type == SelectorType.WebDomainPathStartsWith) { return MatchStartsWith(reference, text); } else if (type == SelectorType.PathEquals || type == SelectorType.WebDomainPathEquals) { return MatchEquals(reference, text); } else if (type == SelectorType.EndsWith) { return MatchEndsWith(reference, text); } else { return false; } }
public string GetContactsByPrefix(string prefix, SelectorType selectorType, int targetEntityType, int targetEntityID) { if (targetEntityID > 0) { return GetContactsByPrefixJSON((EntityType)targetEntityType, targetEntityID, prefix); } var maxItemCount = 30; switch (selectorType) { case SelectorType.All: return ContactsToJSON(Global.DaoFactory.GetContactDao().GetContactsByPrefix(prefix, -1, 0, maxItemCount)); case SelectorType.Companies: return ContactsToJSON(Global.DaoFactory.GetContactDao().GetContactsByPrefix(prefix, 0, 0, maxItemCount)); case SelectorType.Persons: return ContactsToJSON(Global.DaoFactory.GetContactDao().GetContactsByPrefix(prefix, 1, 0, maxItemCount)); case SelectorType.PersonsWithoutCompany: return ContactsToJSON(Global.DaoFactory.GetContactDao().GetContactsByPrefix(prefix, 2, 0, maxItemCount)); case SelectorType.CompaniesAndPersonsWithoutCompany: return ContactsToJSON(Global.DaoFactory.GetContactDao().GetContactsByPrefix(prefix, 3, 0, maxItemCount)); default: throw new ArgumentException(); } }
//- @Substitute -// public static String Substitute(SelectorType type, String matchText, String target) { var ex = new Regex(matchText, RegexOptions.IgnoreCase); String path = GetReference(type); Match m = ex.Match(path); if (m.Groups.Count > 1) { for (Int32 i = 1; i < m.Groups.Count; i++) { Group g = m.Groups[i]; target = target.Replace("$" + i.ToString(CultureInfo.CurrentCulture), g.Value); } } //+ return target; }
/// <summary> /// Initializes a new instance of the <see cref="SelectorAttribute"/> class. /// </summary> /// <param name="expression">The expression.</param> /// <param name="selectorType">Type of the selector.</param> protected SelectorAttribute(string expression, SelectorType selectorType) : this(expression, SelectorType.Include, null) { Expression = expression; SelectorType = selectorType; }
public bool Has(string path, SelectorType selector) { return(HasSelector(path, SelectorType.XPath)); }
internal IEnumerable<HtmlStyle> ParseRules(string styleText, SelectorType type) { styleText = TrimComments(styleText); string[] styleSet = styleText.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string style in styleSet) { string styleNode = style.Trim(); if (!string.IsNullOrEmpty(styleNode)) { string[] nodeSet = styleNode.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (nodeSet != null && nodeSet.Length > 1) { HtmlStyle htmlStyle = CreateHtmlStyleFromRule(nodeSet[0], nodeSet[1], type); if (htmlStyle != null) { yield return htmlStyle; } } } } }
/// <summary> /// Select implementation. The public method automatically remaps a selector with the knowledge /// that the context is external (and not part of a chain) /// </summary> /// /// <exception cref="ArgumentNullException"> /// Thrown when one or more required arguments are null. /// </exception> /// /// <param name="context"> /// The context in which the selector applies. If null, the selector is run against the entire /// Document. If not, the selector is run against this sequence of elements. /// </param> /// /// <returns> /// A list of elements. This method returns a list (rather than a sequence) because the sequence /// must be enumerated to ensure that end-users don't cause the selector to be rerun repeatedly, /// and that the values are not mutable (e.g. if the underlying source changes). /// </returns> public IList <IDomObject> Select(IEnumerable <IDomObject> context) { // this holds the final output HashSet <IDomObject> output = new HashSet <IDomObject>(); if (Selector == null) { throw new ArgumentNullException("The selector cannot be null."); } if (Selector.Count == 0) { return(EmptyEnumerable().ToList()); } ActiveSelectors = new List <SelectorClause>(Selector); // First just check if we ended up here with an HTML selector; if so, hand it off. var firstSelector = ActiveSelectors[0]; if (firstSelector.SelectorType == SelectorType.HTML) { return(CsQuery.Implementation. DomDocument.Create(firstSelector.Html, HtmlParsingMode.Fragment) .ChildNodes .ToList()); } // this holds any results that carried over from the previous loop for chaining IEnumerable <IDomObject> lastResult = null; // this is the source from which selections are made in a given iteration; it could be the DOM // root, a context, or the previous result set. IEnumerable <IDomObject> selectionSource = null; // Disable the index if there is no context (e.g. disconnected elements) // or if the first element is not indexed, or the context is not from the same document as this // selector is bound. Determine which features can be used for this query by casting the index // to the known interfaces. bool useIndex; if (context.IsNullOrEmpty()) { useIndex = true; } else { IDomObject first = context.First(); useIndex = !first.IsDisconnected && first.IsIndexed && first.Document == Document; } IDomIndexRanged rangedIndex = null; IDomIndexSimple simpleIndex = null; if (useIndex) { rangedIndex = Document.DocumentIndex as IDomIndexRanged; simpleIndex = Document.DocumentIndex as IDomIndexSimple; } for (activeSelectorId = 0; activeSelectorId < ActiveSelectors.Count; activeSelectorId++) { var selector = ActiveSelectors[activeSelectorId].Clone(); if (lastResult != null && (selector.CombinatorType == CombinatorType.Root || selector.CombinatorType == CombinatorType.Context)) { // we will alter the selector during each iteration to remove the parts that have already been // parsed, so use a copy. This is a selector that was chained with the selector grouping // combinator "," -- we always output the results so far when beginning a new group. output.AddRange(lastResult); lastResult = null; } // For "and" combinator types, we want to leave everything as it was -- the results of this // selector should compound with the prior. This is not an actual CSS combinator, this is the // equivalent of grouping parenthesis. That is, in CSS there's no way to say "(input[submit], // button):visible" - that is group the results on selector part and apply a filter to it. But // we need to do exactly this for certain selector types (for example the jQuery :button // selector). if (selector.CombinatorType != CombinatorType.Grouped) { selectionSource = GetSelectionSource(selector, context, lastResult); lastResult = null; } List <ushort> key = new List <ushort>(); SelectorType removeSelectorType = 0; // determine the type of traversal & depth for this selector int depth = 0; bool descendants = true; switch (selector.TraversalType) { case TraversalType.Child: depth = selector.ChildDepth; descendants = false; break; case TraversalType.Filter: case TraversalType.Adjacent: case TraversalType.Sibling: depth = 0; descendants = false; break; case TraversalType.Descendent: depth = 1; descendants = true; break; // default: fall through with default values set above. } bool canUseBasicIndex = (selectionSource == null) && descendants && depth == 0; // build index keys when possible for the active index type if (rangedIndex != null || (simpleIndex != null && canUseBasicIndex) && !selector.NoIndex) { // We don't want to use the index for "NotEquals" selectors because a missing attribute // is considered a valid match if (selector.SelectorType.HasFlag(SelectorType.AttributeValue) && selector.AttributeSelectorType != AttributeSelectorType.NotExists && selector.AttributeSelectorType != AttributeSelectorType.NotEquals) { key.Add('!'); key.Add(HtmlData.Tokenize(selector.AttributeName)); // AttributeValue must still be matched manually - so remove this flag only if the // selector is conclusive without further checking if (selector.AttributeSelectorType == AttributeSelectorType.Exists) { removeSelectorType = SelectorType.AttributeValue; } } else if (selector.SelectorType.HasFlag(SelectorType.Tag)) { key.Add('+'); key.Add(HtmlData.Tokenize(selector.Tag)); removeSelectorType = SelectorType.Tag; } else if (selector.SelectorType.HasFlag(SelectorType.ID)) { key.Add('#'); key.Add(HtmlData.TokenizeCaseSensitive(selector.ID)); removeSelectorType = SelectorType.ID; } else if (selector.SelectorType.HasFlag(SelectorType.Class)) { key.Add('.'); key.Add(HtmlData.TokenizeCaseSensitive(selector.Class)); removeSelectorType = SelectorType.Class; } } // If part of the selector was indexed, key will not be empty. Return initial set from the // index. If any selectors remain after this they will be searched the hard way. IEnumerable <IDomObject> result = null; if (key.Count > 0) { // This is the main index access point: if we have an index key, we'll get as much as we can from the index. // Anything else will be handled manually. if (selectionSource == null) { // we don't need to test for index features at this point; if canUseBasicIndex = false and we // are here, then the prior logic dictates that the ranged index is available. But always use // the simple index if that's all we need because it could be faster. result = simpleIndex.QueryIndex(key.ToArray()); } else { HashSet <IDomObject> elementMatches = new HashSet <IDomObject>(); result = elementMatches; foreach (IDomObject obj in selectionSource) { var subKey = key.Concat(HtmlData.indexSeparator).Concat(obj.NodePath).ToArray(); var matches = rangedIndex.QueryIndex(subKey, depth, descendants); elementMatches.AddRange(matches); } } selector.SelectorType &= ~removeSelectorType; // Special case for attribute selectors: when Attribute Value attribute selector is present, we // still need to filter for the correct value afterwards. But we need to change the traversal // type because any nodes with the correct attribute type have already been selected. if (selector.SelectorType.HasFlag(SelectorType.AttributeValue)) { selector.TraversalType = TraversalType.Filter; } } // If any selectors were not handled via the index, match them manually if (selector.SelectorType != 0) { // if there are no temporary results (b/c there was no indexed selector) then use selection // source instead (e.g. start from the same point that the index would have) result = GetMatches(result ?? selectionSource ?? Document.ChildElements, selector); } lastResult = lastResult == null ? result : lastResult.Concat(result); } // After the loop has finished, output any results from the last iteration. output.AddRange(lastResult); // Return the results as a list so that any user will not cause the selector to be run again return(output.OrderBy(item => item.NodePath, Implementation.PathKeyComparer.Comparer).ToList()); }
protected void StartNewSelector(SelectorType positionType) { StartNewSelector(positionType, CombinatorType.Chained, TraversalType.Filter); }
private static SelectList GetSelectListObject(List <KeyValuePair <int, string> > list, int selectedValue, SelectorType selector) { list = AddDefaultSelected(list, selector); SelectList result = null; if (selectedValue == Constants.DEFAULT_VALUE_INT) { result = new SelectList(list, KEY_VALUE_PAIR_KEY, KEY_VALUE_PAIR_VALUE); } else { result = new SelectList(list, KEY_VALUE_PAIR_KEY, KEY_VALUE_PAIR_VALUE, selectedValue); } return(result); }
protected Specificity CalculateSpecificity(SelectorType type) { return this.specificity += type; }
public IList <IDomElement <TDependencyObject, TDependencyProperty> > QuerySelectorAll(StyleSheet styleSheet, ISelector selector, SelectorType type) { var children = (type == SelectorType.LogicalTree ? LogicalChildNodes : ChildNodes); return(children.QuerySelectorAll(styleSheet, selector, type)); }
/// <summary> /// 构造方法 /// </summary> /// <param name="type">选择器类型</param> /// <param name="expression">表达式</param> public SelectorAttribute(SelectorType type, string expression) { Type = type; Expression = expression; }
public void Add(string templateName, string selector, SelectorType selectorType) { Add(templateName, selector, selectorType, c => true); }
public void SetDomElement(DependencyObject obj, IDomElement <DependencyObject> value, SelectorType selectorType) { if (selectorType == SelectorType.LogicalTree) { Css.SetDomElement(obj, value); } else { Css.SetVisualDomElement(obj, value); } }
private static void EnsureParents(IDomElement <TDependencyObject, TDependencyProperty> domElement, ITreeNodeProvider <TDependencyObject, TDependencyProperty> treeNodeProvider, IDependencyPropertyService <TDependencyObject, TStyle, TDependencyProperty> dependencyPropertyService, INativeStyleService <TStyle, TDependencyObject, TDependencyProperty> nativeStyleService, IDictionary <TDependencyObject, StyleUpdateInfo> styleUpdateInfos, SelectorType type) { var current = type == SelectorType.VisualTree ? domElement.Parent : domElement.LogicalParent; while (current != null && current.IsReady) { var styleUpdateInfo = current.StyleInfo = current.StyleInfo ?? (styleUpdateInfos.ContainsKey(current.Element) ? styleUpdateInfos[current.Element] : GetNewStyleUpdateInfo(current, dependencyPropertyService, nativeStyleService)); if ((styleUpdateInfo.DoMatchCheck & type) != type) { return; } object a; a = current.ClassList; //"Id".Measure(() => a = current.Id); a = current.TagName; a = current.AssemblyQualifiedNamespaceName; //"HasAttribute".Measure(() => a = current.HasAttribute("Name")); /*// a = domElement.Parent; */ if (type == SelectorType.VisualTree) { a = current.ChildNodes; current = current.Parent; } else { a = current.LogicalChildNodes; current = current.LogicalParent; } } }
public TargetSelector(SelectorType type) { this.type = type; }
public BaseSelector(SelectorType type, string expression) : base(type, expression) { }
public bool HasNoSelector(string path, SelectorType selector, int count = 1, bool visible = true, string text = null) { return(!HasSelector(path, selector, count, visible, text)); }
public Selector(SelectorType type) { qualifiers = new List <Qualifier>(); this.type = type; SelectEvalMethod(); }
/// <summary> /// Initializes a new instance of the <see cref="SnapshotSelectorAttribute"/> class. /// </summary> /// <param name="expression">The expression.</param> /// <param name="selectorType">Type of the selector.</param> /// <param name="name">The name.</param> public SnapshotSelectorAttribute(string expression, SelectorType selectorType, string name) : base(expression, selectorType, name) { }
/// <summary> /// 构造方法 /// </summary> /// <param name="expression">表达式</param> /// <param name="type">选择器类型</param> /// <param name="arguments">参数</param> public SelectAttribute(string expression, SelectorType type = SelectorType.XPath, string arguments = null) { Type = type; Expression = expression; Arguments = arguments; }
public void ClickButton(string selector = null, SelectorType type = SelectorType.Css, string text = null) { selector = String.Format("{0}[@value={1}]", selector ?? ElementType.Button.GetStringValue(), text); new Query(_browser, selector, SelectorType.XPath).Results.First().Click(); }
public Selector(SelectorType selectorType, string selectorValue) { SelectorType = selectorType; SelectorValue = selectorValue; }
public void ClickOn(string selector = null, SelectorType type = SelectorType.Css, string text = null) { selector = selector ?? ElementType.LinkOrButton.GetStringValue(); new Query(_browser, selector, SelectorType.XPath, text: text).Results.First().Click(); }
private void OnEnable() { selectorType = (SelectorType)target; }
public void FillIn(string value, string selector = null, SelectorType type = SelectorType.Css, string labelText = null) { IWebElement element; if(selector == null) { var label = new Query(_browser, ElementType.Label, SelectorType.XPath, text: labelText).Results.First(); element = _browser.FindElement(By.Id(label.GetAttribute("for"))); } else { element = new Query(_browser, selector, SelectorType.XPath).Results.First(); } element.SendKeys(value); }
public bool HasSelector(string path, SelectorType selector, int count = 1, bool visible = true, string text = null) { throw new NotImplementedException(); }
//Gets the strings for the selection grids internal string[] TextureEntries(SelectorType type) { if (this.textures == null) { return new string[0]; } string[] texts = new string[0]; switch (type) { case SelectorType.CASE: this.textures.TryGetCasesOfType(this.type, ref texts); break; case SelectorType.CHUTE: return this.textures.canopyNames; case SelectorType.MODEL: this.textures.TryGetParameterModels(this.chutes.Count, ref texts); break; default: return new string[0]; } return texts; }
/// <summary> /// Return all elements matching a selector, within a list of elements. This function will /// traverse children, but it is expected that the source list at the current depth (e.g. from an /// Adjacent or Sibling selector) is already processed. /// </summary> /// /// <param name="source"> /// The sequence of elements to filter. /// </param> /// <param name="selector"> /// The selector. /// </param> /// /// <returns> /// The sequence of elements matching the selector. /// </returns> protected IEnumerable <IDomObject> GetMatches(IEnumerable <IDomObject> source, SelectorClause selector) { // Maintain a hashset of every element already searched. Since result sets frequently contain items which are // children of other items in the list, we would end up searching the tree repeatedly HashSet <IDomObject> uniqueElements = null; // The processing stack Stack <MatchElement> stack = null; // The source list for the current iteration IEnumerable <IDomObject> curList = source; // the results obtained so far in this iteration HashSet <IDomObject> temporaryResults = new HashSet <IDomObject>(); // The unique list has to be reset for each sub-selector uniqueElements = new HashSet <IDomObject>(); if (selector.SelectorType.HasFlag(SelectorType.Elements)) { var set = GetAllChildOrDescendants(selector.TraversalType, source); return(set.Intersect(selector.SelectElements)); } // For the jQuery extensions (which are mapped to the position in the output, not the DOM) we have to enumerate // the results first, rather than targeting specific child elements. Handle it here, else if (selector.SelectorType.HasFlag(SelectorType.PseudoClass)) { if (selector.IsResultListPosition) { return(GetResultPositionMatches(curList, selector)); } } else if (selector.SelectorType.HasFlag(SelectorType.All)) { return(GetAllChildOrDescendants(selector.TraversalType, curList)); } // Otherwise, try to match each element individually stack = new Stack <MatchElement>(); foreach (var obj in curList) { // We must check everything again when looking for specific depth of children // otherwise - no point - skip em IDomElement el = obj as IDomElement; if (el == null || selector.TraversalType != TraversalType.Child && uniqueElements.Contains(el)) { continue; } stack.Push(new MatchElement(el, 0)); int matchIndex = 0; while (stack.Count != 0) { var current = stack.Pop(); if (Matches(selector, current.Element, current.Depth)) { temporaryResults.Add(current.Element); matchIndex++; } // Add children to stack (in reverse order, so they are processed in the correct order when popped) // Don't keep going to children if the target depth is < the depth. Though the match would still fail, // stuff would end up the unique list which we might need to test later if it appears directly in the source list // causing it to be ignored. if (selector.TraversalType != TraversalType.Filter && (selector.TraversalType != TraversalType.Child || selector.ChildDepth > current.Depth)) { SelectorType selectorType = selector.SelectorType; IDomElement elm = current.Element; if (selector.IsDomPositionPseudoSelector && ((selector.TraversalType == TraversalType.All) || (selector.TraversalType == TraversalType.Child && selector.ChildDepth == current.Depth + 1) || (selector.TraversalType == TraversalType.Descendent && selector.ChildDepth <= current.Depth + 1))) { temporaryResults.AddRange(GetPseudoClassMatches(elm, selector)); selectorType &= ~SelectorType.PseudoClass; } if (selectorType == 0) { continue; } for (int j = elm.ChildNodes.Count - 1; j >= 0; j--) { IDomElement child = elm[j] as IDomElement; if (child == null || !uniqueElements.Add(child)) { continue; } if (child.NodeType == NodeType.ELEMENT_NODE) { stack.Push(new MatchElement(child, current.Depth + 1)); } } } } } return(temporaryResults); }
/// <summary> /// Start a new chained filter selector of the specified type. /// </summary> /// /// <param name="selectorType"> /// The selector type to start. /// </param> protected void StartNewSelector(SelectorType selectorType) { StartNewSelector(selectorType, NextCombinatorType, NextTraversalType); }
/// <summary> /// Returns a string representation of the parsed selector. This may not exactly match the input /// selector as it is regenerated. /// </summary> /// /// <returns> /// A CSS selector string. /// </returns> public override string ToString() { string output = ""; switch (TraversalType) { case TraversalType.Child: output += " > "; break; case TraversalType.Descendent: output += " "; break; case TraversalType.Adjacent: output += " + "; break; case TraversalType.Sibling: output += " ~ "; break; } if (SelectorType.HasFlag(SelectorType.Elements)) { output += "<ElementList[" + SelectElements.Count() + "]> "; } if (SelectorType.HasFlag(SelectorType.HTML)) { output += "<HTML[" + Html.Length + "]> "; } if (SelectorType.HasFlag(SelectorType.Tag)) { output += Tag; } if (SelectorType.HasFlag(SelectorType.ID)) { output += "#" + ID; } if (SelectorType.HasFlag(SelectorType.AttributeValue) //|| SelectorType.HasFlag(SelectorType.AttributeExists) ) { output += "[" + AttributeName; if (!String.IsNullOrEmpty(AttributeValue)) { output += "." + AttributeSelectorType.ToString() + ".'" + AttributeValue + "'"; } output += "]"; } if (SelectorType.HasFlag(SelectorType.Class)) { output += "." + Class; } if (SelectorType.HasFlag(SelectorType.All)) { output += "*"; } if (SelectorType.HasFlag(SelectorType.PseudoClass)) { output += ":" + PseudoSelector.Name; if (PseudoSelector.Arguments != null && PseudoSelector.Arguments.Length > 0) { output += "(" + String.Join(",", PseudoSelector.Arguments) + ")"; } } return(output); }
/// <summary> /// Close the currently active selector. If it's partial (e.g. a descendant/child marker) then merge its into into the /// new selector created. /// </summary> /// <param name="selectorType"></param> /// <param name="combinatorType"></param> /// <param name="traversalType"></param> protected void StartNewSelector(SelectorType selectorType, CombinatorType combinatorType, TraversalType traversalType) { // if a selector was not finished, do not overwrite the existing combinator & traversal types, // as they could have been changed by a descendant or child selector. The exception is when // the new selector is an explicit "all" type; we always // a new selector will not have been started if there was an explicit "*" creating an all. However, if there's // anything other than a filter, we do actually want if (Current.IsComplete && Current.SelectorType != SelectorType.All || traversalType != TraversalType.Filter) { FinishSelector(); Current.CombinatorType = combinatorType; Current.TraversalType = traversalType; } Current.SelectorType = selectorType; }
private static SelectList GetSelectListObject(List <KeyValuePair <int?, string> > list, int?selectedValue, SelectorType selector) { list = AddDefaultSelected(list, selector); SelectList result = null; if (!selectedValue.HasValue) { result = new SelectList(list, KEY_VALUE_PAIR_KEY, KEY_VALUE_PAIR_VALUE); } else { result = new SelectList(list, KEY_VALUE_PAIR_KEY, KEY_VALUE_PAIR_VALUE, selectedValue.Value); } return(result); }
private void DrawSelector(SelectorType selectorType) { DestroyImmediate(pcObject.GetComponent<ProximitySelector>()); Selector selector = pcObject.GetComponent<Selector>() ?? pcObject.AddComponent<Selector>(); EditorWindowTools.StartIndentedSection(); switch (selectorType) { case SelectorType.CenterOfScreen: EditorGUILayout.HelpBox("Usable objects in the center of the screen will be targeted.", MessageType.None); selector.selectAt = Selector.SelectAt.CenterOfScreen; break; case SelectorType.MousePosition: EditorGUILayout.HelpBox("Usable objects under the mouse cursor will be targeted. Specify which mouse button activates the targeted object.", MessageType.None); selector.selectAt = Selector.SelectAt.MousePosition; MouseButtonChoice mouseButtonChoice = string.Equals(selector.useButton, "Fire2") ? MouseButtonChoice.RightMouseButton : MouseButtonChoice.LeftMouseButton; mouseButtonChoice = (MouseButtonChoice) EditorGUILayout.EnumPopup("Select With", mouseButtonChoice); selector.useButton = (mouseButtonChoice == MouseButtonChoice.RightMouseButton) ? "Fire2" : "Fire1"; break; default: case SelectorType.CustomPosition: EditorGUILayout.HelpBox("Usable objects will be targeted at a custom screen position. You are responsible for setting the Selector component's CustomPosition property.", MessageType.None); selector.selectAt = Selector.SelectAt.CustomPosition; break; } if (selector.reticle != null) { selector.reticle.inRange = EditorGUILayout.ObjectField("In-Range Reticle", selector.reticle.inRange, typeof(Texture2D), false) as Texture2D; selector.reticle.outOfRange = EditorGUILayout.ObjectField("Out-of-Range Reticle", selector.reticle.outOfRange, typeof(Texture2D), false) as Texture2D; } DrawSelectorUIPosition(); selector.useKey = (KeyCode) EditorGUILayout.EnumPopup("'Use' Key", selector.useKey); selector.useButton = EditorGUILayout.TextField("'Use' Button", selector.useButton); EditorGUILayout.HelpBox("Click Select Player to customize the Selector.", MessageType.None); EditorWindowTools.EndIndentedSection(); }
private static List <KeyValuePair <int, string> > AddDefaultSelected(List <KeyValuePair <int, string> > list, SelectorType selector) { switch (selector) { case SelectorType.WithSelect: list.Insert(0, new KeyValuePair <int, string>(Constants.DEFAULT_VALUE_INT, DEFAULT_TEXT_SELECT)); break; case SelectorType.WithAll: list.Insert(0, new KeyValuePair <int, string>(Constants.DEFAULT_VALUE_INT, DEFAULT_TEXT_ALL)); break; } return(list); }
public SimpleSelector(SelectorType type, string name) { Type = type; Name = name; }
public bool Contains(IDomElement <TDependencyObject, TDependencyProperty> otherNode, SelectorType type) { return(type == SelectorType.VisualTree ? ChildNodes.Contains(otherNode) : LogicalChildNodes.Contains(otherNode)); }
public bool Has(string path, SelectorType selector) { return HasSelector(path, SelectorType.XPath); }
public IList <IDomElement <TDependencyObject, TDependencyProperty> > QuerySelectorAllWithSelf(StyleSheet styleSheet, ISelector selector, SelectorType type) { if (!IsReady || !ReferenceEquals(StyleInfo.CurrentStyleSheet, styleSheet) || StyleInfo.DoMatchCheck == SelectorType.None) { return(new List <IDomElement <TDependencyObject, TDependencyProperty> >()); } if (type == SelectorType.LogicalTree && !IsInLogicalTree) { return(new List <IDomElement <TDependencyObject, TDependencyProperty> >()); } else if (type == SelectorType.VisualTree && !IsInVisualTree) { return(new List <IDomElement <TDependencyObject, TDependencyProperty> >()); } var res = (type == SelectorType.LogicalTree ? LogicalChildNodes : ChildNodes).QuerySelectorAll(styleSheet, selector, type); var match = Matches(styleSheet, selector); if (match.IsSuccess) { res.Add(this); } return(res); }
public bool HasNoSelector(string path, SelectorType selector, int count = 1, bool visible = true, string text = null) { return !HasSelector(path, selector, count, visible, text); }
/// <summary> /// 构造方法 /// </summary> /// <param name="expression">表达式</param> /// <param name="type">选择器类型</param> /// <param name="arguments">参数</param> public Selector(string expression, SelectorType type, string arguments = null) { Type = type; Expression = expression; Arguments = arguments; }
public void Add(string templateName, string selector, SelectorType selectorType, string pageName) { Add(templateName, selector, selectorType, pageName, ""); }
/// <summary> /// An internal constructor; see static methods for public interface /// </summary> /// <param name="type">Selector type</param> /// <param name="name">Base page name</param> private Selector(SelectorType type, string name) : this(type, Namespace.Main, name) { }