Browse Source

Merge branch 'master' into fixes/selectableTextBlock

pull/10821/head
Max Katz 4 years ago
committed by GitHub
parent
commit
870ffbd13d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/Avalonia.Base/CombinedGeometry.cs
  2. 5
      src/Avalonia.Base/Media/GeometryGroup.cs
  3. 4
      src/Avalonia.Base/Platform/IPlatformRenderInterface.cs
  4. 12
      src/Avalonia.Base/PropertyStore/EffectiveValue`1.cs
  5. 8
      src/Avalonia.Base/PropertyStore/ValueStore.cs
  6. 4
      src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs
  7. 7
      src/Skia/Avalonia.Skia/CombinedGeometryImpl.cs
  8. 7
      src/Skia/Avalonia.Skia/GeometryGroupImpl.cs
  9. 4
      src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
  10. 4
      src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs
  11. 13
      src/Windows/Avalonia.Direct2D1/Media/CombinedGeometryImpl.cs
  12. 7
      src/Windows/Avalonia.Direct2D1/Media/GeometryGroupImpl.cs
  13. 30
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Inheritance.cs
  14. 19
      tests/Avalonia.Base.UnitTests/Media/GlyphRunTests.cs
  15. 4
      tests/Avalonia.Base.UnitTests/VisualTree/MockRenderInterface.cs
  16. 4
      tests/Avalonia.Benchmarks/NullRenderingPlatform.cs
  17. 9
      tests/Avalonia.Controls.UnitTests/MaskedTextBoxTests.cs
  18. 4
      tests/Avalonia.UnitTests/MockPlatformRenderInterface.cs

14
src/Avalonia.Base/CombinedGeometry.cs

@ -152,19 +152,15 @@ namespace Avalonia.Media
var g1 = Geometry1;
var g2 = Geometry2;
if (g1 is object && g2 is object)
if (g1?.PlatformImpl != null && g2?.PlatformImpl != null)
{
var factory = AvaloniaLocator.Current.GetRequiredService<IPlatformRenderInterface>();
return factory.CreateCombinedGeometry(GeometryCombineMode, g1, g2);
return factory.CreateCombinedGeometry(GeometryCombineMode, g1.PlatformImpl, g2.PlatformImpl);
}
else if (GeometryCombineMode == GeometryCombineMode.Intersect)
return null;
else if (g1 is object)
return g1.PlatformImpl;
else if (g2 is object)
return g2.PlatformImpl;
else
if (GeometryCombineMode == GeometryCombineMode.Intersect)
return null;
return g1?.PlatformImpl ?? g2?.PlatformImpl;
}
}
}

5
src/Avalonia.Base/Media/GeometryGroup.cs

@ -78,7 +78,10 @@ namespace Avalonia.Media
{
var factory = AvaloniaLocator.Current.GetRequiredService<IPlatformRenderInterface>();
return factory.CreateGeometryGroup(FillRule, _children);
var children = new IGeometryImpl?[_children.Count];
for (var c = 0; c < _children.Count; c++)
children[c] = _children[c].PlatformImpl;
return factory.CreateGeometryGroup(FillRule, children!);
}
return null;

4
src/Avalonia.Base/Platform/IPlatformRenderInterface.cs

@ -48,7 +48,7 @@ namespace Avalonia.Platform
/// <param name="fillRule">The fill rule.</param>
/// <param name="children">The geometries to group.</param>
/// <returns>A combined geometry.</returns>
IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<Geometry> children);
IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<IGeometryImpl> children);
/// <summary>
/// Creates a geometry group implementation.
@ -57,7 +57,7 @@ namespace Avalonia.Platform
/// <param name="g1">The first geometry.</param>
/// <param name="g2">The second geometry.</param>
/// <returns>A combined geometry.</returns>
IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, Geometry g1, Geometry g2);
IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, IGeometryImpl g1, IGeometryImpl g2);
/// <summary>
/// Created a geometry implementation for the glyph run.

12
src/Avalonia.Base/PropertyStore/EffectiveValue`1.cs

@ -140,24 +140,24 @@ namespace Avalonia.PropertyStore
var p = (StyledProperty<T>)property;
BindingPriority priority;
T oldValue;
T newValue;
if (property.Inherits && owner.TryGetInheritedValue(property, out var i))
{
oldValue = ((EffectiveValue<T>)i).Value;
newValue = ((EffectiveValue<T>)i).Value;
priority = BindingPriority.Inherited;
}
else
{
oldValue = _metadata.DefaultValue;
newValue = _metadata.DefaultValue;
priority = BindingPriority.Unset;
}
if (!EqualityComparer<T>.Default.Equals(oldValue, Value))
if (!EqualityComparer<T>.Default.Equals(newValue, Value))
{
owner.Owner.RaisePropertyChanged(p, Value, oldValue, priority, true);
owner.Owner.RaisePropertyChanged(p, Value, newValue, priority, true);
if (property.Inherits)
owner.OnInheritedEffectiveValueDisposed(p, Value);
owner.OnInheritedEffectiveValueDisposed(p, Value, newValue);
}
if (ValueEntry?.GetDataValidationState(out _, out _) ??

8
src/Avalonia.Base/PropertyStore/ValueStore.cs

@ -419,7 +419,9 @@ namespace Avalonia.PropertyStore
ReevaluateEffectiveValue(property, current);
}
else
{
ReevaluateEffectiveValues();
}
}
/// <summary>
@ -481,7 +483,8 @@ namespace Avalonia.PropertyStore
/// </summary>
/// <param name="property">The property whose value changed.</param>
/// <param name="oldValue">The old value of the property.</param>
public void OnInheritedEffectiveValueDisposed<T>(StyledProperty<T> property, T oldValue)
/// <param name="newValue">The new value of the property.</param>
public void OnInheritedEffectiveValueDisposed<T>(StyledProperty<T> property, T oldValue, T newValue)
{
Debug.Assert(property.Inherits);
@ -489,12 +492,11 @@ namespace Avalonia.PropertyStore
if (children is not null)
{
var defaultValue = property.GetDefaultValue(Owner.GetType());
var count = children.Count;
for (var i = 0; i < count; ++i)
{
children[i].GetValueStore().OnAncestorInheritedValueChanged(property, oldValue, defaultValue);
children[i].GetValueStore().OnAncestorInheritedValueChanged(property, oldValue, newValue);
}
}
}

4
src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs

@ -47,8 +47,8 @@ namespace Avalonia.Headless
}
public IStreamGeometryImpl CreateStreamGeometry() => new HeadlessStreamingGeometryStub();
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<Geometry> children) => throw new NotImplementedException();
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, Geometry g1, Geometry g2) => throw new NotImplementedException();
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<IGeometryImpl> children) => throw new NotImplementedException();
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, IGeometryImpl g1, IGeometryImpl g2) => throw new NotImplementedException();
public IRenderTarget CreateRenderTarget(IEnumerable<object> surfaces) => new HeadlessRenderTarget();
public bool IsLost => false;

7
src/Skia/Avalonia.Skia/CombinedGeometryImpl.cs

@ -1,4 +1,5 @@
using Avalonia.Media;
using Avalonia.Platform;
using SkiaSharp;
namespace Avalonia.Skia
@ -15,10 +16,10 @@ namespace Avalonia.Skia
Bounds = (stroke ?? fill)?.TightBounds.ToAvaloniaRect() ?? default;
}
public static CombinedGeometryImpl ForceCreate(GeometryCombineMode combineMode, Geometry g1, Geometry g2)
public static CombinedGeometryImpl ForceCreate(GeometryCombineMode combineMode, IGeometryImpl g1, IGeometryImpl g2)
{
if (g1.PlatformImpl is GeometryImpl i1
&& g2.PlatformImpl is GeometryImpl i2
if (g1 is GeometryImpl i1
&& g2 is GeometryImpl i2
&& TryCreate(combineMode, i1, i2) is { } result)
return result;

7
src/Skia/Avalonia.Skia/GeometryGroupImpl.cs

@ -1,5 +1,6 @@
using System.Collections.Generic;
using Avalonia.Media;
using Avalonia.Platform;
using SkiaSharp;
namespace Avalonia.Skia
@ -9,7 +10,7 @@ namespace Avalonia.Skia
/// </summary>
internal class GeometryGroupImpl : GeometryImpl
{
public GeometryGroupImpl(FillRule fillRule, IReadOnlyList<Geometry> children)
public GeometryGroupImpl(FillRule fillRule, IReadOnlyList<IGeometryImpl> children)
{
var fillType = fillRule == FillRule.NonZero ? SKPathFillType.Winding : SKPathFillType.EvenOdd;
var count = children.Count;
@ -22,7 +23,7 @@ namespace Avalonia.Skia
bool requiresFillPass = false;
for (var i = 0; i < count; ++i)
{
if (children[i].PlatformImpl is GeometryImpl geo)
if (children[i] is GeometryImpl geo)
{
if (geo.StrokePath != null)
stroke.AddPath(geo.StrokePath);
@ -42,7 +43,7 @@ namespace Avalonia.Skia
for (var i = 0; i < count; ++i)
{
if (children[i].PlatformImpl is GeometryImpl { FillPath: { } fillPath })
if (children[i] is GeometryImpl { FillPath: { } fillPath })
fill.AddPath(fillPath);
}

4
src/Skia/Avalonia.Skia/PlatformRenderInterface.cs

@ -58,12 +58,12 @@ namespace Avalonia.Skia
return new StreamGeometryImpl();
}
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<Geometry> children)
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<IGeometryImpl> children)
{
return new GeometryGroupImpl(fillRule, children);
}
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, Geometry g1, Geometry g2)
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, IGeometryImpl g1, IGeometryImpl g2)
{
return CombinedGeometryImpl.ForceCreate(combineMode, g1, g2);
}

4
src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs

@ -158,8 +158,8 @@ namespace Avalonia.Direct2D1
public IGeometryImpl CreateLineGeometry(Point p1, Point p2) => new LineGeometryImpl(p1, p2);
public IGeometryImpl CreateRectangleGeometry(Rect rect) => new RectangleGeometryImpl(rect);
public IStreamGeometryImpl CreateStreamGeometry() => new StreamGeometryImpl();
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<Geometry> children) => new GeometryGroupImpl(fillRule, children);
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, Geometry g1, Geometry g2) => new CombinedGeometryImpl(combineMode, g1, g2);
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<IGeometryImpl> children) => new GeometryGroupImpl(fillRule, children);
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, IGeometryImpl g1, IGeometryImpl g2) => new CombinedGeometryImpl(combineMode, g1, g2);
public IGlyphRunImpl CreateGlyphRun(IGlyphTypeface glyphTypeface, double fontRenderingEmSize,
IReadOnlyList<GlyphInfo> glyphInfos, Point baselineOrigin)

13
src/Windows/Avalonia.Direct2D1/Media/CombinedGeometryImpl.cs

@ -1,3 +1,4 @@
using Avalonia.Platform;
using SharpDX.Direct2D1;
using AM = Avalonia.Media;
@ -13,19 +14,19 @@ namespace Avalonia.Direct2D1.Media
/// </summary>
public CombinedGeometryImpl(
AM.GeometryCombineMode combineMode,
AM.Geometry geometry1,
AM.Geometry geometry2)
IGeometryImpl geometry1,
IGeometryImpl geometry2)
: base(CreateGeometry(combineMode, geometry1, geometry2))
{
}
private static Geometry CreateGeometry(
AM.GeometryCombineMode combineMode,
AM.Geometry geometry1,
AM.Geometry geometry2)
IGeometryImpl geometry1,
IGeometryImpl geometry2)
{
var g1 = ((GeometryImpl)geometry1.PlatformImpl).Geometry;
var g2 = ((GeometryImpl)geometry2.PlatformImpl).Geometry;
var g1 = ((GeometryImpl)geometry1).Geometry;
var g2 = ((GeometryImpl)geometry2).Geometry;
var dest = new PathGeometry(Direct2D1Platform.Direct2D1Factory);
using var sink = dest.Open();
g1.Combine(g2, (CombineMode)combineMode, sink);

7
src/Windows/Avalonia.Direct2D1/Media/GeometryGroupImpl.cs

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Avalonia.Platform;
using SharpDX.Direct2D1;
using AM = Avalonia.Media;
@ -12,19 +13,19 @@ namespace Avalonia.Direct2D1.Media
/// <summary>
/// Initializes a new instance of the <see cref="StreamGeometryImpl"/> class.
/// </summary>
public GeometryGroupImpl(AM.FillRule fillRule, IReadOnlyList<AM.Geometry> geometry)
public GeometryGroupImpl(AM.FillRule fillRule, IReadOnlyList<IGeometryImpl> geometry)
: base(CreateGeometry(fillRule, geometry))
{
}
private static Geometry CreateGeometry(AM.FillRule fillRule, IReadOnlyList<AM.Geometry> children)
private static Geometry CreateGeometry(AM.FillRule fillRule, IReadOnlyList<IGeometryImpl> children)
{
var count = children.Count;
var c = new Geometry[count];
for (var i = 0; i < count; ++i)
{
c[i] = ((GeometryImpl)children[i].PlatformImpl).Geometry;
c[i] = ((GeometryImpl)children[i]).Geometry;
}
return new GeometryGroup(Direct2D1Platform.Direct2D1Factory, (FillMode)fillRule, c);

30
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Inheritance.cs

@ -1,5 +1,10 @@
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Data;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.UnitTests;
using Xunit;
namespace Avalonia.Base.UnitTests
@ -90,6 +95,31 @@ namespace Avalonia.Base.UnitTests
Assert.Equal(1, raised);
}
[Fact]
public void ClearValue_On_Parent_Raises_PropertyChanged_On_Child_With_Inherited_Grandparent_Value()
{
var grandparent = new Class1();
var parent = new Class2 { Parent = grandparent };
var child = new Class2 { Parent = parent };
var raised = 0;
grandparent.SetValue(Class1.BazProperty, "grandparent");
parent.SetValue(Class1.BazProperty, "parent");
child.PropertyChanged += (s, e) =>
{
Assert.Same(child, e.Sender);
Assert.Equal("parent", e.OldValue);
Assert.Equal("grandparent", e.NewValue);
Assert.Equal(BindingPriority.Inherited, e.Priority);
++raised;
};
parent.ClearValue(Class1.BazProperty);
Assert.Equal(1, raised);
}
[Fact]
public void Setting_InheritanceParent_Raises_PropertyChanged_When_Parent_Has_Value_Set()
{

19
tests/Avalonia.Base.UnitTests/Media/GlyphRunTests.cs

@ -1,22 +1,13 @@
using System;
using System.Linq;
using Avalonia.Media;
using Avalonia.Media.TextFormatting;
using Avalonia.Platform;
using Avalonia.UnitTests;
using Avalonia.Utilities;
using Xunit;
namespace Avalonia.Base.UnitTests.Media
{
public class GlyphRunTests : TestWithServicesBase
{
public GlyphRunTests()
{
AvaloniaLocator.CurrentMutable
.Bind<IPlatformRenderInterface>().ToSingleton<MockPlatformRenderInterface>();
}
[InlineData(new double[] { 30, 0, 0 }, new int[] { 0, 0, 0 }, 0, 0, 0)]
[InlineData(new double[] { 30, 0, 0 }, new int[] { 0, 0, 0 }, 0, 3, 30)]
[InlineData(new double[] { 10, 10, 10 }, new int[] { 0, 1, 2 }, 1, 0, 10)]
@ -25,7 +16,7 @@ namespace Avalonia.Base.UnitTests.Media
[Theory]
public void Should_Get_Distance_From_CharacterHit(double[] advances, int[] clusters, int start, int trailingLength, double expectedDistance)
{
using(UnitTestApplication.Start(TestServices.StyledWindow))
using (Start())
using (var glyphRun = CreateGlyphRun(advances, clusters))
{
var characterHit = new CharacterHit(start, trailingLength);
@ -44,7 +35,7 @@ namespace Avalonia.Base.UnitTests.Media
public void Should_Get_CharacterHit_FromDistance(double[] advances, int[] clusters, double distance, int start,
int trailingLengthExpected, bool isInsideExpected)
{
using(UnitTestApplication.Start(TestServices.StyledWindow))
using (Start())
using (var glyphRun = CreateGlyphRun(advances, clusters))
{
var textBounds = glyphRun.GetCharacterHitFromDistance(distance, out var isInside);
@ -190,5 +181,11 @@ namespace Avalonia.Base.UnitTests.Media
return new GlyphRun(new MockGlyphTypeface(), 10, new string('a', count).AsMemory(), glyphInfos, biDiLevel: bidiLevel);
}
private static IDisposable Start()
{
return UnitTestApplication.Start(TestServices.StyledWindow.With(
renderInterface: new MockPlatformRenderInterface()));
}
}
}

4
tests/Avalonia.Base.UnitTests/VisualTree/MockRenderInterface.cs

@ -30,12 +30,12 @@ namespace Avalonia.Base.UnitTests.VisualTree
return new MockStreamGeometry();
}
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<Geometry> children)
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<IGeometryImpl> children)
{
throw new NotImplementedException();
}
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, Geometry g1, Geometry g2)
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, IGeometryImpl g1, IGeometryImpl g2)
{
throw new NotImplementedException();
}

4
tests/Avalonia.Benchmarks/NullRenderingPlatform.cs

@ -32,12 +32,12 @@ namespace Avalonia.Benchmarks
return new MockStreamGeometryImpl();
}
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<Geometry> children)
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<IGeometryImpl> children)
{
throw new NotImplementedException();
}
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, Geometry g1, Geometry g2)
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, IGeometryImpl g1, IGeometryImpl g2)
{
throw new NotImplementedException();
}

9
tests/Avalonia.Controls.UnitTests/MaskedTextBoxTests.cs

@ -109,7 +109,7 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void CaretIndex_Can_Moved_To_Position_After_The_End_Of_Text_With_Arrow_Key()
{
using (Start(TestServices.StyledWindow))
using (Start())
{
var target = new MaskedTextBox
{
@ -184,7 +184,7 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void Control_Backspace_Should_Remove_The_Word_Before_The_Caret_If_There_Is_No_Selection()
{
using (Start(TestServices.StyledWindow))
using (Start())
{
MaskedTextBox textBox = new MaskedTextBox
{
@ -226,7 +226,7 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void Control_Delete_Should_Remove_The_Word_After_The_Caret_If_There_Is_No_Selection()
{
using (Start(TestServices.StyledWindow))
using (Start())
{
var textBox = new MaskedTextBox
{
@ -812,7 +812,7 @@ namespace Avalonia.Controls.UnitTests
bool fromClipboard,
string expected)
{
using (Start(TestServices.StyledWindow))
using (Start())
{
var target = new MaskedTextBox
{
@ -898,6 +898,7 @@ namespace Avalonia.Controls.UnitTests
standardCursorFactory: Mock.Of<ICursorFactory>());
private static TestServices Services => TestServices.MockThreadingInterface.With(
renderInterface: new MockPlatformRenderInterface(),
standardCursorFactory: Mock.Of<ICursorFactory>(),
textShaperImpl: new MockTextShaperImpl(),
fontManagerImpl: new MockFontManagerImpl());

4
tests/Avalonia.UnitTests/MockPlatformRenderInterface.cs

@ -72,12 +72,12 @@ namespace Avalonia.UnitTests
return new MockStreamGeometryImpl();
}
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<Geometry> children)
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<IGeometryImpl> children)
{
return Mock.Of<IGeometryImpl>();
}
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, Geometry g1, Geometry g2)
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, IGeometryImpl g1, IGeometryImpl g2)
{
return Mock.Of<IGeometryImpl>();
}

Loading…
Cancel
Save