Skip to content

Commit

Permalink
Prep VisualElement (and descendants) for removal of InternalsVisibleTo (
Browse files Browse the repository at this point in the history
  • Loading branch information
hartez authored and samhouts committed May 2, 2016
1 parent 70d0e40 commit 5f8f47f
Show file tree
Hide file tree
Showing 31 changed files with 384 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void Init ()
var label1 = new Label { Text = "This is a label on page 1" };
page1.Content = new StackLayout { Children = { button1, label1 } };
page1.Appearing += (sender, args) => {
page1.InvalidateMeasure (InvalidationTrigger.MeasureChanged);
((IVisualElementController)page1).InvalidateMeasure(InvalidationTrigger.MeasureChanged);
};

var page2 = new ContentPage { Title = "Page 2" };
Expand Down
3 changes: 2 additions & 1 deletion Xamarin.Forms.Core.UnitTests/GridTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Core.UnitTests
{
Expand Down Expand Up @@ -1555,7 +1556,7 @@ public void NestedInvalidateMeasureDoesNotCrash ()
bool fire = true;
child.SizeChanged += (sender, args) => {
if (fire)
child.InvalidateMeasure (InvalidationTrigger.Undefined);
((IVisualElementController)child).InvalidateMeasure(InvalidationTrigger.Undefined);
fire = false;
};

Expand Down
3 changes: 2 additions & 1 deletion Xamarin.Forms.Core/AbsoluteLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms
{
Expand Down Expand Up @@ -132,7 +133,7 @@ void ChildOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == LayoutFlagsProperty.PropertyName || e.PropertyName == LayoutBoundsProperty.PropertyName)
{
InvalidateMeasure(InvalidationTrigger.MeasureChanged);
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
UpdateChildrenLayout();
}
}
Expand Down
11 changes: 6 additions & 5 deletions Xamarin.Forms.Core/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Globalization;
using System.Windows.Input;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform;

namespace Xamarin.Forms
Expand All @@ -18,7 +19,7 @@ public class Button : View, IFontElement, IButtonController
BindableProperty.Create("ContentLayout", typeof(ButtonContentLayout), typeof(Button), new ButtonContentLayout(ButtonContentLayout.ImagePosition.Left, DefaultSpacing));

public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(Button), null,
propertyChanged: (bindable, oldVal, newVal) => ((Button)bindable).InvalidateMeasure(InvalidationTrigger.MeasureChanged));
propertyChanged: (bindable, oldVal, newVal) => ((Button)bindable).InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged));

public static readonly BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(Button), Color.Default);

Expand Down Expand Up @@ -178,7 +179,7 @@ static void FontStructPropertyChanged(BindableObject bindable, object oldValue,
if (button._cancelEvents)
return;

button.InvalidateMeasure(InvalidationTrigger.MeasureChanged);
button.InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);

button._cancelEvents = true;

Expand Down Expand Up @@ -219,7 +220,7 @@ void OnCommandChanged()
void OnSourceChanged(object sender, EventArgs eventArgs)
{
OnPropertyChanged(ImageProperty.PropertyName);
InvalidateMeasure(InvalidationTrigger.MeasureChanged);
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}

void OnSourcePropertyChanged(ImageSource oldvalue, ImageSource newvalue)
Expand All @@ -229,7 +230,7 @@ void OnSourcePropertyChanged(ImageSource oldvalue, ImageSource newvalue)
newvalue.SourceChanged += OnSourceChanged;
SetInheritedBindingContext(newvalue, BindingContext);
}
InvalidateMeasure(InvalidationTrigger.MeasureChanged);
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}

void OnSourcePropertyChanging(ImageSource oldvalue, ImageSource newvalue)
Expand All @@ -245,7 +246,7 @@ static void SpecificFontPropertyChanged(BindableObject bindable, object oldValue
if (button._cancelEvents)
return;

button.InvalidateMeasure(InvalidationTrigger.MeasureChanged);
button.InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);

button._cancelEvents = true;

Expand Down
9 changes: 5 additions & 4 deletions Xamarin.Forms.Core/Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms
{
Expand All @@ -17,10 +18,10 @@ public partial class Grid : Layout<View>
public static readonly BindableProperty ColumnSpanProperty = BindableProperty.CreateAttached("ColumnSpan", typeof(int), typeof(Grid), 1, validateValue: (bindable, value) => (int)value >= 1);

public static readonly BindableProperty RowSpacingProperty = BindableProperty.Create("RowSpacing", typeof(double), typeof(Grid), 6d,
propertyChanged: (bindable, oldValue, newValue) => ((Grid)bindable).InvalidateMeasure(InvalidationTrigger.MeasureChanged));
propertyChanged: (bindable, oldValue, newValue) => ((Grid)bindable).InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged));

public static readonly BindableProperty ColumnSpacingProperty = BindableProperty.Create("ColumnSpacing", typeof(double), typeof(Grid), 6d,
propertyChanged: (bindable, oldValue, newValue) => ((Grid)bindable).InvalidateMeasure(InvalidationTrigger.MeasureChanged));
propertyChanged: (bindable, oldValue, newValue) => ((Grid)bindable).InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged));

public static readonly BindableProperty ColumnDefinitionsProperty = BindableProperty.Create("ColumnDefinitions", typeof(ColumnDefinitionCollection), typeof(Grid), null,
validateValue: (bindable, value) => value != null, propertyChanged: (bindable, oldvalue, newvalue) =>
Expand Down Expand Up @@ -211,9 +212,9 @@ internal override void ComputeConstraintForView(View view)
view.ComputedConstraint = result;
}

internal override void InvalidateMeasure(InvalidationTrigger trigger)
internal override void InvalidateMeasureInternal(InvalidationTrigger trigger)
{
base.InvalidateMeasure(trigger);
base.InvalidateMeasureInternal(trigger);
_columns = null;
_rows = null;
}
Expand Down
3 changes: 3 additions & 0 deletions Xamarin.Forms.Core/IVisualElementController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Xamarin.Forms.Internals;

namespace Xamarin.Forms
{
public interface IVisualElementController : IElementController
{
void NativeSizeChanged();
void InvalidateMeasure(InvalidationTrigger trigger);
}
}
5 changes: 3 additions & 2 deletions Xamarin.Forms.Core/Image.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform;

namespace Xamarin.Forms
Expand Down Expand Up @@ -110,7 +111,7 @@ protected override SizeRequest OnSizeRequest(double widthConstraint, double heig
void OnSourceChanged(object sender, EventArgs eventArgs)
{
OnPropertyChanged(SourceProperty.PropertyName);
InvalidateMeasure(InvalidationTrigger.MeasureChanged);
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}

static void OnSourcePropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
Expand All @@ -125,7 +126,7 @@ void OnSourcePropertyChanged(ImageSource oldvalue, ImageSource newvalue)
newvalue.SourceChanged += OnSourceChanged;
SetInheritedBindingContext(newvalue, BindingContext);
}
InvalidateMeasure(InvalidationTrigger.MeasureChanged);
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}

static void OnSourcePropertyChanging(BindableObject bindable, object oldvalue, object newvalue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;

namespace Xamarin.Forms
namespace Xamarin.Forms.Internals
{
[Flags]
internal enum InvalidationTrigger
public enum InvalidationTrigger
{
Undefined = 0,
MeasureChanged = 1 << 0,
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.Core/InvalidationEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms
{
Expand Down
15 changes: 8 additions & 7 deletions Xamarin.Forms.Core/Label.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform;

namespace Xamarin.Forms
Expand Down Expand Up @@ -41,13 +42,13 @@ public class Label : View, IFontElement
{
if (newvalue != null)
((FormattedString)newvalue).PropertyChanged += ((Label)bindable).OnFormattedTextChanged;
((Label)bindable).InvalidateMeasure(InvalidationTrigger.MeasureChanged);
((Label)bindable).InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
if (newvalue != null)
((Label)bindable).Text = null;
});

public static readonly BindableProperty LineBreakModeProperty = BindableProperty.Create("LineBreakMode", typeof(LineBreakMode), typeof(Label), LineBreakMode.WordWrap,
propertyChanged: (bindable, oldvalue, newvalue) => ((Label)bindable).InvalidateMeasure(InvalidationTrigger.MeasureChanged));
propertyChanged: (bindable, oldvalue, newvalue) => ((Label)bindable).InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged));

bool _cancelEvents;

Expand Down Expand Up @@ -158,7 +159,7 @@ static void FontStructPropertyChanged(BindableObject bindable, object oldValue,

label._cancelEvents = false;

label.InvalidateMeasure(InvalidationTrigger.MeasureChanged);
label.InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}

static void OnFontAttributesChanged(BindableObject bindable, object oldValue, object newValue)
Expand Down Expand Up @@ -189,7 +190,7 @@ static void OnFontAttributesChanged(BindableObject bindable, object oldValue, ob

label._cancelEvents = false;

label.InvalidateMeasure(InvalidationTrigger.MeasureChanged);
label.InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}

static void OnFontFamilyChanged(BindableObject bindable, object oldValue, object newValue)
Expand Down Expand Up @@ -217,7 +218,7 @@ static void OnFontFamilyChanged(BindableObject bindable, object oldValue, object
}

label._cancelEvents = false;
label.InvalidateMeasure(InvalidationTrigger.MeasureChanged);
label.InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}

static void OnFontSizeChanged(BindableObject bindable, object oldValue, object newValue)
Expand Down Expand Up @@ -247,7 +248,7 @@ static void OnFontSizeChanged(BindableObject bindable, object oldValue, object n

label._cancelEvents = false;

label.InvalidateMeasure(InvalidationTrigger.MeasureChanged);
label.InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}

void OnFormattedTextChanged(object sender, PropertyChangedEventArgs e)
Expand All @@ -270,7 +271,7 @@ static void OnTextPropertyChanged(BindableObject bindable, object oldvalue, obje
bool isVerticallyFixed = (label.Constraint & LayoutConstraint.VerticallyFixed) != 0;
bool isSingleLine = !(breakMode == LineBreakMode.CharacterWrap || breakMode == LineBreakMode.WordWrap);
if (!isVerticallyFixed || !isSingleLine)
((Label)bindable).InvalidateMeasure(InvalidationTrigger.MeasureChanged);
((Label)bindable).InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
if (newvalue != null)
((Label)bindable).FormattedText = null;
}
Expand Down
7 changes: 4 additions & 3 deletions Xamarin.Forms.Core/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms
{
Expand Down Expand Up @@ -168,7 +169,7 @@ public void RaiseChild(View view)
protected virtual void InvalidateLayout()
{
_hasDoneLayout = false;
InvalidateMeasure(InvalidationTrigger.MeasureChanged);
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
if (!_hasDoneLayout)
ForceLayout();
}
Expand Down Expand Up @@ -304,11 +305,11 @@ internal virtual void OnChildMeasureInvalidated(VisualElement child, Invalidatio
_allocatedFlag = false;
if (trigger == InvalidationTrigger.RendererReady)
{
InvalidateMeasure(InvalidationTrigger.RendererReady);
InvalidateMeasureInternal(InvalidationTrigger.RendererReady);
}
else
{
InvalidateMeasure(InvalidationTrigger.MeasureChanged);
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}

s_resolutionList.Add(new KeyValuePair<Layout, int>(this, GetElementDepth(this)));
Expand Down
5 changes: 3 additions & 2 deletions Xamarin.Forms.Core/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform;

namespace Xamarin.Forms
Expand Down Expand Up @@ -283,7 +284,7 @@ internal virtual void OnChildMeasureInvalidated(VisualElement child, Invalidatio
}

_allocatedFlag = false;
InvalidateMeasure(InvalidationTrigger.MeasureChanged);
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
if (!_allocatedFlag && Width >= 0 && Height >= 0)
{
SizeAllocated(Width, Height);
Expand Down Expand Up @@ -348,7 +349,7 @@ void OnInternalAdded(VisualElement view)
view.MeasureInvalidated += OnChildMeasureInvalidated;

OnChildAdded(view);
InvalidateMeasure(InvalidationTrigger.MeasureChanged);
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}

void OnInternalRemoved(VisualElement view)
Expand Down
5 changes: 3 additions & 2 deletions Xamarin.Forms.Core/StackLayout.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms
{
Expand Down Expand Up @@ -73,10 +74,10 @@ internal override void ComputeConstraintForView(View view)
ComputeConstraintForView(view, false);
}

internal override void InvalidateMeasure(InvalidationTrigger trigger)
internal override void InvalidateMeasureInternal(InvalidationTrigger trigger)
{
_layoutInformation = new LayoutInformation();
base.InvalidateMeasure(trigger);
base.InvalidateMeasureInternal(trigger);
}

void AlignOffAxis(LayoutInformation layout, StackOrientation orientation, double widthConstraint, double heightConstraint)
Expand Down
7 changes: 4 additions & 3 deletions Xamarin.Forms.Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms
{
public class View : VisualElement, IViewController
{
public static readonly BindableProperty VerticalOptionsProperty = BindableProperty.Create("VerticalOptions", typeof(LayoutOptions), typeof(View), LayoutOptions.Fill,
propertyChanged: (bindable, oldvalue, newvalue) => ((View)bindable).InvalidateMeasure(InvalidationTrigger.VerticalOptionsChanged));
propertyChanged: (bindable, oldvalue, newvalue) => ((View)bindable).InvalidateMeasureInternal(InvalidationTrigger.VerticalOptionsChanged));

public static readonly BindableProperty HorizontalOptionsProperty = BindableProperty.Create("HorizontalOptions", typeof(LayoutOptions), typeof(View), LayoutOptions.Fill,
propertyChanged: (bindable, oldvalue, newvalue) => ((View)bindable).InvalidateMeasure(InvalidationTrigger.HorizontalOptionsChanged));
propertyChanged: (bindable, oldvalue, newvalue) => ((View)bindable).InvalidateMeasureInternal(InvalidationTrigger.HorizontalOptionsChanged));

public static readonly BindableProperty MarginProperty = BindableProperty.Create("Margin", typeof(Thickness), typeof(View), default(Thickness), propertyChanged: MarginPropertyChanged);

Expand Down Expand Up @@ -100,7 +101,7 @@ protected override void OnBindingContextChanged()

static void MarginPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
((View)bindable).InvalidateMeasure(InvalidationTrigger.MarginChanged);
((View)bindable).InvalidateMeasureInternal(InvalidationTrigger.MarginChanged);
}

void ValidateGesture(IGestureRecognizer gesture)
Expand Down
Loading

0 comments on commit 5f8f47f

Please sign in to comment.