зеркало из https://github.com/mozilla/pjs.git
Bug 672175 part.9 Implement NS_QUERY_SCROLL_TARGET_INFO event dispatcher on MouseScrollHandler::EventInfo r=jimm
This commit is contained in:
Родитель
99686018e1
Коммит
d54e86dc51
|
@ -181,6 +181,94 @@ MouseScrollHandler::GetModifierKeyState()
|
|||
return result;
|
||||
}
|
||||
|
||||
MouseScrollHandler::ScrollTargetInfo
|
||||
MouseScrollHandler::GetScrollTargetInfo(
|
||||
nsWindow* aWindow,
|
||||
const EventInfo& aEventInfo,
|
||||
const nsModifierKeyState& aModifierKeyState)
|
||||
{
|
||||
ScrollTargetInfo result;
|
||||
result.dispatchPixelScrollEvent = false;
|
||||
result.reversePixelScrollDirection = false;
|
||||
result.actualScrollAmount = aEventInfo.GetScrollAmount();
|
||||
result.actualScrollAction = nsQueryContentEvent::SCROLL_ACTION_NONE;
|
||||
result.pixelsPerUnit = 0;
|
||||
if (!mUserPrefs.IsPixelScrollingEnabled()) {
|
||||
PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS,
|
||||
("MouseScroll::GetPixelScrollInfo: Succeeded, aWindow=%p, "
|
||||
"result: { dispatchPixelScrollEvent: %s, actualScrollAmount: %d }",
|
||||
aWindow, GetBoolName(result.dispatchPixelScrollEvent),
|
||||
result.actualScrollAmount));
|
||||
return result;
|
||||
}
|
||||
|
||||
nsMouseScrollEvent testEvent(true, NS_MOUSE_SCROLL, aWindow);
|
||||
aWindow->InitEvent(testEvent);
|
||||
testEvent.scrollFlags = aEventInfo.GetScrollFlags();
|
||||
testEvent.isShift = aModifierKeyState.mIsShiftDown;
|
||||
testEvent.isControl = aModifierKeyState.mIsControlDown;
|
||||
testEvent.isMeta = false;
|
||||
testEvent.isAlt = aModifierKeyState.mIsAltDown;
|
||||
|
||||
testEvent.delta = result.actualScrollAmount;
|
||||
if ((aEventInfo.IsVertical() && aEventInfo.IsPositive()) ||
|
||||
(!aEventInfo.IsVertical() && !aEventInfo.IsPositive())) {
|
||||
testEvent.delta *= -1;
|
||||
}
|
||||
|
||||
nsQueryContentEvent queryEvent(true, NS_QUERY_SCROLL_TARGET_INFO, aWindow);
|
||||
aWindow->InitEvent(queryEvent);
|
||||
queryEvent.InitForQueryScrollTargetInfo(&testEvent);
|
||||
DispatchEvent(aWindow, queryEvent);
|
||||
|
||||
// If the necessary interger isn't larger than 0, we should assume that
|
||||
// the event failed for us.
|
||||
if (!queryEvent.mSucceeded) {
|
||||
PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS,
|
||||
("MouseScroll::GetPixelScrollInfo: Failed to query the "
|
||||
"scroll target information, aWindow=%p"
|
||||
"result: { dispatchPixelScrollEvent: %s, actualScrollAmount: %d }",
|
||||
aWindow, GetBoolName(result.dispatchPixelScrollEvent),
|
||||
result.actualScrollAmount));
|
||||
return result;
|
||||
}
|
||||
|
||||
result.actualScrollAction = queryEvent.mReply.mComputedScrollAction;
|
||||
|
||||
if (result.actualScrollAction == nsQueryContentEvent::SCROLL_ACTION_PAGE) {
|
||||
result.pixelsPerUnit =
|
||||
aEventInfo.IsVertical() ? queryEvent.mReply.mPageHeight :
|
||||
queryEvent.mReply.mPageWidth;
|
||||
} else {
|
||||
result.pixelsPerUnit = queryEvent.mReply.mLineHeight;
|
||||
}
|
||||
|
||||
result.actualScrollAmount = queryEvent.mReply.mComputedScrollAmount;
|
||||
|
||||
if (result.pixelsPerUnit > 0 && result.actualScrollAmount != 0 &&
|
||||
result.actualScrollAction != nsQueryContentEvent::SCROLL_ACTION_NONE) {
|
||||
result.dispatchPixelScrollEvent = true;
|
||||
// If original delta's sign and computed delta's one are different,
|
||||
// we need to reverse the pixel scroll direction at dispatching it.
|
||||
result.reversePixelScrollDirection =
|
||||
(testEvent.delta > 0 && result.actualScrollAmount < 0) ||
|
||||
(testEvent.delta < 0 && result.actualScrollAmount > 0);
|
||||
// scroll amount must be positive.
|
||||
result.actualScrollAmount = NS_ABS(result.actualScrollAmount);
|
||||
}
|
||||
|
||||
PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS,
|
||||
("MouseScroll::GetPixelScrollInfo: Succeeded, aWindow=%p, "
|
||||
"result: { dispatchPixelScrollEvent: %s, reversePixelScrollDirection: %s, "
|
||||
"actualScrollAmount: %d, actualScrollAction: 0x%01X, "
|
||||
"pixelsPerUnit: %d }",
|
||||
aWindow, GetBoolName(result.dispatchPixelScrollEvent),
|
||||
GetBoolName(result.reversePixelScrollDirection), result.actualScrollAmount,
|
||||
result.actualScrollAction, result.pixelsPerUnit));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* EventInfo
|
||||
|
|
|
@ -55,6 +55,35 @@ private:
|
|||
static bool DispatchEvent(nsWindow* aWindow, nsGUIEvent& aEvent);
|
||||
|
||||
public:
|
||||
|
||||
class EventInfo;
|
||||
/**
|
||||
* GetScrollTargetInfo() returns scroll target information which is
|
||||
* computed from the result of NS_QUERY_SCROLL_TARGET_INFO event.
|
||||
*
|
||||
* @param aWindow An nsWindow which is handling the event.
|
||||
* @param aEventInfo The EventInfo which is being handled.
|
||||
* @param aModifierKeyState The modifier key state.
|
||||
*/
|
||||
struct ScrollTargetInfo {
|
||||
// TRUE if pixel scroll event is needed. Otherwise, FALSE.
|
||||
bool dispatchPixelScrollEvent;
|
||||
// TRUE if pixel scroll event's delta value should be reversed.
|
||||
// Otherwise, FALSE.
|
||||
bool reversePixelScrollDirection;
|
||||
// Actual scroll amount. It might be computed with user prefs.
|
||||
PRInt32 actualScrollAmount;
|
||||
// Actual scroll action. It might be computed with user prefs.
|
||||
// The value is one of nsQueryContentEvent::SCROLL_ACTION_*.
|
||||
PRInt32 actualScrollAction;
|
||||
// Pixels per unit (line or page, depends on the action).
|
||||
PRInt32 pixelsPerUnit;
|
||||
};
|
||||
ScrollTargetInfo GetScrollTargetInfo(
|
||||
nsWindow* aWindow,
|
||||
const EventInfo& aEvent,
|
||||
const nsModifierKeyState& aModiferKeyState);
|
||||
|
||||
class EventInfo {
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -6315,71 +6315,22 @@ nsWindow::OnMouseWheelInternal(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
|
|||
|
||||
// Before dispatching line scroll event, we should get the current scroll
|
||||
// event target information for pixel scroll.
|
||||
bool dispatchPixelScrollEvent = false;
|
||||
bool reversePixelScrollDirection = false;
|
||||
PRInt32 actualScrollAction = nsQueryContentEvent::SCROLL_ACTION_NONE;
|
||||
PRInt32 pixelsPerUnit = 0;
|
||||
// the amount is the number of lines (or pages) per WHEEL_DELTA
|
||||
PRInt32 computedScrollAmount = eventInfo.GetScrollAmount();
|
||||
|
||||
if (MouseScrollHandler::GetInstance()->
|
||||
GetUserPrefs().IsPixelScrollingEnabled()) {
|
||||
nsMouseScrollEvent testEvent(true, NS_MOUSE_SCROLL, this);
|
||||
InitEvent(testEvent);
|
||||
testEvent.scrollFlags = eventInfo.GetScrollFlags();
|
||||
testEvent.isShift = scrollEvent.isShift;
|
||||
testEvent.isControl = scrollEvent.isControl;
|
||||
testEvent.isMeta = scrollEvent.isMeta;
|
||||
testEvent.isAlt = scrollEvent.isAlt;
|
||||
|
||||
testEvent.delta = computedScrollAmount;
|
||||
if ((eventInfo.IsVertical() && eventInfo.IsPositive()) ||
|
||||
(!eventInfo.IsVertical() && !eventInfo.IsPositive())) {
|
||||
testEvent.delta *= -1;
|
||||
}
|
||||
nsQueryContentEvent queryEvent(true, NS_QUERY_SCROLL_TARGET_INFO, this);
|
||||
InitEvent(queryEvent);
|
||||
queryEvent.InitForQueryScrollTargetInfo(&testEvent);
|
||||
DispatchWindowEvent(&queryEvent);
|
||||
// If the necessary interger isn't larger than 0, we should assume that
|
||||
// the event failed for us.
|
||||
if (queryEvent.mSucceeded) {
|
||||
actualScrollAction = queryEvent.mReply.mComputedScrollAction;
|
||||
if (actualScrollAction == nsQueryContentEvent::SCROLL_ACTION_PAGE) {
|
||||
if (eventInfo.IsVertical()) {
|
||||
pixelsPerUnit = queryEvent.mReply.mPageHeight;
|
||||
} else {
|
||||
pixelsPerUnit = queryEvent.mReply.mPageWidth;
|
||||
}
|
||||
} else {
|
||||
pixelsPerUnit = queryEvent.mReply.mLineHeight;
|
||||
}
|
||||
computedScrollAmount = queryEvent.mReply.mComputedScrollAmount;
|
||||
if (pixelsPerUnit > 0 && computedScrollAmount != 0 &&
|
||||
actualScrollAction != nsQueryContentEvent::SCROLL_ACTION_NONE) {
|
||||
dispatchPixelScrollEvent = true;
|
||||
// If original delta's sign and computed delta's one are different,
|
||||
// we need to reverse the pixel scroll direction at dispatching it.
|
||||
reversePixelScrollDirection =
|
||||
(testEvent.delta > 0 && computedScrollAmount < 0) ||
|
||||
(testEvent.delta < 0 && computedScrollAmount > 0);
|
||||
// scroll amount must be positive.
|
||||
computedScrollAmount = NS_ABS(computedScrollAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
MouseScrollHandler::ScrollTargetInfo scrollTargetInfo =
|
||||
handler->GetScrollTargetInfo(this, eventInfo, modKeyState);
|
||||
|
||||
// If we dispatch pixel scroll event after the line scroll event,
|
||||
// we should set kHasPixels flag to the line scroll event.
|
||||
scrollEvent.scrollFlags =
|
||||
dispatchPixelScrollEvent ? nsMouseScrollEvent::kHasPixels : 0;
|
||||
scrollEvent.scrollFlags |= eventInfo.GetScrollFlags();
|
||||
scrollEvent.scrollFlags = eventInfo.GetScrollFlags();
|
||||
if (scrollTargetInfo.dispatchPixelScrollEvent) {
|
||||
scrollEvent.scrollFlags |= nsMouseScrollEvent::kHasPixels;
|
||||
}
|
||||
|
||||
PRInt32 nativeDeltaForScroll =
|
||||
eventInfo.GetNativeDelta() + lastEventInfo.mRemainingDeltaForScroll;
|
||||
|
||||
// NOTE: Don't use computedScrollAmount for computing the delta value of
|
||||
// line/page scroll event. The value will be recomputed in ESM.
|
||||
// NOTE: Don't use scrollTargetInfo.actualScrollAmount for computing the
|
||||
// delta value of line/page scroll event. The value will be
|
||||
// recomputed in ESM.
|
||||
if (eventInfo.IsPage()) {
|
||||
scrollEvent.delta = nativeDeltaForScroll * orienter / WHEEL_DELTA;
|
||||
PRInt32 recomputedNativeDelta = scrollEvent.delta * orienter / WHEEL_DELTA;
|
||||
|
@ -6406,7 +6357,7 @@ nsWindow::OnMouseWheelInternal(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
|
|||
}
|
||||
|
||||
// If the query event failed, we cannot send pixel events.
|
||||
if (!dispatchPixelScrollEvent) {
|
||||
if (!scrollTargetInfo.dispatchPixelScrollEvent) {
|
||||
lastEventInfo.mRemainingDeltaForPixel = 0;
|
||||
return;
|
||||
}
|
||||
|
@ -6416,7 +6367,8 @@ nsWindow::OnMouseWheelInternal(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
|
|||
pixelEvent.scrollFlags = nsMouseScrollEvent::kAllowSmoothScroll;
|
||||
pixelEvent.scrollFlags |= eventInfo.IsVertical() ?
|
||||
nsMouseScrollEvent::kIsVertical : nsMouseScrollEvent::kIsHorizontal;
|
||||
if (actualScrollAction == nsQueryContentEvent::SCROLL_ACTION_PAGE) {
|
||||
if (scrollTargetInfo.actualScrollAction ==
|
||||
nsQueryContentEvent::SCROLL_ACTION_PAGE) {
|
||||
pixelEvent.scrollFlags |= nsMouseScrollEvent::kIsFullPage;
|
||||
}
|
||||
// Use same modifier state for pixel scroll event.
|
||||
|
@ -6429,10 +6381,12 @@ nsWindow::OnMouseWheelInternal(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
|
|||
eventInfo.GetNativeDelta() + lastEventInfo.mRemainingDeltaForPixel;
|
||||
// Pixel scroll event won't be recomputed the scroll amout and direction by
|
||||
// ESM. Therefore, we need to set the computed amout and direction here.
|
||||
PRInt32 orienterForPixel = reversePixelScrollDirection ? -orienter : orienter;
|
||||
PRInt32 orienterForPixel =
|
||||
scrollTargetInfo.reversePixelScrollDirection ? -orienter : orienter;
|
||||
|
||||
double deltaPerPixel =
|
||||
(double)WHEEL_DELTA / computedScrollAmount / pixelsPerUnit;
|
||||
(double)WHEEL_DELTA / scrollTargetInfo.actualScrollAmount /
|
||||
scrollTargetInfo.pixelsPerUnit;
|
||||
pixelEvent.delta =
|
||||
RoundDelta((double)nativeDeltaForPixel * orienterForPixel / deltaPerPixel);
|
||||
PRInt32 recomputedNativeDelta =
|
||||
|
|
Загрузка…
Ссылка в новой задаче