forked from AvaloniaUI/Avalonia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,025 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) The Perspex Project. All rights reserved. | ||
// Licensed under the MIT license. See licence.md file in the project root for full license information. | ||
|
||
using System; | ||
using Perspex.LogicalTree; | ||
|
||
namespace Perspex.Styling | ||
{ | ||
internal class ChildSelector : Selector | ||
{ | ||
private readonly Selector _parent; | ||
private string _selectorString; | ||
|
||
public ChildSelector(Selector parent) | ||
{ | ||
if (parent == null) | ||
{ | ||
throw new InvalidOperationException("Child selector must be preceeded by a selector."); | ||
} | ||
|
||
_parent = parent; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override bool InTemplate => _parent.InTemplate; | ||
|
||
/// <inheritdoc/> | ||
public override Type TargetType => null; | ||
|
||
public override string ToString() | ||
{ | ||
if (_selectorString == null) | ||
{ | ||
_selectorString = _parent.ToString() + " > "; | ||
} | ||
|
||
return _selectorString; | ||
} | ||
|
||
protected override SelectorMatch Evaluate(IStyleable control, bool subscribe) | ||
{ | ||
var controlParent = ((ILogical)control).LogicalParent; | ||
|
||
if (controlParent != null) | ||
{ | ||
return _parent.Match((IStyleable)controlParent, subscribe); | ||
} | ||
else | ||
{ | ||
return SelectorMatch.False; | ||
} | ||
} | ||
|
||
protected override Selector MovePrevious() => null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) The Perspex Project. All rights reserved. | ||
// Licensed under the MIT license. See licence.md file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Perspex.LogicalTree; | ||
|
||
namespace Perspex.Styling | ||
{ | ||
internal class DescendentSelector : Selector | ||
{ | ||
private readonly Selector _parent; | ||
private string _selectorString; | ||
|
||
public DescendentSelector(Selector parent) | ||
{ | ||
if (parent == null) | ||
{ | ||
throw new InvalidOperationException("Descendent selector must be preceeded by a selector."); | ||
} | ||
|
||
_parent = parent; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override bool InTemplate => _parent.InTemplate; | ||
|
||
/// <inheritdoc/> | ||
public override Type TargetType => null; | ||
|
||
public override string ToString() | ||
{ | ||
if (_selectorString == null) | ||
{ | ||
_selectorString = _parent.ToString() + ' '; | ||
} | ||
|
||
return _selectorString; | ||
} | ||
|
||
protected override SelectorMatch Evaluate(IStyleable control, bool subscribe) | ||
{ | ||
ILogical c = (ILogical)control; | ||
List<IObservable<bool>> descendentMatches = new List<IObservable<bool>>(); | ||
|
||
while (c != null) | ||
{ | ||
c = c.LogicalParent; | ||
|
||
if (c is IStyleable) | ||
{ | ||
var match = _parent.Match((IStyleable)c, subscribe); | ||
|
||
if (match.ImmediateResult != null) | ||
{ | ||
if (match.ImmediateResult == true) | ||
{ | ||
return SelectorMatch.True; | ||
} | ||
} | ||
else | ||
{ | ||
descendentMatches.Add(match.ObservableResult); | ||
} | ||
} | ||
} | ||
|
||
if (descendentMatches.Count > 0) | ||
{ | ||
return new SelectorMatch(StyleActivator.Or(descendentMatches)); | ||
} | ||
else | ||
{ | ||
return SelectorMatch.False; | ||
} | ||
} | ||
|
||
protected override Selector MovePrevious() => null; | ||
} | ||
} |
Oops, something went wrong.