2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-04-01 08:09:22 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "WheelHandlingHelper.h"
|
|
|
|
|
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-04-01 08:09:22 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
2018-02-22 21:40:44 +03:00
|
|
|
#include "nsITextControlElement.h"
|
2014-04-01 08:09:22 +04:00
|
|
|
#include "nsITimer.h"
|
2015-10-16 07:19:27 +03:00
|
|
|
#include "nsPluginFrame.h"
|
2014-04-01 08:09:22 +04:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "Units.h"
|
2017-09-22 20:42:29 +03:00
|
|
|
#include "ScrollAnimationPhysics.h"
|
2014-04-01 08:09:22 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
/* mozilla::DeltaValues */
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
DeltaValues::DeltaValues(WidgetWheelEvent* aEvent)
|
2016-03-31 12:55:59 +03:00
|
|
|
: deltaX(aEvent->mDeltaX)
|
2016-03-31 12:09:47 +03:00
|
|
|
, deltaY(aEvent->mDeltaY)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
/* mozilla::WheelHandlingUtils */
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
WheelHandlingUtils::CanScrollInRange(nscoord aMin, nscoord aValue, nscoord aMax,
|
|
|
|
double aDirection)
|
|
|
|
{
|
|
|
|
return aDirection > 0.0 ? aValue < static_cast<double>(aMax) :
|
|
|
|
static_cast<double>(aMin) < aValue;
|
|
|
|
}
|
|
|
|
|
2015-10-16 07:19:27 +03:00
|
|
|
/* static */ bool
|
|
|
|
WheelHandlingUtils::CanScrollOn(nsIFrame* aFrame,
|
|
|
|
double aDirectionX, double aDirectionY)
|
|
|
|
{
|
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(aFrame);
|
|
|
|
if (scrollableFrame) {
|
|
|
|
return CanScrollOn(scrollableFrame, aDirectionX, aDirectionY);
|
|
|
|
}
|
|
|
|
nsPluginFrame* pluginFrame = do_QueryFrame(aFrame);
|
|
|
|
return pluginFrame && pluginFrame->WantsToHandleWheelEventAsDefaultAction();
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ bool
|
|
|
|
WheelHandlingUtils::CanScrollOn(nsIScrollableFrame* aScrollFrame,
|
|
|
|
double aDirectionX, double aDirectionY)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aScrollFrame);
|
|
|
|
NS_ASSERTION(aDirectionX || aDirectionY,
|
|
|
|
"One of the delta values must be non-zero at least");
|
|
|
|
|
|
|
|
nsPoint scrollPt = aScrollFrame->GetScrollPosition();
|
|
|
|
nsRect scrollRange = aScrollFrame->GetScrollRange();
|
|
|
|
uint32_t directions = aScrollFrame->GetPerceivedScrollingDirections();
|
|
|
|
|
|
|
|
return (aDirectionX && (directions & nsIScrollableFrame::HORIZONTAL) &&
|
2018-02-19 23:15:23 +03:00
|
|
|
CanScrollInRange(scrollRange.x, scrollPt.x,
|
2014-04-01 08:09:22 +04:00
|
|
|
scrollRange.XMost(), aDirectionX)) ||
|
|
|
|
(aDirectionY && (directions & nsIScrollableFrame::VERTICAL) &&
|
2018-02-19 23:15:23 +03:00
|
|
|
CanScrollInRange(scrollRange.y, scrollPt.y,
|
2014-04-01 08:09:22 +04:00
|
|
|
scrollRange.YMost(), aDirectionY));
|
|
|
|
}
|
|
|
|
|
2018-02-22 21:40:44 +03:00
|
|
|
/*static*/ Maybe<layers::ScrollDirection>
|
|
|
|
WheelHandlingUtils::GetDisregardedWheelScrollDirection(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (!content) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsITextControlElement> ctrl =
|
|
|
|
do_QueryInterface(content->IsInAnonymousSubtree()
|
|
|
|
? content->GetBindingParent() : content);
|
|
|
|
if (!ctrl || !ctrl->IsSingleLineTextControl()) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
// Disregard scroll in the block-flow direction by mouse wheel on a
|
|
|
|
// single-line text control. For instance, in tranditional Chinese writing
|
|
|
|
// system, a single-line text control cannot be scrolled horizontally with
|
|
|
|
// mouse wheel even if they overflow at the right and left edges; Whereas in
|
|
|
|
// latin-based writing system, a single-line text control cannot be scrolled
|
|
|
|
// vertically with mouse wheel even if they overflow at the top and bottom
|
|
|
|
// edges
|
|
|
|
return Some(aFrame->GetWritingMode().IsVertical()
|
|
|
|
? layers::ScrollDirection::eHorizontal
|
|
|
|
: layers::ScrollDirection::eVertical);
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/******************************************************************/
|
2014-04-01 08:09:22 +04:00
|
|
|
/* mozilla::WheelTransaction */
|
2014-04-01 08:09:22 +04:00
|
|
|
/******************************************************************/
|
|
|
|
|
2017-03-01 20:03:14 +03:00
|
|
|
AutoWeakFrame WheelTransaction::sTargetFrame(nullptr);
|
2014-04-01 08:09:22 +04:00
|
|
|
uint32_t WheelTransaction::sTime = 0;
|
|
|
|
uint32_t WheelTransaction::sMouseMoved = 0;
|
|
|
|
nsITimer* WheelTransaction::sTimer = nullptr;
|
|
|
|
int32_t WheelTransaction::sScrollSeriesCounter = 0;
|
|
|
|
bool WheelTransaction::sOwnScrollbars = false;
|
2014-04-01 08:09:22 +04:00
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ bool
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::OutOfTime(uint32_t aBaseTime, uint32_t aThreshold)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
uint32_t now = PR_IntervalToMilliseconds(PR_IntervalNow());
|
|
|
|
return (now - aBaseTime > aThreshold);
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::OwnScrollbars(bool aOwn)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
sOwnScrollbars = aOwn;
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::BeginTransaction(nsIFrame* aTargetFrame,
|
2018-02-22 21:40:44 +03:00
|
|
|
const WidgetWheelEvent* aEvent)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!sTargetFrame, "previous transaction is not finished!");
|
2015-09-10 19:59:54 +03:00
|
|
|
MOZ_ASSERT(aEvent->mMessage == eWheel,
|
2014-04-01 08:09:22 +04:00
|
|
|
"Transaction must be started with a wheel event");
|
2014-04-01 08:09:22 +04:00
|
|
|
ScrollbarsForWheel::OwnWheelTransaction(false);
|
2014-04-01 08:09:22 +04:00
|
|
|
sTargetFrame = aTargetFrame;
|
|
|
|
sScrollSeriesCounter = 0;
|
|
|
|
if (!UpdateTransaction(aEvent)) {
|
|
|
|
NS_ERROR("BeginTransaction is called even cannot scroll the frame");
|
|
|
|
EndTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ bool
|
2018-02-22 21:40:44 +03:00
|
|
|
WheelTransaction::UpdateTransaction(const WidgetWheelEvent* aEvent)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
2015-10-16 07:19:27 +03:00
|
|
|
nsIFrame* scrollToFrame = GetTargetFrame();
|
|
|
|
nsIScrollableFrame* scrollableFrame = scrollToFrame->GetScrollTargetFrame();
|
|
|
|
if (scrollableFrame) {
|
|
|
|
scrollToFrame = do_QueryFrame(scrollableFrame);
|
|
|
|
}
|
2014-04-01 08:09:22 +04:00
|
|
|
|
2015-10-16 07:19:27 +03:00
|
|
|
if (!WheelHandlingUtils::CanScrollOn(scrollToFrame,
|
2016-03-31 12:09:47 +03:00
|
|
|
aEvent->mDeltaX, aEvent->mDeltaY)) {
|
2014-04-01 08:09:22 +04:00
|
|
|
OnFailToScrollTarget();
|
|
|
|
// We should not modify the transaction state when the view will not be
|
|
|
|
// scrolled actually.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetTimeout();
|
|
|
|
|
2015-12-02 00:45:49 +03:00
|
|
|
if (sScrollSeriesCounter != 0 && OutOfTime(sTime, kScrollSeriesTimeoutMs)) {
|
2014-04-01 08:09:22 +04:00
|
|
|
sScrollSeriesCounter = 0;
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
2014-04-01 08:09:22 +04:00
|
|
|
sScrollSeriesCounter++;
|
|
|
|
|
|
|
|
// We should use current time instead of WidgetEvent.time.
|
|
|
|
// 1. Some events doesn't have the correct creation time.
|
|
|
|
// 2. If the computer runs slowly by other processes eating the CPU resource,
|
|
|
|
// the event creation time doesn't keep real time.
|
|
|
|
sTime = PR_IntervalToMilliseconds(PR_IntervalNow());
|
|
|
|
sMouseMoved = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::MayEndTransaction()
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
2014-04-01 08:09:22 +04:00
|
|
|
if (!sOwnScrollbars && ScrollbarsForWheel::IsActive()) {
|
|
|
|
ScrollbarsForWheel::OwnWheelTransaction(true);
|
2014-04-01 08:09:22 +04:00
|
|
|
} else {
|
|
|
|
EndTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::EndTransaction()
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
2014-04-01 08:09:22 +04:00
|
|
|
if (sTimer) {
|
2014-04-01 08:09:22 +04:00
|
|
|
sTimer->Cancel();
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
2014-04-01 08:09:22 +04:00
|
|
|
sTargetFrame = nullptr;
|
|
|
|
sScrollSeriesCounter = 0;
|
|
|
|
if (sOwnScrollbars) {
|
|
|
|
sOwnScrollbars = false;
|
2014-04-01 08:09:22 +04:00
|
|
|
ScrollbarsForWheel::OwnWheelTransaction(false);
|
|
|
|
ScrollbarsForWheel::Inactivate();
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-16 07:19:27 +03:00
|
|
|
/* static */ bool
|
|
|
|
WheelTransaction::WillHandleDefaultAction(WidgetWheelEvent* aWheelEvent,
|
2017-03-01 20:03:14 +03:00
|
|
|
AutoWeakFrame& aTargetWeakFrame)
|
2015-10-16 07:19:27 +03:00
|
|
|
{
|
|
|
|
nsIFrame* lastTargetFrame = GetTargetFrame();
|
|
|
|
if (!lastTargetFrame) {
|
|
|
|
BeginTransaction(aTargetWeakFrame.GetFrame(), aWheelEvent);
|
|
|
|
} else if (lastTargetFrame != aTargetWeakFrame.GetFrame()) {
|
|
|
|
EndTransaction();
|
|
|
|
BeginTransaction(aTargetWeakFrame.GetFrame(), aWheelEvent);
|
|
|
|
} else {
|
|
|
|
UpdateTransaction(aWheelEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the wheel event will not be handled with any frames,
|
|
|
|
// UpdateTransaction() fires MozMouseScrollFailed event which is for
|
|
|
|
// automated testing. In the event handler, the target frame might be
|
|
|
|
// destroyed. Then, the caller shouldn't try to handle the default action.
|
|
|
|
if (!aTargetWeakFrame.IsAlive()) {
|
|
|
|
EndTransaction();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::OnEvent(WidgetEvent* aEvent)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
2014-04-01 08:09:22 +04:00
|
|
|
if (!sTargetFrame) {
|
2014-04-01 08:09:22 +04:00
|
|
|
return;
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
2014-04-01 08:09:22 +04:00
|
|
|
|
|
|
|
if (OutOfTime(sTime, GetTimeoutTime())) {
|
|
|
|
// Even if the scroll event which is handled after timeout, but onTimeout
|
|
|
|
// was not fired by timer, then the scroll event will scroll old frame,
|
|
|
|
// therefore, we should call OnTimeout here and ensure to finish the old
|
|
|
|
// transaction.
|
|
|
|
OnTimeout(nullptr, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (aEvent->mMessage) {
|
2015-09-10 19:59:54 +03:00
|
|
|
case eWheel:
|
2014-04-01 08:09:22 +04:00
|
|
|
if (sMouseMoved != 0 &&
|
|
|
|
OutOfTime(sMouseMoved, GetIgnoreMoveDelayTime())) {
|
|
|
|
// Terminate the current mousewheel transaction if the mouse moved more
|
|
|
|
// than ignoremovedelay milliseconds ago
|
|
|
|
EndTransaction();
|
|
|
|
}
|
|
|
|
return;
|
2015-08-29 02:58:29 +03:00
|
|
|
case eMouseMove:
|
2015-09-02 09:08:02 +03:00
|
|
|
case eDragOver: {
|
2014-04-01 08:09:22 +04:00
|
|
|
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
|
|
|
if (mouseEvent->IsReal()) {
|
|
|
|
// If the cursor is moving to be outside the frame,
|
|
|
|
// terminate the scrollwheel transaction.
|
2017-04-25 01:33:13 +03:00
|
|
|
LayoutDeviceIntPoint pt = GetScreenPoint(mouseEvent);
|
|
|
|
auto r = LayoutDeviceIntRect::FromAppUnitsToNearest(
|
|
|
|
sTargetFrame->GetScreenRectInAppUnits(),
|
|
|
|
sTargetFrame->PresContext()->AppUnitsPerDevPixel());
|
2014-04-01 08:09:22 +04:00
|
|
|
if (!r.Contains(pt)) {
|
|
|
|
EndTransaction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the cursor is moving inside the frame, and it is less than
|
|
|
|
// ignoremovedelay milliseconds since the last scroll operation, ignore
|
|
|
|
// the mouse move; otherwise, record the current mouse move time to be
|
|
|
|
// checked later
|
2014-04-01 08:09:22 +04:00
|
|
|
if (!sMouseMoved && OutOfTime(sTime, GetIgnoreMoveDelayTime())) {
|
|
|
|
sMouseMoved = PR_IntervalToMilliseconds(PR_IntervalNow());
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyPress:
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyUp:
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyDown:
|
2015-08-29 02:58:30 +03:00
|
|
|
case eMouseUp:
|
2015-08-29 02:58:30 +03:00
|
|
|
case eMouseDown:
|
2015-08-29 02:58:31 +03:00
|
|
|
case eMouseDoubleClick:
|
2016-12-01 03:48:02 +03:00
|
|
|
case eMouseAuxClick:
|
2015-08-29 02:58:32 +03:00
|
|
|
case eMouseClick:
|
2015-08-31 18:20:06 +03:00
|
|
|
case eContextMenu:
|
2015-09-02 09:08:01 +03:00
|
|
|
case eDrop:
|
2014-04-01 08:09:22 +04:00
|
|
|
EndTransaction();
|
|
|
|
return;
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::Shutdown()
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
NS_IF_RELEASE(sTimer);
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::OnFailToScrollTarget()
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(sTargetFrame, "We don't have mouse scrolling transaction");
|
|
|
|
|
2017-04-13 05:41:23 +03:00
|
|
|
if (Prefs::sTestMouseScroll) {
|
2014-04-01 08:09:22 +04:00
|
|
|
// This event is used for automated tests, see bug 442774.
|
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
|
|
|
sTargetFrame->GetContent()->OwnerDoc(),
|
|
|
|
sTargetFrame->GetContent(),
|
|
|
|
NS_LITERAL_STRING("MozMouseScrollFailed"),
|
|
|
|
true, true);
|
|
|
|
}
|
|
|
|
// The target frame might be destroyed in the event handler, at that time,
|
|
|
|
// we need to finish the current transaction
|
|
|
|
if (!sTargetFrame) {
|
|
|
|
EndTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::OnTimeout(nsITimer* aTimer, void* aClosure)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
if (!sTargetFrame) {
|
|
|
|
// The transaction target was destroyed already
|
|
|
|
EndTransaction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Store the sTargetFrame, the variable becomes null in EndTransaction.
|
|
|
|
nsIFrame* frame = sTargetFrame;
|
|
|
|
// We need to finish current transaction before DOM event firing. Because
|
|
|
|
// the next DOM event might create strange situation for us.
|
|
|
|
MayEndTransaction();
|
|
|
|
|
2017-04-13 05:41:23 +03:00
|
|
|
if (Prefs::sTestMouseScroll) {
|
2014-04-01 08:09:22 +04:00
|
|
|
// This event is used for automated tests, see bug 442774.
|
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
|
|
|
frame->GetContent()->OwnerDoc(),
|
|
|
|
frame->GetContent(),
|
|
|
|
NS_LITERAL_STRING("MozMouseScrollTransactionTimeout"),
|
|
|
|
true, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::SetTimeout()
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
if (!sTimer) {
|
2017-10-16 09:15:40 +03:00
|
|
|
sTimer = NS_NewTimer().take();
|
|
|
|
if (!sTimer) {
|
2014-04-01 08:09:22 +04:00
|
|
|
return;
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
sTimer->Cancel();
|
2014-04-01 08:09:22 +04:00
|
|
|
DebugOnly<nsresult> rv =
|
2017-06-12 22:34:10 +03:00
|
|
|
sTimer->InitWithNamedFuncCallback(OnTimeout,
|
|
|
|
nullptr,
|
|
|
|
GetTimeoutTime(),
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"WheelTransaction::SetTimeout");
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"nsITimer::InitWithFuncCallback failed");
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
|
2017-04-25 01:33:13 +03:00
|
|
|
/* static */ LayoutDeviceIntPoint
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::GetScreenPoint(WidgetGUIEvent* aEvent)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aEvent, "aEvent is null");
|
2016-04-14 11:03:14 +03:00
|
|
|
NS_ASSERTION(aEvent->mWidget, "aEvent-mWidget is null");
|
2017-04-25 01:33:13 +03:00
|
|
|
return aEvent->mRefPoint + aEvent->mWidget->WidgetToScreenOffset();
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ DeltaValues
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::AccelerateWheelDelta(WidgetWheelEvent* aEvent,
|
|
|
|
bool aAllowScrollSpeedOverride)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
DeltaValues result(aEvent);
|
|
|
|
|
|
|
|
// Don't accelerate the delta values if the event isn't line scrolling.
|
2016-03-31 12:35:24 +03:00
|
|
|
if (aEvent->mDeltaMode != nsIDOMWheelEvent::DOM_DELTA_LINE) {
|
2014-04-01 08:09:22 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAllowScrollSpeedOverride) {
|
|
|
|
result = OverrideSystemScrollSpeed(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accelerate by the sScrollSeriesCounter
|
|
|
|
int32_t start = GetAccelerationStart();
|
|
|
|
if (start >= 0 && sScrollSeriesCounter >= start) {
|
|
|
|
int32_t factor = GetAccelerationFactor();
|
|
|
|
if (factor > 0) {
|
|
|
|
result.deltaX = ComputeAcceleratedWheelDelta(result.deltaX, factor);
|
|
|
|
result.deltaY = ComputeAcceleratedWheelDelta(result.deltaY, factor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ double
|
2015-12-02 00:45:49 +03:00
|
|
|
WheelTransaction::ComputeAcceleratedWheelDelta(double aDelta, int32_t aFactor)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
2015-12-02 00:45:49 +03:00
|
|
|
return mozilla::ComputeAcceleratedWheelDelta(aDelta, sScrollSeriesCounter, aFactor);
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ DeltaValues
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::OverrideSystemScrollSpeed(WidgetWheelEvent* aEvent)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(sTargetFrame, "We don't have mouse scrolling transaction");
|
2016-03-31 12:35:24 +03:00
|
|
|
MOZ_ASSERT(aEvent->mDeltaMode == nsIDOMWheelEvent::DOM_DELTA_LINE);
|
2014-04-01 08:09:22 +04:00
|
|
|
|
|
|
|
// If the event doesn't scroll to both X and Y, we don't need to do anything
|
|
|
|
// here.
|
2016-03-31 12:09:47 +03:00
|
|
|
if (!aEvent->mDeltaX && !aEvent->mDeltaY) {
|
2014-04-01 08:09:22 +04:00
|
|
|
return DeltaValues(aEvent);
|
|
|
|
}
|
|
|
|
|
2016-01-27 09:09:13 +03:00
|
|
|
return DeltaValues(aEvent->OverriddenDeltaX(),
|
|
|
|
aEvent->OverriddenDeltaY());
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************/
|
2014-04-01 08:09:22 +04:00
|
|
|
/* mozilla::ScrollbarsForWheel */
|
2014-04-01 08:09:22 +04:00
|
|
|
/******************************************************************/
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
const DeltaValues ScrollbarsForWheel::directions[kNumberOfTargets] = {
|
2014-04-01 08:09:22 +04:00
|
|
|
DeltaValues(-1, 0), DeltaValues(+1, 0), DeltaValues(0, -1), DeltaValues(0, +1)
|
|
|
|
};
|
|
|
|
|
2017-03-01 20:03:14 +03:00
|
|
|
AutoWeakFrame ScrollbarsForWheel::sActiveOwner = nullptr;
|
|
|
|
AutoWeakFrame ScrollbarsForWheel::sActivatedScrollTargets[kNumberOfTargets] = {
|
2014-04-01 08:09:22 +04:00
|
|
|
nullptr, nullptr, nullptr, nullptr
|
|
|
|
};
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
bool ScrollbarsForWheel::sHadWheelStart = false;
|
|
|
|
bool ScrollbarsForWheel::sOwnWheelTransaction = false;
|
2014-04-01 08:09:22 +04:00
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:23 +04:00
|
|
|
ScrollbarsForWheel::PrepareToScrollText(EventStateManager* aESM,
|
2014-04-01 08:09:22 +04:00
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
WidgetWheelEvent* aEvent)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
2015-09-10 19:59:55 +03:00
|
|
|
if (aEvent->mMessage == eWheelOperationStart) {
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::OwnScrollbars(false);
|
2014-04-01 08:09:22 +04:00
|
|
|
if (!IsActive()) {
|
|
|
|
TemporarilyActivateAllPossibleScrollTargets(aESM, aTargetFrame, aEvent);
|
|
|
|
sHadWheelStart = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DeactivateAllTemporarilyActivatedScrollTargets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
ScrollbarsForWheel::SetActiveScrollTarget(nsIScrollableFrame* aScrollTarget)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
if (!sHadWheelStart) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-14 10:40:53 +04:00
|
|
|
nsIScrollbarMediator* scrollbarMediator = do_QueryFrame(aScrollTarget);
|
|
|
|
if (!scrollbarMediator) {
|
2014-04-01 08:09:22 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
sHadWheelStart = false;
|
|
|
|
sActiveOwner = do_QueryFrame(aScrollTarget);
|
2014-02-14 10:40:53 +04:00
|
|
|
scrollbarMediator->ScrollbarActivityStarted();
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
ScrollbarsForWheel::MayInactivate()
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
2014-04-01 08:09:22 +04:00
|
|
|
if (!sOwnWheelTransaction && WheelTransaction::GetTargetFrame()) {
|
|
|
|
WheelTransaction::OwnScrollbars(true);
|
2014-04-01 08:09:22 +04:00
|
|
|
} else {
|
|
|
|
Inactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
ScrollbarsForWheel::Inactivate()
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
2014-02-14 10:40:53 +04:00
|
|
|
nsIScrollbarMediator* scrollbarMediator = do_QueryFrame(sActiveOwner);
|
|
|
|
if (scrollbarMediator) {
|
|
|
|
scrollbarMediator->ScrollbarActivityStopped();
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
sActiveOwner = nullptr;
|
|
|
|
DeactivateAllTemporarilyActivatedScrollTargets();
|
|
|
|
if (sOwnWheelTransaction) {
|
|
|
|
sOwnWheelTransaction = false;
|
2014-04-01 08:09:22 +04:00
|
|
|
WheelTransaction::OwnScrollbars(false);
|
|
|
|
WheelTransaction::EndTransaction();
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ bool
|
2014-04-01 08:09:22 +04:00
|
|
|
ScrollbarsForWheel::IsActive()
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
if (sActiveOwner) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < kNumberOfTargets; ++i) {
|
|
|
|
if (sActivatedScrollTargets[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
ScrollbarsForWheel::OwnWheelTransaction(bool aOwn)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
sOwnWheelTransaction = aOwn;
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
ScrollbarsForWheel::TemporarilyActivateAllPossibleScrollTargets(
|
2014-04-01 08:09:23 +04:00
|
|
|
EventStateManager* aESM,
|
2014-04-01 08:09:22 +04:00
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
WidgetWheelEvent* aEvent)
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < kNumberOfTargets; i++) {
|
|
|
|
const DeltaValues *dir = &directions[i];
|
2017-03-01 20:03:14 +03:00
|
|
|
AutoWeakFrame* scrollTarget = &sActivatedScrollTargets[i];
|
2014-04-01 08:09:22 +04:00
|
|
|
MOZ_ASSERT(!*scrollTarget, "scroll target still temporarily activated!");
|
2015-10-16 07:19:27 +03:00
|
|
|
nsIScrollableFrame* target = do_QueryFrame(
|
2014-04-01 08:09:22 +04:00
|
|
|
aESM->ComputeScrollTarget(aTargetFrame, dir->deltaX, dir->deltaY, aEvent,
|
2015-10-16 07:19:27 +03:00
|
|
|
EventStateManager::COMPUTE_DEFAULT_ACTION_TARGET));
|
2014-02-14 10:40:53 +04:00
|
|
|
nsIScrollbarMediator* scrollbarMediator = do_QueryFrame(target);
|
|
|
|
if (scrollbarMediator) {
|
2014-04-01 08:09:22 +04:00
|
|
|
nsIFrame* targetFrame = do_QueryFrame(target);
|
|
|
|
*scrollTarget = targetFrame;
|
2014-02-14 10:40:53 +04:00
|
|
|
scrollbarMediator->ScrollbarActivityStarted();
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
/* static */ void
|
2014-04-01 08:09:22 +04:00
|
|
|
ScrollbarsForWheel::DeactivateAllTemporarilyActivatedScrollTargets()
|
2014-04-01 08:09:22 +04:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < kNumberOfTargets; i++) {
|
2017-03-01 20:03:14 +03:00
|
|
|
AutoWeakFrame* scrollTarget = &sActivatedScrollTargets[i];
|
2014-04-01 08:09:22 +04:00
|
|
|
if (*scrollTarget) {
|
2014-02-14 10:40:53 +04:00
|
|
|
nsIScrollbarMediator* scrollbarMediator = do_QueryFrame(*scrollTarget);
|
|
|
|
if (scrollbarMediator) {
|
|
|
|
scrollbarMediator->ScrollbarActivityStopped();
|
2014-04-01 08:09:22 +04:00
|
|
|
}
|
|
|
|
*scrollTarget = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-01 08:09:22 +04:00
|
|
|
|
2017-04-13 05:41:23 +03:00
|
|
|
/******************************************************************/
|
Bug 143038 Make users can scroll contents horizontally with vertical wheel operation with a modifier r=smaug
This patch declares a new default action, "horizontal scroll", this scrolls
content horizontally with deltaY of wheel events and ignores deltaX and deltaZ.
This is used for default action with Shift key in default setting except on
macOS. On macOS, legacy mouse's vertical wheel operation with Shift key causes
native horizontal wheel event. Therefore, we don't need to use this new
default action on macOS. Additionally, old default action with Shift key,
navigating history, is moved to with Alt key. This makes same settings between
macOS and the others. So, this is better for users who use macOS and another
OS and web app developers who check wheel events only on macOS or other
platform(s).
For simpler implementation, default action handlers moves deltaY values to
deltaX values temporarily *only* while they handle wheel events. This is
performed by AutoWheelDeltaAdjuster and restored after handling it
automatically.
So, in other words, even if default action is "horizontal scroll", web apps
receives wheel events whose deltaY is not zero but its content will be
scrolled horizontally. This is same as Chromium, so, this behavior shouldn't
cause any incompatible behavior with it.
MozReview-Commit-ID: E4X3yZzLEAl
--HG--
extra : rebase_source : e20d854c6b0a181ad4c9e7304bd9ad14256481ff
2017-10-04 19:12:35 +03:00
|
|
|
/* mozilla::WheelTransaction::Prefs */
|
2017-04-13 05:41:23 +03:00
|
|
|
/******************************************************************/
|
Bug 143038 Make users can scroll contents horizontally with vertical wheel operation with a modifier r=smaug
This patch declares a new default action, "horizontal scroll", this scrolls
content horizontally with deltaY of wheel events and ignores deltaX and deltaZ.
This is used for default action with Shift key in default setting except on
macOS. On macOS, legacy mouse's vertical wheel operation with Shift key causes
native horizontal wheel event. Therefore, we don't need to use this new
default action on macOS. Additionally, old default action with Shift key,
navigating history, is moved to with Alt key. This makes same settings between
macOS and the others. So, this is better for users who use macOS and another
OS and web app developers who check wheel events only on macOS or other
platform(s).
For simpler implementation, default action handlers moves deltaY values to
deltaX values temporarily *only* while they handle wheel events. This is
performed by AutoWheelDeltaAdjuster and restored after handling it
automatically.
So, in other words, even if default action is "horizontal scroll", web apps
receives wheel events whose deltaY is not zero but its content will be
scrolled horizontally. This is same as Chromium, so, this behavior shouldn't
cause any incompatible behavior with it.
MozReview-Commit-ID: E4X3yZzLEAl
--HG--
extra : rebase_source : e20d854c6b0a181ad4c9e7304bd9ad14256481ff
2017-10-04 19:12:35 +03:00
|
|
|
|
2017-04-13 05:41:23 +03:00
|
|
|
int32_t WheelTransaction::Prefs::sMouseWheelAccelerationStart = -1;
|
|
|
|
int32_t WheelTransaction::Prefs::sMouseWheelAccelerationFactor = -1;
|
|
|
|
uint32_t WheelTransaction::Prefs::sMouseWheelTransactionTimeout = 1500;
|
|
|
|
uint32_t WheelTransaction::Prefs::sMouseWheelTransactionIgnoreMoveDelay = 100;
|
|
|
|
bool WheelTransaction::Prefs::sTestMouseScroll = false;
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
WheelTransaction::Prefs::InitializeStatics()
|
|
|
|
{
|
|
|
|
static bool sIsInitialized = false;
|
|
|
|
if (!sIsInitialized) {
|
|
|
|
Preferences::AddIntVarCache(&sMouseWheelAccelerationStart,
|
|
|
|
"mousewheel.acceleration.start", -1);
|
|
|
|
Preferences::AddIntVarCache(&sMouseWheelAccelerationFactor,
|
|
|
|
"mousewheel.acceleration.factor", -1);
|
|
|
|
Preferences::AddUintVarCache(&sMouseWheelTransactionTimeout,
|
|
|
|
"mousewheel.transaction.timeout", 1500);
|
|
|
|
Preferences::AddUintVarCache(&sMouseWheelTransactionIgnoreMoveDelay,
|
|
|
|
"mousewheel.transaction.ignoremovedelay", 100);
|
|
|
|
Preferences::AddBoolVarCache(&sTestMouseScroll, "test.mousescroll", false);
|
|
|
|
sIsInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 143038 Make users can scroll contents horizontally with vertical wheel operation with a modifier r=smaug
This patch declares a new default action, "horizontal scroll", this scrolls
content horizontally with deltaY of wheel events and ignores deltaX and deltaZ.
This is used for default action with Shift key in default setting except on
macOS. On macOS, legacy mouse's vertical wheel operation with Shift key causes
native horizontal wheel event. Therefore, we don't need to use this new
default action on macOS. Additionally, old default action with Shift key,
navigating history, is moved to with Alt key. This makes same settings between
macOS and the others. So, this is better for users who use macOS and another
OS and web app developers who check wheel events only on macOS or other
platform(s).
For simpler implementation, default action handlers moves deltaY values to
deltaX values temporarily *only* while they handle wheel events. This is
performed by AutoWheelDeltaAdjuster and restored after handling it
automatically.
So, in other words, even if default action is "horizontal scroll", web apps
receives wheel events whose deltaY is not zero but its content will be
scrolled horizontally. This is same as Chromium, so, this behavior shouldn't
cause any incompatible behavior with it.
MozReview-Commit-ID: E4X3yZzLEAl
--HG--
extra : rebase_source : e20d854c6b0a181ad4c9e7304bd9ad14256481ff
2017-10-04 19:12:35 +03:00
|
|
|
/******************************************************************/
|
|
|
|
/* mozilla::AutoWheelDeltaAdjuster */
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
AutoWheelDeltaAdjuster::AutoWheelDeltaAdjuster(WidgetWheelEvent& aWheelEvent)
|
|
|
|
: mWheelEvent(aWheelEvent)
|
|
|
|
, mOldDeltaX(aWheelEvent.mDeltaX)
|
|
|
|
, mOldDeltaZ(aWheelEvent.mDeltaZ)
|
|
|
|
, mOldOverflowDeltaX(aWheelEvent.mOverflowDeltaX)
|
|
|
|
, mOldLineOrPageDeltaX(aWheelEvent.mLineOrPageDeltaX)
|
|
|
|
, mTreatedVerticalWheelAsHorizontalScroll(false)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!aWheelEvent.mDeltaValuesAdjustedForDefaultHandler);
|
|
|
|
|
|
|
|
if (EventStateManager::WheelEventIsHorizontalScrollAction(&aWheelEvent)) {
|
|
|
|
// Move deltaY values to deltaX and set both deltaY and deltaZ to 0.
|
|
|
|
mWheelEvent.mDeltaX = mWheelEvent.mDeltaY;
|
|
|
|
mWheelEvent.mDeltaY = 0.0;
|
|
|
|
mWheelEvent.mDeltaZ = 0.0;
|
|
|
|
mWheelEvent.mOverflowDeltaX = mWheelEvent.mOverflowDeltaY;
|
|
|
|
mWheelEvent.mOverflowDeltaY = 0.0;
|
|
|
|
mWheelEvent.mLineOrPageDeltaX = mWheelEvent.mLineOrPageDeltaY;
|
|
|
|
mWheelEvent.mLineOrPageDeltaY = 0;
|
|
|
|
mWheelEvent.mDeltaValuesAdjustedForDefaultHandler = true;
|
|
|
|
mTreatedVerticalWheelAsHorizontalScroll = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoWheelDeltaAdjuster::~AutoWheelDeltaAdjuster()
|
|
|
|
{
|
|
|
|
if (mTreatedVerticalWheelAsHorizontalScroll &&
|
|
|
|
mWheelEvent.mDeltaValuesAdjustedForDefaultHandler) {
|
|
|
|
mWheelEvent.mDeltaY = mWheelEvent.mDeltaX;
|
|
|
|
mWheelEvent.mDeltaX = mOldDeltaX;
|
|
|
|
mWheelEvent.mDeltaZ = mOldDeltaZ;
|
|
|
|
mWheelEvent.mOverflowDeltaY = mWheelEvent.mOverflowDeltaX;
|
|
|
|
mWheelEvent.mOverflowDeltaX = mOldOverflowDeltaX;
|
|
|
|
mWheelEvent.mLineOrPageDeltaY = mWheelEvent.mLineOrPageDeltaX;
|
|
|
|
mWheelEvent.mLineOrPageDeltaX = mOldLineOrPageDeltaX;
|
|
|
|
mWheelEvent.mDeltaValuesAdjustedForDefaultHandler = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:22 +04:00
|
|
|
} // namespace mozilla
|