Skip to content

Commit

Permalink
Adding Scroller/ScrollViewer's AnimationMode.Auto enum value (#850)
Browse files Browse the repository at this point in the history
* Calling Scroller.ScrollBy instead of Scroller.ScrollFrom when handling user input while animations are turned off.

* Updating ScrollViewer gamepad tests to account for Scroller.ScrolllBy usage.

* Adding test coverage for AnimationMode.Auto.

* Re-enabling Scroller's BasicAlignment, BasicMarginAndAlignment, ImageWithConstrainedWidth, ImageWithConstrainedHeight tests on RS5+.

* Using lambda for isAnimationsEnabled evaluation.

* Improved reliability of ScrollViewerTestsWithInputHelper's WaitForBoxChecked and WaitForScrollViewerOffsets.
  • Loading branch information
RBrid authored Jun 14, 2019
1 parent c75f773 commit 22999aa
Show file tree
Hide file tree
Showing 24 changed files with 452 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -497,36 +497,37 @@ public void VerifyScrollViewerGamePadInteraction()

double expectedVerticalOffset = 0;
double expectedHorizontalOffset = 0;
int? expectedViewChangeCount = areAnimationsEnabled ? null : (int?)1;

//Down. Change focus. Don't scroll.
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickDown, "Button 2", expectedHorizontalOffset, expectedVerticalOffset, 0);

//Down. Change focus. Scroll.
expectedVerticalOffset = 220;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickDown, "Button 3", expectedHorizontalOffset, expectedVerticalOffset, areAnimationsEnabled ? null : (int?)1);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickDown, "Button 3", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Down. Don't change focus. Scroll.
expectedVerticalOffset += scrollAmountForGamepadUpDown;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickDown, "Button 3", expectedHorizontalOffset, expectedVerticalOffset);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickDown, "Button 3", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Down. Change focus. Scroll.
expectedVerticalOffset = 920;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickDown, "Button 4", expectedHorizontalOffset, expectedVerticalOffset, areAnimationsEnabled ? null : (int?)1);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickDown, "Button 4", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Down. Change focus. Scroll.
expectedVerticalOffset = 1020;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickDown, "Button 5", expectedHorizontalOffset, expectedVerticalOffset, areAnimationsEnabled ? null : (int?)1);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickDown, "Button 5", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Up. Change focus. Don't scroll.
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickUp, "Button 4", expectedHorizontalOffset, expectedVerticalOffset, 0);

//Up. Don't change focus. Scroll.
expectedVerticalOffset -= scrollAmountForGamepadUpDown;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickUp, "Button 4", expectedHorizontalOffset, expectedVerticalOffset);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickUp, "Button 4", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Up. Change focus. Scroll.
expectedVerticalOffset = 480;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickUp, "Button 3", expectedHorizontalOffset, expectedVerticalOffset, areAnimationsEnabled ? null : (int?)1);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickUp, "Button 3", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);
}
}
}
Expand Down Expand Up @@ -594,6 +595,7 @@ public void VerifyScrollViewerGamePadHorizontalInteraction()

double expectedVerticalOffset = 0;
double expectedHorizontalOffset = 0;
int? expectedViewChangeCount = areAnimationsEnabled ? null : (int?)1;

//Right. Change focus. Don't scroll.
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickRight, "Button 1B", expectedHorizontalOffset, expectedVerticalOffset, 0);
Expand All @@ -606,23 +608,23 @@ public void VerifyScrollViewerGamePadHorizontalInteraction()

//Right. Change focus. Scroll.
expectedHorizontalOffset = 320;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickRight, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset, areAnimationsEnabled ? null : (int?)1);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickRight, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Right. Don't Change focus. Scroll.
expectedHorizontalOffset += scrollAmountForGamepadLeftRight;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickRight, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickRight, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Right. Don't Change focus. Scroll.
expectedHorizontalOffset += scrollAmountForGamepadLeftRight;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickRight, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickRight, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Left. Don't Change focus. Scroll.
expectedHorizontalOffset -= scrollAmountForGamepadLeftRight;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickLeft, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickLeft, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Left. Change focus. Scroll.
expectedHorizontalOffset = 80;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickLeft, "Button 1B", expectedHorizontalOffset, expectedVerticalOffset, areAnimationsEnabled ? null : (int?)1);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftThumbstickLeft, "Button 1B", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);
}
}
}
Expand Down Expand Up @@ -652,18 +654,19 @@ public void VerifyScrollViewerGamePadTriggerInteraction()

double expectedVerticalOffset = 0;
double expectedHorizontalOffset = 0;
int? expectedViewChangeCount = areAnimationsEnabled ? null : (int?)1;

//Down. Change focus. Scroll.
expectedVerticalOffset = areAnimationsEnabled ? scrollAmountForGamepadTrigger : 220.0;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.RightTrigger, "Button 3", expectedHorizontalOffset, expectedVerticalOffset, areAnimationsEnabled ? null : (int?)1);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.RightTrigger, "Button 3", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Down. Don't change focus. Scroll.
expectedVerticalOffset += scrollAmountForGamepadTrigger;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.RightTrigger, "Button 3", expectedHorizontalOffset, expectedVerticalOffset);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.RightTrigger, "Button 3", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Up. Don't change focus. Scroll.
expectedVerticalOffset -= scrollAmountForGamepadTrigger;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftTrigger, "Button 3", expectedHorizontalOffset, expectedVerticalOffset);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftTrigger, "Button 3", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

double actualHorizontalOffset;
double actualVerticalOffset;
Expand All @@ -672,7 +675,7 @@ public void VerifyScrollViewerGamePadTriggerInteraction()

//Up. Change focus. Scroll.
expectedVerticalOffset = 0;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftTrigger, actualVerticalOffset < scrollAmountForGamepadTrigger ? "Button 1" : "Button 2", expectedHorizontalOffset, expectedVerticalOffset, areAnimationsEnabled ? null : (int?)1);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftTrigger, actualVerticalOffset < scrollAmountForGamepadTrigger ? "Button 1" : "Button 2", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);
}
}
}
Expand Down Expand Up @@ -702,18 +705,19 @@ public void VerifyScrollViewerGamePadBumperInteraction()

double expectedVerticalOffset = 0;
double expectedHorizontalOffset = 0;
int? expectedViewChangeCount = areAnimationsEnabled ? null : (int?)1;

//Right. Change focus. Scroll.
expectedHorizontalOffset = areAnimationsEnabled ? scrollAmountForBumper : 320.0;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.RightShoulder, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset, areAnimationsEnabled ? null : (int?)1);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.RightShoulder, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Right. Don't change focus. Scroll.
expectedHorizontalOffset += scrollAmountForBumper;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.RightShoulder, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.RightShoulder, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

//Left. Don't change focus. Scroll.
expectedHorizontalOffset -= scrollAmountForBumper;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftShoulder, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftShoulder, "Button 1C", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);

double actualHorizontalOffset;
double actualVerticalOffset;
Expand All @@ -722,7 +726,7 @@ public void VerifyScrollViewerGamePadBumperInteraction()

//Left. Change focus. Scroll.
expectedHorizontalOffset = areAnimationsEnabled ? 0 : 80.0;
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftShoulder, actualHorizontalOffset > scrollAmountForBumper ? "Button 1B" : "Button 1", expectedHorizontalOffset, expectedVerticalOffset, areAnimationsEnabled ? null : (int?)1);
PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton.LeftShoulder, actualHorizontalOffset > scrollAmountForBumper ? "Button 1B" : "Button 1", expectedHorizontalOffset, expectedVerticalOffset, expectedViewChangeCount);
}
}
}
Expand Down Expand Up @@ -829,6 +833,13 @@ private void WaitForScrollViewerOffsets(double expectedHorizontalOffset, double
GetScrollerView(out actualHorizontalOffset, out actualVerticalOffset, out actualZoomFactor);
}

if (triesRemaining >= 0)
{
// Allow the view to settle and the STateChanged, ScrollCompleted or ZoomCompleted events to be raised.
Thread.Sleep(250);
GetScrollerView(out actualHorizontalOffset, out actualVerticalOffset, out actualZoomFactor);
}

Log.Comment($"Final ScrollViewer offsets. Expected={expectedHorizontalOffset},{expectedVerticalOffset}, Actual={actualHorizontalOffset},{actualVerticalOffset}.");
if (!areOffsetsCorrect())
{
Expand Down Expand Up @@ -922,11 +933,23 @@ private void PrepareForScrollViewerManipulationStart(string stateTextBoxName = "
Wait.ForIdle();
}

private bool WaitForEditValue(string editName, string editValue, double secondsTimeout = 2.0, bool throwOnError = true)
private void LogEditValue(string editName)
{
Edit edit = new Edit(FindElement.ById(editName));
Verify.IsNotNull(edit);
LogEditValue(editName, edit);
}

private void LogEditValue(string editName, Edit edit)
{
Log.Comment("Current value for " + editName + ": " + edit.Value);
}

private bool WaitForEditValue(string editName, string editValue, double secondsTimeout = 2.0, bool throwOnError = true)
{
Edit edit = new Edit(FindElement.ById(editName));
Verify.IsNotNull(edit);
LogEditValue(editName, edit);
if (edit.Value != editValue)
{
using (var waiter = new ValueChangedEventWaiter(edit, editValue))
Expand Down Expand Up @@ -1060,23 +1083,33 @@ private void WaitForScrollViewerFinalSize(UIObject scrollViewerUIObject, double
private void WaitForBoxChecked(string checkBoxName)
{
Log.Comment($"Waiting for checkbox {checkBoxName} checked...");
LogEditValue("txtResetStatus");

UIObject checkBoxUIObject = FindElement.ById(checkBoxName);
Verify.IsNotNull(checkBoxUIObject);
CheckBox checkBox = new CheckBox(checkBoxUIObject);
Verify.IsNotNull(checkBox);

if (checkBox.ToggleState != ToggleState.On)
if (checkBox.ToggleState == ToggleState.On)
{
checkBox.GetToggledWaiter().Wait();
Log.Comment("CheckBox already checked.");
}
else
{
checkBox.GetToggledWaiter().TryWait();
if (checkBox.ToggleState != ToggleState.On)
{
Log.Warning($"{checkBoxName} was not checked.");
throw new WaiterException();
}
Log.Comment("CheckBox checked.");
}

Log.Comment("CheckBox checked.");
}

private void UpdateTraces()
{
Log.Comment("Updating full log:");
LogEditValue("txtResetStatus");

// Triggering ScrollViewersWithSimpleContentsPage.GetFullLog() call.
TextInput.SendText("g");
Expand All @@ -1103,6 +1136,7 @@ private void LogTraces()
private void ClearTraces()
{
Log.Comment("Clearing full log.");
LogEditValue("txtResetStatus");

// Triggering ScrollViewersWithSimpleContentsPage.ClearFullLog() call.
TextInput.SendText("c");
Expand Down
49 changes: 45 additions & 4 deletions dev/ScrollViewer/ScrollBarController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,15 @@ void ScrollBarController::ScrollToRequested(winrt::event_token const& token)
winrt::event_token ScrollBarController::ScrollByRequested(winrt::TypedEventHandler<winrt::IScrollController, winrt::ScrollControllerScrollByRequestedEventArgs> const& value)
{
SCROLLVIEWER_TRACE_VERBOSE(nullptr, TRACE_MSG_METH, METH_NAME, this);
// This IScrollController implementation only uses the ScrollToRequested and ScrollFromRequested events, and not ScrollByRequested.
return {};

return m_scrollByRequested.add(value);
}

void ScrollBarController::ScrollByRequested(winrt::event_token const& token)
{
SCROLLVIEWER_TRACE_VERBOSE(nullptr, TRACE_MSG_METH, METH_NAME, this);
// This IScrollController implementation only uses the ScrollToRequested and ScrollFromRequested events, and not ScrollByRequested.

m_scrollByRequested.remove(token);
}

winrt::event_token ScrollBarController::ScrollFromRequested(winrt::TypedEventHandler<winrt::IScrollController, winrt::ScrollControllerScrollFromRequestedEventArgs> const& value)
Expand Down Expand Up @@ -507,7 +508,14 @@ void ScrollBarController::OnScroll(
offsetChange += s_minMaxEpsilon;
}

offsetChangeRequested = RaiseScrollFromRequested(offsetChange);
if (SharedHelpers::IsAnimationsEnabled())
{
offsetChangeRequested = RaiseScrollFromRequested(offsetChange);
}
else
{
offsetChangeRequested = RaiseScrollByRequested(offsetChange);
}
}

if (!offsetChangeRequested)
Expand Down Expand Up @@ -555,6 +563,39 @@ bool ScrollBarController::RaiseScrollToRequested(
return false;
}

bool ScrollBarController::RaiseScrollByRequested(
double offsetChange)
{
SCROLLVIEWER_TRACE_VERBOSE(nullptr, TRACE_MSG_METH_DBL, METH_NAME, this, offsetChange);

if (!m_scrollByRequested)
{
return false;
}

auto options = winrt::make_self<ScrollOptions>(
winrt::AnimationMode::Disabled,
winrt::SnapPointsMode::Ignore);

auto scrollByRequestedEventArgs = winrt::make_self<ScrollControllerScrollByRequestedEventArgs>(
offsetChange,
*options);

m_scrollByRequested(*this, *scrollByRequestedEventArgs);

int32_t offsetChangeId = scrollByRequestedEventArgs.as<winrt::ScrollControllerScrollByRequestedEventArgs>().Info().OffsetsChangeId;

// Only increment m_operationsCount when the returned OffsetsChangeId represents a new request that was not coalesced with a pending request.
if (offsetChangeId != -1 && offsetChangeId != m_lastOffsetChangeIdForScrollBy)
{
m_lastOffsetChangeIdForScrollBy = offsetChangeId;
m_operationsCount++;
return true;
}

return false;
}

bool ScrollBarController::RaiseScrollFromRequested(
double offsetChange)
{
Expand Down
4 changes: 4 additions & 0 deletions dev/ScrollViewer/ScrollBarController.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class ScrollBarController final:

bool RaiseScrollToRequested(
double offset);
bool RaiseScrollByRequested(
double offsetChange);
bool RaiseScrollFromRequested(
double offsetChange);
void RaiseInteractionInfoChanged();
Expand All @@ -114,6 +116,7 @@ class ScrollBarController final:
winrt::ScrollBar m_scrollBar;
winrt::ScrollMode m_scrollMode{ winrt::ScrollMode::Disabled };
int32_t m_lastOffsetChangeIdForScrollTo{ -1 };
int32_t m_lastOffsetChangeIdForScrollBy{ -1 };
int32_t m_lastOffsetChangeIdForScrollFrom{ -1 };
int m_operationsCount{ 0 };
double m_lastScrollBarValue{ 0.0 };
Expand All @@ -124,6 +127,7 @@ class ScrollBarController final:

// Event Sources
event<winrt::TypedEventHandler<winrt::IScrollController, winrt::ScrollControllerScrollToRequestedEventArgs>> m_scrollToRequested { };
event<winrt::TypedEventHandler<winrt::IScrollController, winrt::ScrollControllerScrollByRequestedEventArgs>> m_scrollByRequested { };
event<winrt::TypedEventHandler<winrt::IScrollController, winrt::ScrollControllerScrollFromRequestedEventArgs>> m_scrollFromRequested { };
event<winrt::TypedEventHandler<winrt::IScrollController, winrt::IInspectable>> m_interactionInfoChanged{ };

Expand Down
Loading

0 comments on commit 22999aa

Please sign in to comment.