/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. */
bool nsWinGesture::InitLibrary() { // Check to see if we want single finger gesture input. Only do this once // for the app so we don't have to look it up on every window create.
gEnableSingleFingerPanEvents =
Preferences::GetBool("gestures.enable_single_finger_input", false);
// Multiple gesture can occur at the same time so gesture state // info can't be shared. switch (gi.dwID) { case GID_BEGIN: case GID_END: // These should always fall through to DefWndProc returnfalse; break;
case GID_ZOOM: { if (gi.dwFlags & GF_BEGIN) { // Send a zoom start event
// The low 32 bits are the distance in pixels.
mZoomIntermediate = (float)gi.ullArguments;
evt.mMessage = eMagnifyGestureStart;
evt.mDelta = 0.0;
} elseif (gi.dwFlags & GF_END) { // Send a zoom end event, the delta is the change // in touch points.
evt.mMessage = eMagnifyGesture; // (positive for a "zoom in")
evt.mDelta = -1.0 * (mZoomIntermediate - (float)gi.ullArguments);
mZoomIntermediate = (float)gi.ullArguments;
} else { // Send a zoom intermediate event, the delta is the change // in touch points.
evt.mMessage = eMagnifyGestureUpdate; // (positive for a "zoom in")
evt.mDelta = -1.0 * (mZoomIntermediate - (float)gi.ullArguments);
mZoomIntermediate = (float)gi.ullArguments;
}
} break;
case GID_ROTATE: { // Send a rotate start event double radians = 0.0;
// On GF_BEGIN, ullArguments contains the absolute rotation at the // start of the gesture. In later events it contains the offset from // the start angle. if (gi.ullArguments != 0)
radians = GID_ROTATE_ANGLE_FROM_ARGUMENT(gi.ullArguments);
double degrees = -1 * radians * (180 / M_PI);
if (gi.dwFlags & GF_BEGIN) { // At some point we should pass the initial angle in // along with delta. It's useful.
degrees = mRotateIntermediate = 0.0;
}
case GID_TWOFINGERTAP: // Normally maps to "restore" from whatever you may have recently changed. // A simple double click.
evt.mMessage = eTapGesture;
evt.mClickCount = 1; break;
case GID_PRESSANDTAP: // Two finger right click. Defaults to right click if it falls through.
evt.mMessage = ePressTapGesture;
evt.mClickCount = 1; break;
}
BOOL result = GetGestureInfo((HGESTUREINFO)lParam, &gi); if (!result) returnfalse;
// The coordinates of this event
nsPointWin coord;
coord = mPanRefPoint = gi.ptsLocation; // We want screen coordinates in our local offsets as client coordinates will // change when feedback is taking place. Gui events though require client // coordinates.
mPanRefPoint.ScreenToClient(hWnd);
switch (gi.dwID) { case GID_BEGIN: case GID_END: // These should always fall through to DefWndProc returnfalse; break;
inlinebool TestTransition(int32_t a, int32_t b) { // If a is zero, overflow is zero, implying the cursor has moved back to the // start position. If b is zero, cached overscroll is zero, implying feedback // just begun. if (a == 0 || b == 0) returntrue; // Test for different signs. return (a < 0) == (b < 0);
}
void nsWinGesture::UpdatePanFeedbackX(HWND hWnd, int32_t scrollOverflow, bool& endFeedback) { // If scroll overflow was returned indicating we panned past the bounds of // the scrollable view port, start feeback. if (scrollOverflow != 0) { if (!mFeedbackActive) {
BeginPanningFeedback(hWnd);
mFeedbackActive = true;
}
endFeedback = false;
mXAxisFeedback = true; return;
}
if (mXAxisFeedback) {
int32_t newOverflow = mPixelScrollOverflow.x - mPixelScrollDelta.x;
// Detect a reverse transition past the starting drag point. This tells us // the user has panned all the way back so we can stop providing feedback // for this axis. if (!TestTransition(newOverflow, mPixelScrollOverflow.x) ||
newOverflow == 0) return;
// Cache the total over scroll in pixels.
mPixelScrollOverflow.x = newOverflow;
endFeedback = false;
}
}
void nsWinGesture::UpdatePanFeedbackY(HWND hWnd, int32_t scrollOverflow, bool& endFeedback) { // If scroll overflow was returned indicating we panned past the bounds of // the scrollable view port, start feeback. if (scrollOverflow != 0) { if (!mFeedbackActive) {
BeginPanningFeedback(hWnd);
mFeedbackActive = true;
}
endFeedback = false;
mYAxisFeedback = true; return;
}
if (mYAxisFeedback) {
int32_t newOverflow = mPixelScrollOverflow.y - mPixelScrollDelta.y;
// Detect a reverse transition past the starting drag point. This tells us // the user has panned all the way back so we can stop providing feedback // for this axis. if (!TestTransition(newOverflow, mPixelScrollOverflow.y) ||
newOverflow == 0) return;
// Cache the total over scroll in pixels.
mPixelScrollOverflow.y = newOverflow;
endFeedback = false;
}
}
void nsWinGesture::PanFeedbackFinalize(HWND hWnd, bool endFeedback) { if (!mFeedbackActive) return;
// Don't scroll the view if we are currently at a bounds, or, if we are // panning back from a max feedback position. This keeps the original drag // point constant. if (!mXAxisFeedback) {
aWheelEvent.mDeltaX = mPixelScrollDelta.x;
} if (!mYAxisFeedback) {
aWheelEvent.mDeltaY = mPixelScrollDelta.y;
}
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.