/*
- * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
private EventHandler<StateChangedEventArgs> stateChangeHandler;
private bool isPressed = false;
- private bool styleApplied = false;
+ internal int styleApplying = 0;
/// <summary>
- /// Get accessibility name.
+ /// Gets accessibility name.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
protected override string AccessibilityGetName()
}
/// <summary>
- /// Prevents from showing child widgets in AT-SPI tree.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected override bool AccessibilityShouldReportZeroChildren()
- {
- return true;
- }
-
- /// <summary>
/// The ButtonExtension instance that is injected by ButtonStyle.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[EditorBrowsable(EditorBrowsableState.Never)]
protected virtual TextLabel CreateText()
{
- return new TextLabel
+ return new TextLabel(new TextLabelStyle())
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
- AccessibilityHighlightable = false
+ AccessibilityHidden = true,
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected virtual ImageView CreateIcon()
{
- return new ImageView
+ return new ImageView()
{
- AccessibilityHighlightable = false
+ AccessibilityHidden = true,
};
}
PivotPoint = NUI.PivotPoint.Center,
WidthResizePolicy = ResizePolicyType.FillToParent,
HeightResizePolicy = ResizePolicyType.FillToParent,
- AccessibilityHighlightable = false
+ AccessibilityHidden = true,
};
}
return true;
case PointStateType.Up:
{
- bool clicked = isPressed && IsEnabled;
+ if (!isPressed)
+ {
+ return false;
+ }
isPressed = false;
UpdateState();
}
- if (clicked)
- {
- ClickedEventArgs eventArgs = new ClickedEventArgs();
- OnClickedInternal(eventArgs);
- }
+ ClickedEventArgs eventArgs = new ClickedEventArgs();
+ OnClickedInternal(eventArgs, touch);
return true;
}
return base.HandleControlStateOnTouch(touch);
}
+ /// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected override void OnEnabled(bool enabled)
+ {
+ base.OnEnabled(enabled);
+ UpdateState();
+ }
+
/// <summary>
/// Update Button State.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
protected void UpdateState()
{
- if (!styleApplied) return;
+ if (styleApplying > 0) return;
ControlState sourceState = ControlState;
ControlState targetState;
public override void OnInitialize()
{
base.OnInitialize();
- SetAccessibilityConstructor(Role.PushButton);
+ AccessibilityRole = Role.PushButton;
AccessibilityHighlightable = true;
EnableControlStatePropagation = true;
buttonIcon = CreateIcon();
LayoutItems();
-#if PROFILE_MOBILE
Feedback = true;
-#endif
}
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
public override void OnRelayout(Vector2 size, RelayoutContainer container)
{
- Debug.Assert(size != null);
+ if (size == null) return;
if (size.Equals(this.size))
{
{
isPressed = statePressed;
}
+
+ if (IsSelectable)
+ {
+ var stateSelected = controlStateChangedInfo.CurrentState.Contains(ControlState.Selected);
+
+ if (IsSelected != stateSelected)
+ {
+ IsSelected = stateSelected;
+ }
+ }
}
/// <summary>
buttonText.Unparent();
overlayImage?.Unparent();
+#pragma warning disable CA2000
+ Size2D cellPadding = String.IsNullOrEmpty(buttonText.Text) ? new Size2D(0, 0) : itemSpacing;
+#pragma warning restore CA2000
+
if (IconRelativeOrientation == IconOrientation.Left)
{
Layout = new LinearLayout()
{
LinearOrientation = LinearLayout.Orientation.Horizontal,
- LinearAlignment = itemAlignment,
- CellPadding = itemSpacing ?? new Size2D(0, 0)
+ HorizontalAlignment = itemHorizontalAlignment,
+ VerticalAlignment = itemVerticalAlignment,
+ CellPadding = cellPadding
};
Add(buttonIcon);
Layout = new LinearLayout()
{
LinearOrientation = LinearLayout.Orientation.Horizontal,
- LinearAlignment = itemAlignment,
- CellPadding = itemSpacing ?? new Size2D(0, 0)
+ HorizontalAlignment = itemHorizontalAlignment,
+ VerticalAlignment = itemVerticalAlignment,
+ CellPadding = cellPadding
};
Add(buttonText);
Layout = new LinearLayout()
{
LinearOrientation = LinearLayout.Orientation.Vertical,
- LinearAlignment = itemAlignment,
- CellPadding = itemSpacing ?? new Size2D(0, 0)
+ HorizontalAlignment = itemHorizontalAlignment,
+ VerticalAlignment = itemVerticalAlignment,
+ CellPadding = cellPadding
};
Add(buttonIcon);
Layout = new LinearLayout()
{
LinearOrientation = LinearLayout.Orientation.Vertical,
- LinearAlignment = itemAlignment,
- CellPadding = itemSpacing ?? new Size2D(0, 0)
+ HorizontalAlignment = itemHorizontalAlignment,
+ VerticalAlignment = itemVerticalAlignment,
+ CellPadding = cellPadding
};
Add(buttonText);
if (iconRelativeOrientation == IconOrientation.Left || iconRelativeOrientation == IconOrientation.Right)
{
- lengthWithoutText += (itemSpacing?.Width ?? 0) + iconMargin.Start + iconMargin.End + textMargin.Start + textMargin.End;
+ lengthWithoutText += (itemSpacing?.Width ?? 0) + iconMargin.Start + iconMargin.End + textMargin.Start + textMargin.End + Padding.Start + Padding.End;
}
else
{
- lengthWithoutText += (itemSpacing?.Height ?? 0) + iconMargin.Top + iconMargin.Bottom + textMargin.Top + textMargin.Bottom;
+ lengthWithoutText += (itemSpacing?.Height ?? 0) + iconMargin.Top + iconMargin.Bottom + textMargin.Top + textMargin.Bottom + Padding.Top + Padding.Bottom;
}
}
}
}
}
+ private void OnClickedInternal(ClickedEventArgs eventArgs, Touch touch)
+ {
+ // If GrabTouchAfterLeave is true, Up will result in Finished rather than Interrupted even if it is out of the button area.
+ // So, it is necessary to check whether it is Up in the button area.
+ if (GrabTouchAfterLeave == true)
+ {
+ Vector2 localPosition = touch.GetLocalPosition(0);
+ if ((localPosition != null && Size != null &&
+ 0 <= localPosition.X && localPosition.X <= Size.Width &&
+ 0 <= localPosition.Y && localPosition.Y <= Size.Height) == false)
+ {
+ return;
+ }
+ }
+ OnClickedInternal(eventArgs);
+ }
+
private void OnClickedInternal(ClickedEventArgs eventArgs)
{
Command?.Execute(CommandParameter);
ClickEvent?.Invoke(this, nestedEventArgs);
Clicked?.Invoke(this, eventArgs);
}
-
- internal override bool OnAccessibilityActivated()
- {
- using (var key = new Key())
- {
- key.State = Key.StateType.Down;
- key.KeyPressedName = "Return";
-
- // Touch Down
- OnKey(key);
-
- // Touch Up
- key.State = Key.StateType.Up;
- OnKey(key);
- }
-
- return true;
- }
}
}