/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
// These values were tweaked to make the physics feel similar to the native // swipe. staticconstdouble kSpringForce = 250.0; staticconstdouble kSwipeSuccessThreshold = 0.25;
double SwipeTracker::ClampToAllowedRange(double aGestureAmount) const { // gestureAmount needs to stay between -1 and 0 when swiping right and // between 0 and 1 when swiping left. double min =
mSwipeDirection == dom::SimpleGestureEvent_Binding::DIRECTION_RIGHT ? -1.0
: 0.0; double max =
mSwipeDirection == dom::SimpleGestureEvent_Binding::DIRECTION_LEFT ? 1.0
: 0.0; return std::clamp(aGestureAmount, min, max);
}
// If the fingers were moving away from the target direction when they were // lifted from the touchpad, abort the swipe. if (mCurrentVelocity * targetValue <
-StaticPrefs::widget_swipe_velocity_twitch_tolerance()) { returnfalse;
}
nsEventStatus SwipeTracker::ProcessEvent( const PanGestureInput& aEvent, bool aProcessingFirstEvent /* = false */) { // If the fingers have already been lifted or the swipe direction is where // navigation is impossible, don't process this event for swiping. if (!mEventsAreControllingSwipe || !SwipingInAllowedDirection()) { // Return nsEventStatus_eConsumeNoDefault for events from the swipe gesture // and nsEventStatus_eIgnore for events of subsequent scroll gestures. if (aEvent.mType == PanGestureInput::PANGESTURE_MAYSTART ||
aEvent.mType == PanGestureInput::PANGESTURE_START) {
mEventsHaveStartedNewGesture = true;
} return mEventsHaveStartedNewGesture ? nsEventStatus_eIgnore
: nsEventStatus_eConsumeNoDefault;
}
constbool computedSwipeSuccess = ComputeSwipeSuccess(); double eventAmount = mGestureAmount; // If ComputeSwipeSuccess returned false because the users fingers were // moving slightly away from the target direction then we do not want to // display the UI as if we were at the success threshold as that would // give a false indication that navigation would happen. if (!computedSwipeSuccess && (eventAmount >= kSwipeSuccessThreshold ||
eventAmount <= -kSwipeSuccessThreshold)) {
eventAmount = 0.999 * kSwipeSuccessThreshold; if (mGestureAmount < 0.f) {
eventAmount = -eventAmount;
}
}
// Add ourselves as a refresh driver observer. The refresh driver // will call WillRefresh for each animation frame until we // unregister ourselves.
MOZ_RELEASE_ASSERT(!mRegisteredWithRefreshDriver, "We only want a single refresh driver registration"); if (mRefreshDriver) {
mRefreshDriver->AddRefreshObserver(this, FlushType::Style, "Swipe animation");
mRegisteredWithRefreshDriver = true;
}
}
void SwipeTracker::WillRefresh(TimeStamp aTime) { // FIXME(emilio): shouldn't we be using `aTime`?
TimeStamp now = TimeStamp::Now();
mAxis.Simulate(now - mLastAnimationFrameTime);
mLastAnimationFrameTime = now;
constdouble wholeSize = mDeltaTypeIsPage
? StaticPrefs::widget_swipe_page_size()
: StaticPrefs::widget_swipe_pixel_size(); // NOTE(emilio): It's unclear this makes sense for page-based swiping, but // this preserves behavior and all platforms probably will end up converging // in pixel-based pan input, so... constdouble minIncrement = 1.0 / wholeSize; constbool isFinished = mAxis.IsFinished(minIncrement);
void SwipeTracker::UnregisterFromRefreshDriver() { if (mRegisteredWithRefreshDriver) {
MOZ_ASSERT(mRefreshDriver, "How were we able to register, then?");
mRefreshDriver->RemoveRefreshObserver(this, FlushType::Style);
mRegisteredWithRefreshDriver = false;
}
}
if (aPanInput.mType != PanGestureInput::PANGESTURE_START) { returnfalse;
}
// Only initiate horizontal tracking for events whose horizontal element is // at least eight times larger than its vertical element. This minimizes // performance problems with vertical scrolls (by minimizing the possibility // that they'll be misinterpreted as horizontal swipes), while still // tolerating a small vertical element to a true horizontal swipe. The number // '8' was arrived at by trial and error. return std::abs(aPanInput.mPanDisplacement.x) >
std::abs(aPanInput.mPanDisplacement.y) * 8;
}
} // namespace mozilla
¤ Dauer der Verarbeitung: 0.26 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.