/// <summary>Removes this selector from all the computed styles it affects, except for the target. /// Use ComputedStyle.RemoveMatch(x) instead of calling this directly.</summary> internal void Remove() { for (int i = 0; i < MatchedRoots.Length; i++) { // Remove it (if it's the target and it was active, it'll also remove the style for us too): MatchingRoot root = MatchedRoots[i]; // Remove from matches: ComputedStyle cs = (root.Node as IRenderableNode).ComputedStyle; // Remove the node: if (root.NextInStyle == null) { cs.LastMatch = root.PreviousInStyle; } else { root.NextInStyle.PreviousInStyle = root.PreviousInStyle; } if (root.PreviousInStyle == null) { cs.FirstMatch = root.NextInStyle; } else { root.PreviousInStyle.NextInStyle = root.NextInStyle; } if (root.IsTarget && Active) { // Remove props: cs.MatchChanged(Style, false); } } }
/// <summary>Figures out if this root is active or not. /// That may, in turn, figure out if the whole selector is/ is not.</summary> public void ResetActive() { // Get the local matchers: LocalMatcher[] locals = Root.LocalMatchers; bool active = true; if (locals != null) { // For each one.. for (int i = 0; i < locals.Length; i++) { // Is it active? if (!locals[i].TryMatch(Node)) { active = false; break; } } } if (active == Active) { return; } // Active changed! Active = active; // Tell the selector: int activeCount = Selector.ActiveRoots; if (active) { activeCount++; } else { activeCount--; } Selector.ActiveRoots = activeCount; if (activeCount == Selector.RootCount) { // They're all active! Selector.Active = true; if (Selector.Target != null) { // Apply target: ComputedStyle cs = Selector.Target.computedStyle; // Apply now! cs.MatchChanged(Style, true); } } else if (Selector.Active) { // The selector is no longer active. Selector.Active = false; if (Selector.Target != null) { // Apply target: ComputedStyle cs = Selector.Target.computedStyle; // Apply now! cs.MatchChanged(Style, false); } } }